MidiBuffer::addEvent - adding multiple events on the same sample


#1

Another question about my piano roll implementation:

my piano roll allows for overlapping notes, so for example, if i have a long (8 steps) G# on step 4, it is also possible to overlap shorter G# notes within that range.

The behaviour i want is, if there is a new note incoming before the old one is finished, then a note off will immediately be sent, followed by a note on. This is to avoid the possibility that the audio synth plugin may stack the same note on top of itself.

just want to check: if i use MidiBuffer::addEvent to send a note off, and then send a note on to that exact same sample, is it guaranteed that the note off and note on will get triggered in the same order as i send them?

or am i perhaps barking up the wrong tree entirely here, and there’s a better way to do this?


#2

Yes… Probably. The MidiBuffer class is just a container, it doesn’t “send” anything itself so there’s no guarantee that the code which uses it will obey any particular rules. But yes, when you iterate a MidiBuffer it will return the events in the same order that they were added.