Changeset 78ebc27 for python/lib
- Timestamp:
- Nov 4, 2018, 8:00:04 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
- Children:
- 2c8ada6
- Parents:
- a5c3f2a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/cmd.py
ra5c3f2a r78ebc27 169 169 170 170 def add_verbose_help(self): 171 self.add_argument("-v", "--verbose",171 self.add_argument("-v", "--verbose", 172 172 action="count", dest="verbose", default=1, 173 173 help="make lots of noise [default]") 174 self.add_argument("-q", "--quiet",174 self.add_argument("-q", "--quiet", 175 175 action="store_const", dest="verbose", const=0, 176 176 help="be quiet") … … 181 181 182 182 def add_buf_size(self, buf_size=512): 183 self.add_argument("-B", "--bufsize",183 self.add_argument("-B", "--bufsize", 184 184 action="store", dest="buf_size", default=buf_size, 185 185 metavar = "<size>", type=int, … … 187 187 188 188 def add_hop_size(self, hop_size=256): 189 self.add_argument("-H", "--hopsize",189 self.add_argument("-H", "--hopsize", 190 190 metavar = "<size>", type=int, 191 191 action="store", dest="hop_size", default=hop_size, … … 193 193 194 194 def add_method(self, method='default', helpstr='method'): 195 self.add_argument("-m", "--method",195 self.add_argument("-m", "--method", 196 196 metavar = "<method>", type=str, 197 197 action="store", dest="method", default=method, … … 199 199 200 200 def add_threshold(self, default=None): 201 self.add_argument("-t", "--threshold",201 self.add_argument("-t", "--threshold", 202 202 metavar = "<threshold>", type=float, 203 203 action="store", dest="threshold", default=default, … … 240 240 241 241 def add_slicer_options(self): 242 self.add_argument("-o", "--output", type = str,242 self.add_argument("-o", "--output", type = str, 243 243 metavar = "<outputdir>", 244 244 action="store", dest="output_directory", default=None, 245 help="specify path where slices of the original file should be created") 245 help="specify path where slices of the original file should' 246 ' be created") 246 247 self.add_argument("--cut-until-nsamples", type = int, 247 248 metavar = "<samples>", 248 249 action = "store", dest = "cut_until_nsamples", default = None, 249 help="how many extra samples should be added at the end of each slice") 250 help="how many extra samples should be added at the end of' 251 ' each slice") 250 252 self.add_argument("--cut-every-nslices", type = int, 251 253 metavar = "<samples>", … … 255 257 metavar = "<slices>", 256 258 action = "store", dest = "cut_until_nslices", default = None, 257 help="how many extra slices should be added at the end of each slice") 259 help="how many extra slices should be added at the end of' 260 ' each slice") 258 261 self.add_argument("--create-first", 259 262 action = "store_true", dest = "create_first", default = False, … … 289 292 if args.verbose > 2 and hasattr(self, 'options'): 290 293 name = type(self).__name__.split('_')[1] 291 optstr = ' '.join(['running', name, 'with options', repr(self.options), '\n']) 294 optstr = ' '.join(['running', name, 'with options', 295 repr(self.options), '\n']) 292 296 sys.stderr.write(optstr) 293 297 def flush(self, frames_read, samplerate): … … 297 301 def parse_options(self, args, valid_opts): 298 302 # get any valid options found in a dictionnary of arguments 299 options = {k :v for k,v in vars(args).items() if k in valid_opts}303 options = {k: v for k, v in vars(args).items() if k in valid_opts} 300 304 self.options = options 301 305 … … 378 382 outstr = "unknown bpm" 379 383 else: 380 bpms = 60. / np.diff(self.beat_locations)384 bpms = 60. / np.diff(self.beat_locations) 381 385 median_bpm = np.mean(bpms) 382 386 if len(self.beat_locations) < 10: … … 399 403 return self.notes(block) 400 404 def repr_res(self, res, frames_read, samplerate): 401 if res[2] != 0: # note off405 if res[2] != 0: # note off 402 406 fmt_out = self.time2string(frames_read, samplerate) 403 407 sys.stdout.write(fmt_out + '\n') 404 if res[0] != 0: # note on408 if res[0] != 0: # note on 405 409 lastmidi = res[0] 406 410 fmt_out = "%f\t" % lastmidi 407 411 fmt_out += self.time2string(frames_read, samplerate) 408 sys.stdout.write(fmt_out) # + '\t')412 sys.stdout.write(fmt_out) # + '\t') 409 413 def flush(self, frames_read, samplerate): 410 414 eof = self.time2string(frames_read, samplerate) … … 473 477 if self.wassilence != 1: 474 478 self.wassilence = 1 475 return 2 # newly found silence476 return 1 # silence again479 return 2 # newly found silence 480 return 1 # silence again 477 481 else: 478 482 if self.wassilence != 0: 479 483 self.wassilence = 0 480 return -1 # newly found noise481 return 0 # noise again484 return -1 # newly found noise 485 return 0 # noise again 482 486 483 487 def repr_res(self, res, frames_read, samplerate): … … 499 503 def __call__(self, block): 500 504 ret = super(process_cut, self).__call__(block) 501 if ret: self.slices.append(self.onset.get_last()) 505 if ret: 506 self.slices.append(self.onset.get_last()) 502 507 return ret 503 508 … … 505 510 from aubio.cut import _cut_slice 506 511 _cut_slice(self.options, self.slices) 507 duration = float (frames_read) / float(samplerate) 508 base_info = '%(source_file)s' % {'source_file': self.options.source_uri} 512 duration = float(frames_read) / float(samplerate) 513 base_info = '%(source_file)s' % \ 514 {'source_file': self.options.source_uri} 509 515 base_info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % \ 510 {'duration': duration, 'samplerate': samplerate}516 {'duration': duration, 'samplerate': samplerate} 511 517 info = "created %d slices from " % len(self.slices) 512 518 info += base_info … … 526 532 action="store_true", dest="show_version") 527 533 args, extras = parser_root.parse_known_args() 528 if args.show_version == False:# no -V, forward to parser534 if not args.show_version: # no -V, forward to parser 529 535 args = parser.parse_args(extras, namespace=args) 530 elif len(extras) != 0: # -V with other arguments, print help536 elif len(extras) != 0: # -V with other arguments, print help 531 537 parser.print_help() 532 538 sys.exit(1) 533 else: # in py3, we can simply use parser directly539 else: # in py3, we can simply use parser directly 534 540 args = parser.parse_args() 535 541 if 'show_version' in args and args.show_version: … … 538 544 elif 'verbose' in args and args.verbose > 3: 539 545 sys.stderr.write('aubio version ' + aubio.version + '\n') 540 if 'command' not in args or args.command is None or args.command in ['help']: 546 if 'command' not in args or args.command is None \ 547 or args.command in ['help']: 541 548 # no command given, print help and return 1 542 549 parser.print_help() … … 572 579 frames_read += read 573 580 # exit loop at end of file 574 if read < a_source.hop_size: break 581 if read < a_source.hop_size: 582 break 575 583 # flush the processor if needed 576 584 processor.flush(frames_read, a_source.samplerate) … … 580 588 fmt_string += " from {:s} at {:d}Hz\n" 581 589 sys.stderr.write(fmt_string.format( 582 frames_read /float(a_source.samplerate),590 frames_read / float(a_source.samplerate), 583 591 frames_read, 584 592 frames_read // a_source.hop_size + 1,
Note: See TracChangeset
for help on using the changeset viewer.