No internet connection
  1. Home
  2. How to

Pro Tools Clip Gain Script

By Kjartan Kjartansson @Kjartan_Kjartansson
    2021-03-13 12:41:26.116Z2021-03-13 14:50:14.420Z

    Hi.
    I quit using Volume automation in Pro Tools the very moment the Clip Gain feature came in, (I think in PT10).

    Call me strange if you will, but I am an old school sound person who is adamant on keeping a good gain structure throughout my mix. This has a major effect on compressors within the track if any.
    Also I love to see the Clips waveforms in their current set levels rather than screaming at my eyes and then when peeking at the volume automation line realising they are at minus 32 or similar.

    This means that my Clips are really ugly because they are split up every time I change the Clip Gain and use an Equal Gain crossfade between them. I never make Clip Groups though, to clean up the mess, since I am always changing as I go along. I realised that this mess was actually very helpful as it is now very easy for me to redo my levels (Clip Gain settings) since I only need to select a Clip with the Grabber (or Clips, using: Grabber plus shift click another clip) .

    This means that it would be nice to have some preset Clip Gain to paste onto Clips.
    (After copying Clip Gain from one Clip you can use Command+V to paste it into another Clip.
    Which is strange as it would be more logical to use: Shift+Ctrl+V to do this rather than just: Command+V since you copy Clip Gain with: Shift+Ctrl+C).

    I made three tracks with the names: GAIN A, GAIN B and GAIN C at the top of my session with empty Clips throughout my active part of my session. And then these Clips have three different gain settings (+5, -10 and -20 or similar). Then I made the following Script that maybe someone can help me with to make cleaner and more robust.

    Also, it could be possible that someone would like to use some of these ideas.

    Here it is:

    //Activate Protools Main Window
    sf.ui.proTools.appActivateMainWindow();
    
    //Get the first selected track name
    var selectedTrackName = sf.ui.proTools.selectedTrackNames[0];
    
    //Display variables track name in notifications
    //log(selectedTrackName);
    
    sf.keyboard.press({
       keys: "alt+cmd+f",
    });
    
    sf.keyboard.type({
       text: "GAIN A",
    });
    
    sf.keyboard.press({
       keys: "return",
    });
    
    sf.ui.proTools.menuClick({
       menuPath: ["Edit","Copy Special","Clip Gain"],
    });
    
    sf.keyboard.press({
       keys: "alt+cmd+f",
    });
    
    sf.keyboard.type({
       text: selectedTrackName,
    });
    
    sf.keyboard.press({
       keys: "return",
    });
    
    sf.wait({
       intervalMs: 100,
    });
    
    sf.keyboard.press({
       keys: "alt+tab,shift+tab",
    });
    
    sf.ui.proTools.menuClick({
     menuPath: ["Edit","Paste"],
    });
    
    Solved in post #4, click to view
    • 7 replies
    1. Thanks for sharing this, Kjartan!

      I would use this built-in function to select tracks instead of the keyboard simulation:

      sf.ui.proTools.trackSelectByName({
          names: ['GAIN A'],
          deselectOthers: true,
      });
      
      1. Excellent.
        Thank you very much.

      2. I noticed this comment:

        (After copying Clip Gain from one Clip you can use Command+V to paste it into another Clip.
        Which is strange as it would be more logical to use: Shift+Ctrl+V to do this rather than just: Command+V since you copy Clip Gain with: Shift+Ctrl+C).

        The logic is actually sound. Shift-Ctl-C is used to copy clip gain data to the clip board. Pasting from the clipboard is always Cmd-V.

        1. I would be happier with a more logical “family” type of a clipboard function.
          One for normal editing and a second one for Clip Gain editing.
          But I know that I am just barking up a “deaf software tree” and should rather send a command request to Avid.
          I am afraid that from my experince since 1998 with Pro Tools, especially after Avid bought Digidesign, that I would also be barking up a rather “deaf tree” by doing so.
          But yes you are absolutely right: there is only one clipboard.

        2. Looking good, Kjartan!

          This is how I would approach it to make it more robust:

          /**@param { string } clipGainTrackName */
          function copyPasteClipGainFromTrack(clipGainTrackName) {
              // Activate Pro Tools
              sf.ui.proTools.appActivateMainWindow();
          
              // Refresh Main Window
              sf.ui.proTools.mainWindow.invalidate();
          
              // Get Copy Clip Gain menu item
              let copyClipGainMenuItem = sf.ui.proTools.getMenuItem("Edit", "Copy Special", "Clip Gain");
          
              // Error Handling: If no clip is present in current playhead position:
              if (!copyClipGainMenuItem.isEnabled) {
                  // Throw error
                  throw `No clip present on playhead position.`
              };
          
              // Get currently selected track
              const selectedTrack = sf.ui.proTools.selectedTrack;
          
              // Select track containing desired Clip Gain
              sf.ui.proTools.trackSelectByName({ names: [clipGainTrackName], deselectOthers: true });
          
              // Force menu item state to refresh by pressing an arbitrary key
              // This is to be able to read current menu item state in the next step
              sf.keyboard.press({ keys: "down" });
          
              // Error Handling: If no clip is present in current playhead position:
              if (!copyClipGainMenuItem.isEnabled) {
                  // Re-select originally selected track
                  selectedTrack.trackSelect();
          
                  // Throw error
                  throw `No clip present in track ${clipGainTrackName} on playhead position.`
              };
          
              // Copy Clip Gain from clip in track
              copyClipGainMenuItem.elementClick();
          
              // Re-select originally selected track
              selectedTrack.trackSelect();
          
              // Select entire clip in original track
              sf.keyboard.press({
                  keys: "alt+tab,shift+tab",
              });
          
              // Paste Clip Gain
              sf.ui.proTools.menuClick({
                  menuPath: ["Edit", "Paste"],
              });
          };
          
          copyPasteClipGainFromTrack('GAIN A');
          

          Using SF you can select tracks without relying on the PT function to do it, so utilizing it can step through the process much quicker. Also introduced some error handling to stop the script if one of the tracks has no clips present in the current play head position. Finally, you can change which "Gain" track you want to copy Clip Gain info in the last line. This can easily be converted into a command template to have all your gain track options available.

          Hope that helps!

          Reply1 LikeSolution
          1. Wow!
            This is crazy good.
            Thank you very much.

          2. J
            J.R. Chappell @J_R_Chappell
              2024-08-08 13:21:56.771Z

              Hello,
              I am looking to do something similar. I am sure someone has done it already but I can't seem to find it. Here is what I would like the script to do.

              Copy the clip gain from a selected clip.
              Select all clips in the session with the same clip name.
              Paste the clip gain to all of the selected clips.

              That would be the simplest version. I guess a nice addition would be to also copy the volume automation and paste that as well.

              Any help would be much appreciated.

              Thanks,