Forums > MaxMSP

Using fromsymbol but keeping zero padding?

April 5, 2014 | 2:29 am

I’ve got a bit of javascript code that is spitting out strings that I want to pack into a coll. What’s coming out of js is:

"1 0011"
"2 1011"
"3 0001"

etc…

Coll isn’t happy with them as is, but if I run them through fromsymbol I get:

1 11
2 1011
3 1

which is a problem.

The thing is the length of the string is dynamic (depending on what I feed javascript), so I can’t just have a single sprintf formatting it.

How does one convert a string of arbitrary length to a normal message while keeping the zero padding intact?


April 5, 2014 | 2:47 am

If you want zero padding, then you need symbols. Period.

Numbers are *values* and they are simply represented in an arbitrary display format that happens to be decimal (rather than binary or octal or hex or something else) and happens to trim unneeded zeros left and right.

You could use regexp to split the strings into an int followed by a symbol, but if it’s your JScript code, why don’t you just have the object give you what you need? Something like outlet(0, index, stringvalue).


April 5, 2014 | 3:24 am

Perfect!

The problem was I was packing the index into the string itself before spitting it out. I just changed it to add the index when spitting out and it works!

for (var i = 0; i < combinations.length; i++) {
outlet(0, i, combinations[i]);
}


April 5, 2014 | 3:30 am

This also works…

– Pasted Max Patch, click to expand. –

April 5, 2014 | 7:13 am

Ok, this is working to get it into coll, but it looks like I can’t iterate it once it comes out of coll as it’s still a single symbol.

I want to be able to convert the coll contents into a matrixctrl (which then controls a USB-MIDI relay thing).

This is what seems like it would work, but doesn’t because of the symbol-ness of coll’s contents.

– Pasted Max Patch, click to expand. –

April 5, 2014 | 9:02 am

I figured I out. I converted the string from "0011" to "0 0 1 1" in js then [fromsymbol] does the trick in Max.

– Pasted Max Patch, click to expand. –

April 5, 2014 | 12:49 pm

Couldn’t get that last one to work.

Here’s another way from a bit symbol to matrixcrl.

– Pasted Max Patch, click to expand. –

April 5, 2014 | 12:52 pm

Ah nice!

More elegant than my solution anyways.


April 5, 2014 | 7:58 pm

hmm.. that zl.join is completely useless. Not sure why it’s there. Remove at leisure. :)


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