Fix: Scan on button click in background thread, show menu when done — no more crash
Browse files- Source/PluginBridgeEditor.cpp +54 -25
Source/PluginBridgeEditor.cpp
CHANGED
|
@@ -40,19 +40,12 @@ PluginBridgeEditor::PluginBridgeEditor(PluginBridgeProcessor& p)
|
|
| 40 |
pluginLabel.setColour(juce::Label::textColourId, juce::Colour(0xffaaaaaa));
|
| 41 |
addAndMakeVisible(pluginLabel);
|
| 42 |
|
| 43 |
-
// Plugin selector button
|
| 44 |
-
pluginButton.onClick = [this]() {
|
| 45 |
pluginButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xff2d2d44));
|
| 46 |
pluginButton.setColour(juce::TextButton::textColourOffId, juce::Colours::white);
|
| 47 |
addAndMakeVisible(pluginButton);
|
| 48 |
|
| 49 |
-
// Scan plugins on first open
|
| 50 |
-
if (!hasScanned)
|
| 51 |
-
{
|
| 52 |
-
hasScanned = true;
|
| 53 |
-
scanPlugins();
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
startTimerHz(2);
|
| 57 |
}
|
| 58 |
|
|
@@ -113,26 +106,54 @@ void PluginBridgeEditor::timerCallback()
|
|
| 113 |
}
|
| 114 |
}
|
| 115 |
|
| 116 |
-
void PluginBridgeEditor::
|
| 117 |
{
|
| 118 |
-
|
|
|
|
| 119 |
{
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
juce::PluginDirectoryScanner scanner(
|
| 124 |
-
knownPlugins,
|
| 125 |
-
*format,
|
| 126 |
-
searchPaths,
|
| 127 |
-
true,
|
| 128 |
-
juce::File()
|
| 129 |
-
);
|
| 130 |
-
|
| 131 |
-
juce::String pluginName;
|
| 132 |
-
while (scanner.scanNextFile(false, pluginName)) {}
|
| 133 |
}
|
| 134 |
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
}
|
| 137 |
|
| 138 |
void PluginBridgeEditor::showPluginMenu()
|
|
@@ -140,6 +161,14 @@ void PluginBridgeEditor::showPluginMenu()
|
|
| 140 |
juce::PopupMenu menu;
|
| 141 |
auto types = knownPlugins.getTypes();
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
// Group by manufacturer as submenus
|
| 144 |
juce::StringArray manufacturers;
|
| 145 |
for (const auto& desc : types)
|
|
|
|
| 40 |
pluginLabel.setColour(juce::Label::textColourId, juce::Colour(0xffaaaaaa));
|
| 41 |
addAndMakeVisible(pluginLabel);
|
| 42 |
|
| 43 |
+
// Plugin selector button
|
| 44 |
+
pluginButton.onClick = [this]() { scanAndShowMenu(); };
|
| 45 |
pluginButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xff2d2d44));
|
| 46 |
pluginButton.setColour(juce::TextButton::textColourOffId, juce::Colours::white);
|
| 47 |
addAndMakeVisible(pluginButton);
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
startTimerHz(2);
|
| 50 |
}
|
| 51 |
|
|
|
|
| 106 |
}
|
| 107 |
}
|
| 108 |
|
| 109 |
+
void PluginBridgeEditor::scanAndShowMenu()
|
| 110 |
{
|
| 111 |
+
// If already scanned, just show menu immediately
|
| 112 |
+
if (scanComplete)
|
| 113 |
{
|
| 114 |
+
showPluginMenu();
|
| 115 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
}
|
| 117 |
|
| 118 |
+
// If currently scanning, ignore click
|
| 119 |
+
if (scanning)
|
| 120 |
+
return;
|
| 121 |
+
|
| 122 |
+
// Scan in background thread
|
| 123 |
+
scanning = true;
|
| 124 |
+
pluginButton.setButtonText("Scanning...");
|
| 125 |
+
pluginButton.setEnabled(false);
|
| 126 |
+
|
| 127 |
+
auto* thisPtr = this;
|
| 128 |
+
std::thread([thisPtr]()
|
| 129 |
+
{
|
| 130 |
+
for (int i = 0; i < thisPtr->scanFormatManager.getNumFormats(); ++i)
|
| 131 |
+
{
|
| 132 |
+
auto* format = thisPtr->scanFormatManager.getFormat(i);
|
| 133 |
+
auto searchPaths = format->getDefaultLocationsToSearch();
|
| 134 |
+
|
| 135 |
+
juce::PluginDirectoryScanner scanner(
|
| 136 |
+
thisPtr->knownPlugins,
|
| 137 |
+
*format,
|
| 138 |
+
searchPaths,
|
| 139 |
+
true,
|
| 140 |
+
juce::File()
|
| 141 |
+
);
|
| 142 |
+
|
| 143 |
+
juce::String pluginName;
|
| 144 |
+
while (scanner.scanNextFile(false, pluginName)) {}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
// Back to message thread to show menu
|
| 148 |
+
juce::MessageManager::callAsync([thisPtr]()
|
| 149 |
+
{
|
| 150 |
+
thisPtr->scanning = false;
|
| 151 |
+
thisPtr->scanComplete = true;
|
| 152 |
+
thisPtr->pluginButton.setEnabled(true);
|
| 153 |
+
thisPtr->pluginButton.setButtonText("Select Plugin...");
|
| 154 |
+
thisPtr->showPluginMenu();
|
| 155 |
+
});
|
| 156 |
+
}).detach();
|
| 157 |
}
|
| 158 |
|
| 159 |
void PluginBridgeEditor::showPluginMenu()
|
|
|
|
| 161 |
juce::PopupMenu menu;
|
| 162 |
auto types = knownPlugins.getTypes();
|
| 163 |
|
| 164 |
+
if (types.isEmpty())
|
| 165 |
+
{
|
| 166 |
+
menu.addItem(-1, "(No plugins found)", false);
|
| 167 |
+
menu.showMenuAsync(juce::PopupMenu::Options().withTargetComponent(&pluginButton),
|
| 168 |
+
[](int) {});
|
| 169 |
+
return;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
// Group by manufacturer as submenus
|
| 173 |
juce::StringArray manufacturers;
|
| 174 |
for (const auto& desc : types)
|