Index: python.old/aubio/task/__init__.py
===================================================================
--- python.old/aubio/task/__init__.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
+++ python.old/aubio/task/__init__.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
@@ -0,0 +1,9 @@
+from aubio.aubioclass import *
+from aubio.task.task import task
+from aubio.task.params import taskparams
+from aubio.task.silence import tasksilence
+from aubio.task.onset import taskonset
+from aubio.task.beat import taskbeat
+from aubio.task.cut import taskcut
+from aubio.task.pitch import taskpitch
+from aubio.task.notes import tasknotes
Index: python.old/aubio/task/beat.py
===================================================================
--- python.old/aubio/task/beat.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
+++ python.old/aubio/task/beat.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
@@ -0,0 +1,262 @@
+from aubio.aubioclass import *
+from onset import taskonset
+
+class taskbeat(taskonset):
+	def __init__(self,input,params=None,output=None):
+		""" open the input file and initialize arguments 
+		parameters should be set *before* calling this method.
+		"""
+		taskonset.__init__(self,input,output=None,params=params)
+		self.btwinlen  = 512**2/self.params.hopsize
+		self.btstep    = self.btwinlen/4
+		self.btoutput  = fvec(self.btstep,self.channels)
+		self.dfframe   = fvec(self.btwinlen,self.channels)
+		self.bt	       = beattracking(self.btwinlen,self.channels)
+		self.pos2      = 0
+		self.old       = -1000
+
+	def __call__(self):
+		taskonset.__call__(self)
+		#results = taskonset.__call__(self)
+		# write to current file
+		if self.pos2 == self.btstep - 1 : 
+			self.bt.do(self.dfframe,self.btoutput)
+			for i in range (self.btwinlen - self.btstep):
+				self.dfframe.set(self.dfframe.get(i+self.btstep,0),i,0) 
+			for i in range(self.btwinlen - self.btstep, self.btwinlen): 
+				self.dfframe.set(0,i,0)
+			self.pos2 = -1;
+		self.pos2 += 1
+		val = self.opick.pp.getval()
+		#if not results: val = 0
+		#else: val = results[1] 
+		self.dfframe.set(val,self.btwinlen - self.btstep + self.pos2,0)
+		i=0
+		for i in range(1,int( self.btoutput.get(0,0) ) ):
+			if self.pos2 == self.btoutput.get(i,0) and \
+				aubio_silence_detection(self.myvec(),
+					self.params.silence)!=1: 
+				now = self.frameread-0
+				period = (60 * self.params.samplerate) / ((now - self.old) * self.params.hopsize)
+				self.old = now
+				return now,period
+
+	def eval(self,results,tol=0.20,tolcontext=0.25):
+		obeats = self.gettruth()
+		etime = [result[0] for result in results]
+		otime = [obeat[0] for obeat in obeats]
+		CML_tot, CML_max, CML_start, CML_end = 0,0,0,0
+		AML_tot, AML_max, AML_start, AML_end = 0,0,0,0
+		AMLd_tot, AMLd_max, AMLd_start, AMLd_end = 0,0,0,0
+		AMLh_tot, AMLh_max, AMLh_start, AMLh_end = 0,0,0,0
+		AMLo_tot, AMLo_max, AMLo_start, AMLo_end = 0,0,0,0
+		# results iteration
+		j = 1
+		# for each annotation
+		for i in range(2,len(otime)-2):
+			if j+1 >= len(etime): break
+			count = 0
+			# look for next matching beat
+			while otime[i] > etime[j] - (otime[i] - otime[i+1])*tol:
+				if count > 0: 
+					#print "spurious etime"
+					if CML_end - CML_start > CML_max:
+						CML_max = CML_end - CML_start
+					CML_start, CML_end = j, j
+					if AMLh_end - AMLh_start > AMLh_max:
+						AMLh_max = AMLh_end - AMLh_start
+					AMLh_start, AMLh_end = j, j
+					if AMLd_end - AMLd_start > AMLd_max:
+						AMLd_max = AMLd_end - AMLd_start
+					AMLd_start, AMLd_end = j, j
+					if AMLo_end - AMLo_start > AMLo_max:
+						AMLo_max = AMLo_end - AMLo_start
+					AMLo_start, AMLo_end = j, j
+				j += 1
+				count += 1
+			if j+1 >= len(etime): break
+			#print otime[i-1],etime[j-1]," ",otime[i],etime[j]," ",otime[i+1],etime[j+1] 
+			prevtempo = (otime[i] - otime[i-1])
+			nexttempo = (otime[i+1] - otime[i])
+
+			current0  = (etime[j] > otime[i] - prevtempo*tol)
+			current1  = (etime[j] < otime[i] + prevtempo*tol)
+
+			# check correct tempo 
+			prev0 = (etime[j-1] > otime[i-1] - prevtempo*tolcontext)
+			prev1 = (etime[j-1] < otime[i-1] + prevtempo*tolcontext)
+			next0 = (etime[j+1] > otime[i+1] - nexttempo*tolcontext)
+			next1 = (etime[j+1] < otime[i+1] + nexttempo*tolcontext)
+
+			# check for off beat
+			prevoffb0 = (etime[j-1] > otime[i-1] - prevtempo/2 - prevtempo*tolcontext)
+			prevoffb1 = (etime[j-1] < otime[i-1] - prevtempo/2 + prevtempo*tolcontext)
+			nextoffb0 = (etime[j+1] > otime[i+1] - nexttempo/2 - nexttempo*tolcontext)
+			nextoffb1 = (etime[j+1] < otime[i+1] - nexttempo/2 + nexttempo*tolcontext)
+
+			# check half tempo 
+			prevhalf0 = (etime[j-1] > otime[i-1] + prevtempo - prevtempo/2*tolcontext)
+			prevhalf1 = (etime[j-1] < otime[i-1] + prevtempo + prevtempo/2*tolcontext)
+			nexthalf0 = (etime[j+1] > otime[i+1] - nexttempo - nexttempo/2*tolcontext)
+			nexthalf1 = (etime[j+1] < otime[i+1] - nexttempo + nexttempo/2*tolcontext)
+
+			# check double tempo
+			prevdoub0 = (etime[j-1] > otime[i-1] - prevtempo - prevtempo*2*tolcontext)
+			prevdoub1 = (etime[j-1] < otime[i-1] - prevtempo + prevtempo*2*tolcontext)
+			nextdoub0 = (etime[j+1] > otime[i+1] + nexttempo - nexttempo*2*tolcontext)
+			nextdoub1 = (etime[j+1] < otime[i+1] + nexttempo + nexttempo*2*tolcontext)
+
+			if current0 and current1 and prev0 and prev1 and next0 and next1: 
+				#print "YES!"
+				CML_end = j	
+				CML_tot += 1
+			else:
+				if CML_end - CML_start > CML_max:
+					CML_max = CML_end - CML_start
+				CML_start, CML_end = j, j
+			if current0 and current1 and prevhalf0 and prevhalf1 and nexthalf0 and nexthalf1: 
+				AMLh_end = j
+				AMLh_tot += 1
+			else:
+				if AMLh_end - AMLh_start > AMLh_max:
+					AMLh_max = AMLh_end - AMLh_start
+				AMLh_start, AMLh_end = j, j
+			if current0 and current1 and prevdoub0 and prevdoub1 and nextdoub0 and nextdoub1: 
+				AMLd_end = j
+				AMLd_tot += 1
+			else:
+				if AMLd_end - AMLd_start > AMLd_max:
+					AMLd_max = AMLd_end - AMLd_start
+				AMLd_start, AMLd_end = j, j
+			if current0 and current1 and prevoffb0 and prevoffb1 and nextoffb0 and nextoffb1: 
+				AMLo_end = j
+				AMLo_tot += 1
+			else:
+				if AMLo_end - AMLo_start > AMLo_max:
+					AMLo_max = AMLo_end - AMLo_start
+				AMLo_start, AMLo_end = j, j
+			# look for next matching beat
+			count = 0 
+			while otime[i] > etime[j] - (otime[i] - otime[i+1])*tolcontext:
+				j += 1
+				if count > 0: 
+					#print "spurious etime"
+					start = j
+				count += 1
+		total = float(len(otime))
+		CML_tot  /= total 
+		AMLh_tot /= total 
+		AMLd_tot /= total 
+		AMLo_tot /= total 
+		CML_cont  = CML_max/total
+		AMLh_cont = AMLh_max/total
+		AMLd_cont = AMLd_max/total
+		AMLo_cont = AMLo_max/total
+		return CML_cont, CML_tot, AMLh_cont, AMLh_tot, AMLd_cont, AMLd_tot, AMLo_cont, AMLo_tot
+
+#		for i in allfreq:
+#			freq.append(float(i) / 2. / N  * samplerate )
+#			while freq[i]>freqs[j]:
+#				j += 1
+#			a0 = weight[j-1]
+#			a1 = weight[j]
+#			f0 = freqs[j-1]
+#			f1 = freqs[j]
+#			if f0!=0:
+#				iweight.append((a1-a0)/(f1-f0)*freq[i] + (a0 - (a1 - a0)/(f1/f0 -1.)))
+#			else:
+#				iweight.append((a1-a0)/(f1-f0)*freq[i] + a0)
+#			while freq[i]>freqs[j]:
+#				j += 1
+			
+	def eval2(self,results,tol=0.2):
+		truth = self.gettruth()
+		obeats = [i[0] for i in truth] 
+		ebeats = [i[0]*self.params.step for i in results] 
+		NP = max(len(obeats), len(ebeats))
+		N  = int(round(max(max(obeats), max(ebeats))*100.)+100)
+		W  = int(round(tol*100.*60./median([i[1] for i in truth], len(truth)/2)))
+		ofunc = [0 for i in range(N+W)]
+		efunc = [0 for i in range(N+W)]
+		for i in obeats: ofunc[int(round(i*100.)+W)] = 1
+		for i in ebeats: efunc[int(round(i*100.)+W)] = 1
+		assert len(obeats) == sum(ofunc)
+		autocor = 0; m =0
+		for m in range (-W, W):
+			for i in range(W,N):
+				autocor += ofunc[i] * efunc[i-m] 
+		autocor /= float(NP)
+		return autocor
+	
+	def evaluation(self,results,tol=0.2,start=5.):
+
+		""" beat tracking evaluation function
+
+		computes P-score of experimental results (ebeats)
+		        against ground truth annotations (obeats) """
+
+		from aubio.median import short_find as median
+		truth = self.gettruth()
+		ebeats = [i[0]*self.params.step for i in results] 
+		obeats = [i[0] for i in truth] 
+
+		# trim anything found before start
+		while obeats[0] < start: obeats.pop(0)
+		while ebeats[0] < start: ebeats.pop(0)
+		# maximum number of beats found 
+		NP = max(len(obeats), len(ebeats))
+		# length of ofunc and efunc vector 
+		N  = int(round(max(max(obeats), max(ebeats))*100.)+100)
+		# compute W median of ground truth tempi 
+		tempi = []
+		for i in range(1,len(obeats)): tempi.append(obeats[i]-obeats[i-1])
+		W  = int(round(tol*100.*median(tempi,len(tempi)/2)))
+		# build ofunc and efunc functions, starting with W zeros  
+		ofunc = [0 for i in range(N+W)]
+		efunc = [0 for i in range(N+W)]
+		for i in obeats: ofunc[int(round(i*100.)+W)] = 1
+		for i in ebeats: efunc[int(round(i*100.)+W)] = 1
+		# optional: make sure we didn't miss any beats  
+		assert len(obeats) == sum(ofunc)
+		assert len(ebeats) == sum(efunc)
+		# compute auto correlation 
+		autocor = 0; m =0
+		for m in range (-W, W):
+		  for i in range(W,N):
+		    autocor += ofunc[i] * efunc[i-m] 
+		autocor /= float(NP)
+		return autocor
+
+	def gettruth(self):
+		import os.path
+		from aubio.txtfile import read_datafile
+		datafile = self.input.replace('.wav','.txt')
+		if not os.path.isfile(datafile):
+			print "no ground truth "
+			return False,False
+		else:
+			values = read_datafile(datafile,depth=0)
+			old = -1000
+			for i in range(len(values)):
+				now = values[i]
+				period = 60 / (now - old)
+				old = now
+				values[i] = [now,period]
+		return values
+	
+
+	def plot(self,oplots,results):
+		import Gnuplot
+		oplots.append(Gnuplot.Data(results,with_='linespoints',title="auto"))
+
+	def plotplot(self,wplot,oplots,outplot=None,extension=None,xsize=1.,ysize=1.,spectro=False):
+		import Gnuplot
+		from aubio.gnuplot import gnuplot_create, audio_to_array, make_audio_plot
+		import re
+		# audio data
+		#time,data = audio_to_array(self.input)
+		#f = make_audio_plot(time,data)
+
+		g = gnuplot_create(outplot=outplot, extension=extension)
+		oplots = [Gnuplot.Data(self.gettruth(),with_='linespoints',title="orig")] + oplots
+		g.plot(*oplots)
Index: python.old/aubio/task/cut.py
===================================================================
--- python.old/aubio/task/cut.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
+++ python.old/aubio/task/cut.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
@@ -0,0 +1,42 @@
+from task import task
+from aubio.aubioclass import *
+
+class taskcut(task):
+	def __init__(self,input,slicetimes,params=None,output=None):
+		""" open the input file and initialize arguments 
+		parameters should be set *before* calling this method.
+		"""
+		from os.path import basename,splitext
+		task.__init__(self,input,output=None,params=params)
+		self.soundoutbase, self.soundoutext = splitext(basename(self.input))
+		self.newname   = "%s%s%09.5f%s%s" % (self.soundoutbase,".",
+					self.frameread*self.params.step,".",self.soundoutext)
+		self.fileo	= sndfile(self.newname,model=self.filei)
+		self.myvec	= fvec(self.params.hopsize,self.channels)
+		self.mycopy	= fvec(self.params.hopsize,self.channels)
+		self.slicetimes = slicetimes 
+
+	def __call__(self):
+		task.__call__(self)
+		# write to current file
+		if len(self.slicetimes) and self.frameread >= self.slicetimes[0][0]:
+			self.slicetimes.pop(0)
+			# write up to 1st zero crossing
+			zerocross = 0
+			while ( abs( self.myvec.get(zerocross,0) ) > self.params.zerothres ):
+				zerocross += 1
+			writesize = self.fileo.write(zerocross,self.myvec)
+			fromcross = 0
+			while (zerocross < self.readsize):
+				for i in range(self.channels):
+					self.mycopy.set(self.myvec.get(zerocross,i),fromcross,i)
+					fromcross += 1
+					zerocross += 1
+			del self.fileo
+			self.fileo = sndfile("%s%s%09.5f%s%s" % (self.soundoutbase,".",
+				self.frameread*self.params.step,".",self.soundoutext),model=self.filei)
+			writesize = self.fileo.write(fromcross,self.mycopy)
+		else:
+			writesize = self.fileo.write(self.readsize,self.myvec)
+
+
Index: python.old/aubio/task/notes.py
===================================================================
--- python.old/aubio/task/notes.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
+++ python.old/aubio/task/notes.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
@@ -0,0 +1,159 @@
+
+from aubio.task import task
+from aubio.aubioclass import *
+
+class tasknotes(task):
+	def __init__(self,input,output=None,params=None):
+		task.__init__(self,input,params=params)
+		self.opick = onsetpick(self.params.bufsize,
+			self.params.hopsize,
+			self.channels,
+			self.myvec,
+			self.params.threshold,
+			mode=self.params.onsetmode,
+			dcthreshold=self.params.dcthreshold,
+			derivate=self.params.derivate)
+		self.pitchdet  = pitch(mode=self.params.pitchmode,
+			bufsize=self.params.pbufsize,
+			hopsize=self.params.phopsize,
+			channels=self.channels,
+			samplerate=self.srate,
+			omode=self.params.omode)
+		self.olist = [] 
+		self.ofunc = []
+		self.maxofunc = 0
+		self.last = -1000
+		self.oldifreq = 0
+		if self.params.localmin:
+			self.ovalist   = [0., 0., 0., 0., 0.]
+
+	def __call__(self):
+		from aubio.median import short_find
+		task.__call__(self)
+		isonset,val = self.opick.do(self.myvec)
+		if (aubio_silence_detection(self.myvec(),self.params.silence)):
+			isonset=0
+			freq = -1.
+		else:
+			freq = self.pitchdet(self.myvec)
+		minpitch = self.params.pitchmin
+		maxpitch = self.params.pitchmax
+		if maxpitch and freq > maxpitch : 
+			freq = -1.
+		elif minpitch and freq < minpitch :
+			freq = -1.
+		freq = aubio_freqtomidi(freq)
+		if self.params.pitchsmooth:
+			self.shortlist.append(freq)
+			self.shortlist.pop(0)
+			smoothfreq = short_find(self.shortlist,
+				len(self.shortlist)/2)
+			freq = smoothfreq
+		now = self.frameread
+		ifreq = int(round(freq))
+		if self.oldifreq == ifreq:
+			self.oldifreq = ifreq
+		else:
+			self.oldifreq = ifreq
+			ifreq = 0 
+		# take back delay
+		if self.params.delay != 0.: now -= self.params.delay
+		if now < 0 :
+			now = 0
+		if (isonset == 1):
+			if self.params.mintol:
+				# prune doubled 
+				if (now - self.last) > self.params.mintol:
+					self.last = now
+					return now, 1, freq, ifreq
+				else:
+					return now, 0, freq, ifreq
+			else:
+				return now, 1, freq, ifreq 
+		else:
+			return now, 0, freq, ifreq
+
+
+	def fprint(self,foo):
+		print self.params.step*foo[0], foo[1], foo[2], foo[3]
+
+	def compute_all(self):
+		""" Compute data """
+    		now, onset, freq, ifreq = [], [], [], []
+		while(self.readsize==self.params.hopsize):
+			n, o, f, i = self()
+			now.append(n*self.params.step)
+			onset.append(o)
+			freq.append(f)
+			ifreq.append(i)
+			if self.params.verbose:
+				self.fprint((n,o,f,i))
+    		return now, onset, freq, ifreq 
+
+	def plot(self,now,onset,freq,ifreq,oplots):
+		import Gnuplot
+
+		oplots.append(Gnuplot.Data(now,freq,with_='lines',
+			title=self.params.pitchmode))
+		oplots.append(Gnuplot.Data(now,ifreq,with_='lines',
+			title=self.params.pitchmode))
+
+		temponsets = []
+		for i in onset:
+			temponsets.append(i*1000)
+		oplots.append(Gnuplot.Data(now,temponsets,with_='impulses',
+			title=self.params.pitchmode))
+
+	def plotplot(self,wplot,oplots,outplot=None,multiplot = 0):
+		from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
+		import re
+		import Gnuplot
+		# audio data
+		time,data = audio_to_array(self.input)
+		f = make_audio_plot(time,data)
+
+		# check if ground truth exists
+		#timet,pitcht = self.gettruth()
+		#if timet and pitcht:
+		#	oplots = [Gnuplot.Data(timet,pitcht,with_='lines',
+		#		title='ground truth')] + oplots
+
+		t = Gnuplot.Data(0,0,with_='impulses') 
+
+		g = gnuplot_init(outplot)
+		g('set title \'%s\'' % (re.sub('.*/','',self.input)))
+		g('set multiplot')
+		# hack to align left axis
+		g('set lmargin 15')
+		# plot waveform and onsets
+		g('set size 1,0.3')
+		g('set origin 0,0.7')
+		g('set xrange [0:%f]' % max(time)) 
+		g('set yrange [-1:1]') 
+		g.ylabel('amplitude')
+		g.plot(f)
+		g('unset title')
+		# plot onset detection function
+
+
+		g('set size 1,0.7')
+		g('set origin 0,0')
+		g('set xrange [0:%f]' % max(time))
+		g('set yrange [20:100]')
+		g('set key right top')
+		g('set noclip one') 
+		#g('set format x ""')
+		#g('set log y')
+		#g.xlabel('time (s)')
+		g.ylabel('f0 (Hz)')
+		if multiplot:
+			for i in range(len(oplots)):
+				# plot onset detection functions
+				g('set size 1,%f' % (0.7/(len(oplots))))
+				g('set origin 0,%f' % (float(i)*0.7/(len(oplots))))
+				g('set xrange [0:%f]' % max(time))
+				g.plot(oplots[i])
+		else:
+			g.plot(*oplots)
+		#g('unset multiplot')
+
Index: python.old/aubio/task/onset.py
===================================================================
--- python.old/aubio/task/onset.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
+++ python.old/aubio/task/onset.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
@@ -0,0 +1,220 @@
+from aubio.task.task import task
+from aubio.aubioclass import *
+
+class taskonset(task):
+	def __init__(self,input,output=None,params=None):
+		""" open the input file and initialize arguments 
+		parameters should be set *before* calling this method.
+		"""
+		task.__init__(self,input,params=params)
+		self.opick = onsetpick(self.params.bufsize,
+			self.params.hopsize,
+			self.myvec,
+			self.params.threshold,
+			mode=self.params.onsetmode,
+			dcthreshold=self.params.dcthreshold,
+			derivate=self.params.derivate)
+		self.olist = [] 
+		self.ofunc = []
+		self.maxofunc = 0
+		self.last = 0
+		if self.params.localmin:
+			self.ovalist   = [0., 0., 0., 0., 0.]
+
+	def __call__(self):
+		task.__call__(self)
+		isonset,val = self.opick.do(self.myvec)
+		if (aubio_silence_detection(self.myvec(),self.params.silence)):
+			isonset=0
+		if self.params.storefunc:
+			self.ofunc.append(val)
+		if self.params.localmin:
+			if val > 0: self.ovalist.append(val)
+			else: self.ovalist.append(0)
+			self.ovalist.pop(0)
+		if (isonset > 0.):
+			if self.params.localmin:
+				# find local minima before peak 
+				i=len(self.ovalist)-1
+				while self.ovalist[i-1] < self.ovalist[i] and i > 0:
+					i -= 1
+				now = (self.frameread+1-i)
+			else:
+				now = self.frameread
+			# take back delay
+			if self.params.delay != 0.: now -= self.params.delay
+			if now < 0 :
+				now = 0
+			if self.params.mintol:
+				# prune doubled 
+				if (now - self.last) > self.params.mintol:
+					self.last = now
+					return now, val
+			else:
+				return now, val 
+
+
+	def fprint(self,foo):
+		print self.params.step*foo[0]
+
+	def eval(self,inputdata,ftru,mode='roc',vmode=''):
+		from aubio.txtfile import read_datafile 
+		from aubio.onsetcompare import onset_roc, onset_diffs, onset_rocloc
+		ltru = read_datafile(ftru,depth=0)
+		lres = []
+		for i in range(len(inputdata)): lres.append(inputdata[i][0]*self.params.step)
+		if vmode=='verbose':
+			print "Running with mode %s" % self.params.onsetmode, 
+			print " and threshold %f" % self.params.threshold, 
+			print " on file", self.input
+		#print ltru; print lres
+		if mode == 'local':
+			l = onset_diffs(ltru,lres,self.params.tol)
+			mean = 0
+			for i in l: mean += i
+			if len(l): mean = "%.3f" % (mean/len(l))
+			else: mean = "?0"
+			return l, mean
+		elif mode == 'roc':
+			self.orig, self.missed, self.merged, \
+				self.expc, self.bad, self.doubled = \
+				onset_roc(ltru,lres,self.params.tol)
+		elif mode == 'rocloc':
+			self.v = {}
+			self.v['orig'], self.v['missed'], self.v['Tm'], \
+				self.v['expc'], self.v['bad'], self.v['Td'], \
+				self.v['l'], self.v['labs'] = \
+				onset_rocloc(ltru,lres,self.params.tol)
+
+	def plot(self,onsets,ofunc,wplot,oplots,nplot=False):
+		import Gnuplot, Gnuplot.funcutils
+		import aubio.txtfile
+		import os.path
+		from numpy import arange, array, ones
+		from aubio.onsetcompare import onset_roc
+
+		x1,y1,y1p = [],[],[]
+		oplot = []
+		if self.params.onsetmode in ('mkl','kl'): ofunc[0:10] = [0] * 10
+
+		self.lenofunc = len(ofunc) 
+		self.maxofunc = max(ofunc)
+		# onset detection function 
+		downtime = arange(len(ofunc))*self.params.step
+		oplot.append(Gnuplot.Data(downtime,ofunc,with_='lines',title=self.params.onsetmode))
+
+		# detected onsets
+		if not nplot:
+			for i in onsets:
+				x1.append(i[0]*self.params.step)
+				y1.append(self.maxofunc)
+				y1p.append(-self.maxofunc)
+			#x1 = array(onsets)*self.params.step
+			#y1 = self.maxofunc*ones(len(onsets))
+			if x1:
+				oplot.append(Gnuplot.Data(x1,y1,with_='impulses'))
+				wplot.append(Gnuplot.Data(x1,y1p,with_='impulses'))
+
+		oplots.append((oplot,self.params.onsetmode,self.maxofunc))
+
+		# check if ground truth datafile exists
+		datafile = self.input.replace('.wav','.txt')
+		if datafile == self.input: datafile = ""
+		if not os.path.isfile(datafile):
+			self.title = "" #"(no ground truth)"
+		else:
+			t_onsets = aubio.txtfile.read_datafile(datafile)
+			x2 = array(t_onsets).resize(len(t_onsets))
+			y2 = self.maxofunc*ones(len(t_onsets))
+			wplot.append(Gnuplot.Data(x2,y2,with_='impulses'))
+			
+			tol = 0.050 
+
+			orig, missed, merged, expc, bad, doubled = \
+				onset_roc(x2,x1,tol)
+			self.title = "GD %2.3f%% FP %2.3f%%" % \
+				((100*float(orig-missed-merged)/(orig)),
+				 (100*float(bad+doubled)/(orig)))
+
+
+	def plotplot(self,wplot,oplots,outplot=None,extension=None,xsize=1.,ysize=1.,spectro=False):
+		from aubio.gnuplot import gnuplot_create, audio_to_array, make_audio_plot, audio_to_spec
+		import re
+		# prepare the plot
+		g = gnuplot_create(outplot=outplot, extension=extension)
+		g('set title \'%s\'' % (re.sub('.*/','',self.input)))
+		if spectro:
+			g('set size %f,%f' % (xsize,1.3*ysize) )
+		else:
+			g('set size %f,%f' % (xsize,ysize) )
+		g('set multiplot')
+
+		# hack to align left axis
+		g('set lmargin 3')
+		g('set rmargin 6')
+
+		if spectro:
+			import Gnuplot
+			minf = 50
+			maxf = 500 
+			data,time,freq = audio_to_spec(self.input,minf=minf,maxf=maxf)
+			g('set size %f,%f' % (1.24*xsize , 0.34*ysize) )
+			g('set origin %f,%f' % (-0.12,0.65*ysize))
+			g('set xrange [0.:%f]' % time[-1]) 
+			g('set yrange [%f:%f]' % (minf,maxf))
+			g('set pm3d map')
+			g('unset colorbox')
+			g('set lmargin 0')
+			g('set rmargin 0')
+			g('set tmargin 0')
+			g('set palette rgbformulae -25,-24,-32')
+			g.xlabel('time (s)',offset=(0,1.))
+			g.ylabel('freq (Hz)')
+			g('set origin 0,%f' % (1.0*ysize) ) 
+			g('set format x "%1.1f"')
+			#if log:
+			#	g('set yrange [%f:%f]' % (max(10,minf),maxf))
+			#	g('set log y')
+			g.splot(Gnuplot.GridData(data,time,freq, binary=1, title=''))
+		else:
+			# plot waveform and onsets
+			time,data = audio_to_array(self.input)
+			wplot = [make_audio_plot(time,data)] + wplot
+			g('set origin 0,%f' % (0.7*ysize) )
+			g('set size %f,%f' % (xsize,0.3*ysize))
+			g('set format y "%1f"')
+			g('set xrange [0:%f]' % max(time)) 
+			g('set yrange [-1:1]') 
+			g('set noytics')
+			g('set y2tics -1,1')
+			g.xlabel('time (s)',offset=(0,0.7))
+			g.ylabel('amplitude')
+			g.plot(*wplot)
+
+		# default settings for next plots
+		g('unset title')
+		g('set format x ""')
+		g('set format y "%3e"')
+		g('set tmargin 0')
+		g.xlabel('')
+
+		N = len(oplots)
+		y = 0.7*ysize # the vertical proportion of the plot taken by onset functions
+		delta = 0.035 # the constant part of y taken by last plot label and data
+		for i in range(N):
+			# plot onset detection functions
+			g('set size %f,%f' % ( xsize, (y-delta)/N))
+			g('set origin 0,%f' % ((N-i-1)*(y-delta)/N + delta ))
+			g('set nokey')
+			g('set xrange [0:%f]' % (self.lenofunc*self.params.step))
+			g('set yrange [0:%f]' % (1.1*oplots[i][2]))
+			g('set y2tics ("0" 0, "%d" %d)' % (round(oplots[i][2]),round(oplots[i][2])))
+			g.ylabel(oplots[i][1])
+			if i == N-1:
+				g('set size %f,%f' % ( xsize, (y-delta)/N + delta ) )
+				g('set origin 0,0')
+				g.xlabel('time (s)', offset=(0,0.7))
+				g('set format x')
+			g.plot(*oplots[i][0])
+
+		g('unset multiplot')
Index: python.old/aubio/task/params.py
===================================================================
--- python.old/aubio/task/params.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
+++ python.old/aubio/task/params.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
@@ -0,0 +1,33 @@
+
+class taskparams(object):
+	""" default parameters for task classes """
+	def __init__(self,input=None,output=None):
+		self.silence = -90
+		self.derivate = False
+		self.localmin = False
+		self.delay = 4.
+		self.storefunc = False
+		self.bufsize = 512
+		self.hopsize = 256
+		self.pbufsize = 2048
+		self.phopsize =  512
+		self.samplerate = 44100
+		self.tol = 0.05
+		self.mintol = 0.0
+		self.step = float(self.hopsize)/float(self.samplerate)
+		self.threshold = 0.1
+		self.onsetmode = 'dual'
+		self.pitchmode = 'yin'
+		# best threshold for yin monophonic Mirex04 (depth of f0) 
+		self.yinthresh = 0.15 
+		# best thresh for yinfft monophonic Mirex04 (tradeoff sil/gd)
+		# also best param for yinfft polyphonic Mirex04
+		self.yinfftthresh = 0.85 
+		self.pitchsmooth = 0
+		self.pitchmin=20.
+		self.pitchmax=20000.
+		self.pitchdelay = -0.5
+		self.dcthreshold = -1.
+		self.omode = "freq"
+		self.verbose   = False
+
Index: python.old/aubio/task/pitch.py
===================================================================
--- python.old/aubio/task/pitch.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
+++ python.old/aubio/task/pitch.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
@@ -0,0 +1,234 @@
+from aubio.task.task import task
+from aubio.task.silence import tasksilence
+from aubio.aubioclass import *
+
+class taskpitch(task):
+	def __init__(self,input,params=None):
+		task.__init__(self,input,params=params)
+		self.shortlist = [0. for i in range(self.params.pitchsmooth)]
+		if self.params.pitchmode == 'yin':
+			tolerance = self.params.yinthresh
+		elif self.params.pitchmode == 'yinfft':
+			tolerance = self.params.yinfftthresh
+		else:
+			tolerance = 0.
+		self.pitchdet	= pitch(mode=self.params.pitchmode,
+			bufsize=self.params.bufsize,
+			hopsize=self.params.hopsize,
+			samplerate=self.srate,
+			omode=self.params.omode,
+			tolerance = tolerance)
+
+	def __call__(self):
+		from aubio.median import short_find
+		task.__call__(self)
+		if (aubio_silence_detection(self.myvec(),self.params.silence)==1):
+			freq = -1.
+		else:
+			freq = self.pitchdet(self.myvec)
+		minpitch = self.params.pitchmin
+		maxpitch = self.params.pitchmax
+		if maxpitch and freq > maxpitch : 
+			freq = -1.
+		elif minpitch and freq < minpitch :
+			freq = -1.
+		if self.params.pitchsmooth:
+			self.shortlist.append(freq)
+			self.shortlist.pop(0)
+			smoothfreq = short_find(self.shortlist,
+				len(self.shortlist)/2)
+			return smoothfreq
+		else:
+			return freq
+
+	def compute_all(self):
+		""" Compute data """
+    		mylist    = []
+		while(self.readsize==self.params.hopsize):
+			freq = self()
+			mylist.append(freq)
+			if self.params.verbose:
+				self.fprint("%s\t%s" % (self.frameread*self.params.step,freq))
+    		return mylist
+
+	def gettruth(self):
+		""" extract ground truth array in frequency """
+		import os.path
+		""" from wavfile.txt """
+		datafile = self.input.replace('.wav','.txt')
+		if datafile == self.input: datafile = ""
+		""" from file.<midinote>.wav """
+		# FIXME very weak check
+		floatpit = self.input.split('.')[-2]
+		if not os.path.isfile(datafile) and len(self.input.split('.')) < 3:
+			print "no ground truth "
+			return False,False
+		elif floatpit:
+			try:
+				self.truth = float(floatpit)
+				#print "ground truth found in filename:", self.truth
+				tasksil = tasksilence(self.input,params=self.params)
+				time,pitch =[],[]
+				while(tasksil.readsize==tasksil.params.hopsize):
+					tasksil()
+					time.append(tasksil.params.step*(tasksil.frameread))
+					if not tasksil.issilence:
+						pitch.append(self.truth)
+					else:
+						pitch.append(-1.)
+				return time,pitch
+			except ValueError:
+				# FIXME very weak check
+				if not os.path.isfile(datafile):
+					print "no ground truth found"
+					return 0,0
+				else:
+					from aubio.txtfile import read_datafile
+					values = read_datafile(datafile)
+					time, pitch = [], []
+					for i in range(len(values)):
+						time.append(values[i][0])
+						if values[i][1] == 0.0:
+							pitch.append(-1.)
+						else:
+							pitch.append(aubio_freqtomidi(values[i][1]))
+					return time,pitch
+
+	def oldeval(self,results):
+		def mmean(l):
+			return sum(l)/max(float(len(l)),1)
+
+		from aubio.median import percental 
+		timet,pitcht = self.gettruth()
+		res = []
+		for i in results:
+			#print i,self.truth
+			if i <= 0: pass
+			else: res.append(self.truth-i)
+		if not res or len(res) < 3: 
+			avg = self.truth; med = self.truth 
+		else:
+			avg = mmean(res) 
+			med = percental(res,len(res)/2) 
+		return self.truth, self.truth-med, self.truth-avg
+
+	def eval(self,pitch,tol=0.5):
+		timet,pitcht = self.gettruth()
+		pitch = [aubio_freqtomidi(i) for i in pitch]
+		for i in range(len(pitch)):
+			if pitch[i] == "nan" or pitch[i] == -1:
+				pitch[i] = -1
+		time = [ (i+self.params.pitchdelay)*self.params.step for i in range(len(pitch)) ]
+		#print len(timet),len(pitcht)
+		#print len(time),len(pitch)
+		if len(timet) != len(time):
+			time = time[1:len(timet)+1]
+			pitch = pitch[1:len(pitcht)+1]
+			#pitcht = [aubio_freqtomidi(i) for i in pitcht]
+			for i in range(len(pitcht)):
+				if pitcht[i] == "nan" or pitcht[i] == "-inf" or pitcht[i] == -1:
+					pitcht[i] = -1
+		assert len(timet) == len(time)
+		assert len(pitcht) == len(pitch)
+		osil, esil, opit, epit, echr = 0, 0, 0, 0, 0
+		for i in range(len(pitcht)):
+			if pitcht[i] == -1: # currently silent
+				osil += 1 # count a silence
+				if pitch[i] <= 0. or pitch[i] == "nan": 
+					esil += 1 # found a silence
+			else:
+				opit +=1
+				if abs(pitcht[i] - pitch[i]) < tol:
+					epit += 1
+					echr += 1
+				elif abs(pitcht[i] - pitch[i]) % 12. < tol:
+					echr += 1
+				#else:
+				#	print timet[i], pitcht[i], time[i], pitch[i]
+		#print "origsilence", "foundsilence", "origpitch", "foundpitch", "orig pitchroma", "found pitchchroma"
+		#print 100.*esil/float(osil), 100.*epit/float(opit), 100.*echr/float(opit)
+		return osil, esil, opit, epit, echr
+
+	def plot(self,pitch,wplot,oplots,titles,outplot=None):
+		import Gnuplot
+
+		time = [ (i+self.params.pitchdelay)*self.params.step for i in range(len(pitch)) ]
+		pitch = [aubio_freqtomidi(i) for i in pitch]
+		oplots.append(Gnuplot.Data(time,pitch,with_='lines',
+			title=self.params.pitchmode))
+		titles.append(self.params.pitchmode)
+
+			
+	def plotplot(self,wplot,oplots,titles,outplot=None,extension=None,xsize=1.,ysize=1.,multiplot = 1, midi = 1, truth = 1):
+		from aubio.gnuplot import gnuplot_create , audio_to_array, make_audio_plot
+		import re
+		import Gnuplot
+
+		# check if ground truth exists
+		if truth:
+			timet,pitcht = self.gettruth()
+			if timet and pitcht:
+				oplots = [Gnuplot.Data(timet,pitcht,with_='lines',
+					title='ground truth')] + oplots
+
+		g = gnuplot_create(outplot=outplot, extension=extension)
+		g('set title \'%s\'' % (re.sub('.*/','',self.input)))
+		g('set size %f,%f' % (xsize,ysize) )
+		g('set multiplot')
+		# hack to align left axis
+		g('set lmargin 4')
+		g('set rmargin 4')
+    # plot waveform
+		time,data = audio_to_array(self.input)
+		wplot = [make_audio_plot(time,data)]
+		g('set origin 0,%f' % (0.7*ysize) )
+		g('set size %f,%f' % (xsize,0.3*ysize))
+		#g('set format y "%1f"')
+		g('set xrange [0:%f]' % max(time)) 
+		g('set yrange [-1:1]') 
+		g('set noytics')
+		g('set y2tics -1,1')
+		g.xlabel('time (s)',offset=(0,0.7))
+		g.ylabel('amplitude')
+		g.plot(*wplot)
+
+		# default settings for next plots
+		g('unset title')
+		g('set format x ""')
+		g('set format y "%3e"')
+		g('set tmargin 0')
+		g.xlabel('')
+		g('set noclip one') 
+
+		if not midi:
+			g('set log y')
+			#g.xlabel('time (s)')
+			g.ylabel('f0 (Hz)')
+			g('set yrange [100:%f]' % self.params.pitchmax) 
+		else: 
+			g.ylabel('midi')
+			g('set yrange [%f:%f]' % (aubio_freqtomidi(self.params.pitchmin), aubio_freqtomidi(self.params.pitchmax)))
+			g('set y2tics %f,%f' % (round(aubio_freqtomidi(self.params.pitchmin)+.5),12))
+		
+		if multiplot:
+			N = len(oplots)
+			y = 0.7*ysize # the vertical proportion of the plot taken by onset functions
+			delta = 0.035 # the constant part of y taken by last plot label and data
+			for i in range(N):
+				# plot pitch detection functions
+				g('set size %f,%f' % ( xsize, (y-delta)/N))
+				g('set origin 0,%f' % ((N-i-1)*(y-delta)/N + delta ))
+				g('set nokey')
+				g('set xrange [0:%f]' % max(time))
+				g.ylabel(titles[i])
+				if i == N-1:
+					g('set size %f,%f' % (xsize, (y-delta)/N + delta ) )
+					g('set origin 0,0')
+					g.xlabel('time (s)', offset=(0,0.7))
+					g('set format x')
+				g.plot(oplots[i])
+		else:
+			g('set key right top')
+			g.plot(*oplots)
+		g('unset multiplot')
+
Index: python.old/aubio/task/silence.py
===================================================================
--- python.old/aubio/task/silence.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
+++ python.old/aubio/task/silence.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
@@ -0,0 +1,28 @@
+from aubio.task.task import task
+from aubio.aubioclass import *
+
+class tasksilence(task):
+	wassilence = 1
+	issilence  = 1
+	def __call__(self):
+		task.__call__(self)
+		if (aubio_silence_detection(self.myvec(),self.params.silence)==1):
+			if self.wassilence == 1: self.issilence = 1
+			else: self.issilence = 2
+			self.wassilence = 1
+		else: 
+			if self.wassilence <= 0: self.issilence = 0
+			else: self.issilence = -1 
+			self.wassilence = 0
+		if self.issilence == -1:
+			return max(self.frameread-self.params.delay,0.), -1
+		elif self.issilence == 2:
+			return max(self.frameread+self.params.delay,0.), 2 
+
+	def fprint(self,foo):
+		print self.params.step*foo[0],
+		if foo[1] == 2: print "OFF"
+		else: print "ON"
+
+
+
Index: python.old/aubio/task/task.py
===================================================================
--- python.old/aubio/task/task.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
+++ python.old/aubio/task/task.py	(revision b554e41cfcf7d581dc3296f09dc846e5ffc65049)
@@ -0,0 +1,53 @@
+from aubio.aubioclass import * 
+from params import taskparams
+
+class task(taskparams):
+	""" default template class to apply tasks on a stream """
+	def __init__(self,input,output=None,params=None):
+		""" open the input file and initialize default argument 
+		parameters should be set *before* calling this method.
+		"""
+		import time
+		self.tic = time.time()
+		if params == None: self.params = taskparams()
+		else: self.params = params
+		self.frameread = 0
+		self.readsize  = self.params.hopsize
+		self.input     = input
+		self.filei     = sndfile(self.input)
+		self.srate     = self.filei.samplerate()
+		self.params.step = float(self.params.hopsize)/float(self.srate)
+		self.myvec     = fvec(self.params.hopsize)
+		self.output    = output
+
+	def __call__(self):
+		self.readsize = self.filei.read(self.params.hopsize,self.myvec)
+		self.frameread += 1
+		
+	def compute_all(self):
+		""" Compute data """
+    		mylist    = []
+		while(self.readsize==self.params.hopsize):
+			tmp = self()
+			if tmp: 
+				mylist.append(tmp)
+				if self.params.verbose:
+					self.fprint(tmp)
+    		return mylist
+	
+	def fprint(self,foo):
+		print foo
+
+	def eval(self,results):
+		""" Eval data """
+		pass
+
+	def plot(self):
+		""" Plot data """
+		pass
+
+	def time(self):
+		import time
+		#print "CPU time is now %f seconds," % time.clock(),
+		#print "task execution took %f seconds" % (time.time() - self.tic)
+		return time.time() - self.tic
