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
This commit is contained in:
Paul Davis 2010-11-09 18:19:53 +00:00
parent cbaba77588
commit 66a9112d48
15 changed files with 65 additions and 43 deletions

View file

@ -211,8 +211,8 @@ Editor::write_region (string path, boost::shared_ptr<AudioRegion> region)
try { try {
fs = boost::dynamic_pointer_cast<AudioFileSource> ( fs = boost::dynamic_pointer_cast<AudioFileSource> (
SourceFactory::createWritable (DataType::AUDIO, *_session, SourceFactory::createWritable (DataType::AUDIO, *_session,
path, true, path, string(), true,
false, _session->frame_rate())); false, _session->frame_rate()));
} }
catch (failed_constructor& err) { catch (failed_constructor& err) {
@ -350,8 +350,8 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list
try { try {
fs = boost::dynamic_pointer_cast<AudioFileSource> ( fs = boost::dynamic_pointer_cast<AudioFileSource> (
SourceFactory::createWritable (DataType::AUDIO, *_session, SourceFactory::createWritable (DataType::AUDIO, *_session,
path, true, path, string(), true,
false, _session->frame_rate())); false, _session->frame_rate()));
} }
catch (failed_constructor& err) { catch (failed_constructor& err) {

View file

@ -91,7 +91,7 @@ protected:
AudioFileSource (Session&, const std::string& path, Source::Flag flags); AudioFileSource (Session&, const std::string& path, Source::Flag flags);
/** Constructor to be called for new in-session files */ /** 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); SampleFormat samp_format, HeaderFormat hdr_format);
/** Constructor to be called for existing in-session files */ /** Constructor to be called for existing in-session files */

View file

@ -75,12 +75,15 @@ public:
void inc_use_count (); void inc_use_count ();
bool removable () const; bool removable () const;
const std::string& origin() const { return _origin; }
static PBD::Signal3<int,std::string,std::string,std::vector<std::string> > AmbiguousFileName; static PBD::Signal3<int,std::string,std::string,std::vector<std::string> > AmbiguousFileName;
protected: protected:
FileSource (Session& session, DataType type, FileSource (Session& session, DataType type,
const std::string& path, const std::string& path,
Source::Flag flags = Source::Flag(0)); const std::string& origin,
Source::Flag flags = Source::Flag(0));
FileSource (Session& session, const XMLNode& node, bool must_exist); FileSource (Session& session, const XMLNode& node, bool must_exist);
@ -92,9 +95,10 @@ protected:
std::string _path; std::string _path;
std::string _take_id; std::string _take_id;
bool _file_is_new; bool _file_is_new;
uint16_t _channel; uint16_t _channel;
bool _within_session; bool _within_session;
std::string _origin;
}; };
} // namespace ARDOUR } // namespace ARDOUR

View file

@ -31,10 +31,10 @@ namespace ARDOUR {
class SndFileSource : public AudioFileSource { class SndFileSource : public AudioFileSource {
public: public:
/** Constructor to be called for existing external-to-session files */ /** 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 */ /* 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, SampleFormat samp_format, HeaderFormat hdr_format, nframes_t rate,
Flag flags = SndFileSource::default_writable_flags); Flag flags = SndFileSource::default_writable_flags);

View file

@ -48,7 +48,7 @@ class SourceFactory {
int chn, Source::Flag flags, bool announce = true, bool async = false); int chn, Source::Flag flags, bool announce = true, bool async = false);
static boost::shared_ptr<Source> createWritable (DataType type, Session&, 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); bool destructive, nframes_t rate, bool announce = true, bool async = false);
static Glib::Cond* PeaksToBuild; static Glib::Cond* PeaksToBuild;

View file

@ -2176,7 +2176,7 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node)
try { try {
fs = boost::dynamic_pointer_cast<AudioFileSource> ( fs = boost::dynamic_pointer_cast<AudioFileSource> (
SourceFactory::createWritable (DataType::AUDIO, _session, SourceFactory::createWritable (DataType::AUDIO, _session,
prop->value(), false, _session.frame_rate())); prop->value(), string(), false, _session.frame_rate()));
} }
catch (failed_constructor& err) { catch (failed_constructor& err) {

View file

@ -91,12 +91,15 @@ struct SizedSampleBuffer {
Glib::StaticPrivate<SizedSampleBuffer> thread_interleave_buffer = GLIBMM_STATIC_PRIVATE_INIT; 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) AudioFileSource::AudioFileSource (Session& s, const string& path, Source::Flag flags)
: Source (s, DataType::AUDIO, path, flags) : Source (s, DataType::AUDIO, path, flags)
, AudioSource (s, path) , 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)) { if (init (_path, true)) {
throw failed_constructor (); 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. */ /** 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*/) SampleFormat /*samp_format*/, HeaderFormat /*hdr_format*/)
: Source (s, DataType::AUDIO, path, flags) : Source (s, DataType::AUDIO, path, flags)
, AudioSource (s, path) , 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)) { if (init (_path, false)) {
throw failed_constructor (); throw failed_constructor ();
} }
@ -258,6 +263,7 @@ AudioFileSource::get_state ()
char buf[32]; char buf[32];
snprintf (buf, sizeof (buf), "%u", _channel); snprintf (buf, sizeof (buf), "%u", _channel);
root.add_property (X_("channel"), buf); root.add_property (X_("channel"), buf);
root.add_property (X_("origin"), _origin);
return root; return root;
} }

View file

@ -54,11 +54,12 @@ using namespace Glib;
PBD::Signal3<int,std::string,std::string,std::vector<std::string> > FileSource::AmbiguousFileName; 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) : Source(session, type, path, flag)
, _path(path) , _path(path)
, _file_is_new(true) , _file_is_new(true)
, _channel (0) , _channel (0)
, _origin (origin)
{ {
set_within_session_from_path (path); set_within_session_from_path (path);
} }
@ -128,6 +129,10 @@ FileSource::set_state (const XMLNode& node, int /*version*/)
_channel = 0; _channel = 0;
} }
if ((prop = node.property (X_("origin"))) != 0) {
_origin = prop->value();
}
return 0; return 0;
} }

View file

@ -70,7 +70,7 @@ Filter::make_new_sources (boost::shared_ptr<Region> region, SourceList& nsrcs, s
try { try {
nsrcs.push_back (boost::dynamic_pointer_cast<Source> ( nsrcs.push_back (boost::dynamic_pointer_cast<Source> (
SourceFactory::createWritable (region->data_type(), session, SourceFactory::createWritable (region->data_type(), session,
path, false, session.frame_rate()))); path, string(), false, session.frame_rate())));
} }
catch (failed_constructor& err) { catch (failed_constructor& err) {

View file

@ -202,25 +202,27 @@ map_existing_mono_sources (const vector<string>& new_paths, Session& /*sess*/,
} }
static bool static bool
create_mono_sources_for_writing (const vector<string>& new_paths, Session& sess, create_mono_sources_for_writing (const string& origin,
uint samplerate, vector<boost::shared_ptr<Source> >& newfiles, const vector<string>& new_paths,
Session& sess, uint samplerate,
vector<boost::shared_ptr<Source> >& newfiles,
framepos_t timeline_position) 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; boost::shared_ptr<Source> source;
try try {
{
const DataType type = SMFSource::safe_midi_file_extension (*i) ? DataType::MIDI : DataType::AUDIO; const DataType type = SMFSource::safe_midi_file_extension (*i) ? DataType::MIDI : DataType::AUDIO;
source = SourceFactory::createWritable (type, sess, source = SourceFactory::createWritable (type, sess,
i->c_str(), i->c_str(),
false, // destructive origin,
samplerate); 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; error << string_compose (_("Unable to create file %1 during import"), *i) << endmsg;
return false; return false;
} }
@ -488,7 +490,7 @@ Session::import_audiofiles (ImportStatus& status)
fatal << "THIS IS NOT IMPLEMENTED YET, IT SHOULD NEVER GET CALLED!!! DYING!" << endmsg; 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); status.cancel = !map_existing_mono_sources (new_paths, *this, frame_rate(), newfiles, this);
} else { } 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 // copy on cancel/failure so that any files that were created will be removed below

View file

@ -314,7 +314,7 @@ MidiSource::clone (Evoral::MusicalTime begin, Evoral::MusicalTime end)
boost::shared_ptr<MidiSource> newsrc = boost::dynamic_pointer_cast<MidiSource>( boost::shared_ptr<MidiSource> newsrc = boost::dynamic_pointer_cast<MidiSource>(
SourceFactory::createWritable(DataType::MIDI, _session, SourceFactory::createWritable(DataType::MIDI, _session,
newpath, false, _session.frame_rate())); newpath, string(), false, _session.frame_rate()));
newsrc->set_timeline_position(_timeline_position); newsrc->set_timeline_position(_timeline_position);
newsrc->copy_interpolation_from (this); newsrc->copy_interpolation_from (this);

View 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); const string path = new_source_path_from_name(DataType::AUDIO, name, as_stub);
return boost::dynamic_pointer_cast<AudioFileSource> ( 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 */ /** 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> ( return boost::dynamic_pointer_cast<SMFSource> (
SourceFactory::createWritable ( 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 { try {
fsource = boost::dynamic_pointer_cast<AudioFileSource> ( 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) { catch (failed_constructor& err) {

View file

@ -53,13 +53,15 @@ using namespace PBD;
SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags) SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags)
: Source(s, DataType::MIDI, path, flags) : Source(s, DataType::MIDI, path, flags)
, MidiSource(s, path) , MidiSource(s, path)
, FileSource(s, DataType::MIDI, path, flags) , FileSource(s, DataType::MIDI, path, string(), flags)
, Evoral::SMF() , Evoral::SMF()
, _last_ev_time_beats(0.0) , _last_ev_time_beats(0.0)
, _last_ev_time_frames(0) , _last_ev_time_frames(0)
, _smf_last_read_end (0) , _smf_last_read_end (0)
, _smf_last_read_time (0) , _smf_last_read_time (0)
{ {
/* note that origin remains empty */
if (init(_path, false)) { if (init(_path, false)) {
throw failed_constructor (); throw failed_constructor ();
} }
@ -365,7 +367,9 @@ SMFSource::append_event_unlocked_frames (const Evoral::Event<nframes_t>& ev, fra
XMLNode& XMLNode&
SMFSource::get_state () SMFSource::get_state ()
{ {
return MidiSource::get_state(); XMLNode& node = MidiSource::get_state();
node.add_property (X_("origin"), _origin);
return node;
} }
int int

View file

@ -69,6 +69,7 @@ SndFileSource::SndFileSource (Session& s, const XMLNode& node)
/** Files created this way are never writable or removable */ /** Files created this way are never writable or removable */
SndFileSource::SndFileSource (Session& s, const string& path, int chn, Flag flags) SndFileSource::SndFileSource (Session& s, const string& path, int chn, Flag flags)
: Source(s, DataType::AUDIO, path, 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))) , AudioFileSource (s, path, Flag (flags & ~(Writable|Removable|RemovableIfEmpty|RemoveAtDestroy)))
{ {
_channel = chn; _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. */ /** This constructor is used to construct new files, not open existing ones. */
SndFileSource::SndFileSource (Session& s, const string& path, SndFileSource::SndFileSource (Session& s, const string& path, const string& origin,
SampleFormat sfmt, HeaderFormat hf, nframes_t rate, Flag flags) SampleFormat sfmt, HeaderFormat hf, nframes_t rate, Flag flags)
: Source(s, DataType::AUDIO, path, flags) : Source(s, DataType::AUDIO, path, flags)
, AudioFileSource (s, path, flags, sfmt, hf) , AudioFileSource (s, path, origin, flags, sfmt, hf)
{ {
int fmt = 0; int fmt = 0;

View file

@ -256,13 +256,13 @@ SourceFactory::createReadable (DataType type, Session& s, const string& path,
} }
boost::shared_ptr<Source> 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) bool destructive, nframes_t rate, bool announce, bool defer_peaks)
{ {
/* this might throw failed_constructor(), which is OK */ /* this might throw failed_constructor(), which is OK */
if (type == DataType::AUDIO) { 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_data_format(),
s.config.get_native_file_header_format(), s.config.get_native_file_header_format(),
rate, rate,