Teaching NCSA Mosaic to recognize ABC format

This is how I taught my Mosaic to play abc tunes on a sound-capable Linux PC. It's currently at the crude hack stage, and it could be improved. Most other sound-capable Unix-like machines would be quite similar, and it should be possible on non-Unix machines, too. The relevant documentation from NCSA is here.

First, create a .mime.types file in your home directory containing

audio/x-abc     abc
Then, create a .mailcap file in your home directory containing
audio/x-abc; mimeabc %s
Finally, create a little shell script mimeabc in your bin directory
#!/bin/sh
# Bourne shell script which translates files in Chris Walshaw's ABC format
# to visible (printable) and audible forms.  This could be made much
# more cool if it were a Tcl/Tk script which gave pushbutton control
# over the viewing and playing of the music.
########################################################################
#       various and sundry extra inputs for TeX, mostly for music
ABCHOME=$HOME/abc
TEXINPUTS=.:$ABCHOME/abc2mtex:$ABCHOME/musictex/macros:
export TEXINPUTS
TEXFONTS=.:$ABCHOME/musictex/tfm:
export TEXFONTS
TEXPKS=.:$ABCHOME/musictex/300pk:
export TEXPKS
XDVIFONTS=$TEXPKS
export XDVIFONTS
########################################################################
for file in $*; do
	################
	# construct the sound
	nfile=`echo $file | sed s/abc/au/`
	# sed steps around a bug in playabc 1.0 on Linux
	gawk '
		/^P:/ {
			# trim out all the TeX garbage found in P fields
			gsub("Ch"      , "A" );
			gsub("/2"      , ""  );
			gsub("\\infty" , ""  );
			gsub("[}$. ^{]", ""  );
		}
		{ print }
		END { print "" }        # add a blank line at the end (for flex)
	' < $file | playabc | tune > $nfile
	################
	# construct the picture
	abc2mtex m $file
	tex music.tex
	# alternatively, could proceed on to PostScript and use Ghostview
	xdvi music.dvi &
	/bin/rm abc2mtex.log
	/bin/rm music.tex music.log
	sleep 3
	################
	# play the sound
	showaudio $nfile
	# clean up
	/bin/rm $nfile
	/bin/rm music.dvi
	################
done
########################################################################
This assumes that Don Ward's playabc and tune programs are built and in the default search path.

You'll have to restart Mosaic before this takes effect.

Back to the Seabright home page.


Steve Allen (sla@lick.ucsc.edu)