diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h index b63cbb9147..0ef063b29c 100644 --- a/libs/ardour/ardour/route.h +++ b/libs/ardour/ardour/route.h @@ -714,6 +714,8 @@ class LIBARDOUR_API Route : public SessionObject, public Automatable, public Rou void setup_invisible_processors (); void unpan (); + void set_plugin_state_dir (boost::weak_ptr, const std::string&); + boost::shared_ptr _capturing_processor; /** A handy class to keep processor state while we attempt a reconfiguration diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 6a73e85663..a5b93af041 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1839,6 +1839,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop static int get_session_info_from_path (XMLTree& state_tree, const std::string& xmlpath); static const uint32_t session_end_shift; + + std::string _template_state_dir; }; diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 3753bd8066..9c52bb255e 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -44,7 +44,6 @@ #include "ardour/debug.h" #include "ardour/lv2_plugin.h" #include "ardour/session.h" -#include "ardour/template_utils.h" #include "ardour/tempo.h" #include "ardour/types.h" #include "ardour/utils.h" @@ -1744,10 +1743,7 @@ LV2Plugin::set_state(const XMLNode& node, int version) } if ((prop = node.property("template-dir")) != 0) { - // portable templates, strip absolute path - set_state_dir (Glib::build_filename ( - ARDOUR::user_route_template_directory (), - Glib::path_get_basename (prop->value ()))); + set_state_dir (prop->value ()); } _state_version = 0; diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index e24919a3b3..3027019bff 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -2253,6 +2253,11 @@ Route::get_template() XMLNode& Route::state(bool full_state) { + if (!_session._template_state_dir.empty()) { + assert (!full_state); // only for templates + foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir)); + } + XMLNode *node = new XMLNode("Route"); ProcessorList::iterator i; char buf[32]; @@ -2347,6 +2352,10 @@ Route::state(bool full_state) } } + if (!_session._template_state_dir.empty()) { + foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), "")); + } + return *node; } @@ -4154,42 +4163,30 @@ Route::shift (framepos_t pos, framecnt_t frames) } } +void +Route::set_plugin_state_dir (boost::weak_ptr p, const std::string& d) +{ + boost::shared_ptr processor (p.lock ()); + boost::shared_ptr pi = boost::dynamic_pointer_cast (processor); + if (!pi) { + return; + } + pi->set_state_dir (d); +} int Route::save_as_template (const string& path, const string& name) { - { - // would be nice to use foreach_processor() - Glib::Threads::RWLock::ReaderLock lm (_processor_lock); - std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix - for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) { - boost::shared_ptr pi = boost::dynamic_pointer_cast (*i); - if (pi) { - pi->set_state_dir (state_dir); - } - } - } + std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix + PBD::Unwinder uw (_session._template_state_dir, state_dir); XMLNode& node (state (false)); - { - Glib::Threads::RWLock::ReaderLock lm (_processor_lock); - for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) { - boost::shared_ptr pi = boost::dynamic_pointer_cast (*i); - if (pi) { - pi->set_state_dir (); - } - } - } - XMLTree tree; IO::set_name_in_state (*node.children().front(), name); tree.set_root (&node); - // TODO: special case LV2 plugin state - // copy of serialize it. Alternatively: - // create a plugin-preset (which can be loaded separately) /* return zero on success, non-zero otherwise */ return !tree.write (path.c_str()); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index c440b77895..bde7208867 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -73,6 +73,7 @@ #include "pbd/stacktrace.h" #include "pbd/convert.h" #include "pbd/localtime_r.h" +#include "pbd/unwind.h" #include "ardour/amp.h" #include "ardour/async_midi_port.h" @@ -2161,25 +2162,16 @@ Session::save_template (string template_name, bool replace_existing) XMLTree tree; - tree.set_root (&get_template()); + { + PBD::Unwinder uw (_template_state_dir, template_dir_path); + tree.set_root (&get_template()); + } + if (!tree.write (template_file_path)) { error << _("template not saved") << endmsg; return -1; } - if (!ARDOUR::Profile->get_trx()) { - /* copy plugin state directory */ - - std::string template_plugin_state_path (Glib::build_filename (template_dir_path, X_("plugins"))); - - if (g_mkdir_with_parents (template_plugin_state_path.c_str(), 0755) != 0) { - error << string_compose(_("Could not create directory for Session template plugin state\"%1\" (%2)"), - template_plugin_state_path, g_strerror (errno)) << endmsg; - return -1; - } - copy_files (plugins_dir(), template_plugin_state_path); - } - store_recent_templates (template_file_path); return 0;