Type: Howto, Application-Specific (Timidity)

Tested on: SUSE 10.1, SLED 10, OpenSUSE 10.2, OpenSUSE 11.2, OpenSUSE 11.3, OpenSUSE 11.4, OpenSUSE 12.1, OpenSUSE 12.2, OpenSUSE 12.3, OpenSUSE 13.1, OpenSUSE 13.2, OpenSUSE Leap 42.1, OpenSUSE Leap 42.2.
Written By: Kamatsu
Further Modifications by: Josef Huber

Unless you have an expensive or old sound card, most of the MIDI one would hear on a Windows computer is created by a software synthesizer. This means the sounds are generated by software and are sent to the sound card as PCM data, rather than the MIDI data being sent to the sound card.

By default, the ALSA sound architecture on Linux only supports hardware synth, so you'll have to get software synthesis going. This guide will also teach you how to make Timidity load as an ALSA server on startup.

Initial Timidity Installation

Getting the Packages

First you need to get the packages for your distribution or download here.

Configuring a Soundfont

Now that you have installed Timidity, you can play a MIDI file by simply typing in a console:

$ timidity <filename>

However, one would quickly notice that the sounds produced are limited to basic percussion, piano, and guitar. This is because Timidity does not come with a decent soundfont. You'll have to find and download a soundfont.

Once you have a simple .sf2 file, rename it to "soundfont.sf2" and copy it to your home folder. Then, in a console (such as xterm or gnome-terminal), type (replace gedit with your favourite editor if you have one):

$ cd ~

$ su

Password: <enter root password>

# cp soundfont.sf2 /usr/share/timidity

# gedit /usr/share/timidity/timidity.cfg

An editor window will come up with some configuration in it.

Look for the part that reads:

source piano+guitar.cfg
source drums.cfg

And change it to read:

source piano+guitar.cfg
source drums.cfg
soundfont soundfont.sf2

Save changes and exit the editor. Now if you use timidity to play a MIDI file at a console, like so:

$ timidity <filename>

The MIDI will have a full instrument set.

Using a GUI to play MIDI files

Now we can play MIDI files, but it involves mucking around in a console. Let's use a GUI'd timidity to play them, and make it happen automatically from either KDE or GNOME.

Automating for GNOME

Once the installation is complete, open up a console app (xterm, Konsole, gterm etc.), and type:

$ su

<enter root password>

# gedit /usr/bin/timidity-gtk

An editor window will come up. In it, type:

#!/bin/bash
timidity -ig $1 $2 $3 $4 $5 $6 $7 $8 $9

Save and exit the editor.

Then type:

# chmod 755 /usr/bin/timidity-gtk

Then, download a MIDI file from somewhere, such as this MIDI:

http://www.josefhuber.com/Midi/stirit.mid

Save it to a convenient location such as your desktop or your home folder. Right click the file in the file manager, and go to "Properties". Go to the "Open With" tab. Click "Add", and then "Use a custom command". In the textbox presented, type:

timidity-gtk

Then, press "Add" and ensure the timidity-gtk radiobutton is checked, then press "OK".

To test this, double click the midi file. If it opens in a timidity GUI, all is working well.

Automating for KDE

Once the installation is complete, open up a console app (xterm, Konsole, gterm etc.), and type:

$ su

<enter root password>

# kwrite /usr/bin/timidity-gtk

An editor window will come up. In it, type:

#!/bin/bash
timidity -ig $1 $2 $3 $4 $5 $6 $7 $8 $9

Save and exit the editor. Then, still as root, type:

# chmod 755 /usr/bin/timidity-gtk

Then, download a MIDI file from somewhere, such as this MIDI:

http://www.josefhuber.com/Midi/stirit.mid

Save it to a convenient location such as your desktop or your home folder. Right click the file in the file manager, and go to "Open With", then "Other". In the textbox presented, type:

timidity-gtk

Then, check "Remember Application Association for this type of File", then press "OK".

If it then loads the file in Timidity GUI, all is working well.

Using Timidity as fake ALSA MIDI ports

To use Timidity in programs such as Rosegarden and NoteEdit, we need to run timidity in ALSA server mode. This means that timidity installs itself in memory and opens 4 new ALSA ports that ALSA thinks are hardware sequencers, but actually are going to timidity.

This can be done most simply by running the following command in a console:

$ timidity -iA &

And can be stopped by:

$ killall -9 timidity

While this will create the ALSA ports that you can then use in Rosegarden or NoteEdit, if you use a MIDI keyboard, you will most likely notice that the lag or latency of this is very bad. You will press a key and hear the sound about half a second afterward. This can be somewhat difficult to overcome if you are experienced at a keyboard, and can be somewhat reduced by running the command with additional arguments:

$ timidity -iA -B2,8 -Os &

However this does not make much difference. While I do not know exactly why, it appears that this problem pretty much disappears if you configure timidity to do this on boot time, and to stop on shutdown. To do this, see the next section

Automating ALSA server mode

Now we want timidity to open up ALSA ports on boot-time, and close on shutdown. This may be scary at first if you haven't touched init scripts before, but this guide is here to help.

Open up a console (xterm, Konsole, gnome terminal etc.) and type:

$ gedit /etc/init.d/alsasound

(where gedit is your favourite editor)

In this file, there will be a lot of complicated scripting.

Do not touch it, but at the end there should be a line that says:

rc_exit

Directly before this line, add the scripting so that it looks like:

if [ "$RUNLEVEL" = "0" ] || [ "$RUNLEVEL" = "6" ]; then

echo "Stopping timidity"
killall -9 timidity
else

echo "Starting timidity"

timidity -iA -B2,8 -Os &

fi

rc_exit

Save, exit the editor, and reboot. Timidity is now loading as a latency-free ALSA server.

© 2017 josefhuber.com

Pillweinstraße 10, A - 5020 Salzburg, Österreich

Virstad 105, S - 579 92 Högsby, Schweden