From 94d30f085bb7f85b0bcd1e160da4206b86909e79 Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 13 Mar 2019 21:21:21 +0100 Subject: [PATCH] OSC control now waits for responses from server Signed-off-by: falkTX --- source/backend/engine/CarlaEngineOsc.hpp | 1 + .../backend/engine/CarlaEngineOscHandlers.cpp | 224 ++++++++++-------- source/backend/engine/CarlaEngineOscSend.cpp | 58 +---- source/frontend/carla_control.py | 53 ++++- 4 files changed, 178 insertions(+), 158 deletions(-) diff --git a/source/backend/engine/CarlaEngineOsc.hpp b/source/backend/engine/CarlaEngineOsc.hpp index 765d3ce25..edbb266fa 100644 --- a/source/backend/engine/CarlaEngineOsc.hpp +++ b/source/backend/engine/CarlaEngineOsc.hpp @@ -105,6 +105,7 @@ public: void sendPluginCustomData(const CarlaPlugin* const plugin, const uint32_t index) const noexcept; void sendPluginInternalParameterValues(const CarlaPlugin* const plugin) const noexcept; void sendPing() const noexcept; + void sendResponse(const int messageId, const char* const error) const noexcept; void sendExit() const noexcept; // ------------------------------------------------------------------- diff --git a/source/backend/engine/CarlaEngineOscHandlers.cpp b/source/backend/engine/CarlaEngineOscHandlers.cpp index 2a309d9fd..f210eb049 100644 --- a/source/backend/engine/CarlaEngineOscHandlers.cpp +++ b/source/backend/engine/CarlaEngineOscHandlers.cpp @@ -284,6 +284,7 @@ int CarlaEngineOsc::handleMsgControl(const char* const method, carla_debug("CarlaEngineOsc::handleMsgControl()"); CARLA_SAFE_ASSERT_RETURN(method != nullptr && method[0] != '\0', 0); CARLA_SAFE_ASSERT_RETURN(types != nullptr, 0); + CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); if (fControlDataTCP.owner == nullptr) { @@ -291,230 +292,247 @@ int CarlaEngineOsc::handleMsgControl(const char* const method, return 0; } + const int32_t messageId = argv[0]->i; + bool ok; + +#define CARLA_SAFE_ASSERT_RETURN_OSC_ERR(cond) \ + if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); sendResponse(messageId, #cond); return 0; } + /**/ if (std::strcmp(method, "clear_engine_xruns") == 0) { + ok = true; fEngine->clearXruns(); } else if (std::strcmp(method, "cancel_engine_action") == 0) { + ok = true; fEngine->setActionCanceled(true); } else if (std::strcmp(method, "patchbay_connect") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 5, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); - CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0); - CARLA_SAFE_ASSERT_RETURN(types[2] == 'i', 0); - CARLA_SAFE_ASSERT_RETURN(types[3] == 'i', 0); - CARLA_SAFE_ASSERT_RETURN(types[4] == 'i', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 6); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 'i'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 'i'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 'i'); - const bool ext = argv[0]->i != 0; + const bool external = argv[1]->i != 0; - const int32_t i1 = argv[1]->i; - CARLA_SAFE_ASSERT_RETURN(i1 >= 0, 0); + const int32_t groupA = argv[2]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupA >= 0); - const int32_t i2 = argv[2]->i; - CARLA_SAFE_ASSERT_RETURN(i2 >= 0, 0); + const int32_t portA = argv[3]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portA >= 0); - const int32_t i3 = argv[3]->i; - CARLA_SAFE_ASSERT_RETURN(i3 >= 0, 0); + const int32_t groupB = argv[4]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupB >= 0); - const int32_t i4 = argv[4]->i; - CARLA_SAFE_ASSERT_RETURN(i4 >= 0, 0); + const int32_t portB = argv[5]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portB >= 0); - fEngine->patchbayConnect(ext, - static_cast(i1), - static_cast(i2), - static_cast(i3), - static_cast(i4)); + ok = fEngine->patchbayConnect(external, + static_cast(groupA), + static_cast(portA), + static_cast(groupB), + static_cast(portB)); } else if (std::strcmp(method, "patchbay_disconnect") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 2, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); - CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i'); - const bool ext = argv[0]->i != 0; + const bool external = argv[1]->i != 0; - const int32_t id = argv[1]->i; - CARLA_SAFE_ASSERT_RETURN(id >= 0, 0); + const int32_t connectionId = argv[2]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(connectionId >= 0); - fEngine->patchbayDisconnect(ext, static_cast(id)); + ok = fEngine->patchbayDisconnect(external, static_cast(connectionId)); } else if (std::strcmp(method, "patchbay_refresh") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i'); - const bool ext = argv[0]->i != 0; - fEngine->patchbayRefresh(false, true, ext); + const bool external = argv[1]->i != 0; + + ok = fEngine->patchbayRefresh(false, true, external); } else if (std::strcmp(method, "transport_play") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 0, argc, 0); + ok = true; fEngine->transportPlay(); } else if (std::strcmp(method, "transport_pause") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 0, argc, 0); + ok = true; fEngine->transportPause(); } else if (std::strcmp(method, "transport_bpm") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'f', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'f'); - const double f = argv[0]->f; - CARLA_SAFE_ASSERT_RETURN(f >= 0.0, 0); + const double bpm = argv[1]->f; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(bpm >= 0.0); - fEngine->transportBPM(f); + ok = true; + fEngine->transportBPM(bpm); } else if (std::strcmp(method, "transport_relocate") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2); + uint64_t frame; - /**/ if (types[0] == 'i') + /**/ if (types[1] == 'i') { - const int32_t i = argv[0]->i; - CARLA_SAFE_ASSERT_RETURN(i >= 0, 0); + const int32_t i = argv[1]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(i >= 0); frame = static_cast(i); } - else if (types[0] == 'h') + else if (types[1] == 'h') { - const int64_t h = argv[0]->h; - CARLA_SAFE_ASSERT_RETURN(h >= 0, 0); + const int64_t h = argv[1]->h; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(h >= 0); frame = static_cast(h); } else { carla_stderr2("Wrong OSC type used for '%s'", method); + sendResponse(messageId, "Wrong OSC type"); return 0; } + ok = true; fEngine->transportRelocate(frame); } else if (std::strcmp(method, "add_plugin") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 7, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); - CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0); - CARLA_SAFE_ASSERT_RETURN(types[2] == 's', 0); - CARLA_SAFE_ASSERT_RETURN(types[3] == 's', 0); - CARLA_SAFE_ASSERT_RETURN(types[4] == 's', 0); - CARLA_SAFE_ASSERT_RETURN(types[6] == 'i', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 8); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 's'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 's'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 's'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[7] == 'i'); - const int32_t btype = argv[0]->i; - CARLA_SAFE_ASSERT_RETURN(btype >= 0, 0); + const int32_t btype = argv[1]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(btype >= 0); - const int32_t ptype = argv[1]->i; - CARLA_SAFE_ASSERT_RETURN(ptype >= 0, 0); + const int32_t ptype = argv[2]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(ptype >= 0); - const char* filename = &argv[2]->s; + const char* filename = &argv[3]->s; if (filename != nullptr && std::strcmp(filename, "(null)") == 0) filename = nullptr; - const char* name = &argv[3]->s; + const char* name = &argv[4]->s; if (name != nullptr && std::strcmp(name, "(null)") == 0) name = nullptr; - const char* const label = &argv[4]->s; - CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0', 0); + const char* const label = &argv[5]->s; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(label != nullptr && label[0] != '\0'); int64_t uniqueId; - /**/ if (types[5] == 'i') + /**/ if (types[6] == 'i') { - uniqueId = argv[5]->i; + uniqueId = argv[6]->i; } - else if (types[5] == 'h') + else if (types[6] == 'h') { - uniqueId = argv[5]->h; + uniqueId = argv[6]->h; } else { carla_stderr2("Wrong OSC type used for '%s' uniqueId", method); + sendResponse(messageId, "Wrong OSC type"); return 0; } - const int32_t options = argv[6]->i; - CARLA_SAFE_ASSERT_RETURN(options >= 0, 0); + const int32_t options = argv[7]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(options >= 0); - fEngine->addPlugin(static_cast(btype), - static_cast(ptype), - filename, name, label, uniqueId, nullptr, static_cast(options)); + ok = fEngine->addPlugin(static_cast(btype), + static_cast(ptype), + filename, name, label, uniqueId, nullptr, static_cast(options)); } else if (std::strcmp(method, "remove_plugin") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i'); - const int32_t i = argv[0]->i; - CARLA_SAFE_ASSERT_RETURN(i >= 0, 0); + const int32_t id = argv[1]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0); - fEngine->removePlugin(static_cast(i)); + ok = fEngine->removePlugin(static_cast(id)); } else if (std::strcmp(method, "remove_all_plugins") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 0, argc, 0); - - fEngine->removeAllPlugins(); + ok = fEngine->removeAllPlugins(); } else if (std::strcmp(method, "rename_plugin") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 2, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); - CARLA_SAFE_ASSERT_RETURN(types[1] == 's', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 's'); - const int32_t i = argv[0]->i; - CARLA_SAFE_ASSERT_RETURN(i >= 0, 0); + const int32_t id = argv[1]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0); - const char* const s = &argv[1]->s; - CARLA_SAFE_ASSERT_RETURN(s != nullptr && s[0] != '\0', 0); + const char* const newName = &argv[2]->s; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(newName != nullptr && newName[0] != '\0'); - fEngine->renamePlugin(static_cast(i), s); + ok = fEngine->renamePlugin(static_cast(id), newName); } else if (std::strcmp(method, "clone_plugin") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i'); - const int32_t i = argv[0]->i; - CARLA_SAFE_ASSERT_RETURN(i >= 0, 0); + const int32_t id = argv[1]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0); - fEngine->clonePlugin(static_cast(i)); + ok = fEngine->clonePlugin(static_cast(id)); } else if (std::strcmp(method, "replace_plugin") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i'); - const int32_t i = argv[0]->i; - CARLA_SAFE_ASSERT_RETURN(i >= 0, 0); + const int32_t id = argv[1]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0); - fEngine->replacePlugin(static_cast(i)); + ok = fEngine->replacePlugin(static_cast(id)); } else if (std::strcmp(method, "switch_plugins") == 0) { - CARLA_SAFE_ASSERT_INT_RETURN(argc == 2, argc, 0); - CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0); - CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i'); + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i'); - const int32_t i0 = argv[0]->i; - CARLA_SAFE_ASSERT_RETURN(i0 >= 0, 0); + const int32_t idA = argv[1]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idA >= 0); - const int32_t i1 = argv[1]->i; - CARLA_SAFE_ASSERT_RETURN(i1 >= 0, 0); + const int32_t idB = argv[2]->i; + CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idB >= 0); - fEngine->switchPlugins(static_cast(i0), static_cast(i1)); + ok = fEngine->switchPlugins(static_cast(idA), static_cast(idB)); } else { carla_stderr2("Unhandled OSC control for '%s'", method); + sendResponse(messageId, "Unhandled OSC control method"); + return 0; } +#undef CARLA_SAFE_ASSERT_RETURN_OSC_ERR + + sendResponse(messageId, ok ? "" : fEngine->getLastError()); return 0; } diff --git a/source/backend/engine/CarlaEngineOscSend.cpp b/source/backend/engine/CarlaEngineOscSend.cpp index f1188c6d1..258d8e015 100644 --- a/source/backend/engine/CarlaEngineOscSend.cpp +++ b/source/backend/engine/CarlaEngineOscSend.cpp @@ -271,69 +271,29 @@ void CarlaEngineOsc::sendPluginInternalParameterValues(const CarlaPlugin* const ); } -#if 0 -void CarlaEngineOsc::sendset_program_count(const uint pluginId, const uint32_t count) const noexcept -{ - CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.path != nullptr && fControlDataTCP.path[0] != '\0',); - CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.target != nullptr,); - carla_debug("CarlaEngineOsc::sendset_program_count(%i, %i)", pluginId, count); - - char targetPath[std::strlen(fControlDataTCP.path)+19]; - std::strcpy(targetPath, fControlDataTCP.path); - std::strcat(targetPath, "/set_program_count"); - try_lo_send(fControlDataTCP.target, targetPath, "ii", static_cast(pluginId), static_cast(count)); -} - -void CarlaEngineOsc::sendset_midi_program_count(const uint pluginId, const uint32_t count) const noexcept -{ - CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.path != nullptr && fControlDataTCP.path[0] != '\0',); - CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.target != nullptr,); - carla_debug("CarlaEngineOsc::sendset_midi_program_count(%i, %i)", pluginId, count); - - char targetPath[std::strlen(fControlDataTCP.path)+24]; - std::strcpy(targetPath, fControlDataTCP.path); - std::strcat(targetPath, "/set_midi_program_count"); - try_lo_send(fControlDataTCP.target, targetPath, "ii", static_cast(pluginId), static_cast(count)); -} - -void CarlaEngineOsc::sendset_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept -{ - CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.path != nullptr && fControlDataTCP.path[0] != '\0',); - CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.target != nullptr,); - CARLA_SAFE_ASSERT_RETURN(name != nullptr,); - carla_debug("CarlaEngineOsc::sendset_program_name(%i, %i, \"%s\")", pluginId, index, name); - - char targetPath[std::strlen(fControlDataTCP.path)+18]; - std::strcpy(targetPath, fControlDataTCP.path); - std::strcat(targetPath, "/set_program_name"); - try_lo_send(fControlDataTCP.target, targetPath, "iis", static_cast(pluginId), static_cast(index), name); -} +// ----------------------------------------------------------------------- -void CarlaEngineOsc::sendset_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept +void CarlaEngineOsc::sendPing() const noexcept { CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.path != nullptr && fControlDataTCP.path[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.target != nullptr,); - CARLA_SAFE_ASSERT_RETURN(name != nullptr,); - carla_debug("CarlaEngineOsc::sendset_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name); - char targetPath[std::strlen(fControlDataTCP.path)+23]; + char targetPath[std::strlen(fControlDataTCP.path)+6]; std::strcpy(targetPath, fControlDataTCP.path); - std::strcat(targetPath, "/set_midi_program_data"); - try_lo_send(fControlDataTCP.target, targetPath, "iiiis", static_cast(pluginId), static_cast(index), static_cast(bank), static_cast(program), name); + std::strcat(targetPath, "/ping"); + try_lo_send(fControlDataTCP.target, targetPath, ""); } -#endif - -// ----------------------------------------------------------------------- -void CarlaEngineOsc::sendPing() const noexcept +void CarlaEngineOsc::sendResponse(const int messageId, const char* const error) const noexcept { CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.path != nullptr && fControlDataTCP.path[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(fControlDataTCP.target != nullptr,); + carla_debug("CarlaEngineOsc::sendExit()"); char targetPath[std::strlen(fControlDataTCP.path)+6]; std::strcpy(targetPath, fControlDataTCP.path); - std::strcat(targetPath, "/ping"); - try_lo_send(fControlDataTCP.target, targetPath, ""); + std::strcat(targetPath, "/resp"); + try_lo_send(fControlDataTCP.target, targetPath, "is", messageId, error); } void CarlaEngineOsc::sendExit() const noexcept diff --git a/source/frontend/carla_control.py b/source/frontend/carla_control.py index daf2a3311..f594d40b8 100755 --- a/source/frontend/carla_control.py +++ b/source/frontend/carla_control.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Carla Backend code (OSC stuff) -# Copyright (C) 2011-2015 Filipe Coelho +# Copyright (C) 2011-2019 Filipe Coelho # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -16,6 +16,11 @@ # # For a full copy of the GNU General Public License see the doc/GPL.txt file. +# ---------------------------------------------------------------------------------------------------------------------- +# Imports (Global) + +from PyQt5.QtCore import QEventLoop + # ------------------------------------------------------------------------------------------------------------ # Imports (Custom) @@ -51,6 +56,10 @@ class CarlaHostOSC(CarlaHostQtPlugin): self.lo_target_tcp_name = "" self.lo_target_udp_name = "" + self.lastMessageId = 1 + self.pendingMessages = [] + self.responses = {} + # ------------------------------------------------------------------- def printAndReturnError(self, error): @@ -97,6 +106,7 @@ class CarlaHostOSC(CarlaHostQtPlugin): #"save_plugin_state", ): path = "/ctrl/" + method + needResp = True elif method in (#"set_option", "set_active", @@ -118,10 +128,12 @@ class CarlaHostOSC(CarlaHostQtPlugin): #"randomize_parameters", ): pluginId = lines.pop(0) + needResp = False path = "/%s/%i/%s" % (self.lo_target_tcp_name, pluginId, method) elif method == "send_midi_note": pluginId = lines.pop(0) + needResp = False channel, note, velocity = lines if velocity: @@ -133,11 +145,35 @@ class CarlaHostOSC(CarlaHostQtPlugin): else: return self.printAndReturnError("invalid method '%s'" % method) + if len(self.pendingMessages) != 0: + return self.printAndReturnError("A previous operation is still pending, please wait") + args = [int(line) if isinstance(line, bool) else line for line in lines] #print(path, args) - lo_send(self.lo_target_tcp, path, *args) - return True + if not needResp: + lo_send(self.lo_target_tcp, path, *args) + return True + + messageId = self.lastMessageId + self.lastMessageId += 1 + self.pendingMessages.append(messageId) + + lo_send(self.lo_target_tcp, path, messageId, *args) + + while messageId in self.pendingMessages: + QApplication.processEvents(QEventLoop.AllEvents, 100) + + error = self.responses.pop(messageId) + + if not error: + return True + + self.fLastError = error + return False + + def sendMsgAndSetError(self, lines): + return self.sendMsg(lines) # ------------------------------------------------------------------- @@ -166,7 +202,7 @@ class CarlaControlServerTCP(Server): Server.__init__(self, proto=LO_TCP) if False: - host = CarlaHostPlugin() + host = CarlaHostOSC() self.host = host @@ -308,6 +344,13 @@ class CarlaControlServerTCP(Server): self.host._set_internalValue(pluginId, PARAMETER_PANNING, pan) self.host._set_internalValue(pluginId, PARAMETER_CTRL_CHANNEL, ctrlChan) + @make_method('/ctrl/resp', 'is') + def carla_resp(self, path, args): + self.fReceivedMsgs = True + messageId, error = args + self.host.responses[messageId] = error + self.host.pendingMessages.remove(messageId) + @make_method('/ctrl/exit', '') def carla_exit(self, path, args): self.fReceivedMsgs = True @@ -411,12 +454,10 @@ class HostWindowOSC(HostWindow): lo_target_tcp = Address(self.fOscAddressTCP) lo_server_tcp = CarlaControlServerTCP(self.host) lo_send(lo_target_tcp, "/register", lo_server_tcp.getFullURL()) - print(lo_server_tcp.getFullURL()) lo_target_udp = Address(self.fOscAddressUDP) lo_server_udp = CarlaControlServerUDP(self.host) lo_send(lo_target_udp, "/register", lo_server_udp.getFullURL()) - print(lo_server_udp.getFullURL()) except AddressError as e: err = e