shithub: aubio

Download patch

ref: 5ab3c4ece2ba1500c268606df583828d85f6a0ec
parent: 6288806873682848af2dc58fccd51c940a9d35a6
author: Paul Brossier <piem@piem.org>
date: Thu Mar 23 11:09:28 EDT 2017

python/lib/aubio/cmd.py: add a flush function

--- a/python/lib/aubio/cmd.py
+++ b/python/lib/aubio/cmd.py
@@ -194,6 +194,8 @@
             name = type(self).__name__.split('_')[1]
             optstr = ' '.join(['running', name, 'with options', repr(self.options), '\n'])
             sys.stderr.write(optstr)
+    def flush(self, n_frames, samplerate):
+        pass
 
 class process_onset(default_process):
     valid_opts = ['method', 'hop_size', 'buf_size', 'samplerate']
@@ -265,6 +267,9 @@
             fmt_out = "%f\t" % lastmidi
             fmt_out += self.time2string(frames_read, samplerate)
             sys.stdout.write(fmt_out) # + '\t')
+    def flush(self, frames_read, samplerate):
+        eof = self.time2string(frames_read, samplerate)
+        sys.stdout.write(eof + '\n')
 
 class process_mfcc(default_process):
     def __init__(self, args):
@@ -350,11 +355,8 @@
                 frames_read += read
                 # exit loop at end of file
                 if read < a_source.hop_size: break
-            # special case for notes
-            if args.command == 'notes':
-                eof = processor.time2string(frames_read, a_source.samplerate)
-                sys.stdout.write(eof + '\n')
-                sys.stdout.flush()
+            # flush the processor if needed
+            processor.flush(frames_read, a_source.samplerate)
             if args.verbose > 1:
                 fmt_string = "read {:.2f}s"
                 fmt_string += " ({:d} samples in {:d} blocks of {:d})"