-
Notifications
You must be signed in to change notification settings - Fork 2
/
EG101.ino
696 lines (594 loc) · 18.1 KB
/
EG101.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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
/* EG101 Companion
James Higgs 2014
Provides extra front panel functionality for Roland EG101 Synth
*/
/*
Software serial MIDI
The circuit:
* digital 4 connected to MIDI jack pin 5
* MIDI jack pin 2 connected to ground
* MIDI jack pin 4 connected to +5V through 220-ohm resistor
Sotware serial drives the MIDI thru digital port 3 (in) and 4 (out)
*/
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <SPI.h>
#include <GD2.h>
#include <avr/pgmspace.h>
#include "patches.h"
#define midiRxPin 3
#define midiTxPin 4
SoftwareSerial midiSerial(midiRxPin, midiTxPin); // RX, TX
// Patch info for all 400 odd patches is stored in PROGMEM, only the current
// "page" of patches is stored in SRAM
PATCHINFO currentPagePatchInfo[20];
#define MAIN_PAGE 0
#define PATCAT_PAGE 1
#define REVERB_PAGE 2
#define CHORUS_PAGE 3
#define BENDMOD_PAGE 4
#define SYNTH_PAGE 5
#define PATCHES_PAGE0 101
#define BACKBUTTON_TAG 200
byte prevPressedTag = 0;
byte gCurrentPage = MAIN_PAGE;
byte mono = 0;
void setup()
{
//GD.begin();
// Special GD.begin() code to handle calibration of rotated screen
GD.begin(~(GD_STORAGE | GD_CALIBRATE));
GD.wr(REG_ROTATE, 0);
if (EEPROM.read(0) != 0x7c)
{
GD.self_calibrate();
for (int i = 0; i < 24; i++)
EEPROM.write(1 + i, GD.rd(REG_TOUCH_TRANSFORM_A + i));
EEPROM.write(0, 0x7c); // is written!
}
else
{
for (int i = 0; i < 24; i++)
GD.wr(REG_TOUCH_TRANSFORM_A + i, EEPROM.read(1 + i));
}
// define pin modes for MIDI in/out (rx, tx):
pinMode(midiRxPin, INPUT);
pinMode(midiTxPin, OUTPUT);
// set the data rate for the SoftwareSerial port (MIDI rate)
midiSerial.begin(31250);
midiNoteOn(3, 60, 70);
delay(200);
midiNoteOn(3, 60, 0);
}
void loop()
{
// Get input
GD.get_inputs();
byte pressedTag = GD.inputs.tag;
GD.ClearColorRGB(0 == pressedTag ? 0x103000 : 0x106000);
GD.Clear();
GD.cmd_text(0, 0, 30, 0, "GrooveBuddy");
if (MAIN_PAGE == gCurrentPage)
DoMainPage(pressedTag);
else if (PATCAT_PAGE == gCurrentPage)
DoPatchCategoryPage(pressedTag);
else if (REVERB_PAGE == gCurrentPage)
DoReverbPage(pressedTag);
else if (CHORUS_PAGE == gCurrentPage)
DoChorusPage(pressedTag);
else if (BENDMOD_PAGE == gCurrentPage)
DoBendModPage(pressedTag);
else if (SYNTH_PAGE == gCurrentPage)
DoSynthPage(pressedTag);
else if (gCurrentPage >= PATCHES_PAGE0 && gCurrentPage <= (PATCHES_PAGE0 + 21))
DoPatchesPage(pressedTag);
prevPressedTag = pressedTag;
}
// Show and process input for "Main" page
void DoMainPage(byte pressedTag)
{
GD.Tag(PATCAT_PAGE);
GD.cmd_button(20, 60, 160, 48, 28, PATCAT_PAGE == pressedTag ? OPT_FLAT : 0, "Patches");
GD.Tag(REVERB_PAGE);
GD.cmd_button(20, 120, 160, 48, 28, REVERB_PAGE == pressedTag ? OPT_FLAT : 0, "Reverb");
GD.Tag(CHORUS_PAGE);
GD.cmd_button(20, 180, 160, 48, 28, CHORUS_PAGE == pressedTag ? OPT_FLAT : 0, "Chorus");
GD.Tag(BENDMOD_PAGE);
GD.cmd_button(260, 60, 160, 48, 28, BENDMOD_PAGE == pressedTag ? OPT_FLAT : 0, "Bend + Mod");
GD.Tag(SYNTH_PAGE);
GD.cmd_button(260, 120, 160, 48, 28, SYNTH_PAGE == pressedTag ? OPT_FLAT : 0, "Synth");
GD.Tag(20);
GD.cmd_button(260, 180, 100, 44, 28, 20 == pressedTag ? OPT_FLAT : 0, (1 == mono) ? "Mono" : "Poly");
GD.swap(); // swap buffers
if (pressedTag >= PATCAT_PAGE && pressedTag <= SYNTH_PAGE)
{
gCurrentPage = pressedTag;
prevPressedTag = 0;
delay(100);
}
else if (20 == pressedTag)
{
// Toggle mono/poly button
if (0 == mono)
{
// Send "Mono" CC
midiControlChange(3, 126, 1);
mono = 1;
}
else
{
// Send "Poly" CC
midiControlChange(3, 127, 0);
mono = 0;
}
delay(100);
}
}
// Show and process input for "Patch Category" page
void DoPatchCategoryPage(byte pressedTag)
{
// Generate display of patch category buttons
for (int i = 0; i < 22; i++)
{
GD.Tag(i + 1);
int x = (i / 5) * 96;
int y = 48 + (i % 5) * 45;
GD.cmd_button(x, y, 92, 42, 28, (i + 1) == pressedTag ? OPT_FLAT : 0, patchCategories[i]);
}
GD.Tag(BACKBUTTON_TAG);
GD.cmd_button(400, 0, 80, 42, 28, BACKBUTTON_TAG == pressedTag ? OPT_FLAT : 0, "Back");
GD.swap(); // swap buffers
if (BACKBUTTON_TAG == pressedTag)
{
gCurrentPage = 0;
delay(100);
return;
}
if (pressedTag >= 1 && pressedTag <= 22)
{
// Copy the relevant page of patch info to the SRAM copy
int pageNumber = pressedTag - 1;
memcpy_P(¤tPagePatchInfo, &patchInfo[20 * pageNumber], sizeof(PATCHINFO) * 20);
// Set current page to a "patch page"
gCurrentPage = PATCHES_PAGE0 + pageNumber;
prevPressedTag = 0;
}
}
// Show and process input for "Synth Patches" page
void DoPatchesPage(byte pressedTag)
{
GD.cmd_text(240, 0, 28, 0, patchCategories[gCurrentPage - PATCHES_PAGE0]);
// Uses the copy of the "current page patch info" in local SRAM
for (int i = 0; i < 20; i++)
{
GD.Tag(i + 1);
int x = (i / 5) * 120;
int y = 48 + (i % 5) * 45;
GD.cmd_button(x, y, 116, 42, 27, (i + 1) == pressedTag ? OPT_FLAT : 0, currentPagePatchInfo[i].name);
}
GD.Tag(BACKBUTTON_TAG);
GD.cmd_button(400, 0, 80, 42, 28, BACKBUTTON_TAG == pressedTag ? OPT_FLAT : 0, "Back");
GD.swap(); // swap buffers
if (BACKBUTTON_TAG == pressedTag)
{
gCurrentPage = PATCAT_PAGE;
delay(100);
}
else if (pressedTag >= 1 && pressedTag <= 20 && pressedTag != prevPressedTag)
{
// User pressed a patch button, so select the relevant patch
int index = pressedTag - 1;
if (currentPagePatchInfo[index].bank > 0)
{
midiPatchSelect(currentPagePatchInfo[index].bank, currentPagePatchInfo[index].pc - 1);
midiNoteOn(3, 60, 70);
delay(500);
midiNoteOn(3, 60, 0);
}
}
}
// Show and process input for "Reverb" page
void DoReverbPage(byte pressedTag)
{
GD.Tag(1);
GD.cmd_button(10, 48, 100, 44, 28, 1 == pressedTag ? OPT_FLAT : 0, "Room 1");
GD.Tag(2);
GD.cmd_button(10, 96, 100, 44, 28, 2 == pressedTag ? OPT_FLAT : 0, "Room 2");
GD.Tag(3);
GD.cmd_button(10, 144, 100, 44, 28, 3 == pressedTag ? OPT_FLAT : 0, "Room 3");
GD.Tag(6);
GD.cmd_button(10, 192, 100, 44, 28, 6 == pressedTag ? OPT_FLAT : 0, "Plate");
GD.Tag(4);
GD.cmd_button(120, 48, 100, 44, 28, 4 == pressedTag ? OPT_FLAT : 0, "Hall 1");
GD.Tag(5);
GD.cmd_button(120, 96, 100, 44, 28, 5 == pressedTag ? OPT_FLAT : 0, "Hall 2");
GD.Tag(7);
GD.cmd_button(120, 144, 100, 44, 28, 7 == pressedTag ? OPT_FLAT : 0, "Delay");
GD.Tag(8);
GD.cmd_button(120, 192, 100, 44, 28, 8 == pressedTag ? OPT_FLAT : 0, "Pan Delay");
GD.Tag(BACKBUTTON_TAG);
GD.cmd_button(400, 0, 80, 44, 28, BACKBUTTON_TAG == pressedTag ? OPT_FLAT : 0, "Back");
GD.swap(); // swap buffers
if (BACKBUTTON_TAG == pressedTag)
{
gCurrentPage = MAIN_PAGE;
delay(100);
}
else if (pressedTag >= 1 && pressedTag <= 8 && pressedTag != prevPressedTag)
{
/*
byte data[20] = { 0x41, 0x10, 0x00, 0x18, 0x12, 0x40, 0x01, 0x30, 0x00, 0x00 };
data[8] = pressedTag - 1;
byte checksum = GetRolandChecksum(data+5, 4);
data[9] = checksum;
midiSysex(data, 10);
*/
midiSysEx(0x01, 0x30, pressedTag - 1);
midiNoteOn(3, 60, 70);
delay(500);
midiNoteOn(3, 60, 0);
}
}
// Show and process input for "Chorus" page
void DoChorusPage(byte pressedTag)
{
static uint16_t value = 0;
if (20 == GD.inputs.track_tag & 0xFF)
value = GD.inputs.track_val;
GD.Tag(11);
GD.cmd_button(10, 48, 100, 44, 28, 11 == pressedTag ? OPT_FLAT : 0, "Chorus 1");
GD.Tag(12);
GD.cmd_button(10, 96, 100, 44, 28, 12 == pressedTag ? OPT_FLAT : 0, "Chorus 2");
GD.Tag(13);
GD.cmd_button(10, 144, 100, 44, 28, 13 == pressedTag ? OPT_FLAT : 0, "Chorus 3");
GD.Tag(14);
GD.cmd_button(10, 192, 100, 44, 28, 14 == pressedTag ? OPT_FLAT : 0, "Chorus 4");
GD.Tag(15);
GD.cmd_button(120, 48, 100, 44, 28, 15 == pressedTag ? OPT_FLAT : 0, "FB Chorus");
GD.Tag(16);
GD.cmd_button(120, 96, 100, 44, 28, 16 == pressedTag ? OPT_FLAT : 0, "Flanger");
GD.Tag(17);
GD.cmd_button(120, 144, 100, 44, 28, 17 == pressedTag ? OPT_FLAT : 0, "Sht Delay");
GD.Tag(18);
GD.cmd_button(120, 192, 100, 44, 28, 18 == pressedTag ? OPT_FLAT : 0, "S Delay FB");
// "Depth" slider
GD.Tag(20);
GD.cmd_slider(300, 48, 20, 200, 0, value, 65535);
GD.cmd_track(300, 48, 20, 200, 20);
// Back button
GD.Tag(BACKBUTTON_TAG);
GD.cmd_button(400, 0, 80, 44, 28, BACKBUTTON_TAG == pressedTag ? OPT_FLAT : 0, "Back");
GD.swap(); // swap buffers
if (BACKBUTTON_TAG == pressedTag)
{
gCurrentPage = MAIN_PAGE;
delay(100);
}
else if (pressedTag >= 11 && pressedTag <= 18 && pressedTag != prevPressedTag)
{
midiSysEx(0x01, 0x38, pressedTag - 11);
midiNoteOn(3, 60, 70);
delay(500);
midiNoteOn(3, 60, 0);
}
else if (20 == GD.inputs.track_tag & 0xFF)
{
// Chorus send level (0 to 127)
midiControlChange(3, 93, 127 - (value / 512));
delay(100);
}
}
// Show and process input for "Bend+Mod" page
void DoBendModPage(byte pressedTag)
{
static uint16_t bendRange = 32768; //
static uint16_t bendCutoff = 32768; // 50%
static uint16_t modRate = 32768; // 50%
static uint16_t modPitch = 2560; // 10 / 127
static uint16_t modCutoff = 0;
static uint16_t modVol = 0;
GD.cmd_text(20, 40, 28, 0, "Bend");
GD.cmd_text(240, 40, 28, 0, "Mod");
//GD.cmd_text(20, 248, 27, 0, "Pitch");
//GD.cmd_text(84, 248, 27, 0, "Cutoff");
char s[20];
sprintf(s, "%u", (65535 - bendRange) / 2730);
GD.cmd_text(20, 248, 27, 0, s);
sprintf(s, "%u", (65535 - bendCutoff) / 512);
GD.cmd_text(84, 248, 27, 0, s);
GD.cmd_text(228, 248, 27, 0, "Rate");
GD.cmd_text(288, 248, 27, 0, "Pitch");
GD.cmd_text(348, 248, 27, 0, "Cutoff");
GD.cmd_text(408, 248, 27, 0, "Volume");
// "Bend Pitch Range" slider
GD.Tag(20);
GD.cmd_slider(32, 80, 20, 160, 0, bendRange, 65535);
GD.cmd_track(32, 80, 20, 160, 20);
// "Bend Cutoff Range" slider
GD.Tag(21);
GD.cmd_slider(96, 80, 20, 160, 0, bendCutoff, 65535);
GD.cmd_track(96, 80, 20, 160, 21);
// "Mod Rate" slider
GD.Tag(22);
GD.cmd_slider(240, 80, 20, 160, 0, modRate, 65535);
GD.cmd_track(240, 80, 20, 160, 22);
// "Mod Pitch" slider
GD.Tag(23);
GD.cmd_slider(300, 80, 20, 160, 0, modPitch, 65535);
GD.cmd_track(300, 80, 20, 160, 23);
// "Mod Cutoff" slider
GD.Tag(24);
GD.cmd_slider(360, 80, 20, 160, 0, modCutoff, 65535);
GD.cmd_track(360, 80, 20, 160, 24);
// "Mod Vol" slider
GD.Tag(25);
GD.cmd_slider(420, 80, 20, 160, 0, modVol, 65535);
GD.cmd_track(420, 80, 20, 160, 25);
// Back button
GD.Tag(BACKBUTTON_TAG);
GD.cmd_button(400, 0, 80, 44, 28, BACKBUTTON_TAG == pressedTag ? OPT_FLAT : 0, "Back");
GD.swap(); // swap buffers
if (BACKBUTTON_TAG == pressedTag)
{
gCurrentPage = MAIN_PAGE;
delay(100);
}
else
{
byte tt = (GD.inputs.track_tag & 0xFF);
if (20 == tt)
{
// Bend pitch range (40 to 87, default = 64)
bendRange = GD.inputs.track_val;
midiRPN(3, 0, 0, ((65535 - bendRange) / 2730)); // 1365 = 65536 / 48
delay(50);
}
else if (21 == tt)
{
// Bend filter cutoff (0 to 127, default = 64)
bendCutoff = GD.inputs.track_val;
midiSysEx(0x24, 0x11, (byte)((65535 - bendCutoff) / 512));
}
else if (22 == tt)
{
// Mod rate (0 to 127, default = 64)
modRate = GD.inputs.track_val;
midiSysEx(0x24, 0x03, (byte)((65535 - modRate) / 512));
}
else if (23 == tt)
{
// Mod pitch (0 to 127, default = 10)
modPitch = GD.inputs.track_val;
midiSysEx(0x24, 0x04, (byte)((65535 - modPitch) / 512));
}
else if (24 == tt)
{
// Mod cutoff (0 to 127, default = 0)
modCutoff = GD.inputs.track_val;
midiSysEx(0x24, 0x05, (byte)((65535 - modCutoff) / 512));
}
else if (25 == tt)
{
// Mod vol (0 to 127, default = 0)
modVol = GD.inputs.track_val;
midiSysEx(0x24, 0x06, (byte)((65535 - modVol) / 512));
}
}
}
// Show and process input for "Synth" page
void DoSynthPage(byte pressedTag)
{
static uint16_t vibRate = 32767;
static uint16_t vibDepth = 32767;
static uint16_t vibDelay = 32767;
static uint16_t envAttack = 32767;
static uint16_t envDecay = 32767;
static uint16_t envRelease = 32767;
GD.cmd_text(20, 40, 28, 0, "Vibrato");
GD.cmd_text(240, 40, 28, 0, "Envelope");
GD.cmd_text(20, 248, 27, 0, "Rate");
GD.cmd_text(84, 248, 27, 0, "Depth");
GD.cmd_text(148, 248, 27, 0, "Delay");
GD.cmd_text(228, 248, 27, 0, "Attack");
GD.cmd_text(288, 248, 27, 0, "Decay");
GD.cmd_text(348, 248, 27, 0, "Release");
// "Vibrato rate" slider
GD.Tag(20);
GD.cmd_slider(32, 80, 20, 160, 0, vibRate, 65535);
GD.cmd_track(32, 80, 20, 160, 20);
// "Vibrato depth" slider
GD.Tag(21);
GD.cmd_slider(96, 80, 20, 160, 0, vibDepth, 65535);
GD.cmd_track(96, 80, 20, 160, 21);
// "Vibrato delay" slider
GD.Tag(22);
GD.cmd_slider(160, 80, 20, 160, 0, vibDelay, 65535);
GD.cmd_track(160, 80, 20, 160, 22);
// "Env Attack" slider
GD.Tag(23);
GD.cmd_slider(240, 80, 20, 160, 0, envAttack, 65535);
GD.cmd_track(240, 80, 20, 160, 23);
// "Env Decay" slider
GD.Tag(24);
GD.cmd_slider(300, 80, 20, 160, 0, envDecay, 65535);
GD.cmd_track(300, 80, 20, 160, 24);
// "Env Release" slider
GD.Tag(25);
GD.cmd_slider(360, 80, 20, 160, 0, envRelease, 65535);
GD.cmd_track(360, 80, 20, 160, 25);
// Back button
GD.Tag(BACKBUTTON_TAG);
GD.cmd_button(400, 0, 80, 44, 28, BACKBUTTON_TAG == pressedTag ? OPT_FLAT : 0, "Back");
GD.swap(); // swap buffers
if (BACKBUTTON_TAG == pressedTag)
{
gCurrentPage = MAIN_PAGE;
delay(100);
}
else
{
byte tt = (GD.inputs.track_tag & 0xFF);
if (20 == tt)
{
// Vibrato rate (0 to 127, def = 64)
vibRate = GD.inputs.track_val;
midiNRPN(3, 0x01, 0x08, ((65535 - vibRate) / 512));
delay(50);
}
else if (21 == tt)
{
// Vibrato depth (0 to 127, def = 64)
vibDepth = GD.inputs.track_val;
midiNRPN(3, 0x01, 0x09, ((65535 - vibDepth) / 512));
}
else if (22 == tt)
{
// Vibrato delay (0 to 127, def = 64)
vibDelay = GD.inputs.track_val;
midiNRPN(3, 0x01, 0x0A, ((65535 - vibDelay) / 512));
}
else if (23 == tt)
{
// Envelope attack time (0 to 127, def = 64)
envAttack = GD.inputs.track_val;
midiNRPN(3, 0x01, 0x63, ((65535 - envAttack) / 512));
}
else if (24 == tt)
{
// Envelope decay time (0 to 127, def = 64)
envDecay = GD.inputs.track_val;
midiNRPN(3, 0x01, 0x64, ((65535 - envDecay) / 512));
}
else if (25 == tt)
{
// Envelope release time (0 to 127, def = 64)
envRelease = GD.inputs.track_val;
midiNRPN(3, 0x01, 0x66, ((65535 - envRelease) / 512));
}
}
}
// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void midiNoteOn(byte channel, byte pitch, byte velocity)
{
// Serial.write(cmd);
// Serial.write(pitch);
// Serial.write(velocity);
midiSerial.write(0x90 | channel);
midiSerial.write(pitch);
midiSerial.write(velocity);
}
// Sends a MIDI control change
void midiControlChange(byte channel, byte ccNum, byte value)
{
// Serial.write(cmd);
// Serial.write(pitch);
// Serial.write(velocity);
midiSerial.write(0xB0 | channel);
midiSerial.write(ccNum);
midiSerial.write(value);
delay(20);
}
// Sends a MIDI RPN change
void midiRPN(byte channel, byte cc100, byte cc101, byte value)
{
midiSerial.write(0xB0 | channel);
midiSerial.write(0x64);
midiSerial.write(cc100);
//midiSerial.write(0xB0 | channel);
midiSerial.write(0x65);
midiSerial.write(cc101);
//midiSerial.write(0xB0 | channel);
midiSerial.write(0x06);
midiSerial.write(value);
// Set RPN to null so that further spuriuous controller messages are ignored
midiSerial.write(0x64);
midiSerial.write(0x7F);
midiSerial.write(0x65);
midiSerial.write(0x7F);
delay(50);
}
// Sends a MIDI RPN change
void midiNRPN(byte channel, byte msb, byte lsb, byte value)
{
midiSerial.write(0xB0 | channel);
midiSerial.write(0x63);
midiSerial.write(msb);
//midiSerial.write(0xB0 | channel);
midiSerial.write(0x62);
midiSerial.write(lsb);
//midiSerial.write(0xB0 | channel);
midiSerial.write(0x06);
midiSerial.write(value);
// Set RPN to null so that further spuriuous controller messages are ignored
midiSerial.write(0x62);
midiSerial.write(0x7F);
midiSerial.write(0x63);
midiSerial.write(0x7F);
delay(50);
}
// Sends a MIDI control change
void midiPatchSelect(byte bank, byte patch)
{
// Serial.write(cmd);
// Serial.write(pitch);
// Serial.write(velocity);
// Write bank in CC00 and CC32
midiSerial.write(0xB3);
midiSerial.write(byte(0));
midiSerial.write(bank);
delay(5);
midiSerial.write(0xB3);
midiSerial.write(32);
midiSerial.write(byte(0));
delay(5);
// Write PC
midiSerial.write(0xC3);
midiSerial.write(patch);
delay(40);
}
/*
// Send sysex data
void midiSysex(byte *data, int length)
{
// Sysex starts wth 0xF0, ends with 0xF7
midiSerial.write(0xF0);
for (int i = 0; i < length; i++)
midiSerial.write(data[i]);
midiSerial.write(0xF7);
delay(50);
}
*/
// Send sysex data
void midiSysEx(byte addr1, byte addr2, byte value)
{
byte data[20] = { 0x41, 0x10, 0x00, 0x18, 0x12, 0x40, 0x00, 0x00, 0x00, 0x00 };
data[6] = addr1;
data[7] = addr2;
data[8] = value;
byte checksum = GetRolandChecksum(data+5, 4);
data[9] = checksum;
// Sysex starts wth 0xF0, ends with 0xF7
midiSerial.write(0xF0);
for (int i = 0; i < 10; i++)
midiSerial.write(data[i]);
midiSerial.write(0xF7);
delay(50);
}
// calculate Roland sysex checksum
byte GetRolandChecksum(byte* data, int length)
{
// Roland sysex checksum = 128 - (data sum % 128)
int sum = 0;
for (int i = 0; i < length; i++)
sum += data[i];
int rem = sum % 128;
int checksum = (128 - rem);
//int check = sum + checksum;
return byte(checksum);
}
/*
Notes:
1. Reverb depth = CC 91 (eg: 0xB3 91 value)
2. Chorsu depth = CC 93 (eg: 0xB3 93 value)
*/