Fun fact, these audio applications use the word "Panic" a lot. Apparently it means "Reset MIDI Messages".


  • mido - Python MIDI handling. Debian packages: python3-mido python-mido

  • midi2CSV - utilities for extracting plain text representations from MIDI files. And more than that, a decent guide to MIDI as a format.

MIDI Specification


Need to compile USB Audio/MIDI support under

Device Drivers->Sound->ALSA->USB Devices->USB Audio/MIDI driver

Make sure not to compile any of the Dummy or Virtual drivers directly into the kernel since they tend to be the default causing the real devices to be messed up.

For Ubuntu and other fancy pre compiled distributions, you might be able to just load the necessary kernel modules. Try something like this:

$ sudo modprobe snd_seq_midi
$ sudo modprobe emu10k1
$ sudo modprobe snd_rawmidi
$ sudo modprobe snd_seq_oss
$ sudo modprobe snd_seq_midi_event

There might be more, but this is a good start.

You need to see something like this:

$ r!lsusb | grep Midi
Bus 004 Device 002: ID 0763:0150 Midiman

Here’s my USB MIDI interface:

T:  Bus=04 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12  MxCh= 0
D:  Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0763 ProdID=0150 Rev= 1.25
S:  Manufacturer=M-Audio
S:  Product=USB Uno MIDI Interface
C:* #Ifs= 2 Cfg#= 1 Atr=c0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 0 Cls=01(audio) Sub=01 Prot=00 Driver=(none)
I:  If#= 1 Alt= 0 #EPs= 2 Cls=01(audio) Sub=03 Prot=00 Driver=(none)
E:  Ad=81(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms

The midi ports:

$ r! aplaymidi --list
 Port    Client name                      Port name
 14:0    Midi Through                     Midi Through Port-0
 20:0    USB Uno MIDI Interface           USB Uno MIDI Interface MIDI 1
129:0    FLUID Synth (20878)              Synth input port (20878:0)

Or another perhaps better way:

]$ pmidi -l
 Port     Client name                       Port name
 14:0     Midi Through                      Midi Through Port-0
 20:0     USB Uno MIDI Interface            USB Uno MIDI Interface MIDI 1
128:0     Client-128                        qjackctl
129:0     FLUID Synth (20878)               Synth input port (20878:0)

The 20:0 entry is my M-Audio USB to Midi adaptor confirmed by unplugging it. The 129:0 entry is the software synthesizer created by fluidsynth. I’m not entirely sure what the 14:0 entry is or where it comes from.

Physical Plugs

It’s easy to get confused about what’s in and what’s out. My MIDI guitar controller can only send MIDI event information. That’s it. It can not do anything with MIDI event information. It therefore has a single port which should be labeled "MIDI OUT". This should be connected to the "Midiman M-Audio Uno" MIDI to USB adaptor on the MIDI plug labeled "⇒ TO MIDI OUT". I guess the confusion for me arises from the fact that it should say "FROM MIDI OUT".

Testing MIDI Controller Connection

So you’ve plugged in your MIDI piano or guitar and wonder if there is even a connection to the computer. I was able to generate output using this:

cat -A /dev/midi1

and then playing with the controller.

Playing A Midi File To The Digital Piano

First find out what "port" the keyboard is on using the command above. Then use:

aplaymidi --port 20:0 PartitainG.midi


cat PartitainG.midi | aplaymidi --port 20:0 -

Creating A Midi File From abc File

An abc file is an ASCII-based music format that makes it simple to convert (simple) sheet music to some kind of computerized format. Once you have an abc file, you can use the abcmidi package’s abc2midi to make the midifile:

abc2midi -o elchoclo.midi

Here’s a simple abc file as an example:

| CDEC FGaF | bcdb efge | a'b'c'a' [CE]4 |

Save this as and run

abcmidi/abc2midi -o ce.midi

Now play midi with:

aplaymidi --port 20 ce.midi

Here’s another example that shows more:

X: 1
T: Danse Macabre
C: Camille Saint-Saens
N: Violin's first "largamente" section
M: 3/4
L: 1/4
K: Bb

Here’s a pretty good basic reference.

Here’s The ABC Music standard 2.0. This is very useful for complicated stuff.

I was annoyed that accidentals are signified with _A (flat), =A (natural), and ^A (sharp), which make sense, but that the key signature couldn’t use _B for B-flat.


PianoBooster is a free (GPLv3) program that helps develop sight reading skills. It scrolls a score across the screen and you have to play the correct notes (like Guitar Hero/Rock Band). You can (should) use a MIDI capable input device. The cool thing about this program is that it can work with pretty much any MIDI file. This means you can download any MIDI file of a work and use this software to optimally learn to play it. You can also make your own MIDI files from ABC format as shown above.

Musical MIDI Accompaniment (MMA)

This Python program generates MIDI backing tracks. It can be used (in theory) with PianoBooster. It lives here.


Have a look at the info in places like this:

  • /proc/asound/cards

  • /proc/asound/devices

  • /proc/asound/oss

  • /proc/asound/pcm

  • /proc/asound/seq

  • /proc/asound/timers

  • /proc/asound/version


If you don’t have a MIDI keyboard/instrument hooked up, you can perhaps fake it with Timidity. The trick here is getting the patches.

Fluidsynth and Qsynth

Qsynth is the GUI control for Fluidity which is a software synth that can use user specified sound font files. The format for these files needs to be in sf2 format.

Testing Fluidsynth

This command did not work:

$ fluidsynth FluidR3_GM.sf2 test.mid

It produced a bunch of errors relating to something called "lash" (apparently an "audio session handler"):

lash_open_socket: could not connect to host 'localhost', service '14541'
lash_comm_connect_to_server: could not create server connection

And there was also this error when disabling "lash":

fluidsynth: error: Help! Lost the connection to the JACK server

This command, however did work and play my sample midi file:

$ fluidsynth -l -a alsa FluidR3_GM.sf2 test.mid

If you take off the midi file:

$ fluidsynth -l -a alsa FluidR3_GM.sf2

Fluidsynth starts up as a midi device which programs like Rosegarden can see.


Rosegarden is a very awesome piece of software that does tons of awesome stuff. However, it can be a trick to get it to do the very simple stuff you need when you’re just starting.

Play A Midi File

To get it to play a MIDI file, for example, you need a MIDI synthesizing instrument (like a Yamaha P-60) or you need to set your computer up to be such a thing. That is described in the Fluidsynth seciton.

Go to File-→Open and open your midi file and it should show up with it’s midi operations notated in the main display. Click the right facing triangular play button. It should play.

Manage Midi Devices

Go to Studio in th main menu and choose "Manage Midi Devices". There you need to pick which devices are getting the input and which ones are receiving the output. So generally you need something like this: Input: MIDI Outputs: 129:0 Synth input port (1862:0)(write) MIDI Inputs: 20:0 USB Uno MIDI Interface MIDI 1…

Instrument Parameters

There’s a box for "Instrument Parameters". There is an option for "Bank" or "Program". If you’re using Fluidsynth with a sf2 file, click program and then choose the instrument sound you want. That works pretty well and the FluidR3_GM.sf sounds are pretty good. Even a bandoneon! (#24)

Track Parameters

In the box "Track Parameters" you can set things for each of the tracks. For example, for normal piano parts there are two tracks, a left hand and a right hand. To select the track you’re modifying in this box, click on one labeling a row in the main display. I found that "General MIDI Device" worked and "Synth Plugin" and "Audio" did not.

Play Your Midi Controller In Real Time

As described above, you will be able to play your controller and Rosegarden will record the midi events. Then if you play back the track, it will send it to your Fluidsynth process and you’ll hear it. That’s good, but what if you want to play your controller instrument and hear it as you play it? This is also obviously helpful feedback when recording. The secret is to go to the Studio menu and choose "MIDI Through Routing".

MadCatz Fender Wireless Stratocaster Guitar Controller

Once you’ve done this, you can finally play your RockBand3 Pro Guitar controller in "freestyle" mode even if RockBand3 doesn’t allow for it. Cool! I figured out one interesting feature: if you press the start button, it converts from a strummed mode (solid LEDs) to a tapping mode (blinking LEDs). This allows you to just press the buttons on the fret board and not have to pluck the strings. Latency is pretty sever (~.5 second?) but CPU usage is well under control.