Polyphonic Keyboard Latch

Today’s excursion in to envelope land has been a welcome diversion from my current project. I’m attempting to build a clone of the Arpeggiator on my new UltraNova. I don’t think I’ll be able to replicate it exactly but I think I can come close. One of the features is a keyboard latch which will capture notes as they are played. The original captures eighteen notes but I’m shooting for four since that’s the current limit on polyphony breakout. The way it works is as follows: It captures the first note(s) down, then as long as at least one note is down it captures each additional note. When all notes are released it continues to play, but when another note or notes is then played it resets. The difficulty I’m having is dealing with polyphony. You can play four notes together, one note then three notes, one note, one note then two notes etc. The UltraNova not only captures the notes but the velocities and the order in which they are played. It ignores duplicates of notes it has already captured.
I’ve tried several different approaches, none of which have been entirely successful. Some have been close, but usually fail when multiple notes are played together. Any tips would be appreciated. I came up with yet another approach last night, but haven’t had a chance to start working on it.