[ae3f5af] | 1 | """Copyright (C) 2004 Paul Brossier <piem@altern.org> |
---|
| 2 | print aubio.__LICENSE__ for the terms of use |
---|
| 3 | """ |
---|
| 4 | |
---|
| 5 | __LICENSE__ = """\ |
---|
| 6 | Copyright (C) 2004 Paul Brossier <piem@altern.org> |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | (at your option) any later version. |
---|
| 12 | |
---|
| 13 | This program is distributed in the hope that it will be useful, |
---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | GNU General Public License for more details. |
---|
| 17 | |
---|
| 18 | You should have received a copy of the GNU General Public License |
---|
| 19 | along with this program; if not, write to the Free Software |
---|
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 21 | """ |
---|
| 22 | |
---|
| 23 | def plotnote(la,title=None) : |
---|
| 24 | if la[0,:].size() == 3: |
---|
| 25 | d = plotnote_withends(la, plot_title=title) |
---|
| 26 | else: |
---|
| 27 | # scale data if in freq (for REF.txt files) |
---|
| 28 | if max(la[:,1] > 128 ): |
---|
| 29 | print "scaling frequency data to midi range" |
---|
| 30 | la[:,1] /= 6.875 |
---|
| 31 | la[:,1] = log(la[:,1])/0.6931 |
---|
| 32 | la[:,1] *= 12 |
---|
| 33 | la[:,1] -= 3 |
---|
| 34 | d = plotnote_withoutends(la, plot_title=title) |
---|
| 35 | return d |
---|
| 36 | |
---|
| 37 | def plotnote_multi(lalist,title=None,fileout=None) : |
---|
| 38 | d=list() |
---|
| 39 | for i in range(len(lalist)): |
---|
| 40 | d.append(plotnote(lalist[i], title=title)) |
---|
| 41 | return d |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | def plotnote_withends(la,plot_title=None) : |
---|
| 45 | import numarray |
---|
| 46 | import Gnuplot, Gnuplot.funcutils |
---|
| 47 | d=[] |
---|
| 48 | x_widths = numarray.array(la[:,1]-la[:,0])/2. |
---|
| 49 | d.append(Gnuplot.Data( |
---|
| 50 | la[:,0]+x_widths, # x centers |
---|
| 51 | la[:,2], # y centers |
---|
| 52 | x_widths, # x errors |
---|
| 53 | __notesheight*ones(len(la)), # y errors |
---|
| 54 | title=plot_title,with=('boxxyerrorbars fs 3'))) |
---|
| 55 | return d |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | def plotnote_withoutends(la,plot_title=None) : |
---|
| 59 | """ bug: fails drawing last note """ |
---|
| 60 | import numarray |
---|
| 61 | import Gnuplot, Gnuplot.funcutils |
---|
| 62 | d=[] |
---|
| 63 | x_widths = numarray.array(la[1:,0]-la[:-1,0])/2; |
---|
| 64 | d.append(Gnuplot.Data( |
---|
| 65 | la[:-1,0]+x_widths, # x centers |
---|
| 66 | la[:-1,1], # y centers |
---|
| 67 | x_widths, # x errors |
---|
| 68 | __notesheight*ones(len(la)-1), # y errors |
---|
| 69 | title=plot_title,with=('boxxyerrorbars fs 3'))) |
---|
| 70 | return d |
---|
| 71 | |
---|
| 72 | def plotnote_do(d,fileout=None): |
---|
| 73 | import Gnuplot, Gnuplot.funcutils |
---|
| 74 | g = Gnuplot.Gnuplot(debug=1, persist=1) |
---|
| 75 | g.gnuplot('set style fill solid border 1; \ |
---|
| 76 | set size ratio 1/6; \ |
---|
| 77 | set boxwidth 0.9 relative; \ |
---|
| 78 | set mxtics 2.5; \ |
---|
| 79 | set mytics 2.5; \ |
---|
| 80 | set xtics 5; \ |
---|
| 81 | set ytics 1; \ |
---|
| 82 | set grid xtics ytics mxtics mytics') |
---|
| 83 | |
---|
| 84 | g.xlabel('Time (s)') |
---|
| 85 | g.ylabel('Midi pitch') |
---|
| 86 | # do the plot |
---|
| 87 | #g.gnuplot('set multiplot') |
---|
| 88 | #for i in d: |
---|
| 89 | g.plot(d[0]) |
---|
| 90 | #g.gnuplot('set nomultiplot') |
---|
| 91 | if fileout != None: |
---|
| 92 | g.hardcopy(fileout, enhanced=1, color=0) |
---|
| 93 | |
---|