Forums > MaxMSP

Adding spaces to the middle of a 3digit number (131 turning into 1 3 1)

February 29, 2012 | 9:22 am

I’m trying to implement a streamlined way of sending a matrixctrl (8×8) amount of data, by only sending the messages that have changed.

I’m using sprintf to strip spaces (so 1 3 1 becomes 131) then using zl group and zl unique to spit out the unique changes, and this is all working well (did a workaround to avoid stripping leading zeros).

The problem I’m having now is turning the 3digit numbers I have on my output back into 3 digit lists (131 to 1 3 1).

I did some searching on the forum but I couldn’t find out how to keep a number intact, but with spaces in it, using sprintf.

The intended usage for this is to send LED data to a monome but efficiently (so I only send what needs to be changed, and not a a ton of data).

Here’s the patch:

– Pasted Max Patch, click to expand. –

February 29, 2012 | 9:48 am

hi Rodrigo,
does this help? although it avoids sprintf

– Pasted Max Patch, click to expand. –

February 29, 2012 | 9:53 am

Hi rodrigo, here is a possible solution

– Pasted Max Patch, click to expand. –

there must be a cleaner solution but I could not think of it right now


February 29, 2012 | 9:56 am

ok, this is cleaner

– Pasted Max Patch, click to expand. –

February 29, 2012 | 9:56 am

kthozoid, your thresh will be tricky with fast messages


February 29, 2012 | 9:59 am

Timo, agreed, the time based nature of it poses a risk. your 2nd solution seems the most elegant.


February 29, 2012 | 11:48 am

how about this as a solution

– Pasted Max Patch, click to expand. –

just using regex


February 29, 2012 | 3:03 pm

Interesting math solution Timo, though it’s hard to beat the regex example.


February 29, 2012 | 3:24 pm

yeah regexp ftw :-)
though I am always confused, need to read more tutorials… but that’s low priority



Ch
February 29, 2012 | 11:44 pm

I usually use something that is kind of a mix between the patches of kthozoid and timo :

– Pasted Max Patch, click to expand. –

the advantage of that kind of solution is that you can have any numbers of digits.
Is there any way to have a regexp solution that would work with any ‘length’?
would be great


March 1, 2012 | 5:51 am

ha, yeah timo’s last idea was the one I was going with, too.


March 1, 2012 | 5:52 am

@ch you can do a loop and iterate through the list with the regexp patch and then zl group at the end.


March 1, 2012 | 9:03 am

@ch @wetterberg you mean like this?

– Pasted Max Patch, click to expand. –

March 1, 2012 | 9:11 am

took me a while to figure that one out, seems that @substitute has the perl /g equiv in there …



Ch
March 1, 2012 | 11:40 am

@ch @wetterberg you mean like this?

yes exactly!


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