[conspire] HOWTO get MIDI files to play under Ubuntu on a Mac

Daniel Gimpelevich daniel at gimpelevich.san-francisco.ca.us
Mon Dec 5 14:12:38 PST 2005


Discussion

Creative Labs endowed the ancestor of all the sound cards around today,
the SoundBlaster, with abilities that could be compared to the multimedia
capabilities of the non-Intel platforms of the day. These included a "wave
table" function, which allowed a number of "voices" to be multiplexed
together, each with its own waveform played at any pitch, with minimal tax
on the CPU (except of course, compared to the Amiga). Not long before, the
MIDI standard came about, and as part of it, a standard file format for
representing sheet music in a form meant to be interpreted by machines.
Early MIDI file-playing software used whatever limited wave-table
resources were available, but as sound-card designs matured, the
wave-table functionality matured along with it, to a point, before it
began to be largely neglected by sound-card designers. Apple was ahead of
the Intel platforms in early wave-table offerings, and they were likewise
ahead in beginning to neglect them. Their wave-table APIs became quite
unusable so quickly that they were rather hastily superseded in their new
API for managing time-based data, named QuickTime to recall their
once-revolutionary graphics engine, QuickDraw. One application of
time-based data was the ability to play movies, but QuickTime held the
promise of a lot more. Soon, a set of QuickTime Musical Instruments were
added that gave MIDI files the diversity in tone color of a full band or
orchestra without having to obtain any extra software. Later, the
worldwide web came about, and Netscape Navigator version 2 introduced the
idea (and the API) of browser plugins. Among the first such plugins were
ones that would play sound files and ones that would play MIDI files. On
DOS and Windows, the MIDI files would be played using the SoundBlaster
wave-table APIs, and on Macs they would be played using QuickTime. Linux
sees the wave-table portion of a sound card as a "MIDI device" to which it
can send MIDI commands from a MIDI file. The Linux drivers for the Mac
"sound card" do not provide any such device for the above reasons. How
then, can MIDI files be played on such hardware under Linux without
QuickTime?

The answer is to do what QuickTime does: Translate the music data into
sound data using instrument data. The Ubuntu package that does this is
installed like so:
	sudo apt-get install timidity
However, that package does not provide any instrument data, called
"patches." The ALSA project maintains a set of patches that they have
collected under a non-restrictive license that is mostly GPLv2, with an
extra clause that allows creating proprietary works using said patches.
The collection is woefully incomplete, and if used in the stock
configuration, you'll be lucky to hear half the tracks in an average MIDI
file. It comes with a recommendation on how to substitute some of the
patches that are there for many of the patches that aren't. I tried that
approach as well, and the results were still less than
satisfactory. There were still many messages about instruments that would
not be heard, and half the ones that were sounded really off in their tone
color. However, if you are in a commercial setting, this may save you a
few licensing headaches down the road. If you choose to go down this path,
you can get started with:
	sudo apt-get install freepats
Then you would edit /etc/timidity/freepats.cfg to fill in the blanks,
which you would base on the contents of the following file:
/usr/share/doc/freepats/examples/crude.cfg.gz

My recommendation is to forego freepats altogether. The guy who put
freepats together originally put together a collection of patches from all
over the online world in the '90s. However, he did not keep track of which
patch he got from where, much less what licensing terms each originator
imposed. At least a couple of them were for sure not for commercial
redistribution. For this reason, he abandoned that collection and started
freepats. Non-Debian-based distros, as a rule, seem to provide that
collection anyway. Go to a Gentoo mirror and download the file
eawpats12_full.tar.gz to your desktop. Then type:
	cd /opt
	sudo tar xfz ~/Desktop/eawpats12_full.tar.gz
	sudo gedit eawpats/linuxconfig/timidity.cfg
Change the line:
	dir /home/user/eawpats/
to:
	dir /opt/eawpats/
and save changes. Next type:
	sudo gedit /etc/timidity/timidity.cfg
Comment out the last line that says "source" and after it add:
	source /opt/eawpats/linuxconfig/timidity.cfg
With this setup, I found a MIDI file that still gave three messages about
instruments that would not be heard. I found that adding the following
lines to the end gave more or less satisfactory results:
	drumset 0
	11 tamborin
	123 tamborin
	126 tamborin
You may have noticed the top part of the file instructs you to uncomment a
bunch of stuff on slower CPUs. Indeed leaving them all commented is too
much for a 600MHz G3 iBook. But uncommenting them all is overkill. I found
the following to be a nice compromise. Note that the line about
anti-aliasing has been corrected from the suggested line, which would make
timidity error out and not do anything.
	opt EFresamp=d          #disable resampling
	opt EFvlpf=d            #disable VLPF
	opt EFreverb=d          #disable reverb
	#opt EFchorus=d         #disable chorus
	opt EFdelay=d           #disable delay
	opt --no-anti-alias     #disable sample anti-aliasing
	#opt EWPVSETOZ          #disable all Midi Controls
	#opt p32a               #default to 32 voices with auto reduction
	#opt s32kHz             #default sample frequency to 32kHz
	#opt fast-decay         #fast decay notes
After you save changes, you will be ready to play MIDI files from Firefox,
or any other method you choose to obtain them. Just tell Firefox to open
them with timidity. If you're feeling adventurous, you can install and
reconfigure mozplugger to only handle MIDI files, and pass them to
timidity, allowing Firefox to play MIDI files specified with the <EMBED>
tag. There also exists an xmms plugin for timidity, but I rebuilt its
package from source, and only got it to play noise on PowerPC.

This HOWTO would not have been possible without the security hole recently
found in Java. This is because someone came on IRC to ask whether the
Penguin Liberation Front would package Update 6, and asked whether he/she
had followed correct make-jpkg procedure as he/she described at:
http://members.shaw.ca/Limulus/ubuntu.html



More information about the conspire mailing list