[sdiy] MIDI message parsing
Olivier Gillet
ol.gillet at gmail.com
Sun Jun 20 15:26:06 CEST 2010
Hi,
What I did for the Shrut(h)i-1 is the following:
- 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.
There's one unusual thing in what I did, though: to keep the parsing
code reusable and generic, it is independent from the rest of the
synthesis engine. The binding between the synthesis engine and the
MIDI parser could have been done by callbacks/function pointers, but
this would have been a tad inefficient because the synthesis code
doesn't handle all MIDI messages, and because that adds a level of
indirection (I was more concerned about code size than execution
speed). So the binding is done at compile-time, through inlining: the
MIDI handler is a template parameter of the MIDI parser. So dead
"branches" of the parser code corresponding to messages not handled
are just not compiled, and the handlers are directly inlined into the
parser. This is probably doable in C too with a heavy dose of pp
macros.
Olivier
More information about the Synth-diy
mailing list