1
function MaudioXponent () {}
3
// ---------- Global variables ----------
5
MaudioXponent.id = ""; // The ID for the particular device being controlled for use in debugging, set at init time
6
MaudioXponent.off = 0x80;
7
MaudioXponent.on = 0x90;
8
MaudioXponent.mastermeter = 0; //1 for master meter, 0 for channel meter
9
MaudioXponent.flashprogress = 8; //flash duration on progress meters
10
MaudioXponent.leds = {
50
MaudioXponent.binleds = {
60
MaudioXponent.hotcues = {
67
MaudioXponent.timer = [-1]; // Temporary storage of timer IDs
68
MaudioXponent.state = {
79
}; // Temporary state variables
81
// ---------- Functions ----------
83
MaudioXponent.init = function (id) { // called when the MIDI device is opened & set up
85
//This code light on all leds and then light off
86
midi.sendShortMsg(0xB3,0x14,0x00);
87
midi.sendShortMsg(0xB3,0x15,0x00);
88
for (var led in MaudioXponent.leds) {
89
midi.sendShortMsg(MaudioXponent.on,MaudioXponent.leds[led],0x01);
90
midi.sendShortMsg(MaudioXponent.on + 1,MaudioXponent.leds[led],0x01);
91
MaudioXponent.pauseScript(15);
93
midi.sendShortMsg(0xB3,0x12,0x7F);
94
midi.sendShortMsg(0xB3,0x13,0x7F);
95
midi.sendShortMsg(0xB3,0x14,0x7F);
96
midi.sendShortMsg(0xB3,0x15,0x7F);
97
MaudioXponent.pauseScript(500);
98
for (var led in MaudioXponent.leds) {
99
midi.sendShortMsg(MaudioXponent.on,MaudioXponent.leds[led],0x00);
100
midi.sendShortMsg(MaudioXponent.on + 1,MaudioXponent.leds[led],0x00);
101
MaudioXponent.pauseScript(15);
103
midi.sendShortMsg(0xB3,0x14,0x00);
104
midi.sendShortMsg(0xB3,0x15,0x00);
105
//end of light on all leds
107
MaudioXponent.flashdur1 = 0;
108
MaudioXponent.flashdur2 = 0;
109
engine.connectControl("[Channel1]","visual_playposition","MaudioXponent.playPositionMeter1");
110
engine.connectControl("[Channel2]","visual_playposition","MaudioXponent.playPositionMeter2");
111
if (MaudioXponent.mastermeter == 1) {
112
engine.connectControl("[Master]","VuMeterL","MaudioXponent.volumeLEDs1");
113
engine.connectControl("[Master]","VuMeterR","MaudioXponent.volumeLEDs2");
115
engine.connectControl("[Channel1]","VuMeter","MaudioXponent.volumeLEDs1");
116
engine.connectControl("[Channel2]","VuMeter","MaudioXponent.volumeLEDs2");
119
engine.connectControl("[Channel1]","hotcue_1_enabled","MaudioXponent.hotcue");
120
engine.connectControl("[Channel1]","hotcue_2_enabled","MaudioXponent.hotcue");
121
engine.connectControl("[Channel1]","hotcue_3_enabled","MaudioXponent.hotcue");
122
engine.connectControl("[Channel1]","hotcue_4_enabled","MaudioXponent.hotcue");
123
engine.connectControl("[Channel1]","hotcue_5_enabled","MaudioXponent.hotcue");
124
engine.connectControl("[Channel2]","hotcue_1_enabled","MaudioXponent.hotcue");
125
engine.connectControl("[Channel2]","hotcue_2_enabled","MaudioXponent.hotcue");
126
engine.connectControl("[Channel2]","hotcue_3_enabled","MaudioXponent.hotcue");
127
engine.connectControl("[Channel2]","hotcue_4_enabled","MaudioXponent.hotcue");
128
engine.connectControl("[Channel2]","hotcue_5_enabled","MaudioXponent.hotcue");
130
//engine.connectControl("[Channel1]","bpm","MaudioXponent.bpmsync");
134
MaudioXponent.wheel = function (channel, control, value, status) {
135
var currentdeck = channel+1;
137
// In either case, register the movement
139
if (MaudioXponent.state["shift"+currentdeck] == 1) {
141
MaudioXponent.state["plnumberpos"]++;
142
if (MaudioXponent.state["plnumberpos"] % 12 == 0) {
143
engine.setValue("[Playlist]","SelectTrackKnob",1);
145
} else if (value < 64) {
146
MaudioXponent.state["plnumberneg"]++;
147
if (MaudioXponent.state["plnumberneg"] % 12 == 0) {
148
engine.setValue("[Playlist]","SelectTrackKnob",-1);
152
if (MaudioXponent.state["scratching"+currentdeck] == 1) { //scratch mode on
153
engine.scratchTick(currentdeck, value-64);
154
} else { //normal wheel mode
155
engine.setValue("[Channel"+currentdeck+"]", "jog", (value-64)*4);
160
MaudioXponent.wheelbuton = function(channel, control, value, status) {
161
var currentdeck = channel+1;
162
if (MaudioXponent.state["scrmode"+currentdeck] == 1) { //scratch mode on
163
engine.scratchEnable(currentdeck, 3*128, 33+1/3, 1.0/8, (1.0/8)/32);
164
MaudioXponent.state["scratching"+currentdeck] = true;
168
MaudioXponent.wheelbutoff = function(channel, control, value, status) {
169
var currentdeck = channel+1;
170
engine.scratchDisable (currentdeck);
171
MaudioXponent.state["scratching"+currentdeck] = false;
174
MaudioXponent.pauseScript = function(ms) {
175
startDate = new Date();
177
while(currentDate-startDate < ms) currentDate = new Date();
180
MaudioXponent.playPositionMeter1 = function(value) {
182
MaudioXponent.flashdur1++;;
183
if (MaudioXponent.flashdur1 == MaudioXponent.flashprogress) {
184
midi.sendShortMsg(0xB3,0x14,0x00);
186
if (MaudioXponent.flashdur1 >= MaudioXponent.flashprogress*2) {
187
midi.sendShortMsg(0xB3,0x14,MaudioXponent.convert(value));
188
MaudioXponent.flashdur1 = 0;
191
midi.sendShortMsg(0xB3,0x14,MaudioXponent.convert(value));
195
MaudioXponent.playPositionMeter2 = function(value) {
197
MaudioXponent.flashdur2++;;
198
if (MaudioXponent.flashdur2 == MaudioXponent.flashprogress) {
199
midi.sendShortMsg(0xB3,0x15,0x00);
201
if (MaudioXponent.flashdur2 >= MaudioXponent.flashprogress*2) {
202
midi.sendShortMsg(0xB3,0x15,MaudioXponent.convert(value));
203
MaudioXponent.flashdur2 = 0;
206
midi.sendShortMsg(0xB3,0x15,MaudioXponent.convert(value));
210
MaudioXponent.volumeLEDs1 = function(value) {
211
midi.sendShortMsg(0xB3,0x12,MaudioXponent.convert(value));
214
MaudioXponent.volumeLEDs2 = function(value) {
215
midi.sendShortMsg(0xB3,0x13,MaudioXponent.convert(value));
218
MaudioXponent.convert = function(value) {
220
value = value.toFixed(0);
221
value = value.toString(16);
225
MaudioXponent.actbin = function(channel, control, value, status) { // Generic binary button
226
var currentdeck = channel+1;
227
var activenow = engine.getValue("[Channel"+currentdeck+"]",MaudioXponent.binleds[control]);
228
if (activenow == 1) { // If currently active
229
engine.setValue("[Channel"+currentdeck+"]",MaudioXponent.binleds[control],0); // Stop
230
midi.sendShortMsg(MaudioXponent.off + channel,control,0x00); // Turn off the LED
231
}else { // If not currently active
232
engine.setValue("[Channel"+currentdeck+"]",MaudioXponent.binleds[control],1); // Start
233
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
237
MaudioXponent.actbinstop = function(channel, control, value, status) { // Generic binary button
238
print ("sono sulla stop");
239
var currentdeck = channel+1;
240
engine.setValue("[Channel"+currentdeck+"]",MaudioXponent.binleds[control],0); // Stop
241
midi.sendShortMsg(MaudioXponent.off + channel,control,0x00); // Turn off the LED
244
MaudioXponent.hotcue = function(channel, control, value, status) { // Generic binary button
246
if (control == "[Channel2]") {
250
case "hotcue_1_enabled":
252
midi.sendShortMsg(MaudioXponent.on + channelnow,0x17,0x01); // Turn on the LED
254
midi.sendShortMsg(MaudioXponent.on + channelnow,0x17,0x00); // Turn off the LED
257
case "hotcue_2_enabled":
259
midi.sendShortMsg(MaudioXponent.on + channelnow,0x18,0x01); // Turn on the LED
261
midi.sendShortMsg(MaudioXponent.on + channelnow,0x18,0x00); // Turn off the LED
264
case "hotcue_3_enabled":
266
midi.sendShortMsg(MaudioXponent.on + channelnow,0x19,0x01); // Turn on the LED
268
midi.sendShortMsg(MaudioXponent.on + channelnow,0x19,0x00); // Turn off the LED
271
case "hotcue_4_enabled":
273
midi.sendShortMsg(MaudioXponent.on + channelnow,0x1A,0x01); // Turn on the LED
275
midi.sendShortMsg(MaudioXponent.on + channelnow,0x1A,0x00); // Turn off the LED
278
case "hotcue_5_enabled":
280
midi.sendShortMsg(MaudioXponent.on + channelnow,0x1B,0x01); // Turn on the LED
282
midi.sendShortMsg(MaudioXponent.on + channelnow,0x1B,0x00); // Turn off the LED
288
MaudioXponent.hotcueset = function(channel, control, value, status) {
289
//MaudioXponent.debug(channel, control, value, status)
290
var currentdeck = channel+1;
291
if (MaudioXponent.state["shift"+currentdeck] == 1) {
292
engine.setValue("[Channel"+currentdeck+"]","hotcue_"+MaudioXponent.hotcues[control]+"_clear",1);
294
engine.setValue("[Channel"+currentdeck+"]","hotcue_"+MaudioXponent.hotcues[control]+"_activate",1);
298
MaudioXponent.loopin = function(channel, control, value, status) {
299
//MaudioXponent.debug(channel, control, value, status)
300
var currentdeck = channel+1;
301
engine.setValue("[Channel"+currentdeck+"]","loop_in",1);
302
midi.sendShortMsg(MaudioXponent.on + channel,0x29,0x01);
304
MaudioXponent.state["flashes"] = 0; // initialize number of flashes
305
MaudioXponent.timer[0] = engine.beginTimer(250,"MaudioXponent.flashled("+ channel +",\"0x2B\")");
308
MaudioXponent.loopout = function(channel, control, value, status) {
309
//MaudioXponent.debug(channel, control, value, status)
310
var currentdeck = channel+1;
311
engine.setValue("[Channel"+currentdeck+"]","loop_out",1);
312
if (MaudioXponent.timer[0] != -1) engine.stopTimer(MaudioXponent.timer[0]);
313
midi.sendShortMsg(MaudioXponent.on + channel,0x2B,0x01); // Turn on the LED
314
MaudioXponent.timer[1] = engine.beginTimer(250,"MaudioXponent.flashled("+ channel +",\"0x2A\")");
317
MaudioXponent.loopexit = function(channel, control, value, status) {
318
var currentdeck = channel+1;
319
var activenow = engine.getValue("[Channel"+currentdeck+"]","reloop_exit");
320
if (activenow == 1) { // If currently active
321
print ("dentro loop");
322
}else { // If not currently active
323
print ("fuori loop");
325
engine.setValue("[Channel"+currentdeck+"]","reloop_exit",1);
326
//midi.sendShortMsg(MaudioXponent.on + channel,0x2A,0x01); // Turn on the LED
329
MaudioXponent.flashled = function (channel, control) {
330
MaudioXponent.state["flashes"]++;
331
if (MaudioXponent.state["flashes"] % 2 == 0) {
332
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
334
midi.sendShortMsg(MaudioXponent.on + channel,control,0x00); // Turn off the LED
338
MaudioXponent.faderbuttonon = function(channel, control, value, status) {
339
//script.debug(channel, control, value, status);
340
MaudioXponent.state["faderpos"] = engine.getValue("[Master]","crossfader");
341
if (MaudioXponent.state["faderpos"] <= -0.90 && channel == 1) {
342
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
343
engine.setValue("[Master]","crossfader",0);
344
}else if (MaudioXponent.state["faderpos"] >= 0.90 && channel == 0) {
345
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
346
engine.setValue("[Master]","crossfader",0);
350
MaudioXponent.faderbuttonoff = function(channel, control, value, status) {
351
//script.debug(channel, control, value, status);
352
if (MaudioXponent.state["faderpos"] <= -0.90 && channel == 1) {
353
midi.sendShortMsg(MaudioXponent.on + channel,control,0x00); // Turn off the LED
354
engine.setValue("[Master]","crossfader",MaudioXponent.state["faderpos"]);
355
}else if (MaudioXponent.state["faderpos"] >= 0.90 && channel == 0) {
356
midi.sendShortMsg(MaudioXponent.on + channel,control,0x00); // Turn off the LED
357
engine.setValue("[Master]","crossfader",MaudioXponent.state["faderpos"]);
361
MaudioXponent.bpmsync = function(channel, control, value) {
366
MaudioXponent.pitch = function(channel, control, value, status) {
367
var currentdeck = channel+1;
368
engine.setValue("[Channel"+currentdeck+"]","rate",script.pitch(control, value, status));
371
MaudioXponent.secondaryon = function(channel, control, value, status) {
372
var currentdeck = channel+1;
373
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
374
MaudioXponent.state["shift"+currentdeck] = 1;
377
MaudioXponent.secondaryoff = function(channel, control, value, status) {
378
var currentdeck = channel+1;
379
midi.sendShortMsg(MaudioXponent.on + channel,control,0x00); // Turn on the LED
380
MaudioXponent.state["shift"+currentdeck] = 0;
383
MaudioXponent.flanger = function(channel, control, value, status) {
384
script.debug(channel, control, value, status);
386
var activenow = engine.getValue("[Channel1]","flanger");
387
if (activenow == 1) { // If currently active
388
midi.sendShortMsg(MaudioXponent.on+1,control,0x00); // Turn off the LED
389
engine.setValue("[Channel1]","flanger",0);
391
midi.sendShortMsg(MaudioXponent.on+1,control,0x01); // Turn on the LED
392
engine.setValue("[Channel1]","flanger",1);
394
}else if (control == 13) {
395
var activenow = engine.getValue("[Channel2]","flanger");
396
if (activenow == 1) { // If currently active
397
midi.sendShortMsg(MaudioXponent.on+1,control,0x00); // Turn off the LED
398
engine.setValue("[Channel2]","flanger",0);
400
midi.sendShortMsg(MaudioXponent.on+1,control,0x01); // Turn on the LED
401
engine.setValue("[Channel2]","flanger",1);
406
MaudioXponent.scrmode = function(channel, control, value, status) {
407
var currentdeck = channel+1;
408
if (MaudioXponent.state["scrmode"+currentdeck] == 1) {
409
midi.sendShortMsg(MaudioXponent.on + channel,control,0x00); // Turn off the LED
410
MaudioXponent.state["scrmode"+currentdeck] = 0;
412
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
413
MaudioXponent.state["scrmode"+currentdeck] = 1;
417
MaudioXponent.playlist = function(channel, control, value, status) {
418
var currentdeck = channel+1;
421
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
422
engine.setValue("[Playlist]","SelectPrevTrack",1);
425
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
426
engine.setValue("[Playlist]","SelectNextTrack",1);
429
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
430
var activenow = engine.getValue("[Channel"+currentdeck+"]","play");
431
if (activenow == 1) { // If currently active
432
engine.setValue("[Playlist]","LoadSelectedIntoFirstStopped",1);
434
engine.setValue("[Channel"+currentdeck+"]","LoadSelectedTrack",1);
438
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
439
engine.setValue("[Playlist]","SelectPrevPlaylist",1);
442
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
443
engine.setValue("[Playlist]","SelectNextPlaylist",1);
448
MaudioXponent.playlistoff = function(channel, control, value, status) {
449
midi.sendShortMsg(MaudioXponent.off + channel,control,0x00); // Turn off the LED
452
MaudioXponent.cuedefon = function(channel, control, value, status) {
453
var currentdeck = channel+1;
454
engine.setValue("[Channel"+currentdeck+"]","cue_default",1);
455
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
458
MaudioXponent.cuedefoff = function(channel, control, value, status) {
459
var currentdeck = channel+1;
460
engine.setValue("[Channel"+currentdeck+"]","cue_default",0);
461
midi.sendShortMsg(MaudioXponent.off + channel,control,0x00); // Turn off the LED
464
MaudioXponent.volbuttonon = function(channel, control, value, status) {
465
//script.debug(channel, control, value, status);
466
var currentdeck = channel+1;
467
engine.setValue("[Channel"+currentdeck+"]","volume",0);
468
midi.sendShortMsg(MaudioXponent.on + channel,control,0x01); // Turn on the LED
471
MaudioXponent.volbuttonoff = function(channel, control, value, status) {
472
//script.debug(channel, control, value, status);
473
var currentdeck = channel+1;
474
engine.setValue("[Channel"+currentdeck+"]","volume",1);
475
midi.sendShortMsg(MaudioXponent.off + channel,control,0x00); // Turn off the LED
478
MaudioXponent.shutdown = function (id) { // called when the MIDI device is closed
480
for (var led in MaudioXponent.leds) {
481
midi.sendShortMsg(MaudioXponent.on,MaudioXponent.leds[led],0x00); // Turn off deck 1 lights
482
midi.sendShortMsg(MaudioXponent.on + 1,MaudioXponent.leds[led],0x00); // Turn off deck 2 lights
484
midi.sendShortMsg(0xB3,0x14,0x00);
485
midi.sendShortMsg(0xB3,0x15,0x00);