[sdiy] MIDI message parsing
Ingo Debus
igg.debus at t-online.de
Mon Jun 21 17:46:39 CEST 2010
Am 20.06.2010 um 15:26 schrieb Olivier Gillet:
> - The interrupt handler for UART data receive puts the received byte
> into a ring buffer. This is the strict minimum - I personally prefer
> keeping ISRs as lean as possible.
> - There's a task called as often as possible (but outside of ISR-land)
> that polls the ring buffer, does the parsing (a simple state machine
> with a big switch really does the job, I am not even sure you could
> make it faster with function pointers in a table indexed by message
> nibbles), and calls handlers.
This is pretty much how I do it in my projects too. I handle Real-
Time messages in the ISR directly though (becomes tricky if you want
to handle Song Position Pointer too).
Alll other MIDI bytes are grabbed from the ring buffer by a function
do_midi() which detects if there are new MIDI bytes arrived, and if
any, returns after one complete MIDI command is processed. If no new
bytes have been received it returns immediately. do_midi() is called
from the main loop.
The ring buffer allows me to un-get MIDI bytes if necessary (if an
incomplete message has been received, the next status byte can be un-
get).
This approach also allows for merging more than one MIDI input. One
ring buffer per input.
Ingo
More information about the Synth-diy
mailing list