Upload Source/Helper/HelperIPC.cpp
Browse files28 unmodified lines2930313233343538 unmodified lines7475767778793 unmodified lines8384858687888965 unmodified lines1551561571581591604 unmodified lines16516616716816917027 unmodified lines19819920020120220320420520620720820921021121222 unmodified lines23523623723823924024128 unmodified linessocketFd = socket(AF_UNIX, SOCK_STREAM, 0);if (socketFd < 0) return false;// Set SO_NOSIGPIPE (macOS)int nosigpipe = 1;setsockopt(socketFd, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));38 unmodified linessendMessage(juce::String(msg.dump()));}void HelperIPC::sendParamChanged(int index, float value){json msg = {{"notify", "param_changed"}, {"index", index}, {"value", value}};3 unmodified linesvoid HelperIPC::sendMessage(const juce::String& jsonStr){if (socketFd < 0) return;auto data = jsonStr + "\n";auto bytes = data.toRawUTF8();auto len = (size_t)data.getNumBytesAsUTF8();65 unmodified lineshost.unloadPlugin();sendMessage("{\"ok\":true}");}else if (cmd == "search_param"){auto keyword = j.value("keyword", "");4 unmodified lines{arr.push_back({{"i", p.index},{"n", p.name.toStdString()},{"v", std::round(p.value * 1000.0f) / 1000.0f},{"t", p.displayText.toStdString()}27 unmodified linesbool ok = host.setParams(values);sendMessage(ok ? "{\"ok\":true}" : "{\"ok\":false}");}else if (cmd == "show_gui"){host.showGui();sendMessage("{\"ok\":true}");}else if (cmd == "hide_gui"){host.hideGui();sendMessage("{\"ok\":true}");}else if (cmd == "get_state"){22 unmodified lines}catch (const std::exception& e){DBG("HelperIPC: Error handling message: " + juce::String(e.what()));sendMessage("{\"ok\":false,\"error\":\"parse error\"}");}}28 unmodified lines29303132333438 unmodified lines7374757677787980818283848586878889909192933 unmodified lines97989910010110265 unmodified lines1681691701711721731741751761771781791801811821831841854 unmodified lines19019119219319419519627 unmodified lines22422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625722 unmodified lines28028128228328428528628 unmodified linessocketFd = socket(AF_UNIX, SOCK_STREAM, 0);if (socketFd < 0) return false;int nosigpipe = 1;setsockopt(socketFd, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));38 unmodified linessendMessage(juce::String(msg.dump()));}void HelperIPC::sendGuiReady(const juce::String& portName, int width, int height){json msg = {{"notify", "gui_ready"},{"layerPortName", portName.toStdString()},{"width", width},{"height", height}};sendMessage(juce::String(msg.dump()));}void HelperIPC::sendGuiResized(int width, int height){json msg = {{"notify", "resized"}, {"width", width}, {"height", height}};sendMessage(juce::String(msg.dump()));}void HelperIPC::sendParamChanged(int index, float value){json msg = {{"notify", "param_changed"}, {"index", index}, {"value", value}};3 unmodified linesvoid HelperIPC::sendMessage(const juce::String& jsonStr){if (socketFd < 0) return;auto data = jsonStr + "\n";auto bytes = data.toRawUTF8();auto len = (size_t)data.getNumBytesAsUTF8();65 unmodified lineshost.unloadPlugin();sendMessage("{\"ok\":true}");}else if (cmd == "show_gui"){host.showGui();// GUI ready notification is sent asynchronously after GUI is created// (see HelperPluginHost::showGui which calls ipc->sendGuiReady)sendMessage("{\"ok\":true}");}else if (cmd == "hide_gui"){host.hideGui();sendMessage("{\"ok\":true}");}else if (cmd == "search_param"){auto keyword = j.value("keyword", "");4 unmodified lines{arr.push_back({{"i", p.index},{"id", p.id.toStdString()},{"n", p.name.toStdString()},{"v", std::round(p.value * 1000.0f) / 1000.0f},{"t", p.displayText.toStdString()}27 unmodified linesbool ok = host.setParams(values);sendMessage(ok ? "{\"ok\":true}" : "{\"ok\":false}");}else if (cmd == "mouse"){auto type = j.value("type", "");float x = j.value("x", 0.0f);float y = j.value("y", 0.0f);int button = j.value("button", 0);if (type == "down") host.injectMouseDown(x, y, button);else if (type == "up") host.injectMouseUp(x, y, button);else if (type == "move") host.injectMouseMove(x, y);else if (type == "drag") host.injectMouseDrag(x, y, button);else if (type == "scroll"){float dx = j.value("dx", 0.0f);float dy = j.value("dy", 0.0f);host.injectMouseScroll(x, y, dx, dy);}// No response for mouse events (fire-and-forget for low latency)}else if (cmd == "key"){auto type = j.value("type", "");int keyCode = j.value("keyCode", 0);auto chars = j.value("chars", "");int modifiers = j.value("modifiers", 0);if (type == "down") host.injectKeyDown(keyCode, juce::String(chars), modifiers);else if (type == "up") host.injectKeyUp(keyCode, juce::String(chars), modifiers);}else if (cmd == "get_state"){22 unmodified lines}catch (const std::exception& e){DBG("HelperIPC: Error: " + juce::String(e.what()));sendMessage("{\"ok\":false,\"error\":\"parse error\"}");}}
Source/Helper/HelperIPC.cpp+54-9