#
# Programmer:    Craig Stuart Sapp <craig@ccrma.stanford.edu>
# Creation Date: Fri Oct 21 05:22:11 PDT 2005
# Last Modified: Mon Oct 31 02:33:08 PST 2005
# Filename:      ...mazurka/info/revcond/Makefile.performance
# Syntax:        GNU Makefile
#
# Description:   Makefile for creating various stages of data from
#                reverse conducting trials.
#


BASE   := $(shell basename `pwd`)
BINDIR := ../bin


##############################
#
# Make the index file for the directory.
#

index: contents

cbtime: corbeatscore
corbeatscore:
	$(BINDIR)/makecorbeatscore $(BASE).score $(BASE).corrected > \
		$(BASE).cbtime

mindex: 
	$(BINDIR)/makemeasureindex  $(BASE).time > $(BASE).mindex

contents:
	$(BINDIR)/makeperfcontents ../../discography/disk.dat ../../titles.txt > contents.html


avgtempo:
	$(BINDIR)/measureaveragetempo $(BASE) ../ ../../../private/recording \
		> $(BASE).avgtempo

inserttempo:
	$(BINDIR)/insertempo $(BASE) 


##############################
#
# Convert individual tapping trials into a combined data file
# for analysis in Mathematica:
#

math: mathematica

mathematica:
	$(BINDIR)/trials2mma $(BASE)*.tap > $(BASE).ma

absma: absmathematica
absmath: absmathematica

absmathematica:
	$(BINDIR)/trials2mma -o $(BASE)*.tap > $(BASE)-abs.ma



##############################
##
## Insert individual offset times into tap trial files.
##

offsets:
	$(BINDIR)/insertoffsets $(BASE).offsets



##############################
##
## Convert the raw Mathematica analysis output file into a Humdrum
## format file:
##

avg20:
	$(BINDIR)/mma2hum $(BASE).mmaoutput20 avgtemplate > $(BASE).avg20



##############################
##
## Create a plain text file of the absolute beat times in the music.
##

beats20:
	. /etc/profile.d/humdrum.sh
	extract -f3 $(BASE).avg20 | rid -GLId | grep -v = > $(BASE).beats20



##############################
##
## Create the performance analysis in three steps:
##

## first: paste the tap times onto the score

btime20:
	
	$(BINDIR)/makebtime $(BASE).avg20 $(BASE).score > $(BASE).btime20

# old method which did not compensate for uneven durations between two files:
#	. /etc/profile.d/humdrum.sh
#	timebase -t `minrhy $(BASE).score` $(BASE).score > tempb
#	cat $(BASE).avg20 > tempc
#	timebase -t `minrhy $(BASE).score` tempc | extract -f3 > tempa
#	assemble tempa tempb | rid -d | grep -v '\*tb[0-9]' >  $(BASE).btime20
#	rm -f tempa tempb tempc


## then: interpolate the tap times for offbeats

time20:
	. /etc/profile.d/humdrum.sh
	gettime -i $(BASE).btime20 > $(BASE).time20


## finally: create the input data for matlab

notes20: matlab20

matlab20:
	. /etc/profile.d/humdrum.sh
	time2matlab $(BASE).time20 > tempa
	$(BINDIR)/addextrainfo $(BASE).avg20 tempa > $(BASE).notes20
	rm -f tempa
	


###############################
##
## Making notes10 data
##

avg10:
	$(BINDIR)/mma2hum $(BASE).mmaoutput10 avgtemplate | \
		sed "s/trials:\t\t20/trials:\t\t10 (1-10)/" > $(BASE).avg10

beats10:
	. /etc/profile.d/humdrum.sh
	extract -f3 $(BASE).avg10 | rid -GLId | grep -v = > $(BASE).beats10

btime10:
	$(BINDIR)/makebtime $(BASE).avg10 $(BASE).score > $(BASE).btime10


time10:
	. /etc/profile.d/humdrum.sh
	gettime -i $(BASE).btime10 > $(BASE).time10

notes10: avg10 beats10 btime10 time10
	. /etc/profile.d/humdrum.sh
	time2matlab $(BASE).time10 > tempa
	$(BINDIR)/addextrainfo $(BASE).avg10 tempa | \
		sed "s/trials:\t\t20/trials:\t\t10 (1-10)/" > $(BASE).notes10
	rm -f tempa



###############################
##
## Making notes05 data
##

avg05:
	$(BINDIR)/mma2hum $(BASE).mmaoutput05 avgtemplate | \
		sed "s/trials:\t\t20/trials:\t\t5 (1-5)/" > $(BASE).avg05

beats05:
	. /etc/profile.d/humdrum.sh
	extract -f3 $(BASE).avg05 | rid -GLId | grep -v = > $(BASE).beats05

btime05:
	$(BINDIR)/makebtime $(BASE).avg05 $(BASE).score > $(BASE).btime05


time05:
	. /etc/profile.d/humdrum.sh
	gettime -i $(BASE).btime05 > $(BASE).time05

notes05: avg05 beats05 btime05 time05
	. /etc/profile.d/humdrum.sh
	time2matlab $(BASE).time05 > tempa
	$(BINDIR)/addextrainfo $(BASE).avg05 tempa | \
		sed "s/trials:\t\t20/trials:\t\t5 (1-5)/" > $(BASE).notes05
	rm -f tempa
	


##############################
##
## creating initial data from singla tapping sesstion.
##

step2single: singleavg singlebtime singletime singlematlab avgtempo inserttempo mindex

singletime: 
	. /etc/profile.d/humdrum.sh
	gettime -i $(BASE).btime > $(BASE).time

singlebtime:
	. /etc/profile.d/humdrum.sh
	$(BINDIR)/makebtime $(BASE).avg $(BASE).score > $(BASE).btime

singleavg:
	$(BINDIR)/tap2avg $(BASE)-01.tap > $(BASE).avg

singlematlab:
	. /etc/profile.d/humdrum.sh
	time2matlab $(BASE).time > tempa
	$(BINDIR)/addextrainfo $(BASE).avg tempa > $(BASE).notes
	rm -f tempa



##############################
##
## Combined makes
##

# make step1 after all tap trials are finished
step1: mathematica

# make step2 after a link file has been created and an mmaoutput file.
#step2: avg btime time matlab offsets beats absmath index avgtempo inserttempo

step220: avg20 btime20 time20 matlab20 offsets beats20 absmath index avgtempo inserttempo

step205: avg05 notes05 btime05 offsets beats05 absmath index avgtempo inserttempo


all: step1 step2

all05: step1 step205

allsingle: step1 step2single contents