How to generate a 0/1 List Based on Changes in zl.group Output?
Hi everyone,
I’m writing because I’m dealing with a fairly simple problem (I’m attaching the patch here).
From the patch, I get a list of integers coming out of zl.group as the result of an expr operation.
From this list, I’d like to generate another list made only of 0s and 1s: every time a number in the list is different from the previous one, the new list should output 1, otherwise 0.
For example, if zl.group outputs:
0 0 0 1 1 1 2 2 2 3 3 3 4 4
I would like to obtain:
1 0 0 1 0 0 1 0 0 1 0 0 1 0
How can I achieve this?
Thanks a lot!
The way I understand the question, shouldn't it go something like this?
Can't believe this solution @Florian1947 wasn't searchable in forums.
Really great for quick beat pattern maker!

I misunderstood and thought that you wanted to compare lists for changes,
not member to member in the list.
for that add this 2 objects to your patch

or simplify it a bit

Hi everyone!
Thanks a lot for your help — both solutions are great, really.
They both work very well, but I’ve noticed a small bug in both approaches.
When the value in the right inlet of expr (the white number box) decreases — for example going from 3 to 2 to 1 to 0 — everything works correctly and the output is as expected.
However, when the numbers in the right inlet increase (i.e., going from 0 to 1 to 2), the result is not correct until the value reaches 3. From 3 onward, everything works fine.
@SOURCE AUDIO — in your first solution this is very easy to see: if you first set the value to 1 or 0 and then switch to 2, the output is wrong.
@FLORIAN1947 — I tried integrating your solution into the patch (I’m pasting it here). Is the way I inserted it correct? Even in this case, increasing values from 0 to 2 don’t produce the correct list. What could be causing this?
Thanks again, a lot!!

I did not expect that you use right value as low as 0.
it makes no sense because it will produce same result as 1
because you are converting $f1/$f2 *$f3 to int.
if you wanted round to nearest then 1 would produce different result
in the middle of the list.
clear zl.change will give you 1 at first value on new list
no matter what the last value from previous one was.
that made the problem.

see difference between float to int and rounded

Wow! That's right. Thanks so much @SOURCE AUDIO — it works perfectly.
There’s only one small thing: as you can also see in your screenshot, when the right inlet is set to 0, the output is not a list of 0 0 0 0.
Instead, it behaves as if the value were 1.
Do you think this could be fixed? Thanks again!
I’m planning to use this list to quickly create black-and-white visual patterns in jit.matrix linked to rhythmic patterns, and having small values is very useful for this… Thanks a lot!
see my edited post.
no matter what new created list is
first number is a change.
If we take it that each new list does not care what previous one was.
@Livingston - I had neglected to reset the [int] object after each pass, and so it would always compare to the last number stored. In the given setup this works fine counting down, but not when counting up from zero.
correction:
Hi everyone!
I managed to fix the issue that occurred when the right inlet of expr was set to 0 — I simply added a sel 0 object at the top of the algorithm.
The only thing that still isn’t working is this: when the values in the right inlet and the middle inlet of expr are the same, the output should be a list of all 1s.
This only happens for certain values (I can’t figure out why). For some values in expr, the algorithm stops working properly when the two inlets are equal: instead of producing a list of increasing numbers (and therefore all 1s), some numbers get repeated, resulting in 0s at the end of the algorithm.
The values for which the algorithm doesn’t work correctly when the two inlets are equal are:2 (only when ascending), 22, 23, 26, 39, 43, 44, 45, 46, 47, 49, 50, 51, 52, 55, 58, 67, 69, 70, 71...
Is anyone else experiencing the same behavior?
Thanks so much for any help!
