forked from ending2020/Numark-Mixtrack-Platinum-FX-Mapping
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNumark-Mixtrack-Platinum-FX-scripts.js
1460 lines (1299 loc) · 52.8 KB
/
Numark-Mixtrack-Platinum-FX-scripts.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
////////////////////////////////////////////////////////////////////////
// JSHint configuration //
////////////////////////////////////////////////////////////////////////
/* global engine */
/* global script */
/* global print */
/* global midi */
////////////////////////////////////////////////////////////////////////
/******************
* CONFIG OPTIONS *
******************/
// should wheel be enabled on startup?
var EnableWheel = true;
// should we use the manual loop buttons as hotcue buttons 5-8?
var UseManualLoopAsCue = false;
// should we use the auto loop buttons as hotcue buttons 5-8?
var UseAutoLoopAsCue = false;
// should we use the hotcue buttons for samplers 5-8?
var UseCueAsSampler = false;
// should shift+load eject or load and play?
var ShiftLoadEjects = false;
// should we show effect parameters when an effect is focused?
var ShowFocusedEffectParameters = false;
var MixtrackPlatinumFX = {};
// edited code - does something to exit demo mode
var sendSysex = function(buffer) {
midi.sendSysexMsg(buffer, buffer.length);
}
MixtrackPlatinumFX.init = function(id, debug) {
MixtrackPlatinumFX.id = id;
MixtrackPlatinumFX.debug = debug;
//edited code - does something to exit demo mode
sendSysex([0xf0, 0x00, 0x20, 0x7f, 0x03, 0x01, 0xf7]);
sendSysex([0xf0, 0x00, 0x20, 0x7f, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7]);
sendSysex([0xf0, 0x7e, 0x00, 0x06, 0x01, 0xf7]);
// effects
MixtrackPlatinumFX.effects = new components.ComponentContainer();
MixtrackPlatinumFX.effects[1] = new MixtrackPlatinumFX.EffectUnit([1, 3]);
MixtrackPlatinumFX.effects[2] = new MixtrackPlatinumFX.EffectUnit([2, 4]);
// decks
MixtrackPlatinumFX.decks = new components.ComponentContainer();
MixtrackPlatinumFX.decks[1] = new MixtrackPlatinumFX.Deck(1, 0x00, MixtrackPlatinumFX.effects[1]);
MixtrackPlatinumFX.decks[2] = new MixtrackPlatinumFX.Deck(2, 0x01, MixtrackPlatinumFX.effects[2]);
MixtrackPlatinumFX.decks[3] = new MixtrackPlatinumFX.Deck(3, 0x02, MixtrackPlatinumFX.effects[1]);
MixtrackPlatinumFX.decks[4] = new MixtrackPlatinumFX.Deck(4, 0x03, MixtrackPlatinumFX.effects[2]);
// set up two banks of samplers, 4 samplers each
MixtrackPlatinumFX.sampler_all = new components.ComponentContainer();
MixtrackPlatinumFX.sampler_all[1] = new MixtrackPlatinumFX.Sampler(1);
MixtrackPlatinumFX.sampler_all[2] = new MixtrackPlatinumFX.Sampler(5);
MixtrackPlatinumFX.sampler = MixtrackPlatinumFX.sampler_all[1];
MixtrackPlatinumFX.sampler_all[2].forEachComponent(function(component) {
component.disconnect();
});
// headphone gain
MixtrackPlatinumFX.head_gain = new MixtrackPlatinumFX.HeadGain(MixtrackPlatinumFX.sampler_all);
// initialize some leds
MixtrackPlatinumFX.effects.forEachComponent(function (component) {
component.trigger();
});
MixtrackPlatinumFX.decks.forEachComponent(function (component) {
component.trigger();
});
MixtrackPlatinumFX.browse = new MixtrackPlatinumFX.BrowseKnob();
// helper functions
var led = function(group, key, midi_channel, midino) {
if (engine.getValue(group, key)) {
midi.sendShortMsg(0x90 | midi_channel, midino, 0x7F);
}
else {
midi.sendShortMsg(0x80 | midi_channel, midino, 0x00);
}
};
// init a bunch of channel specific leds
for (var i = 0; i < 4; ++i) {
var group = "[Channel"+(i+1)+"]";
// keylock indicator
led(group, 'keylock', i, 0x0D);
// turn off bpm arrows
midi.sendShortMsg(0x80 | i, 0x0A, 0x00); // down arrow off
midi.sendShortMsg(0x80 | i, 0x09, 0x00); // up arrow off
// slip indicator
led(group, 'slip_enabled', i, 0x0F);
// initialize wheel mode (and leds)
MixtrackPlatinumFX.wheel[i] = EnableWheel;
midi.sendShortMsg(0x90 | i, 0x07, EnableWheel ? 0x7F : 0x01);
}
// zero vu meters
midi.sendShortMsg(0xBF, 0x44, 0);
midi.sendShortMsg(0xBF, 0x45, 0);
// setup elapsed/remaining tracking
engine.makeConnection("[Controls]", "ShowDurationRemaining", MixtrackPlatinumFX.timeElapsedCallback);
// setup vumeter tracking
engine.makeConnection("[Channel1]", "VuMeter", MixtrackPlatinumFX.vuCallback);
engine.makeConnection("[Channel2]", "VuMeter", MixtrackPlatinumFX.vuCallback);
engine.makeConnection("[Channel3]", "VuMeter", MixtrackPlatinumFX.vuCallback);
engine.makeConnection("[Channel4]", "VuMeter", MixtrackPlatinumFX.vuCallback);
engine.makeConnection("[Master]", "VuMeterL", MixtrackPlatinumFX.vuCallback);
engine.makeConnection("[Master]", "VuMeterR", MixtrackPlatinumFX.vuCallback);
};
MixtrackPlatinumFX.shutdown = function() {
// note: not all of this appears to be strictly necessary, things work fine
// with out this, but Serato has been observed sending these led reset
// messages during shutdown. The last sysex message may be necessary to
// re-enable demo mode.
// turn off a bunch of channel specific leds
for (var i = 0; i < 4; ++i) {
// pfl/cue button leds
midi.sendShortMsg(0x90 | i, 0x1B, 0x01);
// loop leds
midi.sendShortMsg(0x80 | i + 5, 0x32, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x33, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x34, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x35, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x38, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x39, 0x00);
// play leds
midi.sendShortMsg(0x90 | i, 0x00, 0x01);
midi.sendShortMsg(0x90 | i, 0x04, 0x01);
// sync leds
midi.sendShortMsg(0x90 | i, 0x00, 0x02);
midi.sendShortMsg(0x90 | i, 0x04, 0x03);
// cue leds
midi.sendShortMsg(0x90 | i, 0x00, 0x01);
midi.sendShortMsg(0x90 | i, 0x04, 0x05);
// hotcue leds
midi.sendShortMsg(0x80 | i + 5, 0x18, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x19, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x1A, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x1B, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x20, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x21, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x22, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x23, 0x00);
// auto-loop leds
midi.sendShortMsg(0x80 | i + 5, 0x14, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x15, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x16, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x17, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x1C, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x1D, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x1E, 0x00);
midi.sendShortMsg(0x80 | i + 5, 0x1F, 0x00);
// update spinner and position indicator
midi.sendShortMsg(0xB0 | i, 0x3F, 0);
midi.sendShortMsg(0xB0 | i, 0x06, 0);
// keylock indicator
midi.sendShortMsg(0x80 | i, 0x0D, 0x00);
// turn off bpm arrows
midi.sendShortMsg(0x80 | i, 0x0A, 0x00); // down arrow off
midi.sendShortMsg(0x80 | i, 0x09, 0x00); // up arrow off
// turn off slip indicator
midi.sendShortMsg(0x80 | i, 0x0F, 0x00);
// turn off wheel button leds
midi.sendShortMsg(0x80 | i, 0x07, 0x00);
}
// dim FX leds
midi.sendShortMsg(0x98, 0x00, 0x01);
midi.sendShortMsg(0x98, 0x01, 0x01);
midi.sendShortMsg(0x98, 0x02, 0x01);
midi.sendShortMsg(0x99, 0x00, 0x01);
midi.sendShortMsg(0x99, 0x01, 0x01);
midi.sendShortMsg(0x99, 0x02, 0x01);
// turn off sampler leds
midi.sendShortMsg(0x8F, 0x21, 0x00);
midi.sendShortMsg(0x8F, 0x22, 0x00);
midi.sendShortMsg(0x8F, 0x23, 0x00);
midi.sendShortMsg(0x8F, 0x24, 0x00);
// zero vu meters
midi.sendShortMsg(0xBF, 0x44, 0);
midi.sendShortMsg(0xBF, 0x45, 0);
// send final shutdown message
var byteArray = [0xF0, 0x00, 0x20, 0x7F, 0x02, 0xF7];
midi.sendSysexMsg(byteArray, byteArray.length);
};
MixtrackPlatinumFX.EffectUnit = function (unitNumbers) {
var eu = this;
this.unitNumbers = unitNumbers;
this.setCurrentUnit = function (newNumber) {
this.currentUnitNumber = newNumber;
this.group = '[EffectRack1_EffectUnit' + newNumber + ']';
this.reconnectComponents(function (component) {
// update [EffectRack1_EffectUnitX] groups
var unitMatch = component.group.match(script.effectUnitRegEx);
if (unitMatch !== null) {
component.group = eu.group;
} else {
// update [EffectRack1_EffectUnitX_EffectY] groups
var effectMatch = component.group.match(script.individualEffectRegEx);
if (effectMatch !== null) {
component.group = '[EffectRack1_EffectUnit' +
eu.currentUnitNumber +
'_Effect' + effectMatch[2] + ']';
}
}
});
};
this.setCurrentUnit(unitNumbers[0]);
this.dryWetKnob = new components.Encoder({
group: this.group,
inKey: 'mix',
input: function (channel, control, value, status, group) {
if (value === 1) {
this.inSetParameter(this.inGetParameter() + 0.05);
} else if (value === 127) {
this.inSetParameter(this.inGetParameter() - 0.05);
}
},
});
this.EffectUnitTouchStrip = function() {
components.Pot.call(this);
this.firstValueRecived = true;
this.connect();
};
this.EffectUnitTouchStrip.prototype = new components.Pot({
relative: true, // this disables soft takeover
input: function (channel, control, value, status, group) {
// never do soft takeover when the touchstrip is used
engine.softTakeover(this.group, this.inKey, false);
components.Pot.prototype.input.call(this, channel, control, value, status, group);
},
connect: function() {
this.focus_connection = engine.makeConnection(eu.group, "focused_effect", this.onFocusChange);
this.focus_connection.trigger();
},
disconnect: function() {
this.focus_connection.disconnect();
},
onFocusChange: function(value, group, control) {
if (value === 0) {
this.group = eu.group;
this.inKey = 'super1';
}
else {
this.group = '[EffectRack1_EffectUnit' + eu.currentUnitNumber + '_Effect' + value + ']';
this.inKey = 'meta';
}
},
});
this.BpmTapButton = function () {
this.group = '[Channel' + eu.currentUnitNumber + ']';
this.midi = [0x97 + eu.currentUnitNumber, 0x04];
components.Button.call(this);
};
this.BpmTapButton.prototype = new components.Button({
type: components.Button.prototype.types.push,
key: 'bpm_tap',
off: 0x01,
connect: function () {
this.group = '[Channel' + eu.currentUnitNumber + ']';
components.Button.prototype.connect.call(this);
},
input: function (channel, control, value, status, group) {
components.Button.prototype.input.call(this, channel, control, value, status, group);
if (this.isPress(channel, control, value, status)) {
eu.forEachComponent(function (component) {
if (component.tap !== undefined && typeof component.tap === 'function') {
component.tap();
}
});
}
else {
eu.forEachComponent(function (component) {
if (component.untap !== undefined) {
component.untap();
}
});
}
},
});
this.EffectEnableButton = function (number) {
this.number = number;
this.group = '[EffectRack1_EffectUnit' + eu.currentUnitNumber +
'_Effect' + this.number + ']';
this.midi = [0x97 + eu.currentUnitNumber, this.number - 1];
this.flash_timer = null;
components.Button.call(this);
};
this.EffectEnableButton.prototype = new components.Button({
type: components.Button.prototype.types.powerWindow,
outKey: 'enabled',
inKey: 'enabled',
off: 0x01,
tap: function() {
this.inKey = 'enabled';
this.type = components.Button.prototype.types.toggle;
this.inToggle = this.toggle_focused_effect;
},
untap: function() {
this.type = components.Button.prototype.types.powerWindow;
this.inToggle = components.Button.prototype.inToggle;
},
shift: function() {
this.inKey = 'next_effect';
this.type = components.Button.prototype.types.push;
},
unshift: function() {
this.inKey = 'enabled';
this.type = components.Button.prototype.types.powerWindow;
},
output: function(value, group, control) {
var focused_effect = engine.getValue(eu.group, "focused_effect");
if (focused_effect !== this.number) {
engine.stopTimer(this.flash_timer);
this.flash_timer = null;
components.Button.prototype.output.call(this, value, group, control);
}
else {
this.startFlash();
}
},
toggle_focused_effect: function() {
if (engine.getValue(eu.group, "focused_effect") === this.number) {
engine.setValue(eu.group, "focused_effect", 0);
}
else {
engine.setValue(eu.group, "focused_effect", this.number);
}
},
connect: function() {
components.Button.prototype.connect.call(this);
this.fx_connection = engine.makeConnection(eu.group, "focused_effect", this.onFocusChange);
},
disconnect: function() {
components.Button.prototype.disconnect.call(this);
this.fx_connection.disconnect();
},
onFocusChange: function(value, group, control) {
if (value === this.number) {
this.startFlash();
}
else {
this.stopFlash();
}
},
startFlash: function() {
// already flashing
if (this.flash_timer) {
engine.stopTimer(this.flash_timer);
}
this.flash_state = false;
this.send(this.on);
var time = 500;
if (this.inGetValue() > 0) {
time = 150;
}
var button = this;
this.flash_timer = engine.beginTimer(time, function() {
if (button.flash_state) {
button.send(button.on);
button.flash_state = false;
}
else {
button.send(button.off);
button.flash_state = true;
}
});
},
stopFlash: function() {
engine.stopTimer(this.flash_timer);
this.flash_timer = null;
this.trigger();
},
});
this.show_focus_connection = engine.makeConnection(eu.group, "focused_effect", function(focused_effect, group, control) {
if (focused_effect === 0) {
engine.setValue(eu.group, "show_focus", 0);
if (ShowFocusedEffectParameters) {
engine.setValue(eu.group, "show_parameters", 0);
}
} else {
engine.setValue(eu.group, "show_focus", 1);
if (ShowFocusedEffectParameters) {
engine.setValue(eu.group, "show_parameters", 1);
}
}
});
this.show_focus_connection.trigger();
this.touch_strip = new this.EffectUnitTouchStrip();
this.enableButtons = new components.ComponentContainer();
for (var n = 1; n <= 3; n++) {
this.enableButtons[n] = new this.EffectEnableButton(n);
}
this.bpmTap = new this.BpmTapButton();
this.enableButtons.reconnectComponents();
this.forEachComponent(function (component) {
if (component.group === undefined) {
component.group = eu.group;
}
});
};
MixtrackPlatinumFX.EffectUnit.prototype = new components.ComponentContainer();
MixtrackPlatinumFX.Deck = function(number, midi_chan, effects_unit) {
var deck = this;
var eu = effects_unit;
this.active = (number == 1 || number == 2);
components.Deck.call(this, number);
this.bpm = new components.Component({
outKey: "bpm",
output: function(value, group, control) {
MixtrackPlatinumFX.sendScreenBpmMidi(number, Math.round(value * 100));
},
});
this.duration = new components.Component({
outKey: "duration",
output: function(duration, group, control) {
// update duration
MixtrackPlatinumFX.sendScreenDurationMidi(number, duration * 1000);
// when the duration changes, we need to update the play position
deck.position.trigger();
},
});
this.position = new components.Component({
outKey: "playposition",
output: function(playposition, group, control) {
// the controller appears to expect a value in the range of 0-52
// representing the position of the track. Here we send a message to the
// controller to update the position display with our current position.
var pos = Math.round(playposition * 52);
if (pos < 0) {
pos = 0;
}
midi.sendShortMsg(0xB0 | midi_chan, 0x3F, pos);
// get the current duration
duration = deck.duration.outGetValue();
// update the time display
var time = MixtrackPlatinumFX.timeMs(number, playposition, duration);
MixtrackPlatinumFX.sendScreenTimeMidi(number, time);
// update the spinner (range 64-115, 52 values)
//
// the visual spinner in the mixxx interface takes 1.8 seconds to loop
// (60 seconds/min divided by 33 1/3 revolutions per min)
var period = 60 / (33+1/3);
var midiResolution = 52; // the controller expects a value range of 64-115
var timeElapsed = duration * playposition;
var spinner = Math.round(timeElapsed % period * (midiResolution / period));
if (spinner < 0) {
spinner += 115;
} else {
spinner += 64;
}
midi.sendShortMsg(0xB0 | midi_chan, 0x06, spinner);
},
});
this.play_button = new components.PlayButton({
midi: [0x90 + midi_chan, 0x00],
off: 0x01,
sendShifted: true,
shiftControl: true,
shiftOffset: 4,
unshift: function() {
components.PlayButton.prototype.unshift.call(this);
this.type = components.Button.prototype.types.toggle;
},
shift: function() {
this.inKey = 'play_stutter';
this.type = components.Button.prototype.types.push;
},
});
this.load = new components.Button({
inKey: 'LoadSelectedTrack',
shift: function() {
if (ShiftLoadEjects) {
this.inKey = 'eject';
}
else {
this.inKey = 'LoadSelectedTrackAndPlay';
}
},
unshift: function() {
this.inKey = 'LoadSelectedTrack';
},
});
this.cue_button = new components.CueButton({
midi: [0x90 + midi_chan, 0x01],
off: 0x01,
sendShifted: true,
shiftControl: true,
shiftOffset: 4,
});
this.sync_button = new components.SyncButton({
midi: [0x90 + midi_chan, 0x02],
off: 0x01,
sendShifted: true,
shiftControl: true,
shiftOffset: 1,
});
this.pfl_button = new components.Button({
midi: [0x90 + midi_chan, 0x1B],
key: 'pfl',
off: 0x01,
type: components.Button.prototype.types.toggle,
connect: function() {
components.Button.prototype.connect.call(this);
this.connections[1] = engine.makeConnection(this.group, this.outKey, MixtrackPlatinumFX.pflToggle);
},
});
this.hotcue_buttons = new components.ComponentContainer();
this.sampler_buttons = new components.ComponentContainer();
for (var i = 1; i <= 4; ++i) {
this.hotcue_buttons[i] = new components.HotcueButton({
midi: [0x94 + midi_chan, 0x18 + i - 1],
number: i,
sendShifted: true,
shiftControl: true,
shiftOffset: 8,
});
// sampler buttons 5-8
this.sampler_buttons[i] = new components.SamplerButton({
midi: [0x94 + midi_chan, 0x18 + i - 1],
sendShifted: true,
shiftControl: true,
shiftOffset: 8,
number: i+4,
loaded: 0x00,
playing: 0x7F,
});
}
this.hotcues = this.hotcue_buttons;
this.pitch = new components.Pot({
inKey: 'rate',
invert: true,
});
if (!this.active) {
this.pitch.firstValueReceived = true;
}
var pitch_or_keylock = function (channel, control, value, status, group) {
if (this.other.inGetValue() > 0.0 && this.isPress(channel, control, value, status)) {
// toggle keylock, both keys pressed
script.toggleControl(this.group, "keylock");
}
else {
components.Button.prototype.input.call(this, channel, control, value, status, group);
}
};
this.pitch_bend_up = new components.Button({
inKey: 'rate_temp_up',
input: pitch_or_keylock,
});
this.pitch_bend_down = new components.Button({
inKey: 'rate_temp_down',
input: pitch_or_keylock,
});
this.pitch_bend_up.other = this.pitch_bend_down;
this.pitch_bend_down.other = this.pitch_bend_up;
var key_up_or_down = function (channel, control, value, status, group) {
this.is_pressed = this.isPress(channel, control, value, status);
if (this.is_pressed) {
if (this.other.is_pressed) {
// reset if both buttons are pressed
engine.setValue(deck.currentDeck, "pitch_adjust", 0.0);
}
else {
this.inSetValue(1.0);
}
}
};
this.key_up = new components.Button({
inKey: 'pitch_up',
direction: 1,
input: key_up_or_down,
});
this.key_down = new components.Button({
inKey: 'pitch_down',
direction: -1,
input: key_up_or_down,
});
this.key_up.other = this.key_down;
this.key_down.other = this.key_up;
loop_base = function(midino, obj) {
return _.assign({
midi: [0x94 + midi_chan, midino],
on: 0x01,
sendShifted: true,
shiftChannel: true,
shiftOffset: -0x10,
}, obj);
};
this.alternate_manloop = new components.ComponentContainer({
loop_in: new components.HotcueButton(loop_base(0x38, {
number: 5,
})),
loop_out: new components.HotcueButton(loop_base(0x39, {
number: 6,
})),
loop_toggle: new components.HotcueButton(loop_base(0x32, {
number: 7,
})),
// there are two hotcue 8 controls, one for the loop_halve button and
// one for the loop_double button. These buttons are two individual
// functions when in manual loop mode, but they behave as one button
// in hotcue mode.
loop_halve: new components.HotcueButton(loop_base(0x34, {
number: 8,
})),
loop_double: new components.HotcueButton(loop_base(0x35, {
number: 8,
})),
});
this.normal_manloop = new components.ComponentContainer({
loop_in: new components.Button(loop_base(0x38, {
inKey: 'loop_in',
outKey: 'loop_start_position',
outValueScale: function (value) {
return (value != -1) ? this.on : this.off;
},
})),
loop_out: new components.Button(loop_base(0x39, {
inKey: 'loop_out',
outKey: 'loop_end_position',
outValueScale: function (value) {
return (value != -1) ? this.on : this.off;
},
})),
loop_toggle: new components.LoopToggleButton(loop_base(0x32, {})),
loop_halve: new components.Button(loop_base(0x34, {
key: 'loop_halve',
input: function(channel, control, value, status) {
if (this.isPress(channel, control, value, status)) {
engine.setValue(deck.currentDeck, "loop_scale", 0.5);
}
},
})),
loop_double: new components.Button(loop_base(0x35, {
key: 'loop_double',
input: function(channel, control, value, status) {
if (this.isPress(channel, control, value, status)) {
engine.setValue(deck.currentDeck, "loop_scale", 2.0);
}
},
})),
});
// swap normal and alternate manual loop controls
if (UseManualLoopAsCue) {
var manloop = this.normal_manloop;
this.normal_manloop = this.alternate_manloop;
this.alternate_manloop = manloop;
}
this.manloop = this.normal_manloop;
auto_loop_hotcue = function(midino, obj) {
return _.assign({
midi: [0x94 + midi_chan, midino],
on: 0x40,
sendShifted: true,
shiftControl: true,
shiftOffset: 0x08,
}, obj);
};
auto_loop_base = function(midino, obj) {
return _.assign({
midi: [0x94 + midi_chan, midino],
on: 0x40,
sendShifted: true,
shiftChannel: true,
shiftOffset: -0x10,
}, obj);
};
this.alternate_autoloop = new components.ComponentContainer({
auto1: new components.HotcueButton(auto_loop_hotcue(0x14, {
number: 5,
})),
auto2: new components.HotcueButton(auto_loop_hotcue(0x15, {
number: 6,
})),
auto3: new components.HotcueButton(auto_loop_hotcue(0x16, {
number: 7,
})),
auto4: new components.HotcueButton(auto_loop_hotcue(0x17, {
number: 8,
})),
});
this.alternate_autoloop.roll1 = this.alternate_autoloop.auto1;
this.alternate_autoloop.roll2 = this.alternate_autoloop.auto2;
this.alternate_autoloop.roll3 = this.alternate_autoloop.auto3;
this.alternate_autoloop.roll4 = this.alternate_autoloop.auto4;
this.normal_autoloop = new components.ComponentContainer({
auto1: new components.Button(auto_loop_base(0x14, {
inKey: 'beatloop_1_toggle',
outKey: 'beatloop_1_enabled',
})),
auto2: new components.Button(auto_loop_base(0x15, {
inKey: 'beatloop_2_toggle',
outKey: 'beatloop_2_enabled',
})),
auto3: new components.Button(auto_loop_base(0x16, {
inKey: 'beatloop_4_toggle',
outKey: 'beatloop_4_enabled',
})),
auto4: new components.Button(auto_loop_base(0x17, {
inKey: 'beatloop_8_toggle',
outKey: 'beatloop_8_enabled',
})),
roll1: new components.Button(auto_loop_base(0x1C, {
inKey: 'beatlooproll_0.0625_activate',
outKey: 'beatloop_0.0625_enabled',
})),
roll2: new components.Button(auto_loop_base(0x1D, {
inKey: 'beatlooproll_0.125_activate',
outKey: 'beatloop_0.125_enabled',
})),
roll3: new components.Button(auto_loop_base(0x1E, {
inKey: 'beatlooproll_0.25_activate',
outKey: 'beatloop_0.25_enabled',
})),
roll4: new components.Button(auto_loop_base(0x1F, {
inKey: 'beatlooproll_0.5_activate',
outKey: 'beatloop_0.5_enabled',
})),
});
// swap normal and alternate auto loop controls
if (UseAutoLoopAsCue) {
var autoloop = this.normal_autoloop;
this.normal_autoloop = this.alternate_autoloop;
this.alternate_autoloop = autoloop;
}
this.autoloop = this.normal_autoloop;
this.pad_mode = new components.Component({
input: function (channel, control, value, status, group) {
// only handle button down events
if (value != 0x7F) return;
var shifted_hotcues = deck.sampler_buttons;
var normal_hotcues = deck.hotcue_buttons;
if (UseCueAsSampler) {
shifted_hotcues = deck.hotcue_buttons;
normal_hotcues = deck.sampler_buttons;
}
// if shifted, set a special mode
if (this.isShifted) {
// manual loop
if (control == 0x0E) {
deck.manloop = deck.alternate_manloop;
deck.manloop.reconnectComponents();
}
// auto loop
else if (control == 0x06) {
deck.autoloop = deck.alternate_autoloop;
deck.autoloop.reconnectComponents();
}
// hotcue sampler
if (control == 0x0B) {
deck.hotcues.forEachComponent(function(component) {
component.disconnect();
});
deck.hotcues = shifted_hotcues;
deck.hotcues.reconnectComponents();
}
// reset hotcues in all other modes
else {
deck.hotcues.forEachComponent(function(component) {
component.disconnect();
});
deck.hotcues = deck.hotcue_buttons;
deck.hotcues.reconnectComponents();
}
}
// otherwise set a normal mode
else {
// manual loop
if (control == 0x0E) {
deck.manloop = deck.normal_manloop;
deck.manloop.reconnectComponents();
}
// auto loop
else if (control == 0x06) {
deck.autoloop = deck.normal_autoloop;
deck.autoloop.reconnectComponents();
}
// hotcue sampler
if (control == 0x0B) {
deck.hotcues.forEachComponent(function(component) {
component.disconnect();
});
deck.hotcues = normal_hotcues;
deck.hotcues.reconnectComponents();
}
// reset hotcues
else {
deck.hotcues.forEachComponent(function(component) {
component.disconnect();
});
deck.hotcues = deck.hotcue_buttons;
deck.hotcues.reconnectComponents();
}
}
},
shift: function() {
this.isShifted = true;
},
unshift: function() {
this.isShifted = false;
},
});
this.EqEffectKnob = function (group, in_key, fx_key, filter_knob) {
this.unshift_group = group;
this.unshift_key = in_key;
this.fx_key = fx_key;
if (filter_knob) {
this.shift_key = 'super1';
}
this.ignore_next = null;
components.Pot.call(this, {
group: group,
inKey: in_key,
});
};
this.EqEffectKnob.prototype = new components.Pot({
input: function (channel, control, value, status, group) {
// if the control group and key has changed, ignore_next will hold
// the old settings. We need to tell the soft takeover engine to
// ignore the next values for that control so that when we
// eventually switch back to it, soft takeover will manage it
// properly.
//
// We call IgnoreNextValue() here instead of in shift()/unshift()
// (via connect()/disconnect()) because if we did that, pressing
// the shift key would cause the next value on the control to be
// ignored even if the control wasn't moved, which would trigger
// a phantom soft takeover if the control was moved fast enough. We
// only need to IgnoreNextValue() if the control has actually moved
// after switching the target group/key.
if (this.ignore_next) {
engine.softTakeoverIgnoreNextValue(this.ignore_next.group, this.ignore_next.key);
this.ignore_next = null;
}
components.Pot.prototype.input.call(this, channel, control, value, status, group);
},
connect: function() {
// enable soft takeover on our controls
for (var i = 1; i <= 3; i ++) {
var group = '[EffectRack1_EffectUnit' + eu.currentUnitNumber + '_Effect' + i + ']';
engine.softTakeover(group, this.fx_key, true);
}
components.Pot.prototype.connect.call(this);
},
shift: function() {
var focused_effect = engine.getValue(eu.group, "focused_effect");
if (focused_effect === 0) {
// we need this here so that shift+filter works with soft
// takeover because touching the touch strip disables it each
// time
if (this.shift_key) {
engine.softTakeover(eu.group, this.shift_key, true);
this.switchControl(eu.group, this.shift_key);
}
}
else {
var group = '[EffectRack1_EffectUnit' + eu.currentUnitNumber + '_Effect' + focused_effect + ']';
this.switchControl(group, this.fx_key);
}
},
unshift: function() {
this.switchControl(this.unshift_group, this.unshift_key);
},
switchControl: function(group, key) {
if (this.group != group || this.inKey != key) {
this.ignore_next = { 'group': this.group, 'key': this.inKey };
}
this.group = group;
this.inKey = key;
},
});
var eq_group = '[EqualizerRack1_' + this.currentDeck + '_Effect1]';
this.high_eq = new this.EqEffectKnob(eq_group, 'parameter3', 'parameter3');
this.mid_eq = new this.EqEffectKnob(eq_group, 'parameter2', 'parameter4');
this.low_eq = new this.EqEffectKnob(eq_group, 'parameter1', 'parameter5');
this.filter = new this.EqEffectKnob(
'[QuickEffectRack1_' + this.currentDeck + ']',
'super1',
'parameter1',
true);
this.gain = new this.EqEffectKnob(
this.currentDeck,
'pregain',
'parameter2');
this.reconnectComponents(function (c) {
if (c.group === undefined) {
c.group = deck.currentDeck;
}
});
// don't light up sampler buttons in hotcue mode
this.sampler_buttons.forEachComponent(function(component) {
component.disconnect();
});
this.setActive = function(active) {
this.active = active;
if (!active) {
// trigger soft takeover on the pitch control
this.pitch.disconnect();
}
};
};
MixtrackPlatinumFX.Deck.prototype = new components.Deck();
MixtrackPlatinumFX.Sampler = function(base) {
for (var i = 1; i <= 4; ++i) {