No internet connection
  1. Home
  2. How to

Stream Deck if/then/else with keyboard modifiers.

By Alex Sawyer @Alex_Sawyer1
    2021-06-23 22:21:14.724Z

    I have lots of questions! Mainly things I can do in Keyboard Maestro that I can't work out how to do in SoundFlow. How do I add if/then/else parameters to macros? For example, I would like to use one button on a stream deck to do several different things depending on which modifier is down. So no modifier, opens plugin. Holding down shift, toggles preview button on/off, hold down ctrl renders clip using audiosuite plugin, etc etc.

    Is this only possible if I learn how to use javascript?

    • 10 replies
    1. Kitch Membery @Kitch2021-06-23 22:27:16.421Z

      Hi Alex,

      Thanks for bringing the conversation to the SoundFlow forum. Much appreciated.

      This is certainly possible. To get you started with if statements check out this video.

      Please watch this video to learn how to write an if/else statement in the SoundFlow Editor and how to incorporate it into a script for Pro Tools.

      I'll put a simple script together and post it shortly on how to work with modifiers. :-)

      Rock on!

      1. In reply toAlex_Sawyer1:
        Kitch Membery @Kitch2021-06-23 22:33:47.613Z

        Something like this should work.

        const modifierState = event.keyboardState
        
        if (modifierState.hasShift) {
        
            log("Shift is held down");
        
            //Add code here for when Shift is held down...
        
        } else if (modifierState.hasControl) {
        
            log("Control is held down");
            
            //Add code here for when Control is held down...
        
        } else if (modifierState.hasCommand) {
        
            log("Command is held down");
        
            //Add code here for when Command is held down...
        
        } else if (modifierState.hasAlt) {
        
            log("Option is held down");
        
            //Add code here for when Option is held down...
        
        } else {
        
            log("No modifiers are held down");
        
            //Add code here where no modifiers are held down///
        
        }
        

        Hope that helps :-)

        1. In reply toAlex_Sawyer1:
          Kitch Membery @Kitch2021-06-23 22:41:38.205Z

          For your example you could use this if then else block

          const modifierState = event.keyboardState
          
          if (modifierState.hasShift) {
          
              //Add code here to toggle preview...
          
          } else if (modifierState.hasControl) {
          
              //Add code here to render clip using audiosuite plugin...
          
          } else {
          
              //Add code here to open plugin...
          
          }
          
          1. AAlex Sawyer @Alex_Sawyer1
              2021-06-24 13:20:58.153Z

              Hi Kitch, that's great that seems to work, although the command and control modifiers don't seem to work, but I think that might be a limitation of macOS? But thinking about it, I'd actually like to toggle the plugin show/hide rather than have a separate modifier to close the plugin. This can be part of the if/then/else, but how would I express it in Javascript? Thanks

              1. Kitch Membery @Kitch2021-06-25 06:39:24.596Z

                Hi @Alex_Sawyer1,

                I just tested the script and the modifiers work as expected. Are you wanting to use two modifiers at the same time? If that case you'd need to change the if statement a little.

                For instance, if you wanted to use the combination of Command and Control, you would use the following code;

                const modifierState = event.keyboardState
                
                if (modifierState.hasCommand && modifierState.hasControl) {
                
                    log("Command and Control are held down");
                
                }
                

                I hope that makes sense.

                Rock on

                1. Kitch Membery @Kitch2021-06-25 06:43:37.751Z

                  @Alex_Sawyer1,

                  To answer the second part of the question, you can use the "Open Insert on Track" Macro Action to toggle inserts open and closed on a track.

                  :-)

                  1. AAlex Sawyer @Alex_Sawyer1
                      2021-06-25 15:03:38.566Z

                      Hi Kitch, that's great. The other modifiers work now so it must have been something I was doing wrong. With the second part, I actually meant more like create a toggle for the opening and closing of the audiosuite, so the if/else statement would need to include something like 'if audiosuite plugin xyz is closed, open it, or else close it' Then I wouldnl't need a modifier to open or close it, I could just use the same button. Thanks

                      1. AAlex Sawyer @Alex_Sawyer1
                          2021-06-25 15:06:05.251Z

                          With all the javascript commands that are needed to perform these actions, how do you work out which ones to use? Things like the state of the plugin, or the state of a particular modifier etc. Is there a list somewhere, or is it just the case you just have to know them? Thanks

                          1. Kitch Membery @Kitch2021-06-25 22:36:31.346Z

                            Ah yes. There are a lot of macro actions. So if you are unsure of which SoundFlow Macro actions to use. It's best to search or ask here in the forum especially if you are trying to achieve a particular workflow.

                            Rock on!

                          2. In reply toAlex_Sawyer1:
                            Kitch Membery @Kitch2021-06-25 22:27:47.225Z

                            Hi Alex,

                            The following script should do what you are after. Just change the pluginCategory & pluginName to what you want;

                            var pluginCategory = 'Pitch Shift';
                            var pluginName = 'Pitch II';
                            
                            var win = sf.ui.proTools.getAudioSuiteWindow(pluginName);
                            if (win && win.exists) {
                                win.windowClose();
                            } else {
                                var asWin = sf.ui.proTools.audioSuiteOpenPlugin({ name: pluginName, category: pluginCategory }).window;
                                asWin.buttons.whoseTitle.is('Target button').first.elementClick();
                            }
                            

                            Rock on!