No internet connection
  1. Home
  2. How to

Select a track, scroll into view then adjust track height

Hi, I am not very good with script, I tried to create this command where it select my lead vocal, scrolls it into view, adjust the height to large and select the volume line for automation.

The problems that I run into is that it doesn't scroll into view like it would if I right click on the name and select scroll into view, it would normaly bring my track at the top of the screen, at the moment it puts it at the bottom. Secondly, I tried a few script here for selecting track Height "large" and I can't seem to make it work... Last, for the moment I use the keybord command to select the volume line automation, but if it already in that state, it switch it back. So I was wondering and to select the volume menu on the track.

Thanks for you help.

  • 2 replies
  1. samuel henriques @samuel_henriques
      2021-08-14 19:19:33.409Z

      Hello Charles-Émile Beaudin,

      It could be less code, but I tried to make it so you can change your mind in the future about size and track view. And to avoid opening popup menus as much as possible, to speed up the script.

      Try it and let me know if this is it.

      make sure you replace 'Vocal 1' to the track name you want, in the line
      trackName: 'Vocal 01', as well as the other settings you may want diferent.

      /**
      * @param {number} h
      */
      function getCurrentTrackHeight(h) {
      
          let originalTrackHeight;
      
          switch (true) {
              case (h <= 16):
                  originalTrackHeight = 'micro';
                  break;
              case (h === 23):
                  originalTrackHeight = 'mini';
                  break;
              case (h >= 43 && h <= 61):
                  originalTrackHeight = 'small';
                  break;
              case (h >= 79 && h <= 116):
                  originalTrackHeight = 'medium';
                  break;
              case (h >= 135 && h <= 235):
                  originalTrackHeight = 'large';
                  break;
              case (h >= 257 && h <= 420):
                  originalTrackHeight = 'jumbo';
                  break;
              case (h > 440):
                  originalTrackHeight = 'extreme';
                  break;
          }
          return originalTrackHeight
      }
      
      
      function setTrackSize(size) {
          const f = sf.ui.proTools.selectedTrack.frame;
      
          if (getCurrentTrackHeight(f.h) != size) {
      
              const popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({
                  relativePosition: { x: f.w - 10, y: 5 },
                  isOption: true,
                  isShift: true,
              }).popupMenu;
      
              popupMenu.menuClickPopupMenu({
                  menuPath: [size]
              });
          };
      };
      
      
      function setTrackViewAvoidPopup(trackView) {
          const trackViewSelector = () => sf.ui.proTools.selectedTrack.popupButtons.allItems[2].value.invalidate().value
      
          if (trackViewSelector() != 'volume' && trackViewSelector() != 'waveform') {
              sf.keyboard.press({ keys: "minus", repetitions: 2, fast: true });
      
          } else if (trackViewSelector() === 'waveform') {
              sf.keyboard.press({ keys: "minus" });
          }
      
          if (trackViewSelector() != trackView) {
              // // Set track view with popup
              sf.ui.proTools.selectedTrack.popupButtons.allItems[2].popupMenuSelect({
                  menuPath: [trackView]
              });
          };
      };
      
      
      
      function selectTrackandSetView({ trackName, trackSize, trackView }) {
      
          const isTrackListOpen = sf.ui.proTools.getMenuItem("View", "Other Displays", "Track List").isMenuChecked
      
          // If track list is not opened, open
          if (!isTrackListOpen) { sf.ui.proTools.trackEnsureTrackListViewIsAccessible({ makeVisible: false }) }
      
          // Select track
          sf.ui.proTools.trackSelectByName({ names: [trackName] })
      
          // Scrool to view by track list
          sf.ui.proTools.selectedTrackListItems[0].children.whoseRole.is("AXCell").allItems[1].buttons.first.mouseClickElement({ isControl: true, isShift: true })
      
          // Set track size if not correct
          setTrackSize(trackSize)
      
          // Set track trying to avoid popup
          setTrackViewAvoidPopup(trackView)
      
          // Set Track list view to initial state
          if (!isTrackListOpen) {
              sf.ui.proTools.menuClick({ menuPath: ["View", "Other Displays", "Track List"], targetValue: "Disable" });
          }
      }
      
      
      
      
      sf.ui.proTools.appActivateMainWindow()
      sf.ui.proTools.invalidate()
      
      
      selectTrackandSetView({
          trackName: "Vocal 1",
          trackSize: "large",
          trackView: "volume",
      })
      
      1. C

        Brilliant! Thank you!