MIDI support in Fedora Core 5 (and KDE)

TuxI was never able to play midi files on my laptop due to the fact that my poor audio hardware does not have real midi hardware. However, the command line tool timidity was able to play midi files through converting.

By accident I now found out that you can also run timidity as a daemon, providing several midi ports to the system. This gives you the opportunity to play midi files just like it should be. To do this, start timidity in a shell with a codeline like this:
timidity -iAq -Os
As long as the program runs now there are four midi ports provided – you can even see them in kcontrol and choose them as a device. However, I was never able to play the midi test sound in kcontrol, but everything else works.

But since we do not want to start this by hand every time we need a start script. The documentation on the timidity page is unfortunately close to non existend, but Mandrake does a good job by providing init scripts in a rpm. I downloaded them and modified them to get them running under Fedora Core 5 – but this is more a dirty hack, so be careful. And all comments are appreciated, as usual.

What you have to do:
Copy this file with filename timidity to /etc/init.d/ and set owner and rights correct (chown root:root timidity and chmod 755 timidity):

# Startup script for the TiMidity++ ALSA sequencer interface
# chkconfig: 2345 20 65
# description: TiMidity is a MIDI to WAVE converter and player that uses Gravis
# Ultrasound(tm) or SoundFont(tm) patch files to generate digital
# audio data from general MIDI files.
# processname: timidity
# config: /etc/sysconfig/timidity

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/timidity

[ -x /usr/bin/timidity ] || exit 0


# See how we were called.
case "$1" in
echo "Starting TiMidity++ ALSA sequencer interface:"
if [ ! -f /var/lock/subsys/timidity ]; then

# Parse options
if [[ "$BUFNUM" =~ "[0-9]+" ]] && [[ "$BUFSIZE" =~ "[0-9]+" ]]; then
OPTIONS="${OPTIONS} --buffer-fragments=${BUFNUM},${BUFSIZE}"
[[ "$SAMPLERATE" =~ "[0-9]+" ]] && OPTIONS="$OPTIONS --sampling-freq=$SAMPLERATE"
[ "$ANTIALIAS" = "true" ] && OPTIONS="$OPTIONS --anti-alias"
[[ "$PRIORITY" =~ "[0-9]+" ]] && OPTIONS="$OPTIONS --realtime-priority=$PRIORITY"

daemon timidity $OPTIONS
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/timidity

echo "Shutting down TiMidity++ ALSA sequencer interface:"
if [ -f /var/lock/subsys/timidity ]; then
killproc timidity
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/timidity

status timidity

killproc -HUP timidity

$0 stop
$0 start

echo "Usage: %s {start|stop|status|reload|restart}\n" "$0"
exit 1

exit $RETVAL

After that, register the script to your services-system with the command chkconfig --add timidity. Now check with system-config-services if the script, and therefore the sound support, is started in the runlevels you need it.

The second file you need (well, I don’t know why, but Mandrake provides it, so I better be on the safe side) is also called timidity, but has to be in /etc/sysconfig/:

# Number of buffers, and buffer size in 2^n

# Sampling rate, default is 44100

# Antialias = "true" enhances sound quality

# PRIORITY is the realtime priority. For more detail, see
# manpage sched_setscheduler(2), the part talking about SCHED_FIFO.
# this number is 0-100 inclusive.

# Any extra timidity options please go here

But beware: this is a fast and dirty hack in the middle of the night, and I have no real idea what the scripts are doing because I do not really know timidity. For instance I get an error when I start the timidity-daemon:

Starting TiMidity++ ALSA sequencer interface:
file mcoputils.cc: line 497 (static std::string Arts::MCOPUtils::mcopDirectory()): assertion failed: (home != 0)
TiMidity starting in ALSA server mode
Opening sequencer port: 128:0 128:1 128:2 128:3
[ OK ]

I have no idea what to do about that – but it works for me, so it could probably helpful for others. I can now play and edit midi files in rosegarden without any problems – nice!

A word about the licence of these scripts: since they are published as GPL by Mandrake these scripts and the modifications are also published as GPLv2!


2 thoughts on “MIDI support in Fedora Core 5 (and KDE)”

  1. This works in Cord 6 as well.

    The quotation marks had to be replaced with standard quotation marks, however. Otherwise, works great.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s