No internet connection
  1. Home
  2. How to

Duplicate tracks without any media - record disable/enable

By Miro Wolf @Miro_Wolf
    2021-11-04 09:20:37.678Z

    Hi There

    I would like to have this (Duplicate tracks without any media) function combined with record disable/enable the tracks.

    For example: recording on a track (record enabled), duplicate track to do an overdub (with the renaming funktion of Duplicate tracks without any media), disable record on original track an enable record on the duplicated track.

    Would love to get some help on this one!

    Cheers

    • 15 replies

    There are 15 replies. Estimated reading time: 17 minutes

    1. Hey Miro,

      Here you go!

      sf.ui.proTools.appActivateMainWindow();
      
      if (sf.ui.proTools.selectedTrack.buttons.whoseTitle.is("Track Record Enable").first.value.value === "on state") {
          sf.ui.proTools.selectedTrack.buttons.whoseTitle.is("Track Record Enable").first.elementClick();
      }
      
      sf.ui.proTools.trackDuplicateSelected({
          duplicateActivePlaylist: false,
          duplicateAlternatePlaylists: false,
          duplicateAutomation: false,
          duplicateGroupAssignments: true,
          duplicateInserts: false,
          duplicateSends: false,
          insertAfterLastSelectedTrack: true,
          numberOfDuplicates: 1
      });
      
      sf.ui.proTools.selectedTrack.trackRename({
          renameFunction: function (name) {
              var grps = name.match(/^([^\d]*)(\d+).dup.*/);
              var baseName = grps[1];
              var num = Number(grps[2]);
              return baseName + ((num + 1) + '');
          }
      });
      
      sf.ui.proTools.selectedTrack.buttons.whoseTitle.is("Track Record Enable").first.elementClick();
      
      1. FFukurou Toshima @Fukurou_Toshima
          2021-11-08 13:29:14.016Z

          Hi Raphael,

          I am new to SF and your scripts are tremendously helpful.

          When duplicating track, I'd like to add the letter "+" to selected track name instead of sequential numbers as everyone wants. (of course without "dup")
          Could you tell me some advice to duplicate track in a way like this thread but adding the letter that I want (such as "+") instead of numbers?
          Adding to it, I would like to know the way soundflow dialog ask me what letter I add to original track name before duplicating...

          I will mainly use this macro when tracking vocals and duplicating for its double/triple track or chorus lines.

          I’m looking forward to hearing from you.

          Best

          1. Hello @Fukurou_Toshima , welcome to SoundFlow!

            Yeah, absolutely! Here you go:

            function main() {
                const prefix = prompt('Please enter a prefix', '+');
                if (!prefix) return;
            
                sf.ui.proTools.appActivateMainWindow();
            
                sf.ui.proTools.trackDuplicateSelected({
                    duplicateActivePlaylist: false,
                    duplicateAlternatePlaylists: false,
                    duplicateAutomation: false,
                    duplicateGroupAssignments: true,
                    duplicateInserts: false,
                    duplicateSends: false,
                    insertAfterLastSelectedTrack: true,
                    numberOfDuplicates: 1
                });
            
                // Renames track by adding a prefix and removing the .dup suffix
                sf.ui.proTools.selectedTrack.trackRename({
                    renameFunction: function (name) {
                        const baseName = name.match(/^(.*)\.dup.*/)[1];
                        return prefix + baseName;
                    }
                });
            }
            
            main();
            

            This script will first ask you what the prefix should be. For convenience, I've made it so that the dialog box will be prefilled with a '+'.

            If you'd like to change it to a fixed prefix—meaning no prompt will come up—you can simply change this:

            const prefix = prompt('Please enter a prefix', '+');
                if (!prefix) return;
            

            ... to this:

            const prefix = '+';
            

            By the way, I assumed you only wanted the track duplicated and renamed, so I'm leaving the part that Miro requested which disables/enables its record state. Let me know if you want that in and I'll edit the script for ya!

            1. FFukurou Toshima @Fukurou_Toshima
                2021-11-09 02:19:12.506Z2021-11-09 03:10:05.064Z

                Thank you so much, Raphael!
                My work flow is also going to be nice with that scripts!

                But I’m sorry I didn’t explain it enough...
                This time I want to add “+” as SUFFIX.
                And the only new track made should be record-enabled with the original track disabled.

                For example,

                Chorus A
                Chorus A+
                Chorus A++
                ..

                I made “Chorus A” track manually and have recorded it.
                [And now I want to record its double and I should make the track named “Chorus A+“ and make it record enabled and the track “Chorus A” must be record disabled.]

                I’d like to do [ ] with one macro.
                *When I use this macro, sometimes the original track (“Chorus A” in the example above) is record enable and sometimes not.

                I use “+” the most frequently so I want the macro which automatically add “+”.

                And I want other one which SF prompt ask me what I add as suffix.
                I will use this macro to add letters such as “hi”, “mid”, “lo”, “L”, “R” or something.

                Moreover, It’s so cool if I could choose what I’m gonna add as suffix by clicking from the list I register beforehand.

                I really appreciate your support!

                1. That's okay! Now I know what you're looking for!

                  /** Prompt user for a suffix from a predefined list. 
                   * @param {string[]} suffixOptions
                   * */
                  function promptForSuffix(suffixOptions) {
                      return sf.interaction.popupSearch({
                          title: "Please select a suffix",
                          items: suffixOptions.map(suffix => ({ name: suffix })),
                          columns: [{ name: 'Suffix', key: 'name', width: 10, }],
                      }).item.name
                  }
                  
                  /** @param { "Enable" | "Disable" } state */
                  function setSelectedTrackRecord(state) {
                      const recordBtn = sf.ui.proTools.selectedTrack.buttons.whoseTitle.is("Track Record Enable").first;
                      if (state === 'Enable' && recordBtn.value.value !== "on state") recordBtn.elementClick();
                      if (state === 'Disable' && recordBtn.value.value === "on state") recordBtn.elementClick();
                  }
                  
                  /** @param {{ suffix: string }} arg */
                  function main({ suffix }) {
                      sf.ui.proTools.appActivateMainWindow();
                  
                      setSelectedTrackRecord('Disable');
                  
                      sf.ui.proTools.trackDuplicateSelected({
                          duplicateActivePlaylist: false,
                          duplicateAlternatePlaylists: false,
                          duplicateAutomation: false,
                          duplicateGroupAssignments: true,
                          duplicateInserts: false,
                          duplicateSends: false,
                          insertAfterLastSelectedTrack: true,
                          numberOfDuplicates: 1
                      });
                  
                      sf.ui.proTools.selectedTrack.trackRename({
                          renameFunction: function (name) {
                              const baseName = name.match(/^(.*)\.dup.*/)[1];
                              return baseName + suffix;
                          }
                      });
                  
                      setSelectedTrackRecord('Enable');
                  }
                  
                  main({
                      suffix: '+'
                  });
                  

                  This version will always give you "+" as a suffix.

                  Now, for the version where you choose from a predetermined list, all you have to do is change the last line to this:

                  main({
                      suffix: promptForSuffix([
                          'hi', 'mid', 'lo', 'L', 'R',
                      ])
                  });
                  

                  I prefilled it with the example you gave, but you can of course change it to whatever you like!

                  Let me know how it goes!

                  1. FFukurou Toshima @Fukurou_Toshima
                      2021-11-09 10:58:54.654Z

                      That’s great! Means a lot. You are my life saver!
                      This is completely what I’ve needed and has nice utility to customize.

                      I just wanna thank you!!

                      1. Glad to help!

                        1. FFukurou Toshima @Fukurou_Toshima
                            2021-11-12 09:41:09.983Z

                            My work got much easier to do with your scripts!

                            Could I ask you one more thing??

                            I want to make another macro which duplicates track asking new track name in SF prompt.
                            Not as prefix or suffix but completely new name for duplicated track.

                            What I want is like below.

                            First, SF prompt asks which renaming way.
                            Typing manually or selecting from predefined list.

                            a. typing manually
                            I type a new name track in blank text box and that is simply going to be the name of duplicated track.

                            b. selecting from predefined list
                            Select words from 3 groups, instrument name, section name and suffix.
                            I select instrument at first, then select section name, and select suffix at last.

                            e.g.

                            1st group (instrument name)
                            Lead
                            Chorus
                            Harm
                            Adlib
                            ...

                            2nd group (section name)
                            a-z (alphabet)

                            3rd group (suffix)
                            hi
                            mid
                            lo
                            ...

                            No need record enable/disable section.

                            This is for renaming when duplicating track.
                            But I will be happy if I get a version for creating new track too.

                            I managed to combine the script that you gave me and is on forum to make what I need but I lack basic skill for coding.

                            Thank you for your kind support!

                            1. Hey @Fukurou_Toshima , glad that has been working out!

                              Yes, for sure. Here it is:

                              function promptForRenameInputMethod() {
                                  return sf.interaction.displayDialog({
                                      title: "Duplicate and Rename",
                                      prompt: "Please select an rename method.",
                                      buttons: ["Cancel", "Enter Manually", "From List"],
                                      defaultButton: "From List",
                                  }).button;
                              }
                              
                              /** @param {{ prompt?: string, list: string[] }} args */
                              function promptFromList({ prompt = "Please select an item", list }) {
                                  return sf.interaction.popupSearch({
                                      title: prompt,
                                      items: list.map(item => ({ name: item })),
                                      columns: [{ name: 'Item', key: 'name', width: 10, }],
                                  }).item.name
                              }
                              
                              function composeNameFromList() {
                                  const nameElements = {
                                      instruments: ['Lead', 'Chorus', 'Harm', 'Adlib'],
                                      sections: 'abcdefghijklmnopqrstuvwxyz'.split(''),
                                      suffixes: ['hi', 'mid', 'lo']
                                  }
                              
                                  const instrumentName = promptFromList({ prompt: "Please select an Instrument name", list: nameElements.instruments });
                                  const sectionName = promptFromList({ prompt: "Please select a Section Name", list: nameElements.sections });;
                                  const suffix = promptFromList({ prompt: "Please select a suffix", list: nameElements.suffixes });;
                                  const delimiter = ' ';
                              
                                  return instrumentName + delimiter + sectionName + delimiter + suffix;
                              }
                              
                              function promptForNewName() {
                                  const newName = prompt("Please enter a name for the duplicated track.");
                                  if (!newName) throw 0;
                                  else return newName;
                              }
                              /** @param {{ newName: string }} arg */
                              function duplicateAndRename({ newName }) {
                                  sf.ui.proTools.appActivateMainWindow();
                              
                                  sf.ui.proTools.trackDuplicateSelected({
                                      duplicateActivePlaylist: false,
                                      duplicateAlternatePlaylists: false,
                                      duplicateAutomation: false,
                                      duplicateGroupAssignments: true,
                                      duplicateInserts: false,
                                      duplicateSends: false,
                                      insertAfterLastSelectedTrack: true,
                                      numberOfDuplicates: 1
                                  });
                              
                                  sf.ui.proTools.selectedTrack.trackRename({ newName });
                              }
                              
                              duplicateAndRename({
                                  newName: promptForRenameInputMethod() === "From List" ? composeNameFromList() : promptForNewName()
                              });
                              

                              Let me know how that works out.

                              Oh, and for the new track version, could you make a new forum thread for it? That way we make it easier for other folks to find it in the future. Tag me and I'll take a look when I get another chance!

                              1. FFukurou Toshima @Fukurou_Toshima
                                  2021-11-18 11:33:45.547Z

                                  Thank you, Raphael!
                                  Your script works completely like I want it to!
                                  I was really surprised at your fine skill to understand what other wants and of course code.

                                  Oh, and for the new track version, could you make a new forum thread for it? That way we make it easier for other folks to find it in the future. Tag me and I'll take a look when I get another chance!

                                  Okay, I'm going to make a new thread.

                                  Thank you so far!

                  2. MMiro Wolf @Miro_Wolf
                      2021-11-10 12:50:01.674Z

                      Hi Raphael

                      Wow nice, thanks! Works perfectly!

                    • F
                      In reply toMiro_Wolf:
                      Fukurou Toshima @Fukurou_Toshima
                        2021-11-09 02:18:04.639Z

                        Sorry I made mistake to reply.

                        1. In reply toMiro_Wolf:
                          Oliver Varga @Oliver_Varga
                            2022-02-04 15:31:18.084Z

                            Hey everybody.
                            I can't get this script to work... !??! (Duplicateing a track, rename and enable record)
                            I'm always getting the error saying:
                            "Could not enter new name" Line 36
                            which is: sf.ui.proTools.selectedTrack.trackRename({

                            The track that is beeing duplicted is still selected and the Renaming window stays open... Thats where the script stops.

                            Thanks and all the best

                            • Oliver
                            1. Hey @Oliver_Varga,

                              Give this version a try, should be more robust!

                              sf.ui.proTools.appActivateMainWindow();
                              
                              if (sf.ui.proTools.selectedTrack.buttons.whoseTitle.is("Track Record Enable").first.value.value === "on state") {
                                  sf.ui.proTools.selectedTrack.buttons.whoseTitle.is("Track Record Enable").first.elementClick();
                              }
                              
                              sf.ui.proTools.trackDuplicateSelected({
                                  duplicateActivePlaylist: false,
                                  duplicateAlternatePlaylists: false,
                                  duplicateAutomation: false,
                                  duplicateGroupAssignments: true,
                                  duplicateInserts: false,
                                  duplicateSends: false,
                                  insertAfterLastSelectedTrack: true,
                                  numberOfDuplicates: 1
                              });
                              
                              sf.ui.proTools.mainWindow.invalidate();
                              
                              sf.ui.proTools.selectedTrack.trackRename({
                                  renameFunction: function (name) {
                                      const grps = name.match(/^([^\d]*)(\d*).dup.*/);
                                      const baseName = grps[1];
                                      const num = Number(grps[2]);
                                      return baseName + ((!num && " ") + (num + 1) + '');
                                  }
                              });
                              
                              sf.ui.proTools.selectedTrack.buttons.whoseTitle.is("Track Record Enable").first.elementClick();
                              
                              1. Oliver Varga @Oliver_Varga
                                  2022-02-04 22:22:14.869Z

                                  Yes! It works! Thank you so much!!!