Only show user-presets in favorite sidebar
[ardour.git] / libs / ardour / filter.cc
index eab27b4ce07fcb31359deca6607a088e39d97bd6..96e7cfa3d7664de29035daf2e5dac73111feeb04 100644 (file)
 #include <cerrno>
 
 #include "pbd/basename.h"
-#include "ardour/sndfilesource.h"
-#include "ardour/smf_source.h"
-#include "ardour/session.h"
-#include "ardour/region.h"
+
+#include "ardour/analyser.h"
+#include "ardour/audiofilesource.h"
+#include "ardour/audioregion.h"
 #include "ardour/filter.h"
+#include "ardour/region.h"
 #include "ardour/region_factory.h"
+#include "ardour/session.h"
+#include "ardour/smf_source.h"
 #include "ardour/source_factory.h"
-#include "ardour/analyser.h"
-#include "ardour/audioregion.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
 int
-Filter::make_new_sources (boost::shared_ptr<Region> region, SourceList& nsrcs, string suffix)
+Filter::make_new_sources (boost::shared_ptr<Region> region, SourceList& nsrcs, std::string suffix, bool use_session_sample_rate)
 {
        vector<string> names = region->master_source_names();
        assert (region->n_channels() <= names.size());
@@ -58,19 +59,33 @@ Filter::make_new_sources (boost::shared_ptr<Region> region, SourceList& nsrcs, s
                        }
                }
 
-               string path = session.path_from_region_name (region->data_type(),
-                               PBD::basename_nosuffix (names[i]), string (""));
+               const string path = (region->data_type() == DataType::MIDI)
+                       ? session.new_midi_source_path (name)
+                       : session.new_audio_source_path (name, region->n_channels(), i, false, false);
 
-               if (path.length() == 0) {
+               if (path.empty()) {
                        error << string_compose (_("filter: error creating name for new file based on %1"), region->name())
                              << endmsg;
                        return -1;
                }
 
                try {
+                       samplecnt_t sample_rate;
+                       if (use_session_sample_rate) {
+                               sample_rate = session.sample_rate();
+                       } else {
+                               boost::shared_ptr<AudioRegion> aregion = boost::dynamic_pointer_cast<AudioRegion>(region);
+
+                               if (aregion) {
+                                       sample_rate = aregion->audio_source()->sample_rate();
+                               } else {
+                                       return -1;
+                               }
+                       }
+
                        nsrcs.push_back (boost::dynamic_pointer_cast<Source> (
-                               SourceFactory::createWritable (region->data_type(), session,
-                                                              path, false, session.frame_rate())));
+                                                SourceFactory::createWritable (region->data_type(), session,
+                                                                               path, false, sample_rate)));
                }
 
                catch (failed_constructor& err) {
@@ -116,13 +131,19 @@ Filter::finish (boost::shared_ptr<Region> region, SourceList& nsrcs, string regi
        /* create a new region */
 
        if (region_name.empty()) {
-               region_name = session.new_region_name (region->name());
+               region_name = RegionFactory::new_region_name (region->name());
        }
        results.clear ();
 
-       boost::shared_ptr<Region> r = RegionFactory::create (nsrcs, 0, region->length(), region_name, 0,
-                                                            Region::Flag (Region::WholeFile|Region::DefaultFlags));
-       r->set_position (region->position(), 0);
+       PropertyList plist;
+
+       plist.add (Properties::start, 0);
+       plist.add (Properties::length, region->length());
+       plist.add (Properties::name, region_name);
+       plist.add (Properties::whole_file, true);
+       plist.add (Properties::position, region->position());
+
+       boost::shared_ptr<Region> r = RegionFactory::create (nsrcs, plist);
 
        boost::shared_ptr<AudioRegion> audio_region = boost::dynamic_pointer_cast<AudioRegion> (region);
        boost::shared_ptr<AudioRegion> audio_r = boost::dynamic_pointer_cast<AudioRegion> (r);
@@ -132,6 +153,7 @@ Filter::finish (boost::shared_ptr<Region> region, SourceList& nsrcs, string regi
                audio_r->set_fade_in (audio_region->fade_in ());
                audio_r->set_fade_out_active (audio_region->fade_out_active ());
                audio_r->set_fade_out (audio_region->fade_out ());
+               *(audio_r->envelope()) = *(audio_region->envelope ());
        }
        results.push_back (r);