Using matrixctrl values as weighted probability for gate

izo's icon

I’m trying to take the values from the third row of a matrixctrl (in dial mode) and use them as weighted probabilities to control how likely the gate opens on each step, but I haven’t been able to figure out which objects would be best for handling the probability logic. Basically the value of the dial for each step determines how likely the gate is open so it triggers the sound.

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

TFL's icon

Every time the sound is supposedly triggered, generate a random float between 0 and 1, compare it with your weight, if the generated number is below your weight then trigger the sound. Do nothing otherwise. You'll need [random @range 0. 1.] [< 0.] and [sel 0].

Source Audio's icon

if resoultion of 100 is enough,

use dial value as percentage, set table with 2 % values for 0 & 1

and bang it out.

max 8.6 and higher can use random in float mode.

that gives you other options.

otherwise you can create pool of 100

0 or 1 values and pick one randomly

izo's icon

Ok I think I've managed to create some weighted probabilities using the 2nd row of the matrixctrl but I have some issues with the accuracy. I'm sending a 0 or 1 message to the gate but it doesn't seem to work too well. If I have a dial turned all the way up it should trigger the sound but it only works somewhat if I turn up the dial right next to it. Is the gate too slow or do I need to use a different object?

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

Source Audio's icon

you should post only part in question and compressed.

There is no need to look into the rest of it.

why do you use 2 counters ?

want to run them in different speeds or direction ?

if not, get rid of the 2nd one.

then send counter first to gate matrix, and after that to whatever gate needs to pass through.

in other words, follow order of execution, you need gate state before you cook

value that needs to pass through or not.

trigger object is best for that.

this is your random compared to value gate example

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

izo's icon

Thanks for sharing your patch, it definitely helped. I had to adjust the trigger slightly to get it working in my setup, but it’s now doing exactly what I wanted: using the second row for probability and velocity control of an audio sample. It turns out placing everything after the trigger object was the key. Also, the $ trick for pulling data from the second row was really nice, I learned a few things from this.

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