ref: 0ab19df22676e5ef57ae16f014b7c0f6d4c91085
parent: 32fa8e816aaf24cce0c79dd1cab463fbbf0b9e26
author: Paul Brossier <piem@altern.org>
date: Wed Aug 2 11:25:09 EDT 2006
factorise gnuplot_create options, update aubioplot-spec/audio factorise gnuplot_create options, update aubioplot-spec/audio
--- a/python/aubio/gnuplot.py
+++ b/python/aubio/gnuplot.py
@@ -162,18 +162,36 @@
x,y = downsample_audio(time,data,maxpoints=maxpoints)
return Gnuplot.Data(x,y,with='lines')
-def gnuplot_create(outplot='',extension='',debug=0,persist=1, xsize=1., ysize=1.):
- import Gnuplot
- g = Gnuplot.Gnuplot(debug=debug, persist=persist)
- if not extension or not outplot: return g
- if extension == 'ps': ext, extension = '.ps' , 'postscript'
- elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced'
- elif extension == 'epsc': ext, extension = '.eps' , 'postscript enhanced color'
- elif extension == 'png': ext, extension = '.png', 'png'
- elif extension == 'svg': ext, extension = '.svg', 'svg'
- else: exit("ERR: unknown plot extension")
- g('set terminal %s' % extension)
- if outplot != "stdout":
- g('set output \'%s%s\'' % (outplot,ext))
- g('set size %f,%f' % (xsize, ysize))
- return g
+def gnuplot_addargs(parser):
+ """ add common gnuplot argument to OptParser object """
+ parser.add_option("-x","--xsize",
+ action="store", dest="xsize", default=1.,
+ type='float',help="define xsize for plot")
+ parser.add_option("-y","--ysize",
+ action="store", dest="ysize", default=1.,
+ type='float',help="define ysize for plot")
+ parser.add_option("-d","--debug",
+ action="store_true", dest="debug", default=False,
+ help="use gnuplot debug mode")
+ parser.add_option("-p","--persist",
+ action="store_false", dest="persist", default=True,
+ help="do not use gnuplot persistant mode")
+ parser.add_option("-O","--outplot",
+ action="store", dest="outplot", default=None,
+ help="save plot to output.{ps,png}")
+
+def gnuplot_create(outplot='',extension='', options=None):
+ import Gnuplot
+ g = Gnuplot.Gnuplot(debug=options.debug, persist=options.persist)
+ if not extension or not outplot: return g
+ if extension == 'ps': ext, extension = '.ps' , 'postscript'
+ elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced'
+ elif extension == 'epsc': ext, extension = '.eps' , 'postscript enhanced color'
+ elif extension == 'png': ext, extension = '.png', 'png'
+ elif extension == 'svg': ext, extension = '.svg', 'svg'
+ else: exit("ERR: unknown plot extension")
+ g('set terminal %s' % extension)
+ if outplot != "stdout":
+ g('set output \'%s%s\'' % (outplot,ext))
+ g('set size %f,%f' % (options.xsize, options.ysize))
+ return g
--- a/python/aubioplot-audio
+++ b/python/aubioplot-audio
@@ -1,6 +1,7 @@
#!/usr/bin/python
-import aubio.gnuplot, sys
+import sys
+from aubio.gnuplot import gnuplot_create,gnuplot_addargs,plot_audio
usage = "usage: %s [options] -i soundfile" % sys.argv[0]
@@ -10,15 +11,7 @@
parser.add_option("-i","--input",
action="store", dest="filename",
help="input sound file")
- parser.add_option("-x","--xsize",
- action="store", dest="xsize", default=1.,
- type='float',help="define xsize for plot")
- parser.add_option("-y","--ysize",
- action="store", dest="ysize", default=1.,
- type='float',help="define ysize for plot")
- parser.add_option("-O","--outplot",
- action="store", dest="outplot", default=None,
- help="save plot to output.{ps,png}")
+ gnuplot_addargs(parser)
(options, args) = parser.parse_args()
if not options.filename:
print "no file name given\n", usage
@@ -34,7 +27,7 @@
extension = ''
outplot = None
-g = aubio.gnuplot.gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.xsize)
-aubio.gnuplot.plot_audio(options.filename.split(','), g,
+g = gnuplot_create(outplot,extension,options)
+plot_audio(options.filename.split(','), g,
xsize=options.xsize,
ysize=options.ysize)
--- a/python/aubioplot-spec
+++ b/python/aubioplot-spec
@@ -5,7 +5,7 @@
"""
import sys
-from aubio.gnuplot import *
+from aubio.gnuplot import gnuplot_create,gnuplot_addargs,plot_spec
usage = "usage: %s [options] -i soundfile" % sys.argv[0]
@@ -21,18 +21,9 @@
parser.add_option("-L","--minf",
action="store", dest="minf", default=0.,
type='float',help="lower frequency limit")
- parser.add_option("-x","--xsize",
- action="store", dest="xsize", default=1.,
- type='float',help="define xsize for plot")
- parser.add_option("-y","--ysize",
- action="store", dest="ysize", default=1.,
- type='float',help="define ysize for plot")
parser.add_option("-l","--log",
action="store_true", dest="log", default=False,
help="plot on a logarithmic scale")
- parser.add_option("-O","--outplot",
- action="store", dest="outplot", default=None,
- help="save plot to output.{ps,png}")
parser.add_option("-B","--bufsize", type='int',
action="store", dest="bufsize", default=8192,
help="buffer size [default=8192]")
@@ -39,6 +30,7 @@
parser.add_option("-H","--hopsize", type='int',
action="store", dest="hopsize", default=1024,
help="overlap size [default=1024]")
+ gnuplot_addargs(parser)
(options, args) = parser.parse_args()
if not options.filename:
print "no file name given\n", usage
@@ -55,7 +47,7 @@
extension = ''
outplot = None
-g = gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.ysize)
+g = gnuplot_create(outplot,extension,options)
plot_spec(filename, g, log=options.log,
maxf = options.maxf, minf = options.minf,
xsize = options.xsize, ysize = options.ysize,