Out-of-process rebuild: Add Helper/main.cpp — standalone helper process entry point
Browse files- Source/Helper/main.cpp +112 -0
Source/Helper/main.cpp
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <juce_audio_processors/juce_audio_processors.h>
|
| 2 |
+
#include <juce_audio_utils/juce_audio_utils.h>
|
| 3 |
+
#include <juce_gui_basics/juce_gui_basics.h>
|
| 4 |
+
#include <juce_events/juce_events.h>
|
| 5 |
+
|
| 6 |
+
#include "../Shared/SharedAudioBuffer.h"
|
| 7 |
+
#include "../Shared/IPCProtocol.h"
|
| 8 |
+
#include "../Shared/Constants.h"
|
| 9 |
+
#include "HelperPluginHost.h"
|
| 10 |
+
#include "HelperIPC.h"
|
| 11 |
+
|
| 12 |
+
// PluginBridgeHelper — standalone process that:
|
| 13 |
+
// 1. Connects to parent via Unix socket
|
| 14 |
+
// 2. Opens shared memory for audio
|
| 15 |
+
// 3. Loads third-party plugins
|
| 16 |
+
// 4. Runs processBlock when signaled
|
| 17 |
+
// 5. Shows plugin GUI in its own window
|
| 18 |
+
// 6. If it crashes, only this process dies — Ableton survives
|
| 19 |
+
|
| 20 |
+
class HelperApplication : public juce::JUCEApplication
|
| 21 |
+
{
|
| 22 |
+
public:
|
| 23 |
+
const juce::String getApplicationName() override { return "PluginBridgeHelper"; }
|
| 24 |
+
const juce::String getApplicationVersion() override { return PluginBridgeConstants::kVersion; }
|
| 25 |
+
|
| 26 |
+
void initialise(const juce::String& commandLine) override
|
| 27 |
+
{
|
| 28 |
+
// Parse args: --pid <parentPid>
|
| 29 |
+
auto args = juce::StringArray::fromTokens(commandLine, " ", "\"");
|
| 30 |
+
|
| 31 |
+
int parentPid = 0;
|
| 32 |
+
for (int i = 0; i < args.size() - 1; ++i)
|
| 33 |
+
{
|
| 34 |
+
if (args[i] == "--pid")
|
| 35 |
+
parentPid = args[i + 1].getIntValue();
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
if (parentPid == 0)
|
| 39 |
+
{
|
| 40 |
+
DBG("HelperApplication: --pid argument required");
|
| 41 |
+
quit();
|
| 42 |
+
return;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
DBG("HelperApplication: Starting for parent PID " + juce::String(parentPid));
|
| 46 |
+
|
| 47 |
+
// Initialize components
|
| 48 |
+
pluginHost = std::make_unique<HelperPluginHost>();
|
| 49 |
+
ipcServer = std::make_unique<HelperIPC>(parentPid, *pluginHost);
|
| 50 |
+
|
| 51 |
+
// Connect shared memory
|
| 52 |
+
auto shmName = IPC::getShmName(parentPid);
|
| 53 |
+
if (!sharedAudio.open(shmName))
|
| 54 |
+
{
|
| 55 |
+
DBG("HelperApplication: Failed to open shared memory: " + shmName);
|
| 56 |
+
quit();
|
| 57 |
+
return;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// Connect semaphores
|
| 61 |
+
if (!inputSem.open(IPC::getInputSemName(parentPid)) ||
|
| 62 |
+
!outputSem.open(IPC::getOutputSemName(parentPid)))
|
| 63 |
+
{
|
| 64 |
+
DBG("HelperApplication: Failed to open semaphores");
|
| 65 |
+
quit();
|
| 66 |
+
return;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// Connect IPC socket
|
| 70 |
+
if (!ipcServer->connect())
|
| 71 |
+
{
|
| 72 |
+
DBG("HelperApplication: Failed to connect to parent IPC socket");
|
| 73 |
+
quit();
|
| 74 |
+
return;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
// Give plugin host access to shared audio + semaphores
|
| 78 |
+
pluginHost->setSharedAudio(&sharedAudio, &inputSem, &outputSem);
|
| 79 |
+
|
| 80 |
+
// Start audio processing thread
|
| 81 |
+
pluginHost->startProcessing();
|
| 82 |
+
|
| 83 |
+
// Notify parent we're ready
|
| 84 |
+
ipcServer->sendReady();
|
| 85 |
+
|
| 86 |
+
DBG("HelperApplication: Ready and running");
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
void shutdown() override
|
| 90 |
+
{
|
| 91 |
+
if (pluginHost)
|
| 92 |
+
pluginHost->stopProcessing();
|
| 93 |
+
|
| 94 |
+
ipcServer.reset();
|
| 95 |
+
pluginHost.reset();
|
| 96 |
+
sharedAudio.destroy();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
void systemRequestedQuit() override
|
| 100 |
+
{
|
| 101 |
+
quit();
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
private:
|
| 105 |
+
std::unique_ptr<HelperPluginHost> pluginHost;
|
| 106 |
+
std::unique_ptr<HelperIPC> ipcServer;
|
| 107 |
+
SharedAudioBuffer sharedAudio;
|
| 108 |
+
SharedSemaphore inputSem;
|
| 109 |
+
SharedSemaphore outputSem;
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
START_JUCE_APPLICATION(HelperApplication)
|