add API to use a plugin provided bypass control port
authorRobin Gareus <robin@gareus.org>
Tue, 5 Jul 2016 19:26:45 +0000 (21:26 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 5 Jul 2016 21:30:21 +0000 (23:30 +0200)
* new separate API: en/disable
* old API remains in place for hard bypass
* PluginInsert::enable() falls back to activate/deativate if a plugin
  does not provided designated bypass control port

libs/ardour/ardour/plugin.h
libs/ardour/ardour/plugin_insert.h
libs/ardour/ardour/processor.h
libs/ardour/plugin_insert.cc

index 935b75faead0719bdb869998413e79d5a30710f2..dcb6577e7aaf61dab2b9b3310adaeb0a282b5fb6 100644 (file)
@@ -113,6 +113,8 @@ class LIBARDOUR_API Plugin : public PBD::StatefulDestructible, public Latent
        virtual bool parameter_is_input(uint32_t) const = 0;
        virtual bool parameter_is_output(uint32_t) const = 0;
 
+       virtual uint32_t designated_bypass_port () { return UINT32_MAX; }
+
        struct LIBARDOUR_API IOPortDescription {
                public:
                IOPortDescription (const std::string& n)
index 9f1d56b81103922977b0f16c77dc9e9ba6cee49a..6f7b10cd46d94a99acefc3e9af2668de578f83ea 100644 (file)
@@ -68,6 +68,10 @@ class LIBARDOUR_API PluginInsert : public Processor
        void deactivate ();
        void flush ();
 
+       void enable (bool yn);
+       bool enabled () const;
+       bool bypassable () const;
+
        bool reset_parameters_to_default ();
        bool can_reset_all_parameters ();
 
@@ -355,6 +359,9 @@ class LIBARDOUR_API PluginInsert : public Processor
        void set_parameter_state_2X (const XMLNode& node, int version);
        void set_control_ids (const XMLNode&, int version);
 
+       void enable_changed ();
+       void bypassable_changed ();
+
        boost::shared_ptr<Plugin> plugin_factory (boost::shared_ptr<Plugin>);
        void add_plugin (boost::shared_ptr<Plugin>);
 
@@ -363,6 +370,7 @@ class LIBARDOUR_API PluginInsert : public Processor
 
        void latency_changed (framecnt_t, framecnt_t);
        bool _latency_changed;
+       uint32_t _bypass_port;
 };
 
 } // namespace ARDOUR
index c86827c13b196af1f0ba3b638b8cf1330c7e8665..1a4863ff2d85eef2a53d208078968c37437f7204 100644 (file)
@@ -59,7 +59,9 @@ class LIBARDOUR_API Processor : public SessionObject, public Automatable, public
        virtual bool display_to_user() const { return _display_to_user; }
        virtual void set_display_to_user (bool);
 
-       bool active () const { return _pending_active; }
+       bool active () const { return _pending_active; } ///< ardour hard bypass
+       virtual bool enabled () const { return _pending_active; } ///< processor enabled/bypass
+       virtual bool bypassable () const { return true; } ///< enable is not automated or locked
 
        virtual bool does_routing() const { return false; }
 
@@ -81,6 +83,8 @@ class LIBARDOUR_API Processor : public SessionObject, public Automatable, public
        virtual void deactivate () { _pending_active = false; ActiveChanged(); }
        virtual void flush() {}
 
+       virtual void enable (bool yn) { if (yn) { activate (); } else { deactivate (); } }
+
        virtual bool configure_io (ChanCount in, ChanCount out);
 
        /* Derived classes should override these, or processor appears as an in-place pass-through */
@@ -111,6 +115,7 @@ class LIBARDOUR_API Processor : public SessionObject, public Automatable, public
        virtual void set_pre_fader (bool);
 
        PBD::Signal0<void>                     ActiveChanged;
+       PBD::Signal0<void>                     BypassableChanged;
        PBD::Signal2<void,ChanCount,ChanCount> ConfigurationChanged;
 
        void  set_ui (void*);
index 0de2d7fe5a8dc0b1af4b0048615623883f8b62d9..a8757fc97e53b80785457a0b21f4fe36e927f181 100644 (file)
@@ -76,6 +76,7 @@ PluginInsert::PluginInsert (Session& s, boost::shared_ptr<Plugin> plug)
        , _strict_io (false)
        , _custom_cfg (false)
        , _maps_from_state (false)
+       , _bypass_port (UINT32_MAX)
 {
        /* the first is the master */
 
@@ -457,6 +458,7 @@ PluginInsert::create_automatable_parameters ()
                plugin->set_automation_control (i, c);
        }
 
+
        const Plugin::PropertyDescriptors& pdl (plugin->get_supported_properties ());
        for (Plugin::PropertyDescriptors::const_iterator p = pdl.begin(); p != pdl.end(); ++p) {
                Evoral::Parameter param (PluginPropertyAutomation, 0, p->first);
@@ -469,6 +471,16 @@ PluginInsert::create_automatable_parameters ()
                        add_control (boost::shared_ptr<AutomationControl> (new PluginPropertyControl(this, param, desc, list)));
                }
        }
+
+       _bypass_port = plugin->designated_bypass_port ();
+
+       if (_bypass_port != UINT32_MAX) {
+               boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, _bypass_port));
+               if (0 == (ac->flags () & Controllable::NotAutomatable)) {
+                       ac->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&PluginInsert::bypassable_changed, this));
+                       ac->Changed.connect_same_thread (*this, boost::bind (&PluginInsert::enable_changed, this));
+               }
+       }
 }
 /** Called when something outside of this host has modified a plugin
  * parameter. Responsible for propagating the change to two places:
@@ -559,6 +571,60 @@ PluginInsert::flush ()
        }
 }
 
+void
+PluginInsert::enable (bool yn)
+{
+       if (_bypass_port == UINT32_MAX) {
+               if (yn) {
+                       activate ();
+               } else {
+                       deactivate ();
+               }
+       } else {
+               if (!_pending_active) {
+                       activate ();
+               }
+               boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, _bypass_port));
+               ac->set_value (yn ? 1.0 : 0.0, Controllable::NoGroup);
+               ActiveChanged ();
+       }
+}
+
+bool
+PluginInsert::enabled () const
+{
+       if (_bypass_port == UINT32_MAX) {
+               return Processor::enabled ();
+       } else {
+               boost::shared_ptr<const AutomationControl> ac = boost::const_pointer_cast<AutomationControl> (automation_control (Evoral::Parameter (PluginAutomation, 0, _bypass_port)));
+               return (ac->get_value () > 0 && _pending_active);
+       }
+}
+
+bool
+PluginInsert::bypassable () const
+{
+       if (_bypass_port == UINT32_MAX) {
+               return true;
+       } else {
+               boost::shared_ptr<const AutomationControl> ac = boost::const_pointer_cast<AutomationControl> (automation_control (Evoral::Parameter (PluginAutomation, 0, _bypass_port)));
+
+               return !ac->automation_playback ();
+       }
+}
+
+void
+PluginInsert::enable_changed ()
+{
+       ActiveChanged ();
+}
+
+void
+PluginInsert::bypassable_changed ()
+{
+       BypassableChanged ();
+}
+
 void
 PluginInsert::inplace_silence_unconnected (BufferSet& bufs, const PinMappings& out_map, framecnt_t nframes, framecnt_t offset) const
 {
@@ -2832,6 +2898,7 @@ PluginInsert::add_plugin (boost::shared_ptr<Plugin> plugin)
                vst->set_insert (this, _plugins.size ());
        }
 #endif
+
        _plugins.push_back (plugin);
 }