#!/bin/tcsh

# Rolf Brugger
# Sept '04: updated by Mark Alston

echo "Burning the following tracks to a CD"

set nbtracks = 0

### SCSI emulation problem hack:
#modprobe -r sg

### scan tracks
echo "$argv[*]"
foreach track ($argv[*])
  if($track:e == "flac") then
    echo "  burning flac file $track to CD"
    @ nbtracks += 1
    flac -c -d -s --endian=little --sign=signed --force-raw-format $track | cdrecord -v dev=0,0,0 speed=16 gracetime=2 -audio -pad -swab -nofix  -
  endif
  if($track:e == "wav") then
    echo "  burning wav file $track to CD"
    @ nbtracks += 1
    cat $track | cdrecord -v dev=0,0,0 speed=16 gracetime=2 -pad -audio -swab -nofix -
  endif
  if($track:e == "ogg") then
    echo "  burning ogg file $track to CD"
    @ nbtracks += 1
    ogg123 -f - $track | cdrecord -v dev=0,0,0 speed=16 gracetime=2 -pad -audio -swab -nofix -
  endif
  if($track:e == "mp3") then
    echo "  burning mp3 file $track to CD"
    @ nbtracks += 1
    mpg123 -s $track | cdrecord -v dev=0,0,0 speed=16 gracetime=2 -pad -audio -swab -nofix -
  endif
end
if ($nbtracks > 0) then
    cdrecord -v dev=0,0,0 -fix -eject
endif
exit
#