Browse Source

Made KnownPluginList::addToMenu() and ::getIndexChosenByMenu() operate on a copy of the PluginDescription array so they are in sync

tags/2021-05-28
ed 6 years ago
parent
commit
c88611e5c8
4 changed files with 44 additions and 23 deletions
  1. +5
    -4
      extras/AudioPluginHost/Source/UI/MainHostWindow.cpp
  2. +2
    -1
      extras/AudioPluginHost/Source/UI/MainHostWindow.h
  3. +24
    -11
      modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp
  4. +13
    -7
      modules/juce_audio_processors/scanning/juce_KnownPluginList.h

+ 5
- 4
extras/AudioPluginHost/Source/UI/MainHostWindow.cpp View File

@@ -346,7 +346,7 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/
} }
else else
{ {
if (knownPluginList.getIndexChosenByMenu (menuItemID) >= 0)
if (KnownPluginList::getIndexChosenByMenu (pluginDescriptions, menuItemID) >= 0)
createPlugin (getChosenType (menuItemID), { proportionOfWidth (0.3f + Random::getSystemRandom().nextFloat() * 0.6f), createPlugin (getChosenType (menuItemID), { proportionOfWidth (0.3f + Random::getSystemRandom().nextFloat() * 0.6f),
proportionOfHeight (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); graphHolder->createNewPlugin (desc, pos);
} }
void MainHostWindow::addPluginsToMenu (PopupMenu& m) const
void MainHostWindow::addPluginsToMenu (PopupMenu& m)
{ {
if (graphHolder != nullptr) if (graphHolder != nullptr)
{ {
@@ -377,7 +377,8 @@ void MainHostWindow::addPluginsToMenu (PopupMenu& m) const
m.addSeparator(); m.addSeparator();
knownPluginList.addToMenu (m, pluginSortMethod);
pluginDescriptions = knownPluginList.getTypes();
KnownPluginList::addToMenu (m, pluginDescriptions, pluginSortMethod);
} }
PluginDescription MainHostWindow::getChosenType (const int menuID) const 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()) if (menuID >= 1 && menuID < 1 + internalTypes.size())
return internalTypes [menuID - 1]; return internalTypes [menuID - 1];
return knownPluginList.getTypes()[knownPluginList.getIndexChosenByMenu (menuID)];
return pluginDescriptions[KnownPluginList::getIndexChosenByMenu (pluginDescriptions, menuID)];
} }
//============================================================================== //==============================================================================


+ 2
- 1
extras/AudioPluginHost/Source/UI/MainHostWindow.h View File

@@ -86,7 +86,7 @@ public:
void createPlugin (const PluginDescription&, Point<int> pos); void createPlugin (const PluginDescription&, Point<int> pos);
void addPluginsToMenu (PopupMenu&) const;
void addPluginsToMenu (PopupMenu&);
PluginDescription getChosenType (int menuID) const; PluginDescription getChosenType (int menuID) const;
bool isDoublePrecisionProcessing(); bool isDoublePrecisionProcessing();
@@ -102,6 +102,7 @@ private:
Array<PluginDescription> internalTypes; Array<PluginDescription> internalTypes;
KnownPluginList knownPluginList; KnownPluginList knownPluginList;
KnownPluginList::SortMethod pluginSortMethod; KnownPluginList::SortMethod pluginSortMethod;
Array<PluginDescription> pluginDescriptions;
class PluginListWindow; class PluginListWindow;
std::unique_ptr<PluginListWindow> pluginListWindow; std::unique_ptr<PluginListWindow> pluginListWindow;


+ 24
- 11
modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp View File

@@ -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; Array<PluginDescription> sorted;
{
ScopedLock lock (typesArrayLock);
sorted.addArray (types);
}
sorted.addArray (types);
std::stable_sort (sorted.begin(), sorted.end(), PluginSorter (sortMethod, true)); 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); 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; return isPositiveAndBelow (i, types.size()) ? i : -1;
} }
@@ -611,4 +607,21 @@ bool KnownPluginList::CustomScanner::shouldExit() const noexcept
return false; 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 } // namespace juce

+ 13
- 7
modules/juce_audio_processors/scanning/juce_KnownPluginList.h View File

@@ -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, Depending on the sort method, it may add sub-menus for categories,
manufacturers, etc. manufacturers, etc.
Use getIndexChosenByMenu() to find out the type that was chosen. 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. Returns -1 if it's not an ID that was used.
@see addToMenu @see addToMenu
*/ */
int getIndexChosenByMenu (int menuResultCode) const;
static int getIndexChosenByMenu (const Array<PluginDescription>& types, int menuResultCode);
//============================================================================== //==============================================================================
/** Sorts the list. */ /** Sorts the list. */
@@ -173,8 +173,8 @@ public:
Array<PluginDescription> plugins; 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 */ /** 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** end() noexcept, { jassertfalse; return nullptr; })
JUCE_DEPRECATED_WITH_BODY (PluginDescription* const* end() const 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: private:
//============================================================================== //==============================================================================
Array<PluginDescription> types; Array<PluginDescription> types;


Loading…
Cancel
Save