when renaming redirects, scan all routes AND sends AND port inserts for the name...
[ardour.git] / libs / ardour / audiofilter.cc
index ee38bff89c66884bf93f899fe47cd8324c55e2f7..a85ce16821689ba664d737ea85aa2b95a1009fbd 100644 (file)
@@ -27,6 +27,7 @@
 #include <ardour/audiofilter.h>
 #include <ardour/region_factory.h>
 #include <ardour/source_factory.h>
+#include <ardour/analyser.h>
 
 #include "i18n.h"
 
@@ -38,6 +39,12 @@ AudioFilter::make_new_sources (boost::shared_ptr<AudioRegion> region, SourceList
 {
        vector<string> 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 name = PBD::basename_nosuffix (names[i]);
@@ -98,16 +105,50 @@ AudioFilter::finish (boost::shared_ptr<AudioRegion> region, SourceList& nsrcs, s
                        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<AudioRegion> ar;
+       boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(nsrcs.front());
+
+       string whole_file_region_name = region_name_from_path (afs->path(), true);
+
+       ar = boost::dynamic_pointer_cast<AudioRegion> (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 */
 
        if (region_name.empty()) {
                region_name = session.new_region_name (region->name());
        }
+
        results.clear ();
-       results.push_back (boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (nsrcs, 0, nsrcs.front()->length(), region_name, 0, 
-                                                                                           Region::Flag (Region::WholeFile|Region::DefaultFlags))));
+
+       ar = boost::dynamic_pointer_cast<AudioRegion> (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;
 }