cont'd work on plugin-state templates - #6709
Refactor and consolidate code and re-use it for session-templates. This avoids recursive copying of the plugin-dir()
This commit is contained in:
parent
ec9a8f022c
commit
d9eb5e00c5
@ -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<Processor>, const std::string&);
|
||||
|
||||
boost::shared_ptr<CapturingProcessor> _capturing_processor;
|
||||
|
||||
/** A handy class to keep processor state while we attempt a reconfiguration
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<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());
|
||||
|
@ -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<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;
|
||||
|
Loading…
Reference in New Issue
Block a user