Refactoring MIDI handling code into the MidiInstrument class.