Putting this Multi-Click function on StreamDeck Knob click
Hey @raphaelsepulveda Some sort of interaction with Stream Deck Knob click breaks this script. It will work on the streamdeck+ but not on the knob press aspect of it... any idea if it could be salvage?
/** Counts the amount of times this function is called during a fixed amount of time
* and passes that value to a callback from which different actions can take place.
* @param {object} args
* @param {string} args.name - Name for this instance.
* @param {number} args.waitTime - Amount of time to wait in milliseconds.
* @param {function} args.action - Callback to execute when the waitTime is over. Counter value will be passed as an argument.
*/
function actionCounter({ name, waitTime, action }) {
let actionCounter;
if (!globalState.actionCounter) globalState.actionCounter = {};
actionCounter = globalState.actionCounter;
if (!actionCounter[name]) {
actionCounter[name] = { i: 1 };
} else {
actionCounter[name].i++
return;
}
sf.engine.runInBackground(() => {
sf.wait({ intervalMs: waitTime, executionMode: "Background" });
try {
action(actionCounter[name].i);
} finally {
delete globalState.actionCounter
}
});
}
actionCounter({
name: 'actionCounterInstance',
waitTime: 500
action: i => {
switch (i) {
case 1:
log("1")
break;
case 2:
log("2")
break;
case 3:
log("3")
break;
}
}
});
- Raphael Sepulveda @raphaelsepulveda2023-09-20 03:17:30.175Z
@Owen_Granich_Young, unfortunately, I have yet to snatch a Streamdeck+ and I'm not familiar with the inner workings of its integration with SoundFlow, so I'm going to ping @chrscheuer to see if he can provide some insight.
I have a feeling it may have to do with the way background processes are handled when using a knob click.Christian Scheuer @chrscheuer2023-09-20 19:52:55.294Z
I would have to see some log files and get some more info about how exactly it breaks.
Please use the https://soundflow.org/docs/help#script-help workflow if you need help with it, so we have these details, potential error messages etc.
Chad Wahlbrink @Chad2023-09-20 21:22:08.002Z2023-09-20 21:46:24.167Z
@Owen_Granich_Young
Hey, I troubleshooted this idea a bit. This script will not run as the "click action" of a Generic Knob Command. When I put this script on a knob that is not using a Generic Knob Command, the script runs as expected.
I believe this is because Generic Knob Commands can't access the "global state" like a normal script.
@chrscheuer - can you confirm that the global state isn't accessible this way?Christian Scheuer @chrscheuer2023-09-20 21:59:29.071Z
I can't tell for sure, as I said, I would need to look at log files and example code. Theoretically, they should have access to everything a script could do normally.