This is the start of a custom note allocator for poly~. I made this because, suppose there are sustained note and many short notes. After a number of short notes, the poly~ object truncates the sustained note, because it assigns poly resources round-robin, or in other words, cyclically.
For example, say there are three voices in a poly~. When receiving new notes, the poly~ object seems to assign the incoming notes in cyclic, or round-robin, order…to voice #1, #2, #3, and back to number #1 . Now imagine the first note is still sustained when the fourth arrives. Even if the second and third notes have already been released, poly~ assigns the fourth note to instance 1 and cuts off the sustained note.
This LRU-based algorithm instead assigns new notes to the voice with the oldest note which has already been turned off. What surprises me is, MAX has been around for– what–30 years now? And still there is no patch I know of which doesn’t assign new notes to poly instances in a cyclic style. Trying to make it in Max.
This is more difficult than it appears, because after a mix of long and short notes, the order of voice assignment is no longer cyclic. So here is my current design, but I'm not quite sure how to package it to share?