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.
Why use the serial port for MIDI?
- Some sound modules support faster baud-rates than MIDI (for better timing)
- You already have a suitable NULL modem cable
- Your sound card has a MIDI out but you don't already have the right cable
- Your sound card doesn't have MIDI out and you don't want to buy an external interface
- Your synth has additional features not accessible via its standard MIDI in
- ALSA set up according to the guide
- A NULL-modem cable to connect your serial port to the synth
- 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?
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: Select all
# env ALSA_CARDS='virmidi serial-u16550 intel8x0' emerge alsa-driverBefore 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:
Code: Select all
# /bin/setserial /dev/ttyS0
/dev/ttyS0, UART: unknown, Port: 0x03f8, IRQ: 4Now go to /etc/modules.d/alsa. First increase the sound card limit. If you have one real sound card, add to this the serial driver 'sound card' and the virmidi 'sound card' to make three:
Code: Select all
options snd snd_major=116 snd_cards_limit=3Code: Select all
## ALSA portion
alias snd-card-0 snd-intel8x0
# Before loading snd-serial-u16550 module, reset the serial port so
# that it can be used.
pre-install snd-serial-u16550 /bin/setserial /dev/ttyS0 uart none
alias snd-card-1 snd-serial-u16550
options snd-serial-u16550 snd_port=0x3f8 snd_irq=4 snd_speed=38400
alias snd-card-2 snd-virmidiOSS 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:
Code: Select all
## OSS/Free portion
alias sound-slot-0 snd-card-0
alias sound-slot-1 snd-card-1
alias sound-slot-2 snd-card-2Code: Select all
device minor(s) compat module explanation
mixerX 0 + 16*X snd-mixer-oss.o Mixers, where X is 00 or 01
sequencer 1 snd-seq-oss.o Global sequencer device, first type.
Used by applications such as 'playmidi'.
midiX 2 + 16*X Raw MIDI ports, X is 00-03
dspX 3 + 16*X snd-pcm-oss.o Digital (PCM) audio, X is 00 or 01
audioX 4 + 16*X snd-pcm-oss.o Sun .au format audio, X is 00 or 01
sndstat 6 Human-readable info. Not ALSA.
music / 8 snd-seq-oss.o Alternate global sequencer device. Used by
sequencer2 applications such as jazz++. May not work.
adspX 12 snd-pcm-oss.o X is 00, 01, 02 or 03.
patmgr1 33 Sequencer patch manager device.Code: Select all
# OSS/Free portion - card #1
# Intel810 Sound card
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-12 snd-pcm-oss
## OSS/Free portion - card #2
# Serial MIDI 'card'
alias sound-service-1-1 snd-seq-oss
alias sound-service-1-8 snd-seq-oss
# OSS/Free portion - card #2
# Virtual MIDI 'card'Code: Select all
alias /dev/mixer snd-mixer-oss
alias /dev/dsp snd-pcm-oss
alias /dev/midi snd-seq-ossCode: Select all
# /etc/init.d/alsasound restartYou can test out your MIDI connection with any ALSA-aware sequencer/MIDI player. pmidi is suitable. There is as yet no ebuild but it is easy to install. With pmidi, list the available MIDI ports:
Code: Select all
$ pmidi -l
Port Client name Port name
72:0 External MIDI 1 MIDI 1-0
80:0 Virtual Raw MIDI 2-0 VirMIDI 2-0
81:0 Virtual Raw MIDI 2-1 VirMIDI 2-1
82:0 Virtual Raw MIDI 2-2 VirMIDI 2-2
83:0 Virtual Raw MIDI 2-3 VirMIDI 2-3Code: Select all
pmidi -p72:0 myfile.midThat'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.
