No internet connection
  1. Home
  2. How to

Find a word or letters in a track name and replace intelligently.

By Joe Kearns @Joe_Kearns
    2021-11-24 13:36:05.156Z

    Hey!

    I use a lettering system on playlists to remember processes I have done in the order I do them. ie:

    [a_melo] for melodyne
    [b_voca] for vocalign
    [c_denoise] for rx denoise
    etc

    so basically the letter goes up with each process. I have a few soundflow macros that help with vocalign etc but Id love to have a way that before the macro renames the playlist it can sort of read to see what letter is there and then assign the next one if that makes sense? My track labelling works like this:

    trackname tk.00

    and then when a process is added it goes between the trackname and the take number like so:

    trackname [a_melo] tk.00

    this keeps all the takes in order and remembers the processes in order for that particular take or comp.

    So what i need ideally is a script that can look at a track name to see if "[a_" or "[b_" or "[c_" etc is present in the whole of the track name and add or replace it with the next letter.

    Thanks so much in advance for any ideas and help!

    Joe

    Solved in post #5, click to view
    • 8 replies
    1. You could use something like this:

      
      const processNames = {
          'a': 'melo',
          'b': 'voca',
          'c': 'denoise',
      };
      
      sf.ui.proTools.selectedTrack.trackRename({
          renameFunction: oldName => {
      
              var match = oldName.match(/^(.*)\[([a-z]_[^\]]+)\](.*)$/);
              if (!match) {
                  //throw `No [a_xxx] tag present`;
                  var tkSuffixMatch = oldName.match(/^(.*)( tk\.\d+)/);
                  if (tkSuffixMatch) {
                      var tkPrefix = tkSuffixMatch[1], tkSuffix = tkSuffixMatch[2];
                      return `${tkPrefix} [${Object.keys(processNames)[0]}_${processNames[Object.keys(processNames)[0]]}]${tkSuffix}`;
                  }
                  return `${oldName} [${Object.keys(processNames)[0]}_${processNames[Object.keys(processNames)[0]]}]`;
              }
      
              var prefix = match[1];
              var processName = match[2]; //For example 'a_melo'
              var suffix = match[3];
      
              var processPrefix = processName.split('_')[0]; //gets 'a' from a_melo
              var processPrefixIndex = Object.keys(processNames).indexOf(processPrefix);
              var newProcessPrefix = Object.keys(processNames)[processPrefixIndex + 1];
              if (!newProcessPrefix) throw `No more processes`;
              var newProcessName = newProcessPrefix + '_' + processNames[newProcessPrefix];
      
              return `${prefix}[${newProcessName}]${suffix}`;
      
          },
      });
      
      1. J
        In reply toJoe_Kearns:
        Joe Kearns @Joe_Kearns
          2021-11-24 21:30:37.528Z

          thanks Christian, this is great and got it in place now. However it's not exactly what I had in mind.....the letter ([a_] for example) is not linked to a particular process as every job can be different and require different processes. So the main thing I need it to read/change is the letter and then the process will be speficic to the rest of the script for that job, ie: if its a vocalign helper script then it will add the "voca" or if its a melodyne print helper it will add the "melo".

          does that make sense?

          thanks so so much! I really appreciate this!

          1. Try this instead:

            
            function addProcessName(oldName, processName) {
                var match = oldName.match(/^(.*)\[([a-z]_[^\]]+)\](.*)$/);
                if (!match) {
                    //throw `No [a_xxx] tag present`;
                    var tkSuffixMatch = oldName.match(/^(.*)( tk\.\d+)/);
                    if (tkSuffixMatch) {
                        var tkPrefix = tkSuffixMatch[1], tkSuffix = tkSuffixMatch[2];
                        return `${tkPrefix} [a_${processName}]${tkSuffix}`;
                    }
                    return `${oldName} [a_${processName}]`;
                }
            
                var prefix = match[1];
                var oldProcessName = match[2]; //For example 'a_melo'
                var suffix = match[3];
            
                var oldProcessPrefix = oldProcessName.split('_')[0]; //gets 'a' from a_melo
                var newProcessPrefix = String.fromCharCode(oldProcessPrefix.charCodeAt(0) + 1);
            
                return `${prefix}[${newProcessPrefix}_${processName}]${suffix}`;
            }
            
            function addProcessNameToTrack(processName) {
                sf.ui.proTools.selectedTrack.trackRename({
                    renameFunction: oldName => addProcessName(oldName, processName),
                });
            }
            
            addProcessNameToTrack('melodyne');
            
            ReplySolution
            1. JJoe Kearns @Joe_Kearns
                2021-11-24 22:15:51.870Z

                this works PERFECT!

                thanks so much Christian you are a legend!

                1. Yay :) Sounds like you have a great workflow, can't wait to see what you'll be building with SF :)

            2. J
              In reply toJoe_Kearns:
              Joe Kearns @Joe_Kearns
                2021-11-24 21:58:46.509Z2021-11-24 22:10:17.690Z

                ignore this post

                1. Please check this tutorial for how to quote code in the SoundFlow forum, so that it displays in a readable format:

                2. J
                  In reply toJoe_Kearns:
                  Joe Kearns @Joe_Kearns
                    2021-11-24 22:09:41.246Z

                    apologies!

                    sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is('Playlist selector').first.popupMenuSelect({
                        menuPath: ["Duplicate..."],
                    });
                    
                    sf.keyboard.press({
                        keys: "enter",
                        fast: true,
                    });
                    
                    const processNames = {
                        'a': 'melo',
                        'b': 'voca',
                        'c': 'denoise',
                    };
                    
                    sf.keyboard.press({
                        keys: "right, alt+backspace, alt+backspace, backspace",
                        fast: true,
                    });
                    
                    
                    sf.ui.proTools.selectedTrack.trackRename({
                        renameFunction: oldName => {
                    
                            var match = oldName.match(/^(.*)\[([a-z]_[^\]]+)\](.*)$/);
                            if (!match) {
                                //throw `No [a_xxx] tag present`;
                                return `${oldName} [${Object.keys(processNames)[0]}_${processNames[Object.keys(processNames)[0]]}]`;
                            }
                    
                            var prefix = match[1];
                            var processName = match[2]; //For example 'a_melo'
                            var suffix = match[3];
                    
                            var processPrefix = processName.split('_')[0]; //gets 'a' from a_melo
                            var processPrefixIndex = Object.keys(processNames).indexOf(processPrefix);
                            var newProcessPrefix = Object.keys(processNames)[processPrefixIndex + 1];
                            if (!newProcessPrefix) throw `No more processes`;
                            var newProcessName = newProcessPrefix + '_' + processNames[newProcessPrefix];
                    
                            return `${prefix}[${newProcessName}]${suffix}`;
                    
                        },
                    });
                    
                    sf.ui.proTools.selectedTrack.trackOpenRenameDialog({
                        renameAllSelectedTracks: true,
                    });
                    
                    sf.keyboard.press({
                        keys: "right, space",
                        fast: true,
                    });
                    
                    sf.keyboard.type({
                        text: "tk.00",
                    });
                    
                    
                    sf.keyboard.press({
                        keys: "enter",
                        fast: true,
                    });
                    
                    sf.ui.proTools.windows.whoseTitle.is('Audio Suite: VocAlign Ultra').first.mouseClickElement({
                        relativePosition: {"x":64,"y":377},
                    });