#!/bin/csh -f
# playlist : plays a group of soundfiles listed in an ascii file
# April 1997  A.S.

if ($#argv == 0) then
   echo "playlist syntax:   playlist  [-np]  inputfile  [inputfile2]   [inputfileN]"
   echo ' where "inputfile" is an ascii file that contains a list of user'
   echo ' and/or sflib soundfiles to be played.'
   echo ' a  -np flag will cause the soundfiles to be played in immediate'
   echo ' succession, rather than separated by one second pauses'
   echo '  -    -    -    -   -   -'
   exit 1
endif

set PWD = `pwd`
switch ($1)
case -np:
   set PAUSE = "NO"
   @ ARG = ( 2 )  # command line argument counter
breaksw
default:
   @ ARG = ( 1 )  # command line argument counter
   set PAUSE = "YES"
endsw

while ($ARG <= $#argv)
set i = ( $argv[$ARG] )

  if (-e $i) then
  else
     echo "**** ERROR: No playlist input file named >> $i << found. ****"
     echo "****Your current working Unix directory is   $PWD. ****."
     exit 1
  endif

      echo "Playing these soundfiles in input ascii file >> $i << : "
	  echo " "
      set PLAYLIST = `cat $i | grep -v 'COMMENT' `
#        echo "  $PLAYLIST : "
      cd $SFDIR
      foreach SOUNDFILE (`echo $PLAYLIST`)
        if (-e $SOUNDFILE) then
#           sfinfo $SOUNDFILE  
           # playaifc $SOUNDFILE #   SGI systems
         play $SOUNDFILE   # Linux systems
         else
           echo " *** ERROR. No soundfile named >> $SOUNDFILE << found."
         endif
       if ($PAUSE == YES) then
         sleep 1
       endif
    end
    echo " ------------------------ "
    cd $PWD
@ ARG = ( $ARG + 1 )
end
