File size: 2,756 Bytes
31b4607 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | #pragma once
#include <string>
#include <cstdint>
// IPC Protocol between PluginBridge (parent) and PluginBridgeHelper (child)
// Transport: Unix domain socket, newline-delimited JSON messages
//
// Flow:
// Parent → Helper: commands (load plugin, get/set params, show GUI, quit)
// Helper → Parent: responses + notifications (param changes from GUI, crash)
namespace IPC {
// Socket path (unique per instance using PID)
inline std::string getSocketPath(int parentPid)
{
return "/tmp/pluginbridge_" + std::to_string(parentPid) + ".sock";
}
// Shared memory name (unique per instance)
inline std::string getShmName(int parentPid)
{
return "pluginbridge_audio_" + std::to_string(parentPid);
}
// Semaphore names
inline std::string getInputSemName(int parentPid)
{
return "pb_input_" + std::to_string(parentPid);
}
inline std::string getOutputSemName(int parentPid)
{
return "pb_output_" + std::to_string(parentPid);
}
// --- Message Types (Parent → Helper) ---
// Load a plugin by file path
// {"cmd":"load","path":"/Library/Audio/Plug-Ins/VST3/Pro-Q 4.vst3"}
// Response: {"ok":true,"name":"Pro-Q 4","params":737} or {"ok":false,"error":"..."}
// Unload current plugin
// {"cmd":"unload"}
// Response: {"ok":true}
// Search parameters by keyword
// {"cmd":"search_param","keyword":"gain"}
// Response: {"ok":true,"results":[{"i":12,"n":"Band 1 Gain","v":0.5,"t":"0.0 dB"},...]}
// Get parameter values by index
// {"cmd":"get_params","ids":[12,13,14]}
// Response: {"ok":true,"values":{"12":0.5,"13":0.7,"14":0.0}}
// Set parameter values
// {"cmd":"set_params","values":{"12":0.75,"13":0.3}}
// Response: {"ok":true}
// Show/hide plugin GUI
// {"cmd":"show_gui"}
// {"cmd":"hide_gui"}
// Response: {"ok":true}
// Get plugin state (for save)
// {"cmd":"get_state"}
// Response: {"ok":true,"state":"<base64-encoded state>"}
// Set plugin state (for restore)
// {"cmd":"set_state","state":"<base64-encoded state>"}
// Response: {"ok":true}
// Configure audio
// {"cmd":"configure","sampleRate":44100,"blockSize":512,"channels":2}
// Response: {"ok":true}
// Quit helper
// {"cmd":"quit"}
// No response (process exits)
// --- Message Types (Helper → Parent, unsolicited notifications) ---
// Parameter changed from GUI interaction
// {"notify":"param_changed","index":12,"value":0.75}
// Plugin crashed (sent if helper catches it before dying)
// {"notify":"crashed","error":"..."}
// Helper ready (sent after startup)
// {"notify":"ready"}
// --- Constants ---
static constexpr int kMaxMessageSize = 65536; // 64KB max for state blobs
static constexpr int kHelperTimeoutMs = 5000; // 5s to start up
static constexpr int kProcessBlockTimeoutMs = 50; // 50ms max wait in processBlock
} // namespace IPC
|