-
Notifications
You must be signed in to change notification settings - Fork 0
/
HXstomp_Midi.ino
544 lines (486 loc) · 10.6 KB
/
HXstomp_Midi.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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
#include <Wire.h>
#include "OneButton.h"
#include <EEPROM.h>
#include <Adafruit_NeoPixel.h>
// ##################### LED ####################
#define LEDPIN 4
#define maxLedBrighntess 45
Adafruit_NeoPixel LED(1, LEDPIN, NEO_RGB + NEO_KHZ800);
// ##################### Power and GND for Midi In and Midi OUT ####################
int gndPin = 9; // set to LOW and connect GND to the midi circuit here. (no need to disconnect midi devices for sketch upload)
int powerPin = 8; // set to HIGH and connect power to the midi circuit here. (no need to disconnect midi devices for sketch upload)
// ##################### Pins for Buttons ####################
OneButton SwitchA(10, true); // Setup a new OneButton
OneButton SwitchB(11, true); // Setup a new OneButton
OneButton SwitchC(12, true); // Setup a new OneButton
#define pressTime 300
#define debounceTime 25
// ##################### General Variables ####################
unsigned long blinkPreviousMillis = 0;
int blinkInterval = 0;
bool bypassActive = false;
bool boostActive = false; // CC 100 for Toggle
bool FSextraActive = false; // CC 101 for Toggle
int looperCurrent = 0; // 0=stopped, 1=playing, 2=recording
bool recModeRecord = true; // rec or overdup
#define MIDICHAN 1
// ##################### Banks ####################
const int n_banks = 4;
int currentBank = 0;
bool bankEnabled[n_banks];
// ##################### Bank 0 ####################
// ################# Snapshot Mode ################
#define b0Color 255, 0, 165
#define enter0 SendCC(71, 0)
#define b0_Aclick SetSnapshot(1)
#define b0_Bclick SetSnapshot(2)
#define b0_Cclick SetSnapshot(3)
// ##################### Bank 1 ####################
// ################## Tap / Tuner #################
#define b1Color 153, 255, 51
#define enter1 SendCC(71, 3)
#define b1_Aclick ToggleTuner()
#define b1_Bclick TapTempo()
#define b1_Cclick HXbypass()
// ##################### Bank 2 ####################
// #################### FS Mode ###################
#define b2Color 51, 255, 255
#define enter2 SendCC(71, 3)
#define b2_Aclick FS4()
#define b2_Bclick FS5()
#define b2_Cclick ToggleFSextra()
// ##################### Bank 3 ####################
// ################## Looper Mode #################
#define b3Color 255, 0, 0
#define enter3 SendCC(71, 3)
#define b3_Aclick LoopRecOverdub()
#define b3_Bclick LoopPlayStop()
#define b3_Cclick LoopUndoRedo()
void setup()
{
Serial.begin(31250); // MIDI:31250 // SERIAL MONITOR:9600 OR 115200
// pins for Midi (including power supply pins, so midi is not screwed up when uploading a new sketch)
pinMode(powerPin, OUTPUT);
pinMode(gndPin, OUTPUT);
digitalWrite(powerPin, HIGH); // Power up
digitalWrite(gndPin, LOW); // Power up
// set timings
// longpress
SwitchA.setPressTicks(pressTime);
SwitchB.setPressTicks(pressTime);
SwitchC.setPressTicks(pressTime);
// debounce
SwitchA.setDebounceTicks(debounceTime);
SwitchB.setDebounceTicks(debounceTime);
SwitchC.setDebounceTicks(debounceTime);
// Initialize bankEnabled array to all enable for first startup
for (int i = 0; i < n_banks; ++i)
{
bankEnabled[i] = true;
}
// Read bank enable/disable states from EEPROM
for (int i = 0; i < n_banks; ++i)
{
byte storedValue = EEPROM.read(i);
if (storedValue != 0 && storedValue != 1)
{
// If the stored value is not 0 or 1, overwrite it with the default setting from bankEnabled
EEPROM.update(i, bankEnabled[i]);
}
else
{
// Update the state only if the stored value is 0 (false) or 1 (true)
bankEnabled[i] = storedValue;
}
}
startupLED();
// switch bank state if button A/B is held
unsigned long startupStart = millis();
while (millis() - startupStart <= 1000)
{
SwitchA.tick();
SwitchB.tick();
SwitchC.tick();
if (SwitchA.isLongPressed() || SwitchB.isLongPressed() || SwitchC.isLongPressed())
{
if (SwitchA.isLongPressed())
{
bankEnabled[1] = !bankEnabled[1];
EEPROM.update(1, bankEnabled[1]);
}
if (SwitchB.isLongPressed())
{
bankEnabled[2] = !bankEnabled[2];
EEPROM.update(2, bankEnabled[2]);
}
if (SwitchC.isLongPressed())
{
bankEnabled[3] = !bankEnabled[3];
EEPROM.update(3, bankEnabled[3]);
}
break;
}
}
showInitializedBanks();
// link the button functions
// Button A
SwitchA.attachClick(SwitchAclick);
SwitchA.attachLongPressStart(ModeUp);
// Button B
SwitchB.attachClick(SwitchBclick);
SwitchB.attachLongPressStart(ToggleBoost);
// Button C
SwitchC.attachClick(SwitchCclick);
SwitchC.attachLongPressStart(BankUp);
enterBank();
}
void loop()
{
// ********************Monitor the Buttons***************
SwitchA.tick();
SwitchB.tick();
SwitchC.tick();
if (blinkInterval != 0)
{
blinkLoopLED();
}
} // Loop
//**************** Device Specific Functions below this point (e.g. for Line6 HX Stomp) **************************
void SendCC(int CC, int value)
{
Serial.write(176);
Serial.write(CC);
Serial.write(value);
}
void SetSnapshot(int n)
{
SendCC(69, n - 1);
}
void SwitchAclick()
{
if (currentBank == 0)
{
b0_Aclick;
}
else if (currentBank == 1)
{
b1_Aclick;
}
else if (currentBank == 2)
{
b2_Aclick;
}
else if (currentBank == 3)
{
b3_Aclick;
}
else
{
;
}
}
void SwitchBclick()
{
if (currentBank == 0)
{
b0_Bclick;
}
else if (currentBank == 1)
{
b1_Bclick;
}
else if (currentBank == 2)
{
b2_Bclick;
}
else if (currentBank == 3)
{
b3_Bclick;
}
else
{
;
}
}
void SwitchCclick()
{
if (currentBank == 0)
{
b0_Cclick;
}
else if (currentBank == 1)
{
b1_Cclick;
}
else if (currentBank == 2)
{
b2_Cclick;
}
else if (currentBank == 3)
{
b3_Cclick;
}
else
{
;
}
}
void FS4()
{
SendCC(52, 127);
}
void FS5()
{
SendCC(53, 127);
}
void HXbypass()
{
if (bypassActive == false)
{
SendCC(70, 0);
bypassActive = true;
}
else if (bypassActive == true)
{
SendCC(70, 127);
bypassActive = false;
}
}
void ToggleBoost()
{
if (boostActive == false)
{
SendCC(100, 0);
boostActive = true;
}
else if (boostActive == true)
{
SendCC(100, 127);
boostActive = false;
}
}
void ToggleFSextra()
{
if (FSextraActive == false)
{
SendCC(101, 0);
FSextraActive = true;
}
else if (FSextraActive == true)
{
SendCC(101, 127);
FSextraActive = false;
}
}
void ToggleTuner()
{
SendCC(68, 127);
}
void TapTempo()
{
SendCC(64, 127);
}
void LoopRecOverdub()
{
if (recModeRecord == true)
{
SendCC(60, 127); // Record
recModeRecord = false; // recModeRecord press now overdups
}
else if (recModeRecord == false)
{
SendCC(60, 0); // Overdup
}
else
{
LED.setPixelColor(0, LED.Color(255, 255, 255));
LED.show();
}
looperCurrent = 2;
blinkInterval = 100;
}
void LoopPlayStop()
{
if (looperCurrent == 0 || looperCurrent == 2)
{
SendCC(61, 127); // start playing
looperCurrent = 1;
blinkInterval = 250;
recModeRecord = false; // recModeRecord press now overdups
}
else if (looperCurrent == 1)
{
SendCC(61, 0); // stop playing
looperCurrent = 0;
blinkInterval = 0;
SwitchLED();
recModeRecord = true; // recModeRecord press now records new loop
}
}
void LoopUndoRedo()
{
SendCC(63, 127);
}
void BankUp()
{
do
{
currentBank = (currentBank + 1) % n_banks;
} while (!bankEnabled[currentBank]);
enterBank();
}
void BankDown()
{
do
{
currentBank = (currentBank - 1 + n_banks) % n_banks;
} while (!bankEnabled[currentBank]);
enterBank();
}
void enterBank()
{
if (currentBank == 0)
{
enter0;
}
else if (currentBank == 1)
{
enter1;
}
else if (currentBank == 2)
{
enter2;
}
else if (currentBank == 3)
{
enter3;
}
SwitchLED();
}
void ModeUp()
{
SendCC(71, 4);
}
void ModeDown()
{
SendCC(71, 5);
}
void startupLED()
{
LED.begin();
LED.setBrightness(maxLedBrighntess);
rainbow();
LED.clear();
LED.show();
delay(250);
LED.setPixelColor(0, LED.Color(255, 255, 255));
LED.show();
delay(500);
}
void showInitializedBanks()
{
LED.clear();
LED.show();
delay(250);
int originalBank = currentBank;
for (int i = 0; i < n_banks; ++i)
{
if (bankEnabled[i])
{
currentBank = i;
SwitchLED();
delay(550);
LED.clear();
LED.show();
delay(250);
}
}
currentBank = originalBank;
delay(500);
}
void SwitchLED()
{
if (currentBank == 0)
{
LED.setPixelColor(0, LED.Color(b0Color));
}
else if (currentBank == 1)
{
LED.setPixelColor(0, LED.Color(b1Color));
}
else if (currentBank == 2)
{
LED.setPixelColor(0, LED.Color(b2Color));
}
else if (currentBank == 3)
{
LED.setPixelColor(0, LED.Color(b3Color));
}
else
{
LED.setPixelColor(0, LED.Color(255, 255, 255));
}
LED.show();
}
void blinkLED(int times, int delay_ms, int red, int green, int blue)
{
int i;
for (i = 0; i < times; i++)
{
LED.clear();
LED.show();
delay(delay_ms);
LED.setPixelColor(0, LED.Color(red, green, blue));
LED.show();
delay(delay_ms);
}
}
void rainbow()
{
int i, j;
for (i = 0; i < 1; i++)
{
for (j = 0; j <= 255; j++)
{
LED.setPixelColor(0, Wheel(j));
LED.show();
delay(5);
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos)
{
WheelPos = 255 - WheelPos;
if (WheelPos < 85)
{
return LED.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170)
{
WheelPos -= 85;
return LED.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return LED.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void blinkLoopLED()
{
unsigned long currentMillis = millis();
if (currentMillis - blinkPreviousMillis >= blinkInterval)
{
// save the last time you blinked the LED
blinkPreviousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (LED.getPixelColor(0) == 0)
{
SwitchLED();
}
else
{
LED.clear();
LED.show();
}
}
}