Upload Source/Helper/HelperPluginHost.h
Browse files123456756891011121112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293#pragma once
#include <juce_audio_processors/juce_audio_processors.h>#include <juce_gui_basics/juce_gui_basics.h>#include <thread>#include <atomic>
// Simplified HelperPluginHost — ONLY tests if a plugin can load.// No audio processing, no GUI, no IPC. Just load and report.#include "SharedAudioBuffer.h"
class HelperPluginHost{public: HelperPluginHost() { #if JUCE_PLUGINHOST_VST3 formatManager.addFormat(new juce::VST3PluginFormat()); #endif #if JUCE_PLUGINHOST_AU formatManager.addFormat(new juce::AudioUnitPluginFormat()); #endif }
// Try to load a plugin. Returns true if successful. // If the plugin crashes (abort(), NSAlert, etc.), this process dies // and the parent sees exit code != 0. bool testLoad(const juce::String& path) { juce::File pluginFile(path); if (!pluginFile.exists()) return false;
juce::OwnedArray<juce::PluginDescription> typesFound;
for (int i = 0; i < formatManager.getNumFormats(); ++i) { auto* format = formatManager.getFormat(i); bool isVST3 = pluginFile.getFileExtension() == ".vst3"; bool isAU = pluginFile.getFileExtension() == ".component";
if (isVST3 && format->getName() != "VST3") continue; if (isAU && format->getName() != "AudioUnit") continue;
format->findAllTypesForFile(typesFound, pluginFile.getFullPathName()); if (typesFound.size() > 0) break; }
if (typesFound.isEmpty()) return false;
juce::String errorMessage; auto instance = formatManager.createPluginInstance( *typesFound[0], 44100.0, 512, errorMessage);
if (instance == nullptr) { DBG("HelperPluginHost: Load failed: " + errorMessage); return false; }
// Successfully loaded — release and report safe instance->releaseResources(); instance.reset(); return true; } 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 via CARemoteLayerServer void showGui(); void hideGui(); int getGuiWidth() const { return guiWidth; } int getGuiHeight() const { return guiHeight; }
// Event injection (from host process) void injectMouseDown(float x, float y, int button); void injectMouseUp(float x, float y, int button); void injectMouseMove(float x, float y); void injectMouseDrag(float x, float y, int button); void injectMouseScroll(float x, float y, float dx, float dy); void injectKeyDown(int keyCode, const juce::String& chars, int modifiers); void injectKeyUp(int keyCode, const juce::String& chars, int modifiers);
// State juce::String getStateBase64() const; bool setStateBase64(const juce::String& base64State); void configure(double sampleRate, int blockSize, int channels);
// CARemoteLayerServer port name (set after GUI is created) juce::String getLayerPortName() const { return layerPortName; }
// Callback for resize std::function<void(int w, int h)> onGuiResized;
private: void audioProcessingLoop();
juce::AudioPluginFormatManager formatManager; std::unique_ptr<juce::AudioPluginInstance> plugin; std::unique_ptr<juce::AudioProcessorEditor> editor;
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;
// GUI std::unique_ptr<juce::Component> guiContainer; int guiWidth = 0; int guiHeight = 0; juce::String layerPortName;
// ObjC objects (stored as void* to avoid ObjC in header) void* remoteLayerServer = nullptr; // CARemoteLayerServer* void* guiWindow = nullptr; // NSWindow* (hidden, for layer backing)};Source/Helper/HelperPluginHost.h+81-55