#!/bin/bash
infile="$1"
outfile="$2"
before="$(date +%s)"

chromafile=tempchroma.csv

mkdir -p "`dirname "$outfile"`"

echo "[sonic annotator] ..."
VAMP_PATH=. ./sonic-annotator-unix -d vamp:matthiasm:nnls_chroma:bothchroma -w csv --csv-stdout "$infile" 2> /dev/null | cut -d ',' -f 2-  > "$chromafile" 
infile="`echo "$infile" | sed "s/'/''/g"`"
outfile="`echo "$outfile" | sed "s/'/''/g"`"
chromafile="`echo "$chromafile" | sed "s/'/''/g"`"		
matlab -nodisplay -nojvm -r run_segmentation\(\'"$infile"\',\'"$outfile"\'\,\'"$chromafile"\'\) > /dev/null
after="$(date +%s)"
elapsed_seconds="$(expr $after - $before)"
echo "  -->" time elapsed: $elapsed_seconds seconds
echo " "
