No internet connection
  1. Home
  2. How to

Cycling through Commands (Toggle / Pro Tools)

By Jon Shamieh @Jon_Shamieh
    2019-12-25 20:47:05.232Z

    Hi,

    Is it possible to cycle through Commands?

    For example, I’d like one button on my Stream Deck to cycle these Automation modes:

    1. Automation Read (Selected Tracks)
    2. Automation Touch (Selected Tracks)
    3. Automation Trim (Selected Tracks)
    Solved in post #6, click to view
    • 7 replies
    1. Christian Scheuer @chrscheuer2019-12-26 08:26:59.678Z2019-12-26 09:10:11.496Z

      Hi Jon.

      It's definitely possible to cycle through commands to invoke. And this can be done in a lot of ways.

      You can read some examples of this by searching for toggle in the forum:
      https://forum.soundflow.org/-/search?q=toggle

      Here's a bit more explanation of the different solution types:

      Using internal script state in a variable

      The command itself can hold a state in a number variable for example, and just toggle between running each of the three commands you put here.

      The pseudo code for such a command would be:

      • Increase my internal state number
      • If my internal state number is more than 3, set it back to 1
      • Depending on the value of my internal state number, being 1, 2 or 3, perform 1 of 3 tasks.

      The problem of having state in more than one place

      But what if the script itself was at state 2 and ready to change to Automation Touch but that something else had already changed the state in Pro Tools so that the tracks were in Automation Touch. Then the script would try to change to Automation Touch which was already there, so in other words it would feel to the user as if the script was failing.
      This is due to having the state of the system represented both in Pro Tools and in the script.

      Solving it by reading the Pro Tools state

      But the best results you'll get by having a script that checks the current state in Pro Tools, and then reacts to that state. This way the script doesn't have a variable that holds a "copy" of the state (since we demonstrated having two copies of state that go out of sync is bad). We just read the state directly from Pro Tools.
      Such a script is not universal in that the code will have to be tailored to reading the specific state that you're using in the script.
      In this case you'd need to read the automation mode of the selected track(s), and then set up some logic based on that.

      For example, the pseudo code (logic) could be:

      • If the current track is in automation mode READ (no trim), switch all selected tracks to TOUCH (no trim).
      • If the current track is in automation mode TOUCH (no trim), switch all selected tracks to TOUCH (trim enabled).
      • If the current track is in automation mode TOUCH (trim enabled), switch all selected tracks to READ (no trim).
      • If none of the above conditions are true, switch all selected tracks to READ (no trim).

      A different variation on this logic could be:

      • If any of the selected tracks is in automation mode READ (no trim), switch all selected tracks to TOUCH (no trim).
      • If any of the selected tracks is in automation mode TOUCH (no trim), switch all selected tracks to TOUCH (trim enabled).
      • If any of the selected tracks is in automation mode TOUCH (trim enabled), switch all selected tracks to READ (no trim).
      • If none of the above conditions are true, switch all selected tracks to READ (no trim).

      Note how I've also mapped out the Trim mode to be applied together with touch, since there's no such thing as just being in trim mode, it's always combined with one of the "major" modes of read, touch, latch, touch/latch, etc.

      Once you've decided on the specific logic you want, we could implement the script based on that logic.

      1. JJon Shamieh @Jon_Shamieh
          2019-12-26 18:43:09.512Z

          Very helpful! I see your point with Trim and makes more sense to have it as a separate button so it can be applied to whatever major Automation mode I am in.

          1. Gotcha. Then you can use the built in Automation Trim (Selected Tracks) to toggle the trim setting.

            To cycle between read and touch on one key, your logic would then be something like:

            • If the first selected track is in automation READ, set all selected tracks to TOUCH
            • or, If the first selected track is in automation TOUCH, set all selected tracks to READ
            • else (if the first selected track is neither in read nor in touch), set all selected tracks to READ.

            Since the action is the same for step 2 and step 3, this can be boiled down to:

            • If the first selected track is in automation READ, set all selected tracks to TOUCH
            • else (if the first selected track is not in read), set all selected tracks to READ.

            And now let's look at how to script that:

            if (sf.ui.proTools.selectedTrack.automationModeButton.value.invalidate().value === 'read') {
                sf.ui.proTools.selectedTrack.automationModeSet({
                    automationModeName: 'touch',
                    trackTargetMode: 'SelectedTracks'
                });
            } else {
                sf.ui.proTools.selectedTrack.automationModeSet({
                    automationModeName: 'read',
                    trackTargetMode: 'SelectedTracks'
                });
            }
            
            1. JJon Shamieh @Jon_Shamieh
                2019-12-26 19:34:40.808Z

                This works, but if I select Trim while in Read, let's say, I can't switch to Touch without Toggling out of Trim.. Possible to be able to switch to Touch /Trim from Read / Trim with same toggle button?

                1. Gotcha, then try this:

                  if (sf.ui.proTools.selectedTrack.automationModeButton.value.invalidate().value.indexOf('read') >= 0) {
                      sf.ui.proTools.selectedTrack.automationModeSet({
                          automationModeName: 'touch',
                          trackTargetMode: 'SelectedTracks'
                      });
                  } else {
                      sf.ui.proTools.selectedTrack.automationModeSet({
                          automationModeName: 'read',
                          trackTargetMode: 'SelectedTracks'
                      });
                  }
                  
                  Reply1 LikeSolution
                  1. JJon Shamieh @Jon_Shamieh
                      2019-12-26 19:44:40.582Z

                      Ding ding ding - perfect, there it is! Very much appreciated Christian.

                      1. In reply tochrscheuer:
                        JJon Shamieh @Jon_Shamieh
                          2019-12-29 02:49:18.805Z

                          Is there a way to make this apply to all selected tracks instead of just a single track?