sndstat.c - a replacement for /dev/sndstat
This is a technical overview of the MIDI protocol, which (I hope) serves as a handy reference to midi messages and their meaning.
See: http://crystal.apana.org.au/ghansper/midi_introduction/preface.html An Introduction to MIDI
This is a low-level driver for the Linux sound driver. This driver enables a serial-port to be used like a MIDI device.
Such a driver is useful to you if you have any one of:
The driver allows multiple serial devices to be defined as midi-ports, which makes this a practical solution for supporting multiple simultaneous MIDI inputs and outputs.
The driver is written specifically for 16450 and 16550A UARTs, and operates best when interrupt-driven. But interrupts are a scant resource on today's PC, so this driver supports interrupt sharing and polling.
The driver is capable of sharing interrupts between it's own devices and with other device-drivers. For this to work, both drivers must support interrupt sharing. Due to hardware limitations, interrupt sharing usually only works between PCI devices, or where the devices are physically on the same card. Interrupt-sharing works, provided your hardware supports it.
If no IRQ's are available, a polled-mode is also supported.
This works surprisingly well for
16550A devices for both MIDI-out and MIDI-in.
For 16450 devices, polled-mode gives passable performance
on MIDI-out, but MIDI-in suffers from continual overruns.
In short, if you've run out of IRQ's to use - get a serial card with a 16550A or two, and you'll never look back.
The driver will auto-probe both the IRQ and the required UART divisor. All you need to know is the IO Base Address of your hardware.
Installation has never been simpler.
The driver, plus a few necessary patches for Linux 2.4.x, 2.2.x and 2.0.x kernels are available from:
It is strongly recommended that you download the source package, and recompile this driver from the source code, along with your current kernel. If, for some reason, you cannot do this, you can try using the pre-compiled module below.
To use the pre-compiled module (example only):
gunzip uart16550_midi_241.o.gz cp uart16550_midi_241.o /lib/modules/2.4.1/kernel/drivers/sound/uart16550_midi.o insmod soundcore insmod sound insmod uart16550_midi io1=0x2f8
This is intended as a fall-back solution only. Updates for this binary module will not be provided for newer versions of the Linux 2.4.x kernel.
Note that loading binary modules from the internet into your kernel is a security risk.
If you are using an older kernel (1.x.x), you might be interested in the older versions of this driver. See:
This driver is distributed under the Artistic License (ie the same as Perl).
sndstat.c - a replacement for /dev/sndstatLinux kernels up to 2.2.x included a virtual device /dev/sndstat
which gave some information about what sound and MIDI devices were detected
and configured. This information was also available from /proc/sound in 2.2.x kernel
/dev/sndstat and /proc/sound were removed from
2.4.x kernels, largely because many of the
newer sound-card device-drivers did not support it.
Even so /dev/sndstat
interface was (and is) useful if you have a
sound-card which does support it.
Much of the information available from /dev/sndstat
is also available through ioctl() calls. The program sndstat.c
reproduces the /dev/sndstat information, as best as it can.
Here is an example of output from sndstat -v
OSS/Free version 3.8.2 Config options: Unknown Installed drivers: Card config: Audio devices: 0: Audio Device /dev/audio signed-8/16bit unsigned-8/16bit little-endian 1: Audio Device /dev/audio1 u-Law signed-16bit unsigned-8bit little-endian Dolby Detected 1 Synth device Synth devices: 0: AWE32-0.4.4 (RAM8192k) 0: EMU8K Detected 4 OSS MIDI devices MIDI devices: 0: uart16550_midi 0x03e8 1: MIDI device /dev/midi01 2: Sound Blaster 16 3: AWE Midi Emu Timers: No information available Mixer devices: 0: ESS Solo1 1: Sound Blaster
Note that the headings:
Config options: Installed drivers: Card config: Timers:
Are purely cosmetic. There are no ioctl() calls corresponding to this information.
Notice MIDI device 1 does not contain a description. This is because
this is a PCI device which does not support the necessary ioctl().
In this case, sndstat just confirms that there is a device at /dev/midi01
sndstat.c is included in uart16550_midi.4b.tar.gz.
For those who just want sndstat.c, here it is as a stand-alone download.
To build sndstat from sndstat.c, use:
gcc -o sndstat sndstat.c
The v_midi driver which is bundled with the Linux 2.2.x and 2.4.x kernels makes the uart16550_midi driver (above) superfluous.
The v_midi driver produces MIDI output, suitable for feeding to
a sythesiser or sound-module, but instead of this coming out of some
hardware device, it comes out at a /dev/midinn device-file.
If the above sentence doesn't make sense to you, try the following example:
play2tty.sh as follows:
#!/bin/bash
SEQ=/dev/ttyS1
MIDIFILE="$1"
modprobe v_midi
cleanup () {
kill $1
wait
modprobe -r v_midi
}
stty < $SEQ 38400
cat /dev/midi01 > $SEQ &
CAT=$!
trap "cleanup $CAT" EXIT
playmidi -e -D 0 "$MIDIFILE"
chmod a+x play2tty.sh
play2tty.sh myfile.mid
where myfile.mid is some midi file
The midi output is sent to your synthesiser through /dev/ttyS1
and you should hear the midi-file being played.
If you look at the output from sndstat you will see in particular:
Midi devices: 0: Loopback MIDI Port 1 1: Loopback MIDI Port 2
The playmidi command "plays" the midi device 0
(ie as specified by -D 0). Device 0 is a v_midi device.
The midi-data appears in real-time
at the other v_midi device, device 1 /dev/midi01
The cat command
reads from /dev/midi01 and writes everything to /dev/ttyS1
In this fashion, you can send your real-time midi output to any device you choose, such as a serial-port (as in this example), a parallel port, a special program, or even an rsh command to another computer on your network. Let your imagination run wild!
This is an OpenLook XView widget for setting maximum/minimum key values for a (musical) keyboard.
Furthur details are on my XView-page:
The XView Axis