RAM2118 commited on
Commit
ef91ceb
·
verified ·
1 Parent(s): 475c9dd

Upload Source/Helper/HelperPluginHost.h

Browse files
Files changed (1) hide show
  1. 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
- // Simplified HelperPluginHost — ONLY tests if a plugin can load.
6
- // No audio processing, no GUI, no IPC. Just load and report.
7
 
8
  class HelperPluginHost
9
  {
10
  public:
11
- HelperPluginHost()
12
- {
13
- #if JUCE_PLUGINHOST_VST3
14
- formatManager.addFormat(new juce::VST3PluginFormat());
15
- #endif
16
- #if JUCE_PLUGINHOST_AU
17
- formatManager.addFormat(new juce::AudioUnitPluginFormat());
18
- #endif
19
- }
20
-
21
- // Try to load a plugin. Returns true if successful.
22
- // If the plugin crashes (abort(), NSAlert, etc.), this process dies
23
- // and the parent sees exit code != 0.
24
- bool testLoad(const juce::String& path)
25
- {
26
- juce::File pluginFile(path);
27
- if (!pluginFile.exists())
28
- return false;
29
-
30
- juce::OwnedArray<juce::PluginDescription> typesFound;
31
-
32
- for (int i = 0; i < formatManager.getNumFormats(); ++i)
33
- {
34
- auto* format = formatManager.getFormat(i);
35
- bool isVST3 = pluginFile.getFileExtension() == ".vst3";
36
- bool isAU = pluginFile.getFileExtension() == ".component";
37
-
38
- if (isVST3 && format->getName() != "VST3") continue;
39
- if (isAU && format->getName() != "AudioUnit") continue;
40
-
41
- format->findAllTypesForFile(typesFound, pluginFile.getFullPathName());
42
- if (typesFound.size() > 0)
43
- break;
44
- }
45
-
46
- if (typesFound.isEmpty())
47
- return false;
48
-
49
- juce::String errorMessage;
50
- auto instance = formatManager.createPluginInstance(
51
- *typesFound[0], 44100.0, 512, errorMessage);
52
-
53
- if (instance == nullptr)
54
- {
55
- DBG("HelperPluginHost: Load failed: " + errorMessage);
56
- return false;
57
- }
58
-
59
- // Successfully loaded — release and report safe
60
- instance->releaseResources();
61
- instance.reset();
62
- return true;
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
  };