diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2015-04-06 21:18:52 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2015-04-06 21:18:52 -0400 |
commit | 6dea7ebfb0bb66fa58b353467724a90805fb7a47 (patch) | |
tree | f1484dd9bf6a6f042de379a55ddb681a910ac96e /libs | |
parent | 7ccc471ce14829493eb3af2cbec4a83336c474a3 (diff) |
changes related to resetting source paths during save-as.
This does NOT work with MIDI files at present, because of SNAFU in SMF class, where end_write()
opens the file on its own, without _file_path being set. Needs some careful work, because basically
the SMF<=>SMFSource relationship is not tenable
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/session.h | 2 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 71 |
2 files changed, 60 insertions, 13 deletions
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index d769db25e6..4b50e7c21f 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1443,8 +1443,10 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop typedef std::map<PBD::ID,boost::shared_ptr<Source> > SourceMap; private: + void reset_write_sources (bool mark_write_complete, bool force = false); SourceMap sources; + private: int load_sources (const XMLNode& node); XMLNode& get_sources_as_xml (); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index df2b919c16..fd4fe0a89f 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -1844,6 +1844,22 @@ Session::get_sources_as_xml () return *node; } +void +Session::reset_write_sources (bool mark_write_complete, bool force) +{ + boost::shared_ptr<RouteList> rl = routes.reader(); + for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) { + boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i); + if (tr) { + + // block state saving + _state_of_the_state = StateOfTheState (_state_of_the_state|InCleanup); + tr->reset_write_sources(mark_write_complete, force); + _state_of_the_state = StateOfTheState (_state_of_the_state & ~InCleanup); + } + } +} + int Session::load_sources (const XMLNode& node) { @@ -3867,7 +3883,6 @@ Session::bring_all_sources_into_session (boost::function<void(uint32_t,uint32_t, } if (fs->within_session()) { - cerr << "skip " << fs->name() << endl; continue; } @@ -3902,9 +3917,14 @@ Session::bring_all_sources_into_session (boost::function<void(uint32_t,uint32_t, break; case DataType::MIDI: + /* XXX not implemented yet */ break; } + if (new_path.empty()) { + continue; + } + cerr << "Move " << old_path << " => " << new_path << endl; if (!copy_file (old_path, new_path)) { @@ -3942,6 +3962,22 @@ Session::save_as_bring_callback (uint32_t,uint32_t,string) */ } +static string +make_new_media_path (string old_path, string new_session_folder, string new_session_path) +{ + /* typedir is the "midifiles" or "audiofiles" etc. part of the path. */ + + string typedir = Glib::path_get_basename (Glib::path_get_dirname (old_path)); + vector<string> v; + v.push_back (new_session_folder); /* full path */ + v.push_back (interchange_dir_name); + v.push_back (new_session_path); /* just one directory/folder */ + v.push_back (typedir); + v.push_back (Glib::path_get_basename (old_path)); + + return Glib::build_filename (v); +} + int Session::save_as (SaveAs& saveas) { @@ -4044,18 +4080,8 @@ Session::save_as (SaveAs& saveas) if (saveas.copy_media) { - /* typedir is the "midifiles" or "audiofiles" etc. part of the path. - */ - string typedir = Glib::path_get_basename (Glib::path_get_dirname (*i)); - vector<string> v; - v.push_back (to_dir); - v.push_back (interchange_dir_name); - v.push_back (new_folder); - v.push_back (typedir); - v.push_back (Glib::path_get_basename (*i)); - - std::string to = Glib::build_filename (v); - + string to = make_new_media_path (*i, to_dir, new_folder); + if (!copy_file (from, to)) { throw Glib::FileError (Glib::FileError::IO_ERROR, "copy failed"); } @@ -4083,6 +4109,10 @@ Session::save_as (SaveAs& saveas) if (do_copy) { string to = Glib::build_filename (to_dir, (*i).substr (prefix_len)); + if (g_mkdir_with_parents (Glib::path_get_dirname (to).c_str(), 0755)) { + throw Glib::FileError (Glib::FileError::IO_ERROR, "cannot create required directory"); + } + if (!copy_file (from, to)) { throw Glib::FileError (Glib::FileError::IO_ERROR, "copy failed"); } @@ -4114,6 +4144,7 @@ Session::save_as (SaveAs& saveas) throw Glib::FileError (Glib::FileError::FAILED, "copy cancelled"); } } + } _path = to_dir; @@ -4182,6 +4213,20 @@ Session::save_as (SaveAs& saveas) /* ensure that all existing tracks reset their current capture source paths */ reset_write_sources (true, true); + + /* the copying above was based on actually discovering files, not just iterating over the sources list. + But if we're going to switch to the new (copied) session, we need to change the paths in the sources also. + */ + + for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) { + boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (i->second); + if (!fs) { + continue; + } + + string newpath = make_new_media_path (fs->path(), to_dir, new_folder); + fs->set_path (newpath); + } } } catch (Glib::FileError& e) { |