From 5a6daf79b6f24d3df936c48439336d4c23e00a6a Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Thu, 13 Oct 2022 17:34:17 +0200 Subject: [PATCH] Allow Nil Values in OSC messages Allows providing only one argument value when two (e.g. x and y) are required by specifying the NIL type ('N') in the OSC message. E.g. /vimix/current/position Nf 0.5 sets the Y position. --- ControlManager.cpp | 65 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/ControlManager.cpp b/ControlManager.cpp index 06d88d1..2726313 100644 --- a/ControlManager.cpp +++ b/ControlManager.cpp @@ -622,33 +622,76 @@ bool Control::receiveSourceAttribute(Source *target, const std::string &attribut /// e.g. '/vimix/current/grab ff 10.0 2.2' else if ( attribute.compare(OSC_SOURCE_GRAB) == 0) { float x = 0.f, y = 0.f; - arguments >> x >> y >> osc::EndMessage; + try { + arguments >> x; + } + catch (osc::WrongArgumentTypeException &) { + } + try { + arguments >> y; + } + catch (osc::WrongArgumentTypeException &) { + } + arguments >> osc::EndMessage; target->call( new Grab( x, y, 0.f), true ); } /// e.g. '/vimix/current/position ff 10.0 2.2' else if ( attribute.compare(OSC_SOURCE_POSITION) == 0) { - float x = 0.f, y = 0.f; - arguments >> x >> y >> osc::EndMessage; Group transform; transform.copyTransform(target->group(View::GEOMETRY)); - transform.translation_.x = x; - transform.translation_.y = y; + try { + float val = 0.f; + arguments >> val; + transform.translation_.x = val; + } + catch (osc::WrongArgumentTypeException &) { + } + try { + float val = 0.f; + arguments >> val; + transform.translation_.y = val; + } + catch (osc::WrongArgumentTypeException &) { + } + arguments >> osc::EndMessage; target->call( new SetGeometry( &transform, 0.f), true ); } - /// e.g. '/vimix/current/scale ff 10.0 2.2' + /// e.g. '/vimix/current/resize ff 10.0 2.2' else if ( attribute.compare(OSC_SOURCE_RESIZE) == 0) { float x = 0.f, y = 0.f; - arguments >> x >> y >> osc::EndMessage; + + try { + arguments >> x; + } + catch (osc::WrongArgumentTypeException &) { + } + try { + arguments >> y; + } + catch (osc::WrongArgumentTypeException &) { + } + arguments >> osc::EndMessage; target->call( new Resize( x, y, 0.f), true ); } /// e.g. '/vimix/current/size ff 1.0 2.2' else if ( attribute.compare(OSC_SOURCE_SIZE) == 0) { - float x = 0.f, y = 0.f; - arguments >> x >> y >> osc::EndMessage; Group transform; transform.copyTransform(target->group(View::GEOMETRY)); - transform.scale_.x = x; - transform.scale_.y = y; + try { + float val = 0.f; + arguments >> val; + transform.scale_.x = val; + } + catch (osc::WrongArgumentTypeException &) { + } + try { + float val = 0.f; + arguments >> val; + transform.scale_.y = val; + } + catch (osc::WrongArgumentTypeException &) { + } + arguments >> osc::EndMessage; target->call( new SetGeometry( &transform, 0.f), true ); } /// e.g. '/vimix/current/turn f 1.0'