No internet connection
  1. Home
  2. How to

Toggle Plugin Visibility (Currently Selected/Focused)

By Jordan Pascual @Jordan_Pascual
    2024-05-20 11:18:19.646Z2024-05-28 03:01:15.048Z

    Hey there!

    I know that this has been discussed somewhat prior, but every script seems to be insert number specific, as to say, the script always points to the insert number to toggle it. (Insert A, B, etc.) I was wondering if there was any way for SF to recognize the plugin that's CURRENTLY open, and then based on that, toggle the window open or closed. (The manual way to do this would be by physically clicking on the currently selected insert)

    A good example is toggling the 'Detachable Melodyne Tab' (ARA)... I have a key command set up to open and close it at my will. It would be great to do that with any plugin that I choose, and not have it 'insert specific' dependent!

    Thanks friends!

    Solved in post #4, click to view
    • 6 replies
    1. Jordan Pascual @Jordan_Pascual
        2024-05-28 01:06:39.594Z

        Bumping this again

        1. In reply toJordan_Pascual:

          This may seem like a simple task but there are a few scenarios which make it difficult to implement.
          Let say you have 2 plugin windows open. You run the script and it hides the last focused plugin. If you run the script again, what do you want to happen? - close the remaining open plugin or reopen the one that was just closed?

          If only one plugin is open and you run the script to close it, then open another plugin window and run the script again whcat should happen - reopen the last closed plugin or close the newly opened one?

          1. In reply toJordan_Pascual:
            Chris Shaw @Chris_Shaw2024-05-28 19:35:15.144Z2024-05-28 19:47:13.620Z

            That being said,
            This script will close a plugin window and open it when it is run again.
            If more than one plugin window is open it will close the last focused plugin window each time it is run. When only one plugin remains it will close the last plugin window. After that running the script again will open the last closed plugin window.

            sf.ui.proTools.appActivateMainWindow()
            
            // Get open plugin windows
            let pluginWindows = sf.ui.proTools.windows.invalidate().allItems.filter(w =>
            
                (w.title && w.title.value !== null && w.title.value.includes("Plug-in"))
            )
            let openPluginWindowsCount = pluginWindows.length;
            
            // Store and and close plugin window
            if (openPluginWindowsCount > 0) {
                if (openPluginWindowsCount == 1) {
                    // Store last open plugin insert slot and track name
                    let pluginWindow = sf.ui.proTools.windows.whoseTitle.startsWith("Plug-in: ").first
                    const trackName = pluginWindow.popupButtons.whoseTitle.is("Track Selector").first.value.invalidate().value;
                    const insertLetter = pluginWindow.popupButtons.whoseTitle.is("Insert Position selector").first.value.invalidate().value;
            
                    globalState.lastOpenPlugin = {
                        trackName,
                        insertLetter
                    }
                }
                // Close plugin window
                pluginWindows[0].windowClose()
            
            } else {
                // Re-open last pluginwindow
                const { trackName, insertLetter } = globalState.lastOpenPlugin;
                const pluginTrack = sf.ui.proTools.trackGetByName({ name: trackName }).track;
                const insertLetters = "abcdefghij";
                const insertNumber = insertLetters.indexOf(insertLetter) + 1;
            
                pluginTrack.trackInsertToggleShow({
                    insertNumber,
                });
            }
            
            ReplySolution
            1. Chris Shaw @Chris_Shaw2024-05-28 19:42:54.978Z2024-05-28 20:50:26.022Z

              One thing to keep in mind - you need to close the last open plugin window with this script which stores the the track name and plugin. Otherwise the last plugin info will not be saved.

              1. Jordan Pascual @Jordan_Pascual
                  2024-05-29 00:15:11.302Z

                  Hey Chris,

                  Thanks so much for this! This is such a great approach to this, I actually never really thought ahead of having the 'multiple plugins' on screen dilemma before, but the script seems to cover this quite well! I also just use the built in 'Hide All Floating Windows' menu option via SF if I need to close ALL of them all at once (although this, as expected, hides other windows like color palette and such)

                  I much prefer this scripts' method of hiding the plugins over the previously mentioned 'Hide All Floating Windows' option! Thanks again Chris! :)

                  1. In reply toChris_Shaw:
                    Jordan Pascual @Jordan_Pascual
                      2024-05-30 23:20:04.281Z

                      Hey @Chris_Shaw wanted to ask about another related thing...

                      The script above works awesome! Wondering if the same process could be applied to INACTIVATING the selected plugin, much in the sequential order as it is with 'closing'/toggling the active plugs. I've tried playing with the script, but I think choosing to activate/inactivate plugins behave a bit different than just toggling visibility.

                      Thanks much! :)