File size: 3,217 Bytes
644b727
 
 
 
590be7d
 
42bb859
4a72dce
644b727
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42bb859
644b727
 
590be7d
644b727
590be7d
 
644b727
590be7d
 
 
 
 
 
 
4a72dce
 
42bb859
644b727
 
42bb859
 
 
 
590be7d
 
 
 
 
 
42bb859
 
590be7d
 
42bb859
 
644b727
590be7d
42bb859
 
 
590be7d
 
42bb859
590be7d
 
 
 
 
 
 
644b727
 
 
 
 
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
#pragma once

#include <juce_audio_processors/juce_audio_processors.h>
#include <juce_dsp/juce_dsp.h>
#include "HelperConnection.h"
#include "McpServer.h"
#include "Blocklist.h"
#include "Constants.h"

class PluginBridgeProcessor : public juce::AudioProcessor
{
public:
    PluginBridgeProcessor();
    ~PluginBridgeProcessor() override;

    void prepareToPlay(double sampleRate, int samplesPerBlock) override;
    void releaseResources() override;
    void processBlock(juce::AudioBuffer<float>&, juce::MidiBuffer&) override;

    juce::AudioProcessorEditor* createEditor() override;
    bool hasEditor() const override { return true; }

    const juce::String getName() const override { return "PluginBridge"; }
    bool acceptsMidi() const override { return true; }
    bool producesMidi() const override { return true; }
    double getTailLengthSeconds() const override { return 0.0; }

    int getNumPrograms() override { return 1; }
    int getCurrentProgram() override { return 0; }
    void setCurrentProgram(int) override {}
    const juce::String getProgramName(int) override { return {}; }
    void changeProgramName(int, const juce::String&) override {}

    void getStateInformation(juce::MemoryBlock& destData) override;
    void setStateInformation(const void* data, int sizeInBytes) override;

    // MCP
    bool isMcpServerRunning() const;
    int getMcpServerPort() const;
    HelperConnection& getHelperConnection() { return helper; }

    // Plugin lifecycle (via Helper)
    void loadPlugin(const juce::String& pluginPath);
    void unloadPlugin();
    void showPluginGui();
    void hidePluginGui();

    bool isPluginLoaded() const { return pluginLoaded; }
    juce::String getLoadedPluginName() const { return pluginName; }
    int getLoadedPluginParamCount() const { return pluginParamCount; }
    HelperConnection::State getConnectionState() const { return helper.getState(); }
    juce::String getLastPluginPath() const { return pluginPath; }

    // Plugin list
    juce::Array<juce::File> getInstalledPluginFiles() const;

    // Blocklist
    bool isBlocked(const juce::String& path) const;
    Blocklist& getBlocklist() { return blocklist; }

    // Remote GUI info (from Helper via IPC)
    juce::String getRemoteLayerPortName() const { return remoteLayerPortName; }
    int getRemoteGuiWidth() const { return remoteGuiWidth; }
    int getRemoteGuiHeight() const { return remoteGuiHeight; }

    // Callbacks for editor
    std::function<void()> onPluginLoaded;
    std::function<void()> onPluginUnloaded;
    std::function<void()> onGuiReady;       // remote layer port available
    std::function<void(int, int)> onGuiResized;
    std::function<void(const juce::String&)> onLoadFailed;

private:
    HelperConnection helper;
    std::unique_ptr<McpServer> mcpServer;
    Blocklist blocklist;

    bool pluginLoaded = false;
    juce::String pluginName;
    juce::String pluginPath;
    int pluginParamCount = 0;

    // Remote GUI state
    juce::String remoteLayerPortName;
    int remoteGuiWidth = 0;
    int remoteGuiHeight = 0;

    double currentSampleRate = 44100.0;
    int currentBlockSize = 512;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginBridgeProcessor)
};