No internet connection
  1. Home
  2. How to

Check playback engine then execute script

By danielkassulke @danielkassulke
    2023-08-02 23:57:43.397Z

    Hey all. Here's an excerpt of a script that allows me to set my system to "Mix Mode", with highest buffer size and the correct playback engine for mixing.

    const pbEngineWin = pt.windows.whoseTitle.is("Playback Engine").first;
    const firstPopupBtn = pbEngineWin.popupButtons;
    
    pt.appActivateMainWindow();
    
    // Open and wait for playback engine dialogue to appear
    pt.menuClick({ menuPath: ["Setup","Playback Engine..."], });
    pbEngineWin.elementWaitFor({ waitType: "Appear", });
    
    // Select 64 samples
    firstPopupBtn.allItems[1].popupMenuSelect({ menuPath: ["1024 Samples"], });
    // CHANGE THIS AFTER TESTING
    firstPopupBtn.first.popupMenuSelect({ menuPath: ["Pro Tools Aggregate I/O"], });
    
    pt.confirmationDialog.elementWaitFor({
        waitType: "Appear",
    });
    
    pt.confirmationDialog.buttons.whoseTitle.is("Yes").first.elementClick();
    
    pt.confirmationDialog.elementWaitFor({
        waitType: "Disappear",
    });
    
    // Clicking the OK button
    pbEngineWin.buttons.whoseTitle.is("OK").first.elementClick();
    
    // Wait for the Playback Engine window to disappear after clicking OK
    pbEngineWin.elementWaitFor({ waitType: "Disappear", });
    
    pt.waitForNoModals();
    

    The issue I have is that the playback engine confirmation dialog only appears if the playback engine is being swapped, so if the playback engine is already set correctly (and therefore the buffer size is all that needs to be modified), the script fails because it won't see any confirmation dialog appear. I am curious to know if there is a way to assess the current playback engine in the background without menu diving. If I could avoid scraping that info from the popup element, I could happily proceed with an if/else statement. Is this possible?

    Solved in post #4, click to view
    • 9 replies
    1. S
      SoundFlow Bot @soundflowbot
        2023-08-02 23:57:44.646Z

        Thanks for contacting SoundFlow support.

        Please note, that the best way to get help with a script, macro or other content installed from the Store or content that you've made yourself, is to select the script/macro, then click the red Need help button, and then click "Get help with this script or macro".
        By using this method, we will get access to more information and so should be able to help you quicker.
        You can read more about how this works here: bit.ly/sfscripthelp

        If you're seeing an error that isn't related to scripts or macros, and you think this is a bug in SoundFlow, please file a Help/Issue bug report.
        You can see how to do this by going to bit.ly/sfhelpissue

        1. In reply todanielkassulke:
          Kitch Membery @Kitch2023-08-03 00:33:31.501Z

          Hi @danielkassulke,

          So I can understand your question more, what value(s) are you trying to retrieve without opening the Playback Engine window?

          You can avoid changing the popup menu values if they are already set correctly, but that would still require the Playback Engine Window to be open.

          You can get the Current values for the Playback Engine and the Buffer Size like this

          // Current Playback Engine Name
          log(sf.ui.proTools.windows.whoseTitle.is("Playback Engine").first.popupButtons.first.value.invalidate().value);
          
          // Current Hardware Buffer Size
          log(sf.ui.proTools.windows.whoseTitle.is("Playback Engine").first.popupButtons.allItems[1].value.invalidate().value);
          

          This should allow you to make an if/else statement based on the current Popup menu state.

          SoundFlow is designed (in most cases) to be able to read information that is accessible which requires that UI elements are visible.

          On a side note, for future Script or Macro help please use the script help workflow. See here for more info on how to do that. bit.ly/sfscripthelp :-)

          1. Ddanielkassulke @danielkassulke
              2023-08-03 00:54:38.919Z2023-08-03 01:02:13.917Z

              Hi @Kitch ,

              Thanks for your lightning-fast response. I didn't find any way to achieve it after searching, but ultimately I was wondering if there was something similar to this // Get session sample rate const currentSampleRate = sf.app.proTools.getSessionSampleRate().sampleRate; that would be able to fetch the current session's playback device. Noted re: script help too, by the way. Always assumed with snippets like this it was OK to post directly to the forum, but will make sure I am submitting them all within SF in future.

              1. Kitch Membery @Kitch2023-08-03 01:35:37.192Z

                No worries, Daniel,

                Yes, you can always post directly in the forum but be sure to post in the "How to" or "Macro & Script Help" sections rather than the "Support" section as it's more for broad technical difficulties and bugs. :-)

                Unfortunately, there is no way AFAIK to get the Playback Engine information through sf.app.proTools. I would love it if that was the case.

                Rock on!

            • In reply todanielkassulke:

              @danielkassulke , haven't tested this but if you replace Line 12-23 with the following, it should skip setting the Playback Engine if it's already set to the Pro Tools Aggregate I/O. Give it a shot!

              if (firstPopupBtn.first.value.value !== "Pro Tools Aggregate I/O") {
                  firstPopupBtn.first.popupMenuSelect({ menuPath: ["Pro Tools Aggregate I/O"], });
              
                  pt.confirmationDialog.elementWaitFor({
                      waitType: "Appear",
                  });
              
                  pt.confirmationDialog.buttons.whoseTitle.is("Yes").first.elementClick();
              
                  pt.confirmationDialog.elementWaitFor({
                      waitType: "Disappear",
                  });
              }
              
              Reply1 LikeSolution
              1. Ah, posted at the same time as @Kitch 🤦🏻‍♂️ lol

                1. Kitch Membery @Kitch2023-08-03 00:40:45.951Z

                  Your answer was better @raphaelsepulveda :-)

                2. Ddanielkassulke @danielkassulke
                    2023-08-03 01:00:59.132Z

                    Thanks so much, Raphael - this worked a charm. Just to allow me to understand this a little better, is the second value within firstPopupBtn.first.value.value referring to the currently selected value within that popup?

                    1. This threw me off a bit too when I first learned about it.

                      firstPopupBtn.first.value is a reference to the currently selected value, but if you log it—log(firstPopupBtn.first.value)—you'll see that it's actually an object that contains more information than just the value:

                      {
                          "Value": "Pro Tools Aggregate I/O",
                          "IntValue": 0,
                          "DoubleValue": 0,
                          "Name": "AXValue",
                          "Parent": "{\"title\":\"Pro Tools Aggregate I/O\",\"role\":\"AXPopUpButton\",\"fullRole\":\"AXPopUpButton\"}",
                          "FriendlyNodeName": "AxStringOrIntProperty",
                          "SupportsAutoUpdate": false
                      }
                      

                      As you can see, there's another property in there called "Value" which has the data we're looking for.

                      To access it we just add another .value.

                      Alternatively, you can also access it like this firstPopupBtn.first.value["Value"]—but you will never see anyone doing that here lol

                      Hopefully, that makes sense!