Sorting Midi Low to High

Aera's icon

I'm building a sort of arpeggiator. I want to sort incoming Midi from the lowest note to the highest note when playing a quantized chord into my device. 90% of the time the midi from Ableton actually is already sorted that way, so the first note that arrives is the lowest and I can happily use a Poly object.

But with some chord changes this does not work - usually if I only change one note in my chord from one to the next.

Is there a way to do this without too much latency? I've tried a few methods before but they all create some sort of latency. I hope I'm not asking for something impossible.

Wil's icon

Quick search brought this thread

Source Audio explained what to do

You can easily use zl.sort once list is grouped

But

What if chord is 3 notes, then next chord is 5 notes?

What if chord is 4 notes but only one note changes and 3 are held?

How does computer know what comes next when grouping?

Aera's icon

Thank you! Yes I've tried thresh and group with zl.sort but the latency is too high unfortunately. There's must be something quicker I hope.

Aera's icon

I mean off course there has to be some latency logically, but it should be a few samples only, since the notes arrive basically at the same time if I draw them in the note editor.

double_UG's icon

xxxxxxxxxxxxxxxxxxxxxxxx

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

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

Thanks! I guess I'll have to live with some delay. I updated your patch so that it uses my note on / off as well.

Aera's icon

Also works with a quickthresh

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

Roman Thilenius's icon

"since the notes arrive basically at the same time if I draw them in the note editor."

in theory, in live, midi events can be scheduled in ticks. in practice they will not arrive in the same speed in max4live as they were send by the sequencer. it is not as bad as sending them over a physical connection, but it is not immovable, either.

also, in theory, if you set two notes to the same logical time (and the same track) in an app like live, they are usually sent out ordered already. at least you should check that if live sorts or actually store and play the events in the order they have been created. (i dont know for sure)

quickthresh or thresh 1 usually work in practice, but there is no written warranty coming with that.

Source Audio's icon

as mentioned in that first link, you could use coll.

more of a question is how to play arpeggio with held notes

when number of held notes changes and they also get resorted.

here one example.

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

you can delete cellblock , it is just there to show held notes

Aera's icon

"they are usually sent out ordered already." In most cases they are, just any note that stays the same between two chords comes late. If I play c3 min and c3 maj it becomes 60, 63, 67 - 64, 60, 67.

I'll also take a look at the coll suggestion, that looks like just what I needed. Thank you.

Aera's icon

I found a 0ms latency solution by simply using a "delay" without any arguments, which I don't know why it works but it does. I guess it has to do with how high prio scheduling works. Would love to know why this actually does the trick.

You could also sort high to low or even scramble if you wanted to btw. I've tested this extensively on my system but maybe someone can make it break. I hope not.

This could actually be a standalone device to finally make m4l arpeggiators behave how they should (except Ableton's build in Arpeggiator which seems to sort properly internally)

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

Source Audio's icon

delay without argument defaults to delay 0.

but for you it blocks bang output untill it stops receiving.

that could work, depending on midi input speed

between notes.

try it with external keyboard, you will not get any sorting by pitch

because zl.group will collect only single numbers.

even very fast IAC buss on mac can't pass few notes that fast...

but maybe in Live which I don't use delay works different then in max ?

Aera's icon

This is only for quantizated chords. Non quantized chords (e.g. via keyboard) are fine to be sorted by order of playing, actually that is desired behaviour. Before this device I had to manually move the notes inside some chords by milliseconds only to get many Arpeggiators to use the correct sorting.

Attempting to sort manually played chords with 0 latency would be trying to break the laws of physics I guess.

Roman Thilenius's icon

if you knew in advance when a chord appears and how many notes it has, you can make it at least output right after the last note came in.