File size: 6,833 Bytes
179fedf c8a084b 179fedf b520f82 179fedf c8a084b 179fedf c8a084b 179fedf b520f82 179fedf c8a084b 179fedf b520f82 179fedf c8a084b 179fedf c8a084b 179fedf c8a084b b520f82 c8a084b b520f82 c8a084b b520f82 179fedf c8a084b 179fedf c8a084b b520f82 c8a084b 179fedf b520f82 179fedf c8a084b 179fedf b520f82 179fedf c8a084b 179fedf b520f82 c8a084b b520f82 c8a084b b520f82 c8a084b b520f82 c8a084b b520f82 c8a084b b520f82 c8a084b b520f82 c8a084b b520f82 179fedf c8a084b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | #include "PluginBridgeEditor.h"
PluginBridgeEditor::PluginBridgeEditor(PluginBridgeProcessor& p)
: AudioProcessorEditor(&p), processorRef(p)
{
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 (opens popup menu)
pluginButton.onClick = [this]() { showPluginMenu(); };
pluginButton.setColour(juce::TextButton::buttonColourId, juce::Colour(0xff2d2d44));
pluginButton.setColour(juce::TextButton::textColourOffId, juce::Colours::white);
addAndMakeVisible(pluginButton);
// Scan plugins in background on first open
if (!hasScanned)
{
hasScanned = true;
// Scan runs on message thread — fast enough for installed plugins
scanPlugins();
}
startTimerHz(2);
}
PluginBridgeEditor::~PluginBridgeEditor()
{
stopTimer();
}
void PluginBridgeEditor::paint(juce::Graphics& g)
{
// Dark gradient background
g.fillAll(juce::Colour(0xff12121f));
g.setColour(juce::Colour(0xff1e1e35));
g.fillRoundedRectangle(getLocalBounds().toFloat().reduced(4), 6.0f);
}
void PluginBridgeEditor::resized()
{
auto area = getLocalBounds().reduced(14);
titleLabel.setBounds(area.removeFromTop(30));
area.removeFromTop(4);
statusLabel.setBounds(area.removeFromTop(18));
portLabel.setBounds(area.removeFromTop(16));
area.removeFromTop(10);
pluginButton.setBounds(area.removeFromTop(30).reduced(20, 0));
area.removeFromTop(8);
pluginLabel.setBounds(area.removeFromTop(20));
}
void PluginBridgeEditor::timerCallback()
{
// MCP status
if (processorRef.isMcpServerRunning())
{
statusLabel.setText("MCP: running", juce::dontSendNotification);
statusLabel.setColour(juce::Label::textColourId, juce::Colour(0xff4cef50));
portLabel.setText("127.0.0.1:" + juce::String(processorRef.getMcpServerPort()),
juce::dontSendNotification);
}
else
{
statusLabel.setText("MCP: offline", juce::dontSendNotification);
statusLabel.setColour(juce::Label::textColourId, juce::Colour(0xffef5350));
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::Colour(0xffffeb3b));
pluginButton.setButtonText(mgr.getPluginName());
}
else
{
pluginLabel.setText("No plugin loaded", juce::dontSendNotification);
pluginLabel.setColour(juce::Label::textColourId, juce::Colour(0xff888888));
pluginButton.setButtonText("Select Plugin...");
}
}
void PluginBridgeEditor::scanPlugins()
{
// Scan standard plugin directories
for (int i = 0; i < scanFormatManager.getNumFormats(); ++i)
{
auto* format = scanFormatManager.getFormat(i);
auto searchPaths = format->getDefaultLocationsToSearch();
juce::PluginDirectoryScanner scanner(
knownPlugins,
*format,
searchPaths,
true, // recursive
juce::File() // no dead-mans-pedal for speed
);
juce::String pluginName;
while (scanner.scanNextFile(false, pluginName))
{
// Scanning...
}
}
DBG("PluginBridge: Scanned " + juce::String(knownPlugins.getNumTypes()) + " plugins");
}
void PluginBridgeEditor::showPluginMenu()
{
juce::PopupMenu menu;
// Sort by manufacturer → plugin name
auto types = knownPlugins.getTypes();
// Group by manufacturer
juce::StringArray manufacturers;
for (auto& desc : types)
{
if (!manufacturers.contains(desc.manufacturerName))
manufacturers.add(desc.manufacturerName);
}
manufacturers.sort(true);
int itemId = 1;
for (auto& mfr : manufacturers)
{
juce::PopupMenu subMenu;
for (int i = 0; i < types.size(); ++i)
{
if (types[i].manufacturerName == mfr)
{
subMenu.addItem(itemId, types[i].name + " (" + types[i].pluginFormatName + ")");
}
itemId++;
}
menu.addSubMenu(mfr, subMenu);
// Reset itemId for proper indexing
itemId = 1;
for (int i = 0; i < types.size(); ++i)
{
if (types[i].manufacturerName == mfr)
itemId++;
}
}
// Simpler approach: flat list with manufacturer prefix, proper IDs
menu.clear();
for (int i = 0; i < types.size(); ++i)
{
menu.addItem(i + 1, types[i].manufacturerName + " — " + types[i].name
+ " [" + types[i].pluginFormatName + "]");
}
menu.showMenuAsync(juce::PopupMenu::Options().withTargetComponent(&pluginButton),
[this, types](int result)
{
if (result > 0 && result <= types.size())
{
loadPluginByIndex(result - 1);
}
});
}
void PluginBridgeEditor::loadPluginByIndex(int index)
{
auto types = knownPlugins.getTypes();
if (index >= 0 && index < types.size())
{
auto& desc = types[index];
juce::File pluginFile(desc.fileOrIdentifier);
processorRef.loadPluginFromFile(pluginFile);
}
}
|