RAM2118 commited on
Commit
df8bc97
·
verified ·
1 Parent(s): 9788b5f

fix: wire onGuiCreated callback in HelperIPC constructor to send gui_ready notification

Browse files
Files changed (1) hide show
  1. Source/Helper/HelperIPC.cpp +22 -52
Source/Helper/HelperIPC.cpp CHANGED
@@ -15,10 +15,17 @@ HelperIPC::HelperIPC(int parentPid, HelperPluginHost& host)
15
  : parentPid(parentPid), host(host)
16
  {
17
  signal(SIGPIPE, SIG_IGN);
 
 
 
 
 
 
18
  }
19
 
20
  HelperIPC::~HelperIPC()
21
  {
 
22
  disconnect();
23
  }
24
 
@@ -133,7 +140,6 @@ void HelperIPC::listenLoop()
133
  {
134
  auto msg = buffer.substr(0, pos);
135
  buffer.erase(0, pos + 1);
136
-
137
  if (!msg.empty())
138
  handleMessage(juce::String(msg));
139
  }
@@ -152,15 +158,12 @@ void HelperIPC::handleMessage(const juce::String& message)
152
  auto path = j.value("path", "");
153
  double sr = j.value("sampleRate", 44100.0);
154
  int bs = j.value("blockSize", 512);
155
-
156
  bool ok = host.loadPlugin(juce::String(path), sr, bs);
157
-
158
  json response;
159
  if (ok)
160
  response = {{"ok", true}, {"name", host.getPluginName().toStdString()}, {"params", host.getParameterCount()}};
161
  else
162
  response = {{"ok", false}, {"error", "Failed to load plugin"}};
163
-
164
  sendMessage(juce::String(response.dump()));
165
  }
166
  else if (cmd == "unload")
@@ -171,8 +174,7 @@ void HelperIPC::handleMessage(const juce::String& message)
171
  else if (cmd == "show_gui")
172
  {
173
  host.showGui();
174
- // GUI ready notification is sent asynchronously after GUI is created
175
- // (see HelperPluginHost::showGui which calls ipc->sendGuiReady)
176
  sendMessage("{\"ok\":true}");
177
  }
178
  else if (cmd == "hide_gui")
@@ -184,64 +186,38 @@ void HelperIPC::handleMessage(const juce::String& message)
184
  {
185
  auto keyword = j.value("keyword", "");
186
  auto results = host.searchParams(juce::String(keyword));
187
-
188
  json arr = json::array();
189
  for (auto& p : results)
190
- {
191
- arr.push_back({
192
- {"i", p.index},
193
- {"id", p.id.toStdString()},
194
- {"n", p.name.toStdString()},
195
- {"v", std::round(p.value * 1000.0f) / 1000.0f},
196
- {"t", p.displayText.toStdString()}
197
- });
198
- }
199
-
200
- json response = {{"ok", true}, {"results", arr}};
201
- sendMessage(juce::String(response.dump()));
202
  }
203
  else if (cmd == "get_params")
204
  {
205
  std::vector<int> ids;
206
- for (auto& id : j["ids"])
207
- ids.push_back(id.get<int>());
208
-
209
  auto results = host.getParams(ids);
210
-
211
  json values = json::object();
212
- for (auto& [idx, val] : results)
213
- values[std::to_string(idx)] = std::round(val * 1000.0f) / 1000.0f;
214
-
215
- json response = {{"ok", true}, {"values", values}};
216
- sendMessage(juce::String(response.dump()));
217
  }
218
  else if (cmd == "set_params")
219
  {
220
  std::map<int, float> values;
221
- for (auto& [key, val] : j["values"].items())
222
- values[std::stoi(key)] = val.get<float>();
223
-
224
  bool ok = host.setParams(values);
225
  sendMessage(ok ? "{\"ok\":true}" : "{\"ok\":false}");
226
  }
227
  else if (cmd == "mouse")
228
  {
229
  auto type = j.value("type", "");
230
- float x = j.value("x", 0.0f);
231
- float y = j.value("y", 0.0f);
232
  int button = j.value("button", 0);
233
-
234
  if (type == "down") host.injectMouseDown(x, y, button);
235
  else if (type == "up") host.injectMouseUp(x, y, button);
236
  else if (type == "move") host.injectMouseMove(x, y);
237
  else if (type == "drag") host.injectMouseDrag(x, y, button);
238
- else if (type == "scroll")
239
- {
240
- float dx = j.value("dx", 0.0f);
241
- float dy = j.value("dy", 0.0f);
242
- host.injectMouseScroll(x, y, dx, dy);
243
- }
244
- // No response for mouse events (fire-and-forget for low latency)
245
  }
246
  else if (cmd == "key")
247
  {
@@ -249,28 +225,22 @@ void HelperIPC::handleMessage(const juce::String& message)
249
  int keyCode = j.value("keyCode", 0);
250
  auto chars = j.value("chars", "");
251
  int modifiers = j.value("modifiers", 0);
252
-
253
- if (type == "down") host.injectKeyDown(keyCode, juce::String(chars), modifiers);
254
- else if (type == "up") host.injectKeyUp(keyCode, juce::String(chars), modifiers);
255
  }
256
  else if (cmd == "get_state")
257
  {
258
  auto state = host.getStateBase64();
259
- json response = {{"ok", true}, {"state", state.toStdString()}};
260
- sendMessage(juce::String(response.dump()));
261
  }
262
  else if (cmd == "set_state")
263
  {
264
- auto state = j.value("state", "");
265
- bool ok = host.setStateBase64(juce::String(state));
266
  sendMessage(ok ? "{\"ok\":true}" : "{\"ok\":false}");
267
  }
268
  else if (cmd == "configure")
269
  {
270
- double sr = j.value("sampleRate", 44100.0);
271
- int bs = j.value("blockSize", 512);
272
- int ch = j.value("channels", 2);
273
- host.configure(sr, bs, ch);
274
  sendMessage("{\"ok\":true}");
275
  }
276
  else if (cmd == "quit")
 
15
  : parentPid(parentPid), host(host)
16
  {
17
  signal(SIGPIPE, SIG_IGN);
18
+
19
+ // Wire the GUI created callback so we send notification to host process
20
+ host.onGuiCreated = [this](const juce::String& portName, int width, int height)
21
+ {
22
+ sendGuiReady(portName, width, height);
23
+ };
24
  }
25
 
26
  HelperIPC::~HelperIPC()
27
  {
28
+ host.onGuiCreated = nullptr;
29
  disconnect();
30
  }
31
 
 
140
  {
141
  auto msg = buffer.substr(0, pos);
142
  buffer.erase(0, pos + 1);
 
143
  if (!msg.empty())
144
  handleMessage(juce::String(msg));
145
  }
 
158
  auto path = j.value("path", "");
159
  double sr = j.value("sampleRate", 44100.0);
160
  int bs = j.value("blockSize", 512);
 
161
  bool ok = host.loadPlugin(juce::String(path), sr, bs);
 
162
  json response;
163
  if (ok)
164
  response = {{"ok", true}, {"name", host.getPluginName().toStdString()}, {"params", host.getParameterCount()}};
165
  else
166
  response = {{"ok", false}, {"error", "Failed to load plugin"}};
 
167
  sendMessage(juce::String(response.dump()));
168
  }
169
  else if (cmd == "unload")
 
174
  else if (cmd == "show_gui")
175
  {
176
  host.showGui();
177
+ // gui_ready notification sent via onGuiCreated callback (async)
 
178
  sendMessage("{\"ok\":true}");
179
  }
180
  else if (cmd == "hide_gui")
 
186
  {
187
  auto keyword = j.value("keyword", "");
188
  auto results = host.searchParams(juce::String(keyword));
 
189
  json arr = json::array();
190
  for (auto& p : results)
191
+ arr.push_back({{"i",p.index},{"id",p.id.toStdString()},{"n",p.name.toStdString()},
192
+ {"v",std::round(p.value*1000.0f)/1000.0f},{"t",p.displayText.toStdString()}});
193
+ sendMessage(juce::String(json({{"ok",true},{"results",arr}}).dump()));
 
 
 
 
 
 
 
 
 
194
  }
195
  else if (cmd == "get_params")
196
  {
197
  std::vector<int> ids;
198
+ for (auto& id : j["ids"]) ids.push_back(id.get<int>());
 
 
199
  auto results = host.getParams(ids);
 
200
  json values = json::object();
201
+ for (auto& [idx, val] : results) values[std::to_string(idx)] = std::round(val*1000.0f)/1000.0f;
202
+ sendMessage(juce::String(json({{"ok",true},{"values",values}}).dump()));
 
 
 
203
  }
204
  else if (cmd == "set_params")
205
  {
206
  std::map<int, float> values;
207
+ for (auto& [key, val] : j["values"].items()) values[std::stoi(key)] = val.get<float>();
 
 
208
  bool ok = host.setParams(values);
209
  sendMessage(ok ? "{\"ok\":true}" : "{\"ok\":false}");
210
  }
211
  else if (cmd == "mouse")
212
  {
213
  auto type = j.value("type", "");
214
+ float x = j.value("x", 0.0f), y = j.value("y", 0.0f);
 
215
  int button = j.value("button", 0);
 
216
  if (type == "down") host.injectMouseDown(x, y, button);
217
  else if (type == "up") host.injectMouseUp(x, y, button);
218
  else if (type == "move") host.injectMouseMove(x, y);
219
  else if (type == "drag") host.injectMouseDrag(x, y, button);
220
+ else if (type == "scroll") host.injectMouseScroll(x, y, j.value("dx",0.0f), j.value("dy",0.0f));
 
 
 
 
 
 
221
  }
222
  else if (cmd == "key")
223
  {
 
225
  int keyCode = j.value("keyCode", 0);
226
  auto chars = j.value("chars", "");
227
  int modifiers = j.value("modifiers", 0);
228
+ if (type == "down") host.injectKeyDown(keyCode, juce::String(chars), modifiers);
229
+ else if (type == "up") host.injectKeyUp(keyCode, juce::String(chars), modifiers);
 
230
  }
231
  else if (cmd == "get_state")
232
  {
233
  auto state = host.getStateBase64();
234
+ sendMessage(juce::String(json({{"ok",true},{"state",state.toStdString()}}).dump()));
 
235
  }
236
  else if (cmd == "set_state")
237
  {
238
+ bool ok = host.setStateBase64(juce::String(j.value("state", "")));
 
239
  sendMessage(ok ? "{\"ok\":true}" : "{\"ok\":false}");
240
  }
241
  else if (cmd == "configure")
242
  {
243
+ host.configure(j.value("sampleRate",44100.0), j.value("blockSize",512), j.value("channels",2));
 
 
 
244
  sendMessage("{\"ok\":true}");
245
  }
246
  else if (cmd == "quit")