No internet connection
  1. Home
  2. How to

Solo/mute track based on track name variable

By Les Cooper @Les_Cooper
    2022-02-07 20:30:53.299Z

    I'd like to make a separate button on my device for each track to toggle mute state.
    I have a very basic script that stores the first 6 track names into variables.

    //Get the track names of first 6 tracks
    var selectedTrackName1 = sf.ui.proTools.selectedTrackNames[0];
    var selectedTrackName2 = sf.ui.proTools.selectedTrackNames[1];
    var selectedTrackName3 = sf.ui.proTools.selectedTrackNames[2];
    var selectedTrackName4 = sf.ui.proTools.selectedTrackNames[3];
    var selectedTrackName5 = sf.ui.proTools.selectedTrackNames[4];
    var selectedTrackName6 = sf.ui.proTools.selectedTrackNames[5];
    var selectedTrackName7 = sf.ui.proTools.selectedTrackNames[6];
    

    so...for the script below, instead of toggling mute for 'Audio 3' I'd like to toggle mute for selectedTrackName(1-6)
    Please excuse my beginner coding skills. Just getting my head around some of this stuff.

    sf.ui.proTools.trackGetByName({
        name: 'Audio 3'
    }).track.trackSetMute({ targetValue: 'Enable' });
    
    sf.ui.proTools.trackSetMuteByName({
        name: 'Audio 3',
        targetValue: 'Toggle'   
    });
    
    Solved in post #7, click to view
    • 7 replies
    1. Chris Shaw @Chris_Shaw2022-02-07 23:05:11.119Z2022-02-07 23:23:54.199Z

      This should do it:
      Create a copy of this script for each selected track number you want to mute and change toggleTrackMute = # accordingly.

      This script will toggle the first selected track.
      Creating a copy of this script and changing toggleTrackMute to 2 will mute the second selected track and so on.

      Assign each copy to a button on your deck and you should be good to go.

      const toggleTrackMute = 1
      
      sf.ui.proTools.appActivate()
      var selectedTracks = sf.ui.proTools.selectedTrackNames
      
      // Make sure that the selected track to mute exists
      if (toggleTrackMute > selectedTracks.length){
          log (`There are only ${selectedTracks.length} tracks selected.`, `Track ${toggleTrackMute} can't be muted`);
          throw 0
      };
      
      // Mute track
      sf.ui.proTools.trackSetMuteByName({
          name: selectedTracks[toggleTrackMute - 1],
          targetValue: 'Toggle'   
      });
      
      
      1. I've re-edited the code to check that it is possible to mute the track # you want.

        1. LLes Cooper @Les_Cooper
            2022-02-07 23:53:42.723Z2022-02-08 00:00:08.311Z

            Hey Chris. Thank so much for looking at this.
            I think that I've caused a bit of confusion by naming my variables too close to the name of the selectedTrackNames action. I've changed the name of the variables to be copiedName(1-6) now
            I think that this script may make more sense.
            My hope is to be able to set the track names for the first 6 tracks (in this case) to variables and then at any point, even if I move the tracks, be able to mute or solo them.

            //Get the track names of first 6 tracks
            var copiedName1 = sf.ui.proTools.selectedTrackNames[0];
            var copiedName2 = sf.ui.proTools.selectedTrackNames[1];
            var copiedName3 = sf.ui.proTools.selectedTrackNames[2];
            var copiedName4 = sf.ui.proTools.selectedTrackNames[3];
            var copiedName5 = sf.ui.proTools.selectedTrackNames[4];
            var copiedName6 = sf.ui.proTools.selectedTrackNames[5];
            
            // code should toggle the mute state for whichever track is stored in the variable
            // so it should do the following
            
            // toggleTrackMute = whatever the string/name is of the track that is stored in copiedName1
            // how do I assign that variable to the toggleTrackMute command?
            
            1. Chris Shaw @Chris_Shaw2022-02-08 00:30:32.136Z2022-02-08 00:53:37.905Z

              I see what you're trying to do. However every time you run this script it's going to overwrite the names (copiedName) from whatever tracks are selected at the time the script is run. If different tracks are selected the next time you run this script then the variables will not be the same.

              I'm not at my computer at the moment but this could be done.
              You'll need two distinct scripts: one to store / update the names into globalSate which will retain their values after the script is run, and another to select/retrieve the track names from globalState and mute them (similar to the script I wrote above.

              1. Use this script to get the track names to be muted and save them into a globalState:

                sf.ui.proTools.appActivate()
                globalState.lcTracksToMute = sf.ui.proTools.selectedTrackNames
                

                then use this to mute them (again changing the toggleMute value where needed)

                const toggleTrackMute = 1
                
                sf.ui.proTools.appActivate()
                
                // Make sure that the selected track to mute exists
                if (toggleTrackMute > globalState.lcTracksToMute.length){
                    log (`There are only ${globalState.lcTracksToMute.length} tracks selected.`, `Track ${toggleTrackMute} can't be muted`);
                    throw 0
                };
                
                // Mute track
                sf.ui.proTools.trackSetMuteByName({
                    name: globalState.lcTracksToMute[toggleTrackMute - 1],
                    targetValue: 'Toggle'   
                });
                

                Now, once you set the names of the tracks to be muted you'll be able to use the second script to mute them even if you move them.

                1. Because other scripts can store values in globalState I prepended the global state variable TracksToMute with your initials to make it more unique.

                  Reply1 LikeSolution
                2. In reply toChris_Shaw:
                  LLes Cooper @Les_Cooper
                    2022-02-08 01:06:40.804Z2022-02-08 02:09:40.606Z

                    This is so great Chris!
                    I'm attempting to recreate my S3 on a surface and your script gets me a lot closer!​

                    My end goal, and this is likely a lot more involved,

                    1. find a way to have the buttons reflect the mute/solo state of the tracks. ie. change color or show an M or an S
                    2. dynamically populate buttons on my surface with the track names from the global name pull.

                    I'm not even sure if all of this is possible but it would be very cool if it was.
                    One can dream.