-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.lua
295 lines (232 loc) · 8.84 KB
/
display.lua
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
format_version = "1.0"
local inputs = { "A1", "A2", "A3", "A4", "A5", "A6", "B1", "B2", "B3", "B4", "B5", "B6" }
--------------- Definition ----------------------
function gestureFunction(handlers)
return function(props, di, sp)
local gesture_definition = {
custom_data = {},
handlers = handlers
}
return gesture_definition
end
end
function switchTapFunction(singleStateStep, input)
return function(props, di, gi, cd) return handleSwitchTap(props, singleStateStep, input) end
end
function switchDrawFunction(singleStateStep, bank)
return function(props, di, dr) return handleSwitchDraw(props, singleStateStep, bank) end
end
-- generated by lua create_display_handlers.lua
SwitchGestureA1 = gestureFunction{ on_tap = "SwitchTapA1" }
SwitchTapA1 = switchTapFunction(1, "A1")
SwitchDrawA1 = switchDrawFunction(1, "A")
SwitchGestureA2 = gestureFunction{ on_tap = "SwitchTapA2" }
SwitchTapA2 = switchTapFunction(2, "A2")
SwitchDrawA2 = switchDrawFunction(2, "A")
SwitchGestureA3 = gestureFunction{ on_tap = "SwitchTapA3" }
SwitchTapA3 = switchTapFunction(3, "A3")
SwitchDrawA3 = switchDrawFunction(3, "A")
SwitchGestureA4 = gestureFunction{ on_tap = "SwitchTapA4" }
SwitchTapA4 = switchTapFunction(4, "A4")
SwitchDrawA4 = switchDrawFunction(4, "A")
SwitchGestureA5 = gestureFunction{ on_tap = "SwitchTapA5" }
SwitchTapA5 = switchTapFunction(5, "A5")
SwitchDrawA5 = switchDrawFunction(5, "A")
SwitchGestureA6 = gestureFunction{ on_tap = "SwitchTapA6" }
SwitchTapA6 = switchTapFunction(6, "A6")
SwitchDrawA6 = switchDrawFunction(6, "A")
SwitchGestureB1 = gestureFunction{ on_tap = "SwitchTapB1" }
SwitchTapB1 = switchTapFunction(7, "B1")
SwitchDrawB1 = switchDrawFunction(7, "B")
SwitchGestureB2 = gestureFunction{ on_tap = "SwitchTapB2" }
SwitchTapB2 = switchTapFunction(8, "B2")
SwitchDrawB2 = switchDrawFunction(8, "B")
SwitchGestureB3 = gestureFunction{ on_tap = "SwitchTapB3" }
SwitchTapB3 = switchTapFunction(9, "B3")
SwitchDrawB3 = switchDrawFunction(9, "B")
SwitchGestureB4 = gestureFunction{ on_tap = "SwitchTapB4" }
SwitchTapB4 = switchTapFunction(10, "B4")
SwitchDrawB4 = switchDrawFunction(10, "B")
SwitchGestureB5 = gestureFunction{ on_tap = "SwitchTapB5" }
SwitchTapB5 = switchTapFunction(11, "B5")
SwitchDrawB5 = switchDrawFunction(11, "B")
SwitchGestureB6 = gestureFunction{ on_tap = "SwitchTapB6" }
SwitchTapB6 = switchTapFunction(12, "B6")
SwitchDrawB6 = switchDrawFunction(12, "B")
-- bank toggle
BankToggleGesture = gestureFunction{ on_tap = "BankToggleTap", on_release = "BankToggleRelease" }
-- bank toggle A
BankToggleGestureA = gestureFunction{ on_tap = "BankToggleTapA" }
-- bank toggle B
BankToggleGestureB = gestureFunction{ on_tap = "BankToggleTapB" }
-------------------------------------------------
local switchRect = { left = 0, top = 0, right = 20, bottom = 19 }
local propModeSingle = 0
local propModeMulti = 1
-- properties for switch
local propModeIdx = 1
local propStateSingleIdx = 2
local propStateSingleCVIdx = 3
local propStateSingleOverrideCV = 4
local propStateMultiIdx = 5
local propStateMidiIdx = 6
local propSwitchBankIdx = 7
local propSwitchBankCVIdx = 8
local colorSingleMode = { r = 255, g = 0, b = 0, a = 200 }
local colorMultiMode = { r = 255, g = 127, b = 0, a = 200 }
local colorMidiMode = { r = 255, g = 255, b = 0, a = 200 }
local colorDisabledByBank = { r = 0, g = 0, b = 0, a = 127 }
-- for a regular n-gon, x = cos(2 * k * pi / n), y = sin(2 * k * pi / n) for k = 1...n + translation...
function computeNGon()
local nGonSides = 6
local nGonSize = 10
local rect = {}
for k = 1, nGonSides do
local c = 2 * k * math.pi / nGonSides
rect[#rect + 1] = { x = nGonSize * math.cos(c) + 17, y = nGonSize * math.sin(c) + 14 }
end
return rect
end
local bankToggleRect = computeNGon()
local bankToggleRectAB = { left = 3, top = 3, right = 18, bottom = 17 }
local propBankIdx = 1
local propBankCVIdx = 2
local propBankOverrideCVIdx = 3
local propBankToggle = 4
local propBankNone = 0
local propBankA = 1
local propBankB = 2
local propBankAB = 3
local bankAToggles = {
[propBankNone] = propBankA,
[propBankA] = propBankNone,
[propBankB] = propBankAB,
[propBankAB] = propBankB,
}
local bankBToggles = {
[propBankNone] = propBankB,
[propBankA] = propBankAB,
[propBankB] = propBankNone,
[propBankAB] = propBankA,
}
-- handle tap on a switch (singleStateStep represents the step in single mode)
function handleSwitchTap(props, singleStateStep, input)
local changes = {}
local uiText = ""
if props[propModeIdx] == propModeMulti then
-- jbox.trace("Tap[" .. singleStateStep .. "] - Handle Multi Mode")
changes[propStateMultiIdx] = not props[propStateMultiIdx]
uiText = "cd handleSwitchTap_multi_" .. tostring(changes[propStateMultiIdx])
elseif props[propModeIdx] == propModeSingle then
changes[propStateSingleOverrideCV] = not props[propStateSingleOverrideCV]
if props[propStateSingleCVIdx] > 0 then
-- jbox.trace("Tap - Handle Single Mode.. overriding CV: " .. tostring(props[propStateSingleOverrideCV]))
changes[propStateSingleIdx] = singleStateStep
else
-- jbox.trace("Tap - Handle Single Mode: " .. props[propStateSingleIdx])
if props[propStateSingleIdx] == singleStateStep then
-- toggle the step if you press on it again
changes[propStateSingleIdx] = 0
else
changes[propStateSingleIdx] = singleStateStep
end
end
uiText = "cd handleSwitchTap_single_" .. tostring(changes[propStateSingleIdx] == singleStateStep)
else
-- jbox.trace("Tap - MidiX - ignoring... ")
end
if uiText == "" then
return { property_changes = changes }
else
uiText = uiText .. "_" .. input
return { gesture_ui_name = jbox.ui_text(uiText), property_changes = changes }
end
end
-- handle drawing the switch
function handleSwitchDraw(props, singleStateStep, bank)
if props[propModeIdx] == propModeMulti then
-- jbox.trace("Draw - Handle Multi Mode")
if props[propStateMultiIdx] then
jbox_display.draw_rect(switchRect, colorMultiMode)
end
elseif props[propModeIdx] == propModeSingle then
-- jbox.trace("Draw - Handle Single Mode: " .. props[propStateSingleIdx] .. " / " .. props[propStateSingleCVIdx])
local singleStateIdx = props[propStateSingleIdx]
if props[propStateSingleCVIdx] > 0 then
singleStateIdx = props[propStateSingleCVIdx]
end
if singleStateIdx == singleStateStep then
jbox_display.draw_rect(switchRect, colorSingleMode)
end
else
-- jbox.trace("Draw - Handle Midi Mode")
if props[propStateMidiIdx] then
jbox_display.draw_rect(switchRect, colorMidiMode)
end
end
local propBank = props[propSwitchBankIdx]
if props[propSwitchBankCVIdx] > 0 then
propBank = props[propSwitchBankCVIdx] - 1
end
if bank == "A" then
if propBank == propBankNone or propBank == propBankB then
jbox_display.draw_rect(switchRect, colorDisabledByBank)
end
else
if propBank == propBankNone or propBank == propBankA then
jbox_display.draw_rect(switchRect, colorDisabledByBank)
end
end
-- jbox.trace("handleSwitchDraw " .. tostring(singleStateStep) .. " bank=" .. tostring(propBank))
end
-- handle bank toggle tap
BankToggleTap = function(props, di, gi, cd)
-- jbox.trace("BankToggleTap: " .. tostring(props[propBankIdx]))
local changes = {}
local propBank = props[propBankIdx]
if props[propBankCVIdx] > 0 then
propBank = props[propBankCVIdx] - 1
-- jbox.trace("propBank from CV " .. propBank)
changes[propBankOverrideCVIdx] = not props[propBankOverrideCVIdx]
else
-- jbox.trace("propBank from UI " .. propBank)
end
if props[propBank] == propBankA then
changes[propBankIdx] = propBankB
else
changes[propBankIdx] = propBankA
end
changes[propBankToggle] = 1
return { gesture_ui_name = jbox.ui_text("cd BankToggleTap"), property_changes = changes }
end
-- handle bank toggle release
BankToggleRelease = function(props, di, gi, cd)
-- jbox.trace("BankToggleRelease")
local changes = {}
changes[propBankToggle] = 0
return { property_changes = changes }
end
-- handle bank toggle for A or B
function handlBankToggleTapX(props, toggle, bankToggles)
-- jbox.trace("BankToggleTap" .. toggle .. ": " .. tostring(props[propBankIdx]))
local changes = {}
local propBank = props[propBankIdx]
if props[propBankCVIdx] > 0 then
propBank = props[propBankCVIdx] - 1
changes[propBankOverrideCVIdx] = not props[propBankOverrideCVIdx]
end
changes[propBankIdx] = bankToggles[propBank]
local uiText = "cd handlBankToggleTapX_" .. toggle
return { gesture_ui_name = jbox.ui_text(uiText), property_changes = changes }
end
-- handle bank toggle tap A
BankToggleTapA = function(props, di, gi, cd)
return handlBankToggleTapX(props, "A", bankAToggles)
end
-- handle bank toggle tap B
BankToggleTapB = function(props, di, gi, cd)
return handlBankToggleTapX(props, "B", bankBToggles)
end
-- nothing to do
NoOpDraw = function(props, di, dr)
end