-
Notifications
You must be signed in to change notification settings - Fork 0
/
numark_mixtrack_pro_3_henrizo.js
2032 lines (1759 loc) · 73.2 KB
/
numark_mixtrack_pro_3_henrizo.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
/***********************************************************************
* ============== Configuration Options =================
* valid values are "true" or "false" unless specified
**********************************************************************/
// TrackEndWarning: "true": when you reach the end of the track,
// the jog wheel Button will flash. "false": No flash of Jog Wheel Button
var TrackEndWarning = true;
//iCutEnabled: iCut mode will automatically cut your track with the cross fader
// when SHIFT enabled and scratching with the jog wheel
var iCutEnabled = true;
//activate PFL of deck on track load
var smartPFL = true;
//Disable Play on Sync button Double Press
var noPlayOnSyncDoublePress = false;
// Shift+Filter control behavior
// true (default) - FX parameter 4 (when the FX is focused)
// false - Channel Gain
var ShiftFilterFX4 = true;
// allow pitch bend with wheel when wheel is not active
var PitchBendOnWheelOff = true;
/**************************
* scriptpause
* ---------------
* period (in ms) while the script will be paused when sending messages
* to the controller in order to avoid too much data flow at once in the same time.
* - default value : 5 ms
* - To disable : 0;
**************************/
var scriptpause = 0;
/**************************
* Constants for scratching :
**************************/
var intervalsPerRev = 1200;
var rpm = 33 + 1 / 3; // Like a real vinyl !!! :)
var alpha = 1.0 / 8; // Adjust to suit.
var beta = alpha / 32; // Adjust to suit.
/**************************
* Loop Size array
* first 4 values used for Autoloop Not shifted
* last 4 values used for Autoloop Shifted
**************************/
var loopsize = [2, 4, 8, 16, 0.125, 0.25, 0.5, 1];
/************************ GPL v2 licence *****************************
* Numark Mixtrack Pro 3 controller script (Henrizo mod)
* Author: Stéphane Morin
* Modified by: Radu Suciu, Henrizo
*
* Key features
* ------------
* - ICUT effect for scratching
* - Fader Start
* - press/double press/long press handling
* - Smart PFL
* - 4 deck support
* - Full effect chains support from Deere Skin
**********************************************************************
* User References
* ---------------
* Wiki/manual : http://mixxx.org/wiki/doku.php/numark_mixtrack_pro_3
* Scripting manual: https://www.mixxx.org/wiki/doku.php/midi_scripting
* https://www.mixxx.org/wiki/doku.php/mixxxcontrols
* e-mail : [email protected], [email protected]
*
* Thanks
* ----------------
* Thanks to Chloé AVRILLON (DJ Chloé) and authors of other scripts and particularly
* to authors of Numark Dj2Go, KANE QuNeo, Vestax-VCI-400
*
* Revision history
* ----------------
* 2016-01-12 (V0.9) to 2016-01-15 (1.0 beta 3) - Chloé AVRILLON
* 2016-02-17 (1.0 beta 4) 2016-04-08 (V1.3 )- Stéphane Morin
* 2016-04-08 (1.3) - Stéphane Morin - https://github.com/mixxxdj/mixxx/pull/905
* 2016-09-14 (1.31) - Stefan Mikolajczyk - https://github.com/mixxxdj/mixxx/pull/1012
* 2016-04-08 (1.4) to 2017-01-05 (2.2) - Stéphane Morin - https://github.com/mixxxdj/mixxx/pull/1014
* 2017-02-10 (2.3) - Radu Suciu - https://github.com/mixxxdj/mixxx/pull/1180
* 2018-01-20 (2.4) - NTMusic - Shift+Filter can control either FX4 or channel gain
*
** Henrizo mods (https://github.com/henrizo-configs/mixxx) :
** --------------------------------------------------------
** I decided to mod this config file so the controller adjusts to my needs and style. Of course,
** I'm standing in the shoulders of giants here. Thanks again to all the folks above.
*
* 2019-12-17 (V0) - Shift + reloop_exit : activates beatloop
- Effects are focused with TAP + FX_ and activated with FX, unlike the original file,
which inverts these controls.
- The top corners pitch bend buttons sets the pitch (independent of the tempo) up or down,
- and pressing Shift with these buttons resets the pitch.
***********************************************************************
* GPL v2 licence
* --------------
* Numark Mixtrack Pro 3 controller script 2.4 for Mixxx 2.1+
* Copyright (C) 2016 Stéphane Morin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***********************************************************************/
////////////////////////////////////////////////////////////////////////
// JSHint configuration //
////////////////////////////////////////////////////////////////////////
/* global engine */
/* global print */
/* global midi */
/* global script */
/* jshint sub:true */
/* jshint shadow:true */
////////////////////////////////////////////////////////////////////////
var NumarkMixtrack3 = {
group: '[Master]',
decks: [],
samplers: []
};
// Array of Objects can be created
// Global constants/variables
var ON = 0x7F,
OFF = 0x00,
DOWN = 0x7F;
var QUICK_PRESS = 1,
DOUBLE_PRESS = 2,
LONG_PRESS = 3;
//LEDs constants
var ledCategories = {
"master": 0,
"channel1": 1,
"channel2": 2,
"meters": 32
};
var leds = {
// Master: all are first byte 0x90 ( = 0x90+ledcatecories.master )
"headphones1": 0x0e,
"headphones2": 0x0f,
"all": 0x75,
// Deck 1: first byte 0x91 ( = 0x90+ledcatecories.channel1 = 0x90+1 )
// Deck 2: first byte 0x92 ( = 0x90+ledcatecories.channel2 = 0x90+2 )
"jogWheelsInScratchMode": 0x06,
"loopin": 0x13,
"loopout": 0x14,
"reloopExit": 0x15,
"loopHalve": 0x16,
"hotCue1": 0x1b,
"hotCue2": 0x1c,
"hotCue3": 0x1d,
"hotCue4": 0x1e,
"cue": 0x03,
"sync": 0x02,
"play": 0x01,
"fx1": 0x07,
"fx2": 0x08,
"fx3": 0x09,
"tap": 0x0a,
"padLoop1": 0x17,
"padLoop2": 0x18,
"padLoop3": 0x19,
"padLoop4": 0x1A,
"padSampler1": 0x20,
"padSampler2": 0x21,
"padSampler3": 0x22,
"padSampler4": 0x23,
"padSampler5": 0x20,
"padSampler6": 0x21,
"padSampler7": 0x22,
"padSampler8": 0x23,
// Meters: first byte 0xb0 ( = 0x90+ledcatecories.meters )
"meter1": 0x02,
"meter2": 0x03
};
var PADcolors = {
"black": 0,
"blue": 32,
"yellow": 96,
"purple": 127
};
// Utilities
// =====================================================================
function pauseScript(ms) {
if (ms > 0) {
var startDate = new Date();
var currentDate = null;
while (currentDate - startDate < ms) {
currentDate = new Date();
}
}
}
Math.sign = Math.sign || function(x) {
x = +x; // convert the parameter into a number
if (x === 0 || isNaN(x)) {
return x;
}
return x > 0 ? 1 : -1;
};
function sendShortMsg(control, midino, value) {
midi.sendShortMsg(control, midino, value);
}
function parameterSoftTakeOver(group, control, value) {
var threshold = 0.07; //on the CMD Studio 4a this threshold got the right balance
//between smooth takeover and keeping up with quick turns, but you can adjust the value to suit your needs
var currentKnobVal = value / 127;
var currentParamVal = engine.getParameter(group, control);
var spread = Math.abs(currentParamVal - currentKnobVal);
if (spread < threshold) {
engine.setParameter(group, control, currentKnobVal); //set the new value
} else {
return; //do nothing until we get close
}
}
// =====================================================================
// Reusable Objects (special buttons handling, LEDs, iCUT and Jog wheels)
// =====================================================================
// LED class object
var LED = function(control, midino) {
this.control = control;
this.midino = midino;
this.lit = 0;
this.flashTimer = 0;
this.flashTimer2 = 0;
this.flashOnceTimer = 0;
this.flashDuration = 0;
this.flashOnceDuration = 0;
this.num_ms_on = 0;
this.valueon = 0;
this.num_ms_off = 0;
this.flashCount = 0;
this.relight = 0;
this.valueoff = 0;
};
// public : light on/off
LED.prototype.onOff = function(value) {
// stop pending flashing effects now
if (this.flashTimer !== 0) {
engine.stopTimer(this.flashTimer);
this.flashTimer = 0;
this.flashDuration = 0;
}
if (this.flashTimer2 !== 0) {
engine.stopTimer(this.flashTimer2);
this.flashTimer2 = 0;
this.flashDuration = 0;
}
if (this.flashOnceTimer !== 0) {
engine.stopTimer(this.flashOnceTimer);
this.flashOnceTimer = 0;
this.flashOnceDuration = 0;
}
sendShortMsg(this.control, this.midino, value);
pauseScript(scriptpause);
this.lit = value;
};
// public : make a light flashing
// ------------------------------
// num_ms_on : number of ms the light should stay enlighted when blinking
// value : value to send to the controller to lit it up,
// generally 0x00 means OFF, 0x7F means ON, but the light
// can receive some other values if it can have various colors
// num_ms_off : number of ms the light should be switched off when blinking
// flashcount : number of time the light should blink (3 times ? 10 times ? only once (1) ?
// if set to 0 or not set, flashes for ever, can be stopped with flashOff()
// relight : once the light has finished to blink, should we restore it in its original state (true) or must it be switched off (false).
// if not set, it considers it as a switch off (default=false)
// valueoff : like "value". That permits for instance with two colors (once red(on), once blue(off), once red(on), etc...)
LED.prototype.flashOn = function(num_ms_on, value, num_ms_off, flashCount, relight, valueoff) {
// stop pending timers
this.flashOff();
// init
this.flashDuration = num_ms_on;
this.num_ms_on = num_ms_on;
this.valueon = value;
this.num_ms_off = num_ms_off;
this.flashCount = flashCount;
this.relight = relight;
this.valueoff = valueoff;
// 1st flash
// This is because the permanent timer below takes
// num_ms_on milisecs before first flash.
this.flashOnceOn(num_ms_on, value);
if (flashCount !== 1) {
// flashcount == 0 means permanent flash,
// flashcount > 0 , means temporary flash, first flash already done,
// so we don't need this part if flashcount == 1
// permanent timer
this.flashTimer = engine.beginTimer(num_ms_on + num_ms_off, function() {
this.flashOnceOn(false);
});
}
if (flashCount > 1) {
// flashcount>0 , means temporary flash, first flash already done,
// so we don't need this part if flashcount=1
// temporary timer. The end of this timer stops the permanent flashing
this.flashTimer2 = engine.beginTimer(flashCount * (num_ms_on + num_ms_off) - num_ms_off, function() {
this.stopflash(relight);
}, true);
}
};
// private : relight=true : restore light state before it was flashing
// this is a call back function (called in flashon() )
LED.prototype.flashOff = function(relight) {
// stop permanent timer if any
if (this.flashTimer !== 0) {
engine.stopTimer(this.flashTimer);
// reset flash variables to 0
this.flashTimer = 0;
}
if (this.flashTimer2 !== 0) {
engine.stopTimer(this.flashTimer2);
// reset flash variables to 0
this.flashTimer2 = 0;
}
this.flashDuration = 0;
if (relight) {
this.onOff(this.lit);
} else {
this.onOff(OFF);
}
};
// private : relight=true : restore light state before it was flashing
// this is a call back function (called in flashon() )
LED.prototype.stopflash = function(relight) {
// stop permanent timer
if (this.flashTimer !== 0) {
engine.stopTimer(this.flashTimer);
}
// reset flash variables to 0
this.flashTimer = 0;
this.flashTimer2 = 0;
this.flashDuration = 0;
this.flashOff(relight);
};
// private : call back function (called in flashon() )
LED.prototype.flashOnceOn = function(relight) {
sendShortMsg(this.control, this.midino, this.valueon);
pauseScript(scriptpause);
this.flashOnceDuration = this.num_ms_on;
this.flashOnceTimer = engine.beginTimer(this.num_ms_on - scriptpause, function() {
this.flashOnceOff(relight);
}, true);
};
// private :call back function (called in flashOnceOn() )
LED.prototype.flashOnceOff = function(relight) {
this.flashOnceTimer = 0;
this.flashOnceDuration = 0;
if (relight) {
sendShortMsg(this.control, this.midino, this.lit);
pauseScript(scriptpause);
} else {
sendShortMsg(this.control, this.midino, this.valueoff);
pauseScript(scriptpause);
this.lit = OFF;
}
};
// ********* special buttons handlers (SHIFT ,LOAD, PFL and SYNC buttons)
// ======================= SingleDoubleBtn
// callback : Callback function you have to provide (see end of
// the code), that will return the original event
// parameters (channel, control, value, status, group)
// and the kind of press event affecting your button
// (eventkind).
// This callback will be triggered as soon as you
// press the button a second time (Value will be
// equal to DOWN), or the Long press is asserted
// (value = DOWN because you are still holding down
// the button or value=UP because you have released
// the button only once before it becomes a long press).
// doublePressTimeOut : delay in ms above which a second press on the
// button will not be considered as a potential double
// but as a new press cycle event (default = 400ms).
var SingleDoubleBtn = function(callback, doublePressTimeOut) {
this.channel = 0;
this.control = 0;
this.value = 0;
this.status = 0;
this.group = "";
this.callback = callback;
this.doublePressTimeOut = doublePressTimeOut || 400;
this.buttonCount = 0;
this.buttonTimer = 0;
};
// Button pressed
SingleDoubleBtn.prototype.buttonDown = function(channel, control, value, status, group) {
this.channel = channel;
this.control = control;
this.value = value;
this.status = status;
this.group = group;
if (this.buttonTimer === 0) { // first press
this.buttonTimer = engine.beginTimer(this.doublePressTimeOut, this.buttonDecide, true);
this.buttonCount = 1;
} else { // 2nd press (before timer's out)
engine.stopTimer(this.buttonTimer);
this.buttonTimer = 0;
this.buttonCount = 2;
this.buttonDecide();
}
};
// Take action
SingleDoubleBtn.prototype.buttonDecide = function() {
this.buttonTimer = 0;
this.callback(this.channel, this.control, this.value, this.status, this.group, this.buttonCount);
this.buttonCount = 0;
};
// ======================= LongShortBtn
// callback : callback function you have to provide (see end of the code), that will return
// the original event parameters (channel, control, value, status, group)
// and the kind of press event affecting your button (eventkind)
// This callback will be called once you release the button
// (Value will be equal to UP). You must provide this parameter.
// longPressThreshold : delay in ms above which a first press on the
// button will be considered as a Long press (default = 500ms).
// This parameter is optional.
// callBackOKLongPress : This callback will give you the same values than the first one
// but it will be triggered as soon as the Long press is taken
// into account ( at this moment, value = DOWN because you are still
// holding down the button). This permits for instance to lit up a light indicating
// the user that he/she can release the button. This callback occurs before the first one.
// This parameter is optional.
// Like that, you can decide to put the code for the long press in either callback function
var LongShortBtn = function(callback, longPressThreshold, callBackOKLongPress) {
this.callback = callback;
this.channel = 0;
this.control = 0;
this.value = 0;
this.status = 0;
this.group = "";
this.callBackOKLongPress = callBackOKLongPress;
this.longPressThreshold = longPressThreshold || 500;
this.buttonLongPress = false;
this.buttonLongPressTimer = 0;
};
// Timer's call back for long press
LongShortBtn.prototype.buttonAssertLongPress = function() {
this.buttonLongPress = true;
//the timer was stopped, we set it to zero
this.buttonLongPressTimer = 0;
if (typeof this.callBackOKLongPress === "function") {
this.callBackOKLongPress(this.channel, this.control, this.value, this.status, this.group, LONG_PRESS);
}
};
LongShortBtn.prototype.buttonDown = function(channel, control, value, status, group) {
this.channel = channel;
this.control = control;
this.value = value;
this.status = status;
this.group = group;
this.buttonLongPress = false;
this.buttonLongPressTimer = engine.beginTimer(this.longPressThreshold, this.buttonAssertLongPress, true);
};
LongShortBtn.prototype.buttonUp = function() {
if (this.buttonLongPressTimer !== 0) {
engine.stopTimer(this.buttonLongPressTimer);
this.buttonLongPressTimer = 0;
}
if (this.buttonLongPress) {
this.callback(this.channel, this.control, this.value, this.status, this.group, LONG_PRESS);
} else {
this.callback(this.channel, this.control, this.value, this.status, this.group, QUICK_PRESS);
}
};
// ======================= LongShortDoubleBtn
// callback : Callback function you have to provide (see end of
// the code), that will return the original event
// parameters (channel, control, value, status, group)
// and the kind of press event affecting your button
// (eventkind).
// This callback will be triggered as soon as you
// press the button a second time (Value will be
// equal to DOWN), or the Long press is asserted
// (value = DOWN because you are still holding down
// the button or value=UP because you have released
// the button only once before it becomes a long press).
// longPressThreshold : delay in ms above which a first press on the
// button will be considered as a Long press (default = 500ms).
// doublePressTimeOut : delay in ms above which a second press on the
// button will not be considered as a potential double
// but as a new press cycle event (default = 400ms).
var LongShortDoubleBtn = function(callback, longPressThreshold, doublePressTimeOut) {
this.callback = callback;
this.channel = 0;
this.control = 0;
this.value = 0;
this.status = 0;
this.group = "";
this.longPressThreshold = longPressThreshold || 500;
this.doublePressTimeOut = doublePressTimeOut || 400;
this.buttonTimer = 0;
this.buttonLongPress = false;
this.buttonLongPressTimer = 0;
this.buttonCount = 0;
};
// Timer's call back for long press
LongShortDoubleBtn.prototype.buttonAssertLongPress = function() {
this.buttonLongPress = true;
// the timer was stopped, we set it to zero
this.buttonLongPressTimer = 0;
// let's take action of the long press
this.buttonDecide();
};
// Timer's callback for single press/double press
LongShortDoubleBtn.prototype.buttonAssert1Press = function() {
// Short Timer ran out before it was manually stopped by release
// of the button (buttonUp):
// for sure it is a single click (short or long), we will know
// when button will be released or when longtimer will stop by itself
// the timer was stopped, we set it to zero
this.buttonTimer = 0;
this.buttonCount = 1;
if (this.buttonLongPressTimer === 0) {
// long press timer was stopped (short press)
//take action
this.buttonDecide();
}
};
// Button pressed (function called by mapper's code)
LongShortDoubleBtn.prototype.buttonDown = function(channel, control, value, status, group) {
this.channel = channel;
this.control = control;
this.value = value;
this.status = status;
this.group = group;
if (this.buttonCount === 0) { //first press (inits)
// 1st press
this.buttonCount = 1;
// and short press
this.buttonLongPress = false;
this.buttonLongPressTimer = engine.beginTimer(
this.longPressThreshold, this.buttonAssertLongPress, true
);
this.buttonTimer = engine.beginTimer(
this.doublePressTimeOut, this.buttonAssert1Press, true
);
} else if (this.buttonCount === 1) { // 2nd press (before short timer's out)
// stop timers...
if (this.buttonLongPressTimer !== 0) {
engine.stopTimer(this.buttonLongPressTimer);
this.buttonLongPressTimer = 0;
}
// we stopped the timer, we have to set it to zero.
// You must have this reflex : "stopTimer(timer)/timer=0" in mind
// so that you can test later on if it is active or not. Other else
// it's value stays with the one given by engine.beginTimer
// "stopTimer(timer)/timer=0"
if (this.buttonTimer !== 0) {
engine.stopTimer(this.buttonTimer);
this.buttonTimer = 0;
}
// 2nd press
this.buttonCount = 2;
// ...and take action immediately
this.buttonDecide();
} // else :
// 2nd press after short timer's out, this cannot happen,
// do nothing
};
// Button released (function called by mapper's code)
LongShortDoubleBtn.prototype.buttonUp = function() {
// button released
if (this.buttonLongPress === false) {
// long press was not asserted by timer (buttonAssertLongPress)
// Button is released before timer's out
// If first Buttun up, long timer is still running
// stop long timer if it is still running, keep short timer,
// longpress will never happen
if (this.buttonLongPressTimer !== 0) {
engine.stopTimer(this.buttonLongPressTimer);
this.buttonLongPressTimer = 0;
}
} // else :
// longpressed is confirmed, we already took action in buttonAssertLongPress
};
// Take actions and call callback
LongShortDoubleBtn.prototype.buttonDecide = function() {
if (this.buttonLongPressTimer !== 0) {
engine.stopTimer(this.buttonLongPressTimer);
}
this.buttonLongPressTimer = 0;
this.buttonTimer = 0;
if (this.buttonLongPress) {
this.callback(this.channel, this.control, this.value, this.status, this.group, LONG_PRESS);
} else {
if (this.buttonCount === 2) {
this.callback(this.channel, this.control, this.value, this.status, this.group, DOUBLE_PRESS);
} else { // We pressed sync only once
this.callback(this.channel, this.control, this.value, this.status, this.group, QUICK_PRESS);
}
}
// re-init
this.buttonCount = 0;
this.buttonLongPress = false;
};
// *************************************************
// iCut mode management
// *************************************************
// this mode simulates a scratch routine. When the jog wheel is turned back
// the crossfader closes, when the jog wheel is turned forward the crossfader
// will open.
var AutoCut = function(decknum) {
this.decknum = decknum;
this.timer = 0;
this.enabled = false;
};
AutoCut.prototype.On = function() {
if (!this.enabled) {
this.enabled = true;
engine.softTakeover("[Master]", "crossfader", false);
}
};
AutoCut.prototype.FaderCut = function(jogValue, decknum) {
if (this.enabled) {
var direction = Math.sign(jogValue); //Get Jog wheel direction
// Backward=-1 (close), forward =0 (open)
if (direction > 0) {
direction = 0;
}
// Left Deck direction = 0 (open : crossfader to zero) or 1 (close : crossfader to the right)
// Right Deck direction = 0 (open : crossfader to zero) or -1 (close : crossfader to the left)
if (decknum === 1) {
direction = -direction;
} // else direction is of the good sign
engine.setValue('[Master]', 'crossfader', direction);
}
};
AutoCut.prototype.Off = function() {
if (this.enabled) {
this.enabled = false;
engine.setValue('[Master]', 'crossfader', 0);
engine.softTakeover("[Master]", "crossfader", true);
}
};
// *****************************************************************
// Jog wheel management (scratching, bending, ...)
// *************************************************
var Jogger = function(group, decknum) {
this.decknum = decknum;
this.group = group;
this.wheelTouchInertiaTimer = 0;
this.iCUT = new AutoCut(decknum);
};
// ******************************************************************
// Decks
// ******************************************************************
NumarkMixtrack3.deck = function(decknum) {
this.decknum = decknum;
this.group = "[Channel" + decknum + "]";
this.loaded = false;
this.jogWheelsInScratchMode = false;
this.PADMode = false; //false = not pressed; true = pressed
this.shiftKey = false;
this.touch = false;
this.faderstart = false;
this.PitchFaderHigh = 0;
this.lastfadervalue = 0;
this.scratchTimer = 0;
this.seekingfast = false;
this.iCutStatus = false;
this.LEDs = [];
this.TapDown = false;
this.InstantFX = [];
this.Jog = new Jogger(this.group, this.decknum);
this.duration = 0;
engine.setValue('[EffectRack1_EffectUnit' + decknum + ']', 'show_focus', true);
// buttons
this.LoadButtonControl = new LongShortBtn(NumarkMixtrack3.OnLoadButton);
this.SyncButtonControl = new LongShortDoubleBtn(NumarkMixtrack3.OnSyncButton);
this.PADLoopButtonHold = new LongShortBtn(NumarkMixtrack3.onPADLoopButtonHold);
engine.softTakeover(this.group, "rate", true); // Enable soft-takeover for Pitch slider
engine.softTakeover(this.group, "volume", true); // Enable soft-takeover for volume
engine.setParameter(this.group, "volume", 0); // Set volume to zero for each deck (initial load only)
// only have two physical sets of buttons for our 4 virtual decks
var j = (decknum + 1) % 2 + 1;
this.LEDs.headphones = new LED(0x90 + ledCategories.master, leds.headphones1 - 1 + j);
this.LEDs.jogWheelsInScratchMode = new LED(0x90 + j, leds.jogWheelsInScratchMode);
this.LEDs.loopin = new LED(0x90 + j, leds.loopin);
this.LEDs.loopout = new LED(0x90 + j, leds.loopout);
this.LEDs.reloopExit = new LED(0x90 + j, leds.reloopExit);
this.LEDs.loopHalve = new LED(0x90 + j, leds.loopHalve);
this.LEDs.hotCue1 = new LED(0x90 + j, leds.hotCue1);
this.LEDs.hotCue2 = new LED(0x90 + j, leds.hotCue2);
this.LEDs.hotCue3 = new LED(0x90 + j, leds.hotCue3);
this.LEDs.hotCue4 = new LED(0x90 + j, leds.hotCue4);
this.LEDs.cue = new LED(0x90 + j, leds.Cue);
this.LEDs.sync = new LED(0x90 + j, leds.sync);
this.LEDs.play = new LED(0x90 + j, leds.play);
this.LEDs.fx1 = new LED(0x90 + j, leds.fx1);
this.LEDs.fx2 = new LED(0x90 + j, leds.fx2);
this.LEDs.fx3 = new LED(0x90 + j, leds.fx3);
this.LEDs.tap = new LED(0x90 + j, leds.tap);
this.LEDs.padLoop1 = new LED(0x90 + j, leds.padLoop1);
this.LEDs.padLoop2 = new LED(0x90 + j, leds.padLoop2);
this.LEDs.padLoop3 = new LED(0x90 + j, leds.padLoop3);
this.LEDs.padLoop4 = new LED(0x90 + j, leds.padLoop4);
this.LEDs.meter = new LED(0x90 + ledCategories.meters, leds.meter1 - 1 + j);
for (var led in this.LEDs) {
if (led.hasOwnProperty("onOff")) {
led.onOff(OFF);
}
}
for (var j = 1; j <= 4; j++) {
this.LEDs['padLoop' + j].onOff(PADcolors.black);
}
};
NumarkMixtrack3.deck.prototype.trackLoaded = function() {
return engine.getValue(this.group, "track_loaded");
};
NumarkMixtrack3.deck.prototype.getFocusedEffect = function() {
var effectGroup = "[EffectRack1_EffectUnit" + this.decknum + "]";
return engine.getValue(effectGroup, "focused_effect");
};
NumarkMixtrack3.deck.prototype.focusEffect = function(effectNum) {
var effectGroup = "[EffectRack1_EffectUnit" + this.decknum + "]";
engine.setValue(effectGroup, "focused_effect", effectNum);
};
NumarkMixtrack3.deck.prototype.focusNextEffect = function() {
var effectsPerUnit = 3;
var nextEffect = (this.getFocusedEffect() + 1) % (effectsPerUnit + 1);
this.focusEffect(nextEffect);
};
// ******************************************************************
// Samplers - object
// ******************************************************************
NumarkMixtrack3.sampler = function(decknum) {
this.decknum = decknum;
this.group = '[Sampler' + decknum + ']';
this.loaded = false;
this.PitchFaderHigh = 0;
this.lastfadervalue = 0;
this.LEDs = [];
this.PADSampleButtonHold = new LongShortBtn(NumarkMixtrack3.onPADSampleButtonHold);
engine.connectControl(this.group, 'play', 'NumarkMixtrack3.OnSamplePlayStop');
// sampler LED, first 4 are 0x91, next 4 are 0x92
this.led = new LED(0x91 + Math.round(decknum / 9), leds['padSampler' + decknum]);
this.led.onOff(PADcolors.black);
};
// =====================================================================
// Initialization of the mapping
// =====================================================================
NumarkMixtrack3.init = function(id, debug) {
// Set up the controller to manipulate decks 1 & 2 when this script is loaded
print("********* Initialisation process engaged *****************");
print(" Mapping initialization");
print("");
print("==========================================================");
print(" Initialize variables");
print("");
NumarkMixtrack3.id = id; // Store the ID of this device for later use
NumarkMixtrack3.debug = debug;
engine.setValue('[Master]', 'show_superknobs', 1);
NumarkMixtrack3.deckGroup = {
'[Channel1]': '[Channel1]',
'[Channel2]': '[Channel2]',
'[Channel3]': '[Channel3]',
'[Channel4]': '[Channel4]'
};
NumarkMixtrack3.fxControls = { // used to determine FX Button
'[EffectRack1_EffectUnit1_Effect1]': 1,
'[EffectRack1_EffectUnit1_Effect2]': 2,
'[EffectRack1_EffectUnit1_Effect3]': 3,
'[EffectRack1_EffectUnit2_Effect1]': 1,
'[EffectRack1_EffectUnit2_Effect2]': 2,
'[EffectRack1_EffectUnit2_Effect3]': 3,
'[EffectRack1_EffectUnit3_Effect1]': 1,
'[EffectRack1_EffectUnit3_Effect2]': 2,
'[EffectRack1_EffectUnit3_Effect3]': 3,
'[EffectRack1_EffectUnit4_Effect1]': 1,
'[EffectRack1_EffectUnit4_Effect2]': 2,
'[EffectRack1_EffectUnit4_Effect3]': 3
};
NumarkMixtrack3.fxGroups = { //Used to determine deck
'[EffectRack1_EffectUnit1_Effect1]': 1,
'[EffectRack1_EffectUnit1_Effect2]': 1,
'[EffectRack1_EffectUnit1_Effect3]': 1,
'[EffectRack1_EffectUnit2_Effect1]': 2,
'[EffectRack1_EffectUnit2_Effect2]': 2,
'[EffectRack1_EffectUnit2_Effect3]': 2,
'[EffectRack1_EffectUnit3_Effect1]': 3,
'[EffectRack1_EffectUnit3_Effect2]': 3,
'[EffectRack1_EffectUnit3_Effect3]': 3,
'[EffectRack1_EffectUnit4_Effect1]': 4,
'[EffectRack1_EffectUnit4_Effect2]': 4,
'[EffectRack1_EffectUnit4_Effect3]': 4
};
NumarkMixtrack3.Autoloop = {
'beatloop_2_enabled': 1,
'beatloop_4_enabled': 2,
'beatloop_8_enabled': 3,
'beatloop_16_enabled': 4,
'beatloop_0.125_enabled': 1,
'beatloop_0.25_enabled': 2,
'beatloop_0.5_enabled': 3,
'beatloop_1_enabled': 4
};
// initialize 4 decks
for (var i = 1; i <= 4; i++) {
NumarkMixtrack3.decks['D' + i] = new NumarkMixtrack3.deck(i);
}
// initialize 8 samplers
for (var i = 1; i <= 8; i++) {
NumarkMixtrack3.samplers['S' + i] = new NumarkMixtrack3.sampler(i);
}
NumarkMixtrack3.AllLeds = new LED(0x90 + ledCategories.master, leds.all);
// Turn ON all the lights: the only way PADMode Leds light up
NumarkMixtrack3.AllLeds.onOff(ON);
NumarkMixtrack3.initDeck('[Channel1]', false); //Initial load, "remove" is set to false
NumarkMixtrack3.initDeck('[Channel2]', false);
print("********* Controller is ready *******************");
print("********* End of Initialisation process *******************");
};
NumarkMixtrack3.initDeck = function(group, remove) {
var disconnectDeck = parseInt(NumarkMixtrack3.channelRegEx.exec(group)[1]);
var connectedLED = disconnectDeck;
if (disconnectDeck <= 2) {
disconnectDeck += 2;
} else {
disconnectDeck -= 2;
}
print("==========================================================");
print(" initDeck " + group);
print("");
// If "remove" = true, disconnect old deck's Mixxx controls from LEDs.
// We always connect new deck's Mixxx controls to LEDs
NumarkMixtrack3.connectDeckControls(group, remove);
// Toggle LED that indicates which deck is being controlled
if (connectedLED <= 2) {
NumarkMixtrack3.decks["D" + disconnectDeck].LEDs.tap.onOff((OFF));
} else {
NumarkMixtrack3.decks["D" + connectedLED].LEDs.tap.onOff((ON));
}
};
NumarkMixtrack3.connectDeckControls = function(group, remove) {
// If the 'remove' parameter is not passed to this function, set remove = false
remove = remove || false;
var onDeckNum = parseInt(NumarkMixtrack3.channelRegEx.exec(group)[1]);
var offDeckNum = (onDeckNum + 1) % 4 + 1;
var onDeck = NumarkMixtrack3.decks["D" + onDeckNum];
var offDeck = NumarkMixtrack3.decks["D" + offDeckNum];
if (remove) {
print("==========================================================");
print(" Disconnect controls from deck " + offDeckNum);
print("");
// make sure that the shift is no longer active on either deck to prevent confusion
offDeck.shiftKey = false;
onDeck.shiftKey = false;
for (var led in offDeck.LEDs) {
if (led.hasOwnProperty('onOff')) {
led.onOff(OFF);
}
}
for (var i = 1; i <= 4; i++) {
onDeck.LEDs["padLoop" + i].onOff(PADcolors.yellow);
}
}
print("==========================================================");
print(" Connect controls and triggers deck " + onDeckNum);
print("");
var controlsToFunctions = {
'hotcue_1_enabled': 'NumarkMixtrack3.OnHotcueChange',
'hotcue_2_enabled': 'NumarkMixtrack3.OnHotcueChange',
'hotcue_3_enabled': 'NumarkMixtrack3.OnHotcueChange',
'hotcue_4_enabled': 'NumarkMixtrack3.OnHotcueChange',
'track_samples': 'NumarkMixtrack3.OnTrackLoaded',
'VuMeter': 'NumarkMixtrack3.OnVuMeterChange',
'playposition': 'NumarkMixtrack3.OnPlaypositionChange',
'volume': 'NumarkMixtrack3.OnVolumeChange',
'pfl': 'NumarkMixtrack3.OnPFLStatusChange',
'duration': 'NumarkMixtrack3.OnLoadSelectedTrack',
'play_indicator': 'NumarkMixtrack3.OnPlayIndicatorChange',
'cue_indicator': 'NumarkMixtrack3.OnCuePointChange',
'loop_start_position': 'NumarkMixtrack3.OnLoopInOutChange',
'loop_end_position': 'NumarkMixtrack3.OnLoopInOutChange',
'loop_enabled': 'NumarkMixtrack3.OnLoopInOutChange',
'sync_enabled': 'NumarkMixtrack3.OnSyncButtonChange'
};