From 7a489dd5532ae53ab943adc1f38c1bc24b4474c9 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 12 Apr 2017 14:10:44 +0200 Subject: Add a ReadOnlyControl parameter abstraction This allows to pass a sperici Controllable alike instance around without relying on directly exposing the Plugin instance and parameter-id. --- libs/ardour/ardour/plugin_insert.h | 6 +++++ libs/ardour/ardour/readonly_control.h | 44 ++++++++++++++++++++++++++++++ libs/ardour/plugin_insert.cc | 19 ++++++++++++- libs/ardour/readonly_control.cc | 50 +++++++++++++++++++++++++++++++++++ libs/ardour/wscript | 1 + 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 libs/ardour/ardour/readonly_control.h create mode 100644 libs/ardour/readonly_control.cc (limited to 'libs') diff --git a/libs/ardour/ardour/plugin_insert.h b/libs/ardour/ardour/plugin_insert.h index 2b8d1bc542..b801207eaa 100644 --- a/libs/ardour/ardour/plugin_insert.h +++ b/libs/ardour/ardour/plugin_insert.h @@ -34,6 +34,7 @@ #include "ardour/parameter_descriptor.h" #include "ardour/plugin.h" #include "ardour/processor.h" +#include "ardour/readonly_control.h" #include "ardour/sidechain.h" #include "ardour/automation_control.h" @@ -243,6 +244,8 @@ class LIBARDOUR_API PluginInsert : public Processor PluginType type (); + boost::shared_ptr control_output (uint32_t) const; + std::string describe_parameter (Evoral::Parameter param); framecnt_t signal_latency () const; @@ -375,6 +378,9 @@ class LIBARDOUR_API PluginInsert : public Processor bool _latency_changed; uint32_t _bypass_port; + typedef std::map >CtrlOutMap; + CtrlOutMap _control_outputs; + void preset_load_set_value (uint32_t, float); }; diff --git a/libs/ardour/ardour/readonly_control.h b/libs/ardour/ardour/readonly_control.h new file mode 100644 index 0000000000..8a2901af68 --- /dev/null +++ b/libs/ardour/ardour/readonly_control.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2017 Robin Gareus + * Copyright (C) 2000, 2007 Paul Davis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __ardour_readonly_control_h__ +#define __ardour_readonly_control_h__ + +#include + +namespace ARDOUR { + +class Plugin; + +class LIBARDOUR_API ReadOnlyControl : public PBD::Destructible +{ +public: + ReadOnlyControl (boost::shared_ptr p, uint32_t pnum); + + double get_parameter () const; + std::string describe_parameter (); + +private: + boost::weak_ptr _plugin; + uint32_t _parameter_num; +}; + +} // namespace ARDOUR + +#endif /* __ardour_readonly_control_h__ */ diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc index 7196a6d844..e9bea95dc9 100644 --- a/libs/ardour/plugin_insert.cc +++ b/libs/ardour/plugin_insert.cc @@ -98,6 +98,9 @@ PluginInsert::PluginInsert (Session& s, boost::shared_ptr plug) PluginInsert::~PluginInsert () { + for (CtrlOutMap::const_iterator i = _control_outputs.begin(); i != _control_outputs.end(); ++i) { + boost::dynamic_pointer_cast(i->second)->drop_references (); + } } void @@ -452,7 +455,11 @@ PluginInsert::create_automatable_parameters () set a = _plugins.front()->automatable (); for (uint32_t i = 0; i < plugin->parameter_count(); ++i) { - if (!plugin->parameter_is_control (i) || !plugin->parameter_is_input (i)) { + if (!plugin->parameter_is_control (i)) { + continue; + } + if (!plugin->parameter_is_input (i)) { + _control_outputs[i] = boost::shared_ptr (new ReadOnlyControl (plugin, i)); continue; } Evoral::Parameter param (PluginAutomation, 0, i); @@ -2803,6 +2810,16 @@ PluginInsert::set_parameter_state_2X (const XMLNode& node, int version) } } +boost::shared_ptr +PluginInsert::control_output (uint32_t num) const +{ + CtrlOutMap::const_iterator i = _control_outputs.find (num); + if (i == _control_outputs.end ()) { + return boost::shared_ptr (); + } else { + return (*i).second; + } +} string PluginInsert::describe_parameter (Evoral::Parameter param) diff --git a/libs/ardour/readonly_control.cc b/libs/ardour/readonly_control.cc new file mode 100644 index 0000000000..3b72ac5e1b --- /dev/null +++ b/libs/ardour/readonly_control.cc @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017 Robin Gareus + * Copyright (C) 2000, 2007 Paul Davis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "pbd/destructible.h" + +#include "ardour/plugin.h" +#include "ardour/readonly_control.h" + +using namespace ARDOUR; + +ReadOnlyControl::ReadOnlyControl (boost::shared_ptr p, uint32_t pnum) + : _plugin (boost::weak_ptr (p)) + , _parameter_num (pnum) +{ } + +double +ReadOnlyControl::get_parameter () const +{ + boost::shared_ptr p = _plugin.lock(); + if (p) { + return p->get_parameter (_parameter_num); + } + return 0; +} + +std::string +ReadOnlyControl::describe_parameter () +{ + boost::shared_ptr p = _plugin.lock(); + if (p) { + return p->describe_parameter (Evoral::Parameter (ARDOUR::PluginAutomation, 0, _parameter_num)); + } + return ""; +} diff --git a/libs/ardour/wscript b/libs/ardour/wscript index 31eab1cd0c..1098477426 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -178,6 +178,7 @@ libardour_sources = [ 'progress.cc', 'quantize.cc', 'rc_configuration.cc', + 'readonly_control.cc', 'recent_sessions.cc', 'record_enable_control.cc', 'record_safe_control.cc', -- cgit v1.2.3