-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFADERPORT.control.js
1098 lines (991 loc) · 34.8 KB
/
FADERPORT.control.js
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
loadAPI(1);
load("mcu_display.js");
load("mcu_encoders.js");
load("mcu_var.js");
host.defineController("PreSonus", "FaderPort", "1.0", "e8d7b358-a945-4002-b9f4-50860877ec0c");
host.defineMidiPorts(1, 1);
host.addDeviceNameBasedDiscoveryPair(["FaderPort"],["FaderPort"]);
host.addDeviceNameBasedDiscoveryPair(["FaderPort MIDI 1"],["FaderPort MIDI 1"]);
var isShiftPressed = false;
var isResetPressed = false;
var isScrubPressed = false;
var isVpotPressed = initArray(false, 8);
var isFlipOn = false;
var isPlay = false;
var isPunchIn = false;
var isPunchOut = false;
var isGrooveOn = false;
var pageUp = VPOT_ASSIGN.EQ;
var pageDown = VPOT_ASSIGN.INSTRUMENT;
var mcuActiveEncoderPage = VPOT_PAGE.TRACK;
var mcuActiveDisplayPage = DISPLAY_PAGES.NAME_AND_VOLUME;
var activeSendPage = VPOT_PAGE.SEND0;
var activeDevicePage = VPOT_PAGE.DEVICE_PARAM;
var parameterPageBuffer = -1;
var vuMeter = [0,8];
var v_page = VPOT_PAGE.SEND0;
var d_page = DISPLAY_PAGES.NAME_AND_SEND0;
var activeVuMode = vuMode.LED;
var punchIO = Punch.OFF;
var parameterPageBuffer = 0;
var selectedTrack = 0;
var isTempoDisplayActive = true;
var numSendPages = 8;
var numDevicePages = 2;
var tempo = "110";
var returnToArrangement = MODIFIER.CONTROL;
var displayPages = [new DisplayPage(),new DisplayPage(),new DisplayPage(),new DisplayPage(),new DisplayPage(),new DisplayPage(),new DisplayPage(),new DisplayPage(),new DisplayPage()];
var encoderPages = [new EncoderPage(0),new EncoderPage(1),new EncoderPage(2),new EncoderPage(3),new EncoderPage(4),new EncoderPage(5),new EncoderPage(6),new EncoderPage(7),new EncoderPage(8),new EncoderPage(9),new EncoderPage(10)];
var automationWrite = false;
var automationWriteMode = "";
var sendMode = false;
var sendValueArray = new Array(999);
var panelLayout = ["ARRANGE", "EDIT", "MIX"];
function init()
{
clearLCD();
writeToLCD(0, 0, " *** init Bitwig Studio Open API 1.0 ***", TOTAL_DISPLAY_SIZE);
host.getMidiInPort(0).setMidiCallback(onMidi);
// //////////////////////////////////////////////////////////////////////*Host*/
application = host.createApplicationSection();
cursorDevice = host.createCursorDeviceSection(8);
cursorTrack = host.createCursorTrackSection(0, 1);
// cursorClip = host.createCursorClipSection(16, 16);
groove = host.createGrooveSection();
masterTrack = host.createMasterTrackSection(0);
trackBank = host.createTrackBankSection(8, numSendPages, 99);
transport = host.createTransportSection();
// //////////////////////////////////////////////////////////////////* TRANSPORT */
transport.addIsPlayingObserver(function(on)
{
isPlay = on;
sendNoteOn(0, TRANSPORT.PLAY, on ? 127 : 0);
sendNoteOn(0, TRANSPORT.STOP, on ? 0 : 127);
});
transport.addIsLoopActiveObserver(function(on)
{
sendNoteOn(0, TRANSPORT.CYCLE, on ? 127 : 0);
});
transport.addIsRecordingObserver(function(on)
{
sendNoteOn(0, TRANSPORT.RECORD, on ? 127 : 0);
});
transport.addIsWritingArrangerAutomationObserver(function(on)
{
automationWrite = on;
});
transport.addAutomationWriteModeObserver(function(mode)
{
setAutomationModeLED(mode);
});
transport.addPunchInObserver(function(on)
{
isPunchIn = on;
sendNoteOn(0, TRANSPORT.REW, on ? 127 : 0);
});
transport.addPunchOutObserver(function(on)
{
isPunchOut = on;
sendNoteOn(0, TRANSPORT.FF, on ? 127 : 0);
});
transport.addClickObserver(function(on)
{
sendNoteOn(0, TRANSPORT.CLICK, on ? 127 : 0);
});
transport.addOverdubObserver(function(on)
{
sendNoteOn(0, TRANSPORT.REPLACE, on ? 127 : 0);
});
transport.getPosition().addTimeObserver("", 3, 2, 2, 3, function(value)
{
setTransportPositionDisplay(value);
});
transport.getTempo().addValueDisplayObserver(3, "", function(value)
{
setTempo(value);
isTempoDisplayActive ? setTransportTempoDisplay(value) : null;
});
// ///////////////////////////////////////////////////////////////////////* GROOVE */
groove.getEnabled().addValueDisplayObserver(12, "", function(text)
{
if (text == "on")
{
sendNoteOn(0, TRANSPORT.SOLO, 127);
isGrooveOn = true;
}
else
{
sendNoteOn(0, TRANSPORT.SOLO, 0);
isGrooveOn = false;
}
});
// //////////////////////////////////////////////////////////////////////* TRACK BANK */
for ( var t = 0; t < 8; t++)
{
var track = trackBank.getTrack(t);
track.addNameObserver(6, "", makeIndexedFunction(t, function(index, value)
{
writeToColumn(DISPLAY_PAGES.NAME_AND_VOLUME, 0, index, value);
writeToColumn(DISPLAY_PAGES.NAME_AND_PAN, 0, index, value);
for ( var s = 0; s < numSendPages; s++)
{
d_page = DISPLAY_PAGES.NAME_AND_SEND0 + s;
writeToColumn(d_page, 0, index, value);
}
}));
track.addVuMeterObserver(14, -1, true, makeIndexedFunction(t, function(index, vuMeter)
{
sendChannelPressure(0, parseInt(vuMeter) + (index << 4));
}));
track.getVolume().addValueDisplayObserver(6, "", makeIndexedFunction(t, function(index, value)
{
writeToColumn(DISPLAY_PAGES.NAME_AND_VOLUME, 1, index, value);
}));
track.getVolume().addValueObserver(16384, makeIndexedFunction(t, function(index, value)
{
encoderPages[VPOT_PAGE.VOLUME].setEncoder(index, value, 0, 0);
}));
track.getPan().addValueObserver(16384, makeIndexedFunction(t, function(index, value)
{
encoderPages[VPOT_PAGE.PAN].setEncoder(index, value, 1, 0);
encoderPages[VPOT_PAGE.TRACK].setEncoder(index, value, 1, 0);
}));
track.getPan().addValueDisplayObserver(6, "", makeIndexedFunction(t, function(index, value)
{
writeToColumn(DISPLAY_PAGES.NAME_AND_PAN, 1, index, value);
}));
track.getPan().setLabel("P" + (t + 1));
//track.getSend(0).addValueObserver(16384, makeIndexedFunction(t, function(index, value)
//{
// encoderPages[VPOT_PAGE.SEND0].setEncoder(index, value, 0, 0);
//}));
//track.getSend(0).addValueDisplayObserver(6, "", makeIndexedFunction(t, function(index, value)
//{
// writeToColumn(DISPLAY_PAGES.NAME_AND_SEND0, 1, index, value);
//}));
//track.getSend(1).addValueObserver(16384, makeIndexedFunction(t, function(index, value)
//{
// encoderPages[VPOT_PAGE.SEND1].setEncoder(index, value, 0, 0);
//}));
//track.getSend(1).addValueDisplayObserver(6, "", makeIndexedFunction(t, function(index, value)
//{
// writeToColumn(DISPLAY_PAGES.NAME_AND_SEND1, 1, index, value);
//}));
//track.getSend(2).addValueObserver(16384, makeIndexedFunction(t, function(index, value)
//{
// encoderPages[VPOT_PAGE.SEND2].setEncoder(index, value, 0, 0);
//}));
//track.getSend(2).addValueDisplayObserver(6, "", makeIndexedFunction(t, function(index, value)
//{
// writeToColumn(DISPLAY_PAGES.NAME_AND_SEND2, 1, index, value);
//}));
//track.getSend(3).addValueObserver(16384, makeIndexedFunction(t, function(index, value)
//{
// encoderPages[VPOT_PAGE.SEND3].setEncoder(index, value, 0, 0);
//}));
//track.getSend(3).addValueDisplayObserver(6, "", makeIndexedFunction(t, function(index, value)
//{
// writeToColumn(DISPLAY_PAGES.NAME_AND_SEND3, 1, index, value);
//}));
//track.getSend(4).addValueObserver(16384, makeIndexedFunction(t, function(index, value)
//{
// encoderPages[VPOT_PAGE.SEND4].setEncoder(index, value, 0, 0);
//}));
//track.getSend(4).addValueDisplayObserver(6, "", makeIndexedFunction(t, function(index, value)
//{
// writeToColumn(DISPLAY_PAGES.NAME_AND_SEND4, 1, index, value);
//}));
for ( var s = 0; s < numSendPages; s++) /////////////////////////////////////not working??
{
//v_page = VPOT_PAGE.SEND0 + s;
//d_page = DISPLAY_PAGES.NAME_AND_SEND0 + s;
//track.getSend(s).setLabel("S" + (t + 1));
//host.println("test 5:" + t);
//makeSendValue(t, s, 0);
track.getSend(s).addValueObserver(16384, makeIndexedFunction(s,
function(index, value)
{
makeSendValue(selectedTrack, index, value);
for (encoderi = 0; encoderi < numSendPages; encoderi++) {
//encoderPages[VPOT_PAGE.SEND0].setEncoder(index, value, 0, 0);
encoderPages[VPOT_PAGE.SEND0].valueBuffer[encoderi] = sendValueArray[selectedTrack][encoderi];
//encoderPages[VPOT_PAGE.SEND0].sendValueToFader(index);
//host.println("test 7:" + encoderPages[VPOT_PAGE.SEND0].valueBuffer);
}
encoderPages[VPOT_PAGE.SEND0].sendAllValuesToFaders();
//if (sendMode) {
// host.println(value);
// sendValueArray[t][s] = value;
// encoderPages[VPOT_PAGE.SEND0].valueBuffer[st] = value
//}
}));
//track.getSend(s).addValueDisplayObserver(6, "", makeIndexedFunction(t,
//function(index, value)
//{
//writeToColumn(d_page, 1, index, value);
//}));
}//////////////////////////////////////////////////////////////////////////////////////////////
track.addIsSelectedObserver(makeIndexedFunction(t, function(index, isSelected)
{
if (isSelected)
{
sendNoteOn(0, CHANNEL_BUTTON.SELECT0 + index, 127);
setTrackSelected(index);
if (mcuActiveDisplayPage == DISPLAY_PAGES.NAME_AND_VOLUME || mcuActiveDisplayPage == DISPLAY_PAGES.NAME_AND_PAN) setPageDisplay(index);
//host.println("track change");
if (sendMode) {
for (var st = 0; st < numSendPages; st++) {
//trackBank.getTrack(this.selectedTrack).getSend(st);
encoderPages[VPOT_PAGE.SEND0].valueBuffer[st] = sendValueArray[index][st];
}
encoderPages[VPOT_PAGE.SEND0].sendAllValuesToFaders();
}
}
else sendNoteOn(0, CHANNEL_BUTTON.SELECT0 + index, 0);
}));
track.getMute().addValueObserver(makeIndexedFunction(t, function(index, on)
{
sendNoteOn(0, CHANNEL_BUTTON.MUTE0 + index, on ? 127 : 0);
}));
track.getSolo().addValueObserver(makeIndexedFunction(t, function(index, on)
{
sendNoteOn(0, CHANNEL_BUTTON.SOLO0 + index, on ? 127 : 0);
}));
track.getArm().addValueObserver(makeIndexedFunction(t, function(index, on)
{
sendNoteOn(0, CHANNEL_BUTTON.ARM0 + index, on ? 127 : 0);
}));
track.getVolume().setLabel("V" + (t + 1));
track.getVolume().setIndication(true);
}
// /////////////////////////////////////////////////////////////// /* MASTER TRACK */
masterTrack.getVolume().addValueObserver(16384, function(value)
{
sendPitchBend(8, value);
});
masterTrack.getVolume().setIndication(true);
//
// ///////////////////////////////////////////////////////////////* CURSOR DEVICE */
cursorDevice.addSelectedPageObserver(0, function(page)
{
if (mcuActiveDisplayPage == DISPLAY_PAGES.DEVICE_PARAMETERS)
{
storeToParameterPageBuffer(page);
setPageDisplay(page);
}
else storeToParameterPageBuffer(page);
});
for ( var p = 0; p < 8; p++)
{
var parameter = cursorDevice.getParameter(p);
parameter.addNameObserver(6, "", makeIndexedFunction(p, function(index, value)
{
writeToColumn(DISPLAY_PAGES.DEVICE_PARAMETERS, 0, index, value);
}));
parameter.addValueDisplayObserver(6, "", makeIndexedFunction(p, function(index, value)
{
writeToColumn(DISPLAY_PAGES.DEVICE_PARAMETERS, 1, index, value);
}));
parameter.addValueObserver(16384, makeIndexedFunction(p, function(index, value)
{
encoderPages[VPOT_PAGE.DEVICE_PARAM].setEncoder(index, value, 0, 0);
encoderPages[VPOT_PAGE.DEVICE_PRESETS].setEncoder(index, value, 0, 0);
}));
parameter.setLabel("P" + (p + 1));
}
cursorDevice.addPresetNameObserver(46, "-", function(name)
{
writeToDisplay(DISPLAY_PAGES.DEVICE_PRESETS, 0, 0, " preset: " + name, 56);
});
cursorDevice.addPresetCategoryObserver(22, "-", function(category)
{
writeToDisplay(DISPLAY_PAGES.DEVICE_PRESETS, 1, 0, "category: " + category, 32);
});
cursorDevice.addPresetCreatorObserver(14, "-", function(creator)
{
writeToDisplay(DISPLAY_PAGES.DEVICE_PRESETS, 1, 31, " creator: " + creator, 24);
});
clearLCD();
flushLEDs();
// sendSysex(SYSEX_HDR + "61 f7"); //All faders to the bottom (doesn't work?)
sendSysex(SYSEX_HDR + "62 f7"); // All leds off (doesn't work?)
for ( var i = 0; i < 6; i++)
{
sendNoteOn(0, VPOT_ASSIGN.TRACK + i, 0); // VPOT-Assign LEDs all OFF
}
mcuActiveEncoderPage = VPOT_PAGE.TRACK;
sendNoteOn(0, 0x72, 127); // Beats LED on
sendNoteOn(0, VPOT_ASSIGN.TRACK, 127); // VPOT_Assign Track LED ON
sendSysex(SYSEX_HDR + "0a 01 f7"); // Transport Button Klick OFF=0a 00
// ,ON=0a 01
// vu-meter
sendSysex(SYSEX_HDR + "21 01 f7"); // set Global LCD meter mode to vertical
for ( var j = 0; j < 8; j++)
{
sendSysex(SYSEX_HDR + "20 0" + j + " 00 f7"); // address all channel vuMode.OFF
sendChannelPressure(0, 0xf + (j << 4)); // reset peak hold
}
// ----------tryout blinking lights in the automation section
// for (var i=0;i<3;i++)
// {
// sendNoteOn(0, AUTOMATION.WRITE + i, 1))
// }
setIndications("pan");
}
function exit()
{
clearLCD();
writeToLCD(0, 0, " *** exit Bitwig Studio Open API 1.0 ***", TOTAL_DISPLAY_SIZE);
for ( var j = 0; j < 8; j++)
{
sendSysex(SYSEX_HDR + "20 0" + j + "00 f7");
// sendChannelPressure(0, 0xf + (j << 4));
}
sendSysex(SYSEX_HDR + "0a 00 f7"); // Transport Button Klick OFF=0a 00, ON=0a 01
// sendSysex(SYSEX_HDR + "61 f7"); // All faders to the bottom
sendSysex(SYSEX_HDR + "62 f7"); // All leds off
sendSysex(SYSEX_HDR + "21 01 f7");// set Global LCD meter mode to vertical
}
function flush()
{
}
/* ----------------------- onMidi ----------------- */
// /////// Knobs send/receive Midi Notes
// /////// MotorFaders send/receive PitchBend (14bit)
// /////// VPots send/receive Controller Messages
function onMidi(status, data1, data2)
{
//printMidi(status, data1, data2);
// host.println("status: " + status + " data1: " + data1 + " data2: " + data2);
if (isPitchBend(status)) ////////only the motor faders send/receive pitch bend messages(14bit --> 0 - 16383)
{
var index = MIDIChannel(status);
if (index < 8)
{
//host.println("Test 9:" + index);
getFaderObjectPath(index).set(pitchBendValue(data1, data2), 16384 - 127);
makeSendValue(this.selectedTrack,index, pitchBendValue(data1, data2));
}
if (index == 8)
{
masterTrack.getVolume().set(pitchBendValue(data1, data2), 16384 - 127);
}
}
/* ---------------------- isNoteOn --- */
//all buttons, the click of the encoders and the touch of the motor faders send/receive note on messages (release a button = velocity 0)
if (isNoteOn(status))
{
if (data1 == MODIFIER.SHIFT)
{
isShiftPressed = data2 > 0; //boolean that is true as long as the shift button is pressed
}
else if (data1 == MODIFIER.OPTION)
{
isResetPressed = data2 > 0; //boolean that is true as long as the reset button is pressed
}
//else if (data1 == SCRUB)
//{
// isScrubPressed = data2 > 0; //boolean that is true as long as the scrub button is pressed
//}
else if (data1 >= VPOT_CLICK0 && data1 < (VPOT_CLICK0 + 8)) //
{
if (isResetPressed)
{
getEncoderObjectPath(data1 - VPOT_CLICK0).reset(); // if reset is pressed, reset the parameter of the clicked encoder to its default value
}
else isVpotPressed[data1 - VPOT_CLICK0] = data2 > 0; // as long as an encoder is clicked (and reset is not) the range is set to fine tune
}
if (data2 > 0) // Check button presses (but not releases) in here
{
if (data1 >= VPOT_ASSIGN.TRACK && data1 <= VPOT_ASSIGN.INSTRUMENT) // the 4 mode buttons change the vpot assignement and what's displayed
{
sendMode = false;
switch (data1)
{
case VPOT_ASSIGN.TRACK:
if (mcuActiveEncoderPage != VPOT_PAGE.TRACK)
{
setEncoderPage(VPOT_PAGE.TRACK);
setDisplayPage(DISPLAY_PAGES.NAME_AND_VOLUME);
setPageDisplay(selectedTrack);
sendNoteOn(0, VPOT_ASSIGN.TRACK, 127);
sendNoteOn(0, VPOT_ASSIGN.SEND, 0);
sendNoteOn(0, VPOT_ASSIGN.PAN, 0);
sendNoteOn(0, VPOT_ASSIGN.DEVICE, 0);
setIndications("pan");
switchVuMode(activeVuMode);
}
break;
case VPOT_ASSIGN.SEND:
sendMode = true;
//for (var st = 0; st < numSendPages; st++) {
// //trackBank.getTrack(this.selectedTrack).getSend(st);
// host.println(this.selectedTrack);
// encoderPages[VPOT_PAGE.SEND0].valueBuffer[st] = sendValueArray[this.selectedTrack][st];
//}
////encoderPages[VPOT_PAGE.SEND0].sendAllValuesToFaders();
if (mcuActiveEncoderPage == activeSendPage) // if already in send mode, switch the send page
{
switchActiveSendPage();
setPageDisplay(activeSendPage - 4);
setEncoderPage(activeSendPage);
setDisplayPage(activeSendPage);
setIndications("send");
}
else if (mcuActiveEncoderPage != VPOT_PAGE.SEND0 && mcuActiveEncoderPage != VPOT_PAGE.SEND1 && mcuActiveEncoderPage != VPOT_PAGE.SEND2 && mcuActiveEncoderPage != VPOT_PAGE.SEND3 && mcuActiveEncoderPage != VPOT_PAGE.SEND4)
{
setPageDisplay(activeSendPage - 4);
setEncoderPage(activeSendPage);
setDisplayPage(activeSendPage);
sendNoteOn(0, VPOT_ASSIGN.TRACK, 0);
sendNoteOn(0, VPOT_ASSIGN.SEND, 127);
sendNoteOn(0, VPOT_ASSIGN.PAN, 0);
sendNoteOn(0, VPOT_ASSIGN.DEVICE, 0);
setIndications("send");
switchVuMode(activeVuMode);
}
break;
case VPOT_ASSIGN.PAN:
if (mcuActiveEncoderPage != VPOT_PAGE.PAN)
{
setEncoderPage(VPOT_PAGE.PAN);
setDisplayPage(DISPLAY_PAGES.NAME_AND_PAN);
setPageDisplay(selectedTrack);
sendNoteOn(0, VPOT_ASSIGN.TRACK, 0);
sendNoteOn(0, VPOT_ASSIGN.SEND, 0);
sendNoteOn(0, VPOT_ASSIGN.PAN, 127);
sendNoteOn(0, VPOT_ASSIGN.DEVICE, 0);
setIndications("pan");
switchVuMode(activeVuMode);
}
break;
case VPOT_ASSIGN.DEVICE:
if (mcuActiveEncoderPage == activeDevicePage) // if already in device mode, toggle between displaying mapped parameters or device presets
{
switchActiveDevicePage();
setEncoderPage(activeDevicePage);
setDisplayPage(activeDevicePage);
setIndications("device");
if (activeDevicePage == VPOT_PAGE.DEVICE_PARAM) setPageDisplay(parameterPageBuffer);
}
else if (mcuActiveEncoderPage != VPOT_PAGE.DEVICE_PARAM && mcuActiveEncoderPage != VPOT_PAGE.DEVICE_PRESETS)
{
setEncoderPage(activeDevicePage);
setDisplayPage(activeDevicePage);
sendNoteOn(0, VPOT_ASSIGN.TRACK, 0);
sendNoteOn(0, VPOT_ASSIGN.PAN, 0);
sendNoteOn(0, VPOT_ASSIGN.SEND, 0);
sendNoteOn(0, VPOT_ASSIGN.DEVICE, 127);
setIndications("device");
if (activeDevicePage == VPOT_PAGE.DEVICE_PARAM) setPageDisplay(parameterPageBuffer);
}
switch (activeVuMode)
{
case vuMode.LED:
break;
case vuMode.LED_AND_LCD:
for ( var i = 0; i < 8; i++)
{
sendChannelPressure(0, 0 + (i << 4));
sendSysex(SYSEX_HDR + "20 0" + i + "01 f7");
}
break;
case vuMode.LCD:
for ( var i = 0; i < 8; i++)
{
sendChannelPressure(0, 0 + (i << 4));
sendSysex(SYSEX_HDR + "20 0" + i + "01 f7");
}
break;
default:
for ( var i = 0; i < 8; i++)
{
sendChannelPressure(0, 0 + (i << 4));
sendSysex(SYSEX_HDR + "20 0" + i + "00 f7");
}
}
break;
case pageUp: //select previous device on selected track or with shift pressed: select previous parameter page on selected device
!isShiftPressed ? cursorDevice.previousParameterPage() : cursorDevice.selectPrevious();
// setIndications("device");
break;
case pageDown: //select next device on selected track or with shift pressed: select next parameter page on selected device
!isShiftPressed ? cursorDevice.nextParameterPage() : cursorDevice.selectNext();
// setIndications("device");
break;
}
}
// ///////////////////////////////////// channel buttons ///////
else if (data1 >= 0 && data1 <= 7) // is one of the arm buttons pressed
{
var index = data1 - CHANNEL_BUTTON.ARM0; //which arm button is pressed
trackBank.getTrack(index).getArm().toggle(); // tell the application to toggle the state of the corresponding arm button
}
else if (data1 >= 8 && data1 <= 15) // is one of the solo buttons pressed
{
var index = data1 - CHANNEL_BUTTON.SOLO0; //which solo button is pressed
trackBank.getTrack(index).getSolo().toggle(); // tell the application to toggle the state of the corresponding solo button
}
else if (data1 >= 16 && data1 <= 23) // is one of the mute buttons pressed
{
var index = data1 - CHANNEL_BUTTON.MUTE0; //which mute button is pressed
trackBank.getTrack(index).getMute().toggle(); // tell the application to toggle the state of the corresponding mute button
}
else if (data1 >= 24 && data1 <= 31) // is a select button pressed
{
var index = data1 - CHANNEL_BUTTON.SELECT0; //which select button is pressed
trackBank.getTrack(index).select(); // tell the application to toggle the state of the corresponding arm button
}
else if (data1 >= 54 && data1 <= 61) // is one of the f buttons pressed
{
var index = data1 - SET_PAGE0; //which f button is pressed
if (mcuActiveEncoderPage == VPOT_PAGE.DEVICE_PARAM)
{
cursorDevice.setParameterPage(index);
// setIndications("device");
}
else if (mcuActiveEncoderPage == VPOT_PAGE.DEVICE_PRESETS) //browse presets,preset category, preset creator
{
switch (index)
{
case 0:
cursorDevice.switchToPreviousPreset();
break;
case 1:
cursorDevice.switchToNextPreset();
break;
case 2:
cursorDevice.switchToPreviousPresetCategory();
break;
case 3:
cursorDevice.switchToNextPresetCategory();
break;
case 4:
cursorDevice.switchToPreviousPresetCreator();
break;
case 5:
cursorDevice.switchToNextPresetCreator();
break;
case 6:
break;
case 7:
break;
}
}
else if ((mcuActiveEncoderPage >= VPOT_PAGE.SEND0 && mcuActiveEncoderPage <= VPOT_PAGE.SEND4) && index < numSendPages) //select send page
{
//activeSendPage = index + 4;
//setPageDisplay(activeSendPage - 4);
//setEncoderPage(activeSendPage);
//setDisplayPage(activeSendPage);
//setIndications("send");
//host.println("test 1");
}
}
// /////////////////////////////// transport ///////
switch (data1)
{
case TRANSPORT.PLAY:
transport.play();
break;
case TRANSPORT.STOP:
transport.stop();
break;
case TRANSPORT.RECORD:
transport.record();
break;
case TRANSPORT.REW:
if (isShiftPressed)
{
transport.togglePunchIn();
}
else
{
transport.rewind();
}
break;
case TRANSPORT.FF:
if (isShiftPressed)
{
transport.togglePunchOut();
}
else
{
transport.fastForward();
}
break;
case TRANSPORT.CYCLE:
transport.toggleLoop();
break;
case TRANSPORT.CLICK:
transport.toggleClick();
break;
case TRANSPORT.SOLO:
if (isGrooveOn)
groove.getEnabled().set(0, 127);
else groove.getEnabled().set(127, 127);
break;
case TRANSPORT.REPLACE:
transport.toggleOverdub();
break;
case returnToArrangement:
trackBank.getTrack(selectedTrack).getClipLauncher().returnToArrangement();
break;
case FADER_BANKS.FLIP:
toggleFlip();
break;
case FADER_BANKS.BANK_UP:
trackBank.scrollTracksPageUp();
// setIndications("pan");
break;
case FADER_BANKS.BANK_DOWN:
trackBank.scrollTracksPageDown();
// setIndications("pan");
break;
case FADER_BANKS.CHANNEL_UP:
cursorTrack.selectPrevious();
break;
case FADER_BANKS.CHANNEL_DOWN:
cursorTrack.selectNext();
break;
case APPLICATION.UNDO:
application.undo();
sendNoteOn(0, APPLICATION.UNDO, 127);
break;
case APPLICATION.REDO:
application.redo();
break;
case APPLICATION.CANCEL:
application.escape();
break;
case APPLICATION.ENTER:
application.enter();
break;
case APPLICATION.TOGGLE_NOTE_EDITOR:
//application.nextPanelLayout();
//var paneli = panelLayout.indexOf(application.panelLayout())+1;
// if (i > 2) {
// i = 0;
//}
//host.println(panelLayout[paneli]);
//application.setPanelLayout(panelLayout[paneli]);
//application.nextPerspective();
break;
case APPLICATION.TOGGLE_DEVICES:
application.toggleDevices();
break;
case APPLICATION.TOGGLE_AUTOMATION_EDITOR:
application.toggleAutomationEditor();
break;
case APPLICATION.TOGGLE_MIXER:
application.toggleMixer();
break;
case APPLICATION.TOGGLE_BROWSER:
application.toggleBrowserVisibility();
// cursorDevice.replaceDeviceInsertionPoint().browse();
break;
case APPLICATION.REPLACE_DEVICE:
//cursorDevice.replaceDeviceInsertionPoint().browse();
break;
case TOGGLE_VU_METER:
switchVuMode(activeVuMode + 1);
break;
case TOGGLE_TEMPO_OR_TICKS:
toggleTempoOrTicks();
break;
case NAVI.LEFT:
if (isShiftPressed) application.focusPanelToLeft();
else application.arrowKeyLeft();
break;
case NAVI.RIGHT:
if (isShiftPressed) application.focusPanelToRight();
else application.arrowKeyRight();
break;
case NAVI.UP:
if (isShiftPressed) application.focusPanelAbove();
else application.arrowKeyUp();
break;
case NAVI.DOWN:
if (isShiftPressed) application.focusPanelBelow();
else application.arrowKeyDown();
break;
case NAVI.ZOOM:
// TODO
break;
}
}
else if (data2 == 0) // Check button release, no press
{
switch (data1)
{
case APPLICATION.UNDO:
sendNoteOn(0, APPLICATION.UNDO, 0);
break;
}
}
if (data1 >= FADERTOUCH0 && data1 < FADERTOUCH0 + 8) //if a fader is released..
{
if (isResetPressed)
{
var t = data1 - FADERTOUCH0;
getFaderObjectPath(t).reset(); // ..reset the corresponding parameter to its default value (if flip is off, this is the volume)
}
}
else if (data1 == FADERTOUCH0 + 8) // masterfader
if (isResetPressed)
{
masterTrack.getVolume().set(11163, 16384);
}
}
// ////////////////////////////////////// isChannelController //////
if (isChannelController(status)) //encoders(vpots) and the wheel send/receive channel controller messages
{
var index = 0;
data1 != TRANSPORT.WHEEL ? index = data1 - VPOT0 : index = data1; // distinguish vpots from wheel
var relativeRange = isVpotPressed[index] || isShiftPressed ? 1000 : 200; // set relative range dependent on if vpot or shift is pressed
var delta = data2;
if (delta > 64) // if an encoder is turned counterclockwise..
{
delta = (-1) * (Math.round(delta) - 64); // ..do this math
}
/* vpots */
if (data1 >= VPOT0 && data1 < (VPOT0 + 8)) // if the cc comes from a vpot..
{
//host.println("test 10");
isFlipOn ? trackBank.getTrack(index).getVolume().inc(delta, relativeRange) : getEncoderObjectPath(index).inc(delta, relativeRange); // ..get the target parameter dependent on the active encoder page and if flip is on or off
}
else if (data1 == TRANSPORT.WHEEL) // increasePosition didn't work (trunk 2740). for now the wheel changes the tempo
{
if (isShiftPressed)
{
transport.increaseTempo(delta, isScrubPressed ? 6461 : 1293); // relativeRange: 647 = full, 1293 = half, 3231 = 1/5, 6461 = 1/10 bpm steps
//host.println("test 11");
}
else
{
transport.incPosition(delta, true);
//host.println("test 12");
}
}
}
}
function onSysex(data)
{
}
function switchVuMode(mode) // leds on/leds and vu-meter on display on/vu-meter on display on/all off
{
if (activeVuMode != mode)
{
if (activeVuMode < NUM_VU_MODES)
activeVuMode = mode;
else activeVuMode = vuMode.LED;
if (mcuActiveEncoderPage == VPOT_PAGE.DEVICE_PARAM) // no vu-meter on display when in device mode
{
switch (activeVuMode)
{
case vuMode.LED_AND_LCD:
activeVuMode = vuMode.OFF;
break;
case vuMode.LCD:
activeVuMode = vuMode.OFF;
break;
}
}
}
switch (activeVuMode) // the mcu changes the vu-meter mode when receiving the corresponding sysex message
{
case vuMode.LED:
for ( var i = 0; i < 8; i++)
{
sendChannelPressure(0, 0 + (i << 4)); // resets the leds (and vu-meters on the display?)
sendSysex(SYSEX_HDR + "20 0" + i + "01 f7");
}
break;
case vuMode.LED_AND_LCD:
for ( var i = 0; i < 8; i++)
{
sendChannelPressure(0, 0 + (i << 4));
sendSysex(SYSEX_HDR + "20 0" + i + "03 f7");
}
break;
case vuMode.LCD:
for ( var i = 0; i < 8; i++)
{
sendChannelPressure(0, 0 + (i << 4));
sendSysex(SYSEX_HDR + "20 0" + i + "06 f7");
}
break;
case vuMode.OFF:
for ( var i = 0; i < 8; i++)
{
sendChannelPressure(0, 0 + (i << 4), 0);
sendSysex(SYSEX_HDR + "20 0" + i + "00 f7");
}
break;
}
}
function makeIndexedFunction(index, f) // this is needed to
{
return function(value)
{
f(index, value);
};
}
// if (index >= Observer.VU_METER0 && index < (Observer.VU_METER0 + 8))
// {
// var channel = index - Observer.VU_METER0;
// sendMidi(new ChannelPressure(0, parseInt(message) + (channel << 4)));
// }
function getFaderObjectPath(index) // for now this is mainly used for the flip
{
if (isFlipOn)
{
switch (mcuActiveEncoderPage)
{
case VPOT_PAGE.TRACK:
return trackBank.getTrack(index).getPan();
break;
case VPOT_PAGE.PAN:
return trackBank.getTrack(index).getPan();
break;
case VPOT_PAGE.DEVICE_PARAM:
return cursorDevice.getParameter(index);
break;
case VPOT_PAGE.DEVICE_PRESETS:
return cursorDevice.getParameter(index);
break;
case VPOT_PAGE.SEND0:
//host.println("test 6:" + this.selectedTrack);
return trackBank.getTrack(this.selectedTrack).getSend(index);
break;
//case VPOT_PAGE.SEND1:
// return trackBank.getTrack(index).getSend(1);
// break;
//case VPOT_PAGE.SEND2:
// return trackBank.getTrack(index).getSend(2);
// break;
//case VPOT_PAGE.SEND3:
// return trackBank.getTrack(index).getSend(3);
// break;
//case VPOT_PAGE.SEND4:
// return trackBank.getTrack(index).getSend(4);
// break;
}
}
else return trackBank.getTrack(index).getVolume();
}
function toggleFlip() // toggle flip on/off and send all values to all vpots and faders
{
switch (isFlipOn)
{
case true:
isFlipOn = false;
sendNoteOn(0, FADER_BANKS.FLIP, 0);
encoderPages[mcuActiveEncoderPage].sendAllValuesToVpots();
encoderPages[VPOT_PAGE.VOLUME].sendAllValuesToFaders();
break;
case false:
isFlipOn = true;
sendNoteOn(0, FADER_BANKS.FLIP, 127);
encoderPages[mcuActiveEncoderPage].sendAllValuesToFaders();
//host.println("test 8:" + mcuActiveEncoderPage);
encoderPages[VPOT_PAGE.VOLUME].sendAllValuesToVpots();
break;
}
}
function flushLEDs()
{
sendNoteOn(0, FADER_BANKS.FLIP, 0);
sendNoteOn(0, FADER_BANKS.GLOBAL_VIEW, 0);
}
function setAutomationModeLED(mode)
{
automationWriteMode = mode;
}
function switchActiveSendPage() // when the active encoder page is 'send' and the send mode button is pressed
{