1
DenonDNSC2000 = new function() {}
3
DenonDNSC2000.Deck = function (deckNumber, group) {
4
this.deckNumber = deckNumber;
6
this.scratchMode = false;
7
this.controlPressed = -1;
10
DenonDNSC2000.init = function (id) {
11
var leds = [0x11,0x13,0x15,0x17,0x19,0x1B,0x1D,0x20,/* cues */
12
0x24,0x40,0x2B,/* loops */
13
0x27,0x26,/* play,cue */
14
0x08,0x09,/* key lock, sync*/
15
0x5A,0x5B,/* flanger,scratch mode */
16
0x5D,0x5E,0x5F/* depth, delay, lfo */
18
for(var index = 0, count = leds.length;index < count; index ++) {
19
midi.sendShortMsg(0xB0,0x4B,leds[index]);
20
midi.sendShortMsg(0xB1,0x4B,leds[index]);
21
midi.sendShortMsg(0xB2,0x4B,leds[index]);
22
midi.sendShortMsg(0xB3,0x4B,leds[index]);
26
DenonDNSC2000.shutdown = function (id) {
27
DenonDNSC2000.init(id);
30
DenonDNSC2000.getDeckByGroup = function(group) {
31
for(var index = 0, count = decks.length;index < count; index++) {
32
if(decks[index].group == group)
38
DenonDNSC2000.shift = function(midino, control, value, status, group) {
39
shiftPressed = ((status & 0xF0) == 0x90);
41
engine.setValue(group, 'reverse', 0);
44
DenonDNSC2000.changeDeck = function(midino, control, value, status, group) {
45
DenonDNSC2000.handleLeds(group);
48
DenonDNSC2000.newValue = function(currentVal,min,max,increment,ticksCount) {
49
var interval = (max - min) / 24;
52
newVal = Math.min(max,currentVal + interval);
54
newVal = Math.max(min,currentVal - interval);
58
DenonDNSC2000.flanger = function (midino, control, value, status, group) {
59
DenonDNSC2000.toggleBinaryValue(group,'flanger');
60
engine.beginTimer(100, 'DenonDNSC2000.handleFlangerLed("'+group+'")', true);
63
DenonDNSC2000.changeDepth = function (midino, control, value, status, group) {
64
engine.setValue(group, 'lfoDepth', DenonDNSC2000.newValue(engine.getValue(group, 'lfoDepth'),0,1,(value == 0x00),24));
67
DenonDNSC2000.changeDelay = function (midino, control, value, status, group) {
68
engine.setValue(group, 'lfoDelay', DenonDNSC2000.newValue(engine.getValue(group, 'lfoDelay'),50,10000,(value == 0x00),24));
71
DenonDNSC2000.changeLFO = function (midino, control, value, status, group) {
72
engine.setValue(group, 'lfoPeriod', DenonDNSC2000.newValue(engine.getValue(group, 'lfoPeriod'),50000,2000000,(value == 0x00),24));
75
DenonDNSC2000.resetDepth = function (midino, control, value, status, group) {
76
engine.setValue(group, 'lfoDepth', 0.5);
79
DenonDNSC2000.resetDelay = function (midino, control, value, status, group) {
80
engine.setValue(group, 'lfoDelay', 50 + (10000 - 50) / 2);
83
DenonDNSC2000.resetLFO = function (midino, control, value, status, group) {
84
engine.setValue(group, 'lfoPeriod', 50000 + (2000000 - 50000) / 2);
87
DenonDNSC2000.selectTrack = function (midino, control, value, status, group) {
89
engine.setValue('[Playlist]', 'SelectNextTrack', 1);
91
engine.setValue('[Playlist]', 'SelectPrevTrack', 1);
94
DenonDNSC2000.loadSelectedTrack = function (midino, control, value, status, group) {
95
engine.setValue(group, 'LoadSelectedTrack', 1);
96
engine.beginTimer(1500, 'DenonDNSC2000.handleLeds("'+group+'")', true);
99
DenonDNSC2000.loopOrHotcues = function (midino, control, value, status, group) {
100
var deck = DenonDNSC2000.getDeckByGroup(group);
101
if ((status & 0xF0) == 0x80)
102
deck.controlPressed = -1;
104
deck.controlPressed = control;
108
DenonDNSC2000.hotcue(1,group,value,shiftPressed);
111
DenonDNSC2000.hotcue(2,group,value,shiftPressed);
114
DenonDNSC2000.hotcue(3,group,value,shiftPressed);
117
DenonDNSC2000.hotcue(4,group,value,shiftPressed);
120
DenonDNSC2000.hotcue(5,group,value,shiftPressed);
123
DenonDNSC2000.hotcue(6,group,value,shiftPressed);
126
DenonDNSC2000.hotcue(7,group,value,shiftPressed);
129
DenonDNSC2000.hotcue(8,group,value,shiftPressed);
133
DenonDNSC2000.loopIn(group,value,shiftPressed);
136
DenonDNSC2000.loopOut(group,value,shiftPressed);
139
DenonDNSC2000.reloop(group,value,shiftPressed);
145
DenonDNSC2000.hotcue = function(cueIndex, group, value, shift) {
147
engine.setValue(group, 'hotcue_' + cueIndex + '_activate', 1);
150
if(engine.getValue(group, 'hotcue_' + cueIndex + '_enabled') == 0) {
151
var samplesPerBeat = DenonDNSC2000.samplesPerBeat(group);
152
var positionInBeats = (engine.getValue(group,'playposition') * engine.getValue(group,'track_samples')) / samplesPerBeat;
153
if((positionInBeats - Math.floor(positionInBeats)) > 0.5)
154
positionInBeats = Math.floor(0.5 + positionInBeats) * samplesPerBeat;
156
positionInBeats = Math.floor(positionInBeats) * samplesPerBeat;
157
positionInBeats = Math.floor(0.5 + positionInBeats);
158
positionInBeats = Math.max(0,positionInBeats - positionInBeats % 2);
159
engine.setValue(group, 'hotcue_' + cueIndex + '_activate', 1);
160
engine.setValue(group, 'hotcue_' + cueIndex + '_position',positionInBeats);
163
engine.setValue(group, 'hotcue_' + cueIndex + '_clear',1);
165
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
168
DenonDNSC2000.loopIn = function(group, value, shift) {
170
engine.setValue(group, 'loop_start_position', -1);
173
engine.setValue(group, 'loop_in', 1);
174
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
177
DenonDNSC2000.loopOut = function(group, value, shift) {
179
engine.setValue(group, 'loop_end_position', -1);
180
if(engine.getValue(group,'loop_enabled'))
181
engine.setValue(group, 'reloop_exit', 1);
184
engine.setValue(group, 'loop_out', 1);
185
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
188
DenonDNSC2000.reloop = function(group, value, shift) {
189
var loopInPosition = engine.getValue(group,'loop_start_position');
190
var loopOutPosition = engine.getValue(group,'loop_end_position');
191
if(loopInPosition != -1 && loopOutPosition!=-1) {
192
engine.setValue(group, 'reloop_exit', 1);
195
var samplesPerBeat = DenonDNSC2000.samplesPerBeat(group);
196
loopInPosition = engine.getValue(group,'playposition') * engine.getValue(group,'track_samples');
198
var loopInPositionInBeats = loopInPosition / samplesPerBeat;
199
if((loopInPositionInBeats - Math.floor(loopInPositionInBeats)) > 0.5)
200
loopInPosition = Math.floor(0.5 + loopInPositionInBeats) * samplesPerBeat;
202
loopInPosition = Math.floor(loopInPositionInBeats) * samplesPerBeat;
205
loopInPosition = engine.getValue(group,'playposition') * engine.getValue(group,'track_samples');
206
loopInPosition = Math.floor(0.5 + loopInPosition);
207
loopInPosition = Math.max(0,loopInPosition - loopInPosition % 2);
208
var loopOutPosition = loopInPosition + Math.floor(0.5 + samplesPerBeat);
209
loopOutPosition = Math.max(0,loopOutPosition - loopOutPosition % 2);
210
if(loopInPosition + samplesPerBeat < engine.getValue(group,'track_samples')) {
211
engine.setValue(group, 'loop_start_position', loopInPosition);
212
engine.setValue(group, 'loop_end_position', loopOutPosition);
213
engine.setValue(group, 'reloop_exit', 1);
216
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
219
DenonDNSC2000.resizeLoop = function(midino, control, value, status, group) {
220
var increment = true;
223
var loopInPosition = engine.getValue(group,'loop_start_position');
224
var loopOutPosition = engine.getValue(group,'loop_end_position');
225
if(loopInPosition != -1 && loopOutPosition!= -1) {
226
var samplesPerBeat = DenonDNSC2000.samplesPerBeat(group);
227
var deltaSamples = loopOutPosition - loopInPosition;
228
var newLoopOutPosition = loopOutPosition;
230
Math.floor(0.5 + samplesPerBeat * 1 / 32),
231
Math.floor(0.5 + samplesPerBeat * 1 / 16),
232
Math.floor(0.5 + samplesPerBeat * 1 / 8),
233
Math.floor(0.5 + samplesPerBeat * 1 / 4),
234
Math.floor(0.5 + samplesPerBeat * 1 / 2),
235
Math.floor(0.5 + samplesPerBeat),
236
Math.floor(0.5 + samplesPerBeat * 2),
237
Math.floor(0.5 + samplesPerBeat * 4),
238
Math.floor(0.5 + samplesPerBeat * 8),
239
Math.floor(0.5 + samplesPerBeat * 16),
240
Math.floor(0.5 + samplesPerBeat * 32)
244
for(var index = 0, count = loopLengthes.length;index < count; index++) {
245
if(deltaSamples < loopLengthes[index]) {
246
newLoopOutPosition = loopInPosition + loopLengthes[index];
252
for(var index = loopLengthes.length-1;index >= 0; index--) {
253
if(deltaSamples > loopLengthes[index]) {
254
newLoopOutPosition = loopInPosition + loopLengthes[index];
259
newLoopOutPosition = Math.max(0,newLoopOutPosition - newLoopOutPosition % 2);
260
engine.setValue(group, 'loop_end_position', newLoopOutPosition);
262
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
265
DenonDNSC2000.moveLoopLeft = function(midino, control, value, status, group) {
266
var samplesPerBeat = Math.floor(0.5 + DenonDNSC2000.samplesPerBeat(group));
267
var loopInPosition = engine.getValue(group,'loop_start_position');
268
var loopOutPosition = engine.getValue(group,'loop_end_position');
269
if(loopInPosition != -1 && loopOutPosition != -1 && loopInPosition > samplesPerBeat) {
270
loopInPosition = loopInPosition - samplesPerBeat;
271
loopInPosition = Math.max(0,loopInPosition - loopInPosition % 2);
272
loopOutPosition = loopOutPosition - samplesPerBeat;
273
loopOutPosition = Math.max(0,loopOutPosition - loopOutPosition % 2);
274
engine.setValue(group, 'loop_start_position', loopInPosition);
275
engine.setValue(group, 'loop_end_position', loopOutPosition);
279
DenonDNSC2000.moveLoopRight = function(midino, control, value, status, group) {
280
var samplesPerBeat = Math.floor(0.5 + DenonDNSC2000.samplesPerBeat(group));
281
var loopInPosition = engine.getValue(group,'loop_start_position');
282
var loopOutPosition = engine.getValue(group,'loop_end_position');
283
if(loopInPosition != -1 && loopOutPosition != -1 && loopOutPosition + samplesPerBeat < engine.getValue(group,'track_samples')) {
284
loopInPosition = loopInPosition + samplesPerBeat;
285
loopInPosition = Math.max(0,loopInPosition - loopInPosition % 2);
286
loopOutPosition = loopOutPosition + samplesPerBeat;
287
loopOutPosition = Math.max(0,loopOutPosition - loopOutPosition % 2);
288
engine.setValue(group, 'loop_start_position', loopInPosition);
289
engine.setValue(group, 'loop_end_position', loopOutPosition);
293
DenonDNSC2000.play = function (midino, control, value, status, group) {
295
if ((status & 0xF0) == 0x90 && engine.getValue(group, 'play') == 1)
296
engine.setValue(group, 'reverse', 1);
298
if ((status & 0xF0) == 0x80 && engine.getValue(group, 'play') == 1)
299
engine.setValue(group, 'reverse', 0);
302
if((status & 0xF0) == 0x90) {
303
DenonDNSC2000.toggleBinaryValue(group,'play');
306
engine.beginTimer(100, 'DenonDNSC2000.handlePlayLed("'+group+'")', true);
309
DenonDNSC2000.cue = function (midino, control, value, status, group) {
310
var ledChannel = DenonDNSC2000.getLedChannelByGroup(group);
311
if ((status & 0xF0) == 0x90) {
312
engine.setValue(group, 'cue_default', 1);
313
midi.sendShortMsg(ledChannel,0x4A,0x26);
316
if ((status & 0xF0) == 0x80) {
317
engine.setValue(group, 'cue_default', 0);
318
midi.sendShortMsg(ledChannel,0x4B,0x26);
322
DenonDNSC2000.keyLock = function (midino, control, value, status, group) {
323
if ((status & 0xF0) == 0x90) {
324
DenonDNSC2000.toggleBinaryValue(group,'keylock');
325
engine.beginTimer(100, 'DenonDNSC2000.handleKeyLockLed("'+group+'")', true);
329
DenonDNSC2000.beatSync = function (midino, control, value, status, group) {
330
if ((status & 0xF0) == 0x90) {
331
DenonDNSC2000.toggleBinaryValue(group,'beatsync');
332
engine.beginTimer(100, 'DenonDNSC2000.handleBeatSyncLed("'+group+'")', true);
336
DenonDNSC2000.pitchBend = function (midino, control, value, status, group) {
339
if ((status & 0xF0) == 0x90)
340
engine.setValue(group, 'rate_temp_down', 1);
342
engine.setValue(group, 'rate_temp_down', 0);
345
if ((status & 0xF0) == 0x90)
346
engine.setValue(group, 'rate_temp_up', 1);
348
engine.setValue(group, 'rate_temp_up', 0);
353
DenonDNSC2000.jog = function (midino, control, value, status, group) {
354
var deck = DenonDNSC2000.getDeckByGroup(group);
355
if(!deck.scratchMode)
356
deck.picthJog(value);
358
deck.scratchJog(value);
361
DenonDNSC2000.jogTouch = function (midino, control, value, status, group) {
362
DenonDNSC2000.getDeckByGroup(group).jogTouch(midino, control, value, status, group);
365
DenonDNSC2000.handleLoopAndHotcuesLeds = function(group) {
366
var ledChannel = DenonDNSC2000.getLedChannelByGroup(group);
367
var cueLeds = [0x11,0x13,0x15,0x17,0x19,0x1B,0x1D,0x20];
368
for(var index = 0, count = cueLeds.length;index < count; index ++) {
369
DenonDNSC2000.handleLed(ledChannel,(engine.getValue(group,'hotcue_' + (index + 1) + '_position') != -1),cueLeds[index],0x4A,0x4B);
372
var ledChannel = DenonDNSC2000.getLedChannelByGroup(group);
373
DenonDNSC2000.handleLed(ledChannel,(engine.getValue(group, 'loop_start_position') != -1),0x24,0x4A,0x4B);
374
DenonDNSC2000.handleLed(ledChannel,(engine.getValue(group, 'loop_end_position') != -1),0x40,0x4A,0x4B);
375
DenonDNSC2000.handleLed(ledChannel,(engine.getValue(group, 'loop_enabled') == 1),0x2B,0x4A,0x4B);
378
DenonDNSC2000.handlePlayLed = function(group) {
379
DenonDNSC2000.handleLed(DenonDNSC2000.getLedChannelByGroup(group),(engine.getValue(group, 'play') == 1),0x27,0x4A,0x4C);
382
DenonDNSC2000.handleKeyLockLed = function (group) {
383
DenonDNSC2000.handleLed(DenonDNSC2000.getLedChannelByGroup(group),(engine.getValue(group, 'keylock') == 1),0x08,0x4A,0x4B);
386
DenonDNSC2000.handleBeatSyncLed = function (group) {
387
DenonDNSC2000.handleLed(DenonDNSC2000.getLedChannelByGroup(group),(engine.getValue(group, 'beatsync') == 1),0x09,0x4A,0x4B);
390
DenonDNSC2000.handleFlangerLed = function (group) {
391
var flangerOn = (engine.getValue(group, 'flanger') == 1);
392
DenonDNSC2000.handleLed(DenonDNSC2000.getLedChannelByGroup(group),flangerOn,0x5A,0x4A,0x4B);
393
DenonDNSC2000.handleLed(DenonDNSC2000.getLedChannelByGroup(group),flangerOn,0x5D,0x4A,0x4B);
394
DenonDNSC2000.handleLed(DenonDNSC2000.getLedChannelByGroup(group),flangerOn,0x5E,0x4A,0x4B);
395
DenonDNSC2000.handleLed(DenonDNSC2000.getLedChannelByGroup(group),flangerOn,0x5F,0x4A,0x4B);
398
DenonDNSC2000.handleLed = function (ledChannel,test,led,stateTrue, stateFalse) {
400
midi.sendShortMsg(ledChannel,stateTrue,led);
403
midi.sendShortMsg(ledChannel,stateFalse,led);
407
DenonDNSC2000.handleLeds = function(group) {
408
DenonDNSC2000.handleLoopAndHotcuesLeds(group);
409
DenonDNSC2000.handleLoopAndHotcuesLeds(group);
410
DenonDNSC2000.handlePlayLed(group);
411
DenonDNSC2000.handleKeyLockLed(group);
412
DenonDNSC2000.handleBeatSyncLed(group);
413
DenonDNSC2000.handleFlangerLed(group);
416
DenonDNSC2000.getLedChannelByGroup = function(group) {
417
if(group == '[Channel1]')
420
if(group == '[Channel2]')
423
if(group == '[Channel3]')
426
if(group == '[Channel4]')
430
DenonDNSC2000.toggleBinaryValue = function(group,key) {
431
engine.setValue(group,key,engine.getValue(group,key)*-1 + 1);
434
DenonDNSC2000.samplesPerBeat = function(group) {
435
return 2 * engine.getValue(group,'track_samplerate') * 60 / engine.getValue(group, "file_bpm");
437
/*******************************************************************************/
438
DenonDNSC2000.Deck.prototype.picthJog = function(value) {
439
value = (value - 0x40)/4;
441
value = value * value;
443
value = -value * value;
445
engine.setValue(this.group,"jog", value);
448
DenonDNSC2000.Deck.prototype.jogTouch = function (midino, control, value, status, group) {
449
if ((status & 0xF0) == 0x90) {
450
engine.scratchEnable(this.deckNumber, 2048, 33+1/3, 1.0/8, (1.0/8)/32);
451
this.scratchMode = true;
454
if ((status & 0xF0) == 0x80) {
455
engine.scratchDisable(this.deckNumber);
456
this.scratchMode = false;
460
DenonDNSC2000.Deck.prototype.scratchJog = function (value) {
461
engine.scratchTick(this.deckNumber,value-0x40);
463
/*******************************************************************************/
464
var shiftPressed = false;
465
var decks = [new DenonDNSC2000.Deck(1,'[Channel1]'),
466
new DenonDNSC2000.Deck(2,'[Channel2]'),
467
new DenonDNSC2000.Deck(3,'[Channel3]'),
468
new DenonDNSC2000.Deck(4,'[Channel4]'),
b'\\ No newline at end of file'