#!/bin/sh
#
# csfmulti - play multiple csf files
# PD by RJM 960620
#
# usage: csfmulti [-r] desc_file.mlt
#
# If '-r' is specified, repeat forever, otherwise play once.
#
# The 'mlt' file's format is each csf to play, in order, one per line.
# You need not include the '.csf'.
# Comment lines start with '#'. Blank lines are ignored.
# A '*dir=...' line specifies the dir to find the csfs in; the default
#  is the current directory.
# A '*args=...' line specifies args to give to sod2; defaults to -Rp.

repeat=n
if [ "$1" = "-r" ]; then
  repeat=y
  shift
fi

if [ ! -f "$1" ]; then
  echo 'usage: csfmulti desc_file.mlt'
  exit 1
fi

args=`grep '^*args=' $1`

if [ "$args" = "" ]; then
  args='-Rp'
else
  args=`echo "$args" |cut -f 2 -d '='`
fi
  
csfdir=`grep '^*dir=' $1`

if [ "$csfdir" = "" ]; then
  csfdir=.
else
  csfdir=`echo "$csfdir" |cut -f 2 -d '='`
fi

foo="s!~!$HOME!g"
csfdir=`echo "$csfdir" |sed $foo`
  
first=y

while [ $first = y -o $repeat = y ]; do
  first=n
  
  for i in `sed -e '/^#/d' -e '/^*/d' <$1 | tr '[\n]' '[ ]'`; do
    csffile=`basename $i .csf`.csf
    echo Running: sod2 "$args" $csfdir/$csffile
    echo ''
    sod2 "$args" $csfdir/$csffile
  done
  
  echo ''
  if [ $repeat = y ]; then
    echo repeating...
  else
    echo finished.
  fi
  echo ''
done
