The MIDI module defines the In class which provides parsers for MIDI
(Musical Instrument Digital Interface) input data with a flexible
callback registration mechanism.  The actual parsing is done in the C
MIDI._In extension module for speed.

A parser is constructed as follows:

MIDI.In([<sysex callback>])

If <sysex callback> is provided, it's invoked on every MIDI system
exclusive message found in the parsed stream (the data provided does
not include the start-of-exclusive or end-of-exclusive bytes).

For example:

def sysexcb(bs): print 'sysex: ', map(ord, bs)

m = MIDI.In(sysexcb)

Input is run through the parser by calling its inbytes() method:

m.inbytes(some_bytes)

Alternatively, you can call the read() method with a file object and
the parser will do reads on it until end-of-file or error.  The
potentially blocking read is done in a thread friendly manner, so this
can be appropriate for multi-threaded applications.

Non-system-exclusive callbacks are invoked on a string with the
message type as well as any other data appropriate for the given
message type.  These callbacks can be set to run on various message
classes.  These classes consist of a message type (or all messages)
and optionally partial descriptions of the message data for which the
callback should be invoked.

m[...] = None

Sets the callback for all message types to None, which will not be
invoked.  Only one callback can be active for a given message class,
so this would eliminate all other callbacks!

Note that `...' isn't a `rubber index' here but merely refers to all
possible values for a field. `:' might be more appropriate.

Say you have a parser object m and want it to call function foo on
continuous controllers 1 through 5 on all channels.  The following
will do the trick:

m['control-change', ..., 1:5] = bar

This syntax works with complete generality for all midi message types.

m['pitch-bend', 5, 42] = baz

Invokes baz when the pitch-bend on channel 5 is exactly 42!

You can receive callbacks for any of the MIDI message types listed
here along with their argument data:

    note-off              channel  key      velocity
    note-on               channel  key      velocity
    poly-key-pressure     channel  key      velocity
    control-change        channel  control  value
    program-change        channel  program
    channel-pressure      channel  pressure
    pitch-bend channel    bend
    all-sound-off         channel
    reset-all-controllers channel
    local-control         channel  bool
    all-notes-off         channel
    omni-off              channel
    omni-on               channel
    mono-on               channel  nchannels
    poly-on               channel
    song-position-pointer position
    song-select           song
    MTC-quarter-frame     mtcval
    tune-request
    timing-clock
    start
    continue
    stop
    active-sensing
    system-reset
