File size: 3,749 Bytes
179fedf
 
 
 
 
b520f82
179fedf
b520f82
179fedf
 
 
 
 
b520f82
179fedf
b520f82
179fedf
 
 
b520f82
179fedf
b520f82
179fedf
 
 
 
b520f82
 
 
 
 
 
 
 
 
 
 
 
179fedf
 
 
 
 
 
 
 
 
 
 
 
 
 
b520f82
 
 
 
 
 
 
 
 
179fedf
 
 
 
b520f82
 
 
179fedf
 
 
 
b520f82
 
 
179fedf
 
 
 
b520f82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179fedf
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
#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);
        });
}