Hi, I am wondering if there is a general toggle action I can use to switch between commands. You helped me create a script to toggle commands on this thread:
https://forum.soundflow.org/-443/how-to-toggle-between-smart-tool-trim-tce-and-smart-tool-trim-standard
but I am wondering if there is an easy way I can build them in the future. I want to toggle between these two scrips for example: "Set Nudge to Timecode 1 second" and "Set Nudge to Timecode 1 Frame"
- Christian Scheuer @chrscheuer2019-12-28 20:19:12.307Z
Hi Jon.
For others reading this, this also refers to the first few paragraphs of my comment here:
https://forum.soundflow.org/-1435#post-2You can do a generic toggle action by using a global state variable. That is a variable that will keep its value when the script is called again.
You would do something like this (pseudo-code):
- Set the state variable to the opposite of what it was (if it was true, set to false, if it was false, set to true).
- Check if the state variable is true - then do task A
- or else (if it was false) - do task B.
In Javascript, that looks like this:
//This reverses the value of globalState.myVariable globalState.myVariable = !globalState.myVariable; if (globalState.myVariable) { //Do task A } else { //Do task B }
You would then insert the two actions you want to toggle between where it says "Do task A" / "Do task B" (at a new line under those comments).
If you use this in other scripts, make sure to use something other than "myVariable"
Christian Scheuer @chrscheuer2019-12-28 20:22:30.753Z
As mentioned in my previous comment here the downside of using this approach is that the script doesn't know what's going on in Pro Tools.
So the script will toggle back and forth between executing command A and command B regardless of the state inside Pro Tools.
So where this approach - a general toggle - enables you to generally make a toggle action, it is recommended to use logic that reads the actual state to determine which action to take, whenever possible (as we did in the post you were referring to).- JJon Shamieh @Jon_Shamieh
Gotcha, thank you. Although I do understand in theory what you are saying, it's a little over my head at the moment as far as how to implement via a script - for example, I am not sure why this doesn't work:
//This reverses the value of globalState.myVariable
globalState.myVariable = !globalState.myVariable;if (globalState.myVariable) {
//sf.ui.proTools.nudgeSet({
value: "00:00:01:00.00",
});
} else {
//sf.ui.proTools.nudgeSet({
value: "00:00:00:01.00",
});
}But it's OK for now, I think I'll be able to get it eventually, there's just a learning curve I am battling at the moment :)
Christian Scheuer @chrscheuer2019-12-28 21:50:49.001Z
Just remove the double slashes //
They mean "ignore everything after the slashes on this line"- JJon Shamieh @Jon_Shamieh
that worked!
- OOwen Granich-Young @Owen_Granich_Young
Needed this today... this was one of my forum stops to find it, figured I'd put the 'check status version' here for anybody else who went looking with these key terms. Thanks to @samuel_henriques from another posting (How to change specific Pro Tools nudge values (in msec)) for most of this code.
sf.ui.proTools.appActivateMainWindow(); const nudgeBtn = sf.ui.proTools.mainWindow.gridNudgeCluster.nudgeControls const nudgeValue = nudgeBtn.nudgeValue.value.invalidate().value if (nudgeValue === "00:00:00:01.00") { sf.ui.proTools.nudgeSet({ value: '00:00:01:00.00', }); } else { sf.ui.proTools.nudgeSet({ value: '00:00:00:01.00', }); }