X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_timefx.cc;h=d7274388aab35af77bf0968351deed9e2adbbe2c;hb=41d8747e9d4bbf10f848d907b879ba2211c89b8e;hp=6351aa9825924ab3854b9cdf65baa14346de9260;hpb=e27ac3278b0d335be0ccd9d6d6373287d406adb5;p=ardour.git diff --git a/libs/ardour/session_timefx.cc b/libs/ardour/session_timefx.cc index 6351aa9825..d7274388aa 100644 --- a/libs/ardour/session_timefx.cc +++ b/libs/ardour/session_timefx.cc @@ -27,27 +27,29 @@ #include #include -#include #include +#include +#include #include "i18n.h" using namespace std; using namespace ARDOUR; +using namespace PBD; using namespace soundtouch; -AudioRegion* +boost::shared_ptr Session::tempoize_region (TimeStretchRequest& tsr) { - AudioRegion::SourceList sources; - AudioRegion::SourceList::iterator it; - AudioRegion* r = 0; + SourceList sources; + SourceList::iterator it; + boost::shared_ptr r; SoundTouch st; string region_name; string ident = X_("-TIMEFX-"); float percentage; - jack_nframes_t total_frames; - jack_nframes_t done; + nframes_t total_frames; + nframes_t done; /* the soundtouch code wants a *tempo* change percentage, which is of opposite sign to the length change. @@ -80,7 +82,8 @@ Session::tempoize_region (TimeStretchRequest& tsr) } try { - sources.push_back(new FileSource (path, frame_rate(), false, Config->get_native_file_data_format())); + sources.push_back (boost::dynamic_pointer_cast (SourceFactory::createWritable (*this, path, false, frame_rate()))); + } catch (failed_constructor& err) { error << string_compose (_("tempoize: error creating new audio file %1 (%2)"), path, strerror (errno)) << endmsg; goto out; @@ -88,18 +91,17 @@ Session::tempoize_region (TimeStretchRequest& tsr) } try { - const jack_nframes_t bufsize = 16384; + const nframes_t bufsize = 16384; for (uint32_t i = 0; i < sources.size(); ++i) { gain_t gain_buffer[bufsize]; Sample buffer[bufsize]; - char workbuf[bufsize*4]; - jack_nframes_t pos = 0; - jack_nframes_t this_read = 0; + nframes_t pos = 0; + nframes_t this_read = 0; st.clear(); while (tsr.running && pos < tsr.region->length()) { - jack_nframes_t this_time; + nframes_t this_time; this_time = min (bufsize, tsr.region->length() - pos); @@ -107,7 +109,7 @@ Session::tempoize_region (TimeStretchRequest& tsr) not the ones currently in use, in case it's already been subject to timefx. */ - if ((this_read = tsr.region->master_read_at (buffer, buffer, gain_buffer, workbuf, pos + tsr.region->position(), this_time)) != this_time) { + if ((this_read = tsr.region->master_read_at (buffer, buffer, gain_buffer, pos + tsr.region->position(), this_time)) != this_time) { error << string_compose (_("tempoize: error reading data from %1"), sources[i]->name()) << endmsg; goto out; } @@ -120,7 +122,7 @@ Session::tempoize_region (TimeStretchRequest& tsr) st.putSamples (buffer, this_read); while ((this_read = st.receiveSamples (buffer, bufsize)) > 0 && tsr.running) { - if (sources[i]->write (buffer, this_read, workbuf) != this_read) { + if (sources[i]->write (buffer, this_read) != this_read) { error << string_compose (_("error writing tempo-adjusted data to %1"), sources[i]->name()) << endmsg; goto out; } @@ -132,7 +134,7 @@ Session::tempoize_region (TimeStretchRequest& tsr) } while (tsr.running && (this_read = st.receiveSamples (buffer, bufsize)) > 0) { - if (sources[i]->write (buffer, this_read, workbuf) != this_read) { + if (sources[i]->write (buffer, this_read) != this_read) { error << string_compose (_("error writing tempo-adjusted data to %1"), sources[i]->name()) << endmsg; goto out; } @@ -150,15 +152,17 @@ Session::tempoize_region (TimeStretchRequest& tsr) xnow = localtime (&now); for (it = sources.begin(); it != sources.end(); ++it) { - dynamic_cast(*it)->update_header (tsr.region->position(), *xnow, now); + boost::shared_ptr afs = boost::dynamic_pointer_cast(*it); + if (afs) { + afs->update_header (tsr.region->position(), *xnow, now); + } } region_name = tsr.region->name() + X_(".t"); - r = new AudioRegion (sources, 0, sources.front()->length(), region_name, - 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile)); - - + r = (boost::dynamic_pointer_cast (RegionFactory::create (sources, 0, sources.front()->length(), region_name, + 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile)))); + out: if (sources.size()) { @@ -167,21 +171,19 @@ Session::tempoize_region (TimeStretchRequest& tsr) for deletion. */ - if ((r == 0 || !tsr.running)) { + if ((!r || !tsr.running)) { for (it = sources.begin(); it != sources.end(); ++it) { (*it)->mark_for_remove (); - delete *it; } } + + sources.clear (); } /* if the process was cancelled, delete the region */ if (!tsr.running) { - if (r) { - delete r; - r = 0; - } + r.reset (); } return r;