Chris@50: #!/bin/bash
Chris@50: 
Chris@119: . ../include.sh
Chris@50: 
Chris@119: infile1=$audiopath/3clicks8.wav
Chris@119: infile2=$audiopath/6clicks8.wav
Chris@50: 
Chris@119: outfile1=$audiopath/3clicks8_vamp_vamp-example-plugins_percussiononsets_onsets.csv
Chris@119: outfile2=$audiopath/6clicks8_vamp_vamp-example-plugins_percussiononsets_onsets.csv
Chris@50: 
Chris@119: infile1dot=$audiopath/3.clicks.8.wav
Chris@119: outfile1dot=$audiopath/3.clicks.8_vamp_vamp-example-plugins_percussiononsets_onsets.csv
Chris@50: 
Chris@119: outfile3=$audiopath/3clicks8_vamp_vamp-example-plugins_percussiononsets_onsets.csv
Chris@119: outfile4=$audiopath/3clicks8_vamp_vamp-example-plugins_percussiononsets_detectionfunction.csv
Chris@50: 
Chris@50: tmpcsv=$mypath/tmp_1_$$.csv
Chris@50: 
Chris@50: trap "rm -f $tmpcsv $outfile1 $outfile2 $outfile3 $outfile4 $infile1dot $outfile1dot" 0
Chris@50: 
Chris@119: transformdir=$mypath/transforms
Chris@50: 
Chris@50: check_csv() {
Chris@50:     test -f $1 || \
Chris@50: 	fail "Fails to write output to expected location $1 for $2"
Chris@50:     # every line must contain the same number of commas
Chris@50:     formats=`awk -F, '{ print NF; }' $1 | sort | uniq | wc | awk '{ print $1 }'`
Chris@50:     if [ "$formats" != "1" ]; then
Chris@50: 	fail "Output is not consistently formatted comma-separated file for $2"
Chris@50:     fi
Chris@50:     rm -f $1
Chris@50: }    
Chris@50: 
Chris@50: 
Chris@50: ctx="onsets transform, one audio file, default CSV writer destination"
Chris@50: 
Chris@50: rm -f $outfile1
Chris@50: 
Chris@119: $r -t $transformdir/onsets.n3 -w csv $infile1 2>/dev/null || \
Chris@50:     fail "Fails to run with $ctx"
Chris@50: 
Chris@50: check_csv $outfile1 "$ctx"
Chris@50: 
Chris@50: 
Chris@50: ctx="onsets transform, one audio file with dots in filename, default CSV writer destination"
Chris@50: 
Chris@50: rm -f $outfile1
Chris@50: 
Chris@50: cp $infile1 $infile1dot
Chris@50: 
Chris@119: $r -t $transformdir/onsets.n3 -w csv $infile1dot 2>/dev/null || \
Chris@50:     fail "Fails to run with $ctx"
Chris@50: 
Chris@50: check_csv $outfile1dot "$ctx"
Chris@50: 
Chris@50: rm -f $infile1dot $outfile1dot
Chris@50: 
Chris@50: 
Chris@50: ctx="onsets and df transforms, one audio file, default CSV writer destination"
Chris@50: 
Chris@50: rm -f $outfile1
Chris@50: 
Chris@119: $r -t $transformdir/onsets.n3 -t $transformdir/detectionfunction.n3 -w csv $infile1 2>/dev/null || \
Chris@50:     fail "Fails to run with $ctx"
Chris@50: 
Chris@50: check_csv $outfile1 "$ctx"
Chris@50: 
Chris@50: 
Chris@50: ctx="onsets transform, two audio files, default CSV writer destination"
Chris@50: 
Chris@50: rm -f $outfile1
Chris@50: rm -f $outfile2
Chris@50: 
Chris@119: $r -t $transformdir/onsets.n3 -w csv $infile1 $infile2 2>/dev/null || \
Chris@50:     fail "Fails to run with $ctx"
Chris@50: 
Chris@50: check_csv $outfile1 "$ctx"
Chris@50: check_csv $outfile2 "$ctx"
Chris@50: 
Chris@50: 
Chris@50: ctx="onsets transform, two audio files, one-file CSV writer"
Chris@50: 
Chris@119: $r -t $transformdir/onsets.n3 -w csv --csv-one-file $tmpcsv $infile1 $infile2 2>/dev/null || \
Chris@50:     fail "Fails to run with $ctx"
Chris@50: 
Chris@50: check_csv $tmpcsv "$ctx"
Chris@50: 
Chris@50: 
Chris@50: ctx="onsets transform, two audio files, stdout CSV writer"
Chris@50: 
Chris@119: $r -t $transformdir/onsets.n3 -w csv --csv-stdout $infile1 $infile2 2>/dev/null >$tmpcsv || \
Chris@50:     fail "Fails to run with $ctx"
Chris@50: 
Chris@50: check_csv $tmpcsv "$ctx"
Chris@50: 
Chris@50: 
Chris@50: ctx="existing output file and no --csv-force"
Chris@50: 
Chris@50: touch $outfile1
Chris@50: 
Chris@119: $r -t $transformdir/onsets.n3 -w csv $infile1 2>/dev/null && \
Chris@50:     fail "Fails by completing successfully when output file already exists (should refuse and bail out)"
Chris@50: 
Chris@50: 
Chris@50: ctx="existing output file and --csv-force"
Chris@50: 
Chris@50: touch $outfile1
Chris@50: 
Chris@119: $r -t $transformdir/onsets.n3 -w csv --csv-force $infile1 2>/dev/null || \
Chris@50:     fail "Fails to run with $ctx"
Chris@50: 
Chris@50: check_csv $outfile1 "$ctx"
Chris@50: 
Chris@50: exit 0