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 {
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) {

View 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 */

View 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

View 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);

View 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;

View 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) {

View 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;
}

View 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;
}

View 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) {

View 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

View 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);

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);
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) {

View 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

View 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;

View 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,