History

[py] move cut_slice from cut to cmd to avoid cyclic import

Paul Brossier committed 8 years ago

Commit dc74f691 parent f8c75aa2 files · +28 −32Browse files

Showing the changes to python (2 of 2 files). Show all

Unified · Split

2 files
  1. python/lib/aubio/cmd.py +27 −1
  2. python/lib/aubio/cut.py +1 −31
python/lib/aubio/cmd.py+27−1
@@ -11,6 +11,7 @@ readable code examples, check out the `python/demos` folder.""" · 10 unmodified lines
11 11
12import sys12import sys
13import argparse13import argparse
14import warnings
14import aubio15import aubio
15 16
16def aubio_parser():17def aubio_parser():
@@ -507,7 +508,6 @@ class process_cut(process_onset): · 490 unmodified lines
507 return ret508 return ret
508 509
509 def flush(self, frames_read, samplerate):510 def flush(self, frames_read, samplerate):
510 from aubio.cut import _cut_slice
511 _cut_slice(self.options, self.slices)511 _cut_slice(self.options, self.slices)
512 duration = float(frames_read) / float(samplerate)512 duration = float(frames_read) / float(samplerate)
513 base_info = '%(source_file)s' % \513 base_info = '%(source_file)s' % \
@@ -518,6 +518,32 @@ class process_cut(process_onset): · 4 unmodified lines
518 info += base_info518 info += base_info
519 sys.stderr.write(info)519 sys.stderr.write(info)
520 520
521def _cut_slice(options, timestamps):
522 # cutting pass
523 nstamps = len(timestamps)
524 if nstamps > 0:
525 # generate output files
526 timestamps_end = None
527 if options.cut_every_nslices:
528 timestamps = timestamps[::options.cut_every_nslices]
529 nstamps = len(timestamps)
530 if options.cut_until_nslices and options.cut_until_nsamples:
531 msg = "using cut_until_nslices, but cut_until_nsamples is set"
532 warnings.warn(msg)
533 if options.cut_until_nsamples:
534 lag = options.cut_until_nsamples
535 timestamps_end = [t + lag for t in timestamps[1:]]
536 timestamps_end += [1e120]
537 if options.cut_until_nslices:
538 slice_lag = options.cut_until_nslices
539 timestamps_end = [t for t in timestamps[1 + slice_lag:]]
540 timestamps_end += [1e120] * (options.cut_until_nslices + 1)
541 aubio.slice_source_at_stamps(options.source_uri,
542 timestamps, timestamps_end = timestamps_end,
543 output_dir = options.output_directory,
544 samplerate = options.samplerate,
545 create_first = options.create_first)
546
521def main():547def main():
522 parser = aubio_parser()548 parser = aubio_parser()
523 if sys.version_info[0] != 3:549 if sys.version_info[0] != 3:
python/lib/aubio/cut.py+1−31
@@ -5,10 +5,7 @@ · 4 unmodified lines
5"""5"""
6 6
7import sys7import sys
8import warnings8from aubio.cmd import AubioArgumentParser, _cut_slice
9from aubio.cmd import AubioArgumentParser
10from aubio.slicing import slice_source_at_stamps
11
12 9
13def aubio_cut_parser():10def aubio_cut_parser():
14 parser = AubioArgumentParser()11 parser = AubioArgumentParser()
@@ -136,33 +133,6 @@ def _cut_analyze(options): · 121 unmodified lines
136 del s133 del s
137 return timestamps, total_frames134 return timestamps, total_frames
138 135
139
140def _cut_slice(options, timestamps):
141 # cutting pass
142 nstamps = len(timestamps)
143 if nstamps > 0:
144 # generate output files
145 timestamps_end = None
146 if options.cut_every_nslices:
147 timestamps = timestamps[::options.cut_every_nslices]
148 nstamps = len(timestamps)
149 if options.cut_until_nslices and options.cut_until_nsamples:
150 msg = "using cut_until_nslices, but cut_until_nsamples is set"
151 warnings.warn(msg)
152 if options.cut_until_nsamples:
153 lag = options.cut_until_nsamples
154 timestamps_end = [t + lag for t in timestamps[1:]]
155 timestamps_end += [1e120]
156 if options.cut_until_nslices:
157 slice_lag = options.cut_until_nslices
158 timestamps_end = [t for t in timestamps[1 + slice_lag:]]
159 timestamps_end += [1e120] * (options.cut_until_nslices + 1)
160 slice_source_at_stamps(options.source_uri,
161 timestamps, timestamps_end = timestamps_end,
162 output_dir = options.output_directory,
163 samplerate = options.samplerate,
164 create_first = options.create_first)
165
166def main():136def main():
167 parser = aubio_cut_parser()137 parser = aubio_cut_parser()
168 options = parser.parse_args()138 options = parser.parse_args()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t