+
+ if (ensure_subdirs ()) {
+ return -1;
+ }
+
+ /* check new_session so we don't overwrite an existing one */
+
+ if (!mix_template.empty()) {
+ 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);
+ _locations.add (start_location);
+
+ end_location->set_end (initial_length);
+ _locations.add (end_location);
+
+ _state_of_the_state = Clean;
+
+ save_state ("");
+
+ return 0;