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

Apr 16, 2013 at 11:01am

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

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?

#67736
Apr 16, 2013 at 12:27pm

I would use 2 alternating counters for this.

– Pasted Max Patch, click to expand. –
#243608
Apr 16, 2013 at 12:31pm

Just send “updown” message to the [counter] object.

#243609
Apr 16, 2013 at 1:41pm

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. –
#243610
Apr 16, 2013 at 3:13pm

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

#243611
Apr 16, 2013 at 6:35pm

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

– Pasted Max Patch, click to expand. –
#243612
Apr 16, 2013 at 10:52pm

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

#243613
Apr 16, 2013 at 10:55pm

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.

#243614
Apr 17, 2013 at 12:15pm

> 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).

#243615
Apr 17, 2013 at 4:00pm

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

– Pasted Max Patch, click to expand. –
#243616
Apr 17, 2013 at 4:23pm

@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.

#243617
Apr 17, 2013 at 5:01pm

@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.

#243618
Apr 17, 2013 at 5:08pm

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″

#243619
Apr 17, 2013 at 6:56pm

@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);
}
}

#243620
Apr 17, 2013 at 7:02pm

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);
}

#243621
Apr 17, 2013 at 8:50pm

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

#243622
Apr 17, 2013 at 9:18pm

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

#243623
Apr 17, 2013 at 11:10pm

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

#243624
Apr 18, 2013 at 9:00am

@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.

#243625

You must be logged in to reply to this topic.