-
Notifications
You must be signed in to change notification settings - Fork 82
/
ls_midi.ino
2936 lines (2721 loc) · 82.7 KB
/
ls_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
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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************** ls_midi: LinnStrument MIDI ************************************
Copyright 2023 Roger Linn Design (https://www.rogerlinndesign.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
***************************************************************************************************
These are the MIDI functions for the LinnStrument
**************************************************************************************************/
#include "ls_bytebuffer.h"
#include "ls_midi.h"
#define MAX_SYSEX_LENGTH 256
// first byte is the status byte, the two following bytes are the data bytes and
// the channel will be encoded in the 4th byte if applicable
byte midiMessage[4];
byte midiMessageBytes = 0; // the number of bytes that are expected in the message that is being constituted
byte midiMessageIndex = 0; // the message array index of the message that is being constituted
byte midiCellColCC = 0;
byte midiCellRowCC = 0;
ByteBuffer<4096> midiOutQueue;
ByteBuffer<MAX_SYSEX_LENGTH * 2> sysexOutQueue;
byte midiSysExBuffer[MAX_SYSEX_LENGTH];
short midiSysExLength = -1;
// MIDI Clock State
const int32_t MIDI_CLOCK_UNIT = 2500000; // 1000000 ( microsecond) * 60 ( minutes - bpm) / 24 ( frames per beat)
const int32_t MIDI_CLOCK_MIN_DELTA = 6756; // maximum 370 BPM (taking a little margin to allow for clock fluctuations)
const byte MIDI_CLOCK_SAMPLES = 6;
const int32_t FXD4_MIDI_CLOCK_SAMPLES = FXD4_FROM_INT(MIDI_CLOCK_SAMPLES);
enum MidiClock {
midiClockOff,
midiClockStart,
midiClockOn
};
MidiClock midiClockStatus = midiClockOff; // indicates whether the MIDI clock transport is running
unsigned long lastMidiClockTime = 0; // the last time we received a MIDI clock message in micros
int32_t fxd4MidiTempoAverage = fxd4CurrentTempo; // the current average of the MIDI clock tempo, in fixes precision
byte midiClockMessageCount = 0; // the number of MIDI clock messages we've received, from 1 to 24, with 0 meaning none has been received yet
byte initialMidiClockMessageCount = 0; // the first MIDI clock messages, counted until the minimum number of samples have been received
bool receivedSongPositionPointer = false; // tracks whether a song position pointer message was received before the MIDI clock start
bool standaloneMidiClockRunning = false; // indicates whether the MIDI Clock is sending data in a standalone fashion, without sequencer
byte lastRpnMsb = 127;
byte lastRpnLsb = 127;
byte lastNrpnMsb = 127;
byte lastNrpnLsb = 127;
byte lastDataMsb = 0;
byte lastDataLsb = 0;
boolean isMidiUsingDIN() {
return Global.midiIO == 0;
}
void applyMidiIo() {
// do not reconfigure the serial speeds when device update mode is active
// the MIDI IO settings will be applied when OS update mode is turned off
if (Device.serialMode) {
return;
}
if (isMidiUsingDIN()) {
digitalWrite(36, LOW); // Set LOW for DIN jacks
Serial.begin(31250); // set serial port at MIDI DIN speed 31250
Serial.flush(); // clear the serial port
}
else {
digitalWrite(36, HIGH); // Set HIGH for USB
Serial.begin(115200); // set serial port at fastest speed 115200
Serial.flush(); // clear the serial port
}
applyMidiInterval();
}
void handleMidiInput(unsigned long nowMicros) {
// handle turning off the MIDI clock led after minimum 30ms
if (isSyncedToMidiClock() &&
controlButton != GLOBAL_SETTINGS_ROW &&
tempoLedOn != 0 &&
calcTimeDelta(nowMicros, tempoLedOn) > LED_FLASH_DELAY) {
tempoLedOn = 0;
clearLed(0, GLOBAL_SETTINGS_ROW);
}
// if no serial data is available, return
if (Serial.available() <= 0) {
return;
}
// get the next byte from the serial bus
byte d = Serial.read();
// check if we're dealing with a status byte
if ((d & B10000000) == B10000000) {
memset(midiMessage, 0, 4);
midiMessage[0] = d;
midiMessageBytes = 0;
midiMessageIndex = 0;
switch (d) {
case MIDIActiveSensing:
midiMessageBytes = 1;
midiMessageIndex = 1;
// indicate MIDI activity sensing in test mode
if (operatingMode == modeManufacturingTest) {
setLed(NUMCOLS - 1, 2, COLOR_GREEN, cellOn);
}
break;
case MIDIStart:
case MIDIContinue:
midiMessageBytes = 1;
midiMessageIndex = 1;
if (!receivedSongPositionPointer) {
midiClockMessageCount = 1;
setSequencerSongPositionPointer(0);
}
midiClockStatus = midiClockStart;
fxd4MidiTempoAverage = fxd4CurrentTempo;
lastMidiClockTime = 0;
initialMidiClockMessageCount = 0;
resetClockAdvancement(nowMicros);
break;
case MIDIStop:
midiMessageBytes = 1;
midiMessageIndex = 1;
sequencersTurnOff(false);
midiClockStatus = midiClockOff;
midiClockMessageCount = 0;
lastMidiClockTime = 0;
initialMidiClockMessageCount = 0;
resetClockAdvancement(nowMicros);
break;
case MIDISongPositionPointer:
midiMessageBytes = 3;
midiMessageIndex = 1;
lastMidiClockTime = 0;
break;
case MIDITimingClock:
{
midiMessageBytes = 1;
midiMessageIndex = 1;
if (midiClockStatus != midiClockOff) {
if (lastMidiClockTime > 0) {
unsigned long clockDelta = calcTimeDelta(nowMicros, lastMidiClockTime);
if (clockDelta != 0 && clockDelta > MIDI_CLOCK_MIN_DELTA) {
fxd4MidiTempoAverage -= FXD4_DIV(fxd4MidiTempoAverage, FXD4_MIDI_CLOCK_SAMPLES);
fxd4MidiTempoAverage += FXD4_DIV(FXD4_FROM_INT(MIDI_CLOCK_UNIT / clockDelta), FXD4_MIDI_CLOCK_SAMPLES);
if (initialMidiClockMessageCount < MIDI_CLOCK_SAMPLES) {
initialMidiClockMessageCount += 1;
}
else {
fxd4CurrentTempo = fxd4MidiTempoAverage;
}
}
}
lastMidiClockTime = nowMicros;
// differentiate between the first clock message right after the start message
// and all the other ones
if (midiClockStatus == midiClockStart) {
midiClockStatus = midiClockOn;
boolean clockUpdated = checkUpdateClock(nowMicros);
sequencersTurnOn();
if (clockUpdated) {
performCheckAdvanceArpeggiator();
performCheckAdvanceSequencer();
}
}
else {
midiClockMessageCount += 1;
}
// wrap around the MIDI clock message count
if (midiClockMessageCount == 25) {
midiClockMessageCount = 1;
}
// flash the global settings led green on tempo, unless it's currently pressed down
if (controlButton != GLOBAL_SETTINGS_ROW && midiClockMessageCount == 1) {
setLed(0, GLOBAL_SETTINGS_ROW, COLOR_GREEN, cellOn);
tempoLedOn = nowMicros;
}
// play the next arpeggiator and sequencer steps if needed
if (checkUpdateClock(nowMicros)) {
performCheckAdvanceArpeggiator();
performCheckAdvanceSequencer();
}
// flash the tempo led in the global display when it is on
updateGlobalSettingsFlashTempo(nowMicros);
}
break;
}
case MIDISystemExclusive:
midiSysExLength = 0;
break;
case MIDIEndOfExclusive:
if (Device.midiThrough) {
sysexOutQueue.push(MIDISystemExclusive);
for (short i = 0; i < midiSysExLength; ++i) {
sysexOutQueue.push(midiSysExBuffer[i]);
}
sysexOutQueue.push(MIDIEndOfExclusive);
}
midiSysExLength = -1;
break;
case MIDIReset:
case MIDIUndefined1:
case MIDIUndefined2:
case MIDIUndefined3:
case MIDIUndefined4:
midiMessageBytes = 1;
midiMessageIndex = 1;
break;
default:
{
byte channelStatus = (d & B11110000); // remove channel nibble
switch (channelStatus) {
case MIDINoteOff:
case MIDINoteOn:
case MIDIPolyphonicPressure:
case MIDIControlChange:
case MIDIPitchBend:
midiMessage[0] = channelStatus;
midiMessage[3] = (d & B00001111);
midiMessageBytes = 3;
midiMessageIndex = 1;
break;
case MIDIProgramChange:
case MIDIChannelPressure:
midiMessage[0] = channelStatus;
midiMessage[3] = (d & B00001111);
midiMessageBytes = 2;
midiMessageIndex = 1;
break;
}
break;
}
}
}
// constitute the sysex message
else if (midiSysExLength != -1) {
if (midiSysExLength < MAX_SYSEX_LENGTH) {
midiSysExBuffer[midiSysExLength++] = d;
}
}
// otherwise this is a data byte
else if (midiMessageBytes) {
midiMessage[midiMessageIndex++] = d;
}
// we have all the bytes we need for the message that is being constituted
if (midiMessageBytes && midiMessageIndex == midiMessageBytes) {
MIDIStatus midiStatus = (MIDIStatus)midiMessage[0];
byte midiChannel = midiMessage[3];
byte midiData1 = midiMessage[1];
byte midiData2 = midiMessage[2];
if (Device.midiThrough) {
queueMidiMessage(midiStatus, midiData1, midiData2, midiChannel);
}
int split = determineSplitForChannel(midiChannel);
if (midiStatus == MIDISongPositionPointer) {
receivedSongPositionPointer = true;
}
else {
receivedSongPositionPointer = false;
}
switch (midiStatus) {
case MIDISongPositionPointer:
{
unsigned pos = midiData2 << 7 | midiData1;
midiClockMessageCount = (pos * 6) % 24 + 1;
setSequencerSongPositionPointer(pos);
break;
}
case MIDINoteOn:
{
// velocity 0 means the same as note off, so don't handle it further in this case
if (midiData2 > 0) {
if (split != -1 && (split == Global.currentPerSplit || Global.splitActive) && !isVisibleSequencerForSplit(split)) {
// attempts to highlight the exact cell that belongs to a midi note and channel
if (!highlightExactNoteCell(split, midiData1, midiChannel)) {
// if there's not one exact location, we highlight all cells that could correspond to the note number
highlightPossibleNoteCells(split, midiData1);
}
}
break;
}
// purposely fall-through in case of velocity 0
}
case MIDINoteOff:
{
if (split != -1 && (split == Global.currentPerSplit || Global.splitActive) && !isVisibleSequencerForSplit(split)) {
// attempts to reset the exact cell that belongs to a midi note and channel
if (!resetExactNoteCell(split, midiData1, midiChannel)) {
// if there's not one exact location, we reset all cells that could correspond to the note number
resetPossibleNoteCells(split, midiData1);
}
}
break;
}
case MIDIProgramChange:
{
if (split != -1) {
midiPreset[split] = midiData1;
if (displayMode == displayPreset) {
updateDisplay();
}
}
break;
}
case MIDIControlChange:
{
switch (midiData1) {
case 6:
// if an NRPN or RPN parameter was selected, start constituting the data
// otherwise control the fader of MIDI CC 6
if ((lastRpnMsb != 127 || lastRpnLsb != 127) ||
(lastNrpnMsb != 127 || lastNrpnLsb != 127)) {
lastDataMsb = midiData2;
break;
}
case 1:
case 2:
case 3:
case 4:
case 5:
case 7:
case 8:
if (split != -1) {
unsigned short ccForFader = Split[split].ccForFader[midiData1-1];
ccFaderValues[split][ccForFader] = midiData2;
if ((displayMode == displayNormal && Split[split].ccFaders) ||
displayMode == displayVolume) {
updateDisplay();
}
}
break;
case 9:
if (userFirmwareActive && midiChannel < NUMROWS && (midiData2 == 0 || midiData2 == 1)) {
userFirmwareSlideMode[midiChannel] = midiData2;
}
break;
case 10:
if (userFirmwareActive && midiChannel < NUMROWS && (midiData2 == 0 || midiData2 == 1)) {
userFirmwareXActive[midiChannel] = midiData2;
}
break;
case 11:
if (userFirmwareActive && midiChannel < NUMROWS && (midiData2 == 0 || midiData2 == 1)) {
userFirmwareYActive[midiChannel] = midiData2;
}
break;
case 12:
if (userFirmwareActive && midiChannel < NUMROWS && (midiData2 == 0 || midiData2 == 1)) {
userFirmwareZActive[midiChannel] = midiData2;
}
break;
case 13:
if (userFirmwareActive) {
unsigned long rate = midiData2 * 1000;
if (!Device.operatingLowPower || rate > LOWPOWER_MIDI_DECIMATION) {
midiDecimateRate = rate;
}
}
break;
case 20:
if (midiData2 < NUMCOLS) {
midiCellColCC = midiData2;
}
break;
case 21:
if (midiData2 < NUMROWS) {
midiCellRowCC = midiData2;
}
break;
case 22:
if (displayMode == displayNormal || displayMode == displayCustomLedsEditor) {
byte layer = LED_LAYER_CUSTOM1;
// we light the LEDs of user firmware mode in a dedicated custom layer
// this will be cleared when switching back to regular firmware mode
if (userFirmwareActive) {
layer = LED_LAYER_CUSTOM2;
}
if (midiData2 <= COLOR_PINK && midiData2 != COLOR_OFF) {
setLed(midiCellColCC, midiCellRowCC, midiData2, cellOn, layer);
}
else {
setLed(midiCellColCC, midiCellRowCC, COLOR_OFF, cellOff, layer);
}
checkRefreshLedColumn(micros());
}
break;
case 23:
if (midiData2 < LED_PATTERNS) {
storeCustomLedLayer(midiData2);
storeSettings();
}
break;
case 24:
if (midiData2 < LED_PATTERNS) {
clearStoredCustomLedLayer(midiData2);
storeSettings();
}
break;
case 38:
if (lastRpnMsb != 127 || lastRpnLsb != 127) {
lastDataLsb = midiData2;
receivedRpn(midiChannel, (lastRpnMsb<<7)+lastRpnLsb, (lastDataMsb<<7)+lastDataLsb);
break;
}
if (lastNrpnMsb != 127 || lastNrpnLsb != 127) {
lastDataLsb = midiData2;
receivedNrpn((lastNrpnMsb<<7)+lastNrpnLsb, (lastDataMsb<<7)+lastDataLsb, midiChannel);
break;
}
case 98:
lastNrpnLsb = midiData2;
break;
case 99:
lastNrpnMsb = midiData2;
break;
case 100:
lastRpnLsb = midiData2;
// resetting RPN numbers also resets NRPN numbers
if (lastRpnLsb == 127 && lastRpnMsb == 127) {
lastNrpnLsb = 127;
lastNrpnMsb = 127;
}
break;
case 101:
lastRpnMsb = midiData2;
break;
}
}
default:
// don't handle other MIDI messages
break;
}
// reset the message
memset(midiMessage, 0, 4);
midiMessageBytes = 0;
midiMessageIndex = 0;
}
}
signed char determineSplitForChannel(byte channel) {
if (channel > 15) {
return -1;
}
for (byte split = LEFT; split <= RIGHT; ++split) {
switch (Split[split].midiMode) {
case oneChannel:
if (Split[split].midiChanMain-1 == channel) {
return split;
}
break;
case channelPerNote:
if (Split[split].midiChanSet[channel] == true) {
return split;
}
break;
case channelPerRow:
if (calculateRowPerChannelRow(split, channel) < NUMROWS) {
return split;
}
break;
}
}
return -1;
}
inline boolean inRange(int value, int lower, int upper) {
return value >= lower && value <= upper;
}
void receivedRpn(byte midiChannel, int parameter, int value) {
switch (parameter) {
// Pitch Bend Sensitivity
case 0:
applyBendRange(Split[LEFT], constrain(value >> 7, 1, 96));
applyBendRange(Split[RIGHT], constrain(value >> 7, 1, 96));
break;
case 6:
// support for activating MPE mode with the standard MPE message
if (midiChannel == 0 || midiChannel == 15) {
byte split = LEFT;
if (midiChannel == 15) {
split = RIGHT;
}
int polyphony = value >> 7;
if (polyphony == 0) {
disableMpe(split);
}
else {
enableMpe(split, midiChannel + 1, polyphony);
}
updateDisplay();
}
break;
}
updateDisplay();
}
void receivedNrpn(int parameter, int value, int channel) {
byte split = LEFT;
if (parameter >= 100 && parameter < 200) {
parameter -= 100;
split = RIGHT;
}
switch (parameter) {
// Split MIDI Mode
case 0:
if (inRange(value, 0, 2)) {
preResetMidiExpression(split);
Split[split].midiMode = value;
// ensure MPE is turned off
disableMpe(split);
updateSplitMidiChannels(split);
}
break;
// Split MIDI Main Channel
case 1:
if (inRange(value, 1, 16)) {
preResetMidiExpression(split);
Split[split].midiChanMain = value;
// ensure MPE is turned off
disableMpe(split);
updateSplitMidiChannels(split);
}
break;
// Split MIDI Per Note Channels
case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9:
case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17:
if (inRange(value, 0, 1)) {
preResetMidiExpression(split);
Split[split].midiChanSet[parameter-2] = value;
// ensure MPE is turned off
disableMpe(split);
updateSplitMidiChannels(split);
}
break;
// Split MIDI Per Row Lowest Channel
case 18:
if (inRange(value, 1, 16)) {
preResetMidiExpression(split);
Split[split].midiChanPerRow = value;
updateSplitMidiChannels(split);
}
break;
// Split MIDI Bend Range
case 19:
if (inRange(value, 1, 96)) {
applyBendRange(Split[split], value);
}
break;
// Split Send X
case 20:
if (inRange(value, 0, 1)) {
preSendPitchBend(split, 0);
Split[split].sendX = value;
}
break;
// Split Pitch Quantize
case 21:
if (inRange(value, 0, 1)) {
Split[split].pitchCorrectQuantize = value;
}
break;
// Split Pitch Quantize Hold
case 22:
if (inRange(value, 0, 3)) {
Split[split].pitchCorrectHold = value;
applyPitchCorrectHold();
}
break;
// Split Pitch Reset On Release
case 23:
if (inRange(value, 0, 1)) {
Split[split].pitchResetOnRelease = value;
}
break;
// Split Send Y
case 24:
if (inRange(value, 0, 1)) {
Split[split].sendY = value;
}
break;
// Split MIDI CC For Y
case 25:
if (inRange(value, 0, 127)) {
if (Split[split].expressionForY == timbreCC1 && value != 1) {
Split[split].expressionForY = timbreCC74;
}
Split[split].customCCForY = value;
}
break;
// Split Relative Y
case 26:
if (inRange(value, 0, 1)) {
Split[split].relativeY = value;
}
break;
// Split Send Z
case 27:
if (inRange(value, 0, 1)) {
Split[split].sendZ = value;
}
break;
// Split MIDI Expression For Z
case 28:
if (inRange(value, 0, 2)) {
Split[split].expressionForZ = (LoudnessExpression)value;
}
break;
// Split MIDI CC For Z
case 29:
if (inRange(value, 0, 127)) {
Split[split].customCCForZ = value;
}
break;
// Split Color Main
case 30:
if (inRange(value, 1, 11)) {
Split[split].colorMain = value;
}
break;
// Split Color Accent
case 31:
if (inRange(value, 1, 11)) {
Split[split].colorAccent = value;
}
break;
// Split Color Played
case 32:
if (inRange(value, 0, 11)) {
Split[split].colorPlayed = value;
}
break;
// Split Color LowRow
case 33:
if (inRange(value, 1, 11)) {
Split[split].colorLowRow = value;
}
break;
// Split LowRow Mode
case 34:
if (inRange(value, 0, 7)) {
Split[split].lowRowMode = value;
}
break;
// Split Special
case 35:
if (inRange(value, 0, 4)) {
switch (value) {
case 0:
Split[split].arpeggiator = false;
Split[split].ccFaders = false;
Split[split].strum = false;
setSplitSequencerEnabled(split, false);
break;
case 1:
Split[split].arpeggiator = true;
Split[split].ccFaders = false;
Split[split].strum = false;
setSplitSequencerEnabled(split, false);
break;
case 2:
Split[split].arpeggiator = false;
Split[split].ccFaders = true;
Split[split].strum = false;
setSplitSequencerEnabled(split, false);
break;
case 3:
Split[split].arpeggiator = false;
Split[split].ccFaders = false;
Split[split].strum = true;
setSplitSequencerEnabled(split, false);
break;
case 4:
Split[split].arpeggiator = false;
Split[split].ccFaders = false;
Split[split].strum = false;
setSplitSequencerEnabled(split, true);
break;
}
}
break;
// Split Octave
case 36:
if (inRange(value, 0, 10)) {
Split[split].transposeOctave = (value-5)*12;
}
break;
// Split Transpose Pitch
case 37:
if (inRange(value, 0, 14)) {
Split[split].transposePitch = value-7;
}
break;
// Split Transpose Lights
case 38:
if (inRange(value, 0, 14)) {
Split[split].transposeLights = value-7;
}
break;
// Split MIDI Expression For Y
case 39:
if (inRange(value, 0, 2)) {
Split[split].expressionForY = (TimbreExpression)value;
if (Split[split].expressionForY == timbrePolyPressure) {
Split[split].customCCForY = 128;
}
else if (Split[split].expressionForY == timbreChannelPressure) {
Split[split].customCCForY = 129;
}
else {
if (Split[split].customCCForY == 1) {
Split[split].expressionForY = timbreCC1;
}
else {
Split[split].expressionForY = timbreCC74;
}
}
}
break;
// Split MIDI CC For Fader 1
case 40:
if (inRange(value, 0, 128)) {
Split[split].ccForFader[0] = value;
}
break;
// Split MIDI CC For Fader 2
case 41:
if (inRange(value, 0, 128)) {
Split[split].ccForFader[1] = value;
}
break;
// Split MIDI CC For Fader 3
case 42:
if (inRange(value, 0, 128)) {
Split[split].ccForFader[2] = value;
}
break;
// Split MIDI CC For Fader 4
case 43:
if (inRange(value, 0, 128)) {
Split[split].ccForFader[3] = value;
}
break;
// Split MIDI CC For Fader 5
case 44:
if (inRange(value, 0, 128)) {
Split[split].ccForFader[4] = value;
}
break;
// Split MIDI CC For Fader 6
case 45:
if (inRange(value, 0, 128)) {
Split[split].ccForFader[5] = value;
}
break;
// Split MIDI CC For Fader 7
case 46:
if (inRange(value, 0, 128)) {
Split[split].ccForFader[6] = value;
}
break;
// Split MIDI CC For Fader 8
case 47:
if (inRange(value, 0, 128)) {
Split[split].ccForFader[7] = value;
}
break;
// Split LowRow X Behavior
case 48:
if (inRange(value, 0, 1)) {
Split[split].lowRowCCXBehavior = (LowRowCCBehavior)value;
}
break;
// Split MIDI CC For LowRow X
case 49:
if (inRange(value, 0, 128)) {
Split[split].ccForLowRow = value;
}
break;
// Split LowRow XYZ Behavior
case 50:
if (inRange(value, 0, 1)) {
Split[split].lowRowCCXYZBehavior = (LowRowCCBehavior)value;
}
break;
// Split MIDI CC For LowRow XYZ X
case 51:
if (inRange(value, 0, 128)) {
Split[split].ccForLowRowX = value;
}
break;
// Split MIDI CC For LowRow XYZ Y
case 52:
if (inRange(value, 0, 128)) {
Split[split].ccForLowRowY = value;
}
break;
// Split MIDI CC For LowRow XYZ Z
case 53:
if (inRange(value, 0, 128)) {
Split[split].ccForLowRowZ = value;
}
break;
// Split Minimum CC Value For Y
case 54:
if (inRange(value, 0, 127)) {
Split[split].minForY = value;
applyLimitsForY();
}
break;
// Split Maximum CC Value For Y
case 55:
if (inRange(value, 0, 127)) {
Split[split].maxForY = value;
applyLimitsForY();
}
break;
// Split Minimum CC Value For Z
case 56:
if (inRange(value, 0, 127)) {
Split[split].minForZ = value;
applyLimitsForZ();
}
break;
// Split Maximum CC Value For Z
case 57:
if (inRange(value, 0, 127)) {
Split[split].maxForZ = value;
applyLimitsForZ();
}
break;
// Split CC Value For Z in 14-bit
case 58:
if (inRange(value, 0, 1)) {
Split[split].ccForZ14Bit = value;
}
break;
// Split Initial For Relative Y
case 59:
if (inRange(value, 0, 127)) {
Split[split].initialRelativeY = value;
}
break;
// Split Channel Per Row MIDI Channel Order
case 60:
if (inRange(value, 0, 1)) {
Split[split].midiChanPerRowReversed = value;
}
break;
// Split Touch Animation
case 61:
if (inRange(value, 0, 14)) {
Split[split].playedTouchMode = value;
}
break;
// Split Sequencer Toggle Play
case 62:
if (value == 1) {
sequencerTogglePlay(split);
}
break;
// Split Sequencer Previous Pattern
case 63:
if (value == 1) {
sequencerPreviousPattern(split);
}
break;
// Split Sequencer Next Pattern
case 64:
if (value == 1) {
sequencerNextPattern(split);
}
break;
// Split Sequencer Select Pattern
case 65:
if (inRange(value, 0, 3)) {
sequencerSelectPattern(split, value);
}
break;
// Split Sequencer Toggle Mute
case 66:
if (value == 1) {
sequencerToggleMute(split);
}
break;
// Global Split Active
case 200:
if (inRange(value, 0, 1)) {
Global.splitActive = value;
}
break;
// Global Selected Split
case 201:
if (inRange(value, 0, 1)) {
Global.currentPerSplit = value;
}
break;
// Global Split Point Column
case 202:
if (inRange(value, 2, 25)) {
Global.splitPoint = value;
}
break;
// Global Main Note Lights
case 203: case 204: case 205: case 206: case 207: case 208:
case 209: case 210: case 211: case 212: case 213: case 214:
if (inRange(value, 0, 1)) {
if (value) {
Global.mainNotes[Global.activeNotes] |= (1 << (parameter-203));
}
else {
Global.mainNotes[Global.activeNotes] &= ~(1 << (parameter-203));
}
}
break;
// Global Accent Note Lights
case 215: case 216: case 217: case 218: case 219: case 220:
case 221: case 222: case 223: case 224: case 225: case 226:
if (inRange(value, 0, 1)) {
if (value) {
Global.accentNotes[Global.activeNotes] |= (1 << (parameter-215));
}
else {
Global.accentNotes[Global.activeNotes] &= ~(1 << (parameter-215));
}
}
break;
// Global Row Offset
case 227:
if (value == ROWOFFSET_NOOVERLAP || value == 3 || value == 4 || value == 5 || value == 6 ||
value == 7 || value == ROWOFFSET_OCTAVECUSTOM || value == ROWOFFSET_GUITAR || value == ROWOFFSET_ZERO) {
Global.rowOffset = value;
}
break;
// Global Switch 1 Assignment
case 228:
if (inRange(value, ASSIGNED_OCTAVE_DOWN, MAX_ASSIGNED)) {
Global.switchAssignment[SWITCH_SWITCH_1] = value;
if (value >= ASSIGNED_TAP_TEMPO) {
Global.customSwitchAssignment[SWITCH_SWITCH_1] = value;
}
}
break;
// Global Switch 2 Assignment
case 229:
if (inRange(value, ASSIGNED_OCTAVE_DOWN, MAX_ASSIGNED)) {
Global.switchAssignment[SWITCH_SWITCH_2] = value;
if (value >= ASSIGNED_TAP_TEMPO) {
Global.customSwitchAssignment[SWITCH_SWITCH_2] = value;
}
}
break;