Forums > MaxMSP

parsing OSC messages…

November 12, 2006 | 11:36 am

I am a Lemur user and I am trying to parse messages that are created by default (based upon my object creation) by the Jazzmutuant Lemur/JazzEditor, in Max. These messages come out as a long word such as "/Lem40j/Press_0/x 0" or "/Lem40j/Press_12/x 3" … which are mixed with words, decimals, and other symbols…

I saw the post on using the object ‘regexp’ to parse out things from entire words, but am not able to understand all the messages, etc, in the reference manual for this object in order to apply it to my specific application. I specifically would like to be able to change "/" or "_" symbols to spaces and then be able to further unpack the symbol into individual digits contained within…

Here is an example of what I would like to parse:

from message:

"/Lem40j/Press_0/x 0"

to

"40 0 0" or at least "Lem 40 j Press 0 x 0"

or

"/Lem40j/Press_12/x 3"

to

"40 12 3" or at least "Lem 40 j Press 12 x 3"

Is this possible with ‘regexp’ or maybe another object?

Really, if I could just change a "/" to a "space", my problems could be mostly solved.

But also, to know how to change any other basic digit, letter, or series of letters to "spaces" (to create a list!), would be a wonderful thing to know.

It seems that I basically need the opposite of what the ‘tosymbol’ object does… instead of taking a list and creating a single symbol with "/"s instead of spaces using the message:"separator /" … I want to take a symbol with "/"s and replace those "/"s with "space"s and create a list.

As a complimentry object, one would think that the ‘fromsymbol’ object would do this… but it doesn’t!

Thank for any help!

-Tyco


November 12, 2006 | 12:10 pm

Hey, I think this is what you’re looking for:

http://www.cnmat.berkeley.edu/OpenSoundControl/Max/

Greets,
Mattijs


November 12, 2006 | 2:06 pm

I think you’re looking for the [OSC-route] external from CNMAT.
it’s made for parsing the URL-style paths in the OpenSoundControl
protocol.

"/Lem40j/Press_12/x 3" would be parsed by: [OSC-route Lem40j] -> [OSC-
route Press_12] -> [OSC-route x]

to replace any one character by another in a symbol i’d use regexp
like so:
[regexp @re ([/]*) @substitute " "]

or if all you want is to slice one symbol into substrings at a
specific character use my [strtok] external from the standard C
functions. -> http://www.jasch.ch/dl/

full patch see below

hth

/*j

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 37 419 38 196617 strtok;
#P comment 37 278 41 196617 regexp;
#P message 324 353 22 196617 set;
#P message 108 300 131 196617 "/Lem40j/Press_12/x 3";
#P window linecount 0;
#P message 108 369 238 196617;
#P window linecount 1;
#P newex 108 348 62 196617 prepend set;
#P newex 108 324 166 196617 regexp @re ([/]*) @substitute " ";
#P message 325 544 22 196617 set;
#P number 230 97 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 175 503 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 108 485 51 196617 zl slice 1;
#P newex 108 461 64 196617 fromsymbol;
#P window linecount 0;
#P message 108 560 238 196617;
#P window linecount 1;
#P newex 108 540 62 196617 prepend set;
#P message 108 437 131 196617 "/Lem40j/Press_12/x 3";
#P newex 108 519 47 196617 strtok /;
#P number 181 230 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 181 189 72 196617 OSC-route /x;
#P message 230 116 127 196617 /Lem40j/Press_12/x $1;
#P number 108 96 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 108 230 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 108 189 72 196617 OSC-route /x;
#P newex 108 164 157 196617 OSC-route /Press_0 /Press_12;
#P newex 108 140 100 196617 OSC-route /Lem40j;
#P message 108 116 121 196617 /Lem40j/Press_0/x $1;
#P comment 160 523 238 196617 slice string into substrings at
delimiter -> e.g. "/";
#P comment 37 51 57 196617 OSC-route;
#P connect 24 0 22 0;
#P connect 23 0 20 0;
#P connect 20 0 21 0;
#P connect 21 0 22 0;
#P connect 19 0 14 0;
#P connect 3 0 4 0;
#P connect 8 0 3 0;
#P connect 2 0 3 0;
#P connect 18 0 8 0;
#P connect 13 0 14 0;
#P connect 11 0 13 0;
#P connect 16 1 17 0;
#P connect 15 0 16 0;
#P connect 16 0 11 0;
#P connect 12 0 15 0;
#P connect 9 0 10 0;
#P connect 4 1 9 0;
#P connect 4 0 5 0;
#P connect 7 0 2 0;
#P connect 5 0 6 0;
#P window clipboard copycount 27;


November 12, 2006 | 6:36 pm

Thanks so much for your replies.

jasch-

That definitely seems to cover all that I want/need to do. Your [strtok] object especially is wonderful… Very simple (especially compared to regexp!) and intuitive. Exactly what I was hoping existed. Thank you very much!

Cheers!


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