... and a happy new year. Pedro #!/bin/bash # We Wish You a Merry Christmas. Traditional Song # Copyright (C) 2004 Pedro Lopez-Cabanillas <plcl@xxxxxxxxxxxxxxxxxxxxx> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA t1="g 4," t2="C 4, C 8, D 8, C 8, b 8, \ a 4, a 4, a 4, \ D 4, D 8, E 8, D 8, C 8, \ b 4, g 4, g 4, \ E 4, E 8, F 8, E 8, D 8, \ C 4, a 4, g 8, g 8, \ a 4, D 4, b 4, \ C 2, g 4," t3="C 4, C 4, C 4, \ b 2, b 4, \ C 4, b 4, a 4, \ g 2, D 4, \ E 4, D 8, D 8, C 8, C 8, \ G 4, g 4, g 8, g 8, \ a 4, D 4, b 4, \ C 2," # By default, send MIDI events to /dev/midi01. Change it here or pass # some other raw MIDI device as argument, like /dev/snd/midiC0D0 mididev=${1:-/dev/midi01} tempo=160 # quarters per minute function playnote() { let "ms = 240000 / ($2 * $tempo)" echo -ne '\x90' >&3 echo -ne "$1\144" >&3 sleep $ms'e-3s' echo -ne '\x80' >&3 echo -ne "$1\000" >&3 } function playtune() { echo $1 | tr "cdefgabCDEFGAB" "<>@ACEGHJLMOQS" | \ while read -d, note length; do playnote $note $length done } if [ -c $mididev -a -w $mididev ]; then exec 3>$mididev echo -ne '\xb0\x07\x7f' >&3 # volume = 127 echo -ne '\xc0\x0a' >&3 # instrument = music box playtune "$t1 $t2 $t2 $t3" exec 3<&- else echo "`basename $0` : invalid MIDI device ( $mididev )" fi