Hi! I’m trying to figure out what best practices for managing MIDI note on/off pairs might look like in the land of norns.
One pattern I’ve noticed is to maintain a table of active notes, sending note offs for anything in that table when a new note on is about to be sent. I haven’t experimented with it enough to confirm, but on first inspection this approach seems best suited for monophonic sequencers. It’s also handy for handling events like stopping a sequencer or changing devices.
What I’m working on now is meant to work polyphonically - a new note on event shouldn’t trigger a note off event. Further to that, each note on event can be of a variable duration. Here’s what I’ve come up with that seems to work:
function play_midi(note, vel, duration, chan) m_out:note_on(note, vel, chan) clock.run(midi_note_off, note, duration, chan) end function midi_note_off(note, duration, chan) clock.sync(duration) m_out:note_off(note, 0, chan) end
(Note that I do still keep a running table of active notes for stopping the sequencer, but I stripped it out here to get the core of what’s happening)
Does something like this look familiar to you? Or are you going about it differently? Please do tell! I’m hoping to pack this stuff away in a lib once I sort out the best approach so I can never think about it again.