Goto next positive value in a coll /

Buma's icon

Hi,
I'm using a Matrixctrl to set the active steps of a step sequencer. I use this solution and not a live.step because instead of having a linear loop like 1 to 8 I want to have the possibility to have a loop that goes for example 1 4 6 9 12.
The active steps (1) are stored in a coll (e;g: 2, 1; 12, 1; etc) and the steps which change (0) are removed from the coll. Maybe there's a better solution than a coll, I don't know.. (EXAMPLE 1)
Here's a patch:

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

The problem is that each time the state of a cell is changed, the whole set of cells states is sent; that's not good, especially with presets. The loop jumps each time a cell is changed

In the (EXAMPLE 2), the 32 steps are stored in the coll and have a value of 1 or 0 . It's a bit better but since I use the "next" message to output the next step number in the coll, I need to find a way to output only the entries that have a value of 0 and skip the other ones.

Is there a better way to do this than the solution shown in (EXAMPLE 3) ?

Thank you.

Source Audio's icon

I would be glad to help You, but I don't understand what You want to do.
Statements in above post are totaly contradictory - removing steps wit value 0,
outputing steps with values 0, omitting others ?????

Buma's icon

Ah yes, sorry :) It's always quite hard to explain.
I output the state of a matrixctrl in a coll, then I circle through this coll that is supposed to contain the steps that need to be played (they have a value of 1, coming from the matrixctrl). It drives a Bpatcher containing 32 live.step objects. Removing and adding entries in the coll is not the problem actually. (this process is simple and is contained in the subpatch)
My question was : Is the third example of the posted patch, the best way to "goto" an entry that has a value of 1 (or -n-) and skip the others ? Is there a better way to do this ? (because I encountered some stack overflow problems with this one) Is there an object which can receive a message like " goto next step (entry) that has a value of (n)" ?

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

This is simplified patch that does what You wanted, at least I hope I understood
correctly what coll should do.
And a suggestion to using multislider instead of matrix, it would allow a step to have other values than
just 1 or 0, according to multislider range.
I allways used multisliders for Step Sequencers.

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

Stack Overflow happens if all 32 Steps have a Value of 0.
Next Patch has a gate to avoid that.

Buma's icon

Hi! Thanks for the patch and all the advices and comments. That helps a lot. Next time I will consider using a multislider .
The solution you've posted is perfect. Thanks again !

Buma's icon

Actually, stack overflow happens also if only 1 step is active

Source Audio's icon

I can't reproduce stack overflow if 1 Step has positive value.
In that case each time next message is sent to coll, it runs thru all 32 steps
until it hits the one with positive value again.
So You must have changed something in the patch...

Buma's icon

Yes, sorry. actually, I had to modify something to prevent the skipped steps numbers from being sent. And the stack overflow comes from there. Now I've replaced the [message] (which was the cause) and a [i] seems to work a bit better

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

Buma's icon

I ended up with this solution. It could be improved but it works fine and most of all , changing presets or adding steps is quite smooth

In the final patch I will probably add a pipe 1n or something like that

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

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

Now that is alltogether another thing, if You want to just store Steps
with Value = 1 into coll, there is a simple solution, have a look in the patch.
Also mousefilter to have list sent only on mouse release...

Buma's icon

Oh great ! I didn't know the mousefilter object. Yes, storing only the active steps was the first plan shown in the EX 1 of the first patch, but the coll was not updated "smoothly" and that used to cause "jitter" on preset change. What we have tried to do before (looking for the next value > 0) is a bit risky. The stack overflow was not happening in the demo patch but when it was plugged to the real big patch, that was not working if the gap between two values of 1 was too big . Your solution is even simpler than funbuff or Route 1, I will try it out tomorrow. Thank you !

James Bradbury's icon

Just use multislider and list generators for sequencing. Look at 'fetch' message in the help file.

Buma's icon

HI James,
Now, I use a multislider to set the steps contained in the loop. These steps that have to be played are stored in a coll and a phasor or plugphasor sends a "next" message to the coll. That activates the correct live.step. That works really well. (Cycling through the coll to find the next active step with a value of 1 was not particularly efficient, that was the original goal of this thread)

but... now I'm looking for the best way to switch between presets very smoothly:

Let's say that:
The Pattern A contains the steps 1, 3, and 5
The pattern B contains the steps 5, 24 and 32

The presets are not stored in the coll but they are stored for the multislider so there's a lap of time that introduces a small "jittering" when I switch between presets. Maybe I should append the values of the multislider pattr to the coll and then remove the old ones once they have been "read". Updating the coll "on the fly" while it's "read" by the message "next" is obviously not the solution.

Multiple coll (one for each preset), a gate and a pipe could also work maybe ^^

Sorry, it's hard to explain :)

Buma's icon

The solution was quite simple in that case: just storing 1, 23; 2, 25; 3, 32; instead of 23, 1; etc. I will post a patch tomorrow ;)