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
This commit is contained in:
parent
7ccc471ce1
commit
6dea7ebfb0
@ -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 ();
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user