Every time I make an adjustment to a mix I save a version (i.e. v2 Artist_SongTitle). I currently have a script that removes the 'v#' from the beginning of the file name, prompts for a version number and renames the bounce to that resulting name. I'm looking for a way to use the 'v#' as the version number. Example if the project title is Artist_SongTitle the script will know there isn't a 'v#' and the bounce will be titled Artist_SongTitle_NS_Mix_1. If the project title is v2 Artist_SongTitle, the bounce will be titled Artist_SongTitle_NS_Mix_2.
sf.ui.proTools.appActivateMainWindow();
//Get session name from session path
const sessionPath = sf.ui.proTools.mainWindow.sessionPath;
let sessionName = sessionPath.split("/").slice(-1)[0].split(".ptx")[0]
//Check if session name starts with a v## using a reglar expression to replace "V##" with an epty string
const regex = /^[vV]\d{1,2}/
const match = sessionName.match(regex);
if (match) {
//.trim is used to remove any empty spaces in front and end of name
sessionName = sessionName.replace(regex, "").trim();
};
// Get version # via displayDialog so user has the option to cancel
let version = sf.interaction.displayDialog({
prompt: `Version`,
defaultAnswer: "",
buttons: ["Cancel", "OK"],
defaultButton: "OK",
}).text;
//Open Bounce window
sf.ui.proTools.menuClick({
menuPath: ["File", "Bounce Mix..."],
});
// Make reference to Bounce window
const bounceWindow = sf.ui.proTools.windows.whoseTitle.is('Bounce Mix').first
//Wait for Bounce window
bounceWindow.elementWaitFor()
//Enter session name
bounceWindow.textFields.whoseTitle.is('').first.elementSetTextFieldWithAreaValue({
value: `${sessionName}_NS_Mix_${version}`,
});
Thanks as always!
Nathan
- Nathan Salefski @nathansalefski
I got to here: It seems to be working ok with any session beginning with 'v#' but I can't quite figure out how to make the original session's version number 1.
sf.ui.proTools.appActivate(); sf.ui.proTools.mainWindow.invalidate(); //Get session name from session path const sessionPath = sf.ui.proTools.mainWindow.sessionPath; let sessionName = sessionPath.split("/").slice(-1)[0].split(".ptx")[0] //Check if session name starts with a v## using a reglar expression to replace "V##" with an epty string const regex = /^([vV])(\d{1,2})/ const match = sessionName.match(regex); let version = match[2]; if (match) { //Remove Prefix of Session sessionName = sessionName.replace(regex, "").trim(); } if (!match) { //Make Mix Version 1 version = version.replace(match[2], "1"); }; //Open Bounce window sf.ui.proTools.menuClick({ menuPath: ["File", "Bounce Mix..."], }); // Make reference to Bounce window const bounceWindow = sf.ui.proTools.windows.whoseTitle.is('Bounce Mix').first //Wait for Bounce window bounceWindow.elementWaitFor() //Enter session name bounceWindow.textFields.whoseTitle.is('').first.elementSetTextFieldWithAreaValue({ value: `${sessionName}_NS_Mix_${version}`, });
Nathan Salefski @nathansalefski
I think I got it but would love some confirmation, had it worded a bit backwards:
sf.ui.proTools.appActivate(); sf.ui.proTools.mainWindow.invalidate(); //Get session name from session path const sessionPath = sf.ui.proTools.mainWindow.sessionPath; let sessionName = sessionPath.split("/").slice(-1)[0].split(".ptx")[0] //Check if session name starts with a v## using a reglar expression to replace "V##" with an epty string const regex = /^([v])(\d{1,2})/ const match = sessionName.match(regex); let version = "1"; if (match) { //Remove Prefix of Session version = version.replace("1", match[2]); sessionName = sessionName.replace(regex, "").trim(); }; //Open Bounce window sf.ui.proTools.menuClick({ menuPath: ["File", "Bounce Mix..."], }); // Make reference to Bounce window const bounceWindow = sf.ui.proTools.windows.whoseTitle.is('Bounce Mix').first //Wait for Bounce window bounceWindow.elementWaitFor() //Enter session name bounceWindow.textFields.whoseTitle.is('').first.elementSetTextFieldWithAreaValue({ value: `${sessionName}_NS_Mix_${version}`, });
- In reply tonathansalefski⬆:Nathan Salefski @nathansalefski
- In reply tonathansalefski⬆:Kitch Membery @Kitch2023-07-18 00:23:26.586Z
Hi Nathan,
This should do the trick...
function createBounceName(sessionName) { // Regular expression breakdown // ^ - Asserts the start of the string // v - Matches the character 'v' literally // (\d+) - Captures one or more digits as the version number and stores it in match group 1 // [\s_] - Matches a whitespace character or "_" // (.+) - Captures one or more characters (the name) and stores it in match group 2 // $ - Asserts the end of the string // i - Makes the regex case-insensitive let regex = /^v(\d+)[\s_](.+)$/i; let match = sessionName.match(regex); let versionNumber let songtitle if (match) { versionNumber = match[1]; songtitle = match[2]; } else { versionNumber = 1; songtitle = sessionName; } let bounceName = `${songtitle}_NS_Mix_${versionNumber}`; return bounceName } function bounceMix({ name }) { //Open Bounce window sf.ui.proTools.menuClick({ menuPath: ["File", "Bounce Mix..."], }); // Make reference to Bounce window const bounceWindow = sf.ui.proTools.windows.whoseTitle.is('Bounce Mix').first; //Wait for Bounce window bounceWindow.elementWaitFor(); //Enter session name bounceWindow.textFields.first.elementSetTextFieldWithAreaValue({ value: name, }); } function main() { sf.ui.proTools.appActivate(); sf.ui.proTools.mainWindow.invalidate(); //Get session name from session path const sessionPath = sf.ui.proTools.mainWindow.sessionPath; let sessionName = sessionPath.split("/").slice(-1)[0].split(".ptx")[0] let bounceName = createBounceName(sessionName); bounceMix({ name: bounceName }); } main();
It needs some testing but should work. :-)
Let me know how it goes for you.Nathan Salefski @nathansalefski
Seems to be working great although my third iteration was also working. I'm just learning about functions and the whole regular expression thing is pretty confusing still so thank you!
Kitch Membery @Kitch2023-07-18 00:45:32.224Z
Ahh I see...
Looking at your script again I can now see that it would have worked as you coded it.
The code was a little unclear, however, as you were changing the value of the
sessionName
variable to be the song title. And by doing this, the "sessionName" variable name is no longer representing the session name.Let me know if you need further clarification of what I mean by that. :-)
Maybe we can take a look at this sometime in the Wednesday SoundFlow Hangout. https://soundflow.org/hangout
Rock on!
Nathan Salefski @nathansalefski
Thanks man, I'll be there. Have another issue I posted about too if you have time! Something you should be familiar with and hopefully a quick fix; the fastDrag function Moving Clips to "Dump" Tracks while Tracking #post-2
Kitch Membery @Kitch2023-07-18 01:37:59.042Z
Yep saw that will do my best to take a look later tonight
Nathan Salefski @nathansalefski
Take your time man. It's a Monday, no one wants to do extra work. Whenever you have time