source: python.old/aubio/plot/notes.py @ 733aea2

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 733aea2 was b554e41, checked in by Paul Brossier <piem@piem.org>, 12 years ago

moved out old python interface

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