How to check if a track exists?
I'm trying to make a simple script that solos 4 tracks, if one of those tracks is not present in the session, it should just solo the ones that are there. I thought with the onError: "Continue" would be enough, but seems like if "track 3" is not present in the session, itll still throw an error and stop there, failing to solo "track 4". Any ideas?
sf.ui.proTools.mainWindow.invalidate();
sf.ui.proTools.trackGetByName({ name: "track 1", makeVisible: true }).track.trackSetSolo({
onError: "Continue",
});
sf.ui.proTools.trackGetByName({ name: "track 2", makeVisible: true }).track.trackSetSolo({
onError: "Continue",
});
sf.ui.proTools.trackGetByName({ name: "track 3", makeVisible: true }).track.trackSetSolo({
onError: "Continue",
});
sf.ui.proTools.trackGetByName({ name: "track 4", makeVisible: true }).track.trackSetSolo({
onError: "Continue",
});
And this is the error:
02.08.2023 13:33:11.48 <info> [Backend]: JavaScript error with InnerException: null
!! Command Error: Solo D&B [user:ck8ko0s09000f2210f6n002uz:clksnvsg80000ap10sxg9iqhs]:
TypeError: Cannot read property 'trackSetSolo' of null
(Solo D&B line 11)
- SSoundFlow Bot @soundflowbot
Thanks for contacting SoundFlow support.
Please note, that the best way to get help with a script, macro or other content installed from the Store or content that you've made yourself, is to select the script/macro, then click the red Need help button, and then click "Get help with this script or macro".
By using this method, we will get access to more information and so should be able to help you quicker.
You can read more about how this works here: bit.ly/sfscripthelpIf you're seeing an error that isn't related to scripts or macros, and you think this is a bug in SoundFlow, please file a Help/Issue bug report.
You can see how to do this by going to bit.ly/sfhelpissue - In reply toNacho_Sotelo⬆:Raphael Sepulveda @raphaelsepulveda2023-08-02 19:20:22.246Z
@Nacho_Sotelo, here you go!
/** @param {{ trackNames: string[] }} arg */ function soloTracks({ trackNames }) { sf.ui.proTools.mainWindow.invalidate(); trackNames.forEach(name => { const track = sf.ui.proTools.trackGetByName({ name, makeVisible: true }).track; if (track) track.trackSetSolo(); }); } soloTracks({ trackNames: ["track 1", "track 2", "track 3", "track 4"] });
- NNacho @Nacho_Sotelo
Thank you Raphael!
Any idea why the onError: "Continue" does not work?
Your script works perfectly but takes just a bit more time to complete after triggering it.
Raphael Sepulveda @raphaelsepulveda2023-08-03 00:19:35.942Z
When the
trackGetByName
method doesn't find a track, it returnsnull
instead of throwing an error. SoonError
doesn't do anything since technically no error has occurred. We need to handle that case ourselves to get the desired result. The way I scripted it above is my preferred way of doing that.From a quick test, I see that both approaches take the same amount of time if all the tracks are present, but if one or more are missing, it suddenly takes a bit longer—and that's again because of the
trackGetByName
method, which seems to retry a few times before returningnull
.- NNacho @Nacho_Sotelo
Understood, thanks a lot!