No internet connection
  1. Home
  2. How to

Insert menu search times with new popup menu handling

By Andrew Scheps @Andrew_Scheps
    2020-03-11 16:00:45.745Z

    The new popup menu handling is awesome for sends and outputs, but I'm seeing some performance issues with inserts. I'm assuming this is because each time the command is run it needs to build a cache of all of the inserts so you can search them. I have thousands of plugins and this is causing it to take a few seconds for the script to continue every time it's run. I wonder if there could be a persistent cache of the plugin menus...

    To illustrate, I have a script to insert a plugin on the first available slot (It doesn't go in strict order but that's just me making things complicated). The old version using explicit paths runs very quickly, adding the insert within 2 seconds. The new method with implicit paths (I still have to search separately for mono and stereo since there are no wildcards) takes more than double the time.

    Script 1 (Explicit paths):

    sf.ui.proTools.appActivateMainWindow();
    
    function getFirstFreeInsertIndex() {
        var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
        let insertArray = [2, 3, 4, 5, 6, 7, 8, 9, 1, 0];
        for (let i = 0; i < insertArray.length; i++)
    
            if (btns[insertArray[i]].value.invalidate().value === "unassigned") return (insertArray[i]);
    
        throw 0;
    }
    
    
    sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
        insertOrSend: "Insert",
        pluginNumber: getFirstFreeInsertIndex() + 1,
        pluginPath: ["plug-in", "EQ", "Scheps Omni Channel (mono)"],
    }, function (notMonoTrack) {
        sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
            insertOrSend: "Insert",
            pluginNumber: getFirstFreeInsertIndex() + 1,
            pluginPath: ["multichannel plug-in", "EQ", "Scheps Omni Channel (stereo)"],
        })
    });
    

    Script 2 (new method, slower)

    sf.ui.proTools.appActivateMainWindow();
    
    sf.ui.proTools.appActivateMainWindow();
    
    function getFirstFreeInsertIndex() {
        var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
        let insertArray = [2, 3, 4, 5, 6, 7, 8, 9, 1, 0];
        for (let i = 0; i < insertArray.length; i++)
    
            if (btns[insertArray[i]].value.invalidate().value === "unassigned") return (insertArray[i]);
    
        throw 0;
    }
    
    sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
        insertOrSend: "Insert",
        pluginNumber: getFirstFreeInsertIndex() + 1,
        pluginSelector: items => items.filter(item => item.path[0] === "plug-in" && item.path.slice(-1)[0] === "Scheps Omni Channel (mono)")[0], 
    }, function (notMonoTrack) {
        sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
            insertOrSend: "Insert",
            pluginNumber: getFirstFreeInsertIndex() + 1,
            pluginSelector: items => items.filter(item => item.path[0] === "multichannel plug-in" && item.path.slice(-1)[0] === "Scheps Omni Channel (stereo)")[0],
        
        })
    });
    
    Solved in post #2, click to view
    • 18 replies
    1. Two things.
      Since the pluginSelector gives you access to all items, there's no need for wildcards as you can do whatever filtering you like (it's much more flexible than wildcards), so you don't need 2 calls - something like this should be enough:

      sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
          insertOrSend: "Insert",
          pluginNumber: getFirstFreeInsertIndex() + 1,
          pluginSelector: items => items.filter(item => item.path[0] === ("plug-in" || "multichannel plug-in") && item.path.slice(-1)[0].indexOf("Scheps Omni Channel (") === 0)[0],
      });
      

      2nd - I understand that if you have thousands of plugins this process might be slower since it fetches all menu items.
      I don't think it would help much to cache this since it would need to cache for each individual track and with caching comes all the complexity of making sure to invalidate the cache at the right times.
      Instead let's create a function specifically for your purpose of trying a couple of different menu paths... This should be the fastest possible option:

      sf.ui.proTools.appActivateMainWindow();
      
      function getFirstFreeInsertIndex() {
          var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
          let insertArray = [2, 3, 4, 5, 6, 7, 8, 9, 1, 0];
          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 addSchepsOmniChannel() {
          var popupMenu = sf.ui.proTools.selectedTrack.trackInsertOrSendOpenMenu({
              insertOrSend: 'Insert',
              pluginNumber: getFirstFreeInsertIndex() + 1,
          }).popupMenu;
      
          clickPopupMenu(popupMenu, [
              ["plug-in", "EQ", "Scheps Omni Channel (mono)"],
              ["multichannel plug-in", "EQ", "Scheps Omni Channel (stereo)"],
          ]);
      }
      
      addSchepsOmniChannel();
      
      Reply1 LikeSolution
      1. Andrew Scheps @Andrew_Scheps
          2020-03-11 19:46:04.267Z

          This is awesome Christian, thanks. I'm really starting to think I need to take a general Javascript programming course. I had no idea you could have multiple parameters for these functions.

          1. In reply tochrscheuer:
            Andrew Scheps @Andrew_Scheps
              2020-03-12 15:00:37.876Z

              I couldn't get your first version working for some reason but the second is great.

              1. In reply tochrscheuer:
                Andrew Scheps @Andrew_Scheps
                  2020-03-14 13:31:26.672Z

                  I've been thinking about this and there's no way to cache the insert menu contents to have it available for scripts? Technically it can't change without re-launching Pro Tools, and the only variations are the channel widths. I'm sure I'm missing something.

                  1. What would you hope to obtain by caching? The last implementation of the script would not benefit significantly from caching IMO since it's already likely to be as fast as it can get.

                    1. Andrew Scheps @Andrew_Scheps
                        2020-03-15 11:35:58.967Z

                        Every time I run the script there's a delay before the searchable list comes up, whereas Pro Tool's built in search is instantaneous because it's cached when Pro Tools launches. I don't know if it's possible to have something persistent like that or not, and once Pro Tools fixes the menu bug so that type ahead search works with accessibility then this will be moot I suppose.

                        1. Hi Andrew.

                          I'm wondering if this is related to SoundFlow or not? Ie. is the delay caused simply because PT needs to generate the full menu (which would be quicker with the dark menus since they're rendered on-demand)?
                          Can you show me a screen recording of the issue so I can better understand?
                          SoundFlow's ask for Pro Tools to run a couple of menu items should not cause any delay of itself, so my guess based on your description is that the issue really is that the legacy system menus (light grey) are simply slower to show.

                          1. Andrew Scheps @Andrew_Scheps
                              2020-03-15 21:20:13.077Z

                              I’ll do a screen capture for you, I’m conflating two things and not explaining myself very well. I can see I’ve been confusing!

                              On the script in this thread there is a short delay but not long enough to be an issue. The long delay is in a script that uses the same function to find the available insert slot and then lets you search for a plugin. It’s bringing up the SoundFlow search dialog that takes a few seconds every time run the script. As soon as I’m in front of the computer I’ll give you the specifics.

                              1. Andrew Scheps @Andrew_Scheps
                                  2020-03-16 09:56:51.557Z

                                  Ok, I've just run the script on a fresh boot and it actually goes quite quickly. Maybe there's a memory leak or something like that that makes it slow down over time. I'll keep an eye on it and if it slows down today I'll do a new bug report.

                                  1. Thanks Andrew. Make sure to grab a screen record when/if it happens so I'm 100% sure I understand what's going on.

                                    1. Andrew Scheps @Andrew_Scheps
                                        2020-03-18 15:43:17.311Z

                                        Here you go. This is one of the longer delays but it's been worse (and better).

                                        https://www.dropbox.com/s/rm9tw9o1e0exmj4/Plugin%20Search%20delay.mov?dl=0
                                        

                                        (Formatting the link because otherwise it seems to break it)

                                        1. Aaaah... I didn't understand that you were talking about SoundFlow's search functionality. I thought you were still talking about the scripts that interact directly (without the popup search window).
                                          Yes this content could be cached. Perhaps that's a good thing to take to a new thread - ie. how to cache the contents of the insert search popup.

                                          1. In reply toAndrew_Scheps:
                                            Kitch Membery @Kitch2020-08-14 22:47:51.534Z

                                            Hi Andrew... For future http links try this :-)

                                            <a href="https://www.dropbox.com/s/rm9tw9o1e0exmj4/Plugin%20Search%20delay.mov?dl=0">Here is a link to the video</a>
                                            

                                            That will show this;

                                            Here is a link to the video

                            • In reply tochrscheuer:
                              Brandon Metcalf @Brandon_Metcalf
                                2020-07-22 00:06:03.134Z

                                Brilliant. I'm using this as a starting point to create a couple quick-load triggers for frequently used plugins. Quick question - anytime I trigger this, the first insert slot a plugin will load to is slot C, even if there are not any inserts currently on the track. Is that how this script is intended to work? I'm a big time beginner at all this so forgive any silly questions! Having so much fun learning to hack my way to a more enjoyable Pro Tools experience w Soundflow!

                                1. Andrew Scheps @Andrew_Scheps
                                    2020-07-22 00:09:23.867Z

                                    This line:

                                    let insertArray = [2, 3, 4, 5, 6, 7, 8, 9, 1, 0];
                                    

                                    is what determines the plugin slot priority. Remember they start at 0, not 1. I do this so I can still have a couple of slots before the plugin I'm inserting. Basically change the order of the numbers to change your slot priority.

                                    1. Brandon Metcalf @Brandon_Metcalf
                                        2020-07-22 00:25:56.163Z

                                        Got it!

                                        How cool that a mixing legend has the time to jump in and help, with a lightning fast response no less. Thank you for sharing your knowledge and experience with all of us, Andrew. It's inspiring. Also - your melodyne helper package is absolutely brilliant. I can't even imagine how many hours that script alone will save me every month.

                                        1. Andrew Scheps @Andrew_Scheps
                                            2020-07-22 10:18:23.184Z

                                            Thanks for the kind words! It's a great community

                                      • In reply tochrscheuer:
                                        DDidier Bergeron @didierbergeron
                                          2020-08-14 19:25:27.214Z

                                          This is exactly what I was looking for.
                                          Combine with my new Stream Deck, my workflow will be unbelievably faster
                                          Thank you so much