File size: 1,968 Bytes
1af93a1 cd1256e 1af93a1 cd1256e 1af93a1 | 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 | #pragma once
#include <juce_audio_processors/juce_audio_processors.h>
#include <juce_gui_basics/juce_gui_basics.h>
#include <thread>
#include <atomic>
#include "SharedAudioBuffer.h"
class HelperPluginHost
{
public:
HelperPluginHost();
~HelperPluginHost();
// Plugin lifecycle
bool loadPlugin(const juce::String& path, double sampleRate, int blockSize);
void unloadPlugin();
bool isLoaded() const { return plugin != nullptr; }
juce::String getPluginName() const;
int getParameterCount() const;
// Audio processing (shared memory)
void setSharedAudio(SharedAudioBuffer* shm, SharedSemaphore* inSem, SharedSemaphore* outSem);
void startProcessing();
void stopProcessing();
// Parameters
struct ParamInfo {
int index;
juce::String id;
juce::String name;
float value;
juce::String displayText;
};
std::vector<ParamInfo> searchParams(const juce::String& keyword) const;
std::vector<std::pair<int, float>> getParams(const std::vector<int>& ids) const;
bool setParams(const std::map<int, float>& values);
// GUI
void showGui();
void hideGui();
// State
juce::String getStateBase64() const;
bool setStateBase64(const juce::String& base64State);
// Configure
void configure(double sampleRate, int blockSize, int channels);
// Param change callback
std::function<void(int index, float value)> onParamChanged;
private:
void audioProcessingLoop();
juce::AudioPluginFormatManager formatManager;
std::unique_ptr<juce::AudioPluginInstance> plugin;
std::thread audioThread;
std::atomic<bool> processing{false};
SharedAudioBuffer* sharedAudio = nullptr;
SharedSemaphore* inputSem = nullptr;
SharedSemaphore* outputSem = nullptr;
double currentSampleRate = 44100.0;
int currentBlockSize = 512;
int currentChannels = 2;
std::unique_ptr<juce::DocumentWindow> guiWindow;
};
|