Hi,
After midi.StartReceive() , is midi.Listen() necessary to receive MIDI messages (it seems blocking)
Or is it enough to call midi.StartReceive() and (possibly at a constant rate) check if there are new MIDI events (midi.HasEvents() )?
Furthermore what is the internal queue length of midi events? And what happens if it is full (older events discarded or newer events are discarded)
Thank you in advance!
After StartReceive
you should call Listen
at a constant rate. Listen
will simply pull all available messages from uart, parse them, and put them in the queue. HasEvents
simply tells you if the queue is empty or not.
so:
midi.StartReceive();
while(true){
midi.Listen();
while(midi.HasEvents()){
MidiEvent event = midi.PopEvent();
// handle the midi event
}
}
The patch midi example shows this in practice.
The internal queue is a RingBuffer of size 256. The way it’s set up I believe it’ll wait in a blocking manner for you to read some old data before it writes. If I’m correct that means it’s important to pop the events as they come!
3 Likes