#!/bin/sh

# Display datascript.
# by Rob, use at your own risk...
#

export ESPS_BASE=/cstr/linux/entropic/esps531.linux
export PATH=$PATH:$ESPS_BASE/bin

menu="labelmenu.def"
showspec="no"; showintevent="no"; showphrase="no"; showword="no"; showsyl="no"
showseg="no"; showil="no"; showtg="no"; showall="no"; showpstream="no"
while test $# -gt 0 ; do
  case "$1" in
	-m ) send_xwaves set f0_min 50 f0_max 200 f0_size 1 ref_size5; 
            shift ;;	
	-f ) send_xwaves set f0_min 100 f0_max 400 f0_size 1 ref_size 5;
            shift ;;
        --spec ) showspec="yes"
            shift ;;
        --int ) showintevent="yes"
            shift ;;
        --phrase ) showphrase="yes"
            shift ;;
        --word ) showword="yes"
            shift ;;
        --syl ) showsyl="yes"
            shift ;;
        --seg ) showseg="yes"
            shift
	    segdir=$1
	    shift ;;
        --il ) showil="yes"
            shift ;;
        --tg ) showtg="yes"
            shift ;;
	--all ) showall="yes"
	    shift ;;
	--f0other ) showf0other="yes"
	    shift ;;
	--ps ) showpstream="yes"
	    shift ;;
	--menu ) shift ;
	        menu=$1;
	        shift;;
	-* ) echo "Usage:   f2bdisplay [options] basename [basename ...]";
             echo "";
             echo "options: -m                                 male pitchrange 50-200 Hz" ;
	     echo "         -f                                 female pitchrange 100-400 Hz" ;
	     echo "         --spec                             show spectrogram";
	     echo "         --int --phrase                     show intevent, phrase labels";
	     echo "         (--syl | --seg | --word) dir       show segment, syllable, word labels";
	     echo "         --ps                               show prosodic structure labels";
	     echo "         --il --tg                          show il, tg labels"; 
	     echo "         --all                              show all labels";
	     echo "         --menu <menu>                      use this label menu file";
	     exit 1 ;;
	* ) # finish processing options
	    break;;
esac
done

menubase=$HOME/lib/entropic
menufile=$menubase/$menu

# attach xlabel
send_xwaves attach function xlabel 

# loop through given files
for i in $*
do
   # set variables
   base=.
   name=`basename $i .wav`
   wave=$base/wav/$name.wav
   spec=$base/spec/$name.spec
   f0=$base/f0/$name.f0
   words=$base/word/$name.lab
   syls=$base/syl/$name.lab
   segs=$base/$segdir/$name.lab


   # test for spec and generate if not found.
   if [ "$showspec" = "yes" -a ! -f $spec ] ; then
      sgram -dHAMMING -o8 -E0.94 -S2 -w8 $wave $spec
   fi

   # get xwaves to do stuff
   send_xwaves make name $name file $wave width 1100 height 150 loc_x 10 loc_y 10 
   #send_xwaves make name $name file $f0   width 1100 height 200 loc_x 10 loc_y 160 
   send_xwaves $name  op file $f0 op "bracket horiz. markers"


   if [ "$showf0other" = "no" ] ; then
     send_xwaves $name activate file $f0 op clear identifiers k1 ac_peak rms "prob_voice"
   fi

   if [ "$showspec" = "yes" ] ; then
     send_xwaves make name $name file $spec width 1100 height 200 loc_x 10 loc_y 460
   fi

   if [ "$showword" = "yes" -o "$showall" = "yes" ] ; then
     send_xwaves send make signal $spec name $name file $words color 125 menufile $menufile
     send_xwaves send activate fields 1 2 3
   fi

   if [ "$showsyl" = "yes" -o "$showall" = "yes" ] ; then
     send_xwaves send make signal $spec name $name file $syls color 125 menufile $menufile
     send_xwaves send activate fields 1 2 3
   fi

   if [ "$showseg" = "yes" -o "$showall" = "yes" ] ; then
   send_xwaves send make signal $spec name $name file $segs color 125 menufile $menufile
   send_xwaves send activate fields 1 2 3
   fi

   send_xwaves $name align file $wave
   send_xwaves pause
   send_xwaves kill
done













