Fix crash: Editor is thin — no threads, no scan ownership, just reads Processor state
Browse files4 unmodified lines56789101112131415168910111213231415161718291920212223243625262728293043443132333435493637383923 unmodified lines636465666768698 unmodified lines787980818283846 unmodified lines91929394105959697989910010110210310410510610710810910911011111111211211311411511511611711811912012112212312412512612712811711813013113213313413513613713813914014114214314414514614714814915015115215315415515611912012112212312412512616116212712812913013113213313413513613717213813914014114223 unmodified lines1661671682021691701711724 unmodified lines{ setSize(360, 220);
// Register formats for scanning #if JUCE_PLUGINHOST_VST3 scanFormatManager.addFormat(new juce::VST3PluginFormat()); #endif #if JUCE_PLUGINHOST_AU scanFormatManager.addFormat(new juce::AudioUnitPluginFormat()); #endif
// Title titleLabel.setText("PluginBridge", juce::dontSendNotification); titleLabel.setFont(juce::FontOptions(22.0f)); titleLabel.setJustificationType(juce::Justification::centred); titleLabel.setColour(juce::Label::textColourId, juce::Colours::white); addAndMakeVisible(titleLabel);
// MCP status statusLabel.setText("MCP: starting...", juce::dontSendNotification); statusLabel.setFont(juce::FontOptions(12.0f)); statusLabel.setJustificationType(juce::Justification::centred); addAndMakeVisible(statusLabel);
// Port portLabel.setText("", juce::dontSendNotification); portLabel.setFont(juce::FontOptions(10.0f)); portLabel.setJustificationType(juce::Justification::centred); portLabel.setColour(juce::Label::textColourId, juce::Colour(0xff888888)); addAndMakeVisible(portLabel);
// Plugin name display pluginLabel.setText("No plugin loaded", juce::dontSendNotification); pluginLabel.setFont(juce::FontOptions(13.0f)); pluginLabel.setJustificationType(juce::Justification::centred); pluginLabel.setColour(juce::Label::textColourId, juce::Colour(0xffaaaaaa)); addAndMakeVisible(pluginLabel);
// Plugin selector button pluginButton.onClick = [this]() { scanAndShowMenu(); }; pluginButton.onClick = [this]() { pluginButtonClicked(); }; pluginButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xff2d2d44)); pluginButton.setColour(juce::TextButton::textColourOffId, juce::Colours::white); addAndMakeVisible(pluginButton);
startTimerHz(2); startTimerHz(4);}
PluginBridgeEditor::~PluginBridgeEditor()23 unmodified lines
void PluginBridgeEditor::timerCallback(){ // MCP status if (processorRef.isMcpServerRunning()) { statusLabel.setText("MCP: running", juce::dontSendNotification);8 unmodified lines portLabel.setText("", juce::dontSendNotification); }
// Plugin status auto& mgr = processorRef.getHostedPluginManager(); if (mgr.isLoaded()) {6 unmodified lines { pluginLabel.setText("No plugin loaded", juce::dontSendNotification); pluginLabel.setColour(juce::Label::textColourId, juce::Colour(0xff888888)); if (!processorRef.isScanning()) pluginButton.setButtonText("Select Plugin..."); pluginButton.setButtonText("Select Plugin..."); }
// Update button during scan if (processorRef.isScanning()) { pluginButton.setButtonText("Scanning..."); pluginButton.setEnabled(false); } else { pluginButton.setEnabled(true); }}
void PluginBridgeEditor::scanAndShowMenu()void PluginBridgeEditor::pluginButtonClicked(){ // If already scanned, just show menu immediately if (scanComplete) if (processorRef.isScanComplete()) { // Scan done — show menu immediately showPluginMenu(); return; }
// If currently scanning, ignore click if (scanning) return;
// Scan in background thread scanning = true; pluginButton.setButtonText("Scanning..."); pluginButton.setEnabled(false);
auto* thisPtr = this; std::thread([thisPtr]() else if (!processorRef.isScanning()) { for (int i = 0; i < thisPtr->scanFormatManager.getNumFormats(); ++i) { auto* format = thisPtr->scanFormatManager.getFormat(i); auto searchPaths = format->getDefaultLocationsToSearch();
juce::PluginDirectoryScanner scanner( thisPtr->knownPlugins, *format, searchPaths, true, juce::File() );
juce::String pluginName; while (scanner.scanNextFile(false, pluginName)) {} }
// Back to message thread to show menu juce::MessageManager::callAsync([thisPtr]() { thisPtr->scanning = false; thisPtr->scanComplete = true; thisPtr->pluginButton.setEnabled(true); thisPtr->pluginButton.setButtonText("Select Plugin..."); thisPtr->showPluginMenu(); }); }).detach(); // Start scan (owned by Processor — safe even if editor closes) processorRef.startPluginScan(); // Timer will update button text to "Scanning..." and show menu when done }}
void PluginBridgeEditor::showPluginMenu(){ juce::PopupMenu menu; auto types = knownPlugins.getTypes(); const auto& types = processorRef.getScannedPlugins();
if (types.isEmpty()) { juce::PopupMenu menu; menu.addItem(-1, "(No plugins found)", false); menu.showMenuAsync(juce::PopupMenu::Options().withTargetComponent(&pluginButton), [](int) {}); return; }
// Group by manufacturer as submenus // Group by manufacturer juce::PopupMenu menu; juce::StringArray manufacturers; for (const auto& desc : types) {23 unmodified lines
void PluginBridgeEditor::loadPluginByIndex(int index){ auto types = knownPlugins.getTypes(); const auto& types = processorRef.getScannedPlugins(); if (index >= 0 && index < types.size()) { const auto& desc = types[index];Source/PluginBridgeEditor.cpp+30-63