File size: 2,811 Bytes
31b4607
 
 
 
 
 
4ad264f
 
 
 
 
 
 
 
 
31b4607
 
 
 
 
 
 
 
 
4ad264f
31b4607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ad264f
 
 
 
 
31b4607
4ad264f
 
31b4607
 
4ad264f
 
31b4607
 
 
4ad264f
31b4607
 
4ad264f
 
 
 
 
 
 
 
 
 
 
 
 
 
31b4607
 
 
4ad264f
 
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
#pragma once

#include <string>
#include <cstdint>

// IPC Protocol between PluginBridge (parent) and PluginBridgeHelper (child)
//
// v0.4 Architecture:
// - Audio: POSIX shared memory (zero-copy, same as v0.2)
// - Sync: Named semaphores (same as v0.2)
// - Commands: Unix domain socket, newline-delimited JSON
// - GUI: CARemoteLayerServer in Helper → Mach port → CARemoteLayerClient in Host
//
// The Mach port for CARemoteLayerServer is transferred via NSMachBootstrapServer
// using the name "com.pluginbridge.layer.<parentPid>"

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
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);
}

// Mach bootstrap port name for CARemoteLayerServer
inline std::string getLayerPortName(int parentPid)
{
    return "com.pluginbridge.layer." + std::to_string(parentPid);
}

// --- Message Types (Parent → Helper) ---
// {"cmd":"load","path":"/path/to/plugin.vst3","sampleRate":44100,"blockSize":512}
// {"cmd":"unload"}
// {"cmd":"search_param","keyword":"gain"}
// {"cmd":"get_params","ids":[0,1,2]}
// {"cmd":"set_params","values":{"0":0.5,"1":0.75}}
// {"cmd":"show_gui"}
// {"cmd":"hide_gui"}
// {"cmd":"get_state"}
// {"cmd":"set_state","state":"<base64>"}
// {"cmd":"configure","sampleRate":44100,"blockSize":512,"channels":2}
// {"cmd":"quit"}
//
// --- Mouse/Keyboard forwarding (Parent → Helper) ---
// {"cmd":"mouse","type":"down","x":120.5,"y":45.0,"button":0}
// {"cmd":"mouse","type":"up","x":120.5,"y":45.0,"button":0}
// {"cmd":"mouse","type":"move","x":130.0,"y":50.0}
// {"cmd":"mouse","type":"drag","x":135.0,"y":52.0,"button":0}
// {"cmd":"mouse","type":"scroll","x":120.5,"y":45.0,"dx":0,"dy":-3.0}
// {"cmd":"key","type":"down","keyCode":36,"chars":"a","modifiers":0}
// {"cmd":"key","type":"up","keyCode":36,"chars":"a","modifiers":0}
//
// --- Notifications (Helper → Parent) ---
// {"notify":"ready","layerPortName":"com.pluginbridge.layer.12345","width":800,"height":600}
// {"notify":"param_changed","index":5,"value":0.75}
// {"notify":"resized","width":900,"height":650}
// {"notify":"crashed","error":"..."}

// --- Constants ---
static constexpr int kMaxMessageSize = 65536;
static constexpr int kHelperTimeoutMs = 10000;   // 10s for startup (CARemoteLayer init takes time)
static constexpr int kProcessBlockTimeoutMs = 50; // 50ms max wait in processBlock

} // namespace IPC