Upload Source/Helper/main.cpp
Browse files- Source/Helper/main.cpp +63 -42
Source/Helper/main.cpp
CHANGED
|
@@ -1,78 +1,99 @@
|
|
| 1 |
#include <juce_audio_processors/juce_audio_processors.h>
|
|
|
|
| 2 |
#include <juce_gui_basics/juce_gui_basics.h>
|
| 3 |
#include <juce_events/juce_events.h>
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
#include "HelperPluginHost.h"
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
// Spawned by PluginBridge to test if a plugin can load safely.
|
| 9 |
-
// If the plugin crashes, only this process dies. Ableton survives.
|
| 10 |
-
//
|
| 11 |
-
// Usage: PluginBridgeHelper --test "/path/to/plugin.vst3"
|
| 12 |
-
// Exit code 0 = safe, exit code 1 = failed to load, crash = unsafe
|
| 13 |
-
|
| 14 |
-
class HelperApplication : public juce::JUCEApplication, private juce::Timer
|
| 15 |
{
|
| 16 |
public:
|
| 17 |
const juce::String getApplicationName() override { return "PluginBridgeHelper"; }
|
| 18 |
-
const juce::String getApplicationVersion() override { return
|
| 19 |
|
| 20 |
void initialise(const juce::String& commandLine) override
|
| 21 |
{
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
{
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
quit();
|
| 29 |
-
return;
|
| 30 |
}
|
| 31 |
|
| 32 |
-
|
| 33 |
-
pluginPath = commandLine.substring(testFlagPos + 7).trim().unquoted();
|
| 34 |
-
|
| 35 |
-
if (pluginPath.isEmpty())
|
| 36 |
{
|
| 37 |
-
DBG("HelperApplication:
|
| 38 |
-
setApplicationReturnValue(1);
|
| 39 |
quit();
|
| 40 |
return;
|
| 41 |
}
|
| 42 |
|
| 43 |
-
DBG("HelperApplication:
|
| 44 |
|
| 45 |
-
//
|
| 46 |
-
|
| 47 |
-
startTimer(100);
|
| 48 |
-
}
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
stopTimer();
|
| 53 |
|
| 54 |
-
|
| 55 |
-
bool success = host.testLoad(pluginPath);
|
| 56 |
|
| 57 |
-
|
|
|
|
| 58 |
{
|
| 59 |
-
DBG("HelperApplication:
|
| 60 |
-
|
|
|
|
| 61 |
}
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
{
|
| 64 |
-
DBG("HelperApplication:
|
| 65 |
-
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
}
|
| 70 |
|
| 71 |
-
void shutdown() override
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
private:
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
};
|
| 77 |
|
| 78 |
START_JUCE_APPLICATION(HelperApplication)
|
|
|
|
| 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 "SharedAudioBuffer.h"
|
| 7 |
+
#include "IPCProtocol.h"
|
| 8 |
+
#include "Constants.h"
|
| 9 |
#include "HelperPluginHost.h"
|
| 10 |
+
#include "HelperIPC.h"
|
| 11 |
|
| 12 |
+
class HelperApplication : public juce::JUCEApplication
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
{
|
| 14 |
public:
|
| 15 |
const juce::String getApplicationName() override { return "PluginBridgeHelper"; }
|
| 16 |
+
const juce::String getApplicationVersion() override { return PluginBridgeConstants::kVersion; }
|
| 17 |
|
| 18 |
void initialise(const juce::String& commandLine) override
|
| 19 |
{
|
| 20 |
+
auto args = juce::StringArray::fromTokens(commandLine, " ", "\"");
|
| 21 |
+
|
| 22 |
+
int parentPid = 0;
|
| 23 |
+
for (int i = 0; i < args.size() - 1; ++i)
|
| 24 |
{
|
| 25 |
+
if (args[i] == "--pid")
|
| 26 |
+
parentPid = args[i + 1].getIntValue();
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
+
if (parentPid == 0)
|
|
|
|
|
|
|
|
|
|
| 30 |
{
|
| 31 |
+
DBG("HelperApplication: --pid argument required");
|
|
|
|
| 32 |
quit();
|
| 33 |
return;
|
| 34 |
}
|
| 35 |
|
| 36 |
+
DBG("HelperApplication: Starting for parent PID " + juce::String(parentPid));
|
| 37 |
|
| 38 |
+
// Set the layer port name based on parent PID
|
| 39 |
+
auto portName = juce::String(IPC::getLayerPortName(parentPid));
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
pluginHost = std::make_unique<HelperPluginHost>();
|
| 42 |
+
pluginHost->layerPortName = portName;
|
|
|
|
| 43 |
|
| 44 |
+
ipcServer = std::make_unique<HelperIPC>(parentPid, *pluginHost);
|
|
|
|
| 45 |
|
| 46 |
+
auto shmName = IPC::getShmName(parentPid);
|
| 47 |
+
if (!sharedAudio.open(shmName))
|
| 48 |
{
|
| 49 |
+
DBG("HelperApplication: Failed to open shared memory: " + shmName);
|
| 50 |
+
quit();
|
| 51 |
+
return;
|
| 52 |
}
|
| 53 |
+
|
| 54 |
+
if (!inputSem.open(IPC::getInputSemName(parentPid)) ||
|
| 55 |
+
!outputSem.open(IPC::getOutputSemName(parentPid)))
|
| 56 |
{
|
| 57 |
+
DBG("HelperApplication: Failed to open semaphores");
|
| 58 |
+
quit();
|
| 59 |
+
return;
|
| 60 |
}
|
| 61 |
|
| 62 |
+
if (!ipcServer->connect())
|
| 63 |
+
{
|
| 64 |
+
DBG("HelperApplication: Failed to connect to parent IPC socket");
|
| 65 |
+
quit();
|
| 66 |
+
return;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
pluginHost->setSharedAudio(&sharedAudio, &inputSem, &outputSem);
|
| 70 |
+
pluginHost->startProcessing();
|
| 71 |
+
ipcServer->sendReady();
|
| 72 |
+
|
| 73 |
+
DBG("HelperApplication: Ready and running");
|
| 74 |
}
|
| 75 |
|
| 76 |
+
void shutdown() override
|
| 77 |
+
{
|
| 78 |
+
if (pluginHost)
|
| 79 |
+
pluginHost->stopProcessing();
|
| 80 |
+
|
| 81 |
+
ipcServer.reset();
|
| 82 |
+
pluginHost.reset();
|
| 83 |
+
sharedAudio.destroy();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
void systemRequestedQuit() override
|
| 87 |
+
{
|
| 88 |
+
quit();
|
| 89 |
+
}
|
| 90 |
|
| 91 |
private:
|
| 92 |
+
std::unique_ptr<HelperPluginHost> pluginHost;
|
| 93 |
+
std::unique_ptr<HelperIPC> ipcServer;
|
| 94 |
+
SharedAudioBuffer sharedAudio;
|
| 95 |
+
SharedSemaphore inputSem;
|
| 96 |
+
SharedSemaphore outputSem;
|
| 97 |
};
|
| 98 |
|
| 99 |
START_JUCE_APPLICATION(HelperApplication)
|