MAME has a built-in MIDI framework using the PortMIDI library. Add a MIDI IN port to your card and parse the incoming 31500 bps serial data (look at the Apple II MIDI card for details).