ref: dc74f69e5d1ca32f9dbd4fc0e23de5ed015f7a13
parent: f8c75aaa3c89099bc4a46b325e4bbc5c8c82d106
author: Paul Brossier <piem@piem.org>
date: Mon Nov 5 09:02:20 EST 2018
[py] move cut_slice from cut to cmd to avoid cyclic import
--- a/python/lib/aubio/cmd.py
+++ b/python/lib/aubio/cmd.py
@@ -11,6 +11,7 @@
import sys
import argparse
+import warnings
import aubio
def aubio_parser():
@@ -507,7 +508,6 @@
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' % \
@@ -517,6 +517,32 @@
info = "created %d slices from " % len(self.slices)
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()
--- a/python/lib/aubio/cut.py
+++ b/python/lib/aubio/cut.py
@@ -5,11 +5,8 @@
"""
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()
parser.add_input()
@@ -135,33 +132,6 @@
break
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()