Skip to content

Commit

Permalink
fix(controller): mass replace outdated usage idioms of `engine.beginT…
Browse files Browse the repository at this point in the history
…imer`

Due to the switch to QJSEngine in Mixxx 2.4 the previous API
where the `this` of the callback function was set to the `this` in the
calling context of the `beginTimer` is not possible to retain
(nor does it make much sense anymore). For this reason this commit
fixes all controllers where this behavior was assumed and updates
the rest of them to use arrow functions instead of anonymous function
expressions or strings.
  • Loading branch information
Swiftb0y committed Dec 5, 2023
1 parent a93beb7 commit 306bbe4
Show file tree
Hide file tree
Showing 80 changed files with 333 additions and 385 deletions.
10 changes: 5 additions & 5 deletions res/controllers/Akai-LPD8-RK-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ LPD8RK.init = function (id, debug) { // called when the device is opened & set u
engine.softTakeover("[Sampler2]","rate",true);

//set LED timer
LPD8RK.ledTimer = engine.beginTimer(LPD8RK.LEDinterval, "LPD8RK.setLeds()");
LPD8RK.ledTimer = engine.beginTimer(LPD8RK.LEDinterval, LPD8RK.setLeds);
};

LPD8RK.shutdown = function () {
Expand All @@ -263,7 +263,7 @@ LPD8RK.shutdown = function () {
LPD8RK.resetLEDTimer = function () {
engine.stopTimer(LPD8RK.ledTimer);
LPD8RK.setLeds()
LPD8RK.ledTimer = engine.beginTimer(LPD8RK.LEDinterval, "LPD8RK.setLeds()");
LPD8RK.ledTimer = engine.beginTimer(LPD8RK.LEDinterval, LPD8RK.setLeds);
};

LPD8RK.setLeds = function () {
Expand Down Expand Up @@ -376,7 +376,7 @@ LPD8RK.reloopButton = function (channel, control, value, status, group) {
engine.stopTimer(LPD8RK.reloopTimer);
LPD8RK.loopbuttonDown=true;
LPD8RK.doreloop=true;
LPD8RK.reloopTimer = engine.beginTimer(500, "LPD8RK.disablereloop()", true);
LPD8RK.reloopTimer = engine.beginTimer(500, LPD8RK.disablereloop, true);
} else {//button was released
LPD8RK.loopbuttonDown=false;
if (LPD8RK.doreloop===true) {engine.setValue(group, "reloop_exit", 1);};
Expand Down Expand Up @@ -437,11 +437,11 @@ LPD8RK.hotcueBankDial = function (channel, control, value, status, group) {
LPD8RK.oldHotcueBank=LPD8RK.hotcueBank;
//set timer to clear old bank number after 500 msec, so bank indicator light will light up
engine.stopTimer(LPD8RK.oldbanktimer);
LPD8RK.oldbanktimer = engine.beginTimer(500, "LPD8RK.resetOldBank()", true);
LPD8RK.oldbanktimer = engine.beginTimer(500, LPD8RK.resetOldBank, true);

//set timer to restart LED updates in 500 msec
engine.stopTimer(LPD8RK.LEDPauseTimer);
LPD8RK.LEDPauseTimer = engine.beginTimer(LPD8RK.LEDinterval, "LPD8RK.resetLEDTimer()", true);
LPD8RK.LEDPauseTimer = engine.beginTimer(LPD8RK.LEDinterval, LPD8RK.resetLEDTimer, true);
};

LPD8RK.looplenDial = function (channel, control, value, status, group) {
Expand Down
2 changes: 1 addition & 1 deletion res/controllers/American-Audio-VMS2-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ VMS2.playlight = function(value, group, control) {
deck.Buttons.Pause.setLed(LedState.on);
// start a fancy blink timer
deck.switchPlaylightOff = true;
deck.playTimer = engine.beginTimer(500,"VMS2.playlightflash(\""+group+"\")");
deck.playTimer = engine.beginTimer(500,()=>VMS2.playlightflash(group));
}
};

Expand Down
2 changes: 1 addition & 1 deletion res/controllers/Behringer-BCD3000-Advanced-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ BehringerBCD3000.jogWheel = function (channel, control, value, status, group) {
scratchValue = (value - 0x40);
engine.scratchEnable(deck + 1, 100, 33+1/3, 1.0/8, (1.0/8)/32);
engine.scratchTick(deck + 1, scratchValue);
BehringerBCD3000.scratchTimer[deck] = engine.beginTimer(20, "BehringerBCD3000.stopScratch(" + deck + ")", true);
BehringerBCD3000.scratchTimer[deck] = engine.beginTimer(20, ()=>BehringerBCD3000.stopScratch(deck), true);

} else if (BehringerBCD3000.onKey) {
if (value > 0x40){
Expand Down
2 changes: 1 addition & 1 deletion res/controllers/Behringer-CMDStudio4a-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ BehringerCMDStudio4a.hotcue = function (channel, control, value, status, group)
// https://github.com/mixxxdj/mixxx/issues/8456
// Changed timer from 50 to 100 after the pathology of this
// bug was explained in the bug report.
engine.beginTimer(100, function() { engine.setValue(group, "slip_enabled", 1); }, 1);
engine.beginTimer(100, () => engine.setValue(group, "slip_enabled", 1), 1);
}
}
} else {
Expand Down
9 changes: 4 additions & 5 deletions res/controllers/Behringer-Extension-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,11 @@
isEnabled: function() { return this.id !== 0; },
start: function() {
this.reset();
var timer = this;
this.id = engine.beginTimer(this.timeout, function() {
if (timer.oneShot) {
timer.disable();
this.id = engine.beginTimer(this.timeout, () => {
if (this.oneShot) {
this.disable();
}
timer.action.call(timer.owner);
this.action.call(this.owner);
}, this.oneShot);
},
reset: function() {
Expand Down
2 changes: 1 addition & 1 deletion res/controllers/DJ-Tech-CDJ-101-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ DJTechCDJ101.jogtouch = function(channel, control, value, status, group)
}
else {
DJTechCDJ101.outer2inner = true;
DJTechCDJ101.scratch_timer = engine.beginTimer(DJTechCDJ101.scratch_timeout, 'DJTechCDJ101.finishScratch(' + deck + ', true)');
DJTechCDJ101.scratch_timer = engine.beginTimer(DJTechCDJ101.scratch_timeout, () => DJTechCDJ101.finishScratch(deck, true));
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions res/controllers/DJ-Tech-Kontrol-One-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ KONTROL1.mod["s"]={state:"o",timer:false,doshift:true};
KONTROL1.init = function init(id, debug) { // called when the device is opened & set up
if (KONTROL1.debug>2){print("##function: "+KONTROL1.getFunctionName())};
KONTROL1.updateLEDs();
if(KONTROL1.disableFlash!==true)KONTROL1.ledTimer = engine.beginTimer(1000, "KONTROL1.doLEDs()");//set timer for LED indicator flashes
if(KONTROL1.disableFlash!==true)KONTROL1.ledTimer = engine.beginTimer(1000, KONTROL1.doLEDs);//set timer for LED indicator flashes
engine.connectControl("[Channel1]", "volume", "KONTROL1.testconnect");
};

Expand Down Expand Up @@ -113,7 +113,7 @@ KONTROL1.knobPress = function knobPress(knobnum){
//{state:"o",timer:false,dobankswitch:true};
KONTROL1.modPress(knobnum);//turn mod on
engine.stopTimer(KONTROL1.mod[knobnum]["timer"]);//kill any previous timer
KONTROL1.mod[knobnum]["timer"]=engine.beginTimer(KONTROL1.modTimeout, "KONTROL1.disableBankSwitch('"+knobnum+"')", true);
KONTROL1.mod[knobnum]["timer"]=engine.beginTimer(KONTROL1.modTimeout, () => KONTROL1.disableBankSwitch(knobnum), true);
}

KONTROL1.knobRelease = function knobRelease(knobnum){
Expand Down Expand Up @@ -145,7 +145,7 @@ KONTROL1.shiftPress = function shiftPress(){
var knobnum="s";
KONTROL1.modPress(knobnum);//turn mod on
engine.stopTimer(KONTROL1.mod[knobnum]["timer"]);//kill any previous timer
KONTROL1.mod[knobnum]["timer"]=engine.beginTimer(500, "KONTROL1.disableShiftSwitch('"+knobnum+"')", true);
KONTROL1.mod[knobnum]["timer"]=engine.beginTimer(500, () => KONTROL1.disableShiftSwitch(knobnum), true);
}

KONTROL1.shiftRelease = function shiftRelease(){
Expand Down Expand Up @@ -198,7 +198,7 @@ KONTROL1.modRelease = function modRelease(knobnum){
KONTROL1.doLEDs = function doLEDs() {
if (KONTROL1.debug>2){print("##function: "+KONTROL1.getFunctionName())};
engine.stopTimer(KONTROL1.flashTimer);
KONTROL1.flashTimer=engine.beginTimer(30, "KONTROL1.bankIndicators()");
KONTROL1.flashTimer=engine.beginTimer(30, KONTROL1.bankIndicators);
return;
};

Expand Down Expand Up @@ -589,7 +589,7 @@ KONTROL1.cueClear = function cueClear(cue, control, deck){//clear hotcue - OR mo
if(engine.getValue(group, "hotcue_"+cue+"_enabled")!=true){//hotcue not set - prepare to move next hotcue pressed to this button
KONTROL1.cueMoveToNum=cue;
engine.stopTimer(KONTROL1.cueMoveIndicator);
KONTROL1.cueMoveIndicator=engine.beginTimer(100, "KONTROL1.cueMoveIndicatorLEDs("+control+")");//start timer for LED indicator flasher showing the button we're moving to
KONTROL1.cueMoveIndicator=engine.beginTimer(100, () => KONTROL1.cueMoveIndicatorLEDs(control));//start timer for LED indicator flasher showing the button we're moving to
return true;
}

Expand Down Expand Up @@ -881,7 +881,7 @@ KONTROL1.loopIn = function loopIn(value, deck) {
if (value>0){//button was pressed
KONTROL1.loopinbuttonDown=true;
KONTROL1.doloopin=true;
KONTROL1.loopinbuttonTimer = engine.beginTimer(500, "KONTROL1.disableloopin()", true);
KONTROL1.loopinbuttonTimer = engine.beginTimer(500, KONTROL1.disableloopin, true);
} else {//button was released
KONTROL1.loopinbuttonDown=false;
if (KONTROL1.doloopin===true) {engine.setValue(group, "loop_in", 1);engine.setValue(group, "loop_in", 0);};
Expand All @@ -900,7 +900,7 @@ KONTROL1.loopOut = function loopOut(value, deck) {
if (value>0){//button was pressed
KONTROL1.loopoutbuttonDown=true;
KONTROL1.doloopout=true;
KONTROL1.loopoutbuttonTimer = engine.beginTimer(500, "KONTROL1.disableloopout()", true);
KONTROL1.loopoutbuttonTimer = engine.beginTimer(500, KONTROL1.disableloopout, true);
} else {//button was released
KONTROL1.loopoutbuttonDown=false;
if (KONTROL1.doloopout===true) {engine.setValue(group, "loop_out", 1);};
Expand Down Expand Up @@ -1307,7 +1307,7 @@ KONTROL1.test = function test(channel, control, value, status, group) {
};


//KONTROL1.ledTimer = engine.beginTimer(250, "KONTROL1.testflash()");
//KONTROL1.ledTimer = engine.beginTimer(250, KONTROL1.testflash);
//midi.sendShortMsg(status, ctrl, state);
//engine.stopTimer(KONTROL1.ledTimer);

Expand Down
2 changes: 1 addition & 1 deletion res/controllers/DJ-Tech-i-Mix-Reload-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ DJTechiMixReload.init = function(ID)
DJTechiMixReload.setbutton["[Channel2]"] = false;

DJTechiMixReload.allleadson();
engine.beginTimer(4000,"DJTechiMixReload.allleadsoff()",true);
engine.beginTimer(4000, DJTechiMixReload.allleadsoff ,true);
for(var deck = 1; deck <= 2; deck++){
engine.connectControl("[Channel" + deck + "]","play","DJTechiMixReload.deck" + deck + "play");
engine.connectControl("[Channel" + deck + "]","cue_default","DJTechiMixReload.deck" + deck + "cue");
Expand Down
20 changes: 10 additions & 10 deletions res/controllers/Denon-DN-SC2000.midi.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ DenonDNSC2000.newValue = function(currentVal,min,max,increment,ticksCount) {

DenonDNSC2000.flanger = function (midino, control, value, status, group) {
DenonDNSC2000.toggleBinaryValue(group,'flanger');
engine.beginTimer(100, 'DenonDNSC2000.handleFlangerLed("'+group+'")', true);
engine.beginTimer(100, ()=>DenonDNSC2000.handleFlangerLed(group), true);
}

DenonDNSC2000.changeDepth = function (midino, control, value, status, group) {
Expand Down Expand Up @@ -100,7 +100,7 @@ DenonDNSC2000.loadSelectedTrack = function (midino, control, value, status, grou
}
else {
engine.setValue(group, 'LoadSelectedTrack', 1);
engine.beginTimer(1500, 'DenonDNSC2000.handleLeds("'+group+'")', true);
engine.beginTimer(1500, ()=>DenonDNSC2000.handleLeds(group), true);
}
}

Expand Down Expand Up @@ -170,7 +170,7 @@ DenonDNSC2000.hotcue = function(cueIndex, group, value, shift) {
else
engine.setValue(group, 'hotcue_' + cueIndex + '_clear',1);
}
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
engine.beginTimer(100, ()=>DenonDNSC2000.handleLoopAndHotcuesLeds(group), true);
}

DenonDNSC2000.loopIn = function(group, value, shift) {
Expand All @@ -179,7 +179,7 @@ DenonDNSC2000.loopIn = function(group, value, shift) {
}
else
engine.setValue(group, 'loop_in', 1);
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
engine.beginTimer(100, ()=>DenonDNSC2000.handleLoopAndHotcuesLeds(group), true);
}

DenonDNSC2000.loopOut = function(group, value, shift) {
Expand All @@ -190,7 +190,7 @@ DenonDNSC2000.loopOut = function(group, value, shift) {
}
else
engine.setValue(group, 'loop_out', 1);
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
engine.beginTimer(100, ()=>DenonDNSC2000.handleLoopAndHotcuesLeds(group), true);
}

DenonDNSC2000.reloop = function(group, value, shift) {
Expand Down Expand Up @@ -221,7 +221,7 @@ DenonDNSC2000.reloop = function(group, value, shift) {
engine.setValue(group, 'reloop_exit', 1);
}
}
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
engine.beginTimer(100, ()=>DenonDNSC2000.handleLoopAndHotcuesLeds(group), true);
}

DenonDNSC2000.resizeLoop = function(midino, control, value, status, group) {
Expand Down Expand Up @@ -267,7 +267,7 @@ DenonDNSC2000.resizeLoop = function(midino, control, value, status, group) {
newLoopOutPosition = Math.max(0,newLoopOutPosition - newLoopOutPosition % 2);
engine.setValue(group, 'loop_end_position', newLoopOutPosition);
}
engine.beginTimer(100, 'DenonDNSC2000.handleLoopAndHotcuesLeds("'+group+'")', true);
engine.beginTimer(100, ()=>DenonDNSC2000.handleLoopAndHotcuesLeds(group), true);
}

DenonDNSC2000.moveLoopLeft = function(midino, control, value, status, group) {
Expand Down Expand Up @@ -311,7 +311,7 @@ DenonDNSC2000.play = function (midino, control, value, status, group) {
DenonDNSC2000.toggleBinaryValue(group,'play');
}
}
engine.beginTimer(100, 'DenonDNSC2000.handlePlayLed("'+group+'")', true);
engine.beginTimer(100, ()=>DenonDNSC2000.handlePlayLed(group), true);
}

DenonDNSC2000.cue = function (midino, control, value, status, group) {
Expand All @@ -330,14 +330,14 @@ DenonDNSC2000.cue = function (midino, control, value, status, group) {
DenonDNSC2000.keyLock = function (midino, control, value, status, group) {
if ((status & 0xF0) == 0x90) {
DenonDNSC2000.toggleBinaryValue(group,'keylock');
engine.beginTimer(100, 'DenonDNSC2000.handleKeyLockLed("'+group+'")', true);
engine.beginTimer(100, ()=>DenonDNSC2000.handleKeyLockLed(group), true);
}
}

DenonDNSC2000.beatSync = function (midino, control, value, status, group) {
if ((status & 0xF0) == 0x90) {
DenonDNSC2000.toggleBinaryValue(group,'beatsync');
engine.beginTimer(100, 'DenonDNSC2000.handleBeatSyncLed("'+group+'")', true);
engine.beginTimer(100, () => DenonDNSC2000.handleBeatSyncLed(group), true);
}
}

Expand Down
22 changes: 6 additions & 16 deletions res/controllers/Denon-MC7000-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ MC7000.init = function() {
engine.makeConnection("[Sampler"+samplerIdx+"]", "play", MC7000.VelSampLED);
}
// send Softtakeover delayed to avoid conflicts with ControllerStatusSysex
engine.beginTimer(2000, function() {
engine.beginTimer(2000, () => {
// Softtakeover for Pitch Faders only
for (let chanIdx = 1; chanIdx <= 4; chanIdx++) {
engine.softTakeover("[Channel" + chanIdx + "]", "rate", true);
Expand Down Expand Up @@ -430,9 +430,7 @@ MC7000.PadButtons = function(channel, control, value, status, group) {
engine.setValue(group, "hotcue_" + cueIdx + "_activate", false);
if (engine.getValue(group, "slip_enabled")) {
engine.setValue(group, "slip_enabled", false);
engine.beginTimer(50, function() {
engine.setValue(group, "slip_enabled", true);
}, true);
engine.beginTimer(50, () => engine.setValue(group, "slip_enabled", true), true);
}
} else if (control === 0x1C + cueIdx - 1 && value === 0x7F) {
engine.setValue(group, "hotcue_" + cueIdx + "_clear", true);
Expand Down Expand Up @@ -589,9 +587,7 @@ MC7000.PadButtons = function(channel, control, value, status, group) {
// midi.sendShortMsg(0x94 + deckIndex, 0x14 + pitchIdx - 1, MC7000.padColor.pitchoff); // switch to pitch off color
if (engine.getValue(group, "slip_enabled")) {
engine.setValue(group, "slip_enabled", false);
engine.beginTimer(50, function() {
engine.setValue(group, "slip_enabled", true);
}, true);
engine.beginTimer(50, () => engine.setValue(group, "slip_enabled", true), true);
}
} else if (isButtonPressed && isControlAddressShift) { //shifted buttons deselect hotcue for pitch
engine.setValue(group, "pitch", 0);
Expand Down Expand Up @@ -691,9 +687,7 @@ MC7000.wheelTouch = function(channel, control, value, status, group) {
if (engine.getValue(group, "slip_enabled")) {
engine.scratchDisable(deckNumber, false); // stops scratching immediately
engine.setValue(group, "slip_enabled", false);
engine.beginTimer(50, function() {
engine.setValue(group, "slip_enabled", true);
}, true);
engine.beginTimer(50, () => engine.setValue(group, "slip_enabled", true), true);
} else {
engine.scratchDisable(deckNumber); // continues scratching e.g. for backspin
}
Expand Down Expand Up @@ -909,9 +903,7 @@ MC7000.reverse = function(channel, control, value, status, group) {
engine.brake(deckNumber, false); // disable brake effect
engine.setValue(group, "play", 1);
engine.setValue(group, "slip_enabled", false);
engine.beginTimer(50, function() {
engine.setValue(group, "slip_enabled", true);
}, true);
engine.beginTimer(50, () => engine.setValue(group, "slip_enabled", true), true);
} else {
engine.softStart(deckNumber, true, MC7000.spinbackFactor[deckIndex]);
}
Expand All @@ -927,9 +919,7 @@ MC7000.censor = function(channel, control, value, status, group) {
} else {
engine.setValue(group, "reverseroll", 0);
}
engine.beginTimer(50, function() {
engine.setValue(group, "slip_enabled", true);
}, true);
engine.beginTimer(50, () => engine.setValue(group, "slip_enabled", true), true);
} else {
// reverse play while button pressed
if (value > 0) {
Expand Down
4 changes: 2 additions & 2 deletions res/controllers/EKS-Otus.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ EksOtus.init = function (id) {
if (EksOtus.LEDUpdateInterval!=undefined) {
controller.timers["led_update"] = engine.beginTimer(
EksOtus.LEDUpdateInterval,
"EksOtus.updateLEDs(true)"
() => EksOtus.updateLEDs(true)
);
}

Expand Down Expand Up @@ -670,7 +670,7 @@ EksOtus.deckSwitch = function(field) {
if (EksOtus.deckSwitchClicked==false) {
EksOtus.deckSwitchClicked=true;
controller.timers["deck_switch"] = engine.beginTimer(
250,"EksOtus.deckSwitchClickedClear()"
250, EksOtus.deckSwitchClickedClear
);
} else {
EksOtus.deckSwitchDoubleClick();
Expand Down
Loading

0 comments on commit 306bbe4

Please sign in to comment.