No internet connection
  1. Home
  2. How to

Toggle for 'Output Window: Follow Selected Track' - Not working... Globals script Issue?

By Jordan Pascual @Jordan_Pascual
    2024-04-13 16:15:04.754Z

    First, I apologize if this is a 'duh' answer, but I just spent an hour researching this on the forum, and found no up to date answer on how to solve this.

    In the official SoundFlow PT package created by @chrscheuer, there is the "Output Window: Follow Selected Track" script, which I've listed the source for reference below:

    var lastFocusedTrackName;
    
    function main() {
        try {
    
            var newName = sf.ui.proTools.selectedTrackNames[0];
            if (newName === lastFocusedTrackName || newName === undefined) return;
    
            lastFocusedTrackName = newName;
    
            if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value !== 'open')
                sf.ui.proTools.selectedTrack.trackOutputToggleShow({ onError: 'Continue' });
    
        } catch (err) {
        }
    }
    
    function runForever(name, action, interval, timeout) {
        var now = (new Date).valueOf();
        if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout
    
        globalState[name] = now;
        sf.engine.runInBackground(function () {
            try {
                while (true) {
                    sf.engine.checkForCancellation();
                    globalState[name] = (new Date).valueOf();
    
                    action();
    
                    sf.wait({ intervalMs: interval, executionMode: 'Background' });
                }
            } finally {
                globalState[name] = null;
            }
        });
    }
    
    runForever("isFollowFocusedTrackRunning", main, 500, 5000);
    
    

    I also understand that here in the forums, there has been a few discussions regarding 'Toggling' it using globals. Here is the script I have found for that:

    globalState.isFollowFocusedTrackActive = !globalState.isFollowFocusedTrackActive;
    
    log(`Follow Focused Track is now: ${globalState.isFollowFocusedTrackActive ? 'ON' : 'OFF'}`);
    

    Now, let's say I hook that up as a StreamDeck command or a keyboard trigger. Ideally, I would like that button to turn 'off' this application trigger script. I see the log that is being created in the top right hand corner, however, to my knowledge, it is not doing anything but creating the log, as nothing changes in PT.

    I understand that 'killing the script' and removing the application trigger will work, however, it isn't quite practical for what I want to do.

    I was wondering if there is a way to build the script so:

    1. When PT is active, the script is active (currently works by default w/ app trigger)
    2. Press a toggle button, and that turns 'off' the script, as well as CLOSES the current tracks Output Window.
    3. When I press the same button again, it will 'reactivate' the script, and open the selected tracks Output Window.

    Again, apologies if this has been answered, but if so, please link it to me, as all of the below dead threads from 2020 or so don't seem to have an up to date answer as far as I know :)

    Jordan

    Links to prior discussion:

    Solved in post #2, click to view
    • 6 replies
    1. You just need to adjust the two scripts a bit to tie them together

      var lastFocusedTrackName;
      globalState.isFollowFocusedTrackActive = true
      
      function main() {
          try {
              if (globalState.isFollowFocusedTrackActive) {
      
                  var newName = sf.ui.proTools.selectedTrackNames[0];
                  if (newName === lastFocusedTrackName || newName === undefined) return;
      
                  lastFocusedTrackName = newName;
      
                  if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value !== 'open')
                      sf.ui.proTools.selectedTrack.trackOutputToggleShow({ onError: 'Continue' });
              } else lastFocusedTrackName = "";
      
          } catch (err) {
          }
      }
      
      function runForever(name, action, interval, timeout) {
          var now = (new Date).valueOf();
          if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout
      
          globalState[name] = now;
          sf.engine.runInBackground(function () {
              try {
                  while (true) {
                      sf.engine.checkForCancellation();
                      globalState[name] = (new Date).valueOf();
      
                      action();
      
                      sf.wait({ intervalMs: interval, executionMode: 'Background' });
                  }
              } finally {
                  globalState[name] = null;
              }
          });
      }
      
      runForever("isFollowFocusedTrackRunning", main, 500, 5000);
      

      Use this script to toggle:

      if (globalState.isFollowFocusedTrackActive) {
          if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value == 'open') {
              sf.ui.proTools.selectedTrack.outputWindowButton.elementClick()
          }
      };
      
      globalState.isFollowFocusedTrackActive = !globalState.isFollowFocusedTrackActive;
      
      sf.interaction.notify({
          title:`Follow Focused Track is now: ${globalState.isFollowFocusedTrackActive ? 'ON' : 'OFF'}`
      })
      
      ReplySolution
      1. One thing to keep in mind is that when the script toggles the function to "off" the run forever script is still running in the background - it's just not opening the output window.

        1. Jordan Pascual @Jordan_Pascual
            2024-04-13 20:41:14.616Z2024-04-13 20:50:05.609Z

            Wonderful! Great to know! And thank you for the update, I definitely couldn't find this anywhere else!

            For anyone who follows this post in the future, I made 2 quick modifications:

            1. If the sf notification / log bugs you, I just got rid of line 9-10 on the 'toggle script'.
            2. I set the Application Trigger to 'launch' instead of active, so that the Output Window didn't keep coming back after I returned from another app.

            Works like a charm, thanks @Chris_Shaw !

            1. In reply toChris_Shaw:
              Jordan Pascual @Jordan_Pascual
                2024-04-14 00:09:41.633Z

                Okay... one last lil question...

                Is it possible to modify the script slightly so that upon startup and loading a project, it DOESN'T automatically show the Output Window? I know this sounds counterproductive, however, it would be ideal to startup PT, have the script run, and then immediately hide it. Possible?

                1. It'd be easier just to not have the application trigger the script.
                  Trigger it manually when you want to start seeing the output window.
                  Then use a second trigger to toggle it on or off

                  1. Jordan Pascual @Jordan_Pascual
                      2024-04-15 04:50:04.153Z2024-04-15 05:14:14.027Z

                      Hey another question:

                      Let's say I have a grouped track and I want to see BOTH faders, just by toggling it using the 2nd script. How would you go about doing this?

                      (I understand that they would be grouped together, and that any volume changes would affect both, but visually, it may be nice to see, just to make sure where each is at)