back and forth counter with repeating values?

meeble's icon

hey folks,

What's the simplest way to make the counter object go back and forth like this:

0 1 2 3
3 2 1 0
0 1 2 3
3 2 1 0
etc.

seejayjames's icon

set the range to 1 greater in each direction, so [counter -1 4 2] for your example.

add a [sel -1 4] object to the output. The rightmost outlet of [sel] lets the values out that you want. Both of the other two should bang the counter so there's no appreciable delay as it hits the extreme values, then it'll go back into the range of values you want. You could use [split] in the same way.

Try it out, I can't try it here so maybe there's stuttering, but I think it should be OK...

roger.carruthers's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I asked the same question years ago, and someone kindly provided me with this (you are excused for not finding it via a search, because it would have been on the old McGill mailing list ;-)
Inlets are count min and max,
Cheer
Roger

meeble's icon

seejayjames,

thanks but that gives me this output:

0 1 2 3 3
3 2 1 0 0
0 1 2 3 3
3 2 1 0 0
etc.

meeble's icon

thanks, Roger, I will check out your patch!

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Here's an abstraction that I call CounterSeeSaw:

Wetterberg's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I did it with [split] and like four other objects - this is about as small as I can get it, I think.

meeble's icon

Thanks, Chris. That works!

Wetterberg: Thank you. Yours is definitely the simplest solution that works. Although, when I tried to modify it to work with different number ranges, I quickly broke it. :

meeble's icon

Wetterberg,

Max Patch
Copy patch and select New From Clipboard in Max.

Never mind what I said about breaking it - also, I don't think the modulo is needed, see this patch...

Chris Muir's icon

Well, if object count is paramount, here's my CounterSeeSaw with the two routes replaced by one sel. :-) I'm still up a couple of message boxes, though.

Max Patch
Copy patch and select New From Clipboard in Max.

It's worth noting that CounterSeeSaw can count between arbitrary ranges, e.g. 1-4, 10-20

Wetterberg's icon

yeah, the modulo is left over from the patch it's copied from - it normally hooks into [transport]

meeble's icon

Chris,

Your design is the most user friendly, no doubt. :)

Peter Castine's icon

@Nicolas — génial !!

meeble's icon

yes, very interesting bit of math there, Nicolas. :)