* Caller must not hold process lock.
*/
int
-Session::create (const string& session_template, BusProfile* bus_profile)
+Session::create (const string& st, BusProfile* bus_profile)
{
if (g_mkdir_with_parents (_path.c_str(), 0755) < 0) {
error << string_compose(_("Session: cannot create session folder \"%1\" (%2)"), _path, strerror (errno)) << endmsg;
_writable = exists_and_writable (_path);
+ string session_template (st);
+
if (!session_template.empty()) {
- string in_path = (ARDOUR::Profile->get_trx () ? session_template : session_template_dir_to_file (session_template));
- FILE* in = g_fopen (in_path.c_str(), "rb");
+ if (session_template.find (G_DIR_SEPARATOR) == string::npos) {
+ /* not a path */
+ session_template = Glib::build_filename (user_template_directory(), session_template);
+ }
- if (in) {
- /* no need to call legalize_for_path() since the string
- * in session_template is already a legal path name
- */
- string out_path = Glib::build_filename (_session_dir->root_path(), _name + statefile_suffix);
+ cerr << "Using session template " << session_template << endl;
- FILE* out = g_fopen (out_path.c_str(), "wb");
+ string in_path = (ARDOUR::Profile->get_trx () ? session_template : session_template_dir_to_file (session_template));
- if (out) {
- char buf[1024];
- stringstream new_session;
+ FILE* in = g_fopen (in_path.c_str(), "rb");
- while (!feof (in)) {
- size_t charsRead = fread (buf, sizeof(char), 1024, in);
+ if (!in) {
+ error << string_compose (_("Could not open session template %1 for reading"), in_path)
+ << endmsg;
+ return -1;
+ }
- if (ferror (in)) {
- error << string_compose (_("Error reading session template file %1 (%2)"), in_path, strerror (errno)) << endmsg;
- fclose (in);
- fclose (out);
- return -1;
- }
- if (charsRead == 0) {
- break;
- }
- new_session.write (buf, charsRead);
- }
- fclose (in);
+ /* no need to call legalize_for_path() since the string
+ * in session_template is already a legal path name
+ */
+ string out_path = Glib::build_filename (_session_dir->root_path(), _name + statefile_suffix);
- string file_contents = new_session.str();
- size_t writeSize = file_contents.length();
- if (fwrite (file_contents.c_str(), sizeof(char), writeSize, out) != writeSize) {
- error << string_compose (_("Error writing session template file %1 (%2)"), out_path, strerror (errno)) << endmsg;
- fclose (out);
- return -1;
- }
- fclose (out);
+ FILE* out = g_fopen (out_path.c_str(), "wb");
- _is_new = false;
+ if (!out) {
+ error << string_compose (_("Could not open %1 for writing session template"), out_path)
+ << endmsg;
+ fclose(in);
+ return -1;
+ }
- if (!ARDOUR::Profile->get_trx()) {
- /* Copy plugin state files from template to new session */
- std::string template_plugins = Glib::build_filename (session_template, X_("plugins"));
- copy_recurse (template_plugins, plugins_dir ());
- }
+ char buf[1024];
+ stringstream new_session;
- return 0;
+ while (!feof (in)) {
+ size_t charsRead = fread (buf, sizeof(char), 1024, in);
- } else {
- error << string_compose (_("Could not open %1 for writing session template"), out_path)
- << endmsg;
- fclose(in);
+ if (ferror (in)) {
+ error << string_compose (_("Error reading session template file %1 (%2)"), in_path, strerror (errno)) << endmsg;
+ fclose (in);
+ fclose (out);
return -1;
}
+ if (charsRead == 0) {
+ break;
+ }
+ new_session.write (buf, charsRead);
+ }
+ fclose (in);
- } else {
- error << string_compose (_("Could not open session template %1 for reading"), in_path)
- << endmsg;
+ string file_contents = new_session.str();
+ size_t writeSize = file_contents.length();
+ if (fwrite (file_contents.c_str(), sizeof(char), writeSize, out) != writeSize) {
+ error << string_compose (_("Error writing session template file %1 (%2)"), out_path, strerror (errno)) << endmsg;
+ fclose (out);
return -1;
}
+ fclose (out);
+ _is_new = false;
+
+ if (!ARDOUR::Profile->get_trx()) {
+ /* Copy plugin state files from template to new session */
+ std::string template_plugins = Glib::build_filename (session_template, X_("plugins"));
+ copy_recurse (template_plugins, plugins_dir ());
+ }
+
+ return 0;
}
if (Profile->get_trx()) {