From fab965b5a2ce10ffe126fcec5875079594dbe1cd Mon Sep 17 00:00:00 2001 From: Giso Grimm Date: Wed, 8 May 2024 15:50:41 +0200 Subject: [PATCH] improve oscrelay --- manual/modoscrelay.tex | 12 +++++++++--- plugins/src/tascarmod_oscrelay.cc | 13 +++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/manual/modoscrelay.tex b/manual/modoscrelay.tex index f11f3e59..d21dc2b4 100644 --- a/manual/modoscrelay.tex +++ b/manual/modoscrelay.tex @@ -1,6 +1,6 @@ Relay OSC messages, e.g., for distribution of motion sensors. -\begin{snugshade} +\definecolor{shadecolor}{RGB}{255,230,204}\begin{snugshade} {\footnotesize \label{attrtab:oscrelay} Attributes of element {\bf oscrelay}\nopagebreak @@ -10,11 +10,17 @@ name & description (type, unit) & def.\\ \hline \hline -\indattr{url} & Target OSC URL (string) & {\tiny osc.udp://localhost:9000/}\\ +\indattr{newpath} & Replace incoming path with this path, or empty for no replacement (string) & \\ \hline \indattr{path} & Path filter, or empty to match any path (string) & \\ \hline -\indattr{newpath} & Replace incoming path with this path, or empty for no replacement (string) & \\ +\indattr{retval} & Return value: 0 = handle messages also locally, non-0 = do not handle locally (int32) & 1\\ +\hline +\indattr{startswith} & Forward only messags which start with this path (string) & \\ +\hline +\indattr{trimstart} & Trim startswith part of the path before forwarding (bool) & false\\ +\hline +\indattr{url} & Target OSC URL (string) & {\tiny osc.udp://localhost:9000/}\\ \hline \end{tabularx} } diff --git a/plugins/src/tascarmod_oscrelay.cc b/plugins/src/tascarmod_oscrelay.cc index bf7e0a15..4d355b8e 100644 --- a/plugins/src/tascarmod_oscrelay.cc +++ b/plugins/src/tascarmod_oscrelay.cc @@ -33,6 +33,7 @@ class oscrelay_t : public TASCAR::module_base_t { std::string url; std::string newpath; std::string startswith; + bool trimstart = false; lo_address target; int retval = 1; }; @@ -45,13 +46,19 @@ int oscrelay_t::osc_recv(const char* path, const char*, lo_arg**, int, int oscrelay_t::osc_recv(const char* lpath, lo_message msg) { - if(startswith.size() && (strcmp(lpath, startswith.c_str()) != 0)) + bool start_matched = startswith.size() && + (strlen(lpath) >= startswith.size()) && + (strcmp(lpath, startswith.c_str()) == 0); + if(startswith.size() && (!start_matched)) return retval; if(newpath.size()) { lo_send_message(target, newpath.c_str(), msg); return retval; } - lo_send_message(target, lpath, msg); + const char* trimmedpath = lpath; + if(start_matched) + trimmedpath = lpath + startswith.size(); + lo_send_message(target, trimmedpath, msg); return retval; } @@ -66,6 +73,8 @@ oscrelay_t::oscrelay_t(const TASCAR::module_cfg_t& cfg) "Replace incoming path with this path, or empty for no replacement"); GET_ATTRIBUTE(startswith, "", "Forward only messags which start with this path"); + GET_ATTRIBUTE_BOOL(trimstart, + "Trim startswith part of the path before forwarding"); GET_ATTRIBUTE(retval, "", "Return value: 0 = handle messages also locally, non-0 = do " "not handle locally");