pluginbridge / Source /PluginBridgeEditor.cpp
RAM2118's picture
Sprint 2: Update PluginBridgeEditor.cpp \u2014 Load Plugin button + status display
b520f82 verified
Raw History Blame
3.75 kB
#include "PluginBridgeEditor.h"
PluginBridgeEditor::PluginBridgeEditor(PluginBridgeProcessor& p)
: AudioProcessorEditor(&p), processorRef(p)
{
setSize(320, 200);
// Title
titleLabel.setText("PluginBridge", juce::dontSendNotification);
titleLabel.setFont(juce::FontOptions(20.0f));
titleLabel.setJustificationType(juce::Justification::centred);
addAndMakeVisible(titleLabel);
// MCP status
statusLabel.setText("MCP: starting...", juce::dontSendNotification);
statusLabel.setFont(juce::FontOptions(13.0f));
statusLabel.setJustificationType(juce::Justification::centred);
addAndMakeVisible(statusLabel);
// Port
portLabel.setText("", juce::dontSendNotification);
portLabel.setFont(juce::FontOptions(11.0f));
portLabel.setJustificationType(juce::Justification::centred);
portLabel.setColour(juce::Label::textColourId, juce::Colours::grey);
addAndMakeVisible(portLabel);
// Hosted plugin name
pluginLabel.setText("No plugin loaded", juce::dontSendNotification);
pluginLabel.setFont(juce::FontOptions(13.0f));
pluginLabel.setJustificationType(juce::Justification::centred);
pluginLabel.setColour(juce::Label::textColourId, juce::Colours::lightyellow);
addAndMakeVisible(pluginLabel);
// Load button
loadButton.onClick = [this]() { loadPluginClicked(); };
addAndMakeVisible(loadButton);
startTimerHz(2);
}
PluginBridgeEditor::~PluginBridgeEditor()
{
stopTimer();
}
void PluginBridgeEditor::paint(juce::Graphics& g)
{
g.fillAll(juce::Colour(0xff1a1a2e));
}
void PluginBridgeEditor::resized()
{
auto area = getLocalBounds().reduced(12);
titleLabel.setBounds(area.removeFromTop(32));
area.removeFromTop(6);
statusLabel.setBounds(area.removeFromTop(22));
portLabel.setBounds(area.removeFromTop(18));
area.removeFromTop(8);
pluginLabel.setBounds(area.removeFromTop(22));
area.removeFromTop(8);
loadButton.setBounds(area.removeFromTop(28).reduced(60, 0));
}
void PluginBridgeEditor::timerCallback()
{
// MCP status
if (processorRef.isMcpServerRunning())
{
statusLabel.setText("MCP: running", juce::dontSendNotification);
statusLabel.setColour(juce::Label::textColourId, juce::Colours::limegreen);
portLabel.setText("http://127.0.0.1:" + juce::String(processorRef.getMcpServerPort()) + "/mcp",
juce::dontSendNotification);
}
else
{
statusLabel.setText("MCP: offline", juce::dontSendNotification);
statusLabel.setColour(juce::Label::textColourId, juce::Colours::red);
portLabel.setText("", juce::dontSendNotification);
}
// Plugin status
auto& mgr = processorRef.getHostedPluginManager();
if (mgr.isLoaded())
{
pluginLabel.setText(mgr.getPluginName() + " (" + juce::String(mgr.getParameterCount()) + " params)",
juce::dontSendNotification);
pluginLabel.setColour(juce::Label::textColourId, juce::Colours::lightyellow);
}
else
{
pluginLabel.setText("No plugin loaded", juce::dontSendNotification);
pluginLabel.setColour(juce::Label::textColourId, juce::Colours::grey);
}
}
void PluginBridgeEditor::loadPluginClicked()
{
auto chooser = std::make_shared<juce::FileChooser>(
"Select VST3 or AU plugin",
juce::File("/Library/Audio/Plug-Ins"),
"*.vst3;*.component");
chooser->launchAsync(juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
[this, chooser](const juce::FileChooser& fc)
{
auto file = fc.getResult();
if (file.exists())
processorRef.loadPluginFromFile(file);
});
}