Skip to content

Commit

Permalink
improve oscrelay
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed May 8, 2024
1 parent de15ab0 commit fab965b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 9 additions & 3 deletions manual/modoscrelay.tex
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}
}
Expand Down
13 changes: 11 additions & 2 deletions plugins/src/tascarmod_oscrelay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
}

Expand All @@ -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");
Expand Down

0 comments on commit fab965b

Please sign in to comment.