-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path21_launchpad.lua
More file actions
executable file
·67 lines (55 loc) · 1.37 KB
/
21_launchpad.lua
File metadata and controls
executable file
·67 lines (55 loc) · 1.37 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
require("21_launchpad_defines")
require("08_midi")
LaunchPad = {}
LaunchPad.__index = LaunchPad
function LaunchPad:setLed(x, y, clr)
LaunchPadCmd:new():setLed(x, y, clr):exec()
end
function LaunchPad:setLedRGB(x, y, r, g, b, dim)
LaunchPadCmd:new():setLedRGB(x, y, r, g, b, dim):exec()
end
function LaunchPad:setMapping(x, y, obj)
MidiInput:set(1, x + y * 10, obj)
end
function LaunchPad:unsetMapping(x, y, obj)
MidiInput:unset(1, x + y * 10)
end
function LaunchPad:clear()
LaunchPadCmd:new():clear():exec()
end
LaunchPadCmd = {}
LaunchPadCmd.__index = LaunchPadCmd
function LaunchPadCmd:new()
local lpcmd = setmetatable({}, LaunchPadCmd)
lpcmd.op = Builder:new()
return lpcmd
end
function LaunchPadCmd:from(op)
local lpcmd = setmetatable({}, LaunchPadCmd)
lpcmd.op = op
return lpcmd
end
function LaunchPadCmd:setLed(x, y, clr)
self.op:noteOn(1, x + y * 10, clr)
return self
end
function LaunchPadCmd:setLedRGB(x, y, r, g, b, dim)
self.op:noteOn(1, x + y * 10, matchColor(r, g, b, dim or 255))
return self
end
function LaunchPadCmd:clear()
for x = 1, 9 do
for y = 1, 9 do
self:setLed(x, y, 0)
end
end
return self
end
function LaunchPadCmd:exec()
self.op:exec()
end
function LaunchPadCmd:copyToCmd(cmd)
for _, op in pairs(self.op.op) do
table.insert(cmd.op, op)
end
end