Forums > Dev

OSC command formatting from an outlet

Jul 28 2011 | 4:07 am

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:
long ac;
t_atom av[7];
ac = 7;
SETLONG(av+0, 240);
SETLONG(av+1, 103);
SETLONG(av+2, 2);
SETLONG(av+3, a);
SETLONG(av+4, b);
SETLONG(av+5, c);
SETLONG(av+6, 247);
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?

Jul 28 2011 | 8:03 am

Yes, read that thread: At the end, I attached my howto as PDF. There is a description inside how OSC works with Max and a C# exampel.

Jul 28 2011 | 10:54 am


probably the best and easiest method would be to use sprintf(). See a brief description for instance here:

A more safe way would be to use std::string ( or std::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,

Viewing 3 posts - 1 through 3 (of 3 total)

Forums > Dev