From f74e17706d275b24a7b01660121dbafd963d9563 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Mon, 28 Jul 2025 16:57:59 +0900 Subject: [PATCH 1/3] Check for end of client name in path Otherwise a path like /Carlaz0/... works. Signed-off-by: Asahi Lina --- source/backend/engine/CarlaEngineOscHandlers.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/backend/engine/CarlaEngineOscHandlers.cpp b/source/backend/engine/CarlaEngineOscHandlers.cpp index 1258c302c..fdc6332f1 100644 --- a/source/backend/engine/CarlaEngineOscHandlers.cpp +++ b/source/backend/engine/CarlaEngineOscHandlers.cpp @@ -87,7 +87,8 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, { bytesAfterName = fName.length(); - if (std::strlen(path) <= bytesAfterName || std::strncmp(path+1, fName, bytesAfterName) != 0) + if (std::strlen(path) <= bytesAfterName || std::strncmp(path+1, fName, bytesAfterName) != 0 || + path[bytesAfterName+1] != '/') { carla_stderr("CarlaEngineOsc::handleMessage() - message not for this client -> '%s' != '/%s/'", path, fName.buffer()); From 8e813ef9c9d36c9bac6bccd8e78380a8e60e3e94 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Mon, 28 Jul 2025 17:17:27 +0900 Subject: [PATCH 2/3] OSC: Allow looking up plugins by name as well as ID Signed-off-by: Asahi Lina --- .../backend/engine/CarlaEngineOscHandlers.cpp | 73 ++++++++++--------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/source/backend/engine/CarlaEngineOscHandlers.cpp b/source/backend/engine/CarlaEngineOscHandlers.cpp index fdc6332f1..fe57ff5ab 100644 --- a/source/backend/engine/CarlaEngineOscHandlers.cpp +++ b/source/backend/engine/CarlaEngineOscHandlers.cpp @@ -100,63 +100,66 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, // Get plugin id from path, "/carla/23/method" -> 23 uint pluginId = 0; - std::size_t offset; - if (! std::isdigit(path[bytesAfterName+1])) + const char* const pluginPath = &path[bytesAfterName+1]; + std::size_t pluginLen; + if (const char* const slash = std::strchr(pluginPath, '/')) { - carla_stderr("CarlaEngineOsc::handleMessage() - invalid message '%s'", path); + pluginLen = slash - pluginPath; + } + else + { + carla_stderr("CarlaEngineOsc::handleMessage() - message '%s' is invalid", path); return 1; } - if (std::isdigit(path[bytesAfterName+2])) - { - if (std::isdigit(path[bytesAfterName+4])) - { - carla_stderr2("CarlaEngineOsc::handleMessage() - invalid plugin id, over 999? (value: \"%s\")", - path+bytesAfterName); - return 1; - } - else if (std::isdigit(path[bytesAfterName+3])) + CarlaPluginPtr plugin = nullptr; + bool isNumeric = true; + for (std::size_t i = 0; i < pluginLen; i++) { + if (! std::isdigit(pluginPath[i])) { - // 3 digits, /xyz/method - offset = 5; - pluginId += uint(path[bytesAfterName+1]-'0')*100; - pluginId += uint(path[bytesAfterName+2]-'0')*10; - pluginId += uint(path[bytesAfterName+3]-'0'); + isNumeric = false; + break; } - else + } + if (pluginLen <= 4 && isNumeric) + { + pluginId = atoi(pluginPath); + + if (pluginId > fEngine->getCurrentPluginCount()) { - // 2 digits, /xy/method - offset = 4; - pluginId += uint(path[bytesAfterName+1]-'0')*10; - pluginId += uint(path[bytesAfterName+2]-'0'); + carla_stderr("CarlaEngineOsc::handleMessage() - failed to get plugin, wrong id '%i'", pluginId); + return 0; } + + // Get plugin + plugin = fEngine->getPluginUnchecked(pluginId); + } else { - // single digit, /x/method - offset = 3; - pluginId += uint(path[bytesAfterName+1]-'0'); - } + for (pluginId = 0; pluginId < fEngine->getCurrentPluginCount(); pluginId++) + { + plugin = fEngine->getPluginUnchecked(pluginId); - if (pluginId > fEngine->getCurrentPluginCount()) - { - carla_stderr("CarlaEngineOsc::handleMessage() - failed to get plugin, wrong id '%i'", pluginId); - return 0; - } + carla_stderr("%s %s %d\n", plugin->getName(), pluginPath, pluginLen); + if (strlen(plugin->getName()) == pluginLen && !strncmp(plugin->getName(), pluginPath, pluginLen)) { + break; + } - // Get plugin - const CarlaPluginPtr plugin = fEngine->getPluginUnchecked(pluginId); + plugin = nullptr; + } + } if (plugin == nullptr || plugin->getId() != pluginId) { - carla_stderr("CarlaEngineOsc::handleMessage() - invalid plugin id '%i', probably has been removed (path: '%s')", pluginId, path); + carla_stderr("CarlaEngineOsc::handleMessage() - plugin not found, probably has been removed (path: '%s')", path); return 0; } // Get method from path, "/Carla/i/method" -> "method" char method[48]; - std::strncpy(method, path + (bytesAfterName + offset), 47); + std::strncpy(method, &pluginPath[pluginLen + 1], 47); method[47] = '\0'; if (method[0] == '\0') From 49c5d16cc9c410d6083cb2e43effa5298e2cef17 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Mon, 28 Jul 2025 17:20:05 +0900 Subject: [PATCH 3/3] Help: Update OSC help text to document plugin lookup by name Signed-off-by: Asahi Lina --- source/backend/engine/CarlaEngineOscHandlers.cpp | 1 - source/frontend/C++/carla_widgets.cpp | 3 ++- source/frontend/dialogs/aboutdialog.cpp | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/backend/engine/CarlaEngineOscHandlers.cpp b/source/backend/engine/CarlaEngineOscHandlers.cpp index fe57ff5ab..696a45079 100644 --- a/source/backend/engine/CarlaEngineOscHandlers.cpp +++ b/source/backend/engine/CarlaEngineOscHandlers.cpp @@ -142,7 +142,6 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, { plugin = fEngine->getPluginUnchecked(pluginId); - carla_stderr("%s %s %d\n", plugin->getName(), pluginPath, pluginLen); if (strlen(plugin->getName()) == pluginLen && !strncmp(plugin->getName(), pluginPath, pluginLen)) { break; } diff --git a/source/frontend/C++/carla_widgets.cpp b/source/frontend/C++/carla_widgets.cpp index c6e176ad1..97322dee8 100644 --- a/source/frontend/C++/carla_widgets.cpp +++ b/source/frontend/C++/carla_widgets.cpp @@ -118,7 +118,8 @@ struct CarlaAboutW::PrivateData { ""); ui.l_example->setText("/Carla/2/set_parameter_value 5 1.0"); - ui.l_example_help->setText("(as in this example, \"2\" is the plugin number and \"5\" the parameter)"); + ui.l_example_help->setText("(In this example, \"2\" is the plugin number and \"5\" the parameter.
" + "Plugins can also be referenced by their name.)
"); ui.l_ladspa->setText(tr("Everything! (Including LRDF)")); ui.l_dssi->setText(tr("Everything! (Including CustomData/Chunks)")); diff --git a/source/frontend/dialogs/aboutdialog.cpp b/source/frontend/dialogs/aboutdialog.cpp index 0174472f6..bc462cff0 100644 --- a/source/frontend/dialogs/aboutdialog.cpp +++ b/source/frontend/dialogs/aboutdialog.cpp @@ -72,7 +72,8 @@ AboutDialog::AboutDialog(QWidget* const parent, ""); ui.l_example->setText("/Carla/2/set_parameter_value 5 1.0"); - ui.l_example_help->setText("(as in this example, \"2\" is the plugin number and \"5\" the parameter)"); + ui.l_example_help->setText("(In this example, \"2\" is the plugin number and \"5\" the parameter.
" + "Plugins can also be referenced by their name.)
"); ui.l_ladspa->setText(tr("Everything! (Including LRDF)")); ui.l_dssi->setText(tr("Everything! (Including CustomData/Chunks)"));