Compare four values at once and other complicated logic (to me at least).

David Boldt's icon

I would like to make buttons that control multiple things at once. Incase all the elements that they control are in the same state (on/off) I would like to get a different behaviour out of the buttons than if the receiving elements they are going into are in different states.

So: 1 1 1 1 --> Instantly turn all elements off and then on again, repeat.
But: 1 0 1 0, 1 1 0 0, etc.. --> Only turn off elements on, and after that have all 4 elements behave normally (turn all off, all on, repeat).

Is there a way to compare all 4 elements at once? And only if all are on 1 or 0 change their state immediately. But if they are different, i.e. 1 0 1 0 only change the state of the 0s first to get them all to the same state (1) first?

I wonder if there is a good list comment. With a little help I could also get into more programming territory, but I am not experienced with that at all.


To complicate things further I also want to gate which of the four elements the buttons control (I'm building a special type of sequencer). I have installed four gates which can be triggered via toggle. These gate off the control to the four elements. So I can choose to control only elements 1, 2, and 4 or any combination. That would mean, that I don't want to always compare all four elements. Ideally I only compare what ever elements are "selected" to be controlled. Elements which are not selected should be dynamically left out of the comparison.

I would be very thankful for any pointers to useful commands or objects. If someone could maybe build a little example patch that would be absolutely incredible.

(If someone is interested I will try to share an example, but my file is very big and reliant on Push. So it would probably be better to make a whole new testing patch to share with you.)

Roman Thilenius's icon

this is asked here about every 4 weeks.

you can combine conditions´ results arithmetically using result+result for "OR" (at least one condition is true) and result*result for "AND" (all conditions must be true.)

for a version with a dynamic number of inputs i would just reset the unused ones to 0. (or 1 for NAND and NOR)

well, actually i would use... https://cycling74.com/forums/logic-gates

double_UG's icon

Please provide at least 10 characters

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.

__________________________

Wetterberg's icon

@sourcaudio; that looks like a device you already had up your sleeve?

I would look towards doing some binary fuckery - that's always good for sequencing!

Here's my little suggestion, that also hinges on zl.sum

Make a device that gathers together each value, but assigns them a value of 2^n. That way you can gather them all together in a list, sum them, but still know precisely which step was on/off:

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

Source Audio's icon

@wetterberg
not exactly ready on my sleeve, but I used similar logic to start/stop only recorded and synced loops in a multilooper with 16 tracks.
One could sync or desync recorded loops and group them for
playback.
Was easy to reduce and adapt.

Maybe one could do all this in a simpler way...



David Boldt's icon

@sourceaudio Wow! That system is pretty amazing to me! Exactly what I needed. I've quadrupled it 4 times so that I can use it for a 16 Step Sequencer. It will be made of four buttons on the Push controlling all 16 steps in groups of four depending on which groups I route them to. Love that combination of using router and zl.sum and lenght.

I gotta say, I don't really understand what zl.reg, zl.mth and thresh are doing above. Also the "if ... then ..." statement doesn't have an $i2 input. Can you maybe give me some pointers on that?


Thanks @all for the great pointers! Really shows to how deep this program goes.

My takeaways from this thread:

  • Using " * " as an AND gate for multiple inputs.

  • Using "router" for routing inputs and outputs and how to control.

  • Using "zl.length" and "zl.sum" to look for all ON all OFF

  • Looking into binary "fuckery" (lol) to give each ON/OFF state an individual symbol

  • ...

Source Audio's icon

in your patch zl.reg serves as storage of gate states.
That because on every button fire, patch has to check which control list members to check and control (gate states), and once it is clear which ones, indexes of active gates get sent to zl.mth to output selected controls states.
They then travel to zl.len, zl.sum etc to check if all are
ON, OFF or mixed.

thresh collects stream of single messages into a list.

That is needed because listfunnel - which is used to prepend indexes for each list member outputs itered pairs of index-value.

Thresh has default time of 10 ms, which can be modified if needed.Thresh is very handy to capture for example raw midi messages into a list....

than if object passes only indexes which have value > 0.
if object accepts also a list as input, not only direct input to inlets.
example: if $i1+$i2+$i3 > 10 then ok else no

For 16 steps .. could you not increase the list instead of making 4 copies of the same thing ?



David Boldt's icon

Ok thanks for the explanation! Copying the whole patch actually made a lot of sense, as I want to make a trigger sequencer in which I can activate multiple steps at once depending on the 4 buttons that gate this control. The upper row controls which quarter step I will change the 16ths notes of. So I can press 1.1 and 1.3 and give both the same rhythm. Thus getting 16 steps with 8 buttons. So I needed one gate for four steps anyways and four gates in total.

1.1, ..., 1.4 are the gates which route keypresses to diffrent 16ths steps

Wetterberg's icon

hah, I love this idea.

so if I understand it right you hold down a pad on the top row, and it'll let you program the four 16th notes within that beat?

I did something along those lines once, for the OG Lemur; a menu system where you went through branching options in the same manner; pads above re-route the pads below.