[sdiy] MIDI spec

Seb Francis seb at is-uk.com
Wed Dec 4 01:24:00 CET 2002


Paul Maddox wrote:

> Seb/Colin,
>
> all I tend to do is use a switch/case statement
> and at the end use the default: and clear running status, that way messages
> I haven't explicity asked for reset the running status byte.
>

Unfortunatly, of the 30 or so instructions in a PIC16XXXX, switch/case isn't included ;-)

Generally though I agree with your approach, except I would argue against explicitly resetting the running status byte in the case of an unhandled system realtime message (but I think you didn't mean this?)

This is how I have done things in the MIDI2CV converter that I'm currently programming:

(1) In the interrupt service routine which gets called when a new MIDI byte is received, I am using the quick-logic I described before..
> Status bytes starting with "11111" are system realtime messages
> Status bytes starting with "11110" are system common messages
> Status bytes starting with "110" have 1 data byte
> All the rest have 2 data bytes
The ISR simply keeps track of incoming messages and pushes them into a 16 byte ring-buffer when a complete message is ready.

(2) In the main loop, I pole the buffer and process messages as they become available.  This way processing can take a long time if necessary (for example if many calculations are required to use the message), and it doesn't block the time critical timer-driven interrupts such as the software LFOs, Envelopes and Portamento, and the S&H refreshing/sequencing.

In the main message parser I use a jump table to decode bits 4-6 of the status byte (kind of the assembly language equivalent of a switch/case statement, but very efficient).

This approach also means the PIC can fall up to 16 bytes behind the incoming data before getting a buffer overflow - hopefully this should never happen, but it's nice to have a bit of margin to avoid dropped MIDI messages when things get really busy.


BTW, when I finally finish this sucker I will be putting up everything, but if anyone wants any particular snippets now (e.g. the MIDI receiving/parsing code), feel free to ask.

Seb




More information about the Synth-diy mailing list