From b691d4bf04b46059c09e144e34fc58504926ef06 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 30 Mar 2013 14:02:26 -0400 Subject: [PATCH] fix up some confusion with filesources' _origin and _file_is_new members. if _origin is set, it means that the file is "external" to the session (aka "embedded") and for some purposes this is more significant than _file_is_new. rename SourceFactory::createReadable() to ::createExternal() to more clearly indicate its purpose; remove never-supplied "origin" argument from SourceFactor::createWritable(). Fixes problems caused by 864ce8f0 --- gtk2_ardour/editor_audio_import.cc | 2 +- gtk2_ardour/editor_export_audio.cc | 4 ++-- gtk2_ardour/sfdb_ui.cc | 6 +++--- libs/ardour/ardour/source_factory.h | 6 +++--- libs/ardour/audio_diskstream.cc | 2 +- libs/ardour/audiofilesource.cc | 4 +--- libs/ardour/file_source.cc | 11 ++++++----- libs/ardour/filter.cc | 2 +- libs/ardour/import.cc | 6 ++---- libs/ardour/midi_source.cc | 2 +- libs/ardour/session.cc | 6 +++--- libs/ardour/source_factory.cc | 20 ++++++++++---------- 12 files changed, 34 insertions(+), 37 deletions(-) diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index 3a120c709f..31ccdb7a53 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -612,7 +612,7 @@ Editor::embed_sndfiles (vector paths, bool multifile, if ((s = _session->source_by_path_and_channel (path, n)) == 0) { source = boost::dynamic_pointer_cast ( - SourceFactory::createReadable (DataType::AUDIO, *_session, + SourceFactory::createExternal (DataType::AUDIO, *_session, path, n, (mode == ImportAsTapeTrack ? Source::Destructive diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index 78e7674042..877a39e773 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -274,7 +274,7 @@ Editor::write_region (string path, boost::shared_ptr region) try { fs = boost::dynamic_pointer_cast ( SourceFactory::createWritable (DataType::AUDIO, *_session, - path, string(), true, + path, true, false, _session->frame_rate())); } @@ -413,7 +413,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list try { fs = boost::dynamic_pointer_cast ( SourceFactory::createWritable (DataType::AUDIO, *_session, - path, string(), true, + path, true, false, _session->frame_rate())); } diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index 20c2875d9c..3383cf3ff9 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -340,9 +340,9 @@ SoundFileBox::audition () for (int n = 0; n < sf_info.channels; ++n) { try { afs = boost::dynamic_pointer_cast ( - SourceFactory::createReadable (DataType::AUDIO, *_session, - path, n, Source::Flag (0), false)); - + SourceFactory::createExternal (DataType::AUDIO, *_session, + path, n, Source::Flag (0), false)); + srclist.push_back(afs); } catch (failed_constructor& err) { diff --git a/libs/ardour/ardour/source_factory.h b/libs/ardour/ardour/source_factory.h index 387a40aff3..c94f783b44 100644 --- a/libs/ardour/ardour/source_factory.h +++ b/libs/ardour/ardour/source_factory.h @@ -46,14 +46,14 @@ class SourceFactory { static boost::shared_ptr createSilent (Session&, const XMLNode& node, framecnt_t nframes, float sample_rate); - static boost::shared_ptr createReadable + static boost::shared_ptr createExternal (DataType type, Session&, - const std::string& path, + const std::string& path, 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& origin, + const std::string& path, bool destructive, framecnt_t rate, bool announce = true, bool async = false); diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index 24687c766f..c302e06681 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -2168,7 +2168,7 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node) fs = boost::dynamic_pointer_cast ( SourceFactory::createWritable ( DataType::AUDIO, _session, - prop->value(), string(), false, _session.frame_rate())); + prop->value(), false, _session.frame_rate())); } catch (failed_constructor& err) { diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc index 2486d45ca1..e7d69d2258 100644 --- a/libs/ardour/audiofilesource.cc +++ b/libs/ardour/audiofilesource.cc @@ -95,8 +95,6 @@ AudioFileSource::AudioFileSource (Session& s, const string& path, Source::Flag f /* 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 (); } @@ -322,7 +320,7 @@ int AudioFileSource::setup_peakfile () { if (!(_flags & NoPeakFile)) { - return initialize_peakfile (_file_is_new, _path); + return initialize_peakfile (_origin.empty(), _path); } else { return 0; } diff --git a/libs/ardour/file_source.cc b/libs/ardour/file_source.cc index 8c207feea7..e3a442b0de 100644 --- a/libs/ardour/file_source.cc +++ b/libs/ardour/file_source.cc @@ -55,8 +55,8 @@ PBD::Signal3 > FileSource:: 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) + , _path (path) + , _file_is_new (!origin.empty()) // origin empty => new file VS. origin !empty => new file , _channel (0) , _origin (origin) , _open (false) @@ -133,11 +133,12 @@ FileSource::init (const string& pathstr, bool must_exist) } set_within_session_from_path (_path); - _name = Glib::path_get_basename (_path); - if (_file_is_new && must_exist) { - return -1; + if (must_exist) { + if (!Glib::file_test (_path, Glib::FILE_TEST_EXISTS)) { + throw MissingSource (pathstr, _type); + } } return 0; diff --git a/libs/ardour/filter.cc b/libs/ardour/filter.cc index 67aa840cad..b085ec946b 100644 --- a/libs/ardour/filter.cc +++ b/libs/ardour/filter.cc @@ -71,7 +71,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, string(), false, session.frame_rate()))); + path, false, session.frame_rate()))); } catch (failed_constructor& err) { diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc index 07c7958ad7..047b46f553 100644 --- a/libs/ardour/import.cc +++ b/libs/ardour/import.cc @@ -214,8 +214,7 @@ map_existing_mono_sources (const vector& new_paths, Session& /*sess*/, } static bool -create_mono_sources_for_writing (const string& origin, - const vector& new_paths, +create_mono_sources_for_writing (const vector& new_paths, Session& sess, uint samplerate, vector >& newfiles, framepos_t timeline_position) @@ -229,7 +228,6 @@ create_mono_sources_for_writing (const string& origin, source = SourceFactory::createWritable (type, sess, i->c_str(), - origin, false, // destructive samplerate); } @@ -527,7 +525,7 @@ Session::import_files (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 (*p, new_paths, *this, frame_rate(), newfiles, natural_position); + status.cancel = !create_mono_sources_for_writing (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 30dc23f998..124d3f7c9b 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -355,7 +355,7 @@ MidiSource::clone (const string& path, Evoral::MusicalTime begin, Evoral::Musica boost::shared_ptr newsrc = boost::dynamic_pointer_cast( SourceFactory::createWritable(DataType::MIDI, _session, - newpath, string(), false, _session.frame_rate())); + newpath, 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 cb743cca62..75303251d8 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -3381,7 +3381,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); return boost::dynamic_pointer_cast ( - SourceFactory::createWritable (DataType::AUDIO, *this, path, string(), destructive, frame_rate())); + SourceFactory::createWritable (DataType::AUDIO, *this, path, destructive, frame_rate())); } /** Return a unique name based on \a base for a new internal MIDI source */ @@ -3457,7 +3457,7 @@ Session::create_midi_source_for_session (Track* track, string const & n) return boost::dynamic_pointer_cast ( SourceFactory::createWritable ( - DataType::MIDI, *this, path, string(), false, frame_rate())); + DataType::MIDI, *this, path, false, frame_rate())); } @@ -4009,7 +4009,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, string(), false, frame_rate())); + SourceFactory::createWritable (DataType::AUDIO, *this, buf, false, frame_rate())); } catch (failed_constructor& err) { diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc index da5980599d..5e1a7d40d9 100644 --- a/libs/ardour/source_factory.cc +++ b/libs/ardour/source_factory.cc @@ -218,11 +218,11 @@ SourceFactory::create (Session& s, const XMLNode& node, bool defer_peaks) } boost::shared_ptr -SourceFactory::createReadable (DataType type, Session& s, const string& path, +SourceFactory::createExternal (DataType type, Session& s, const string& path, int chn, Source::Flag flags, bool announce, bool defer_peaks) { if (type == DataType::AUDIO) { - + if (!(flags & Destructive)) { try { @@ -291,19 +291,19 @@ SourceFactory::createReadable (DataType type, Session& s, const string& path, } boost::shared_ptr -SourceFactory::createWritable (DataType type, Session& s, const std::string& path, const std::string& origin, +SourceFactory::createWritable (DataType type, Session& s, const std::string& path, bool destructive, framecnt_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, origin, - s.config.get_native_file_data_format(), - s.config.get_native_file_header_format(), - rate, - (destructive - ? Source::Flag (SndFileSource::default_writable_flags | Source::Destructive) - : SndFileSource::default_writable_flags)); + Source* src = new SndFileSource (s, path, string(), + s.config.get_native_file_data_format(), + s.config.get_native_file_header_format(), + rate, + (destructive + ? Source::Flag (SndFileSource::default_writable_flags | Source::Destructive) + : SndFileSource::default_writable_flags)); #ifdef BOOST_SP_ENABLE_DEBUG_HOOKS // boost_debug_shared_ptr_mark_interesting (src, "Source"); #endif -- 2.30.2