File size: 1,703 Bytes
2b132c2
 
cf8bc89
 
 
2b132c2
 
 
 
cf8bc89
 
2b132c2
cf8bc89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b132c2
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
#pragma once

#include <juce_audio_processors/juce_audio_processors.h>
#include <vector>
#include <map>

class HostedPluginManager
{
public:
    HostedPluginManager();
    ~HostedPluginManager();

    // Plugin lifecycle
    void loadPlugin(const juce::File& pluginFile, double sampleRate, int blockSize);
    void unloadPlugin();
    bool isLoaded() const;
    juce::String getPluginName() const;

    // Audio processing — called from audio thread
    void prepareToPlay(double sampleRate, int blockSize);
    void processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midi);
    void releaseResources();

    // Parameter surface — called from HTTP thread (thread-safe)
    struct ParamInfo {
        int index;
        juce::String id;
        juce::String name;
        float value;        // 0.0–1.0 normalized
        juce::String displayText;
        bool automatable;
    };

    std::vector<ParamInfo> searchParams(const juce::String& keyword) const;
    std::vector<std::pair<int, float>> getParams(const std::vector<int>& indices) const;
    bool setParams(const std::map<int, float>& values);
    int getParameterCount() const;

    // Thread safety
    juce::CriticalSection& getPluginLock() { return pluginLock; }

    // File path of currently loaded plugin (for state save/restore)
    juce::String getLoadedPluginPath() const;

private:
    juce::AudioPluginFormatManager formatManager;
    std::unique_ptr<juce::AudioPluginInstance> hostedPlugin;
    juce::CriticalSection pluginLock;

    double currentSampleRate = 44100.0;
    int currentBlockSize = 512;
    juce::String loadedPluginPath;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(HostedPluginManager)
};