No internet connection
  1. Home
  2. Support

How modify this script for only selected tracks?

By Yujiro Yonetsu @Yujiro_Yonetsu
    2021-04-15 06:26:11.661Z

    Desired Workflow

    I select only Stereo Tracks in already selected Tracks.

    Question

    Now, this script will select only the stereo tracks from all the tracks in the session.
    I would like to modify this script to select only the stereo of the currently selected track.

    Command Info

    ID: user:ckn2gzwxh0000e71043ve6uq8:cknihgx63000sr0103hjyr7u1
    Name: test
    

    Source

    
    function isAudioTrack(trackName) {
        var track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
        if (!track) return;
        return track.title.value.indexOf('Audio Track') >= 0;
    }
    
    
    function getTrackWidth(trackName) {
        var track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
        var width = track.groups.whoseTitle.is('Audio IO').first.sliders.whoseTitle.contains('Pan').count;
        return width;
    }
    
    function selectAllAudioTracksOfWidth(width) {
        var names = sf.ui.proTools.trackNames.filter(isAudioTrack).filter(t => getTrackWidth(t) === width);
        if (names.length === 0) return;
        sf.ui.proTools.trackGetByName({ name: names[0] }).track.trackScrollToView();
        sf.ui.proTools.trackSelectByName({
            names: names,
            deselectOthers: true
        });
    }
    
    
    //To select all stereo audio tracks
    selectAllAudioTracksOfWidth(2);
    

    Links

    User UID: 2rFAsTbdHvMB0V3hq0Qqhg8wpZy2

    Feedback Key: sffeedback:2rFAsTbdHvMB0V3hq0Qqhg8wpZy2:-MYJCL-4ceYP4WqRzbwo

    Feedback ZIP

    Solved in post #2, click to view
    • 3 replies
    1. Try this:

      function isAudioTrack(trackName) {
          var track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
          if (!track) return;
          return track.title.value.indexOf('Audio Track') >= 0;
      }
      
      
      function getTrackWidth(trackName) {
          var track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
          var width = track.groups.whoseTitle.is('Audio IO').first.sliders.whoseTitle.contains('Pan').count;
          return width;
      }
      
      function selectAllSelectedAudioTracksOfWidth(width) {
          var names = sf.ui.proTools.selectedTrackNames.filter(isAudioTrack).filter(t => getTrackWidth(t) === width);
          if (names.length === 0) return;
          sf.ui.proTools.trackGetByName({ name: names[0] }).track.trackScrollToView();
          sf.ui.proTools.trackSelectByName({
              names: names,
              deselectOthers: true
          });
      }
      
      
      //To select all stereo audio tracks
      selectAllSelectedAudioTracksOfWidth(2);
      
      Reply1 LikeSolution
      1. Yujiro Yonetsu @Yujiro_Yonetsu
          2021-04-15 13:44:59.192Z

          It's perfect!

          Thank you!

        • C
          In reply toYujiro_Yonetsu:
          Charles Elmi @Charles_Elmi
            2023-01-25 21:04:06.183Z

            Just a side note:

            When a track is set to 'no output' the panners are gone and getTrackWidth in this case will return 0.

            My solution/fallback for this has been to detect if returned value is zero and if so, check if menuPath:
            'Track > Split into Mono' is available for the specific track.

            If yes assume 'stereo'; if no assume 'mono'. Has been working so far.

            This works for following track types:
            Audio Tracks
            Aux Tracks
            Master Tracks
            Instrument Tracks


            However it does not work for Routing Folder Tracks.

            So one needs to detect if requested track falls into the category of 'working track types' and if so apply the 'fallback'.

            Hope this helps someone, and if there's a better solution I would love to know!! :)
            //Charles