initially pass at libardour VCA implementation
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 22 Jan 2016 19:42:25 +0000 (14:42 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 31 May 2016 19:30:38 +0000 (15:30 -0400)
libs/ardour/ardour/gain_control.h
libs/ardour/ardour/vca.h [new file with mode: 0644]
libs/ardour/gain_control.cc
libs/ardour/vca.cc [new file with mode: 0644]
libs/ardour/wscript

index 07a900a164ddb3322145e515a0f38203eb67d4a0..fa43b5d39f5faee24516b309a84640918669972a 100644 (file)
@@ -40,6 +40,7 @@ class LIBARDOUR_API GainControl : public AutomationControl {
 
        void set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
        void set_value_unchecked (double);
+       double get_value () const;
 
        double internal_to_interface (double) const;
        double interface_to_internal (double) const;
@@ -49,8 +50,13 @@ class LIBARDOUR_API GainControl : public AutomationControl {
 
        double lower_db;
        double range_db;
+
+       boost::shared_ptr<GainControl> master() const { return _master; }
+       void set_master (boost::shared_ptr<GainControl>);
+
   private:
        void _set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
+       boost::shared_ptr<GainControl> _master;
 };
 
 } /* namespace */
diff --git a/libs/ardour/ardour/vca.h b/libs/ardour/ardour/vca.h
new file mode 100644 (file)
index 0000000..a394dac
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+    Copyright (C) 2016 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.,
+    675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef __ardour_vca_h__
+#define __ardour_vca_h__
+
+#include <string>
+#include <boost/shared_ptr.hpp>
+
+#include "pbd/controllable.h"
+
+#include "ardour/session_handle.h"
+
+namespace ARDOUR {
+
+class GainControl;
+class Route;
+
+class LIBARDOUR_API VCA : public SessionHandleRef {
+  public:
+       VCA (Session& session, const std::string& name);
+
+       void set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
+       double get_value () const;
+
+       boost::shared_ptr<AutomationControl> control() const { return _control; }
+
+       void add (boost::shared_ptr<Route>);
+       void remove (boost::shared_ptr<Route>);
+
+  private:
+       std::string name;
+       boost::shared_ptr<GainControl> _control;
+};
+
+} /* namespace */
+
+#endif /* __ardour_vca_h__ */
index 867edaf5a39d5ef3e666d61565d1505304bba610..5af0e2d397cf13d0d86d81dd17f82bbb23e7a7cb 100644 (file)
@@ -36,6 +36,15 @@ GainControl::GainControl (Session& session, const Evoral::Parameter &param, boos
        range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db;
 }
 
+double
+GainControl::get_value() const
+{
+       if (!_master) {
+               return AutomationControl::get_value();
+       }
+       return AutomationControl::get_value() * _master->get_value();
+}
+
 void
 GainControl::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
 {
@@ -97,3 +106,29 @@ GainControl::get_user_string () const
        return std::string(theBuf);
 }
 
+void
+GainControl::set_master (boost::shared_ptr<GainControl> m)
+{
+       double old_master_val;
+
+       if (_master) {
+               old_master_val = _master->get_value();
+       } else {
+               old_master_val = 1.0;
+       }
+
+       _master = m;
+
+       double new_master_val;
+
+       if (_master) {
+               new_master_val = _master->get_value();
+       } else {
+               new_master_val = 1.0;
+       }
+
+       if (old_master_val != new_master_val) {
+               Changed(); /* EMIT SIGNAL */
+       }
+}
+
diff --git a/libs/ardour/vca.cc b/libs/ardour/vca.cc
new file mode 100644 (file)
index 0000000..7580d57
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+    Copyright (C) 2016 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.,
+    675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "ardour/automation_control.h"
+#include "ardour/gain_control.h"
+#include "ardour/route.h"
+#include "ardour/vca.h"
+
+using namespace ARDOUR;
+using namespace PBD;
+using std::string;
+
+VCA::VCA (Session& s, const string& n)
+       : SessionHandleRef (s)
+       , name (n)
+       , _control (new GainControl (s, Evoral::Parameter (GainAutomation), boost::shared_ptr<AutomationList> ()))
+{
+}
+
+void
+VCA::set_value (double val, Controllable::GroupControlDisposition gcd)
+{
+       _control->set_value (val, gcd);
+}
+
+double
+VCA::get_value() const
+{
+       return _control->get_value();
+}
+
+void
+VCA::add (boost::shared_ptr<Route> r)
+{
+       boost::dynamic_pointer_cast<GainControl>(r->gain_control())->set_master (_control);
+}
+
+void
+VCA::remove (boost::shared_ptr<Route> r)
+{
+       boost::shared_ptr<GainControl> route_gain = boost::dynamic_pointer_cast<GainControl>(r->gain_control());
+       boost::shared_ptr<GainControl> current_master = route_gain->master();
+
+       if (current_master == _control) {
+               route_gain->set_master (boost::shared_ptr<GainControl>());
+       }
+}
index 80ec8e8e931d2a52f6b80aff30f8fd4c2c5aa7b6..a5ef2da595ae8c8b4053f8b13541c34d78d77d48 100644 (file)
@@ -231,6 +231,7 @@ libardour_sources = [
         'unknown_processor.cc',
         'user_bundle.cc',
         'utils.cc',
+        'vca.cc',
         'vumeterdsp.cc',
         'worker.cc'
 ]