#!/usr/bin/python""" this file is used to get filter the (old) output format of aubionotes """# default parameters __eps = [0.250,0.50] # minimum length, pitch tolerance (ms,midipitch)__plot = 0 # -P (command line switch)__delay = 0.0 # -D <value> (fixed delay for score alignement)__winlength = 10 # -w <value> (window length for pitch estimation in frames)import getoptimport sysdef parse_args (sysargs): from getopt import gnu_getopt shortopts ='i:o:t:p:w:D:P:' longopts =('input=','output=','tolpitch=','toltime=','winlength=','delay','plot=') args,tmp = gnu_getopt(sysargs,shortopts,longopts) assert len(args) > 1 plot = __plot delay = __delay eps = __eps winlength = __winlength plot = __plot fileout = '/tmp/testprint.ps' args.sort() for i in range(len(args)): # a bad way if args[i][0] == '-i' or args[i][0] == '--input': fileorg = args[i][1] if args[i][0] == '-o' or args[i][0] == '--output': fileerr = args[i][1] if args[i][0] == '-t' or args[i][0] == '--toltime': eps[0] = float(args[i][1]) if args[i][0] == '-p' or args[i][0] == '--tolpitch': eps[1] = float(args[i][1]) if args[i][0] == '-D' or args[i][0] == '--delay': delay = float(args[i][1]) if args[i][0] == '-w' or args[i][0] == '--winlength': winlength = int(args[i][1]) if args[i][0] == '-P' or args[i][0] == '--plot': plot = 1 fileout = args[i][1] return fileorg,fileerr,eps,winlength,plot,delay,fileoutdef usage(): print __file__, "with at least some arguments"def main(): try: opts,args = getopt.getopt(sys.argv[1:], "hvo:i:p:P", ["help", "output=", "verbose", "input=", "plot="]) except getopt.GetoptError: usage() sys.exit(2) input = None output = None verbose = False winlength = __winlength plot = __plot eps = __eps for o, a in opts: if o in ("-v", "--verbose"): verbose = True if o in ("-h", "--help"): usage() sys.exit(2) if o in ("--output"): output = a if o in ("-i", "--input"): input = a if o in ("-P", "--plot"): plot = 1 assert input != None and input != "", "no input file" from aubio import notefilter,txtfile,gnuplot """ load midi and raw data """ from numpy import array notelist = array(txtfile.read_datafile(input)) """ filter it out """ notelist_filtered = notefilter.segraw_onsets4(notelist,winlength,eps) if verbose == 1 : for a,b in notelist_filtered: print a,b """ plot results """ if plot == 1 : gnuplot.plotnote(notelist_filtered,title=input,fileout=output)if __name__ == "__main__": main()
#!/usr/bin/python
""" this file is used to get filter the (old) output format of aubionotes """
# default parameters
__eps = [0.250,0.50] # minimum length, pitch tolerance (ms,midipitch)
__plot = 0 # -P (command line switch)
__delay = 0.0 # -D <value> (fixed delay for score alignement)
__winlength = 10 # -w <value> (window length for pitch estimation in frames)
import getopt
import sys
def parse_args (sysargs):
from getopt import gnu_getopt
shortopts ='i:o:t:p:w:D:P:'
longopts =('input=','output=','tolpitch=','toltime=','winlength=','delay','plot=')
args,tmp = gnu_getopt(sysargs,shortopts,longopts)
assert len(args) > 1
plot = __plot
delay = __delay
eps = __eps
winlength = __winlength
plot = __plot
fileout = '/tmp/testprint.ps'
args.sort()
for i in range(len(args)): # a bad way
if args[i][0] == '-i' or args[i][0] == '--input':
fileorg = args[i][1]
if args[i][0] == '-o' or args[i][0] == '--output':
fileerr = args[i][1]
if args[i][0] == '-t' or args[i][0] == '--toltime':
eps[0] = float(args[i][1])
if args[i][0] == '-p' or args[i][0] == '--tolpitch':
eps[1] = float(args[i][1])
if args[i][0] == '-D' or args[i][0] == '--delay':
delay = float(args[i][1])
if args[i][0] == '-w' or args[i][0] == '--winlength':
winlength = int(args[i][1])
if args[i][0] == '-P' or args[i][0] == '--plot':
plot = 1
fileout = args[i][1]
return fileorg,fileerr,eps,winlength,plot,delay,fileout
def usage():
print __file__, "with at least some arguments"
def main():
try:
opts,args = getopt.getopt(sys.argv[1:],
"hvo:i:p:P",
["help", "output=", "verbose", "input=", "plot="])
except getopt.GetoptError:
usage()
sys.exit(2)
input = None
output = None
verbose = False
winlength = __winlength
plot = __plot
eps = __eps
for o, a in opts:
if o in ("-v", "--verbose"):
verbose = True
if o in ("-h", "--help"):
usage()
sys.exit(2)
if o in ("--output"):
output = a
if o in ("-i", "--input"):
input = a
if o in ("-P", "--plot"):
plot = 1
assert input != None and input != "", "no input file"
from aubio import notefilter,txtfile,gnuplot
""" load midi and raw data """
from numpy import array
notelist = array(txtfile.read_datafile(input))
""" filter it out """
notelist_filtered = notefilter.segraw_onsets4(notelist,winlength,eps)
if verbose == 1 :
for a,b in notelist_filtered:
print a,b
""" plot results """
if plot == 1 :
gnuplot.plotnote(notelist_filtered,title=input,fileout=output)
if __name__ == "__main__":
main()