add "origin" property to FileSource so that we can track multiple imports
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 9 Nov 2010 18:19:53 +0000 (18:19 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 9 Nov 2010 18:19:53 +0000 (18:19 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7986 d708f5d6-7413-0410-9779-e7cbd77b26cf

15 files changed:
gtk2_ardour/editor_export_audio.cc
libs/ardour/ardour/audiofilesource.h
libs/ardour/ardour/file_source.h
libs/ardour/ardour/sndfilesource.h
libs/ardour/ardour/source_factory.h
libs/ardour/audio_diskstream.cc
libs/ardour/audiofilesource.cc
libs/ardour/file_source.cc
libs/ardour/filter.cc
libs/ardour/import.cc
libs/ardour/midi_source.cc
libs/ardour/session.cc
libs/ardour/smf_source.cc
libs/ardour/sndfilesource.cc
libs/ardour/source_factory.cc

index bab5d4c1e64a4b3248723bf248f8c234197f95cc..342ccb80e0204543a8ef659e15e8ac413d5d52d8 100644 (file)
@@ -211,8 +211,8 @@ Editor::write_region (string path, boost::shared_ptr<AudioRegion> region)
                        try {
                                fs = boost::dynamic_pointer_cast<AudioFileSource> (
                                                SourceFactory::createWritable (DataType::AUDIO, *_session,
-                                                               path, true,
-                                                               false, _session->frame_rate()));
+                                                                               path, string(), true,
+                                                                               false, _session->frame_rate()));
                        }
 
                        catch (failed_constructor& err) {
@@ -350,8 +350,8 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list
                try {
                        fs = boost::dynamic_pointer_cast<AudioFileSource> (
                                        SourceFactory::createWritable (DataType::AUDIO, *_session,
-                                                       path, true,
-                                                       false, _session->frame_rate()));
+                                                                       path, string(), true,
+                                                                       false, _session->frame_rate()));
                }
 
                catch (failed_constructor& err) {
index 57b5ced93cf406253ea427ebe767d937616048fc..4f01bf4182b8c858cc4dbb4f606d50301e435374 100644 (file)
@@ -91,7 +91,7 @@ protected:
        AudioFileSource (Session&, const std::string& path, Source::Flag flags);
 
        /** Constructor to be called for new in-session files */
-       AudioFileSource (Session&, const std::string& path, Source::Flag flags,
+       AudioFileSource (Session&, const std::string& path, const std::string& origin, Source::Flag flags,
                        SampleFormat samp_format, HeaderFormat hdr_format);
 
        /** Constructor to be called for existing in-session files */
index 78210916f024e81a4559aa51ac3b179a88be86b0..4aadce27e89d4e292a492ef7e7957c5354d72c26 100644 (file)
@@ -75,12 +75,15 @@ public:
         void inc_use_count ();
        bool removable () const;
 
+        const std::string& origin() const { return _origin; }
+
        static PBD::Signal3<int,std::string,std::string,std::vector<std::string> > AmbiguousFileName;
 
 protected:
        FileSource (Session& session, DataType type,
-                       const std::string& path, 
-                       Source::Flag flags = Source::Flag(0));
+                    const std::string& path, 
+                    const std::string& origin,
+                    Source::Flag flags = Source::Flag(0));
 
        FileSource (Session& session, const XMLNode& node, bool must_exist);
 
@@ -92,9 +95,10 @@ protected:
 
        std::string _path;
        std::string _take_id;
-       bool          _file_is_new;
-       uint16_t      _channel;
-       bool          _within_session;
+       bool        _file_is_new;
+       uint16_t    _channel;
+       bool        _within_session;
+        std::string _origin;
 };
 
 } // namespace ARDOUR
index ae2cba449a7d2452fd6bcb3b809935f366f66686..ff15608d7057b68ac6305bcbc0faaa8491a83717 100644 (file)
@@ -31,10 +31,10 @@ namespace ARDOUR {
 class SndFileSource : public AudioFileSource {
   public:
        /** Constructor to be called for existing external-to-session files */
-       SndFileSource (Session&, const std::string& path, int chn, Flag flags);
+        SndFileSource (Session&, const std::string& path, int chn, Flag flags);
 
        /* Constructor to be called for new in-session files */
-       SndFileSource (Session&, const std::string& path, 
+       SndFileSource (Session&, const std::string& path, const std::string& origin,
                        SampleFormat samp_format, HeaderFormat hdr_format, nframes_t rate,
                        Flag flags = SndFileSource::default_writable_flags);
 
index 14d0de5f4dfb0c4d8f2bae067a5ac13670084c92..c59dab92234625e110f27d1473b5ed0bb9f99266 100644 (file)
@@ -48,7 +48,7 @@ class SourceFactory {
                        int chn, Source::Flag flags, bool announce = true, bool async = false);
 
        static boost::shared_ptr<Source> createWritable (DataType type, Session&,
-                       const std::string& path, 
+                        const std::string& path, const std::string& origin,
                        bool destructive, nframes_t rate, bool announce = true, bool async = false);
 
        static Glib::Cond*                               PeaksToBuild;
index b994c5e3e2ff52b1a92a3e67bdf709edad6105a0..00d89f82718e75d79406ac7fea00fe9415b1dd6d 100644 (file)
@@ -2176,7 +2176,7 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node)
                        try {
                                fs = boost::dynamic_pointer_cast<AudioFileSource> (
                                                SourceFactory::createWritable (DataType::AUDIO, _session,
-                                                               prop->value(), false, _session.frame_rate()));
+                                                                               prop->value(), string(), false, _session.frame_rate()));
                        }
 
                        catch (failed_constructor& err) {
index 12c2c6ad17ea83f83f659f2c541a666651e62dba..39701f24cc25550cff57942214ae4148c4f7a3c1 100644 (file)
@@ -91,12 +91,15 @@ struct SizedSampleBuffer {
 
 Glib::StaticPrivate<SizedSampleBuffer> thread_interleave_buffer = GLIBMM_STATIC_PRIVATE_INIT;
 
-/** Constructor used for existing internal-to-session files. */
+/** Constructor used for existing external-to-session files. */
 AudioFileSource::AudioFileSource (Session& s, const string& path, Source::Flag flags)
        : Source (s, DataType::AUDIO, path, flags)
        , AudioSource (s, path)
-       , FileSource (s, DataType::AUDIO, path, flags)
+          /* note that external files have their own path as "origin" */
+       , FileSource (s, DataType::AUDIO, path, path, flags)
 {
+        /* note that origin remains empty */
+
        if (init (_path, true)) {
                throw failed_constructor ();
        }
@@ -104,12 +107,14 @@ AudioFileSource::AudioFileSource (Session& s, const string& path, Source::Flag f
 }
 
 /** Constructor used for new internal-to-session files. */
-AudioFileSource::AudioFileSource (Session& s, const string& path, Source::Flag flags,
+AudioFileSource::AudioFileSource (Session& s, const string& path, const string& origin, Source::Flag flags,
                                  SampleFormat /*samp_format*/, HeaderFormat /*hdr_format*/)
        : Source (s, DataType::AUDIO, path, flags)
        , AudioSource (s, path)
-       , FileSource (s, DataType::AUDIO, path, flags)
+       , FileSource (s, DataType::AUDIO, path, origin, flags)
 {
+        /* note that origin remains empty */
+
        if (init (_path, false)) {
                throw failed_constructor ();
        }
@@ -258,6 +263,7 @@ AudioFileSource::get_state ()
        char buf[32];
        snprintf (buf, sizeof (buf), "%u", _channel);
        root.add_property (X_("channel"), buf);
+        root.add_property (X_("origin"), _origin);
        return root;
 }
 
index 7eac1a23ea2a10fa52845b109ad99536154f6aa2..264d6482b46b7988083056cb09d93c89e9418ed9 100644 (file)
@@ -54,11 +54,12 @@ using namespace Glib;
 
 PBD::Signal3<int,std::string,std::string,std::vector<std::string> > FileSource::AmbiguousFileName;
 
-FileSource::FileSource (Session& session, DataType type, const string& path, Source::Flag flag)
+FileSource::FileSource (Session& session, DataType type, const string& path, const string& origin, Source::Flag flag)
        : Source(session, type, path, flag)
        , _path(path)
        , _file_is_new(true)
        , _channel (0)
+        , _origin (origin)
 {
        set_within_session_from_path (path);
 }
@@ -128,6 +129,10 @@ FileSource::set_state (const XMLNode& node, int /*version*/)
                _channel = 0;
        }
 
+        if ((prop = node.property (X_("origin"))) != 0) {
+                _origin = prop->value();
+        }
+
        return 0;
 }
 
index 2bbeecf37e6f560a84c6aca7b314ea987b4b9b3a..c82f6ae4d6d4a438313892fcac4780dd8899332e 100644 (file)
@@ -70,7 +70,7 @@ Filter::make_new_sources (boost::shared_ptr<Region> region, SourceList& nsrcs, s
                try {
                        nsrcs.push_back (boost::dynamic_pointer_cast<Source> (
                                SourceFactory::createWritable (region->data_type(), session,
-                                                              path, false, session.frame_rate())));
+                                                              path, string(), false, session.frame_rate())));
                }
 
                catch (failed_constructor& err) {
index 929f3c5bf4c0c73c5d89705ca6573adca996fb64..4fc546ebd5259e26dd3668db62d286c0681cfa1f 100644 (file)
@@ -202,25 +202,27 @@ map_existing_mono_sources (const vector<string>& new_paths, Session& /*sess*/,
 }
 
 static bool
-create_mono_sources_for_writing (const vector<string>& new_paths, Session& sess,
-                                uint samplerate, vector<boost::shared_ptr<Source> >& newfiles,
+create_mono_sources_for_writing (const string& origin,
+                                 const vector<string>& new_paths, 
+                                 Session& sess, uint samplerate, 
+                                 vector<boost::shared_ptr<Source> >& newfiles,
                                 framepos_t timeline_position)
 {
-       for (vector<string>::const_iterator i = new_paths.begin(); i != new_paths.end(); ++i)
-       {
+       for (vector<string>::const_iterator i = new_paths.begin(); i != new_paths.end(); ++i) {
+
                boost::shared_ptr<Source> source;
 
-               try
-               {
+               try {
                        const DataType type = SMFSource::safe_midi_file_extension (*i) ? DataType::MIDI : DataType::AUDIO;
 
                        source = SourceFactory::createWritable (type, sess,
-                                       i->c_str(),
-                                       false, // destructive
-                                       samplerate);
+                                                                i->c_str(),
+                                                                origin,
+                                                                false, // destructive
+                                                                samplerate);
                }
-               catch (const failed_constructor& err)
-               {
+
+               catch (const failed_constructor& err) {
                        error << string_compose (_("Unable to create file %1 during import"), *i) << endmsg;
                        return false;
                }
@@ -488,7 +490,7 @@ Session::import_audiofiles (ImportStatus& status)
                        fatal << "THIS IS NOT IMPLEMENTED YET, IT SHOULD NEVER GET CALLED!!! DYING!" << endmsg;
                        status.cancel = !map_existing_mono_sources (new_paths, *this, frame_rate(), newfiles, this);
                } else {
-                        status.cancel = !create_mono_sources_for_writing (new_paths, *this, frame_rate(), newfiles, natural_position);
+                        status.cancel = !create_mono_sources_for_writing (*p, new_paths, *this, frame_rate(), newfiles, natural_position);
                }
 
                // copy on cancel/failure so that any files that were created will be removed below
index ebb2d17696608f92c2afc803c6c567e125c745d4..5a703f6772e9a564908a36a15204388d4b71ed7c 100644 (file)
@@ -314,7 +314,7 @@ MidiSource::clone (Evoral::MusicalTime begin, Evoral::MusicalTime end)
         
         boost::shared_ptr<MidiSource> newsrc = boost::dynamic_pointer_cast<MidiSource>(
                 SourceFactory::createWritable(DataType::MIDI, _session,
-                                              newpath, false, _session.frame_rate()));
+                                              newpath, string(), false, _session.frame_rate()));
 
         newsrc->set_timeline_position(_timeline_position);
        newsrc->copy_interpolation_from (this);
index 55b5a4baeef6f62bb450100cc27f9be7f46fedb9..c5aef9531c334f16d1ca1bd3203015d9837d8372 100644 (file)
@@ -2981,7 +2981,7 @@ Session::create_audio_source_for_session (size_t n_chans, string const & n, uint
        const string path    = new_source_path_from_name(DataType::AUDIO, name, as_stub);
 
        return boost::dynamic_pointer_cast<AudioFileSource> (
-               SourceFactory::createWritable (DataType::AUDIO, *this, path, destructive, frame_rate()));
+               SourceFactory::createWritable (DataType::AUDIO, *this, path, string(), destructive, frame_rate()));
 }
 
 /** Return a unique name based on \a base for a new internal MIDI source */
@@ -3058,7 +3058,7 @@ Session::create_midi_source_for_session (Track* track, string const & n, bool as
 
        return boost::dynamic_pointer_cast<SMFSource> (
                        SourceFactory::createWritable (
-                                       DataType::MIDI, *this, path, false, frame_rate()));
+                                DataType::MIDI, *this, path, string(), false, frame_rate()));
 }
 
 
@@ -3617,7 +3617,7 @@ Session::write_one_track (AudioTrack& track, framepos_t start, framepos_t end,
 
                try {
                        fsource = boost::dynamic_pointer_cast<AudioFileSource> (
-                               SourceFactory::createWritable (DataType::AUDIO, *this, buf, false, frame_rate()));
+                               SourceFactory::createWritable (DataType::AUDIO, *this, buf, string(), false, frame_rate()));
                }
 
                catch (failed_constructor& err) {
index 1b9be5ddaa26cdee440db618d3354dda4767de94..7a664b30d6ed3c86bc5da2711a62821e28b4ba9e 100644 (file)
@@ -53,13 +53,15 @@ using namespace PBD;
 SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags)
        : Source(s, DataType::MIDI, path, flags)
        , MidiSource(s, path)
-       , FileSource(s, DataType::MIDI, path, flags)
+       , FileSource(s, DataType::MIDI, path, string(), flags)
        , Evoral::SMF()
        , _last_ev_time_beats(0.0)
        , _last_ev_time_frames(0)
        , _smf_last_read_end (0)
        , _smf_last_read_time (0)
 {
+        /* note that origin remains empty */
+
        if (init(_path, false)) {
                throw failed_constructor ();
        }
@@ -365,7 +367,9 @@ SMFSource::append_event_unlocked_frames (const Evoral::Event<nframes_t>& ev, fra
 XMLNode&
 SMFSource::get_state ()
 {
-       return MidiSource::get_state();
+        XMLNode& node = MidiSource::get_state();
+        node.add_property (X_("origin"), _origin);
+        return node;
 }
 
 int
index 9508391d07b0ee5febe691456c347875772e1cf8..0afe50a3111f977836597910de66793c3c898598 100644 (file)
@@ -69,6 +69,7 @@ SndFileSource::SndFileSource (Session& s, const XMLNode& node)
 /** Files created this way are never writable or removable */
 SndFileSource::SndFileSource (Session& s, const string& path, int chn, Flag flags)
        : Source(s, DataType::AUDIO, path, flags)
+          /* note that the origin of an external file is itself */
        , AudioFileSource (s, path, Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
 {
        _channel = chn;
@@ -81,10 +82,10 @@ SndFileSource::SndFileSource (Session& s, const string& path, int chn, Flag flag
 }
 
 /** This constructor is used to construct new files, not open existing ones. */
-SndFileSource::SndFileSource (Session& s, const string& path, 
-               SampleFormat sfmt, HeaderFormat hf, nframes_t rate, Flag flags)
+SndFileSource::SndFileSource (Session& s, const string& path, const string& origin,
+                              SampleFormat sfmt, HeaderFormat hf, nframes_t rate, Flag flags)
        : Source(s, DataType::AUDIO, path, flags)
-       , AudioFileSource (s, path, flags, sfmt, hf)
+       , AudioFileSource (s, path, origin, flags, sfmt, hf)
 {
        int fmt = 0;
 
index ca1dc3b35466859e312280138fafd56c567f934c..c9f7386c008e073b66565a7d743bb3c93fd5dac6 100644 (file)
@@ -256,13 +256,13 @@ SourceFactory::createReadable (DataType type, Session& s, const string& path,
 }
 
 boost::shared_ptr<Source>
-SourceFactory::createWritable (DataType type, Session& s, const std::string& path, 
+SourceFactory::createWritable (DataType type, Session& s, const std::string& path, const std::string& origin,
                               bool destructive, nframes_t rate, bool announce, bool defer_peaks)
 {
        /* this might throw failed_constructor(), which is OK */
 
        if (type == DataType::AUDIO) {
-               Source* src = new SndFileSource (s, path, 
+               Source* src = new SndFileSource (s, path, origin,
                                s.config.get_native_file_data_format(),
                                s.config.get_native_file_header_format(),
                                rate,