Refactor and consolidate code and re-use it for session-templates.
This avoids recursive copying of the plugin-dir()
void setup_invisible_processors ();
void unpan ();
+ void set_plugin_state_dir (boost::weak_ptr<Processor>, const std::string&);
+
boost::shared_ptr<CapturingProcessor> _capturing_processor;
/** A handy class to keep processor state while we attempt a reconfiguration
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;
};
#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"
}
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;
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];
}
}
+ if (!_session._template_state_dir.empty()) {
+ foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
+ }
+
return *node;
}
}
}
+void
+Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
+{
+ boost::shared_ptr<Processor> processor (p.lock ());
+ boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (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<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*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<std::string> 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<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*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());
#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"
XMLTree tree;
- tree.set_root (&get_template());
+ {
+ PBD::Unwinder<std::string> 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;