Add a ReadOnlyControl parameter abstraction
authorRobin Gareus <robin@gareus.org>
Wed, 12 Apr 2017 12:10:44 +0000 (14:10 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 12 Apr 2017 19:14:46 +0000 (21:14 +0200)
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
libs/ardour/ardour/readonly_control.h [new file with mode: 0644]
libs/ardour/plugin_insert.cc
libs/ardour/readonly_control.cc [new file with mode: 0644]
libs/ardour/wscript

index 2b8d1bc54246cc491f2ac9161b61b34d630563bc..b801207eaa9ee1e4b0fdd4208702d3bb758522f4 100644 (file)
@@ -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<ReadOnlyControl> 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<uint32_t, boost::shared_ptr<ReadOnlyControl> >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 (file)
index 0000000..8a2901a
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
+ * 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 <boost/weak_ptr.hpp>
+
+namespace ARDOUR {
+
+class Plugin;
+
+class LIBARDOUR_API ReadOnlyControl : public PBD::Destructible
+{
+public:
+       ReadOnlyControl (boost::shared_ptr<Plugin> p, uint32_t pnum);
+
+       double get_parameter () const;
+       std::string describe_parameter ();
+
+private:
+       boost::weak_ptr<Plugin> _plugin;
+       uint32_t _parameter_num;
+};
+
+} // namespace ARDOUR
+
+#endif /* __ardour_readonly_control_h__ */
index 7196a6d8445df0063e1a69dc3258e7b9a0a27d79..e9bea95dc9067e0856d2396aca988735d0c242df 100644 (file)
@@ -98,6 +98,9 @@ PluginInsert::PluginInsert (Session& s, boost::shared_ptr<Plugin> plug)
 
 PluginInsert::~PluginInsert ()
 {
+       for (CtrlOutMap::const_iterator i = _control_outputs.begin(); i != _control_outputs.end(); ++i) {
+               boost::dynamic_pointer_cast<ReadOnlyControl>(i->second)->drop_references ();
+       }
 }
 
 void
@@ -452,7 +455,11 @@ PluginInsert::create_automatable_parameters ()
        set<Evoral::Parameter> 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<ReadOnlyControl> (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<ReadOnlyControl>
+PluginInsert::control_output (uint32_t num) const
+{
+       CtrlOutMap::const_iterator i = _control_outputs.find (num);
+       if (i == _control_outputs.end ()) {
+               return boost::shared_ptr<ReadOnlyControl> ();
+       } 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 (file)
index 0000000..3b72ac5
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
+ * 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<Plugin> p, uint32_t pnum)
+               : _plugin (boost::weak_ptr<Plugin> (p))
+               , _parameter_num (pnum)
+{ }
+
+double
+ReadOnlyControl::get_parameter () const
+{
+       boost::shared_ptr<Plugin> p = _plugin.lock();
+       if (p) {
+               return p->get_parameter (_parameter_num);
+       }
+       return 0;
+}
+
+std::string
+ReadOnlyControl::describe_parameter ()
+{
+       boost::shared_ptr<Plugin> p = _plugin.lock();
+       if (p) {
+               return p->describe_parameter (Evoral::Parameter (ARDOUR::PluginAutomation, 0, _parameter_num));
+       }
+       return "";
+}
index 31eab1cd0c1b6b540907cc617480ae5c4587c96e..10984774260d2cd1be558b1845c444a309a58152 100644 (file)
@@ -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',