Upload Source/Helper/HelperPluginHost.h
Browse files1234564856789101314151617181920212223242526272829303132333435363738394041424344454647484950515211121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465555666585960616263646566676869707167#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"// Simplified HelperPluginHost — ONLY tests if a plugin can load.// No audio processing, no GUI, no IPC. Just load and report.
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; 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; }
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;};Source/Helper/HelperPluginHost.h+55-60