No internet connection
  1. Home
  2. How to

Three-Way Toggle (Solo, Mute, Active)

By Jeff Whitcher @Jeff_Whitcher
    2022-02-19 05:26:53.617Z

    Greetings,

    I have been playing around with the solo and mute and have had great success toggling solo on a selection of tracks or toggling mute on a selection of tracks.

    What I am trying to do is a three-step sequence on one button:

    1. push the button and, if the track is NOT soloed, solo it
    2. push the same button again and the track will mute
    3. push it one more time and its active/opened up to normal

    So, a three-step toggle. I kept getting stuck where BOTH solo and mute would happen at the same time, then solo would turn off with mute staying on, then mute would shut off. I missing something in the IF, ELSE IF, IF routine I believe but please correct me if that is incorrect - I am a super-noob with this and appreciate any guidance.

    Jeff

    • 4 replies
    1. Chris Shaw @Chris_Shaw2022-02-19 21:56:41.872Z2022-02-19 22:09:16.553Z

      That's a tricky one because you have to store the track's mute state in order to restore it after going through the cycle. A simple if logic won't work.

      This should do it. Two things to keep in mind: It will only work on one track at a time (or the first selected track) and switching tracks before completing the three button presses will give you unexpected results.

      const selectedTrack = sf.ui.proTools.selectedTrack;
      
      // Check if we have a valid trigger count if not set it to 1 and 
      // get the track's orig mute state
      if (!globalState.triggerCount) {
          globalState.triggerCount = 1;
          globalState.origMuteState = selectedTrack.isMuted
      };
      
      const triggerCount = globalState.triggerCount
      const origMuteState = globalState.origMuteState
      
      // First trigger - solo and unmute track
      if (triggerCount == 1) {
          selectedTrack.trackSetSolo({ targetValue: 'Enable' });
          selectedTrack.trackSetMute({ targetValue: 'Disable' });
          globalState.triggerCount = 2
          throw 0
      
      };
      
      //Second trigger - solo and mute track
      if (triggerCount == 2) {
          selectedTrack.trackSetSolo({ targetValue: 'Enable' });
          selectedTrack.trackSetMute({ targetValue: 'Enable' });
          globalState.triggerCount = 3
          throw 0
      
      };
      
      //Third trigger - un-solo and set track's mute to original state
      if (triggerCount == 3) {
          selectedTrack.trackSetSolo({ targetValue: 'Disable' });
          selectedTrack.trackSetMute({ targetValue: (origMuteState) ? 'Enable' : "Disable" });
      
          // Set trigger count and track mute state to `null`
          globalState.triggerCount = null
          globalState.origMuteState = null
          throw 0
      };
      
      
      
      1. Chris Shaw @Chris_Shaw2022-02-19 22:13:47.015Z2022-02-19 23:00:09.011Z

        You could just reduce this to two triggers. The first will solo and unmute the track the second will un-solo and set the track mute to it's original state:

        const selectedTrack = sf.ui.proTools.selectedTrack;
        
        // Check if we have a valid trigger count if not set it to 1
        if (!globalState.triggerCount) {
            globalState.triggerCount = 1;
            globalState.origMuteState = selectedTrack.isMuted
        };
        
        const triggerCount = globalState.triggerCount
        const origMuteState = globalState.origMuteState
        
        // First trigger - solo and unmute track
        if (triggerCount == 1) {
            selectedTrack.trackSetSolo({ targetValue: 'Enable' });
            selectedTrack.trackSetMute({ targetValue: 'Disable' });
            globalState.triggerCount = 2
            throw 0
        
        };
        
        //Second trigger - un-solo and set track's mute to original state
        if (triggerCount == 2) {
            selectedTrack.trackSetSolo({ targetValue: 'Disable' });
            selectedTrack.trackSetMute({ targetValue: (origMuteState) ? 'Enable' : "Disable" });
        
            // Reset trigger count and track mute state
            globalState.triggerCount = null
            globalState.origMuteState = null
        };
        
      2. In reply toJeff_Whitcher:
        Jeff Whitcher @Jeff_Whitcher
          2022-02-19 23:38:06.804Z2022-02-20 01:07:13.115Z

          Chris, you are so kind to reply. Thank you so much. And this worked with one small change in step 2. I changed the targetValue to 'Disable' for trackSetSolo. Now, it works in sequence: it first solos the selected track, then it turns solo off and mutes the track, then it turns off the mute.

          I really appreciate your reply and hope you have a terrific weekend,
          Jeff

          Here is the code with the final change:

          preformatted text
          ```const selectedTrack = sf.ui.proTools.selectedTrack;
          
          // Check if we have a valid trigger count if not set it to 1 and 
          // get the track's orig mute state
          if (!globalState.triggerCount) {
              globalState.triggerCount = 1;
              globalState.origMuteState = selectedTrack.isMuted
          };
          
          const triggerCount = globalState.triggerCount
          const origMuteState = globalState.origMuteState
          
          // First trigger - solo and unmute track
          if (triggerCount == 1) {
              selectedTrack.trackSetSolo({ targetValue: 'Enable' });
              selectedTrack.trackSetMute({ targetValue: 'Disable' });
              globalState.triggerCount = 2
              throw 0
          
          };
          
          //Second trigger - unsolo and mute track
          if (triggerCount == 2) {
              selectedTrack.trackSetSolo({ targetValue: 'Disable' });
              selectedTrack.trackSetMute({ targetValue: 'Enable' });
              globalState.triggerCount = 3
              throw 0
          
          };
          
          //Third trigger - un-solo and set track's mute to original state
          if (triggerCount == 3) {
              selectedTrack.trackSetSolo({ targetValue: 'Disable' });
              selectedTrack.trackSetMute({ targetValue: (origMuteState) ? 'Enable' : "Disable" });
          
              // Set trigger count and track mute state to `null`
              globalState.triggerCount = null
              globalState.origMuteState = null
              throw 0
          };
          
          
          1. In reply toJeff_Whitcher:
            Jeff Whitcher @Jeff_Whitcher
              2022-02-22 00:46:11.657Z

              Hi, Chris.

              I further refined the script to now run based on a user-assigned 'track name', rather than simply on the "selected track." If you get a moment to give this a try and let me know it runs smoothly for you, I'll then update this thread by checking the solution prompt.

              Let me know what you think,
              Jeff

              var track = sf.ui.proTools.trackGetByName({ name: 'track name', makeVisible: true }).track;
              
              // Check if we have a valid trigger count if not set it to 1 and 
              // get the track's orig mute state
              if (!globalState.triggerCount) {
                  globalState.triggerCount = 1;
                  globalState.origMuteState = track.isMuted
              };
              
              var triggerCount = globalState.triggerCount
              var origMuteState = globalState.origMuteState
              
              // First trigger - solo and unmute track
              if (triggerCount == 1) {
                  track.trackSetSolo({ targetValue: 'Enable' });
                  track.trackSetMute({ targetValue: 'Disable' });
                  globalState.triggerCount = 2
                  throw 0
              
              };
              
              //Second trigger - unsolo and mute track
              if (triggerCount == 2) {
                  track.trackSetSolo({ targetValue: 'Disable' });
                  track.trackSetMute({ targetValue: 'Enable' });
                  globalState.triggerCount = 3
                  throw 0
              
              };
              
              //Third trigger - un-solo and set track's mute to original state
              if (triggerCount == 3) {
                  track.trackSetSolo({ targetValue: 'Disable' });
                  track.trackSetMute({ targetValue: (origMuteState) ? 'Enable' : "Disable" });
              
                  // Set trigger count and track mute state to `null`
                  globalState.triggerCount = null
                  globalState.origMuteState = null
                  throw 0
              };