Global State Issue (I think)
I have a script I wrote ages ago that stopped working a few months back with an updated of PT or Soundflow, I don't remember. But trying to troubleshoot it now and struggling. I read that there was a change in how info is recovered from Global state, and I've tried to fix this accordingly and no joy. But I also can't tell what exactly it is failing on as it isn't giving me an error, it just stops halfway through and doesn't export.
The idea of the script is a have clip groups on a channel named "Export", then a load of output busses after that in my project. So I select all the buses I want to export, AND the Export channel strip, then Soundflow takes the name from the Clip Group on the Export channel, copies it and uses it for the song title. It then deselects the Export channel strip and just exports the others. It iterates over all the clip groups so I can export a big session quickly.
Any help fixing this is much appreciated!
sf.ui.proTools.appActivate();
//Ensure Link Timeline and Edit Selection is ON
var TimelineEditwasLinked = sf.ui.proTools.getMenuItem('Options', 'Link Timeline and Edit Selection').isMenuChecked;
if (!TimelineEditwasLinked) {
sf.ui.proTools.menuClick({
menuPath: ["Options", "Link Timeline and Edit Selection"],
});
}
//Ensure Link Track and Edit Selection is ON
var TrackEditwasLinked = sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').isMenuChecked;
if (!TrackEditwasLinked) {
sf.ui.proTools.menuClick({
menuPath: ["Options", "Link Track and Edit Selection"],
});
}
//Clear Clip Search//
sf.keyboard.press({
keys: "cmd+shift+d",
});
// Remove "Export" Track from the Selection
sf.ui.proTools.trackSelectByName({
names: sf.ui.proTools.selectedTrackNames.filter(n => n.toLowerCase().indexOf('Export'.toLowerCase()) < 0),
deselectOthers: true,
});
/// Get Selected track names to variable
globalState.selectedTracks = Array.from(sf.ui.proTools.selectedTrackNames);
//Get the selection and store it in globalState variable 'rememberedSelection'
globalState.rememberedSelection = sf.ui.proTools.selectionGet();
//Select track "EXPORT"
sf.ui.proTools.mainWindow.invalidate();
sf.ui.proTools.trackGetByName({ name: "Export", makeVisible: true }).track.trackSelect();
function PrintBuses() {
sf.ui.proTools.appActivateMainWindow();
sf.ui.proTools.menuClick({menuPath: ["Clip", "Rename..."],});
sf.keyboard.press({keys: "cmd+c"});
sf.ui.proTools.windows.whoseTitle.is("Name").first.buttons.whoseTitle.is("OK").first.elementClick();
sf.ui.proTools.trackSelectByName({ names: globalState.selectedTracks })
sf.ui.proTools.menuClick({menuPath: ["Track", "Bounce..."],});
sf.ui.proTools.windows.whoseTitle.is("Track Bounce").first.elementWaitFor();
sf.keyboard.press({keys: "cmd+v",});
sf.ui.proTools.windows.whoseTitle.is("Track Bounce").first.buttons.whoseTitle.is("Bounce").first.elementClick();
sf.wait({ intervalMs: 1000 });
sf.keyboard.press({keys: "return",});
sf.wait({ intervalMs: 100 });
sf.ui.proTools.waitForNoModals();
sf.ui.proTools.appActivate();
// Recall track by name using variable selectedTracks
sf.ui.proTools.trackSelectByName({ names: globalState.selectedTracks })
//Select track "EXPORT"
sf.ui.proTools.mainWindow.invalidate();
sf.ui.proTools.trackGetByName({ name: "Export", makeVisible: true }).track.trackSelect();
}
sf.ui.proTools.clipDoForEachSelectedClip({
action: PrintBuses,
onError: "Continue"
});
// Recall track by name using variable selectedTracks
sf.ui.proTools.trackSelectByName({ names: globalState.selectedTracks })
//Recall selection from globalState variable 'rememberedSelection'
sf.ui.proTools.selectionSet({
selectionStart: globalState.rememberedSelection.selectionStart,
selectionLength: globalState.rememberedSelection.selectionLength,
});
//Restore Link Timeline and Edit selection
if (!TimelineEditwasLinked) {
sf.ui.proTools.menuClick({
menuPath: ["Options", "Link Timeline and Edit Selection"],
});
}
//Restore Link Track and Edit selection
if (!TrackEditwasLinked) {
sf.ui.proTools.menuClick({
menuPath: ["Options", "Link Track and Edit Selection"],
});
}
- Christian Scheuer @chrscheuer2024-08-06 11:16:43.324Z
Hi Pete,
I believe this could be the culprit:
globalState.rememberedSelection = sf.ui.proTools.selectionGet();
Try instead:
globalState.rememberedSelection = { ...sf.ui.proTools.selectionGet() }; //And then log it to see what you get: log(globalState.rememberedSelection);
Christian Scheuer @chrscheuer2024-08-06 11:17:47.709Z
Please note that since your script reads this later - you shouldn't need to use globalState at all (globalState is for running another script again later and reading out the info, but since you're still in the same script there's no need to save it into globalState).
You could just do:
var rememberedSelection = sf.ui.proTools.selectionGet();
And then later:
//Recall selection from variable 'rememberedSelection' sf.ui.proTools.selectionSet({ selectionStart: rememberedSelection.selectionStart, selectionLength: rememberedSelection.selectionLength, });
- PPete Watson @Pete_Watson
Thanks Christian - neither of these fixed it (they also didn't make it worse!) It still stops at the point I think it's trying to open the Track menu item "bounce..." I tried replacing that menu call with the keyboard shortcut and that also didn't work. Maybe that's not what is tripping it up but I see it opens the rename, copies the text, closes the rename, selects the correct tracks, then it just kind of fails with no error
Thanks
Christian Scheuer @chrscheuer2024-08-06 11:30:24.538Z
Hm, I don't know why it would stop half-way with no error. You could try using the Script Help feature to send us the logs if you'd like us to investigate:
- PPete Watson @Pete_Watson
Thanks, Ive submitted that (without the edits you suggested above), thanks
- In reply tochrscheuer⬆:PPete Watson @Pete_Watson
Hi Christian - i submitted the issue as requested but not heard any feedback yet on this one? Thanks
Christian Scheuer @chrscheuer2024-08-23 09:04:28.503Z
Thanks, Pete - I just CC'ed a member of our team who can hopefully help troubleshoot.
- PPete Watson @Pete_Watson
Thanks - I think what is catching me out is that it used to work. So as far as all my understanding goes the code was correct, it's just something in Protools or SF has changed behaviour I believe, thanks and hope to get to the bottom of it!