[py] move cut_slice from cut to cmd to avoid cyclic import
authorPaul Brossier <piem@piem.org>
Mon, 5 Nov 2018 13:02:20 +0000 (14:02 +0100)
committerPaul Brossier <piem@piem.org>
Mon, 5 Nov 2018 13:02:20 +0000 (14:02 +0100)
python/lib/aubio/cmd.py
python/lib/aubio/cut.py

index 5b7acb8..05780ea 100644 (file)
@@ -11,6 +11,7 @@ readable code examples, check out the `python/demos` folder."""
 
 import sys
 import argparse
 
 import sys
 import argparse
+import warnings
 import aubio
 
 def aubio_parser():
 import aubio
 
 def aubio_parser():
@@ -507,7 +508,6 @@ class process_cut(process_onset):
         return ret
 
     def flush(self, frames_read, samplerate):
         return ret
 
     def flush(self, frames_read, samplerate):
-        from aubio.cut import _cut_slice
         _cut_slice(self.options, self.slices)
         duration = float(frames_read) / float(samplerate)
         base_info = '%(source_file)s' % \
         _cut_slice(self.options, self.slices)
         duration = float(frames_read) / float(samplerate)
         base_info = '%(source_file)s' % \
@@ -518,6 +518,32 @@ class process_cut(process_onset):
         info += base_info
         sys.stderr.write(info)
 
         info += base_info
         sys.stderr.write(info)
 
+def _cut_slice(options, timestamps):
+    # cutting pass
+    nstamps = len(timestamps)
+    if nstamps > 0:
+        # generate output files
+        timestamps_end = None
+        if options.cut_every_nslices:
+            timestamps = timestamps[::options.cut_every_nslices]
+            nstamps = len(timestamps)
+        if options.cut_until_nslices and options.cut_until_nsamples:
+            msg = "using cut_until_nslices, but cut_until_nsamples is set"
+            warnings.warn(msg)
+        if options.cut_until_nsamples:
+            lag = options.cut_until_nsamples
+            timestamps_end = [t + lag for t in timestamps[1:]]
+            timestamps_end += [1e120]
+        if options.cut_until_nslices:
+            slice_lag = options.cut_until_nslices
+            timestamps_end = [t for t in timestamps[1 + slice_lag:]]
+            timestamps_end += [1e120] * (options.cut_until_nslices + 1)
+        aubio.slice_source_at_stamps(options.source_uri,
+                timestamps, timestamps_end = timestamps_end,
+                output_dir = options.output_directory,
+                samplerate = options.samplerate,
+                create_first = options.create_first)
+
 def main():
     parser = aubio_parser()
     if sys.version_info[0] != 3:
 def main():
     parser = aubio_parser()
     if sys.version_info[0] != 3:
index 09f44a1..a31e38d 100644 (file)
@@ -5,10 +5,7 @@
 """
 
 import sys
 """
 
 import sys
-import warnings
-from aubio.cmd import AubioArgumentParser
-from aubio.slicing import slice_source_at_stamps
-
+from aubio.cmd import AubioArgumentParser, _cut_slice
 
 def aubio_cut_parser():
     parser = AubioArgumentParser()
 
 def aubio_cut_parser():
     parser = AubioArgumentParser()
@@ -136,33 +133,6 @@ def _cut_analyze(options):
     del s
     return timestamps, total_frames
 
     del s
     return timestamps, total_frames
 
-
-def _cut_slice(options, timestamps):
-    # cutting pass
-    nstamps = len(timestamps)
-    if nstamps > 0:
-        # generate output files
-        timestamps_end = None
-        if options.cut_every_nslices:
-            timestamps = timestamps[::options.cut_every_nslices]
-            nstamps = len(timestamps)
-        if options.cut_until_nslices and options.cut_until_nsamples:
-            msg = "using cut_until_nslices, but cut_until_nsamples is set"
-            warnings.warn(msg)
-        if options.cut_until_nsamples:
-            lag = options.cut_until_nsamples
-            timestamps_end = [t + lag for t in timestamps[1:]]
-            timestamps_end += [1e120]
-        if options.cut_until_nslices:
-            slice_lag = options.cut_until_nslices
-            timestamps_end = [t for t in timestamps[1 + slice_lag:]]
-            timestamps_end += [1e120] * (options.cut_until_nslices + 1)
-        slice_source_at_stamps(options.source_uri,
-                timestamps, timestamps_end = timestamps_end,
-                output_dir = options.output_directory,
-                samplerate = options.samplerate,
-                create_first = options.create_first)
-
 def main():
     parser = aubio_cut_parser()
     options = parser.parse_args()
 def main():
     parser = aubio_cut_parser()
     options = parser.parse_args()