No internet connection
  1. Home
  2. How to

Insert X follows track selection

By Ingo Pusswald @ingo_luftrausch
    2020-04-17 11:33:28.149Z

    Hi,
    we have the wonderful script called "Output Window: Follow Selected Track"

    Is it possible to have this for Insert Slots?

    Thanks

    Solved in post #3, click to view
    • 7 replies
    1. Ingo Pusswald @ingo_luftrausch
        2020-04-17 12:53:49.153Z

        So far I have this, and its working somehow. The PluginWindow is constantly re-opened (blinking :-(
        Any Tipps on how to modify?
        thx

        var lastFocusedTrackName;

        function main() {

        const firstSelectedTrackHeader = sf.proTools.trackGetFirstSelectedTrackHeader({
        onError: "Continue",
        }).firstSelectedTrackHeader;
        
        firstSelectedTrackHeader.trackInsertToggleShow({
            insertNumber: 3,
         onError: "Continue",
        });
        

        }

        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);

        1. In reply toingo_luftrausch:
          Ingo Pusswald @ingo_luftrausch
            2020-04-17 14:59:16.745Z

            After lots of try and error, here is it finally: Track Output Window + Insert Slot Nr3 follows Track Selection.

            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' });
                        sf.ui.proTools.selectedTrack.trackInsertToggleShow({
                        insertNumber: 3,
                        targetValue: "Enable",
                        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)`;`
            `
            Reply1 LikeSolution
            1. Great work, Ingo!!

              1. In reply toingo_luftrausch:
                DDan Bozek @Dan_Bozek
                  2021-03-06 21:43:16.843Z

                  How are you getting this to work/trigger? I would love to get this working on my rig!!

                  1. Ingo Pusswald @ingo_luftrausch
                      2021-03-06 22:00:55.341Z

                      Hi Dan,

                      I have a XL Deck full of triggers build around that script.

                      Follow Insert No. X with or without Pan Window of selected track etc.

                      Its basically working but sometimes there are hick-ups cause of the loop running in background.

                      If I forget to post it within the next 4 days give me a reminder ;-)

                      1. DDan Bozek @Dan_Bozek
                          2021-03-06 22:02:59.720Z

                          Cool!! No hurry. I'm just curious. It is a fantastic idea.

                          1. Ingo Pusswald @ingo_luftrausch
                              2021-03-07 10:42:43.084Z

                              Here is the Deck:

                              The "STOP" button is the "stop all running commands" from the SF main menu.
                              You need to stop everytime you wanna switch the Insert number to follow.

                              As I mentioned it has it hick-ups....

                              Here is the script for "follow Pan/Ins A":

                              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' });
                                          sf.ui.proTools.selectedTrack.trackInsertToggleShow({
                                          insertNumber: 1,
                                          targetValue: "Enable",
                                          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);
                              

                              But its the same script allready posted above.......