Forums > MaxMSP

how do i make a basic counter sequencer with ping pong mode?

April 16, 2013 | 11:01 am

hey,

how do i make a basic counter sequencer with ping pong mode?

(first – last – second first – second last etc)

can this be done in a very simple way?


April 16, 2013 | 12:27 pm

I would use 2 alternating counters for this.

– Pasted Max Patch, click to expand. –

April 16, 2013 | 12:31 pm

Just send "updown" message to the [counter] object.


April 16, 2013 | 1:41 pm

updown counts "1, 2, 3, 4… 15, 16, 15 ,14 … 3, 2, 1, 2" which isn’t what dear OP wants.

Alternating counters is good – what we do is drive everything from raw ticks in Live, so we aren’t using counters.
We derive 32 steps from the transport, and then modulo it out like this:

– Pasted Max Patch, click to expand. –

April 16, 2013 | 3:13 pm

@Wetterberg
It looks like your patch generates "1, 2, 3, 4… 15, 16, 15 ,14 …" (not what the OP wants).


April 16, 2013 | 6:35 pm

I would probably use something like coll or umenu to renumber the output of a linear counter.

– Pasted Max Patch, click to expand. –

April 16, 2013 | 10:52 pm

@broc whoops, must’ve pasted the wrong patch. huh…. that’s odd. Hang on. Thanks for checking! sorry OP!


April 16, 2013 | 10:55 pm

just checked… it probably just *looks* that way, but if you check with print or similar you’ll see the 1′s and 16′s repeated.


April 17, 2013 | 12:15 pm

> updown counts "1, 2, 3, 4… 15, 16, 15 ,14 … 3, 2, 1, 2" which isn’t what dear OP wants.

True, my fault ;-)

This is one of the problems very easy to solve in traditional text-based coding, but a bit harder in visual paradigm. In my opinion simplest solution should be javascripting…

Of course it is also possible by combining 2 [counter] object (driven by metro) or re-calculating transport data (maybe with [coll]… – it’s nice idea).


April 17, 2013 | 4:00 pm

It can also be solved with pure math, ie. without counters or coll.

– Pasted Max Patch, click to expand. –

April 17, 2013 | 4:23 pm

@broc I got this count out of your solution: 16, 2, 15, 3, 14, 4, 13, 5, 12, 6, 11, 7, 10, 8, 9, 1

@yaniki: I’d love to see your js for something like this. In my limited code capacity I can’t imagine it being simple.


April 17, 2013 | 5:01 pm

@Wetterberg
Yes, the count doesn’t contain the first ’1′ because it’s already sent at initialization.
Of course this may be changed depending on context.


April 17, 2013 | 5:08 pm

aaah, okay; I’ve misread OPs request.

I thought OP was looking for "1,2,3,4….15,16,16,15….4,3,2,1"


April 17, 2013 | 6:56 pm

@Wetterberg: I’d love to see your js for something like this. In my limited code capacity I can’t imagine it being simple.

It’s a bit like broc’s solution. For bang-driven counter:

var _current_step = 0;
var _number_of_steps = 16;

function bang()
{
_current_step += 1;
if(_current_step > _number_of_steps) _current_step = 0;
if(_current_step % 2 == 1)
{
outlet(0, _current_step / 2);
}
else
{
outlet(0, _number_of_steps – _current_step / 2);
}
}


April 17, 2013 | 7:02 pm

Oh, this is better (sorry):

var _current_step = 0;
var _number_of_steps = 16;

function bang()
{
_current_step += 1;
if(_current_step >= _number_of_steps) _current_step = 0;
if(_current_step % 2 == 1) outlet(0, _current_step / 2); else outlet(0, _number_of_steps – _current_step / 2);
}


April 17, 2013 | 8:50 pm

thanks, yaniki. Yeah, they’re more or less the exact same code as broc’s, only in js, I guess. Thanks for showing me.


April 17, 2013 | 9:18 pm

Note however that Javascript is generally not suited for controlling a sequencer because it may lead to inaccurate timing (running on low priority thread).


April 17, 2013 | 11:10 pm

oh yeah, definitely. But these simple examples give some nice insights for luddites like myself ;)


April 18, 2013 | 9:00 am

@broc: Note however that Javascript is generally not suited for controlling a sequencer because it may lead to inaccurate timing (running on low priority thread).

Agree – in this case your implementation is much better.


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