-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Roland_DJ-505-scripts.js
1893 lines (1760 loc) · 70.2 KB
/
Roland_DJ-505-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
/*
* The Roland DJ-505 controller has two basic modes:
*
* 1. Standalone mode
*
* When the DJ-505 is not connected to a computer (or no SysEx/Keep-Alive
* messages are sent [see below]), the controller is put into standalone mode.
*
* In this mode, the controller's LEDs automatically react on button presses.
* Releasing a button will switches off the button LED, so a MIDI message
* needs to be send afterwards to switch it on again.
* The performance pads LEDs also indicate different modes, but the colors are
* different from the modes described in the Owner's Manual. It does not seem
* to be possible to illuminate individual pads.
*
* he built-in TR-S drum machine works in standalone mode and its output level
* is controlled by the TR/SAMPLER LEVEL knob.
*
*
* 2. Serato mode
*
* When the DJ-505 receives a SysEx message, the controller is put in "Serato"
* mode. However, in order to keep the DJ-505 in this mode, it seems to be
* necessary to regularly send a "keep-alive" MIDI message (0xBF 0x64 0x00).
* Otherwise the device will switch back to "Standalone mode" after
* approximately 1.5 seconds.
*
* In Serato mode, the all LEDs have to be illuminated by sending MIDI
* messages: Pressing a button does not switch the LED on and releasing it does
* not switch it off. The performance pad LEDs can all be set individually
* (including the mode buttons).
*
* The TR-S output is not connected to the main out. Instead, it is connected
* to one of input channels of the controller's audio interface. Hence, the
* TR/SAMPLER LEVEL knob does not control the output volume of TR-S, and
* works as a generic MIDI control instead.
*
*
* Other quirks and issues of the Roland DJ-505:
* - The controller does not send the current value of the crossfader when it
* receives the SysEx message. This also happens when it's used with Serato,
* so Mixxx tries to work around the issue by using "soft takeover" to avoid
* sudden volume changes when the crossfader is first used.
* - It does not seem to be possible to toggle the LEDs of the BACK and the ADD
* PREPARE buttons. Again, this can be reproduced in Serato, so it looks like
* a firmware problem and cannot be worked around.
*
*/
var DJ505 = {};
/////////////////
// Tweakables. //
/////////////////
DJ505.stripSearchScaling = 0.15;
DJ505.tempoRange = [0.08, 0.16, 0.5];
DJ505.autoShowFourDecks = false;
DJ505.trsGroup = "Auxiliary1"; // TR-S input
///////////
// Code. //
///////////
DJ505.init = function() {
DJ505.shiftButton = function(channel, control, value, _status, _group) {
DJ505.deck.concat(DJ505.effectUnit, [DJ505.sampler, DJ505.browseEncoder]).forEach(
value ? function(module) { module.shift(); } : function(module) { module.unshift(); }
);
};
DJ505.deck = [];
for (let i = 0; i < 4; i++) {
DJ505.deck[i] = new DJ505.Deck(i + 1, i);
DJ505.deck[i].setCurrentDeck("[Channel" + (i + 1) + "]");
}
DJ505.leftLoadTrackButton = new components.Button({
group: "[Channel1]",
midi: [0x9F, 0x02],
unshift: function() {
this.inKey = "LoadSelectedTrack";
},
shift: function() {
this.inKey = "eject";
},
input: function(channel, control, value, status, _group) {
this.send(this.isPress(channel, control, value, status) ? this.on : this.off);
components.Button.prototype.input.apply(this, arguments);
},
});
DJ505.deck3Button = new DJ505.DeckToggleButton({
midi: [0x90, 0x08],
decks: [1, 3],
loadTrackButton: DJ505.leftLoadTrackButton,
});
DJ505.rightLoadTrackButton = new components.Button({
group: "[Channel2]",
midi: [0x9F, 0x02],
unshift: function() {
this.inKey = "LoadSelectedTrack";
},
shift: function() {
this.inKey = "eject";
},
input: function(channel, control, value, status, _group) {
this.send(this.isPress(channel, control, value, status) ? this.on : this.off);
components.Button.prototype.input.apply(this, arguments);
},
});
DJ505.deck4Button = new DJ505.DeckToggleButton({
midi: [0x91, 0x08],
decks: [2, 4],
loadTrackButton: DJ505.rightLoadTrackButton,
});
DJ505.sampler = new DJ505.Sampler();
DJ505.effectUnit = [];
for (let i = 0; i <= 1; i++) {
DJ505.effectUnit[i] = new components.EffectUnit([i + 1, i + 3]);
DJ505.effectUnit[i].sendShifted = true;
DJ505.effectUnit[i].shiftOffset = 0x0B;
DJ505.effectUnit[i].shiftControl = true;
DJ505.effectUnit[i].enableButtons[1].midi = [0x98 + i, 0x00];
DJ505.effectUnit[i].enableButtons[2].midi = [0x98 + i, 0x01];
DJ505.effectUnit[i].enableButtons[3].midi = [0x98 + i, 0x02];
DJ505.effectUnit[i].effectFocusButton.midi = [0x98 + i, 0x04];
DJ505.effectUnit[i].knobs[1].midi = [0xB8 + i, 0x00];
DJ505.effectUnit[i].knobs[2].midi = [0xB8 + i, 0x01];
DJ505.effectUnit[i].knobs[3].midi = [0xB8 + i, 0x02];
DJ505.effectUnit[i].dryWetKnob.midi = [0xB8 + i, 0x03];
DJ505.effectUnit[i].dryWetKnob.input = function(channel, control, value, _status, _group) {
if (value === 1) {
// 0.05 is an example. Adjust that value to whatever works well for your controller.
this.inSetParameter(this.inGetParameter() + 0.05);
} else if (value === 127) {
this.inSetParameter(this.inGetParameter() - 0.05);
}
};
for (let j = 1; j <= 4; j++) {
DJ505.effectUnit[i].enableOnChannelButtons.addButton("Channel" + j);
DJ505.effectUnit[i].enableOnChannelButtons["Channel" + j].midi = [0x98 + i, 0x04 + j];
}
DJ505.effectUnit[i].enableOnChannelButtons.addButton(DJ505.trsGroup);
DJ505.effectUnit[i].enableOnChannelButtons[DJ505.trsGroup].midi = [0x98 + i, 0x09];
DJ505.effectUnit[i].enableOnChannelButtons[DJ505.trsGroup].input = function(channel, control, value, status, _group) {
components.Button.prototype.input.apply(this, arguments);
if (this.isPress(channel, control, value, status)) {
const enabled = this.inGetValue();
for (let j = 1; j <= 16; j++) {
engine.setValue(this.group, "group_[Sampler" + j + "]_enable", enabled);
}
}
};
DJ505.effectUnit[i].enableOnTrsButton = DJ505.effectUnit[i].enableOnChannelButtons[DJ505.trsGroup];
DJ505.effectUnit[i].init();
}
engine.makeConnection("[Channel3]", "track_loaded", DJ505.autoShowDecks);
engine.makeConnection("[Channel4]", "track_loaded", DJ505.autoShowDecks);
if (engine.getValue("[App]", "num_samplers") < 16) {
engine.setValue("[App]", "num_samplers", 16);
}
// Send Serato SysEx messages to request initial state and unlock pads
midi.sendSysexMsg([0xF0, 0x00, 0x20, 0x7F, 0x00, 0xF7], 6);
midi.sendSysexMsg([0xF0, 0x00, 0x20, 0x7F, 0x01, 0xF7], 6);
// Send "keep-alive" message to keep controller in Serato mode
engine.beginTimer(500, () => {
midi.sendShortMsg(0xBF, 0x64, 0x00);
});
// Reset LEDs
DJ505.deck3Button.trigger();
DJ505.deck4Button.trigger();
for (let i = 0; i < 4; i++) {
DJ505.deck[i].reconnectComponents();
}
};
DJ505.autoShowDecks = function(_value, _group, _control) {
const anyLoaded = engine.getValue("[Channel3]", "track_loaded") || engine.getValue("[Channel4]", "track_loaded");
if (!DJ505.autoShowFourDecks) {
return;
}
engine.setValue("[Master]", "show_4decks", anyLoaded);
};
DJ505.shutdown = function() {
};
DJ505.browseEncoder = new components.Encoder({
longPressTimer: 0,
longPressTimeout: 250,
trackColorCycleEnabled: false,
trackColorCycleHappened: false,
previewSeekEnabled: false,
previewSeekHappened: false,
unshift: function() {
this.onKnobEvent = function(rotateValue) {
if (rotateValue !== 0) {
if (this.previewSeekEnabled) {
const oldPos = engine.getValue("[PreviewDeck1]", "playposition");
const newPos = Math.max(0, oldPos + (0.05 * rotateValue));
engine.setValue("[PreviewDeck1]", "playposition", newPos);
} else {
engine.setValue("[Playlist]", "SelectTrackKnob", rotateValue);
}
}
};
this.onButtonEvent = function(value) {
if (value) {
this.isLongPressed = false;
this.longPressTimer = engine.beginTimer(
this.longPressTimeout,
() => { this.isLongPressed = true; },
true
);
this.previewStarted = false;
if (!engine.getValue("[PreviewDeck1]", "play")) {
engine.setValue("[PreviewDeck1]", "LoadSelectedTrackAndPlay", 1);
this.previewStarted = true;
}
// Track in PreviewDeck1 is playing, either the user
// wants to stop the track or seek in it
this.previewSeekEnabled = true;
} else {
if (this.longPressTimer !== 0) {
engine.stopTimer(this.longPressTimer);
this.longPressTimer = 0;
}
if (!this.isLongPressed && !this.previewStarted && engine.getValue("[PreviewDeck1]", "play")) {
script.triggerControl("[PreviewDeck1]", "stop");
}
this.previewSeekEnabled = false;
this.previewStarted = false;
}
};
},
shift: function() {
this.onKnobEvent = function(rotateValue) {
if (rotateValue !== 0) {
if (this.trackColorCycleEnabled) {
const key = (rotateValue > 0) ? "track_color_next" : "track_color_prev";
engine.setValue("[Library]", key, 1.0);
this.trackColorCycleHappened = true;
} else {
engine.setValue("[Playlist]", "SelectPlaylist", rotateValue);
}
}
};
this.onButtonEvent = function(value) {
if (value) {
this.trackColorCycleEnabled = true;
this.trackColorCycleHappened = false;
} else {
if (!this.trackColorCycleHappened) {
script.triggerControl("[Playlist]", "ToggleSelectedSidebarItem");
}
this.trackColorCycleEnabled = false;
this.trackColorCycleHappened = false;
}
};
},
input: function(channel, control, value, status, _group) {
switch (status) {
case 0xBF: { // Rotate.
const rotateValue = (value === 127) ? -1 : ((value === 1) ? 1 : 0);
this.onKnobEvent(rotateValue);
break;
}
case 0x9F: // Push.
this.onButtonEvent(value);
}
}
});
DJ505.backButton = new components.Button({
// TODO: Map the BACK button
midi: [0x9F, 0x07],
shiftOffset: 11,
sendShifted: true,
shiftControl: true,
type: undefined,
});
DJ505.addPrepareButton = new components.Button({
midi: [0x9F, 0x1B],
shiftOffset: -7,
sendShifted: true,
shiftControl: true,
group: "[Skin]",
key: "show_maximized_library",
type: components.Button.prototype.types.toggle,
});
DJ505.sortLibrary = function(channel, control, value, _status, _group) {
if (value === 0) {
return;
}
let sortColumn;
switch (control) {
case 0x12: // SONG
sortColumn = 2;
break;
case 0x13: // BPM
sortColumn = 15;
break;
case 0x14: // ARTIST
sortColumn = 1;
break;
case 0x1E: // KEY
sortColumn = 20;
break;
default:
// unknown sort column
return;
}
engine.setValue("[Library]", "sort_column_toggle", sortColumn);
};
DJ505.crossfader = new components.Pot({
midi: [0xBF, 0x08],
group: "[Master]",
inKey: "crossfader",
input: function() {
// We need a weird max. for the crossfader to make it cut cleanly.
// However, components.js resets max. to 0x3fff when the first value is
// received. Hence, we need to set max. here instead of within the
// constructor.
this.max = (0x7f<<7) + 0x70;
components.Pot.prototype.input.apply(this, arguments);
}
});
DJ505.crossfader.setCurve = function(channel, control, value, _status, _group) {
// 0x00 is Picnic Bench, 0x01 is Constant Power and 0x02 is Linear
switch (value) {
case 0x00: // Picnic Bench / Fast Cut
engine.setValue("[Mixer Profile]", "xFaderMode", 0);
engine.setValue("[Mixer Profile]", "xFaderCalibration", 0.9);
engine.setValue("[Mixer Profile]", "xFaderCurve", 7.0);
break;
case 0x01: // Constant Power
engine.setValue("[Mixer Profile]", "xFaderMode", 1);
engine.setValue("[Mixer Profile]", "xFaderCalibration", 0.3);
engine.setValue("[Mixer Profile]", "xFaderCurve", 0.6);
break;
case 0x02: // Additive
engine.setValue("[Mixer Profile]", "xFaderMode", 0);
engine.setValue("[Mixer Profile]", "xFaderCalibration", 0.4);
engine.setValue("[Mixer Profile]", "xFaderCurve", 0.9);
}
};
DJ505.crossfader.setReverse = function(channel, control, value, _status, _group) {
// 0x00 is ON, 0x01 is OFF
engine.setValue("[Mixer Profile]", "xFaderReverse", (value === 0x00) ? 1 : 0);
};
DJ505.setChannelInput = function(channel, control, value, _status, _group) {
const number = (channel === 0x00) ? 0 : 1;
const channelgroup = "[Channel" + (number + 1) + "]";
switch (value) {
case 0x00: // PC
engine.setValue(channelgroup, "passthrough", 0);
break;
case 0x01: // LINE
case 0x02: // PHONO
engine.setValue(channelgroup, "passthrough", 1);
break;
}
};
DJ505.Deck = function(deckNumbers, offset) {
components.Deck.call(this, deckNumbers);
this.slipModeButton = new DJ505.SlipModeButton({
midi: [0x90 + offset, 0xF],
shiftOffset: -8,
shiftControl: true,
sendShifted: true,
});
engine.setValue(this.currentDeck, "rate_dir", -1);
this.tempoFader = new components.Pot({
group: "[Channel" + deckNumbers + "]",
midi: [0xB0 + offset, 0x09],
connect: function() {
engine.softTakeover(this.group, "pitch", true);
engine.softTakeover(this.group, "rate", true);
components.Pot.prototype.connect.apply(this, arguments);
},
unshift: function() {
this.inKey = "rate";
this.inSetParameter = components.Pot.prototype.inSetParameter;
engine.softTakeoverIgnoreNextValue(this.group, "pitch");
},
shift: function() {
this.inKey = "pitch";
this.inSetParameter = function(value) {
// Scale to interval ]-7…7[; invert direction as per controller
// labeling.
value = 14 * value - 7;
value *= -1;
components.Pot.prototype.inSetValue.call(this, value);
};
engine.softTakeoverIgnoreNextValue(this.group, "rate");
}
});
// ============================= JOG WHEELS =================================
this.wheelTouch = function(channel, control, value, _status, _group) {
if (value === 0x7F && !this.isShifted) {
const alpha = 1.0/8;
const beta = alpha/32;
engine.scratchEnable(script.deckFromGroup(this.currentDeck), 512, 45, alpha, beta);
} else { // If button up
engine.scratchDisable(script.deckFromGroup(this.currentDeck));
}
};
this.wheelTurn = function(channel, control, value, _status, _group) {
// When the jog wheel is turned in clockwise direction, value is
// greater than 64 (= 0x40). If it's turned in counter-clockwise
// direction, the value is smaller than 64.
const newValue = value - 64;
const deck = script.deckFromGroup(this.currentDeck);
if (engine.isScratching(deck)) {
engine.scratchTick(deck, newValue); // Scratch!
} else if (this.isShifted) {
const oldPos = engine.getValue(this.currentDeck, "playposition");
// Since ‘playposition’ is normalized to unity, we need to scale by
// song duration in order for the jog wheel to cover the same amount
// of time given a constant turning angle.
const duration = engine.getValue(this.currentDeck, "duration");
const newPos = Math.max(0, oldPos + (newValue * DJ505.stripSearchScaling / duration));
engine.setValue(this.currentDeck, "playposition", newPos); // Strip search
} else {
engine.setValue(this.currentDeck, "jog", newValue); // Pitch bend
}
};
/* Platter Spin LED Indicator on Jog Wheels
*
* The Controller features a LED indicator that imitates a spinning
* platter when the deck is playing and also shows to position inside a
* bar.
*
* LED indicator values:
* - 0x00 - 0x1F: Beat 0 (downbeat) to 1
* - 0x20 - 0x3F: Beat 1 to 2
* - 0x40 - 0x5F: Beat 2 to 3
* - 0x60 - 0x7F: Beat 3 (upbeat) to 0 (next downbeat)
*
* TODO: Add proper bar support for the LED indicators
*
* Mixxx currently does not support bar detection, so we don't know which
* of the 4 beats in a we are on. This has been worked around by counting
* beats manually, but this is error prone and does not support moving
* backwards in a track, has problems with loops, does not detect hotcue
* jumps and does not indicate the downbeat (obviously).
*
* See Launchpad issue: https://github.com/mixxxdj/mixxx/issues/5218
*/
this.beatIndex = 0;
this.lastBeatDistance = 0;
engine.makeConnection(this.currentDeck, "beat_distance", function(value) {
// Check if we're already in front of the next beat.
if (value < this.lastBeatDistance) {
this.beatIndex = (this.beatIndex + 1) % 4;
}
this.lastBeatDistance = value;
// Since deck indices start with 1, we use 0xAF + deck for the status
// byte, so that we 0xB0 for the first deck.
const status = 0xAF + script.deckFromGroup(this.currentDeck);
// Send a value between 0x00 and 0x7F to set jog wheel LED indicator
midi.sendShortMsg(status, 0x06, Math.round(0x1f * value + 0x20 * this.beatIndex));
}.bind(this));
// ========================== LOOP SECTION ==============================
this.loopActive = new components.Button({
midi: [0x94 + offset, 0x32],
key: "loop_enabled",
type: components.Button.prototype.types.toggle,
});
this.reloopExit = new components.Button({
midi: [0x94 + offset, 0x33],
key: "reloop_exit",
});
this.loopHalve = new components.Button({
midi: [0x94 + offset, 0x34],
key: "loop_halve",
});
this.loopDouble = new components.Button({
midi: [0x94 + offset, 0x35],
key: "loop_double",
});
this.loopShiftBackward = new components.Button({
midi: [0x94 + offset, 0x36],
key: "beatjump_backward",
});
this.loopShiftForward = new components.Button({
midi: [0x94 + offset, 0x37],
key: "beatjump_forward",
});
this.loopIn = new components.Button({
midi: [0x94 + offset, 0x38],
key: "loop_in",
});
this.loopOut = new components.Button({
midi: [0x94 + offset, 0x39],
key: "loop_out",
});
this.slotSelect = new components.Button({
midi: [0x94 + offset, 0x3B],
key: "quantize",
type: components.Button.prototype.types.toggle,
});
this.autoLoop = new components.Button({
midi: [0x94 + offset, 0x40],
inKey: "beatloop_activate",
outKey: "loop_enabled",
});
// ========================== PERFORMANCE PADS ==============================
this.padSection = new DJ505.PadSection(this, offset);
this.keylock = new components.Button({
midi: [0x90 + offset, 0x0D],
sendShifted: true,
shiftControl: true,
shiftOffset: 1,
outKey: "keylock",
currentRangeIndex: (DJ505.tempoRange.indexOf(engine.getValue("[Channel" + deckNumbers + "]", "rateRange"))) ? DJ505.tempoRange.indexOf(engine.getValue("[Channel" + deckNumbers + "]", "rateRange")) : 0,
unshift: function() {
this.inKey = "keylock";
this.input = components.Button.prototype.input;
this.type = components.Button.prototype.types.toggle;
},
shift: function() {
this.inKey = "rateRange";
this.type = undefined;
this.input = function(channel, control, value, status, _group) {
if (this.isPress(channel, control, value, status)) {
this.currentRangeIndex++;
if (this.currentRangeIndex >= DJ505.tempoRange.length) {
this.currentRangeIndex = 0;
}
this.inSetValue(DJ505.tempoRange[this.currentRangeIndex]);
}
};
},
});
// ============================= TRANSPORT ==================================
this.cue = new components.CueButton({
midi: [0x90 + offset, 0x01],
sendShifted: true,
shiftControl: true,
shiftOffset: 4,
reverseRollOnShift: false,
input: function(channel, control, value, status, group) {
components.CueButton.prototype.input.call(this, channel, control, value, status, group);
if (value) {
return;
}
const state = engine.getValue(group, "cue_indicator");
if (state) {
this.trigger();
}
}
});
this.play = new components.PlayButton({
midi: [0x90 + offset, 0x00],
sendShifted: true,
shiftControl: true,
shiftOffset: 4,
});
this.sync = new components.Button({
midi: [0x90 + offset, 0x02],
group: "[Channel" + deckNumbers + "]",
outKey: "sync_mode",
output: function(value, group, control) {
if (this.connections[1] !== undefined) {
this.connections[1].disconnect();
delete this.connections[1];
}
// If the new sync_mode is "Explicit Leader", use the blinking
// indicator for the LED instead.
if (value === 3) {
if (this.connections[1] === undefined) {
this.connections[1] = engine.makeConnection("[App]", "indicator_500ms", this.setLed.bind(this));
}
return;
}
this.setLed(value, group, control);
},
setLed: function(value, _group, _control) {
midi.sendShortMsg(this.midi[0], value ? 0x02 : 0x03, this.on);
},
input: function(channel, control, value, _status, _group) {
if (value) {
this.longPressTimer = engine.beginTimer(this.longPressTimeout, () => {
this.onLongPress();
this.longPressTimer = 0;
}, true);
} else if (this.longPressTimer !== 0) {
// Button released after short press
engine.stopTimer(this.longPressTimer);
this.longPressTimer = 0;
this.onShortPress();
}
},
unshift: function() {
this.onShortPress = function() {
script.triggerControl(this.group, "beatsync", 1);
};
this.onLongPress = function() {
if (engine.getValue(this.group, "sync_enabled")) {
// If already explicit leader, reset explicit state
// (setting it to 0 may still make it implicit leader and
// immediately resetting it to 1).
const value = (engine.getValue(this.group, "sync_leader") === 2) ? 0 : 2;
engine.setValue(this.group, "sync_leader", value);
} else {
engine.setValue(this.group, "sync_enabled", 1);
}
};
},
shift: function() {
this.onShortPress = function() {
engine.setValue(this.group, "sync_enabled", 0);
};
this.onLongPress = function() {
script.toggleControl(this.group, "quantize");
};
},
});
// =============================== MIXER ====================================
this.pregain = new components.Pot({
midi: [0xB0 + offset, 0x16],
group: "[Channel" + deckNumbers + "]",
inKey: "pregain",
});
this.eqKnob = [];
for (let k = 1; k <= 3; k++) {
this.eqKnob[k] = new components.Pot({
midi: [0xB0 + offset, 0x20 - k],
group: "[EqualizerRack1_" + this.currentDeck + "_Effect1]",
inKey: "parameter" + k,
});
}
this.filter = new components.Pot({
midi: [0xB0 + offset, 0x1A],
group: "[QuickEffectRack1_" + this.currentDeck + "]",
inKey: "super1",
});
this.pfl = new components.Button({
midi: [0x90 + offset, 0x1B],
group: "[Channel" + deckNumbers + "]",
type: components.Button.prototype.types.toggle,
inKey: "pfl",
outKey: "pfl",
});
this.tapBPM = new components.Button({
midi: [0x90 + offset, 0x12],
group: "[Channel" + deckNumbers + "]",
input: function(_channel, _control, value, _status, group) {
if (value) {
this.longPressTimer = engine.beginTimer(this.longPressTimeout, () => {
this.onLongPress(group);
this.longPressTimer = 0;
}, true);
} else if (this.longPressTimer !== 0) {
// Button released after short press
engine.stopTimer(this.longPressTimer);
this.longPressTimer = 0;
this.onShortPress(group);
}
},
onShortPress: function(group) {
script.triggerControl(group, "beats_translate_curpos");
},
onLongPress: function(group) {
script.triggerControl(group, "beats_translate_match_alignment");
},
});
this.volume = new components.Pot({
midi: [0xB0 + offset, 0x1C],
group: "[Channel" + deckNumbers + "]",
inKey: "volume",
});
this.vuMeter = new components.Component({
midi: [0xB0 + offset, 0x1F],
group: "[Channel" + deckNumbers + "]",
outKey: "vu_meter",
output: function(value, group, _control) {
// The red LEDs light up with MIDI values greater than 0x24. The
// maximum brightness is reached at value 0x28. Red LEDs should
// only be illuminated if the track is clipping.
if (engine.getValue(group, "peak_indicator") === 1) {
value = 0x28;
} else {
value = Math.round(value * 0x24);
}
this.send(value);
},
});
};
DJ505.Deck.prototype = Object.create(components.Deck.prototype);
DJ505.DeckToggleButton = function(options) {
this.secondaryDeck = false;
components.Button.call(this, options);
};
DJ505.DeckToggleButton.prototype = Object.create(components.Button.prototype);
DJ505.DeckToggleButton.prototype.input = function(channel, control, value, status, _group) {
if (this.isPress(channel, control, value, status)) {
// Button was pressed
this.longPressTimer = engine.beginTimer(
this.longPressTimeout,
() => { this.isLongPressed = true; },
true
);
this.secondaryDeck = !this.secondaryDeck;
} else if (this.isLongPressed) {
// Button was released after long press
this.isLongPressed = false;
this.secondaryDeck = !this.secondaryDeck;
} else {
// Button was released after short press
engine.stopTimer(this.longPressTimer);
this.longPressTimer = null;
return;
}
this.trigger();
};
DJ505.DeckToggleButton.prototype.trigger = function() {
this.send(this.secondaryDeck ? this.on : this.off);
const newGroup = "[Channel" + (this.secondaryDeck ? this.decks[1] : this.decks[0]) + "]";
if (this.loadTrackButton.group !== newGroup) {
this.loadTrackButton.group = newGroup;
this.loadTrackButton.disconnect();
this.loadTrackButton.connect();
this.loadTrackButton.trigger();
}
};
//////////////////////////////
// TR/Sampler. //
//////////////////////////////
DJ505.Sampler = function() {
// TODO: Improve phase sync (workaround: use NUDGE button for beatmatching)
/*
* The TR-S section behaves differently depending on whether the controller
* is in Standalone or Serato mode:
*
* 1. Standalone mode
*
* When the controller is in standalone mode, the controller's TR-S works
* with the SERATO SAMPLER and SYNC functionality disabled. Also, it's not
* possible to apply FX to the TR-S output signal. The TR/SAMPLER LEVEL
* knob can be used to adjust the volume of the output.
*
*
* 2. Serato mode
*
* In this mode, the BPM can be set by sending MIDI clock
* messages (0xF8). The sampler can be started by sending one MIDI
* message per bar (0xBA 0x02 XX). The TR-S is not directly connected to
* the main out. Instead, the sound is played on channels 7-8 so that the
* signal can be routed through the FX section.
*
* The SERATO SAMPLER features 8 instruments (S1 - S8) that can be to play
* samples from Serato's sampler banks. If the device is in Serato mode and
* the sampler instruments are programmed using the TR-S pads, two MIDI
* messages are sent by the DJ-505 when the sampler step is reached:
*
* 9F 2X YY
* 8F 2X 00
*
* X is the Sampler number, i. e. for S1 this means that X=1. YY is either
* 0x57 (for steps 1, 5, 9, 13, 16) or 0x50 (all other steps).
*
* When the TR-S starts playback, the MIDI start message (0xFA) is sent by the
* device. When the playback stops, the device sends the stop message (0xFC).
*
* In both modes, it is possible to set the BPM in the range 5.0 to 800.0
* BPM by sending this MIDI message:
*
* sendShortMsg(0xEA, Math.round(bpm*10) & 0x7f, (Math.round(bpm*10) >> 7) & 0x7f);
*
*/
components.ComponentContainer.call(this);
this.syncDeck = -1;
const getActiveDeck = function() {
const deckvolume = new Array(0, 0, 0, 0);
let volumemax = -1;
let newdeck = -1;
// get volume from the decks and check it for use
for (let z = 0; z <= 3; z++) {
if (engine.getValue("[Channel" + (z + 1) + "]", "track_loaded") > 0) {
deckvolume[z] = engine.getValue("[Channel" + (z + 1) + "]", "volume");
if (deckvolume[z] > volumemax) {
volumemax = deckvolume[z];
newdeck = z;
}
}
}
return newdeck;
};
this.syncButtonPressed = function(channel, control, value, _status, _group) {
if (value !== 0x7f) {
return;
}
const isShifted = (control === 0x55);
if (isShifted || this.syncDeck >= 0) {
this.syncDeck = -1;
} else {
const deck = getActiveDeck();
if (deck < 0) {
return;
}
const bpm = engine.getValue("[Channel" + (deck + 1) + "]", "bpm");
// Minimum BPM is 5.0 (0xEA 0x32 0x00), maximum BPM is 800.0 (0xEA 0x40 0x3e).
if (!(bpm >= 5 && bpm <= 800)) {
return;
}
const bpmValue = Math.round(bpm*10);
midi.sendShortMsg(0xEA, bpmValue & 0x7f, (bpmValue >> 7) & 0x7f);
this.syncDeck = deck;
}
};
this.bpmKnobTurned = function(channel, control, value, _status, _group) {
if (this.syncDeck >= 0) {
const bpm = ((value << 7) | control) / 10;
engine.setValue("[Channel" + (this.syncDeck + 1) + "]", "bpm", bpm);
}
};
this.startStopButtonPressed = function(channel, control, value, status, _group) {
if (status === 0xFA) {
this.playbackCounter = 1;
this.playbackTimer = engine.beginTimer(500, () => {
midi.sendShortMsg(0xBA, 0x02, this.playbackCounter);
this.playbackCounter = (this.playbackCounter % 4) + 1;
});
} else if (status === 0xFC) {
if (this.playbackTimer) {
engine.stopTimer(this.playbackTimer);
}
}
};
this.customSamplePlayback = function(channel, control, value, status, group) {
if (value) {
// Volume has to be re-set because it could have been modified by
// the Performance Pads in Velocity Sampler mode
engine.setValue(group, "volume", engine.getValue("[" + DJ505.trsGroup + "]", "volume"));
engine.setValue(group, "cue_gotoandplay", 1);
}
};
this.levelKnob = new components.Pot({
group: "[" + DJ505.trsGroup + "]",
inKey: "volume",
input: function(_channel, _control, _value, _status, _group) {
components.Pot.prototype.input.apply(this, arguments);
const volume = this.inGetParameter();
for (let i = 1; i <= 16; i++) {
engine.setValue("[Sampler" + i + "]", this.inKey, volume);
}
},
});
this.cueButton = new components.Button({
group: "[" + DJ505.trsGroup + "]",
key: "pfl",
type: components.Button.prototype.types.toggle,
midi: [0x9F, 0x1D],
input: function(_channel, _control, _value, _status, _group) {
components.Button.prototype.input.apply(this, arguments);
const pfl = this.inGetValue();
for (let i = 1; i <= 16; i++) {
engine.setValue("[Sampler" + i + "]", this.inKey, pfl);
}
},
});
};
DJ505.Sampler.prototype = Object.create(components.ComponentContainer.prototype);
////////////////////////
// Custom components. //
////////////////////////
DJ505.SlipModeButton = function(options) {
components.Button.apply(this, arguments);
this.doubleTapTimeout = 500;
components.Button.call(this, options);
};
DJ505.SlipModeButton.prototype = Object.create(components.Button.prototype);
DJ505.SlipModeButton.prototype.unshift = function() {
this.input = function(channel, control, value, _status, _group) {
if (value) { // Button press.
this.inSetValue(true);
return;
} // Else: button release.
if (!this.doubleTapped) {
this.inSetValue(false);
}
this.doubleTapped = true;
if (this.doubleTapTimer) {
engine.stopTimer(this.doubleTapTimer);
this.doubleTapTimer = null;
}
this.doubleTapTimer = engine.beginTimer(
this.doubleTapTimeout,
() => {
this.doubleTapped = false;
this.doubleTapTimer = null;
},
true
);
};
this.inKey = "slip_enabled";
this.outKey = "slip_enabled";
this.type = components.Button.prototype.types.push;
this.disconnect();
this.connect();
this.trigger();
};
DJ505.SlipModeButton.prototype.shift = function() {
this.input = components.Button.prototype.input;
this.inKey = "vinylcontrol_enabled";
this.outKey = "vinylcontrol_enabled";
this.type = components.Button.prototype.types.toggle;
this.disconnect();
this.connect();
this.trigger();
};
DJ505.PadMode = {
HOTCUE: 0x00,
FLIP: 0x02,
CUELOOP: 0x03,
TR: 0x04,
PATTERN: 0x05,
TRVELOCITY: 0x06,
ROLL: 0x08,
SLICER: 0x09,
SLICERLOOP: 0x0A,
SAMPLER: 0x0B,
VELOCITYSAMPLER: 0x0C,
LOOP: 0x0D,