Reset source paths on session rename (fixes #4389).
authorCarl Hetherington <carl@carlh.net>
Mon, 24 Oct 2011 19:47:06 +0000 (19:47 +0000)
committerCarl Hetherington <carl@carlh.net>
Mon, 24 Oct 2011 19:47:06 +0000 (19:47 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@10299 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/session_state.cc

index 56a1380f9154aac054decded8304bffc9df411bc..f21d80e717ca3d8f0f520db0a7c2ffecc6224b83 100644 (file)
@@ -28,8 +28,6 @@
 #include <fstream>
 #include <string>
 #include <cerrno>
-
-
 #include <cstdio> /* snprintf(3) ... grrr */
 #include <cmath>
 #include <unistd.h>
@@ -53,6 +51,8 @@
 #include <glibmm.h>
 #include <glibmm/thread.h>
 
+#include <boost/algorithm/string.hpp>
+
 #include "midi++/mmc.h"
 #include "midi++/port.h"
 #include "midi++/manager.h"
@@ -3670,6 +3670,8 @@ Session::rename (const std::string& new_name)
        string newstr;
        bool first = true;
 
+       string const old_sources_root = _session_dir->sources_root().to_string ();
+
 #define RENAME ::rename
 
        /* Rename:
@@ -3791,6 +3793,17 @@ Session::rename (const std::string& new_name)
                }
        }
 
+       /* update file source paths */
+       
+       for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) {
+               boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (i->second);
+               if (fs) {
+                       string p = fs->path ();
+                       boost::replace_all (p, old_sources_root, _session_dir->sources_root().to_string ());
+                       fs->set_path (p);
+               }
+       }
+
        /* remove old name from recent sessions */
 
        remove_recent_sessions (_path);