From e27fd43f9bb65ff8be4167c8006d2dbafc120492 Mon Sep 17 00:00:00 2001 From: Geovanni Pacheco Date: Sat, 17 Apr 2021 19:47:16 -0300 Subject: [PATCH 1/3] Listen to changes from mixxx Those updates listen to changes from mixxx interface to replicate at the controller --- res/controllers/Pioneer-DDJ-200-scripts.js | 33 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/res/controllers/Pioneer-DDJ-200-scripts.js b/res/controllers/Pioneer-DDJ-200-scripts.js index 25fc5d9700c..2106210a0b2 100644 --- a/res/controllers/Pioneer-DDJ-200-scripts.js +++ b/res/controllers/Pioneer-DDJ-200-scripts.js @@ -19,11 +19,23 @@ DDJ200.init = function() { var vgroup = "[Channel" + i + "]"; - // run onTrackLoad after every track load to set LEDs accordingly + // run updateDeckLeds after every track load to set LEDs accordingly engine.makeConnection(vgroup, "track_loaded", function(ch, vgroup) { - DDJ200.onTrackLoad(ch, vgroup); + DDJ200.updateDeckLeds(vgroup); }); + // run updateDeckLeds after play/pause track to set LEDs accordingly + engine.makeConnection(vgroup, "play", function(ch, vgroup) { + DDJ200.updateDeckLeds(vgroup); + }); + + // run updateDeckLeds after sync toogle to set LEDs accordingly + engine.makeConnection(vgroup, "sync_enabled", function(ch, vgroup) { + DDJ200.updateDeckLeds(vgroup); + }); + + DDJ200.listemHotcues(vgroup); + // set Pioneer CDJ cue mode for all decks engine.setValue(vgroup, "cue_cdj", true); } @@ -36,6 +48,15 @@ DDJ200.init = function() { }, true); }; +DDJ200.listemHotcues = function(vgroup) { + for (var i = 1; i <= 8; i++) { + // run updateDeckLeds after every hotcue update + engine.makeConnection(vgroup, "hotcue_" + i + "_enabled", function(ch, vgroup) { + DDJ200.updateDeckLeds(vgroup); + }); + } +}; + DDJ200.shutdown = function() { DDJ200.LEDsOff(); }; @@ -54,7 +75,7 @@ DDJ200.LEDsOff = function() { // turn off LED buttons: } }; -DDJ200.onTrackLoad = function(channel, vgroup) { +DDJ200.updateDeckLeds = function(vgroup) { // set LEDs (hotcues, etc.) for the loaded deck // if controller is switched to this deck var vDeckNo = script.deckFromGroup(vgroup); @@ -330,6 +351,12 @@ DDJ200.switchLEDs = function(vDeckNo) { 0x7F * engine.getValue(vgroup, "pfl")); } + DDJ200.switchHotcueLEDs(vDeckNo); +}; + +DDJ200.switchHotcueLEDs = function(vDeckNo) { + var d = (vDeckNo % 2) ? 0 : 1; // d = deckNo - 1 + var vgroup = "[Channel" + vDeckNo + "]"; for (var i = 1; i <= 8; i++) { midi.sendShortMsg(0x97 + 2 * d, i - 1, 0x7F * engine.getValue( vgroup, "hotcue_" + i + "_enabled")); From 1923a3da88be58bf543cbb55d52facd5705bf2fd Mon Sep 17 00:00:00 2001 From: Geovanni Pacheco Date: Sat, 17 Apr 2021 22:32:32 -0300 Subject: [PATCH 2/3] Optimize code changing only necessary leds --- res/controllers/Pioneer-DDJ-200-scripts.js | 59 +++++++++++++--------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/res/controllers/Pioneer-DDJ-200-scripts.js b/res/controllers/Pioneer-DDJ-200-scripts.js index 2106210a0b2..af57e646f98 100644 --- a/res/controllers/Pioneer-DDJ-200-scripts.js +++ b/res/controllers/Pioneer-DDJ-200-scripts.js @@ -24,17 +24,30 @@ DDJ200.init = function() { DDJ200.updateDeckLeds(vgroup); }); - // run updateDeckLeds after play/pause track to set LEDs accordingly + // run switchPlayLED after play/pause track to set LEDs accordingly engine.makeConnection(vgroup, "play", function(ch, vgroup) { - DDJ200.updateDeckLeds(vgroup); + var vDeckNo = script.deckFromGroup(vgroup); + var d = (vDeckNo % 2) ? 0 : 1; + DDJ200.switchPlayLED(d, ch); }); - // run updateDeckLeds after sync toogle to set LEDs accordingly + // run switchSyncLED after sync toogle to set LEDs accordingly engine.makeConnection(vgroup, "sync_enabled", function(ch, vgroup) { - DDJ200.updateDeckLeds(vgroup); + var vDeckNo = script.deckFromGroup(vgroup); + var d = (vDeckNo % 2) ? 0 : 1; + DDJ200.switchSyncLED(d, ch); }); - DDJ200.listemHotcues(vgroup); + // listen to changes on hotcues + for (var j = 1; j <= 8; j++) { + // run switchPadLED after every hotcue update + engine.makeConnection(vgroup, "hotcue_" + j + "_enabled", function(ch, vgroup, control) { + var pad = Number(control.split("_")[1]); + var vDeckNo = script.deckFromGroup(vgroup); + var d = (vDeckNo % 2) ? 0 : 1; // d = deckNo - 1 + DDJ200.switchPadLED(d, pad, ch); + }); + } // set Pioneer CDJ cue mode for all decks engine.setValue(vgroup, "cue_cdj", true); @@ -48,15 +61,6 @@ DDJ200.init = function() { }, true); }; -DDJ200.listemHotcues = function(vgroup) { - for (var i = 1; i <= 8; i++) { - // run updateDeckLeds after every hotcue update - engine.makeConnection(vgroup, "hotcue_" + i + "_enabled", function(ch, vgroup) { - DDJ200.updateDeckLeds(vgroup); - }); - } -}; - DDJ200.shutdown = function() { DDJ200.LEDsOff(); }; @@ -341,28 +345,33 @@ DDJ200.switchLEDs = function(vDeckNo) { // set LEDs of controller deck 1 or 2 according to virtual deck var d = (vDeckNo % 2) ? 0 : 1; // d = deckNo - 1 var vgroup = "[Channel" + vDeckNo + "]"; - midi.sendShortMsg(0x90 + d, 0x0B, 0x7F * engine.getValue(vgroup, "play")); + DDJ200.switchPlayLED(d, engine.getValue(vgroup, "play")); midi.sendShortMsg(0x90 + d, 0x0C, 0x7F * (engine.getValue(vgroup, "cue_point") !== -1)); - midi.sendShortMsg(0x90 + d, 0x58, 0x7F * engine.getValue(vgroup, - "sync_enabled")); + DDJ200.switchSyncLED(d, engine.getValue(vgroup, "sync_enabled")); if (!DDJ200.fourDeckMode) { midi.sendShortMsg(0x90 + d, 0x54, 0x7F * engine.getValue(vgroup, "pfl")); } - DDJ200.switchHotcueLEDs(vDeckNo); -}; - -DDJ200.switchHotcueLEDs = function(vDeckNo) { - var d = (vDeckNo % 2) ? 0 : 1; // d = deckNo - 1 - var vgroup = "[Channel" + vDeckNo + "]"; for (var i = 1; i <= 8; i++) { - midi.sendShortMsg(0x97 + 2 * d, i - 1, 0x7F * engine.getValue( - vgroup, "hotcue_" + i + "_enabled")); + var isButtonEnabled = engine.getValue(vgroup, "hotcue_" + i + "_enabled"); + DDJ200.switchPadLED(d, i, isButtonEnabled); } }; +DDJ200.switchPlayLED = function(deck, enabled) { + midi.sendShortMsg(0x90 + deck, 0x0B, 0x7F * enabled); +} + +DDJ200.switchSyncLED = function(deck, enabled) { + midi.sendShortMsg(0x90 + deck, 0x58, 0x7F * enabled); +} + +DDJ200.switchPadLED = function(deck, pad, enabled) { + midi.sendShortMsg(0x97 + 2 * deck, pad - 1, 0x7F * enabled); +} + DDJ200.toggleDeck = function(channel, control, value, status, group) { if (value) { // only if button pressed, not releases, i.e. value === 0 if (DDJ200.shiftPressed["left"]) { From f0ff2fc8e3ae54143b9a73f3fcc850008022859f Mon Sep 17 00:00:00 2001 From: Geovanni Pacheco Date: Sat, 17 Apr 2021 22:54:23 -0300 Subject: [PATCH 3/3] Fix lint problems --- res/controllers/Pioneer-DDJ-200-scripts.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/res/controllers/Pioneer-DDJ-200-scripts.js b/res/controllers/Pioneer-DDJ-200-scripts.js index af57e646f98..e0c3ca1d2b6 100644 --- a/res/controllers/Pioneer-DDJ-200-scripts.js +++ b/res/controllers/Pioneer-DDJ-200-scripts.js @@ -27,14 +27,14 @@ DDJ200.init = function() { // run switchPlayLED after play/pause track to set LEDs accordingly engine.makeConnection(vgroup, "play", function(ch, vgroup) { var vDeckNo = script.deckFromGroup(vgroup); - var d = (vDeckNo % 2) ? 0 : 1; + var d = (vDeckNo % 2) ? 0 : 1; DDJ200.switchPlayLED(d, ch); }); // run switchSyncLED after sync toogle to set LEDs accordingly engine.makeConnection(vgroup, "sync_enabled", function(ch, vgroup) { var vDeckNo = script.deckFromGroup(vgroup); - var d = (vDeckNo % 2) ? 0 : 1; + var d = (vDeckNo % 2) ? 0 : 1; DDJ200.switchSyncLED(d, ch); }); @@ -362,15 +362,15 @@ DDJ200.switchLEDs = function(vDeckNo) { DDJ200.switchPlayLED = function(deck, enabled) { midi.sendShortMsg(0x90 + deck, 0x0B, 0x7F * enabled); -} +}; DDJ200.switchSyncLED = function(deck, enabled) { midi.sendShortMsg(0x90 + deck, 0x58, 0x7F * enabled); -} +}; DDJ200.switchPadLED = function(deck, pad, enabled) { midi.sendShortMsg(0x97 + 2 * deck, pad - 1, 0x7F * enabled); -} +}; DDJ200.toggleDeck = function(channel, control, value, status, group) { if (value) { // only if button pressed, not releases, i.e. value === 0