X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Faudiofilter.cc;h=a85ce16821689ba664d737ea85aa2b95a1009fbd;hb=ccdd99afcec1118c3a3080e6d109ebae55665336;hp=d10010fbf0c8d858c9fecab2cbecaadb8bc6bc3d;hpb=c268314b64c2235b0d69c3854e303accd2cad4d9;p=ardour.git diff --git a/libs/ardour/audiofilter.cc b/libs/ardour/audiofilter.cc index d10010fbf0..a85ce16821 100644 --- a/libs/ardour/audiofilter.cc +++ b/libs/ardour/audiofilter.cc @@ -27,6 +27,7 @@ #include #include #include +#include #include "i18n.h" @@ -34,13 +35,32 @@ using namespace ARDOUR; using namespace PBD; int -AudioFilter::make_new_sources (boost::shared_ptr region, SourceList& nsrcs) +AudioFilter::make_new_sources (boost::shared_ptr region, SourceList& nsrcs, string suffix) { vector names = region->master_source_names(); + if (names.size() != region->n_channels()) { + warning << _("This is an old Ardour session that does not have\n\ +sufficient information for rendered FX") << endmsg; + return -1; + } + for (uint32_t i = 0; i < region->n_channels(); ++i) { - string path = session.path_from_region_name (PBD::basename_nosuffix (names[i]), string ("")); + string name = PBD::basename_nosuffix (names[i]); + + /* remove any existing version of suffix by assuming it starts + with some kind of "special" character. + */ + + if (!suffix.empty()) { + string::size_type pos = name.find (suffix[0]); + if (pos != string::npos && pos > 2) { + name = name.substr (0, pos - 1); + } + } + + string path = session.path_from_region_name (name, suffix); if (path.length() == 0) { error << string_compose (_("audiofilter: error creating name for new audio file based on %1"), region->name()) @@ -50,6 +70,7 @@ AudioFilter::make_new_sources (boost::shared_ptr region, SourceList try { nsrcs.push_back (boost::dynamic_pointer_cast (SourceFactory::createWritable (session, path, false, session.frame_rate()))); + nsrcs.back()->prepare_for_peakfile_writes (); } catch (failed_constructor& err) { @@ -62,10 +83,8 @@ AudioFilter::make_new_sources (boost::shared_ptr region, SourceList } int -AudioFilter::finish (boost::shared_ptr region, SourceList& nsrcs) +AudioFilter::finish (boost::shared_ptr region, SourceList& nsrcs, string region_name) { - string region_name; - /* update headers on new sources */ time_t xnow; @@ -76,18 +95,60 @@ AudioFilter::finish (boost::shared_ptr region, SourceList& nsrcs) for (SourceList::iterator si = nsrcs.begin(); si != nsrcs.end(); ++si) { boost::shared_ptr afs = boost::dynamic_pointer_cast(*si); + boost::shared_ptr as = boost::dynamic_pointer_cast(*si); + + if (as) { + as->done_with_peakfile_writes (); + } + if (afs) { afs->update_header (region->position(), *now, xnow); afs->mark_immutable (); } + + /* now that there is data there, requeue the file for analysis */ + + if (Config->get_auto_analyse_audio()) { + Analyser::queue_source_for_analysis (*si, false); + } } + + /* make a new whole-file region that copies almost everything from the old one, but + uses the new sources (and new length and name) + */ + + boost::shared_ptr ar; + boost::shared_ptr afs = boost::dynamic_pointer_cast(nsrcs.front()); + + string whole_file_region_name = region_name_from_path (afs->path(), true); + + ar = boost::dynamic_pointer_cast (RegionFactory::create + (nsrcs, 0, nsrcs.front()->length(), whole_file_region_name, 0, + Region::Flag (Region::WholeFile|Region::DefaultFlags))); + + /* now make a copy of the region that copies almost everything from the old one, but + uses the new sources (and new length and name) + */ + /* create a new region */ - region_name = session.new_region_name (region->name()); + if (region_name.empty()) { + region_name = session.new_region_name (region->name()); + } + results.clear (); - results.push_back (boost::dynamic_pointer_cast (RegionFactory::create (nsrcs, 0, region->length(), region_name, 0, - Region::Flag (Region::WholeFile|Region::DefaultFlags)))); + + ar = boost::dynamic_pointer_cast (RegionFactory::create + (region, nsrcs, region_name, 0, region->flags())); + + /* if we changed the length, fix up the envelope */ + + if (region->length() != ar->length()) { + ar->envelope().extend_to (ar->length()); + } + + results.push_back (ar); return 0; }