-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path8_osc.lua
More file actions
109 lines (93 loc) · 1.99 KB
/
8_osc.lua
File metadata and controls
109 lines (93 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
--
-- ////\\\\
-- ////\\\\ TUTORIAL
-- ////\\\\ PART 8
-- \\\\////
-- \\\\//// OSC
-- \\\\////
--
local viewport = { width = 128, height = 64, frame = 0 }
-- Main
function init()
connect()
-- Render Style
screen.level(15)
screen.aa(0)
screen.line_width(1)
-- Render
redraw()
end
function connect()
osc.event = on_osc_event
end
function on_osc_event(path, args, from)
msg = { path = path, ip = from[1], port = from[2], bytes = args }
redraw(msg)
end
-- Interactions
function key(id,state)
if state == 1 and midi_signal then
midi_signal.note_on(60,127)
elseif midi_signal then
midi_signal.note_off(60,127)
end
redraw()
end
function enc(id,delta)
redraw()
end
-- Render
function draw_frame()
screen.level(15)
screen.rect(1, 1, viewport.width-1, viewport.height-1)
screen.stroke()
end
function draw_labels()
line_height = 8
screen.level(1)
screen.move(5,viewport.height - (line_height * 1))
screen.text('path')
screen.move(5,viewport.height - (line_height * 2))
screen.text('ip')
screen.move(5,viewport.height - (line_height * 3))
screen.text('port')
screen.move(5,viewport.height - (line_height * 4))
screen.text('len')
end
function draw_msg(msg)
local line_height = 8
screen.level(15)
if msg.path then
screen.move(30,viewport.height - (line_height * 1))
screen.text(msg.path)
end
if msg.ip then
screen.move(30,viewport.height - (line_height * 2))
screen.text(msg.ip)
end
if msg.port then
screen.move(30,viewport.height - (line_height * 3))
screen.text(msg.port)
end
if msg.bytes then
screen.move(30,viewport.height - (line_height * 4))
screen.text(#msg.bytes)
end
end
function redraw(msg)
screen.clear()
draw_frame()
draw_labels()
if msg then
draw_msg(msg)
end
screen.stroke()
screen.update()
end
-- Utils
function clamp(val,min,max)
return val < min and min or val > max and max or val
end
function note_to_hz(note)
return (440 / 32) * (2 ^ ((note - 9) / 12))
end