Index: python/aubio/plot/keyboard.py
===================================================================
--- python/aubio/plot/keyboard.py	(revision 52aee9bc252e25718b8d5b127e0d9683eb20a778)
+++ python/aubio/plot/keyboard.py	(revision 52aee9bc252e25718b8d5b127e0d9683eb20a778)
@@ -0,0 +1,46 @@
+
+def draw_keyboard(firstnote = 21, lastnote = 108, y0 = 0, y1 = 1):
+  import Gnuplot
+  octaves = 10
+
+  # build template of white notes
+  scalew  = 12/7.
+  xw_temp = [i*scalew for i in range(0,7)]
+  # build template of black notes
+  scaleb  = 6/7.
+  xb_temp = [i*scaleb for i in [1,3,7,9,11]]
+
+  xb,xw = [],[]
+  for octave in range(octaves-1): 
+    for i in xb_temp:
+      curnote = i+12*octave
+      if  curnote > firstnote-1 and curnote < lastnote+1:
+        xb = xb + [curnote] 
+  for octave in range(octaves-1): 
+    for i in xw_temp:
+      curnote = i+12*octave
+      if  curnote > firstnote-1 and curnote < lastnote+1:
+        xw = xw + [curnote]
+
+  xwdelta = [1/2. * scalew for i in range(len(xw))]
+  yw      = [y0+(y1-y0)*1/2. for i in range(len(xw))]
+  ywdelta = [(y1-y0)*1/2. for i in range(len(xw))]
+
+  xbdelta = [2/3. * scaleb for i in range(len(xb))]
+  yb      = [y0+(y1-y0)*2/3. for i in range(len(xb))]
+  ybdelta = [(y1-y0)*1/3. for i in range(len(xb))]
+
+  whites  = Gnuplot.Data(xw,yw,xwdelta,ywdelta,with = 'boxxyerrorbars')
+  blacks  = Gnuplot.Data(xb,yb,xbdelta,ybdelta,with = 'boxxyerrorbars fill solid')
+
+  return blacks,whites
+
+if __name__ == '__main__':
+  from aubio.gnuplot import gnuplot_create
+  blacks,whites = draw_keyboard(firstnote = 21, lastnote = 108)
+  g = gnuplot_create('','')
+  #g('set style fill solid .5')
+  #g('set xrange [60-.5:72+.5]')
+  #g('set yrange [-0.1:1.1]')
+
+  g.plot(whites,blacks)
Index: python/aubio/plot/notes.py
===================================================================
--- python/aubio/plot/notes.py	(revision 52aee9bc252e25718b8d5b127e0d9683eb20a778)
+++ python/aubio/plot/notes.py	(revision 52aee9bc252e25718b8d5b127e0d9683eb20a778)
@@ -0,0 +1,93 @@
+"""Copyright (C) 2004 Paul Brossier <piem@altern.org>
+print aubio.__LICENSE__ for the terms of use
+"""
+
+__LICENSE__ = """\
+	 Copyright (C) 2004 Paul Brossier <piem@altern.org>
+
+	 This program is free software; you can redistribute it and/or modify
+	 it under the terms of the GNU General Public License as published by
+	 the Free Software Foundation; either version 2 of the License, or
+	 (at your option) any later version.
+
+	 This program is distributed in the hope that it will be useful,
+	 but WITHOUT ANY WARRANTY; without even the implied warranty of
+	 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	 GNU General Public License for more details.
+
+	 You should have received a copy of the GNU General Public License
+	 along with this program; if not, write to the Free Software
+	 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+"""
+
+def plotnote(la,title=None) :
+	if la[0,:].size() == 3:
+	        d = plotnote_withends(la, plot_title=title)
+	else: 
+	    # scale data if in freq (for REF.txt files)
+	    if max(la[:,1] > 128 ):
+	        print "scaling frequency data to midi range"
+	        la[:,1] /= 6.875
+	        la[:,1] = log(la[:,1])/0.6931
+	        la[:,1] *= 12
+	        la[:,1] -= 3
+	    d = plotnote_withoutends(la, plot_title=title)
+	return d
+
+def plotnote_multi(lalist,title=None,fileout=None) :
+	d=list()
+	for i in range(len(lalist)):
+	    d.append(plotnote(lalist[i], title=title))
+	return d
+       
+
+def plotnote_withends(la,plot_title=None) :
+	import numarray
+	import Gnuplot, Gnuplot.funcutils
+	d=[]
+	x_widths = numarray.array(la[:,1]-la[:,0])/2.
+	d.append(Gnuplot.Data(
+	        la[:,0]+x_widths,               # x centers
+	        la[:,2],                        # y centers
+	        x_widths,                       # x errors
+	        __notesheight*ones(len(la)),    # y errors
+	        title=plot_title,with=('boxxyerrorbars fs 3')))
+	return d
+
+
+def plotnote_withoutends(la,plot_title=None) :
+        """ bug: fails drawing last note """
+	import numarray
+	import Gnuplot, Gnuplot.funcutils
+        d=[]
+        x_widths = numarray.array(la[1:,0]-la[:-1,0])/2;
+        d.append(Gnuplot.Data(
+                la[:-1,0]+x_widths,             # x centers
+                la[:-1,1],                      # y centers
+                x_widths,                       # x errors
+                __notesheight*ones(len(la)-1),  # y errors
+                title=plot_title,with=('boxxyerrorbars fs 3')))
+        return d
+
+def plotnote_do(d,fileout=None):
+    import Gnuplot, Gnuplot.funcutils
+    g = Gnuplot.Gnuplot(debug=1, persist=1)
+    g.gnuplot('set style fill solid border 1; \
+    set size ratio 1/6; \
+    set boxwidth 0.9 relative; \
+    set mxtics 2.5; \
+    set mytics 2.5; \
+    set xtics 5; \
+    set ytics 1; \
+    set grid xtics ytics mxtics mytics')
+
+    g.xlabel('Time (s)')
+    g.ylabel('Midi pitch')
+    # do the plot
+    #g.gnuplot('set multiplot')
+    #for i in d:
+    g.plot(d[0])
+    #g.gnuplot('set nomultiplot') 
+    if fileout != None:
+        g.hardcopy(fileout, enhanced=1, color=0)
+
Index: python/aubio/task/__init__.py
===================================================================
--- python/aubio/task/__init__.py	(revision 52aee9bc252e25718b8d5b127e0d9683eb20a778)
+++ python/aubio/task/__init__.py	(revision 52aee9bc252e25718b8d5b127e0d9683eb20a778)
@@ -0,0 +1,10 @@
+from aubio.aubioclass import *
+from aubio.task.task import task
+from aubio.task.utils import *
+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/aubio/task/notes.py
===================================================================
--- python/aubio/task/notes.py	(revision 52aee9bc252e25718b8d5b127e0d9683eb20a778)
+++ python/aubio/task/notes.py	(revision 52aee9bc252e25718b8d5b127e0d9683eb20a778)
@@ -0,0 +1,161 @@
+
+from aubio.task import task
+from aubio.task.utils import *
+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=get_onset_mode(self.params.onsetmode),
+			dcthreshold=self.params.dcthreshold,
+			derivate=self.params.derivate)
+		self.pitchdet  = pitchdetection(mode=get_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 numarray
+		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')
+
