I have this with my s_minimoog to emulate how the minimoog keyboard allows lowest notes to be played and automatically changes the frequency to the next highest note when the lowest is let go.

Here’s the keytracking part, you’ll need rjlib and rc-patches for the list abstraction parts (or list-abs where some of them come from).

The basic idea is to keep a running count of the number of keys held down to know when you get a first attack and final release. The second part is to choose the lowest note and I use list unique, list sort, & list map to keep a sorted list of unique notes that I can add and remove from.