Hari's Corner

Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and then

Three steps to MIDI on Linux

Filed under: Tutorials and HOWTOs by Hari
Posted on Fri, Feb 17, 2006 at 18:49 IST (last updated: Sun, Jun 28, 2009 @ 10:56 IST)

I've always wanted to document any tricky steps to getting things done in Linux and MIDI is a very tricky one indeed. In fact, for most of us, the only way to play MIDI music is to install TiMidity++ and use it as an ALSA sequencer. I've struggled though in the past, due to lack of proper documentation for this and so decided to share my knowledge in a place where others can easily get the bigger picture without getting confused with the details. Note that this is not an extensive article and will not go in-depth into each step, but only to serve as a general guide to MIDI on Linux.

I assume that you've properly installed and configured ALSA drivers and sound generally works in your system. Also I assume that you have a fair idea of how to install and uninstall packages for your particular distribution or know how to compile from source.

The three steps are then:
  1. Install TiMidity++. If you are a Debian user, this package is available in the official repositories. Other binary versions may be available. You can also compile from source. Instructions and download location available at the TiMidity website. Binary packages for select distros:
  2. Get some good sound patches. Debian users can use Freepats. But I recommend the eaw patches which are of higher quality. No Debian packages are available, but luckily you can just download it and extract it in any location. You can download the tar.gz here. Just extract it into your home directory. Let's say /home/hari/eawpats.
  3. Replace the default TiMidity++ timidity.cfg file (rename the old file to something like timidity.conf.old) with the one in the /home/hari/eawpats/linuxconfig folder. Just edit it to make sure the location points to the directory where you extracted the EAW patches. The config file is located usually in the /etc/timidity/ folder in Debian. I don't know about other distros. Here is how the file looks like. Just change the dir setting to whichever location you extracted the EAW patches to:
    dir /home/hari/eawpats/
    source gravis.cfg
    source gsdrums.cfg
    source gssfx.cfg
    source xgmap2.cfg
    #mid -> wav: timidity input.mid -Ow1S -s 44100 -o output.wav

All right, you've now installed it. To test it, you need to play a MIDI file. If you have one, just run
timidity filename.mid
from the command line and enjoy the music! If timidity fails with an error message, just check the timidity.cfg file to make sure the path to your patches directory is correct. The EAW patches are excellent and much better than the freepats package in Debian, so the extra trouble to download and install it is worth it.

Now you have got MIDI playback. What if you want to use TiMidity++ as your ALSA sequencer device? Well, for this you have to issue this command from the command line:
timidity -iA -B8,2 -Os
This basically means that you are running timidity as an ALSA sequencer device (-iA) and you've set the buffer fragmensts to 8,2 (-B8,2) and the output device as ALSA (-Os). There you go. Now you can play MIDI files from KDE also. Don't forget to check out the TiMidity++ man and documentation pages as well.

You must run the above command every time you boot Linux if you want to use TiMidity++ as an ALSA back end so that you can play MIDI files from KDE (KMid) without using the timidity command line every time. The added advantage is that you can use MIDI composing tools like NoteEdit or Rosegarden without any additional setup because ALSA automatically recognizes the MIDI devices. So I recommend that you add this command to your startup scripts.

Hope this is clear. If you have any feedback or questions about this, please drop a comment here.

1 comment(s)

  1. [...] synth in Linux Posted by hari under Linux/*nix, Software at 4:18 pm I know I’ve written about MIDI in Linux before, but I thought I’d share another alternative to people who prefer using SoundFonts - [...]

    Comment by Alternate software MIDI synth in Linux (visitor) on Mon, Feb 12, 2007 @ 16:18 IST #

Comments closed

The blog owner has closed further commenting on this entry.