OSC command formatting from an outlet
I am having a hard time understanding how to properly format a complex series of commands into a list to be sent out of an outlet for my object. I am doing the translation from .js to C and my C is not quite as fluent.
Regularly I use a command like this in the .js:
outlet(0, 240, 103,2, a, b, c, 247);
to be replaced by this in the C:
ac = 7;
outlet_anything(x->i_ob.o_outlet, ps_list, ac, av);
But now i need to replace this in .js:
outlet(0, "/board","/"+ (i-2), "/analog",command[i]);
resulting in something like "/board/2/analog/127"
(formatted to be OSC friendly
and I dont understand how to assemble the list properly.
any help or suggestions?
Yes, read that thread: http://cycling74.com/forums/topic.php?id=34378 At the end, I attached my howto as PDF. There is a description inside how OSC works with Max and a C# exampel.
probably the best and easiest method would be to use
sprintf(). See a brief description for instance here: http://www.gnu.org/s/hello/manual/libc/Formatted-Output-Functions.html
A more safe way would be to use
std::string (http://www.cplusplus.com/reference/string/string/) or
std::stringstream (http://www.cplusplus.com/reference/iostream/stringstream/ ), but for that you need to compile your code with a C++ compiler.
Here’s an example (note that I didn’t test the code, so it might contain small errors):
std::stringstream s; s < < "/board/" << i-2 << "/analog/" << command[i]; outlet_anything(x->i_ob.o_outlet, gensym(s.str.c_str), 0, NULL);
Hope this helps,