Using MIDI

From SUSE Wiki

Jump to: navigation, search

Type: Howto, Application-Specific (Rosegarden, NoteEdit, Timidity, WINE)

Tested On: SUSE 10.1, SLED 10, OpenSUSE 10.2

Written By: Kamatsu

Further Modifications By: No One


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 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, and then how to use it in applications such as Rosegarden, WINE, and NoteEdit. There is also a small notice about using USB MIDI keyboards from within SUSE.

Contents

[hide]

Initial Timidity Installation

Getting the Packages

First we need to get the packages. Ensure you have installed the "timidity" package through YaST. It should be available from your SUSE installation disk. If not, you can download it from ftp.opensuse.org.

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 download one. I recommend Musica Theoria 2 by JeffD, but any GM or General MIDI soundfont will suffice. You can get many soundfonts from http://hammersound.net

Note: While Musica Theoria 2 is available from Hammersound, it is in a Windows self-extracting executable file. To get the plain old .sf2 file (this is what you need), you can either extract it within windows or you can download a zipped version from http://www.sf2midi.com , however this requires registration.

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 /usr/share/timidity/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 of "Blue Suede Shoes" by Elvis Presley:

http://209.197.106.133/19580222/rock/elvis/Blue_Suede_Shoes.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 of "Blue Suede Shoes" by Elvis Presley:

http://209.197.106.133/19580222/rock/elvis/Blue_Suede_Shoes.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 alot 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" = "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.

Using Timidity within Applications

Rosegarden

Having installed Rosegarden, you now wish to know how to make it use your shiny new timidity server. Simply click the manage devices button as shown:

Image:Manage Devices.png

Then, ensure the "General MIDI Device" is "Timidity Port 0 (write)". Also check the boxes for any input keyboards you have attatched, as shown:

Image:Screenshot-Manage MIDI Devices - Rosegarden.png

That's all there is to it! Enjoy a fully functional rosegarden.

NoteEdit

Having installed NoteEdit, you now wish to know how to make it use your shiny new timidity server. Simply click on the "Settings" menu, then "Configure NoteEdit". Under the "Sound category", check "ALSA" and ensure that Timidity Port 0 is selected, and click Apply, as shown:

Image:Screenshot-Manage MIDI Devices - Rosegarden.png

That's all there is to it! Enjoy a fully functional NoteEdit.

WINE

In addition to standard Linux MIDI apps, you can make Timidity available for use under WINE, so all your windows apps that use MIDI can use it too. Open up a console and type:

$ winecfg

A window should come up. Choose the "Audio" tab, and ensure that the ALSA driver is checked and not OSS. Click "OK" and exit the terminal.

You can now start all Windows apps that work in WINE with full MIDI support, such as NoteWorthy Composer.

Note about USB Keyboards

Many of the information available on the internet says that to get USB Keyboard support in SUSE you need to recompile ALSA, recompile the kernel, or both. This is no longer necessary, as SUSE as of 10.0 comes with snd-usb-audio module so you do not need to compile it. In fact, ALSA should recognize your keyboard as soon as you plug it in.

Personal tools