#! /bin/sh
# Annotate - Add sysex header to MIDI/MPU file
if [ "$1" = "" -o "$2" != "" -o ! -r $1 ] ; then
	echo "Usage: $0 filename"
	echo "annotation comes from stdin (up to EOF) and the sysex header"
	echo "is prepended to the specified MIDI file (filename)."
	exit 2
fi
echo "Annotation: (end with EOF or ^D)"
trap "rm /tmp/$$" 0 1 2 3
echo "f0 00 7f" | axtobb >/tmp/$$
cat >>/tmp/$$
echo "f7" | axtobb >>/tmp/$$
cat $1 >>/tmp/$$
if [ "$?" = "0" ] ; then
	if cp /tmp/$$ $1 ; then exit 0; fi
fi
echo "cp /tmp/$$ $1 failed; temp file left..."
trap 0 1 2 3
exit 1
