[96fb8ad] | 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 | __notesheight = 0.25 |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | from numarray import * |
---|
| 27 | import Gnuplot, Gnuplot.funcutils |
---|
| 28 | |
---|
| 29 | def plotnote(la,title=None) : |
---|
| 30 | if la[0,:].size() == 3: |
---|
| 31 | d = plotnote_withends(la, plot_title=title) |
---|
| 32 | else: |
---|
| 33 | # scale data if in freq (for REF.txt files) |
---|
| 34 | if max(la[:,1] > 128 ): |
---|
| 35 | print "scaling frequency data to midi range" |
---|
| 36 | la[:,1] /= 6.875 |
---|
| 37 | la[:,1] = log(la[:,1])/0.6931 |
---|
| 38 | la[:,1] *= 12 |
---|
| 39 | la[:,1] -= 3 |
---|
| 40 | d = plotnote_withoutends(la, plot_title=title) |
---|
| 41 | return d |
---|
| 42 | |
---|
| 43 | def plotnote_multi(lalist,title=None,fileout=None) : |
---|
| 44 | d=list() |
---|
| 45 | for i in range(len(lalist)): |
---|
| 46 | d.append(plotnote(lalist[i], title=title)) |
---|
| 47 | return d |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | def plotnote_withends(la,plot_title=None) : |
---|
| 51 | d=[] |
---|
| 52 | |
---|
| 53 | x_widths = array(la[:,1]-la[:,0])/2. |
---|
| 54 | |
---|
| 55 | d.append(Gnuplot.Data( |
---|
| 56 | la[:,0]+x_widths, # x centers |
---|
| 57 | la[:,2], # y centers |
---|
| 58 | x_widths, # x errors |
---|
| 59 | __notesheight*ones(len(la) # y errors |
---|
| 60 | ), |
---|
| 61 | title=plot_title,with=('boxxyerrorbars fs 3'))) |
---|
| 62 | |
---|
| 63 | return d |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | def plotnote_withoutends(la,plot_title=None) : |
---|
| 67 | """ bug: fails drawing last note """ |
---|
| 68 | d=[] |
---|
| 69 | |
---|
| 70 | x_widths = array(la[1:,0]-la[:-1,0])/2; |
---|
| 71 | |
---|
| 72 | d.append(Gnuplot.Data( |
---|
| 73 | la[:-1,0]+x_widths, # x centers |
---|
| 74 | la[:-1,1], # y centers |
---|
| 75 | x_widths, # x errors |
---|
| 76 | __notesheight*ones(len(la)-1 # y errors |
---|
| 77 | ), |
---|
| 78 | title=plot_title,with=('boxxyerrorbars fs 3'))) |
---|
| 79 | |
---|
| 80 | return d |
---|
| 81 | |
---|
| 82 | def plotnote_do(d,fileout=None): |
---|
| 83 | g = Gnuplot.Gnuplot(debug=1, persist=1) |
---|
| 84 | g.gnuplot('set style fill solid border 1; \ |
---|
| 85 | set size ratio 1/6; \ |
---|
| 86 | set boxwidth 0.9 relative; \ |
---|
| 87 | set mxtics 2.5; \ |
---|
| 88 | set mytics 2.5; \ |
---|
| 89 | set xtics 5; \ |
---|
| 90 | set ytics 1; \ |
---|
| 91 | set grid xtics ytics mxtics mytics') |
---|
| 92 | |
---|
| 93 | g.xlabel('Time (s)') |
---|
| 94 | g.ylabel('Midi pitch') |
---|
| 95 | # do the plot |
---|
| 96 | #g.gnuplot('set multiplot') |
---|
| 97 | #for i in d: |
---|
| 98 | g.plot(d[0]) |
---|
| 99 | #g.gnuplot('set nomultiplot') |
---|
| 100 | if fileout != None: |
---|
| 101 | g.hardcopy(fileout, enhanced=1, color=0) |
---|
| 102 | |
---|
| 103 | |
---|