Upload Source/Plugin/PluginBridgeEditor.cpp
Browse files6 unmodified lines789101110111213161415161718191920212223242526272829283031323334333435363735363738394043444546414243444546484950514748495053545556515253545556575859606162636458656667686970717273747576777879807081828372848586877588899091928081828384858687888990919293949596939495969798991001011021031041051061071085 unmodified lines11411511610811711811912011211312112211611711811912312112212412512612412712812913013112812913213313413213313413513613713813914014114214314414514614714814915015115213513613713813914014114214314414514614714814915015515115215715315415916016116216316416516616716816915515615715815916018 unmodified lines1791801811821831841851961861871981881891901913 unmodified lines1951961971981992002012022032042052062072082092102112132142152122132142152166 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); setSize(kDefaultWidth, kDefaultHeight); setResizable(true, true);
// Title titleLabel.setText("PluginBridge", juce::dontSendNotification); titleLabel.setFont(juce::FontOptions(18.0f)); titleLabel.setFont(juce::FontOptions(14.0f)); titleLabel.setJustificationType(juce::Justification::centredLeft); titleLabel.setColour(juce::Label::textColourId, kTextPrimary); addAndMakeVisible(titleLabel);
// MCP status mcpStatusLabel.setFont(juce::FontOptions(11.0f)); mcpStatusLabel.setJustificationType(juce::Justification::centredRight); addAndMakeVisible(mcpStatusLabel);
// Plugin name pluginStatusLabel.setFont(juce::FontOptions(13.0f)); pluginStatusLabel.setFont(juce::FontOptions(11.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);
// Select button 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); // Callbacks from processor processorRef.onPluginLoaded = [this]() { juce::MessageManager::callAsync([this]() { embedPluginEditor(); }); };
reloadButton.onClick = [this]() { auto path = processorRef.getLastPluginPath(); if (path.isNotEmpty()) processorRef.loadPlugin(path); processorRef.onPluginUnloaded = [this]() { juce::MessageManager::callAsync([this]() { removePluginEditor(); }); }; reloadButton.setColour(juce::TextButton::buttonColourId, kRed); reloadButton.setColour(juce::TextButton::textColourOffId, kTextPrimary); reloadButton.setVisible(false); addAndMakeVisible(reloadButton);
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 it if (processorRef.isPluginLoaded()) embedPluginEditor();
startTimerHz(8); startTimerHz(4);}
PluginBridgeEditor::~PluginBridgeEditor(){ stopTimer(); processorRef.onPluginLoaded = nullptr; processorRef.onPluginUnloaded = nullptr; processorRef.onLoadFailed = nullptr; removePluginEditor();}
void PluginBridgeEditor::paint(juce::Graphics& g){ g.fillAll(kBgDark);
auto panelArea = getLocalBounds().reduced(8); // Top bar background auto topBar = getLocalBounds().removeFromTop(kTopBarHeight); g.setColour(kBgPanel); g.fillRoundedRectangle(panelArea.toFloat(), 8.0f); g.fillRect(topBar);
// Separator line g.setColour(kAccent.withAlpha(0.3f)); g.drawRoundedRectangle(panelArea.toFloat(), 8.0f, 1.0f); g.drawHorizontalLine(kTopBarHeight - 1, 0.0f, (float)getWidth());}
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); auto area = getLocalBounds(); auto topBar = area.removeFromTop(kTopBarHeight).reduced(6, 4);
// Top bar layout titleLabel.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 rest if (hostedEditor) hostedEditor->setBounds(area);}
void PluginBridgeEditor::timerCallback()5 unmodified lines } else { mcpStatusLabel.setText("MCP: off", juce::dontSendNotification); 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); pluginStatusLabel.setText(juce::String(processorRef.getLoadedPluginParamCount()) + " params", juce::dontSendNotification); pluginStatusLabel.setColour(juce::Label::textColourId, kGreen); } else 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); 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::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 bar auto editorWidth = std::max(hostedEditor->getWidth(), kDefaultWidth); auto editorHeight = hostedEditor->getHeight() + kTopBarHeight; setSize(editorWidth, editorHeight);}
void PluginBridgeEditor::toggleGui()void PluginBridgeEditor::removePluginEditor(){ if (guiOpen) if (hostedEditor) { 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; 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, name); vst3Menu.addItem(itemId, blocked ? name + " (not compatible)" : name, !blocked); else auMenu.addItem(itemId, name); auMenu.addItem(itemId, blocked ? name + " (not compatible)" : name, !blocked);
itemId++; }3 unmodified lines if (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()) { guiOpen = false; guiButton.setButtonText("Open GUI"); guiButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xff2a2a44)); pluginStatusLabel.setText("Loading...", juce::dontSendNotification); pluginStatusLabel.setColour(juce::Label::textColourId, kTextSecondary); processorRef.loadPlugin(files[result - 1].getFullPathName()); } });Source/Plugin/PluginBridgeEditor.cpp+92-94