Part of code not working when converted to a template.
I’m working on a script that is triggered by a midi rotary knob. Here it is, simplified to it’s purest form:
const midiEventValue = event.trigger.midiBytes[2];
if (midiEventValue > 62) {
log("up")
} else if (midiEventValue < 64) {
log("down") }
if (midiEventValue > 62) {
log("up")
} else if (midiEventValue < 64) {
log("down") }
The original script is kind of complex and therefore I want to make a Template, to make it easier to manage and handle all the input data. However, the code snippet
const midiEventValue = event.trigger.midiBytes[2];
is not recognised when I convert it to a template. I can’t wrap my head around this. My guess is that when in a template, SoundFlow expects som kind of property input (?), but I’m stuck and don’t know where to go. Is there a way to make the template understand const midiEventValue = event.trigger.midiBytes[2]; ?
Thanks
- Christian Scheuer @chrscheuer2023-02-02 23:31:34.396Z
Hi Robert,
Turning your script into a template would only make sense if you wanted to create many different variations of the script, each having their own, different MIDI triggers/inputs.
It doesn't sound like that's what you're trying to achieve though. Could you elaborate on your use case?- RRobert Sörling @robertsorling
What the script is doing when triggered by midi via midi rotary knobs is moving the mouse pointer to the corresponding x&y coordinates for a parameter in a plug-in, and then simulate the mouse scroll wheel. For each parameter in each plug-in there's also variations depending on what keyboard modifier is held, and also the resolution of the scroll wheel simulation vary from plug-in to plug-in, and parameter to parameter. So yes, there will be many, many variations of the script. :) It would be very helpful to understand how I can get the code snippet "const midiEventValue = event.trigger.midiBytes[2];" to work in a template situation. I've experimented with trying to make a property with a Bytes output (not sure if I'm using the right terminology here) from within the Template's template, in order to make the script fetch the undefined property from there. No luck so far. Hope this makes any sense. :)
Chris Shaw @Chris_Shaw2023-02-03 15:28:05.353Z
As @chrscheuer stated you probably don't need a template for this.
You can useevent.keyboardState.asString
to determine which keys are being held when the script is triggered (in this case with your MIDI controller)
Try assigning this script to a CC and hold down the modifier keys while turning it:const modifiersHeld = event.keyboardState.asString log (modifiersHeld)
With this info you can just use
if
,switch
, or object lookup statements to decide which pieces of code to run or change the resolution of the scroll wheel etcChris Shaw @Chris_Shaw2023-02-03 15:30:09.955Z2023-02-03 17:30:27.316Z
.asString
will return the modifier key combinations in this order: ctrl+alt+shift+cmd.- RRobert Sörling @robertsorling
Ok, thanks and great info about the modifier keys!
However, I still really think it would help me turning it into a template. For each parameter i use a unique midi knob (or rather a unique midi channel) , meaning that for example EQ3 7-Band gives me seven unique scripts for the seven frequency bands, and 7x3 parameters to log. So, when I start adding my favorite plug-ins to the list I get alot of unique scripts. Of course I can cope with that, but at least in my head it would be faster and more convenient to put the parameters for each plug-in in its own template.Christian Scheuer @chrscheuer2023-02-03 17:27:01.662Z
Thanks - yea that totally makes sense. I think the missing midiBytes can be considered a bug. I'll log a tracking item for it, we should be able to fix it fairly easily.
- SIn reply torobertsorling⬆:SoundFlow Bot @soundflowbot
This issue is now tracked internally by SoundFlow as SF-754
- SIn reply torobertsorling⬆:SoundFlow Bot @soundflowbot
Linked issue SF-754 updated: This should be fixed in the upcoming 5.3.1 build (pending beta testing completes successfully).
- SIn reply torobertsorling⬆:SoundFlow Bot @soundflowbot
The linked internal issue SF-754 has been marked as Done