-
Notifications
You must be signed in to change notification settings - Fork 0
/
30-dataHandling.ino
350 lines (302 loc) · 9.42 KB
/
30-dataHandling.ino
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#include <avr/wdt.h>
#define MAX_OCTAVE 5
#define MIN_OCTAVE -5
#define MAX_TRANSPOSE 11
#define MIN_TRANSPOSE -11
#define MODE_BYPASS 0
#define MODE_SINGLE 1
#define MODE_DUAL_SPLIT 2
#define MODE_DUAL_LAYER 3
#define DUAL_SPLIT 0
#define DUAL_LAYER 1
#define PROP_MIDI_CHANNEL 0
#define PROP_OCTAVE 1
#define PROP_TRANSPOSE 2
uint8_t currentMode = MODE_BYPASS;
uint8_t lastLayerOrSplit = DUAL_SPLIT;
struct channelItem {
uint8_t midiCh;
String label;
uint16_t color;
uint16_t txtColor;
};
// TODO find a name for this struct...
struct findName {
channelItem item;
int8_t octave;
int8_t transpose;
uint16_t x;
uint8_t editProp;
};
struct channelItem getItemByChannel(uint8_t midiCh) {
channelItem item {
0, " ---", BLACK, WHITE
};
switch(midiCh) {
case 1: item.label = "JD-Xi D1"; item.midiCh = 1; item.color = ORANGE; break;
case 2: item.label = "JD-Xi D2"; item.midiCh = 2; item.color = ORANGE; break;
case 3: item.label = "JD-Xi ana"; item.midiCh = 3; item.color = BLUE; break;
case 4: item.label = "GEM rp-x"; item.midiCh = 4; item.color = GRAY; break;
case 5: item.label = " System1"; item.midiCh = 5; item.color = GREEN; item.txtColor = BLACK; break;
case 6: item.label = "MicroKORG"; item.midiCh = 6; item.color = 0x35B7; break;
case 7: item.label = " VIRUS "; item.midiCh = 7; item.color = RED; break;
case 8: item.label = " TB3"; item.midiCh = 8; item.color = GREEN; item.txtColor = BLACK; break;
case 9: item.label = " CH 9"; item.midiCh = 9; item.color = BLACK; break;
case 10: item.label = " CH 10"; item.midiCh = 10; item.color = BLACK; break;
case 11: item.label = " Blofeld"; item.midiCh = 11; item.color = BROWN; break;
case 12: item.label = "iPad 12"; item.midiCh = 12; item.color = PINK; break;
case 13: item.label = "iPad 13"; item.midiCh = 13; item.color = PINK; break;
case 14: item.label = "iPad 14"; item.midiCh = 14; item.color = PINK; break;
case 15: item.label = "iPad 15"; item.midiCh = 15; item.color = PINK; break;
case 16: item.label = " Digitakt"; item.midiCh = 16; item.color = YELLOW; item.txtColor = BLACK; break;
}
return item;
}
findName modifier1;
findName modifier2;
void setupDataHandling() {
modifier1.item = getItemByChannel(0);
modifier1.x = lcdWidth/4;
modifier1.x = 0;
modifier2.item = getItemByChannel(0);
modifier2.x = lcdWidth/2;
}
void handleEncoderChange(uint8_t eIdx, bool doIncrement) {
//Serial.println("change");
//Serial.println(eIdx);
if (doIncrement) {
incrementParam(eIdx);
return;
}
decrementParam(eIdx);
}
// TODO consider to have a dynamic split point!?
void handleEncoderPush(uint8_t eIdx, int holdTime) {
if(holdTime < 800) {
// short press: control different property
loopEditPropertyIndex(eIdx);
return;
}
if(holdTime > 4000) {
// very long press: reboot
drawReboot();
delay(1000);
reboot();
return;
}
// long press: toggle layer/split mode
currentMode = (lastLayerOrSplit == DUAL_SPLIT) ? MODE_DUAL_LAYER : MODE_DUAL_SPLIT;
lastLayerOrSplit = (currentMode == MODE_DUAL_SPLIT) ? DUAL_SPLIT : DUAL_LAYER;
if(currentMode > MODE_SINGLE) {
drawModeLabel();
}
}
// modify midi channel
void incrementModifierMidiChannel(uint8_t modIndex) {
uint8_t currentMidiChannel;
switch(modIndex) {
case 0: incrementModifierMidiChannel(modifier1); return;
case 1: incrementModifierMidiChannel(modifier2); return;
}
}
void incrementModifierMidiChannel(struct findName &modifierItem) {
uint8_t currentMidiChannel = modifierItem.item.midiCh;
currentMidiChannel++;
if(currentMidiChannel > 16) {
currentMidiChannel = 16;
}
modifierItem.item = getItemByChannel(currentMidiChannel);
checkChangeMode();
if(currentMode == MODE_BYPASS || modifierItem.item.midiCh == 0) {
return;
}
drawMidiChannel(modifierItem);
// reset octave and transpose
modifierItem.octave = 0;
drawOctave(modifierItem);
modifierItem.transpose = 0;
drawTranspose(modifierItem);
}
void decrementModifierMidiChannel(uint8_t modIndex) {
switch(modIndex) {
case 0: decrementModifierMidiChannel(modifier1); return;
case 1: decrementModifierMidiChannel(modifier2); return;
}
}
void decrementModifierMidiChannel(struct findName &modifierItem) {
uint8_t currentMidiChannel;
currentMidiChannel = modifierItem.item.midiCh;
if(currentMidiChannel > 0) {
currentMidiChannel--;
}
modifierItem.item = getItemByChannel(currentMidiChannel);
checkChangeMode();
if(currentMode == MODE_BYPASS || modifierItem.item.midiCh == 0) {
return;
}
drawMidiChannel(modifierItem);
// reset octave and transpose
modifierItem.octave = 0;
drawOctave(modifierItem);
modifierItem.transpose = 0;
drawTranspose(modifierItem);
}
// modify octave
void incrementModifierOctave(uint8_t modIndex) {
switch(modIndex) {
case 0: incrementModifierOctave(modifier1); return;
case 1: incrementModifierOctave(modifier2); return;
}
}
void incrementModifierOctave(struct findName &modifierItem) {
modifierItem.octave++;
if(modifierItem.octave > MAX_OCTAVE) {
modifierItem.octave = MAX_OCTAVE;
}
drawOctave(modifierItem);
}
void decrementModifierOctave(uint8_t modIndex) {
switch(modIndex) {
case 0: decrementModifierOctave(modifier1); return;
case 1: decrementModifierOctave(modifier2); return;
}
}
void decrementModifierOctave(struct findName &modifierItem) {
modifierItem.octave--;
if(modifierItem.octave < MIN_OCTAVE) {
modifierItem.octave = MIN_OCTAVE;
}
drawOctave(modifierItem);
}
// modify semitone
void incrementModifierTranspose(uint8_t modIndex) {
switch(modIndex) {
case 0: incrementModifierTranspose(modifier1); return;
case 1: incrementModifierTranspose(modifier2); return;
}
}
void incrementModifierTranspose(struct findName &modifierItem) {
modifierItem.transpose++;
if(modifierItem.transpose > MAX_TRANSPOSE) {
if(modifierItem.octave < MAX_OCTAVE) {
incrementModifierOctave(modifierItem);
modifierItem.transpose = 0;
} else {
modifierItem.transpose--;
}
}
drawTranspose(modifierItem);
}
void decrementModifierTranspose(uint8_t modIndex) {
switch(modIndex) {
case 0: decrementModifierTranspose(modifier1); return;
case 1: decrementModifierTranspose(modifier2); return;
}
}
void decrementModifierTranspose(struct findName &modifierItem) {
modifierItem.transpose--;
if(modifierItem.transpose < MIN_TRANSPOSE) {
decrementModifierOctave(modifierItem);
modifierItem.transpose = 0;
}
drawTranspose(modifierItem);
}
void incrementParam(uint8_t modIndex) {
switch(modIndex) {
case 0: incrementParam(modifier1); return;
case 1: incrementParam(modifier2); return;
}
}
void incrementParam(struct findName &modifierItem) {
switch(modifierItem.editProp) {
case 0: incrementModifierMidiChannel(modifierItem); return;
case 1: incrementModifierOctave(modifierItem); return;
case 2: incrementModifierTranspose(modifierItem); return;
}
}
void decrementParam(uint8_t modIndex) {
switch(modIndex) {
case 0: decrementParam(modifier1); return;
case 1: decrementParam(modifier2); return;
}
}
void decrementParam(struct findName &modifierItem) {
switch(modifierItem.editProp) {
case PROP_MIDI_CHANNEL: decrementModifierMidiChannel(modifierItem); return;
case PROP_OCTAVE: decrementModifierOctave(modifierItem); return;
case PROP_TRANSPOSE: decrementModifierTranspose(modifierItem); return;
}
}
void loopEditPropertyIndex(uint8_t modIndex) {
switch(modIndex) {
case 0: loopEditPropertyIndex(modifier1); return;
case 1: loopEditPropertyIndex(modifier2); return;
}
}
void loopEditPropertyIndex(struct findName &modifierItem) {
if(modifierItem.item.midiCh == 0) {
return;
}
modifierItem.editProp++;
if(modifierItem.editProp > 2) {
modifierItem.editProp = 0;
}
if(modifierItem.item.midiCh > 0) {
drawArrow(modifierItem);
}
}
void checkChangeMode() {
uint8_t modeBefore = currentMode;
currentMode = MODE_BYPASS;
bool needLeft = false;
bool needRight = false;
if (modifier1.item.midiCh > 0) {
needLeft = true;
currentMode = MODE_SINGLE;
modifier1.x = lcdWidth/4;
if (modifier2.item.midiCh > 0) {
needRight = true;
modifier1.x = 0;
modifier2.x = lcdWidth/2;
currentMode = (lastLayerOrSplit == DUAL_SPLIT) ? MODE_DUAL_SPLIT : MODE_DUAL_LAYER;
lastLayerOrSplit = (currentMode == MODE_DUAL_SPLIT) ? DUAL_SPLIT : DUAL_LAYER;
}
}
if (modeBefore == currentMode) {
//debug("no mode change");
return;
}
if (currentMode == MODE_BYPASS) {
//debug("new mode bypass");
drawBypass();
modifier1.editProp = PROP_MIDI_CHANNEL;
modifier2.editProp = PROP_MIDI_CHANNEL;
return;
}
bool needFullRedraw = false;
if (modeBefore == MODE_BYPASS) {
needFullRedraw = true;
}
if (modeBefore > MODE_SINGLE && currentMode == MODE_SINGLE) {
needFullRedraw = true;
modifier2.editProp = PROP_MIDI_CHANNEL;
}
if (modeBefore == MODE_SINGLE && currentMode > MODE_SINGLE) {
needFullRedraw = true;
}
if(needFullRedraw == true) {
tft.fillRect(0, 0, lcdWidth, lcdHeight, DARKEST_GRAY);
if (currentMode > MODE_SINGLE) {
drawModeLabel();
}
}
drawModifierItem(modifier1);
if(currentMode > MODE_SINGLE) {
drawModifierItem(modifier2);
}
}
void reboot() {
wdt_disable();
wdt_enable(WDTO_15MS);
while (1) {}
}