Recording MIDI files
From the ALSA wiki
MIDI keyboards connected to your PCUsing
If you have a musical instrument like a MIDI keyboard you can connect it to your soundcard's MIDI interface and record a MIDI file from the MIDI port where the MIDI keyboard is attached while you play some music on the keyboard. You can use MIDI sequencer software such as Rosegarden or Muse to record the MIDI file from the MIDI port.
Using MIDI sequencer software on your PC
If you have MIDI sequencer software such as Rosegarden or Muse, you can create music on your PC and record it in a MIDI file. These two MIDI applications also do musical score editing which can be useful for creating complex music. There is also the vkeybd utility which provides a virtual MIDI piano keyboard which you can record from while you play the virtual piano (either by repeatedly mouseclicking on the piano notes or by using keyboard shortcuts for the different notes)
Retrieved from "http://alsa.opensrc.org/Recording_MIDI_files"