Fix crash: Editor is thin — no threads, no scan ownership, just reads Processor state
Browse files4 unmodified lines567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515223 unmodified lines7677787980818 unmodified lines9091929394956 unmodified lines10210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417523 unmodified lines1992002012022032042054 unmodified lines{setSize(360, 220);// Register formats for scanning#if JUCE_PLUGINHOST_VST3scanFormatManager.addFormat(new juce::VST3PluginFormat());#endif#if JUCE_PLUGINHOST_AUscanFormatManager.addFormat(new juce::AudioUnitPluginFormat());#endif// TitletitleLabel.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 statusstatusLabel.setText("MCP: starting...", juce::dontSendNotification);statusLabel.setFont(juce::FontOptions(12.0f));statusLabel.setJustificationType(juce::Justification::centred);addAndMakeVisible(statusLabel);// PortportLabel.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 displaypluginLabel.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 buttonpluginButton.onClick = [this]() { scanAndShowMenu(); };pluginButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xff2d2d44));pluginButton.setColour(juce::TextButton::textColourOffId, juce::Colours::white);addAndMakeVisible(pluginButton);startTimerHz(2);}PluginBridgeEditor::~PluginBridgeEditor()23 unmodified linesvoid PluginBridgeEditor::timerCallback(){if (processorRef.isMcpServerRunning()){statusLabel.setText("MCP: running", juce::dontSendNotification);8 unmodified linesportLabel.setText("", juce::dontSendNotification);}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));pluginButton.setButtonText("Select Plugin...");}}void PluginBridgeEditor::scanAndShowMenu(){// If already scanned, just show menu immediatelyif (scanComplete){showPluginMenu();return;}// If currently scanning, ignore clickif (scanning)return;// Scan in background threadscanning = true;pluginButton.setButtonText("Scanning...");pluginButton.setEnabled(false);auto* thisPtr = this;std::thread([thisPtr](){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 menujuce::MessageManager::callAsync([thisPtr](){thisPtr->scanning = false;thisPtr->scanComplete = true;thisPtr->pluginButton.setEnabled(true);thisPtr->pluginButton.setButtonText("Select Plugin...");thisPtr->showPluginMenu();});}).detach();}void PluginBridgeEditor::showPluginMenu(){juce::PopupMenu menu;auto types = knownPlugins.getTypes();if (types.isEmpty()){menu.addItem(-1, "(No plugins found)", false);menu.showMenuAsync(juce::PopupMenu::Options().withTargetComponent(&pluginButton),[](int) {});return;}// Group by manufacturer as submenusjuce::StringArray manufacturers;for (const auto& desc : types){23 unmodified linesvoid PluginBridgeEditor::loadPluginByIndex(int index){auto types = knownPlugins.getTypes();if (index >= 0 && index < types.size()){const auto& desc = types[index];4 unmodified lines5678910111213141516171819202122232425262728293031323334353637383923 unmodified lines636465666768698 unmodified lines787980818283846 unmodified lines91929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114223 unmodified lines1661671681691701711724 unmodified lines{setSize(360, 220);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);statusLabel.setText("MCP: starting...", juce::dontSendNotification);statusLabel.setFont(juce::FontOptions(12.0f));statusLabel.setJustificationType(juce::Justification::centred);addAndMakeVisible(statusLabel);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);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);pluginButton.onClick = [this]() { pluginButtonClicked(); };pluginButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xff2d2d44));pluginButton.setColour(juce::TextButton::textColourOffId, juce::Colours::white);addAndMakeVisible(pluginButton);startTimerHz(4);}PluginBridgeEditor::~PluginBridgeEditor()23 unmodified linesvoid PluginBridgeEditor::timerCallback(){// MCP statusif (processorRef.isMcpServerRunning()){statusLabel.setText("MCP: running", juce::dontSendNotification);8 unmodified linesportLabel.setText("", juce::dontSendNotification);}// Plugin statusauto& 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...");}// Update button during scanif (processorRef.isScanning()){pluginButton.setButtonText("Scanning...");pluginButton.setEnabled(false);}else{pluginButton.setEnabled(true);}}void PluginBridgeEditor::pluginButtonClicked(){if (processorRef.isScanComplete()){// Scan done — show menu immediatelyshowPluginMenu();}else if (!processorRef.isScanning()){// 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(){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 manufacturerjuce::PopupMenu menu;juce::StringArray manufacturers;for (const auto& desc : types){23 unmodified linesvoid PluginBridgeEditor::loadPluginByIndex(int index){const auto& types = processorRef.getScannedPlugins();if (index >= 0 && index < types.size()){const auto& desc = types[index];
Source/PluginBridgeEditor.cpp+30-63