From 61796c31797b2fdaf0ca6f26bc8dc1fdffff9a31 Mon Sep 17 00:00:00 2001 From: Stephane Alnet Date: Thu, 9 Feb 2023 22:06:16 +0100 Subject: [PATCH] Add support for setting host parameters in OSC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is meant to be used by e.g. small electronic widgets providing live values from potentiometers, switches, … --- src/CardinalCommon.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/CardinalCommon.cpp b/src/CardinalCommon.cpp index 64182cd..f08a597 100644 --- a/src/CardinalCommon.cpp +++ b/src/CardinalCommon.cpp @@ -310,6 +310,32 @@ static int osc_param_handler(const char*, const char* types, lo_arg** argv, int return 0; } +static int osc_host_param_handler(const char*, const char* types, lo_arg** argv, int argc, const lo_message m, void* const self) +{ + d_debug("osc_host_param_handler()"); + DISTRHO_SAFE_ASSERT_RETURN(argc == 2, 0); + DISTRHO_SAFE_ASSERT_RETURN(types != nullptr, 0); + DISTRHO_SAFE_ASSERT_RETURN(types[0] == 'i', 0); + DISTRHO_SAFE_ASSERT_RETURN(types[1] == 'f', 0); + + if (CardinalBasePlugin* const plugin = static_cast(self)->remotePluginInstance) + { + CardinalPluginContext* const context = plugin->context; + + const int paramId = argv[0]->i; + DISTRHO_SAFE_ASSERT_RETURN(paramId >= 0, 0); + + const uint uparamId = static_cast(paramId); + DISTRHO_SAFE_ASSERT_UINT2_RETURN(uparamId < kModuleParameterCount, uparamId, kModuleParameterCount, 0); + + const float paramValue = argv[1]->f; + + context->parameters[uparamId] = paramValue; + } + + return 0; +} + static int osc_screenshot_handler(const char*, const char* types, lo_arg** argv, int argc, const lo_message m, void* const self) { d_debug("osc_screenshot_handler()"); @@ -483,6 +509,7 @@ Initializer::Initializer(const CardinalBasePlugin* const plugin, const CardinalB DISTRHO_SAFE_ASSERT_RETURN(oscServerThread != nullptr,); lo_server_thread_add_method(oscServerThread, "/hello", "", osc_hello_handler, this); + lo_server_thread_add_method(oscServerThread, "/host-param", "if", osc_host_param_handler, this); lo_server_thread_add_method(oscServerThread, "/load", "b", osc_load_handler, this); lo_server_thread_add_method(oscServerThread, "/param", "hif", osc_param_handler, this); lo_server_thread_add_method(oscServerThread, "/screenshot", "b", osc_screenshot_handler, this);