No internet connection
  1. Home
  2. How to

Use "Version Number" in Project Title as "Mix Number"

By Nathan Salefski @nathansalefski
    2023-07-15 05:11:13.349Z

    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

    Solved in post #5, click to view
    • 9 replies
    1. Nathan Salefski @nathansalefski
        2023-07-15 21:21:46.205Z

        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}`,
        });
        
        1. Nathan Salefski @nathansalefski
            2023-07-15 23:56:55.449Z

            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
              2023-07-16 18:35:04.625Z2023-07-17 16:31:25.521Z
              1. 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.

                Reply1 LikeSolution
                1. Nathan Salefski @nathansalefski
                    2023-07-18 00:30:30.671Z

                    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!

                    1. 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!

                      1. Nathan Salefski @nathansalefski
                          2023-07-18 00:53:24.187Z

                          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

                          1. Kitch Membery @Kitch2023-07-18 01:37:59.042Z

                            Yep saw that will do my best to take a look later tonight

                            1. Nathan Salefski @nathansalefski
                                2023-07-18 01:39:40.056Z

                                Take your time man. It's a Monday, no one wants to do extra work. Whenever you have time