[sdiy] Tips for writing a MIDI parser wanted

Tom Wiltshire tom at electricdruid.net
Tue Mar 24 11:47:17 CET 2009


Hi All,

I'm currently putting the main microprocessor board for my monosynth  
together. One important part of this is MIDI handling. I've never  
written any MIDI code before, so I'm looking for some tips. So far,  
the board can scan a keyboard and display info on an LCD, so I have  
some basic tools for debugging MIDI.

I've read through Seb Francis' 4XD code (which is very useful since  
it is in 16F PIC assembly, which is what I'm using) and looked at the  
MIDIbox code too.

Dealing just with MIDI reception for a moment, I think the general  
plan is something like this:

* Every time a byte arrives, an interrupt is generated. The interrupt  
routine checks whether this is a byte on our channel, and whether it  
is a byte that we're expecting (the second byte of a 2-byte message  
for example) or a new message. If it has a complete message, it puts  
either 1,2, or 3 bytes into a MIDI processing buffer.

* The main code goes through the MIDI processing buffer interpreting  
and acting on the received messages.

The point of this two-stage scheme is that the serious work is only  
done on relevant, correct messages. The interrupt will discard  
anything on other channels, or anything badly formed. This should  
both limit the amount of data that goes into the buffer, and also  
remove the need for complex error checking from the interpreting code.

What do you think? Am I on the right track? Anything I need to know?  
Anything I'm forgetting?

I spent last night doing the internet research on this topic, but  
couldn't find anything that gives an overview of the best strategy  
for writing a MIDI parser. There are some examples, but no-one talks  
about *why* they did it the way they did it, and that's the really  
interesting bit.

Thanks,
Tom





More information about the Synth-diy mailing list