-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmlorCtl.pd_lua
More file actions
94 lines (87 loc) · 3.09 KB
/
Copy pathmlorCtl.pd_lua
File metadata and controls
94 lines (87 loc) · 3.09 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
local keybuf = {}
local trackbuf = {{},{},{},{},{},{},{},{}}
--because pd doesnt like $1 as numbers...
local letter2num ={a=0,b=1,c=2,d=3,e=4,f=5,g=6,h=7}
local mlor = pd.Class:new():register("mlorCtl")
for x = 1, 8 do
trackbuf[x].min = 0
trackbuf[x].max = 1
trackbuf[x].dur = 1
end
function mlor:initialize(name, atoms)
self.outlets = 2
self.inlets = 2
return true
end
function mlor:in_2(sel,list)
if sel == "/monome/grid/key" then
local xkey, row, state = list[1], list[2], list[3]
if state == 1 then
if keybuf[row] == nil then
--if there is nothing in keybuf table, this is first key, so create table with entry
keybuf[row] = {xkey} --x value entry
else --else something is in keybuf for this row, so add to table
table.insert(keybuf[row],xkey)
end
elseif state == 0 then
--first check to see if multiple keys in this buf
if #keybuf[row] > 1 then
--now set our keys
local firstkey = (keybuf[row][1]/8)
local secondkey = (keybuf[row][2]/8)
if firstkey > secondkey then
--the first is larger than second, so rev -1 and min max
self:outlet(2,"playctl",{row, "low", secondkey})
self:outlet(2,"playctl",{row, "high", firstkey+(0.125)})---need to add this for gird to make sense
self:outlet(2,"playctl",{row, "dir", -1})
trackbuf[row+1].dur = firstkey - secondkey --setting the new dur of the subloop
trackbuf[row+1].min = secondkey
trackbuf[row+1].max = firstkey
else
self:outlet(2,"playctl",{row, "low", firstkey})
self:outlet(2,"playctl",{row, "high", secondkey+(0.125)})
self:outlet(2,"playctl",{row, "dir", 1})
trackbuf[row+1].dur = secondkey - firstkey --setting the new dur of the subloop
trackbuf[row+1].min = firstkey
trackbuf[row+1].max = secondkey
end
else
local relativegoto = (trackbuf[row+1].dur*(xkey/8))+trackbuf[row+1].min
self:outlet(2,"playctl",{row,"goto",relativegoto})
end
keybuf[list[2]] = {}
end
end
if sel == "/monome/grid/auxkey" then
local recled = {"/monome/grid/led/level/row", 0, list[1], 11,11,11,11,11,11,11,11}
if list[2] ~= 0 then
self:outlet(2,"playctl",{list[1], "stop"})
self:outlet(2,"recctl",{list[1],list[2]})
self:outlet(1, "ledctl",recled)
else
self:outlet(2,"recctl",{list[1],list[2]})
self:outlet(2,"playctl",{list[1], "start"})
end
end
end
function mlor:in_1(sel, list)
-- pd.post("SEL "..sel)
-- pd.post("LIST[1] "..list[1])
--- first start list with row command, 0 offset, and the row
local ledbuf = {"/monome/grid/led/level/row", 0, letter2num[list[1]]}
local row = letter2num[list[1]]+1
local currHead = list[2]
local min, max = trackbuf[row].min*8, trackbuf[row].max*8
for x = 1, 8 do
if x <= min then
ledbuf[x+3] = 0
elseif x > max+1 then
ledbuf[x+3] = 0
elseif x == currHead then
ledbuf[x+3] = 15 --keeping monome "varibright"
else
ledbuf[x+3] = 5
end
end
self:outlet(1, "ledctl",ledbuf)
end