This tip builds on the ALSA Configuration Guide and is intended to help you get MIDI support working, in particular using the serial port to connect directly to a keyboard/synth that has a serial 'To host' connector. You should read the ALSA Configuration Guide before reading this tip. This information has been put together from various sources, but there a dearth of useful documentation on this aspect of ALSA and some of it is out of date.

Quick Summary
The snd-serial-u16550.o and snd-virmidi.o modules are used. They create MIDI devices that are treated as if they were physical sound cards and need to be configured as such in /etc/modules.d/alsa. virmidi is used to create virtual MIDI loopback devices.

I have not yet found out how to get the OSS compatibility device /dev/sequencer to send output to the serial MIDI port. This means that most legacy OSS applications still won't be able to use the external synth. I think this should be possible and welcome any suggestions.

The KDE Control Center still doesn't recognise any MIDI devices. Is this because KDE is not yet fully ALSA-compliant?

Compiling the drivers
There are two ALSA drivers (in addition to the one for your sound card that you have already installed when you followed the ALSA Configuration Guide) that are of interest. The serial-u16550 driver enables the serial port for MIDI, and the virmidi driver creates a kind of MIDI patch panel that allows you to route MIDI from one application to another (e.g. a sequencer to Timidity). These two drivers are treated as if they were actual sound cards, so you need to compile them by re-emerging alsa-driver, for example:

Code:

# env ALSA_CARDS='virmidi serial-u16550 intel8x0' emerge alsa-driver

ALSA configuration
Before installing the serial MIDI driver the serial port must be reset. This is because by default a system console is usually present on the serial port. So first, find out the IRQ and port address of your serial port like this:

When ALSA starts up, it tries to load snd-card-x where x is from zero to one less than the sound card limit set above. These lines tell it the real names of the sound card driver modules and any additional configuration needed. 38400 baud is the usual setting for the 'To host' connector on a sound module. Some support higher speeds - consult your manual. (The 'Host select' switch on the synth should usually be set to PC-2 or similar.)

OSS looks for sound-slot-x in much the same way. So for OSS compatibility, we tell it that sound-slot-0 is snd-card-0 (which is snd-intel8x0 or whatever) and so on:

Now we need to define the sound services that are provided by each 'card'. There are several possible services and in the OSS world they correspond to entries in /dev. Each service has a minor number and some of them have OSS compatibility modules. Below are listed the services I know about:

In my setup, my Intel sound card doesn't support a sequencer so I want this on the external synth on the serial port (but note I haven't made this work properly yet). Conversely, the external serial port won't support digital audio. Here's an example from my /etc/modules.d/alsa file:

There is no OSS compatibility module to specify for raw MIDI, so the Virtual MIDI section is empty. By cross-checking with the table above, you should be able to see how the services are assigned. The first number is the sound slot number and the second is the minor number of the device. Finally, ensure that you have the following settings too, which ensure that when /dev/mixer, /dev/dsp, and /dev/midi are requested by an OSS application, the relevant compatibility modules are loaded:

There is a good HOWTO on using soft synths with virmidi at linux-sound.org. Essentially, virmidi allows you to loop the output sent to a virtual MIDI out interface back to another virtual MIDI in interface. This allows you to connect the output of one MIDI application to the input of another.

That's the end of this tip. If you know how to solve the problem with getting /dev/sequencer to work with an external synth using the serial port, or if you know how to get the KDE Control Center to recognise the ALSA MIDI devices, please shout up.