48 #include <rubberband/RubberBandStretcher.h>
68 begin_reversible_command (
_(
"stretch/shrink"));
70 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
71 if ((*i)->region()->data_type() == DataType::AUDIO) {
72 audio.push_back ((*i)->region());
73 }
else if ((*i)->region()->data_type() == DataType::MIDI) {
74 midi.push_back ((*i)->region());
78 if ((aret = time_fx (audio, fraction,
false)) != 0) {
79 commit_reversible_command ();
83 set<boost::shared_ptr<Playlist> > midi_playlists_affected;
85 for (RegionList::iterator i = midi.begin(); i != midi.end(); ++i) {
97 for (RegionList::iterator i = midi.begin(); i != midi.end(); ++i) {
108 regions.front()->region()->position());
109 midi_playlists_affected.insert (playlist);
116 commit_reversible_command ();
126 for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
127 rl.push_back ((*i)->region());
130 begin_reversible_command (
_(
"pitch shift"));
132 int ret = time_fx (rl, fraction,
true);
135 commit_reversible_command ();
147 delete current_timefx;
149 current_timefx->regions =
regions;
152 RegionList::iterator i = regions.begin ();
157 if (i == regions.end ()) {
163 switch (current_timefx->run ()) {
164 case RESPONSE_ACCEPT:
167 current_timefx->hide ();
171 current_timefx->status = 0;
175 float cents = current_timefx->pitch_octave_adjustment.get_value() * 1200.0;
176 float pitch_fraction;
177 cents += current_timefx->pitch_semitone_adjustment.get_value() * 100.0;
178 cents += current_timefx->pitch_cent_adjustment.get_value();
182 current_timefx->hide ();
190 pitch_fraction = pow(2, cents/1200);
192 current_timefx->request.time_fraction = 1.0;
193 current_timefx->request.pitch_fraction = pitch_fraction;
197 current_timefx->request.time_fraction = val;
198 current_timefx->request.pitch_fraction = 1.0;
202 #ifdef USE_RUBBERBAND
205 RubberBandStretcher::Options options = 0;
207 bool realtime =
false;
208 bool precise =
false;
209 bool peaklock =
true;
210 bool longwin =
false;
211 bool shortwin =
false;
212 bool preserve_formants =
false;
217 BandLimitedTransients,
219 } transients = Transients;
221 precise = current_timefx->precise_button.get_active();
222 preserve_formants = current_timefx->preserve_formants_button.get_active();
224 txt = current_timefx->stretch_opts_selector.get_active_text ();
226 for (
int i = 0; i <= 6; i++) {
227 if (txt == rb_opt_strings[i]) {
233 switch (rb_current_opt) {
235 transients = NoTransients; peaklock =
false; longwin =
true; shortwin =
false;
238 transients = NoTransients; peaklock =
false; longwin =
false; shortwin =
false;
241 transients = NoTransients; peaklock =
true; longwin =
false; shortwin =
false;
244 transients = BandLimitedTransients; peaklock =
true; longwin =
false; shortwin =
false;
247 transients = Transients; peaklock =
false; longwin =
false; shortwin =
true;
250 transients = NoTransients;
252 preserve_formants =
false;
253 current_timefx->request.pitch_fraction = 1/val;
259 transients = Transients; peaklock =
true; longwin =
false; shortwin =
false;
263 if (realtime) options |= RubberBandStretcher::OptionProcessRealTime;
264 if (precise) options |= RubberBandStretcher::OptionStretchPrecise;
265 if (preserve_formants) options |= RubberBandStretcher::OptionFormantPreserved;
266 if (!peaklock) options |= RubberBandStretcher::OptionPhaseIndependent;
267 if (longwin) options |= RubberBandStretcher::OptionWindowLong;
268 if (shortwin) options |= RubberBandStretcher::OptionWindowShort;
270 switch (transients) {
272 options |= RubberBandStretcher::OptionTransientsSmooth;
274 case BandLimitedTransients:
275 options |= RubberBandStretcher::OptionTransientsMixed;
278 options |= RubberBandStretcher::OptionTransientsCrisp;
282 current_timefx->request.opts = (int) options;
284 current_timefx->request.quick_seek = current_timefx->quick_button.get_active();
285 current_timefx->request.antialias = !current_timefx->antialias_button.get_active();
287 current_timefx->request.done =
false;
288 current_timefx->request.cancel =
false;
292 current_timefx->first_cancel.disconnect();
293 current_timefx->first_delete.disconnect();
295 current_timefx->first_cancel = current_timefx->cancel_button->signal_clicked().connect
297 current_timefx->first_delete = current_timefx->signal_delete_event().connect
301 current_timefx->hide ();
302 error <<
_(
"timefx cannot be started - thread creation error") <<
endmsg;
306 pthread_detach (current_timefx->request.thread);
308 while (!current_timefx->request.done && !current_timefx->request.cancel) {
309 gtk_main_iteration ();
312 pthread_join (current_timefx->request.thread, 0);
314 current_timefx->hide ();
315 return current_timefx->status;
323 set<boost::shared_ptr<Playlist> > playlists_affected;
325 uint32_t
const N = current_timefx->regions.size ();
327 for (RegionList::iterator i = current_timefx->regions.begin(); i != current_timefx->regions.end(); ++i) {
335 for (RegionList::iterator i = current_timefx->regions.begin(); i != current_timefx->regions.end(); ++i) {
339 if (!region || (playlist = region->
playlist()) == 0) {
343 if (current_timefx->request.cancel) {
346 current_timefx->status = 1;
352 if (current_timefx->pitching) {
353 fx =
new Pitch (*_session, current_timefx->request);
355 #ifdef USE_RUBBERBAND
356 fx =
new RBStretch (*_session, current_timefx->request);
358 fx =
new STStretch (*_session, current_timefx->request);
362 current_timefx->descend (1.0 / N);
364 if (fx->
run (region, current_timefx)) {
365 current_timefx->status = -1;
366 current_timefx->request.done =
true;
372 new_region = fx->
results.front();
375 playlists_affected.insert (playlist);
378 current_timefx->ascend ();
386 current_timefx->status = 0;
387 current_timefx->request.done =
true;
393 SessionEvent::create_per_thread_pool (
"timefx events", 64);
397 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
406 #ifdef PLATFORM_WINDOWS
407 Glib::usleep(2 * G_USEC_PER_SEC);
409 struct timespec t = { 2, 0 };
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r)
virtual int run(boost::shared_ptr< ARDOUR::Region >, Progress *progress=0)=0
LIBPBD_API Transmitter error
std::ostream & endmsg(std::ostream &ostr)
LIBARDOUR_API PBD::PropertyDescriptor< float > stretch
gint delete_in_progress(GdkEventAny *)
int time_stretch(RegionSelection &, float fraction)
void replace_region(boost::shared_ptr< Region > old, boost::shared_ptr< Region > newr, framepos_t pos)
int time_fx(ARDOUR::RegionList &, float val, bool pitching)
void cancel_in_progress()
LIBARDOUR_API PBD::PropertyDescriptor< bool > regions
std::list< boost::shared_ptr< Region > > RegionList
framepos_t position() const
std::vector< boost::shared_ptr< ARDOUR::Region > > results
static void * timefx_thread(void *arg)
int run(boost::shared_ptr< ARDOUR::Region >, Progress *progress=0)
LIBPBD_API int pthread_create_and_store(std::string name, pthread_t *thread, void *(*start_routine)(void *), void *arg)
int pitch_shift(RegionSelection &, float cents)
boost::shared_ptr< ARDOUR::Playlist > playlist() const