+
+boost::shared_ptr<Controllable>
+Session::solo_cut_control() const
+{
+ /* the solo cut control is a bit of an anomaly, at least as of Febrary 2011. There are no other
+ controls in Ardour that currently get presented to the user in the GUI that require
+ access as a Controllable and are also NOT owned by some SessionObject (e.g. Route, or MonitorProcessor).
+
+ its actually an RCConfiguration parameter, so we use a ProxyControllable to wrap
+ it up as a Controllable. Changes to the Controllable will just map back to the RCConfiguration
+ parameter.
+ */
+
+ return _solo_cut_control;
+}
+
+int
+Session::rename (const std::string& new_name)
+{
+ string legal_name = legalize_for_path (new_name);
+ string newpath;
+ string oldstr;
+ string newstr;
+ bool first = true;
+
+ string const old_sources_root = _session_dir->sources_root().to_string ();
+
+#define RENAME ::rename
+
+ /* Rename:
+
+ * session directory
+ * interchange subdirectory
+ * session file
+ * session history
+
+ * Backup files are left unchanged and not renamed.
+ */
+
+ /* pass one: not 100% safe check that the new directory names don't
+ * already exist ...
+ */
+
+ for (vector<space_and_path>::const_iterator i = session_dirs.begin(); i != session_dirs.end(); ++i) {
+ vector<string> v;
+
+ oldstr = (*i).path;
+
+ /* this is a stupid hack because Glib::path_get_dirname() is
+ * lexical-only, and so passing it /a/b/c/ gives a different
+ * result than passing it /a/b/c ...
+ */
+
+ if (oldstr[oldstr.length()-1] == G_DIR_SEPARATOR) {
+ oldstr = oldstr.substr (0, oldstr.length() - 1);
+ }
+
+ string base = Glib::path_get_dirname (oldstr);
+ string p = Glib::path_get_basename (oldstr);
+
+ newstr = Glib::build_filename (base, legal_name);
+
+ if (Glib::file_test (newstr, Glib::FILE_TEST_EXISTS)) {
+ return -1;
+ }
+ }
+
+ /* Session dirs */
+
+ for (vector<space_and_path>::const_iterator i = session_dirs.begin(); i != session_dirs.end(); ++i) {
+ vector<string> v;
+
+ oldstr = (*i).path;
+
+ /* this is a stupid hack because Glib::path_get_dirname() is
+ * lexical-only, and so passing it /a/b/c/ gives a different
+ * result than passing it /a/b/c ...
+ */
+
+ if (oldstr[oldstr.length()-1] == G_DIR_SEPARATOR) {
+ oldstr = oldstr.substr (0, oldstr.length() - 1);
+ }
+
+ string base = Glib::path_get_dirname (oldstr);
+ string p = Glib::path_get_basename (oldstr);
+
+ newstr = Glib::build_filename (base, legal_name);
+
+ cerr << "Rename " << oldstr << " => " << newstr << endl;
+
+ if (RENAME (oldstr.c_str(), newstr.c_str()) != 0) {
+ return 1;
+ }
+
+ if (first) {
+ (*_session_dir) = newstr;
+ newpath = newstr;
+ first = 1;
+ }
+
+ /* directory below interchange */
+
+ v.push_back (newstr);
+ v.push_back (interchange_dir_name);
+ v.push_back (p);
+
+ oldstr = Glib::build_filename (v);
+
+ v.clear ();
+ v.push_back (newstr);
+ v.push_back (interchange_dir_name);
+ v.push_back (legal_name);
+
+ newstr = Glib::build_filename (v);
+
+ cerr << "Rename " << oldstr << " => " << newstr << endl;
+
+ if (RENAME (oldstr.c_str(), newstr.c_str()) != 0) {
+ return 1;
+ }
+ }
+
+ /* state file */
+
+ oldstr = Glib::build_filename (newpath, _current_snapshot_name) + statefile_suffix;
+ newstr= Glib::build_filename (newpath, legal_name) + statefile_suffix;
+
+ cerr << "Rename " << oldstr << " => " << newstr << endl;
+
+ if (RENAME (oldstr.c_str(), newstr.c_str()) != 0) {
+ return 1;
+ }
+
+ /* history file */
+
+
+ oldstr = Glib::build_filename (newpath, _current_snapshot_name) + history_suffix;
+
+ if (Glib::file_test (oldstr, Glib::FILE_TEST_EXISTS)) {
+ newstr = Glib::build_filename (newpath, legal_name) + history_suffix;
+
+ cerr << "Rename " << oldstr << " => " << newstr << endl;
+
+ if (RENAME (oldstr.c_str(), newstr.c_str()) != 0) {
+ return 1;
+ }
+ }
+
+ /* 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);
+
+ _path = newpath;
+ _current_snapshot_name = new_name;
+ _name = new_name;
+
+ set_dirty ();
+
+ /* save state again to get everything just right */
+
+ save_state (_current_snapshot_name);
+
+
+ /* add to recent sessions */
+
+ store_recent_sessions (new_name, _path);
+
+ return 0;
+
+#undef RENAME
+}