No internet connection
  1. Home
  2. How to

How to insert a plug-in to the next free slot (working across multiple types of tracks and Pro Tools versions)

By MixedByRQ @MixedByRQ
    2020-03-20 08:03:56.967Z

    Hi! Im trying to make a script that would load a plugin in the next avaible insert, but I need the same script to work on HDX systems and non HDX (my laptop).

    I know how to make it work in either configuration with the trackInsertOrSendSelect function but I haven't figured out a condition that would let me choose either path in the code, either it's ['multichannel plug-in', 'Effect', 'CLA Effects (stereo)'] or ['multichannel Native plug-in', 'Effect', 'CLA Effects (stereo)']

    thank you for the help!

    Solved in post #4, click to view

    Linked from:

    1. open a new plugin
    • 14 replies
    1. Hi @MixedByRQ.

      We've been working on an easier way to do this in the upcoming release of 3.5.
      In other words, once 3.5 is updated, this will require less code.

      Until we get 3.5 released, you can find some info here:
      https://forum.soundflow.org/-744#post-22

      And you can also take a look in this script for an approach:

      sf.ui.proTools.appActivateMainWindow();
      
      function getFirstFreeInsertIndex() {
          var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
          let insertArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
          for (let i = 0; i < insertArray.length; i++)
              if (btns[insertArray[i]].value.invalidate().value === "unassigned") return (insertArray[i]);
      
          throw 0;
      }
      
      function clickPopupMenu(popupMenu, paths) {
          for (var i = 0; i < paths.length; i++) {
              var path = paths[i];
              if (popupMenu.menuClickPopupMenu({
                  menuPath: path,
                  onError: 'Continue'
              }).success) {
                  return;
              }
          }
          throw "None of the provided paths were present in this popup menu";
      }
      
      function addCLAEffects() {
          var popupMenu = sf.ui.proTools.selectedTrack.trackInsertOrSendOpenMenu({
              insertOrSend: 'Insert',
              pluginNumber: getFirstFreeInsertIndex() + 1,
          }).popupMenu;
      
          clickPopupMenu(popupMenu, [
              ['multichannel plug-in', 'Effect', 'CLA Effects (stereo)'],
              ['multichannel Native plug-in', 'Effect', 'CLA Effects (stereo)'],
          ]);
      }
      
      addCLAEffects();
      
      1. In reply tochrscheuer:
        MMixedByRQ @MixedByRQ
          2020-03-20 09:41:34.278Z2020-03-20 09:42:44.371Z

          Thank you for the help! I've made a couple modifications that add support for mono/stereo or stereo instances of plugins

          function getFirstFreeInsertIndex() {
              var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
              for (var i = 0; i < 10; i++)
                  if (btns[i].value.invalidate().value === "unassigned") return i;
              return -1;
          }
          
          var pluginPaths = [['plug-in', 'Effect', 'CLA Effects (mono/stereo)'],
                          ['multichannel plug-in', 'Effect', 'CLA Effects (stereo)'],
                          ['Native plug-in', 'Effect', 'CLA Effects (mono/stereo)'],
                          ['multichannel Native plug-in', 'Effect', 'CLA Effects (stereo)']
                          ]
          
          
          function clickPopupMenu(popupMenu, paths) {
              for (var i = 0; i < paths.length; i++) {
                  var path = paths[i];
                  if (popupMenu.menuClickPopupMenu({
                      menuPath: path,
                      onError: 'Continue'
                  }).success) {
                      return;
                  }
              }
              throw "None of the provided paths were present in this popup menu";
          }
          
          function addPlugin() {
              var popupMenu = sf.ui.proTools.selectedTrack.trackInsertOrSendOpenMenu({
                  insertOrSend: 'Insert',
                  pluginNumber: getFirstFreeInsertIndex() + 1,
              }).popupMenu;
          
              clickPopupMenu(popupMenu, pluginPaths);
          }
          
          addPlugin();
          
          ReplySolution
          1. Hi - thanks for the feedback.

            For quoting code, insert a line before and after your code that consists of three backticks: ```
            I'll edit your post to include this.

          2. In reply tochrscheuer:
            MMixedByRQ @MixedByRQ
              2020-03-20 09:42:24.688Z

              Sorry for the mess I'm new to Soundflow and I don't know how to make the code look nice in comments lol

              1. All good :) See my other comment on how to do the formatting.
                Welcome to SoundFlow!

            • In reply toMixedByRQ:
              Jonathan Roye @Jonathan_Roye
                2020-10-29 18:59:43.260Z

                Currently trying to crack the code on this as well. Did you ever get this working? Appreciate any help!

                1. MMixedByRQ @MixedByRQ
                    2020-10-30 03:22:06.636Z
                    function getFirstFreeInsertIndex() {
                        var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
                        for (var i = 0; i < 10; i++)
                            if (btns[i].value.invalidate().value === "unassigned") return i;
                        return -1;
                    }
                    
                    var pluginPaths = [['plug-in', 'Effect', 'CLA Effects (mono/stereo)'],
                                    ['multichannel plug-in', 'Effect', 'CLA Effects (stereo)'],
                                    ['Native plug-in', 'Effect', 'CLA Effects (mono/stereo)'],
                                    ['multichannel Native plug-in', 'Effect', 'CLA Effects (stereo)']
                                    ]
                    
                    function clickPopupMenu(popupMenu, paths) {
                        for (var i = 0; i < paths.length; i++) {
                            var path = paths[i];
                            if (popupMenu.menuClickPopupMenu({
                                menuPath: path,
                                onError: 'Continue'
                            }).success) {
                                return;
                            }
                        }
                        throw "None of the provided paths were present in this popup menu";
                    }
                    
                    function addPlugin() {
                        var popupMenu = sf.ui.proTools.selectedTrack.trackInsertOrSendOpenMenu({
                            insertOrSend: 'Insert',
                            pluginNumber: getFirstFreeInsertIndex() + 1,
                        }).popupMenu;
                    
                        clickPopupMenu(popupMenu, pluginPaths);
                    }
                    
                    try{  
                      addPlugin();
                       }
                    
                    catch(err){
                    
                    sf.ui.proTools.menuClick({
                      menuPath: ["View","Edit Window Views","Inserts F-J"],
                    });
                    
                    addPlugin();
                    
                    }
                    
                    1. Jonathan, if I remember correctly, your issue was that you're on a DSP system right? Can you show us how your menus look - like a screenshot of the popup menu you get when adding an insert?

                      1. Jonathan Roye @Jonathan_Roye
                          2020-10-30 16:45:47.746Z

                          For sure - Here is a screen shot of the plugin menus. Going to try the above script as well when I have time to dive into it this weekend. Appreciate the help all. Loving Soundflow thus far.

                          1. Jonathan Roye @Jonathan_Roye
                              2020-10-30 17:02:40.485Z

                              And another for multi mono...

                              1. Thanks! Try this - the pluginPaths property just needs to specify the menu paths in order of priority - I changed these to map to your screenshots now:

                                function getFirstFreeInsertIndex() {
                                    var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
                                    for (var i = 0; i < 10; i++)
                                        if (btns[i].value.invalidate().value === "unassigned") return i;
                                    return -1;
                                }
                                
                                var pluginPaths = [['DSP plug-in', 'Effect', 'CLA Effects (mono/stereo)'],
                                                ['multichannel DSP plug-in', 'Effect', 'CLA Effects (stereo)'],
                                                ['Native plug-in', 'Effect', 'CLA Effects (mono/stereo)'],
                                                ['multichannel Native plug-in', 'Effect', 'CLA Effects (stereo)']
                                                ]
                                
                                function clickPopupMenu(popupMenu, paths) {
                                    for (var i = 0; i < paths.length; i++) {
                                        var path = paths[i];
                                        if (popupMenu.menuClickPopupMenu({
                                            menuPath: path,
                                            onError: 'Continue'
                                        }).success) {
                                            return;
                                        }
                                    }
                                    throw "None of the provided paths were present in this popup menu";
                                }
                                
                                function addPlugin() {
                                    var popupMenu = sf.ui.proTools.selectedTrack.trackInsertOrSendOpenMenu({
                                        insertOrSend: 'Insert',
                                        pluginNumber: getFirstFreeInsertIndex() + 1,
                                    }).popupMenu;
                                
                                    clickPopupMenu(popupMenu, pluginPaths);
                                }
                                
                                try{  
                                  addPlugin();
                                   }
                                
                                catch(err){
                                
                                sf.ui.proTools.menuClick({
                                  menuPath: ["View","Edit Window Views","Inserts F-J"],
                                });
                                
                                addPlugin();
                                
                                }
                                
                                1. Jonathan Roye @Jonathan_Roye
                                    2020-10-30 20:04:34.932Z

                                    Brilliant! Looking like this script is working. Just because I'm dumb...All I would need to do is for each plugin I want is to Change the category and plugin name here?

                                    var pluginPaths = [['DSP plug-in', 'Effect', 'CLA Effects (mono/stereo)'],
                                    ['multichannel DSP plug-in', 'Effect', 'CLA Effects (stereo)'],
                                    ['Native plug-in', 'Effect', 'CLA Effects (mono/stereo)'],
                                    ['multichannel Native plug-in', 'Effect', 'CLA Effects (stereo)']
                                    ]

                                    1. Yes, exactly :) It just needs to match what the menu item would be called.

                          2. In reply toJonathan_Roye:
                            MMixedByRQ @MixedByRQ
                              2020-10-30 03:22:58.796Z

                              Thats what I have!! It's been working fine for me let me know if it helps!