No internet connection
  1. Home
  2. How to

Programmatically selecting the same number of tracks up or down from currently selected tracks?

By Owen Granich-Young @Owen_Granich_Young
    2023-03-01 20:19:24.999Z

    @Kitch @Chris_Shaw Currently I use this function

    function navigateTrack({ direction, repetitions }) {
        for (let i = 0; i < repetitions; i++) {
            if (direction === 'Up') {
                sf.ui.proTools.getMenuItem("Edit", "Selection", "Extend Edit Up").elementClick();
                sf.ui.proTools.getMenuItem("Edit", "Selection", "Remove Edit from Bottom").elementClick();
            }
            if (direction === 'Down') {
                sf.ui.proTools.getMenuItem("Edit", "Selection", "Extend Edit Down").elementClick();
                sf.ui.proTools.getMenuItem("Edit", "Selection", "Remove Edit from Top").elementClick();
            }
        }
    }
    

    But scripts are moving too fast for it. Hoping you can help build a way that instead uses track index.

    In the meeting I think you said:
    "Getting all the info about the selected tracks and the track number and then from there adding whatever needs to be added."
    And Chris you said :
    'Let the next track index be the first track and count number of tracks from there'

    Thanks guys!

    Solved in post #2, click to view
    • 5 replies
    1. Kitch Membery @Kitch2023-03-01 21:27:42.787Z2023-03-01 21:34:57.600Z

      Fun!!!!

      /**
       * @param {object} obj
       * @param {'Down'|'Up'} obj.direction
       * @param {number} [obj.repetitions]
       */
      function navigateTracks({ direction, repetitions = 1 }) {
          //Activate Pro Tools Main window
          sf.ui.proTools.appActivateMainWindow();
          //Invalidate the main window
          sf.ui.proTools.mainWindow.invalidate();
      
          //Get the visible track names
          let visibleTrackNames = sf.ui.proTools.visibleTrackNames;
          //Get the selected track names
          let selectedTrackNames = sf.ui.proTools.selectedTrackNames;
          //Get the selected track count
          let selectedTrackCount = sf.ui.proTools.selectedTrackCount;
      
          let trackIndexOffset = direction === "Down" ? selectedTrackCount : selectedTrackCount * -1;
      
          //Make a lookup table for the tracks with indexes indexes
          let trackLookup = visibleTrackNames.map((name, index) => ({ name, index, }));
      
          //Get the target track indexs
          let targetTrackIndexes = trackLookup.filter(track => selectedTrackNames.some(name => name === track.name))
              .map(track => track.index + (trackIndexOffset * repetitions));
      
          //Use the lookup table to get the target track names
          let targetTrackSet = targetTrackIndexes.map(index => trackLookup[index].name);
      
          //Select the target tracks
          sf.ui.proTools.trackSelectByName({ names: targetTrackSet });
      }
      
      navigateTracks({
          direction: "Down",
          //repetitions: 2
      });
      

      Updated :-)

      ReplySolution
      1. Kitch Membery @Kitch2023-03-01 21:29:07.259Z

        @Owen_Granich_Young
        FYI The repetitions argument is optional with a default value of 1.

        1. In reply toKitch:
          Kitch Membery @Kitch2023-03-01 21:31:26.395Z

          @Owen_Granich_Young, Stand by for update with improved variable naming.

        2. O

          Thank you!
          waaaay snappier, now to go replace the old function it like half a dozen scripts

          1. Kitch Membery @Kitch2023-03-01 21:56:56.533Z

            Yay!!! UI automation wins over keyboard simulation once again!!! :-)