diff options
author | Carl Hetherington <carl@carlh.net> | 2011-12-11 20:38:42 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2011-12-11 20:38:42 +0000 |
commit | 73a91402cd0b12cf2cfe70f8fc4d4e4667fd259b (patch) | |
tree | 387106c75b4e1177306d3a80d76689808c07f68b | |
parent | a03f3229f44742b579fc0dabf7a2b364e1a9b96b (diff) |
Save templates as directories with plugin state, if
there is any, and copy that state to sessions created
from those templates. Should fix #4525. Breaks
existing session templates, sorry; they can be fixed by
moving the .template file into a new directory with the
name of the template (minus the .template).
git-svn-id: svn://localhost/ardour2/branches/3.0@10982 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | libs/ardour/ardour/session.h | 3 | ||||
-rw-r--r-- | libs/ardour/ardour/template_utils.h | 2 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 79 | ||||
-rw-r--r-- | libs/ardour/template_utils.cc | 30 | ||||
-rw-r--r-- | libs/pbd/filesystem.cc | 22 | ||||
-rw-r--r-- | libs/pbd/pbd/filesystem.h | 6 | ||||
-rw-r--r-- | templates/wscript | 6 |
7 files changed, 88 insertions, 60 deletions
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 19935c5440..734709be6a 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -390,9 +390,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi void remove_pending_capture_state (); int rename (const std::string&); - static int rename_template (std::string old_name, std::string new_name); - static int delete_template (std::string name); - PBD::Signal1<void,std::string> StateSaved; PBD::Signal0<void> StateReady; diff --git a/libs/ardour/ardour/template_utils.h b/libs/ardour/ardour/template_utils.h index fefb4a7c47..ec9fdaac8f 100644 --- a/libs/ardour/ardour/template_utils.h +++ b/libs/ardour/ardour/template_utils.h @@ -22,6 +22,8 @@ namespace ARDOUR { void find_route_templates (std::vector<TemplateInfo>& template_names); void find_session_templates (std::vector<TemplateInfo>& template_names); + std::string session_template_dir_to_file (std::string const &); + } // namespace ARDOUR #endif diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 7e139b2b18..7d6f44b786 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -502,9 +502,11 @@ Session::ensure_subdirs () return 0; } -/** Caller must not hold process lock */ +/** @param session_template directory containing session template, or empty. + * Caller must not hold process lock. + */ int -Session::create (const string& mix_template, BusProfile* bus_profile) +Session::create (const string& session_template, 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; @@ -517,8 +519,8 @@ Session::create (const string& mix_template, BusProfile* bus_profile) _writable = exists_and_writable (sys::path (_path)); - if (!mix_template.empty()) { - std::string in_path = mix_template; + if (!session_template.empty()) { + std::string in_path = session_template_dir_to_file (session_template); ifstream in(in_path.c_str()); @@ -532,16 +534,22 @@ Session::create (const string& mix_template, BusProfile* bus_profile) if (out) { out << in.rdbuf(); _is_new = false; + + /* Copy plugin state files from template to new session */ + sys::path template_plugins = session_template; + template_plugins /= X_("plugins"); + sys::copy_files (template_plugins, plugins_dir ()); + return 0; } else { - error << string_compose (_("Could not open %1 for writing mix template"), out_path) + error << string_compose (_("Could not open %1 for writing session template"), out_path) << endmsg; return -1; } } else { - error << string_compose (_("Could not open mix template %1 for reading"), in_path) + error << string_compose (_("Could not open session template %1 for reading"), in_path) << endmsg; return -1; } @@ -2048,59 +2056,36 @@ Session::save_template (string template_name) tree.set_root (&get_template()); - sys::path template_file_path(user_template_dir); - template_file_path /= template_name + template_suffix; - - if (sys::exists (template_file_path)) + sys::path template_dir_path(user_template_dir); + + /* directory to put the template in */ + template_dir_path /= template_name; + if (sys::exists (template_dir_path)) { warning << string_compose(_("Template \"%1\" already exists - new version not created"), - template_file_path.to_string()) << endmsg; + template_dir_path.to_string()) << endmsg; return -1; } + + sys::create_directories (template_dir_path); + + /* file to write */ + sys::path template_file_path = template_dir_path; + template_file_path /= template_name + template_suffix; if (!tree.write (template_file_path.to_string())) { error << _("template not saved") << endmsg; return -1; } - return 0; -} - -int -Session::rename_template (string old_name, string new_name) -{ - sys::path old_path (user_template_directory()); - old_path /= old_name + template_suffix; - - sys::path new_path(user_template_directory()); - new_path /= new_name + template_suffix; - - if (sys::exists (new_path)) { - warning << string_compose(_("Template \"%1\" already exists - template not renamed"), - new_path.to_string()) << endmsg; - return -1; - } - - try { - sys::rename (old_path, new_path); - return 0; - } catch (...) { - return -1; - } -} + /* copy plugin state directory */ -int -Session::delete_template (string name) -{ - sys::path path = user_template_directory(); - path /= name + template_suffix; + sys::path template_plugin_state_path = template_dir_path; + template_plugin_state_path /= X_("plugins"); + sys::create_directories (template_plugin_state_path); + sys::copy_files (plugins_dir(), template_plugin_state_path); - try { - sys::remove (path); - return 0; - } catch (...) { - return -1; - } + return 0; } void diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index aa0a583af4..825a24d3e1 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -1,6 +1,8 @@ #include <algorithm> #include <cstring> +#include <glibmm.h> + #include "pbd/filesystem.h" #include "pbd/basename.h" #include "pbd/pathscanner.h" @@ -66,11 +68,23 @@ user_route_template_directory () static bool template_filter (const string &str, void */*arg*/) { - cerr << "Checking into " << str << " using " << template_suffix << endl; - return (str.length() > strlen(template_suffix) && - str.find (template_suffix) == (str.length() - strlen (template_suffix))); + if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) { + return false; + } + + return true; +} + +string +session_template_dir_to_file (string const & dir) +{ + sys::path dir_path = dir; + sys::path file_path = dir; + file_path /= dir_path.leaf() + template_suffix; + return file_path.to_string (); } + void find_session_templates (vector<TemplateInfo>& template_names) { @@ -79,7 +93,7 @@ find_session_templates (vector<TemplateInfo>& template_names) SearchPath spath (system_template_directory()); spath += user_template_directory (); - templates = scanner (spath.to_string(), template_filter, 0, false, true); + templates = scanner (spath.to_string(), template_filter, 0, true, true); if (!templates) { cerr << "Found nothing along " << spath.to_string() << endl; @@ -89,18 +103,18 @@ find_session_templates (vector<TemplateInfo>& template_names) cerr << "Found " << templates->size() << " along " << spath.to_string() << endl; for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) { - string fullpath = *(*i); + string file = session_template_dir_to_file (**i); XMLTree tree; - if (!tree.read (fullpath.c_str())) { + if (!tree.read (file.c_str())) { continue; } TemplateInfo rti; - rti.name = basename_nosuffix (fullpath); - rti.path = fullpath; + rti.name = basename_nosuffix (**i); + rti.path = **i; template_names.push_back (rti); } diff --git a/libs/pbd/filesystem.cc b/libs/pbd/filesystem.cc index 661e21cbd5..a4bf781802 100644 --- a/libs/pbd/filesystem.cc +++ b/libs/pbd/filesystem.cc @@ -32,6 +32,7 @@ #include "pbd/filesystem.h" #include "pbd/error.h" #include "pbd/compose.h" +#include "pbd/pathscanner.h" #include "i18n.h" @@ -198,6 +199,27 @@ copy_file(const path & from_path, const path & to_path) } } +static +bool accept_all_files (string const &, void *) +{ + return true; +} + +void +copy_files(const path & from_path, const path & to_dir) +{ + PathScanner scanner; + vector<string*>* files = scanner (from_path.to_string(), accept_all_files, 0, true, false); + for (vector<string*>::iterator i = files->begin(); i != files->end(); ++i) { + sys::path from = from_path; + from /= **i; + sys::path to = to_dir; + to /= **i; + + copy_file (from, to); + } +} + string basename (const path & p) { diff --git a/libs/pbd/pbd/filesystem.h b/libs/pbd/pbd/filesystem.h index a20efaf613..e8073adf0e 100644 --- a/libs/pbd/pbd/filesystem.h +++ b/libs/pbd/pbd/filesystem.h @@ -179,6 +179,12 @@ void rename (const path& from_path, const path& to_path); void copy_file(const path & from_path, const path & to_path); /** + * Attempt to copy all regular files from from_path to a new directory. + * This method does not recurse. + */ +void copy_files(const path & from_path, const path & to_dir); + +/** * @return The substring of the filename component of the path, starting * at the beginning of the filename up to but not including the last dot. * diff --git a/templates/wscript b/templates/wscript index 7d01a73bb8..3f00b785ae 100644 --- a/templates/wscript +++ b/templates/wscript @@ -22,9 +22,11 @@ def build(bld): for t in templates: obj = bld(features = 'subst') obj.source = [ t ] - obj.target = [ os.path.basename(t.srcpath()).replace('.in', '') ] + dir_name = os.path.basename(t.srcpath()).replace('.template.in', '') + file_name = os.path.basename(t.srcpath()).replace('.in', '') + obj.target = [ os.path.join(dir_name, file_name) ] obj.dict = subst_dict - obj.install_path = os.path.join(bld.env['DATADIR'], 'ardour3', 'templates') + obj.install_path = os.path.join(bld.env['DATADIR'], 'ardour3', os.path.join('templates', dir_name)) def options(opt): pass |