From c255b0249f0342b8245442e974dc73021839ec6d Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Fri, 17 Mar 2023 11:58:28 +0100 Subject: [PATCH] Bugfix: support OSC source target by name with ID fix a confusion between targetting source by ID (number) and targetting a source name starting with a number. --- src/ControlManager.cpp | 31 +++++++++++++++++++++---------- src/ControlManager.h | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/ControlManager.cpp b/src/ControlManager.cpp index 52265f3..98b4129 100644 --- a/src/ControlManager.cpp +++ b/src/ControlManager.cpp @@ -57,6 +57,7 @@ void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m, { // regular expression to check for batch static std::regex osc_batch_reg_exp( OSC_BATCH ); + static std::regex osc_sourceid_reg_exp( OSC_SOURCEID ); char sender[IpEndpointName::ADDRESS_AND_PORT_STRING_LENGTH]; remoteEndpoint.AddressAndPortAsString(sender); @@ -186,17 +187,27 @@ void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m, } } } - // General case: try to identify the target + // #ID sources target + else if ( std::regex_match(target, osc_sourceid_reg_exp) ) + { + int i = 0; + std::string num = target.substr(1); + if ( BaseToolkit::is_a_number(num, &i)){ + Source *s = Mixer::manager().sourceAtIndex(i); + if (s) { + // apply attributes to source + if ( Control::manager().receiveSourceAttribute(s, attribute, m.ArgumentStream()) ) + // and send back feedback if needed + Control::manager().sendSourceAttibutes(remoteEndpoint, target, s); + } + else + Log::Info(CONTROL_OSC_MSG "Unknown target '%s' requested by %s.", target.c_str(), sender); + } + } + // General case: try to identify the target by name else { - // try to find source by index - Source *s = nullptr; - int sourceid = -1; - if ( BaseToolkit::is_a_number(target.substr(1), &sourceid) ) - s = Mixer::manager().sourceAtIndex(sourceid); - - // if failed, try to find source by name - if (s == nullptr) - s = Mixer::manager().findSource(target.substr(1)); + // try to find source by given name + Source *s = Mixer::manager().findSource(target.substr(1)); // if a source with the given target name or index was found if (s) { diff --git a/src/ControlManager.h b/src/ControlManager.h index 7010db7..68c071f 100644 --- a/src/ControlManager.h +++ b/src/ControlManager.h @@ -27,6 +27,7 @@ #define OSC_ALL "/all" #define OSC_SELECTION "/selection" +#define OSC_SOURCEID "(\\/)[[:digit:]]+$" #define OSC_BATCH "(\\/batch#)[[:digit:]]+$" #define OSC_CURRENT "/current" #define OSC_NEXT "/next"