From 66a9112d48b5726f61eec7ce4cfc4bd15b9420d0 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 9 Nov 2010 18:19:53 +0000 Subject: [PATCH] add "origin" property to FileSource so that we can track multiple imports git-svn-id: svn://localhost/ardour2/branches/3.0@7986 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor_export_audio.cc | 8 ++++---- libs/ardour/ardour/audiofilesource.h | 2 +- libs/ardour/ardour/file_source.h | 14 +++++++++----- libs/ardour/ardour/sndfilesource.h | 4 ++-- libs/ardour/ardour/source_factory.h | 2 +- libs/ardour/audio_diskstream.cc | 2 +- libs/ardour/audiofilesource.cc | 14 ++++++++++---- libs/ardour/file_source.cc | 7 ++++++- libs/ardour/filter.cc | 2 +- libs/ardour/import.cc | 26 ++++++++++++++------------ libs/ardour/midi_source.cc | 2 +- libs/ardour/session.cc | 6 +++--- libs/ardour/smf_source.cc | 8 ++++++-- libs/ardour/sndfilesource.cc | 7 ++++--- libs/ardour/source_factory.cc | 4 ++-- 15 files changed, 65 insertions(+), 43 deletions(-) diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index bab5d4c1e6..342ccb80e0 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -211,8 +211,8 @@ Editor::write_region (string path, boost::shared_ptr region) try { fs = boost::dynamic_pointer_cast ( 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 ( SourceFactory::createWritable (DataType::AUDIO, *_session, - path, true, - false, _session->frame_rate())); + path, string(), true, + false, _session->frame_rate())); } catch (failed_constructor& err) { diff --git a/libs/ardour/ardour/audiofilesource.h b/libs/ardour/ardour/audiofilesource.h index 57b5ced93c..4f01bf4182 100644 --- a/libs/ardour/ardour/audiofilesource.h +++ b/libs/ardour/ardour/audiofilesource.h @@ -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 */ diff --git a/libs/ardour/ardour/file_source.h b/libs/ardour/ardour/file_source.h index 78210916f0..4aadce27e8 100644 --- a/libs/ardour/ardour/file_source.h +++ b/libs/ardour/ardour/file_source.h @@ -75,12 +75,15 @@ public: void inc_use_count (); bool removable () const; + const std::string& origin() const { return _origin; } + static PBD::Signal3 > 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 diff --git a/libs/ardour/ardour/sndfilesource.h b/libs/ardour/ardour/sndfilesource.h index ae2cba449a..ff15608d70 100644 --- a/libs/ardour/ardour/sndfilesource.h +++ b/libs/ardour/ardour/sndfilesource.h @@ -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); diff --git a/libs/ardour/ardour/source_factory.h b/libs/ardour/ardour/source_factory.h index 14d0de5f4d..c59dab9223 100644 --- a/libs/ardour/ardour/source_factory.h +++ b/libs/ardour/ardour/source_factory.h @@ -48,7 +48,7 @@ class SourceFactory { int chn, Source::Flag flags, bool announce = true, bool async = false); static boost::shared_ptr 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; diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index b994c5e3e2..00d89f8271 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -2176,7 +2176,7 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node) try { fs = boost::dynamic_pointer_cast ( SourceFactory::createWritable (DataType::AUDIO, _session, - prop->value(), false, _session.frame_rate())); + prop->value(), string(), false, _session.frame_rate())); } catch (failed_constructor& err) { diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc index 12c2c6ad17..39701f24cc 100644 --- a/libs/ardour/audiofilesource.cc +++ b/libs/ardour/audiofilesource.cc @@ -91,12 +91,15 @@ struct SizedSampleBuffer { Glib::StaticPrivate 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; } diff --git a/libs/ardour/file_source.cc b/libs/ardour/file_source.cc index 7eac1a23ea..264d6482b4 100644 --- a/libs/ardour/file_source.cc +++ b/libs/ardour/file_source.cc @@ -54,11 +54,12 @@ using namespace Glib; PBD::Signal3 > 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; } diff --git a/libs/ardour/filter.cc b/libs/ardour/filter.cc index 2bbeecf37e..c82f6ae4d6 100644 --- a/libs/ardour/filter.cc +++ b/libs/ardour/filter.cc @@ -70,7 +70,7 @@ Filter::make_new_sources (boost::shared_ptr region, SourceList& nsrcs, s try { nsrcs.push_back (boost::dynamic_pointer_cast ( SourceFactory::createWritable (region->data_type(), session, - path, false, session.frame_rate()))); + path, string(), false, session.frame_rate()))); } catch (failed_constructor& err) { diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc index 929f3c5bf4..4fc546ebd5 100644 --- a/libs/ardour/import.cc +++ b/libs/ardour/import.cc @@ -202,25 +202,27 @@ map_existing_mono_sources (const vector& new_paths, Session& /*sess*/, } static bool -create_mono_sources_for_writing (const vector& new_paths, Session& sess, - uint samplerate, vector >& newfiles, +create_mono_sources_for_writing (const string& origin, + const vector& new_paths, + Session& sess, uint samplerate, + vector >& newfiles, framepos_t timeline_position) { - for (vector::const_iterator i = new_paths.begin(); i != new_paths.end(); ++i) - { + for (vector::const_iterator i = new_paths.begin(); i != new_paths.end(); ++i) { + boost::shared_ptr 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 diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index ebb2d17696..5a703f6772 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -314,7 +314,7 @@ MidiSource::clone (Evoral::MusicalTime begin, Evoral::MusicalTime end) boost::shared_ptr newsrc = boost::dynamic_pointer_cast( 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); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 55b5a4baee..c5aef9531c 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -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 ( - 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 ( 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 ( - SourceFactory::createWritable (DataType::AUDIO, *this, buf, false, frame_rate())); + SourceFactory::createWritable (DataType::AUDIO, *this, buf, string(), false, frame_rate())); } catch (failed_constructor& err) { diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 1b9be5ddaa..7a664b30d6 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -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& ev, fra XMLNode& SMFSource::get_state () { - return MidiSource::get_state(); + XMLNode& node = MidiSource::get_state(); + node.add_property (X_("origin"), _origin); + return node; } int diff --git a/libs/ardour/sndfilesource.cc b/libs/ardour/sndfilesource.cc index 9508391d07..0afe50a311 100644 --- a/libs/ardour/sndfilesource.cc +++ b/libs/ardour/sndfilesource.cc @@ -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; diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc index ca1dc3b354..c9f7386c00 100644 --- a/libs/ardour/source_factory.cc +++ b/libs/ardour/source_factory.cc @@ -256,13 +256,13 @@ SourceFactory::createReadable (DataType type, Session& s, const string& path, } boost::shared_ptr -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, -- 2.30.2