Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -168,10 +168,10 @@ class AubioArgumentParser(argparse.ArgumentParser): · 167 unmodified lines | ||
| 168 | 168 | help="samplerate at which the file should be represented") |
| 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") |
| 177 | 177 | |
| @@ -180,25 +180,25 @@ class AubioArgumentParser(argparse.ArgumentParser): · 2 unmodified lines | ||
| 180 | 180 | self.add_hop_size(hop_size=hop_size) |
| 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, |
| 186 | 186 | help="buffer size [default=%d]" % buf_size) |
| 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, |
| 192 | 192 | help="overlap size [default=%d]" % 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, |
| 198 | 198 | help="%s [default=%s]" % (helpstr, 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, |
| 204 | 204 | help="threshold [default=%s]" % default) |
| @@ -239,14 +239,16 @@ class AubioArgumentParser(argparse.ArgumentParser): · 34 unmodified lines | ||
| 239 | 239 | help=helpstr) |
| 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>", |
| 252 | 254 | action = "store", dest = "cut_every_nslices", default = None, |
| @@ -254,7 +256,8 @@ class AubioArgumentParser(argparse.ArgumentParser): · 1 unmodified line | ||
| 254 | 256 | self.add_argument("--cut-until-nslices", type = int, |
| 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, |
| 260 | 263 | help="always include first slice") |
| @@ -288,7 +291,8 @@ class default_process(object): · 27 unmodified lines | ||
| 288 | 291 | self.time2string = timefunc(args.time_format) |
| 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): |
| 294 | 298 | # optionally called at the end of process |
| @@ -296,7 +300,7 @@ class default_process(object): · 1 unmodified line | ||
| 296 | 300 | |
| 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 | |
| 302 | 306 | def remap_pvoc_options(self, options): |
| @@ -377,7 +381,7 @@ class process_tempo(process_beat): · 74 unmodified lines | ||
| 377 | 381 | if len(self.beat_locations) < 2: |
| 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: |
| 383 | 387 | outstr = "%.2f bpm (uncertain)" % median_bpm |
| @@ -398,14 +402,14 @@ class process_notes(default_process): · 14 unmodified lines | ||
| 398 | 402 | def __call__(self, block): |
| 399 | 403 | return self.notes(block) |
| 400 | 404 | def repr_res(self, res, frames_read, samplerate): |
| 401 | − if res[2] != 0: # note off | |
| 405 | + 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 on | |
| 408 | + 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) |
| 411 | 415 | sys.stdout.write(eof + '\n') |
| @@ -472,13 +476,13 @@ class process_quiet(default_process): · 60 unmodified lines | ||
| 472 | 476 | if aubio.silence_detection(block, self.silence) == 1: |
| 473 | 477 | if self.wassilence != 1: |
| 474 | 478 | self.wassilence = 1 |
| 475 | − return 2 # newly found silence | |
| 476 | − return 1 # silence again | |
| 479 | + 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 noise | |
| 481 | − return 0 # noise again | |
| 484 | + return -1 # newly found noise | |
| 485 | + return 0 # noise again | |
| 482 | 486 | |
| 483 | 487 | def repr_res(self, res, frames_read, samplerate): |
| 484 | 488 | fmt_out = None |
| @@ -498,16 +502,18 @@ class process_cut(process_onset): · 13 unmodified lines | ||
| 498 | 502 | |
| 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 | |
| 504 | 509 | def flush(self, frames_read, samplerate): |
| 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 |
| 513 | 519 | sys.stderr.write(info) |
| @@ -525,19 +531,20 @@ def main(): · 11 unmodified lines | ||
| 525 | 531 | parser_root.add_argument('-V', '--version', help="show version", |
| 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 parser | |
| 534 | + 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 help | |
| 536 | + 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 directly | |
| 539 | + 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: |
| 536 | 542 | sys.stdout.write('aubio version ' + aubio.version + '\n') |
| 537 | 543 | sys.exit(0) |
| 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() |
| 543 | 550 | if args.command and args.command in ['help']: |
| @@ -571,7 +578,8 @@ def main(): · 27 unmodified lines | ||
| 571 | 578 | # increment total number of frames read |
| 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) |
| 577 | 585 | if args.verbose > 1: |
| @@ -579,7 +587,7 @@ def main(): · 1 unmodified line | ||
| 579 | 587 | fmt_string += " ({:d} samples in {:d} blocks of {:d})" |
| 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, |
| 585 | 593 | a_source.hop_size, |