diff --git a/extras/AudioPluginHost/Source/UI/MainHostWindow.cpp b/extras/AudioPluginHost/Source/UI/MainHostWindow.cpp index dfd99c2fd8..201482b9cc 100644 --- a/extras/AudioPluginHost/Source/UI/MainHostWindow.cpp +++ b/extras/AudioPluginHost/Source/UI/MainHostWindow.cpp @@ -346,7 +346,7 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/ } else { - if (knownPluginList.getIndexChosenByMenu (menuItemID) >= 0) + if (KnownPluginList::getIndexChosenByMenu (pluginDescriptions, menuItemID) >= 0) createPlugin (getChosenType (menuItemID), { proportionOfWidth (0.3f + Random::getSystemRandom().nextFloat() * 0.6f), proportionOfHeight (0.3f + Random::getSystemRandom().nextFloat() * 0.6f) }); } @@ -364,7 +364,7 @@ void MainHostWindow::createPlugin (const PluginDescription& desc, Point pos graphHolder->createNewPlugin (desc, pos); } -void MainHostWindow::addPluginsToMenu (PopupMenu& m) const +void MainHostWindow::addPluginsToMenu (PopupMenu& m) { if (graphHolder != nullptr) { @@ -377,7 +377,8 @@ void MainHostWindow::addPluginsToMenu (PopupMenu& m) const m.addSeparator(); - knownPluginList.addToMenu (m, pluginSortMethod); + pluginDescriptions = knownPluginList.getTypes(); + KnownPluginList::addToMenu (m, pluginDescriptions, pluginSortMethod); } PluginDescription MainHostWindow::getChosenType (const int menuID) const @@ -385,7 +386,7 @@ PluginDescription MainHostWindow::getChosenType (const int menuID) const if (menuID >= 1 && menuID < 1 + internalTypes.size()) return internalTypes [menuID - 1]; - return knownPluginList.getTypes()[knownPluginList.getIndexChosenByMenu (menuID)]; + return pluginDescriptions[KnownPluginList::getIndexChosenByMenu (pluginDescriptions, menuID)]; } //============================================================================== diff --git a/extras/AudioPluginHost/Source/UI/MainHostWindow.h b/extras/AudioPluginHost/Source/UI/MainHostWindow.h index a0711a67e0..5860d3ac9f 100644 --- a/extras/AudioPluginHost/Source/UI/MainHostWindow.h +++ b/extras/AudioPluginHost/Source/UI/MainHostWindow.h @@ -86,7 +86,7 @@ public: void createPlugin (const PluginDescription&, Point pos); - void addPluginsToMenu (PopupMenu&) const; + void addPluginsToMenu (PopupMenu&); PluginDescription getChosenType (int menuID) const; bool isDoublePrecisionProcessing(); @@ -102,6 +102,7 @@ private: Array internalTypes; KnownPluginList knownPluginList; KnownPluginList::SortMethod pluginSortMethod; + Array pluginDescriptions; class PluginListWindow; std::unique_ptr pluginListWindow; diff --git a/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp b/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp index c5080989d1..8521c43751 100644 --- a/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp +++ b/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp @@ -553,14 +553,10 @@ struct PluginTreeUtils } }; -std::unique_ptr KnownPluginList::createTree (const SortMethod sortMethod) const +std::unique_ptr KnownPluginList::createTree (const Array& types, SortMethod sortMethod) { Array sorted; - - { - ScopedLock lock (typesArrayLock); - sorted.addArray (types); - } + sorted.addArray (types); std::stable_sort (sorted.begin(), sorted.end(), PluginSorter (sortMethod, true)); @@ -584,16 +580,16 @@ std::unique_ptr KnownPluginList::createTree (const } //============================================================================== -void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod, - const String& currentlyTickedPluginID) const +void KnownPluginList::addToMenu (PopupMenu& menu, const Array& types, SortMethod sortMethod, + const String& currentlyTickedPluginID) { - auto tree = createTree (sortMethod); + auto tree = createTree (types, sortMethod); PluginTreeUtils::addToMenu (*tree, menu, types, currentlyTickedPluginID); } -int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const +int KnownPluginList::getIndexChosenByMenu (const Array& types, int menuResultCode) { - const int i = menuResultCode - PluginTreeUtils::menuIdBase; + auto i = menuResultCode - PluginTreeUtils::menuIdBase; return isPositiveAndBelow (i, types.size()) ? i : -1; } @@ -611,4 +607,21 @@ bool KnownPluginList::CustomScanner::shouldExit() const noexcept return false; } +//============================================================================== +void KnownPluginList::addToMenu (PopupMenu& menu, SortMethod sortMethod, const String& currentlyTickedPluginID) const +{ + addToMenu (menu, getTypes(), sortMethod, currentlyTickedPluginID); +} + +int KnownPluginList::getIndexChosenByMenu (int menuResultCode) const +{ + return getIndexChosenByMenu (getTypes(), menuResultCode); +} + +std::unique_ptr KnownPluginList::createTree (const SortMethod sortMethod) const +{ + return createTree (getTypes(), sortMethod); +} + + } // namespace juce diff --git a/modules/juce_audio_processors/scanning/juce_KnownPluginList.h b/modules/juce_audio_processors/scanning/juce_KnownPluginList.h index c3022a608d..fa1f2f4186 100644 --- a/modules/juce_audio_processors/scanning/juce_KnownPluginList.h +++ b/modules/juce_audio_processors/scanning/juce_KnownPluginList.h @@ -135,21 +135,21 @@ public: }; //============================================================================== - /** Adds all the plugin types to a popup menu so that the user can select one. + /** Adds the plug-in types to a popup menu so that the user can select one. Depending on the sort method, it may add sub-menus for categories, manufacturers, etc. Use getIndexChosenByMenu() to find out the type that was chosen. */ - void addToMenu (PopupMenu& menu, SortMethod sortMethod, - const String& currentlyTickedPluginID = {}) const; + static void addToMenu (PopupMenu& menu, const Array& types, + SortMethod sortMethod, const String& currentlyTickedPluginID = {}); - /** Converts a menu item index that has been chosen into its index in this list. + /** Converts a menu item index that has been chosen into its index in the list. Returns -1 if it's not an ID that was used. @see addToMenu */ - int getIndexChosenByMenu (int menuResultCode) const; + static int getIndexChosenByMenu (const Array& types, int menuResultCode); //============================================================================== /** Sorts the list. */ @@ -173,8 +173,8 @@ public: Array plugins; }; - /** Creates a PluginTree object containing all the known plugins. */ - std::unique_ptr createTree (const SortMethod sortMethod) const; + /** Creates a PluginTree object representing the list of plug-ins. */ + static std::unique_ptr createTree (const Array& types, SortMethod sortMethod); //============================================================================== /** Class to define a custom plugin scanner */ @@ -217,6 +217,12 @@ public: JUCE_DEPRECATED_WITH_BODY (PluginDescription** end() noexcept, { jassertfalse; return nullptr; }) JUCE_DEPRECATED_WITH_BODY (PluginDescription* const* end() const noexcept, { jassertfalse; return nullptr; }) + // These methods have been deprecated in favour of their static counterparts. You should call getTypes() + // to store the plug-in list at a point in time and use it when calling these methods. + JUCE_DEPRECATED (void addToMenu (PopupMenu& menu, SortMethod sortMethod, const String& currentlyTickedPluginID = {}) const); + JUCE_DEPRECATED (int getIndexChosenByMenu (int menuResultCode) const); + JUCE_DEPRECATED (std::unique_ptr createTree (const SortMethod sortMethod) const); + private: //============================================================================== Array types;