Upload Source/Helper/HelperPluginHost.h
Browse files- Source/Helper/HelperPluginHost.h +81 -55
Source/Helper/HelperPluginHost.h
CHANGED
|
@@ -1,67 +1,93 @@
|
|
| 1 |
#pragma once
|
| 2 |
|
| 3 |
#include <juce_audio_processors/juce_audio_processors.h>
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
// No audio processing, no GUI, no IPC. Just load and report.
|
| 7 |
|
| 8 |
class HelperPluginHost
|
| 9 |
{
|
| 10 |
public:
|
| 11 |
-
HelperPluginHost()
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
//
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
juce::
|
| 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 |
private:
|
|
|
|
|
|
|
| 66 |
juce::AudioPluginFormatManager formatManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
};
|
|
|
|
| 1 |
#pragma once
|
| 2 |
|
| 3 |
#include <juce_audio_processors/juce_audio_processors.h>
|
| 4 |
+
#include <juce_gui_basics/juce_gui_basics.h>
|
| 5 |
+
#include <thread>
|
| 6 |
+
#include <atomic>
|
| 7 |
|
| 8 |
+
#include "SharedAudioBuffer.h"
|
|
|
|
| 9 |
|
| 10 |
class HelperPluginHost
|
| 11 |
{
|
| 12 |
public:
|
| 13 |
+
HelperPluginHost();
|
| 14 |
+
~HelperPluginHost();
|
| 15 |
+
|
| 16 |
+
// Plugin lifecycle
|
| 17 |
+
bool loadPlugin(const juce::String& path, double sampleRate, int blockSize);
|
| 18 |
+
void unloadPlugin();
|
| 19 |
+
bool isLoaded() const { return plugin != nullptr; }
|
| 20 |
+
juce::String getPluginName() const;
|
| 21 |
+
int getParameterCount() const;
|
| 22 |
+
|
| 23 |
+
// Audio processing (shared memory)
|
| 24 |
+
void setSharedAudio(SharedAudioBuffer* shm, SharedSemaphore* inSem, SharedSemaphore* outSem);
|
| 25 |
+
void startProcessing();
|
| 26 |
+
void stopProcessing();
|
| 27 |
+
|
| 28 |
+
// Parameters
|
| 29 |
+
struct ParamInfo {
|
| 30 |
+
int index;
|
| 31 |
+
juce::String id;
|
| 32 |
+
juce::String name;
|
| 33 |
+
float value;
|
| 34 |
+
juce::String displayText;
|
| 35 |
+
};
|
| 36 |
+
std::vector<ParamInfo> searchParams(const juce::String& keyword) const;
|
| 37 |
+
std::vector<std::pair<int, float>> getParams(const std::vector<int>& ids) const;
|
| 38 |
+
bool setParams(const std::map<int, float>& values);
|
| 39 |
+
|
| 40 |
+
// GUI via CARemoteLayerServer
|
| 41 |
+
void showGui();
|
| 42 |
+
void hideGui();
|
| 43 |
+
int getGuiWidth() const { return guiWidth; }
|
| 44 |
+
int getGuiHeight() const { return guiHeight; }
|
| 45 |
+
|
| 46 |
+
// Event injection (from host process)
|
| 47 |
+
void injectMouseDown(float x, float y, int button);
|
| 48 |
+
void injectMouseUp(float x, float y, int button);
|
| 49 |
+
void injectMouseMove(float x, float y);
|
| 50 |
+
void injectMouseDrag(float x, float y, int button);
|
| 51 |
+
void injectMouseScroll(float x, float y, float dx, float dy);
|
| 52 |
+
void injectKeyDown(int keyCode, const juce::String& chars, int modifiers);
|
| 53 |
+
void injectKeyUp(int keyCode, const juce::String& chars, int modifiers);
|
| 54 |
+
|
| 55 |
+
// State
|
| 56 |
+
juce::String getStateBase64() const;
|
| 57 |
+
bool setStateBase64(const juce::String& base64State);
|
| 58 |
+
void configure(double sampleRate, int blockSize, int channels);
|
| 59 |
+
|
| 60 |
+
// CARemoteLayerServer port name (set after GUI is created)
|
| 61 |
+
juce::String getLayerPortName() const { return layerPortName; }
|
| 62 |
+
|
| 63 |
+
// Callback for resize
|
| 64 |
+
std::function<void(int w, int h)> onGuiResized;
|
|
|
|
| 65 |
|
| 66 |
private:
|
| 67 |
+
void audioProcessingLoop();
|
| 68 |
+
|
| 69 |
juce::AudioPluginFormatManager formatManager;
|
| 70 |
+
std::unique_ptr<juce::AudioPluginInstance> plugin;
|
| 71 |
+
std::unique_ptr<juce::AudioProcessorEditor> editor;
|
| 72 |
+
|
| 73 |
+
std::thread audioThread;
|
| 74 |
+
std::atomic<bool> processing{false};
|
| 75 |
+
|
| 76 |
+
SharedAudioBuffer* sharedAudio = nullptr;
|
| 77 |
+
SharedSemaphore* inputSem = nullptr;
|
| 78 |
+
SharedSemaphore* outputSem = nullptr;
|
| 79 |
+
|
| 80 |
+
double currentSampleRate = 44100.0;
|
| 81 |
+
int currentBlockSize = 512;
|
| 82 |
+
int currentChannels = 2;
|
| 83 |
+
|
| 84 |
+
// GUI
|
| 85 |
+
std::unique_ptr<juce::Component> guiContainer;
|
| 86 |
+
int guiWidth = 0;
|
| 87 |
+
int guiHeight = 0;
|
| 88 |
+
juce::String layerPortName;
|
| 89 |
+
|
| 90 |
+
// ObjC objects (stored as void* to avoid ObjC in header)
|
| 91 |
+
void* remoteLayerServer = nullptr; // CARemoteLayerServer*
|
| 92 |
+
void* guiWindow = nullptr; // NSWindow* (hidden, for layer backing)
|
| 93 |
};
|