summaryrefslogtreecommitdiff
path: root/libs/ardour/session_state.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2006-09-07 15:07:14 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2006-09-07 15:07:14 +0000
commitf2c8ae66c09d2caffa44743eef0a0ab873024d9a (patch)
tree8118a863600071cc545b4a127e7bb13d3e2c75fe /libs/ardour/session_state.cc
parentbabf75d871ee253fbe32c50737aa110a4fffa36f (diff)
remove all duplicated _id members from children of PBD::Stateful.
Sources now know about Session. rearrange session directory heirarchy. remove tape_dir stuff. NSD allows absolute/relative paths to be typed straight into the text entry. Session history reloaded after all 3rd party registrations done. Editor restores its ID; other objects still need this. use g_mkdir_with_parents() instead of mkdir() one example of using g_file_test() instead of access. git-svn-id: svn://localhost/ardour2/trunk@908 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/session_state.cc')
-rw-r--r--libs/ardour/session_state.cc173
1 files changed, 66 insertions, 107 deletions
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index 9f1c6baf4a..18c5721f7a 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -364,7 +364,6 @@ Session::second_stage_init (bool new_session)
_end_location_is_free = false;
}
- restore_history(_current_snapshot_name);
return 0;
}
@@ -429,16 +428,7 @@ Session::setup_raid_path (string path)
if (fspath[fspath.length()-1] != '/') {
fspath += '/';
}
- fspath += sound_dir_name;
- fspath += ':';
-
- /* tape dir */
-
- fspath += sp.path;
- if (fspath[fspath.length()-1] != '/') {
- fspath += '/';
- }
- fspath += tape_dir_name;
+ fspath += sound_dir (false);
AudioFileSource::set_search_path (fspath);
@@ -459,16 +449,7 @@ Session::setup_raid_path (string path)
if (fspath[fspath.length()-1] != '/') {
fspath += '/';
}
- fspath += sound_dir_name;
- fspath += ':';
-
- /* add tape dir to file search path */
-
- fspath += sp.path;
- if (fspath[fspath.length()-1] != '/') {
- fspath += '/';
- }
- fspath += tape_dir_name;
+ fspath += sound_dir (false);
fspath += ':';
remaining = remaining.substr (colon+1);
@@ -484,15 +465,9 @@ Session::setup_raid_path (string path)
if (fspath[fspath.length()-1] != '/') {
fspath += '/';
}
- fspath += sound_dir_name;
+ fspath += sound_dir (false);
fspath += ':';
- fspath += sp.path;
- if (fspath[fspath.length()-1] != '/') {
- fspath += '/';
- }
- fspath += tape_dir_name;
-
session_dirs.push_back (sp);
}
@@ -509,61 +484,40 @@ int
Session::create (bool& new_session, string* mix_template, jack_nframes_t initial_length)
{
string dir;
+
+ new_session = !g_file_test (_path.c_str(), GFileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR));
- if (mkdir (_path.c_str(), 0755) < 0) {
- if (errno == EEXIST) {
- new_session = false;
- } else {
- error << string_compose(_("Session: cannot create session dir \"%1\" (%2)"), _path, strerror (errno)) << endmsg;
- return -1;
- }
- } else {
- new_session = true;
+ if (g_mkdir_with_parents (_path.c_str(), 0755) < 0) {
+ error << string_compose(_("Session: cannot create session dir \"%1\" (%2)"), _path, strerror (errno)) << endmsg;
+ return -1;
}
dir = peak_dir ();
- if (mkdir (dir.c_str(), 0755) < 0) {
- if (errno != EEXIST) {
- error << string_compose(_("Session: cannot create session peakfile dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
- return -1;
- }
+ if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
+ error << string_compose(_("Session: cannot create session peakfile dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
+ return -1;
}
dir = sound_dir ();
- if (mkdir (dir.c_str(), 0755) < 0) {
- if (errno != EEXIST) {
- error << string_compose(_("Session: cannot create session sounds dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
- return -1;
- }
- }
-
- dir = tape_dir ();
-
- if (mkdir (dir.c_str(), 0755) < 0) {
- if (errno != EEXIST) {
- error << string_compose(_("Session: cannot create session tape dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
- return -1;
- }
+ if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
+ error << string_compose(_("Session: cannot create session sounds dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
+ return -1;
}
dir = dead_sound_dir ();
- if (mkdir (dir.c_str(), 0755) < 0) {
- if (errno != EEXIST) {
- error << string_compose(_("Session: cannot create session dead sounds dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
- return -1;
- }
+ if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
+ error << string_compose(_("Session: cannot create session dead sounds dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
+ return -1;
}
dir = automation_dir ();
- if (mkdir (dir.c_str(), 0755) < 0) {
- if (errno != EEXIST) {
- error << string_compose(_("Session: cannot create session automation dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
- return -1;
- }
+ if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
+ error << string_compose(_("Session: cannot create session automation dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
+ return -1;
}
@@ -709,6 +663,8 @@ Session::save_state (string snapshot_name, bool pending)
}
+ cerr << "actually writing state\n";
+
if (!tree.write (xml_path)) {
error << string_compose (_("state could not be saved to %1"), xml_path) << endmsg;
@@ -1934,7 +1890,7 @@ Session::XMLSourceFactory (const XMLNode& node)
}
try {
- return SourceFactory::create (node);
+ return SourceFactory::create (*this, node);
}
catch (failed_constructor& err) {
@@ -1959,7 +1915,7 @@ Session::save_template (string template_name)
if ((dp = opendir (dir.c_str()))) {
closedir (dp);
} else {
- if (mkdir (dir.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)<0) {
+ if (g_mkdir_with_parents (dir.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
error << string_compose(_("Could not create mix templates directory \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
return -1;
}
@@ -2039,11 +1995,9 @@ Session::ensure_sound_dir (string path, string& result)
/* Ensure that the parent directory exists */
- if (mkdir (path.c_str(), 0775)) {
- if (errno != EEXIST) {
- error << string_compose(_("cannot create session directory \"%1\"; ignored"), path) << endmsg;
- return -1;
- }
+ if (g_mkdir_with_parents (path.c_str(), 0775)) {
+ error << string_compose(_("cannot create session directory \"%1\"; ignored"), path) << endmsg;
+ return -1;
}
/* Ensure that the sounds directory exists */
@@ -2052,33 +2006,27 @@ Session::ensure_sound_dir (string path, string& result)
result += '/';
result += sound_dir_name;
- if (mkdir (result.c_str(), 0775)) {
- if (errno != EEXIST) {
- error << string_compose(_("cannot create sounds directory \"%1\"; ignored"), result) << endmsg;
- return -1;
- }
+ if (g_mkdir_with_parents (result.c_str(), 0775)) {
+ error << string_compose(_("cannot create sounds directory \"%1\"; ignored"), result) << endmsg;
+ return -1;
}
dead = path;
dead += '/';
dead += dead_sound_dir_name;
- if (mkdir (dead.c_str(), 0775)) {
- if (errno != EEXIST) {
- error << string_compose(_("cannot create dead sounds directory \"%1\"; ignored"), dead) << endmsg;
- return -1;
- }
+ if (g_mkdir_with_parents (dead.c_str(), 0775)) {
+ error << string_compose(_("cannot create dead sounds directory \"%1\"; ignored"), dead) << endmsg;
+ return -1;
}
peak = path;
peak += '/';
peak += peak_dir_name;
- if (mkdir (peak.c_str(), 0775)) {
- if (errno != EEXIST) {
- error << string_compose(_("cannot create peak file directory \"%1\"; ignored"), peak) << endmsg;
- return -1;
- }
+ if (g_mkdir_with_parents (peak.c_str(), 0775)) {
+ error << string_compose(_("cannot create peak file directory \"%1\"; ignored"), peak) << endmsg;
+ return -1;
}
/* callers expect this to be terminated ... */
@@ -2093,12 +2041,6 @@ Session::discover_best_sound_dir (bool destructive)
vector<space_and_path>::iterator i;
string result;
- /* destructive files all go into the same place */
-
- if (destructive) {
- return tape_dir();
- }
-
/* handle common case without system calls */
if (session_dirs.size() == 1) {
@@ -2304,20 +2246,37 @@ Session::dead_sound_dir () const
}
string
-Session::sound_dir () const
+Session::sound_dir (bool with_path) const
{
- string res = _path;
+ /* support old session structure */
+
+ struct stat statbuf;
+ string old;
+
+ if (with_path) {
+ old = _path;
+ }
+
+ old += sound_dir_name;
+ old += '/';
+
+ if (stat (old.c_str(), &statbuf) == 0) {
+ return old;
+ }
+
+ string res;
+
+ if (with_path) {
+ res = _path;
+ }
+
+ res += interchange_dir_name;
+ res += '/';
+ res += legalize_for_path (_name);
+ res += '/';
res += sound_dir_name;
res += '/';
- return res;
-}
-string
-Session::tape_dir () const
-{
- string res = _path;
- res += tape_dir_name;
- res += '/';
return res;
}
@@ -3314,8 +3273,7 @@ Session::save_history (string snapshot_name)
XMLTree tree;
string xml_path;
string bak_path;
-
-
+
tree.set_root (&history.get_state());
if (snapshot_name.empty()) {
@@ -3323,7 +3281,6 @@ Session::save_history (string snapshot_name)
}
xml_path = _path + snapshot_name + ".history";
- cerr << "Saving history to " << xml_path << endmsg;
bak_path = xml_path + ".bak";
@@ -3334,6 +3291,8 @@ Session::save_history (string snapshot_name)
return -1;
}
+ cerr << "actually writing history\n";
+
if (!tree.write (xml_path))
{
error << string_compose (_("history could not be saved to %1"), xml_path) << endmsg;