| @@ -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<int> 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)]; | |||
| } | |||
| //============================================================================== | |||
| @@ -86,7 +86,7 @@ public: | |||
| void createPlugin (const PluginDescription&, Point<int> pos); | |||
| void addPluginsToMenu (PopupMenu&) const; | |||
| void addPluginsToMenu (PopupMenu&); | |||
| PluginDescription getChosenType (int menuID) const; | |||
| bool isDoublePrecisionProcessing(); | |||
| @@ -102,6 +102,7 @@ private: | |||
| Array<PluginDescription> internalTypes; | |||
| KnownPluginList knownPluginList; | |||
| KnownPluginList::SortMethod pluginSortMethod; | |||
| Array<PluginDescription> pluginDescriptions; | |||
| class PluginListWindow; | |||
| std::unique_ptr<PluginListWindow> pluginListWindow; | |||
| @@ -553,14 +553,10 @@ struct PluginTreeUtils | |||
| } | |||
| }; | |||
| std::unique_ptr<KnownPluginList::PluginTree> KnownPluginList::createTree (const SortMethod sortMethod) const | |||
| std::unique_ptr<KnownPluginList::PluginTree> KnownPluginList::createTree (const Array<PluginDescription>& types, SortMethod sortMethod) | |||
| { | |||
| Array<PluginDescription> 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::PluginTree> KnownPluginList::createTree (const | |||
| } | |||
| //============================================================================== | |||
| void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod, | |||
| const String& currentlyTickedPluginID) const | |||
| void KnownPluginList::addToMenu (PopupMenu& menu, const Array<PluginDescription>& 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<PluginDescription>& 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::PluginTree> KnownPluginList::createTree (const SortMethod sortMethod) const | |||
| { | |||
| return createTree (getTypes(), sortMethod); | |||
| } | |||
| } // namespace juce | |||
| @@ -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<PluginDescription>& 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<PluginDescription>& types, int menuResultCode); | |||
| //============================================================================== | |||
| /** Sorts the list. */ | |||
| @@ -173,8 +173,8 @@ public: | |||
| Array<PluginDescription> plugins; | |||
| }; | |||
| /** Creates a PluginTree object containing all the known plugins. */ | |||
| std::unique_ptr<PluginTree> createTree (const SortMethod sortMethod) const; | |||
| /** Creates a PluginTree object representing the list of plug-ins. */ | |||
| static std::unique_ptr<PluginTree> createTree (const Array<PluginDescription>& 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<PluginTree> createTree (const SortMethod sortMethod) const); | |||
| private: | |||
| //============================================================================== | |||
| Array<PluginDescription> types; | |||