Remove Session::create_session_directory as it is no longer used
[ardour.git] / libs / ardour / session_state.cc
index e60774e2b1f8d301769468747b84c3476c762dde..e58f2324e34f4a0eb96467916e2b53f318322f42 100644 (file)
@@ -96,7 +96,8 @@
 #include <ardour/region_factory.h>
 #include <ardour/source_factory.h>
 #include <ardour/playlist_factory.h>
-
+#include <ardour/filename_extensions.h>
+#include <ardour/directory_names.h>
 #include <control_protocol/control_protocol.h>
 
 #include "i18n.h"
@@ -463,102 +464,39 @@ Session::setup_raid_path (string path)
        last_rr_session_dir = session_dirs.begin();
 }
 
-int
-Session::create (bool& new_session, string* mix_template, nframes_t initial_length)
+void
+Session::initialize_start_and_end_locations (nframes_t start, nframes_t end)
 {
-       string dir;
-
-       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 (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;
-       }
-
-       /* if this is is an existing session with an old "sounds" directory, just use it. see Session::sound_dir() for more details */
-
-       if (!Glib::file_test (old_sound_dir(), Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_DIR)) {
-
-               dir = sound_dir ();
-               
-               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 (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 = export_dir ();
-
-       if (g_mkdir_with_parents (dir.c_str(), 0755) < 0) {
-               error << string_compose(_("Session: cannot create session export dir \"%1\" (%2)"), dir, strerror (errno)) << endmsg;
-               return -1;
-       }
-
-
-       /* check new_session so we don't overwrite an existing one */
-
-       if (mix_template) {
-               std::string in_path = *mix_template;
-
-               ifstream in(in_path.c_str());
-
-               if (in){
-                       string out_path = _path;
-                       out_path += _name;
-                       out_path += _statefile_suffix;
-
-                       ofstream out(out_path.c_str());
-
-                       if (out){
-                               out << in.rdbuf();
-
-                               // okay, session is set up.  Treat like normal saved
-                               // session from now on.
-
-                               new_session = false;
-                               return 0;
-
-                       } else {
-                               error << string_compose (_("Could not open %1 for writing mix template"), out_path) 
-                                       << endmsg;
-                               return -1;
-                       }
-
-               } else {
-                       error << string_compose (_("Could not open mix template %1 for reading"), in_path) 
-                               << endmsg;
-                       return -1;
-               }
-
-       }
-
-       /* set initial start + end point */
-
-       start_location->set_end (0);
+       start_location->set_end (start);
        _locations.add (start_location);
 
-       end_location->set_end (initial_length);
+       end_location->set_end (end);
        _locations.add (end_location);
+}
 
+bool
+Session::create_session_file ()
+{
        _state_of_the_state = Clean;
 
        if (save_state (_current_snapshot_name)) {
-               return -1;
+               error << "Could not create new session file" << endmsg;
+               return false;
        }
+       return true;
+}
 
-       return 0;
+bool
+Session::create_session_file_from_template (const string& template_path)
+{
+       string out_path = _path + _name + statefile_suffix;
+
+       if(!copy_file (template_path, out_path)) {
+               error << string_compose (_("Could not use session template %1 to create new session."), template_path) 
+                       << endmsg;
+               return false;
+       }
+       return true;
 }
 
 int
@@ -608,7 +546,7 @@ Session::remove_pending_capture_state ()
 
        xml_path = _path;
        xml_path += _current_snapshot_name;
-       xml_path += _pending_suffix;
+       xml_path += pending_suffix;
 
        unlink (xml_path.c_str());
 }
@@ -624,8 +562,8 @@ Session::rename_state (string old_name, string new_name)
                return;
        }
        
-       const string old_xml_path = _path + old_name + _statefile_suffix;
-       const string new_xml_path = _path + new_name + _statefile_suffix;
+       const string old_xml_path = _path + old_name + statefile_suffix;
+       const string new_xml_path = _path + new_name + statefile_suffix;
 
        if (rename (old_xml_path.c_str(), new_xml_path.c_str()) != 0) {
                error << string_compose(_("could not rename snapshot %1 to %2"), old_name, new_name) << endmsg;
@@ -643,7 +581,7 @@ Session::remove_state (string snapshot_name)
                return;
        }
        
-       const string xml_path = _path + snapshot_name + _statefile_suffix;
+       const string xml_path = _path + snapshot_name + statefile_suffix;
 
        /* make a backup copy of the state file */
        const string bak_path = xml_path + ".bak";
@@ -680,10 +618,10 @@ Session::save_state (string snapshot_name, bool pending)
 
        if (!pending) {
 
-               /* proper save: use _statefile_suffix (.ardour in English) */
+               /* proper save: use statefile_suffix (.ardour in English) */
                xml_path = _path;
                xml_path += snapshot_name;
-               xml_path += _statefile_suffix;
+               xml_path += statefile_suffix;
 
                /* make a backup copy of the old file */
                bak_path = xml_path;
@@ -695,10 +633,10 @@ Session::save_state (string snapshot_name, bool pending)
 
        } else {
 
-               /* pending save: use _pending_suffix (.pending in English) */
+               /* pending save: use pending_suffix (.pending in English) */
                xml_path = _path;
                xml_path += snapshot_name;
-               xml_path += _pending_suffix;
+               xml_path += pending_suffix;
 
        }
 
@@ -708,7 +646,7 @@ Session::save_state (string snapshot_name, bool pending)
        tmp_path += snapshot_name;
        tmp_path += ".tmp";
 
-       cerr << "actually writing state to " << xml_path << endl;
+       // cerr << "actually writing state to " << xml_path << endl;
 
        if (!tree.write (tmp_path)) {
                error << string_compose (_("state could not be saved to %1"), tmp_path) << endmsg;
@@ -768,9 +706,9 @@ Session::load_state (string snapshot_name)
 
        xmlpath = _path;
        xmlpath += snapshot_name;
-       xmlpath += _pending_suffix;
+       xmlpath += pending_suffix;
 
-       if (!access (xmlpath.c_str(), F_OK)) {
+       if (Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) {
 
                /* there is pending state from a crashed capture attempt */
 
@@ -783,10 +721,10 @@ Session::load_state (string snapshot_name)
 
                xmlpath = _path;
                xmlpath += snapshot_name;
-               xmlpath += _statefile_suffix;
+               xmlpath += statefile_suffix;
        }
-
-       if (access (xmlpath.c_str(), F_OK)) {
+       
+       if (!Glib::file_test (xmlpath, Glib::FILE_TEST_EXISTS)) {
                error << string_compose(_("%1: session state information file \"%2\" doesn't exist!"), _name, xmlpath) << endmsg;
                return 1;
        }
@@ -828,8 +766,10 @@ Session::load_state (string snapshot_name)
        if (is_old) {
                string backup_path;
 
-               backup_path = xmlpath;
-               backup_path += ".1";
+               backup_path = _path;
+               backup_path += snapshot_name;
+               backup_path += "-1";
+               backup_path += statefile_suffix;
 
                info << string_compose (_("Copying old session file %1 to %2\nUse %2 with Ardour versions before 2.0 from now on"),
                                        xmlpath, backup_path) 
@@ -1614,7 +1554,7 @@ Session::path_from_region_name (string name, string identifier)
                        snprintf (buf, sizeof(buf), "%s/%s-%" PRIu32 ".wav", dir.c_str(), name.c_str(), n);
                }
 
-               if (!g_file_test (buf, G_FILE_TEST_EXISTS)) {
+               if (!Glib::file_test (buf, Glib::FILE_TEST_EXISTS)) {
                        return buf;
                }
        }
@@ -1698,7 +1638,7 @@ Session::save_template (string template_name)
 
        xml_path = dir;
        xml_path += template_name;
-       xml_path += _template_suffix;
+       xml_path += template_suffix;
 
        ifstream in(xml_path.c_str());
        
@@ -1720,8 +1660,8 @@ Session::save_template (string template_name)
 int
 Session::rename_template (string old_name, string new_name) 
 {
-       string old_path = template_dir() + old_name + _template_suffix;
-       string new_path = template_dir() + new_name + _template_suffix;
+       string old_path = template_dir() + old_name + template_suffix;
+       string new_path = template_dir() + new_name + template_suffix;
 
        return rename (old_path.c_str(), new_path.c_str());
 }
@@ -1731,7 +1671,7 @@ Session::delete_template (string name)
 {
        string template_path = template_dir();
        template_path += name;
-       template_path += _template_suffix;
+       template_path += template_suffix;
 
        return remove (template_path.c_str());
 }
@@ -2226,8 +2166,8 @@ Session::load_route_groups (const XMLNode& node, bool edit)
 static bool
 state_file_filter (const string &str, void *arg)
 {
-       return (str.length() > strlen(Session::statefile_suffix()) &&
-               str.find (Session::statefile_suffix()) == (str.length() - strlen (Session::statefile_suffix())));
+       return (str.length() > strlen(statefile_suffix) &&
+               str.find (statefile_suffix) == (str.length() - strlen (statefile_suffix)));
 }
 
 struct string_cmp {
@@ -2490,8 +2430,8 @@ Session::global_record_enable_memento (void* src)
 static bool
 template_filter (const string &str, void *arg)
 {
-       return (str.length() > strlen(Session::template_suffix()) &&
-               str.find (Session::template_suffix()) == (str.length() - strlen (Session::template_suffix())));
+       return (str.length() > strlen(template_suffix) &&
+               str.find (template_suffix) == (str.length() - strlen (template_suffix)));
 }
 
 void
@@ -2655,7 +2595,7 @@ Session::find_all_sources_across_snapshots (set<string>& result, bool exclude_th
 
        this_snapshot_path = _path;
        this_snapshot_path += _current_snapshot_name;
-       this_snapshot_path += _statefile_suffix;
+       this_snapshot_path += statefile_suffix;
 
        for (vector<string*>::iterator i = state_files->begin(); i != state_files->end(); ++i) {
 
@@ -3263,11 +3203,7 @@ Session::config_changed (const char* parameter_name)
 
        } else if (PARAM_IS ("use-video-sync")) {
 
-               if (transport_stopped()) {
-                       if (Config->get_use_video_sync()) {
-                               waiting_for_sync_offset = true;
-                       }
-               }
+               waiting_for_sync_offset = Config->get_use_video_sync();
 
        } else if (PARAM_IS ("mmc-control")) {