#!/bin/bash
#  sctp : displays score11 template files for Eastman Csound Library instruments
# legacy command names  getsc and getscore

if  ( [ $# == 0 ] ) ; then  # print usage summary
    echo " sctp : displays one or more score templates and functions for "
    echo "         instrument algorithms in the Eastman Csound Library"
    echo "   sctp  syntax: "
    echo "   sctp [ f functionfile(s) s ] scoretemplatefile(s)"
    echo "(1) To get score templates only: sctp scorefile1 scorefile2 etc."
    echo "(2) To obtain particular function definitions AND score templates: "
    echo "    sctp f function1 function2 s scorefile1 scorefile2"
    echo "(3) To obtain functions only: sctp f function1 function2 s"
    echo "(The legacy command names getsc and getscore can be used in place of sctp)."
    exit 0
fi

SCDIR="$CSLIBDIR/templates/"
FUNCDIR="$CSLIBDIR/funcs"

####### (1)  Get any needed additional functions:  #####
DIR=$SCDIR
while (( "$#" )); do
if [ $1 == "f" ] ; then
 DIR=$FUNCDIR ; shift
elif [ $1 == "s" ] ; then
 DIR=$SCDIR ; shift
else 
 if [ $DIR == $FUNCDIR ] ; then
  if [ `find  $DIR -name $1` ] ; then
    cat `find  $DIR -name $1` ; shift
     else
       echo "   There is no Library function file called >> $x <<"
       echo "    To obtain a list of available Orchestra Library functions type:"
       echo "              lsfunc"
       exit 1
   fi
 elif [ $DIR == $SCDIR ] ; then
  if [ `find  $DIR -name $1` ] ; then
    FILE=`find  $DIR -name $1`
    echo "<<<<   Score11 file for Library algorithm  ### $1 ###"
    cat $FILE
     echo "  <  Added user p-fields: "
     echo "end;  <<< End of ### $1 ### score >>>"
  # add closing CHORUSLOOP macro if needed:
    if [ `grep "define(CHORUSLOOP" $FILE` ] ; then
           echo "])dnl"
           echo "CHORUSLOOP"
     fi
     shift
  else
      echo "ERROR: There is no Library template file called >> $1 << "
     echo "    To obtain a list of available ECMC Csound Library score templates type:"
          echo "              lstp sc"
          echo "Quitting."
          exit 1
  fi
 fi
fi

done 
