Upload Source/Plugin/PluginBridgeEditor.cpp
Browse files6 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798995 unmodified lines10510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117218 unmodified lines1911921931941951961971981992002013 unmodified lines2052062072082092102112122132142152162172186 unmodified linesstatic const juce::Colour kTextSecondary(0xff8888aa);static const juce::Colour kGreen (0xff4cef50);static const juce::Colour kRed (0xffef5350);static const juce::Colour kYellow (0xffffeb3b);static const juce::Colour kBtnBg (0xff2a2a44);PluginBridgeEditor::PluginBridgeEditor(PluginBridgeProcessor& p): AudioProcessorEditor(&p), processorRef(p){setSize(340, 200);titleLabel.setText("PluginBridge", juce::dontSendNotification);titleLabel.setFont(juce::FontOptions(18.0f));titleLabel.setJustificationType(juce::Justification::centredLeft);titleLabel.setColour(juce::Label::textColourId, kTextPrimary);addAndMakeVisible(titleLabel);mcpStatusLabel.setFont(juce::FontOptions(11.0f));mcpStatusLabel.setJustificationType(juce::Justification::centredRight);addAndMakeVisible(mcpStatusLabel);pluginStatusLabel.setFont(juce::FontOptions(13.0f));pluginStatusLabel.setJustificationType(juce::Justification::centredLeft);pluginStatusLabel.setColour(juce::Label::textColourId, kTextSecondary);addAndMakeVisible(pluginStatusLabel);connectionLabel.setFont(juce::FontOptions(10.0f));connectionLabel.setJustificationType(juce::Justification::centredLeft);connectionLabel.setColour(juce::Label::textColourId, kTextSecondary);addAndMakeVisible(connectionLabel);selectButton.onClick = [this]() { showPluginMenu(); };selectButton.setColour(juce::TextButton::buttonColourId, kAccent);selectButton.setColour(juce::TextButton::textColourOffId, kTextPrimary);addAndMakeVisible(selectButton);guiButton.onClick = [this]() { toggleGui(); };guiButton.setColour(juce::TextButton::buttonColourId, kBtnBg);guiButton.setColour(juce::TextButton::textColourOffId, kTextPrimary);addAndMakeVisible(guiButton);reloadButton.onClick = [this]() {auto path = processorRef.getLastPluginPath();if (path.isNotEmpty())processorRef.loadPlugin(path);};reloadButton.setColour(juce::TextButton::buttonColourId, kRed);reloadButton.setColour(juce::TextButton::textColourOffId, kTextPrimary);reloadButton.setVisible(false);addAndMakeVisible(reloadButton);startTimerHz(8);}PluginBridgeEditor::~PluginBridgeEditor(){stopTimer();}void PluginBridgeEditor::paint(juce::Graphics& g){g.fillAll(kBgDark);auto panelArea = getLocalBounds().reduced(8);g.setColour(kBgPanel);g.fillRoundedRectangle(panelArea.toFloat(), 8.0f);g.setColour(kAccent.withAlpha(0.3f));g.drawRoundedRectangle(panelArea.toFloat(), 8.0f, 1.0f);}void PluginBridgeEditor::resized(){auto area = getLocalBounds().reduced(16);auto topRow = area.removeFromTop(24);titleLabel.setBounds(topRow.removeFromLeft(160));mcpStatusLabel.setBounds(topRow);area.removeFromTop(8);pluginStatusLabel.setBounds(area.removeFromTop(20));connectionLabel.setBounds(area.removeFromTop(16));area.removeFromTop(12);auto buttonRow = area.removeFromTop(32);selectButton.setBounds(buttonRow.removeFromLeft(130));buttonRow.removeFromLeft(6);guiButton.setBounds(buttonRow.removeFromLeft(90));buttonRow.removeFromLeft(6);reloadButton.setBounds(buttonRow);}void PluginBridgeEditor::timerCallback()5 unmodified lines}else{mcpStatusLabel.setText("MCP: off", juce::dontSendNotification);mcpStatusLabel.setColour(juce::Label::textColourId, kRed);}auto connState = processorRef.getConnectionState();if (processorRef.isPluginLoaded()){pluginStatusLabel.setText(processorRef.getLoadedPluginName() + " • " +juce::String(processorRef.getLoadedPluginParamCount()) + " params",juce::dontSendNotification);pluginStatusLabel.setColour(juce::Label::textColourId, kTextPrimary);selectButton.setButtonText(processorRef.getLoadedPluginName());guiButton.setVisible(true);reloadButton.setVisible(false);}else{pluginStatusLabel.setText("No plugin loaded", juce::dontSendNotification);pluginStatusLabel.setColour(juce::Label::textColourId, kTextSecondary);selectButton.setButtonText("Select Plugin");guiButton.setVisible(false);}switch (connState){case HelperConnection::State::Disconnected:connectionLabel.setText("", juce::dontSendNotification);break;case HelperConnection::State::Starting:connectionLabel.setText("Starting helper...", juce::dontSendNotification);connectionLabel.setColour(juce::Label::textColourId, kYellow);break;case HelperConnection::State::Connected:connectionLabel.setText("Helper connected", juce::dontSendNotification);connectionLabel.setColour(juce::Label::textColourId, kGreen);break;case HelperConnection::State::Crashed:connectionLabel.setText("Plugin crashed - click Reload", juce::dontSendNotification);connectionLabel.setColour(juce::Label::textColourId, kRed);reloadButton.setVisible(true);guiButton.setVisible(false);guiOpen = false;break;}}void PluginBridgeEditor::toggleGui(){if (guiOpen){processorRef.hidePluginGui();guiButton.setButtonText("Open GUI");guiButton.setColour(juce::TextButton::buttonColourId, kBtnBg);guiOpen = false;}else{processorRef.showPluginGui();guiButton.setButtonText("Close GUI");guiButton.setColour(juce::TextButton::buttonColourId, kRed.withAlpha(0.7f));guiOpen = true;}}18 unmodified lines{const auto& file = files[i];auto name = file.getFileNameWithoutExtension();if (file.getFileExtension() == ".vst3")vst3Menu.addItem(itemId, name);elseauMenu.addItem(itemId, name);itemId++;}3 unmodified linesif (auMenu.getNumItems() > 0)menu.addSubMenu("Audio Units", auMenu);menu.showMenuAsync(juce::PopupMenu::Options().withTargetComponent(&selectButton),[this, files](int result){if (result > 0 && result <= files.size()){guiOpen = false;guiButton.setButtonText("Open GUI");guiButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xff2a2a44));processorRef.loadPlugin(files[result - 1].getFullPathName());}});6 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071085 unmodified lines11411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916018 unmodified lines1791801811821831841851861871881891901913 unmodified lines1951961971981992002012022032042052062072082092102112122132142152166 unmodified linesstatic const juce::Colour kTextSecondary(0xff8888aa);static const juce::Colour kGreen (0xff4cef50);static const juce::Colour kRed (0xffef5350);PluginBridgeEditor::PluginBridgeEditor(PluginBridgeProcessor& p): AudioProcessorEditor(&p), processorRef(p){setSize(kDefaultWidth, kDefaultHeight);setResizable(true, true);// TitletitleLabel.setText("PluginBridge", juce::dontSendNotification);titleLabel.setFont(juce::FontOptions(14.0f));titleLabel.setJustificationType(juce::Justification::centredLeft);titleLabel.setColour(juce::Label::textColourId, kTextPrimary);addAndMakeVisible(titleLabel);// MCP statusmcpStatusLabel.setFont(juce::FontOptions(11.0f));mcpStatusLabel.setJustificationType(juce::Justification::centredRight);addAndMakeVisible(mcpStatusLabel);// Plugin namepluginStatusLabel.setFont(juce::FontOptions(11.0f));pluginStatusLabel.setJustificationType(juce::Justification::centredLeft);pluginStatusLabel.setColour(juce::Label::textColourId, kTextSecondary);addAndMakeVisible(pluginStatusLabel);// Select buttonselectButton.onClick = [this]() { showPluginMenu(); };selectButton.setColour(juce::TextButton::buttonColourId, kAccent);selectButton.setColour(juce::TextButton::textColourOffId, kTextPrimary);addAndMakeVisible(selectButton);// Callbacks from processorprocessorRef.onPluginLoaded = [this](){juce::MessageManager::callAsync([this]() { embedPluginEditor(); });};processorRef.onPluginUnloaded = [this](){juce::MessageManager::callAsync([this]() { removePluginEditor(); });};processorRef.onLoadFailed = [this](const juce::String& error){juce::MessageManager::callAsync([this, error](){pluginStatusLabel.setText(error, juce::dontSendNotification);pluginStatusLabel.setColour(juce::Label::textColourId, kRed);});};// If plugin already loaded (e.g. restoring state), embed itif (processorRef.isPluginLoaded())embedPluginEditor();startTimerHz(4);}PluginBridgeEditor::~PluginBridgeEditor(){stopTimer();processorRef.onPluginLoaded = nullptr;processorRef.onPluginUnloaded = nullptr;processorRef.onLoadFailed = nullptr;removePluginEditor();}void PluginBridgeEditor::paint(juce::Graphics& g){g.fillAll(kBgDark);// Top bar backgroundauto topBar = getLocalBounds().removeFromTop(kTopBarHeight);g.setColour(kBgPanel);g.fillRect(topBar);// Separator lineg.setColour(kAccent.withAlpha(0.3f));g.drawHorizontalLine(kTopBarHeight - 1, 0.0f, (float)getWidth());}void PluginBridgeEditor::resized(){auto area = getLocalBounds();auto topBar = area.removeFromTop(kTopBarHeight).reduced(6, 4);// Top bar layouttitleLabel.setBounds(topBar.removeFromLeft(90));selectButton.setBounds(topBar.removeFromLeft(110).reduced(0, 2));topBar.removeFromLeft(6);pluginStatusLabel.setBounds(topBar.removeFromLeft(topBar.getWidth() - 70));mcpStatusLabel.setBounds(topBar);// Plugin editor fills the restif (hostedEditor)hostedEditor->setBounds(area);}void PluginBridgeEditor::timerCallback()5 unmodified lines}else{mcpStatusLabel.setText("MCP:off", juce::dontSendNotification);mcpStatusLabel.setColour(juce::Label::textColourId, kRed);}if (processorRef.isPluginLoaded()){selectButton.setButtonText(processorRef.getLoadedPluginName());pluginStatusLabel.setText(juce::String(processorRef.getLoadedPluginParamCount()) + " params", juce::dontSendNotification);pluginStatusLabel.setColour(juce::Label::textColourId, kGreen);}else if (pluginStatusLabel.getColour(juce::Label::textColourId) != kRed){selectButton.setButtonText("Select Plugin");pluginStatusLabel.setText("No plugin loaded", juce::dontSendNotification);pluginStatusLabel.setColour(juce::Label::textColourId, kTextSecondary);}}void PluginBridgeEditor::embedPluginEditor(){removePluginEditor();auto* editor = processorRef.createHostedPluginEditor();if (!editor) return;hostedEditor.reset(editor);addAndMakeVisible(hostedEditor.get());// Resize PluginBridge editor to fit the hosted plugin's GUI + top barauto editorWidth = std::max(hostedEditor->getWidth(), kDefaultWidth);auto editorHeight = hostedEditor->getHeight() + kTopBarHeight;setSize(editorWidth, editorHeight);}void PluginBridgeEditor::removePluginEditor(){if (hostedEditor){removeChildComponent(hostedEditor.get());hostedEditor.reset();setSize(kDefaultWidth, kDefaultHeight);}}18 unmodified lines{const auto& file = files[i];auto name = file.getFileNameWithoutExtension();auto path = file.getFullPathName();bool blocked = processorRef.isBlocked(path);if (file.getFileExtension() == ".vst3")vst3Menu.addItem(itemId, blocked ? name + " (not compatible)" : name, !blocked);elseauMenu.addItem(itemId, blocked ? name + " (not compatible)" : name, !blocked);itemId++;}3 unmodified linesif (auMenu.getNumItems() > 0)menu.addSubMenu("Audio Units", auMenu);menu.addSeparator();menu.addItem(9999, "Clear blocklist");menu.showMenuAsync(juce::PopupMenu::Options().withTargetComponent(&selectButton),[this, files](int result){if (result == 9999){processorRef.getBlocklist().clear();return;}if (result > 0 && result <= files.size()){pluginStatusLabel.setText("Loading...", juce::dontSendNotification);pluginStatusLabel.setColour(juce::Label::textColourId, kTextSecondary);processorRef.loadPlugin(files[result - 1].getFullPathName());}});
Source/Plugin/PluginBridgeEditor.cpp+92-94