-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DDJ-200: Listen to changes from mixxx #3793
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,11 +19,36 @@ 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 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; | ||||||||||||||
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; | ||||||||||||||
DDJ200.switchSyncLED(d, ch); | ||||||||||||||
}); | ||||||||||||||
|
||||||||||||||
// 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); | ||||||||||||||
Comment on lines
+46
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not use one-character variable names (except
Suggested change
I know the rest of the script does that too, but let's at least fix it for new code :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like one-character variables too, but at same time is good to keep a pattern at the code. Don't you think would be better open a new PR fixing all one-character variables after this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I second @Holzhaus, and I think it should probably be done in this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just the new code or a full refactor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
}); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// set Pioneer CDJ cue mode for all decks | ||||||||||||||
engine.setValue(vgroup, "cue_cdj", true); | ||||||||||||||
} | ||||||||||||||
|
@@ -54,7 +79,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); | ||||||||||||||
|
@@ -320,22 +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")); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
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"]) { | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have the same effect, but please test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This don't work cause the callback function is in another context. As the function executes outside the for loop,
j
will be always 8.I could write this instead:
But I think the code readability would be compromised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you are right: Creating closures in loops: A common mistake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I figured
j
was copied in the loop because its just number. Both of your solutions are fine. You can keep it as is if you like.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Swiftb0y If I had to use JavaScript I would fail miserably. Looked it up out of curiosity and was surprised, unpleasantly of course.