working version of new gain control design
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 13 Jan 2016 21:32:24 +0000 (16:32 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 18 Jan 2016 17:11:08 +0000 (12:11 -0500)
gtk2_ardour/gain_meter.cc
libs/ardour/amp.cc
libs/ardour/ardour/amp.h
libs/ardour/ardour/route.h
libs/ardour/audio_track.cc
libs/ardour/internal_send.cc
libs/ardour/route.cc
libs/ardour/session_state.cc
libs/surfaces/osc/osc.cc

index 4a7e75fcf730f27ce1021837c7949a1d89c37033..7fa9bf88de6a16bac9cc2e5b98a8f58aecbb3745 100644 (file)
@@ -470,10 +470,10 @@ GainMeterBase::gain_activated ()
        /* clamp to displayable values */
        if (_data_type == DataType::AUDIO) {
                f = min (f, 6.0f);
-               _amp->set_gain (dB_to_coefficient(f), this);
+               _amp->gain_control()->set_value (dB_to_coefficient(f), Controllable::NoGroup);
        } else {
                f = min (fabs (f), 2.0f);
-               _amp->set_gain (f, this);
+               _amp->gain_control()->set_value (f, Controllable::NoGroup);
        }
 
        if (gain_display.has_focus()) {
@@ -534,7 +534,7 @@ GainMeterBase::gain_adjusted ()
                if (_route && _route->amp() == _amp) {
                        _route->set_gain (value, this);
                } else {
-                       _amp->set_gain (value, this);
+                       _amp->gain_control()->set_value (value, Controllable::NoGroup);
                }
        }
 
index 8dac6d73fc956eee89b17f56e9835b2242603552..49570bb511226d92c11e26be2bbe248c701c7e05 100644 (file)
@@ -348,25 +348,6 @@ Amp::apply_simple_gain (AudioBuffer& buf, framecnt_t nframes, gain_t target)
        }
 }
 
-void
-Amp::inc_gain (gain_t factor, void *src)
-{
-       float desired_gain = _gain_control->user_double();
-
-       if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
-               // really?! what's the idea here?
-               set_gain (0.000001f + (0.000001f * factor), src);
-       } else {
-               set_gain (desired_gain + (desired_gain * factor), src);
-       }
-}
-
-void
-Amp::set_gain (gain_t val, void *)
-{
-       _gain_control->set_value (val, Controllable::NoGroup);
-}
-
 XMLNode&
 Amp::state (bool full_state)
 {
index bd4c8b1259f7d80bde6b8453e865fa87c1efc357..673ec2e3c355ebd2c550a16168c58b7e75dc545c 100644 (file)
@@ -70,14 +70,10 @@ public:
 
        static void declick (BufferSet& bufs, framecnt_t nframes, int dir);
 
-       gain_t         gain () const { return _gain_control->get_value(); }
-
-       void           set_gain (gain_t g, void *src);
-       void           inc_gain (gain_t delta, void *src);
+       gain_t gain () const { return _gain_control->get_value(); }
 
        static void update_meters();
 
-
        boost::shared_ptr<AutomationControl> gain_control() {
                return _gain_control;
        }
index 9a0cf9ee0b58057b72a5371953cf489dcf4a1c65..a57610ab98597f789641f8602a8ff376911f8306 100644 (file)
@@ -41,6 +41,7 @@
 #include "pbd/destructible.h"
 
 #include "ardour/ardour.h"
+#include "ardour/gain_control.h"
 #include "ardour/instrument_info.h"
 #include "ardour/io.h"
 #include "ardour/libardour_visibility.h"
@@ -145,7 +146,6 @@ class LIBARDOUR_API Route : public SessionObject, public Automatable, public Rou
        void inc_gain (gain_t delta, void *src);
 
        void set_trim (gain_t val, void *src);
-       void inc_trim (gain_t delta, void *src);
 
        void set_mute_points (MuteMaster::MutePoint);
        MuteMaster::MutePoint mute_points () const;
@@ -381,7 +381,9 @@ class LIBARDOUR_API Route : public SessionObject, public Automatable, public Rou
        void clear_fed_by ();
        bool add_fed_by (boost::shared_ptr<Route>, bool sends_only);
 
-       /* Controls (not all directly owned by the Route */
+       /* Controls (not all directly owned by the Route) */
+
+       boost::shared_ptr<AutomationControl> get_control (const Evoral::Parameter& param);
 
        class RouteAutomationControl : public AutomationControl {
        public:
@@ -393,7 +395,7 @@ class LIBARDOUR_API Route : public SessionObject, public Automatable, public Rou
                void set_value (double val, PBD::Controllable::GroupControlDisposition group_override) {
                        boost::shared_ptr<Route> r = _route.lock();
                        if (r) {
-                               r->set_control (*this, val, group_override);
+                               r->set_control ((AutomationType) parameter().type(), val, group_override);
                        }
                }
 
@@ -407,7 +409,28 @@ class LIBARDOUR_API Route : public SessionObject, public Automatable, public Rou
                boost::weak_ptr<Route> _route;
        };
 
-       boost::shared_ptr<AutomationControl> get_control (const Evoral::Parameter& param);
+       class GainControllable : public GainControl  {
+       public:
+               GainControllable (Session& session,
+                                 AutomationType type,
+                                 boost::shared_ptr<Route> route);
+
+               void set_value (double val, PBD::Controllable::GroupControlDisposition group_override) {
+                       boost::shared_ptr<Route> r = _route.lock();
+                       if (r) {
+                               r->set_control ((AutomationType) parameter().type(), val, group_override);
+                       }
+               }
+
+       protected:
+               friend class Route;
+
+               void route_set_value (double val) {
+                       GainControl::set_value (val, Controllable::NoGroup);
+               }
+
+               boost::weak_ptr<Route> _route;
+       };
 
        class SoloControllable : public RouteAutomationControl {
        public:
@@ -442,7 +465,7 @@ class LIBARDOUR_API Route : public SessionObject, public Automatable, public Rou
                uint32_t _current_phase;
        };
 
-       void set_control (RouteAutomationControl&, double val, PBD::Controllable::GroupControlDisposition group_override);
+       void set_control (AutomationType, double val, PBD::Controllable::GroupControlDisposition group_override);
 
        boost::shared_ptr<SoloControllable> solo_control() const {
                return _solo_control;
@@ -675,9 +698,9 @@ class LIBARDOUR_API Route : public SessionObject, public Automatable, public Rou
 
        virtual void maybe_declick (BufferSet&, framecnt_t, int);
 
-       boost::shared_ptr<AutomationControl> _gain_control;
+       boost::shared_ptr<GainControllable> _gain_control;
        boost::shared_ptr<Amp>       _amp;
-       boost::shared_ptr<AutomationControl> _trim_control;
+       boost::shared_ptr<GainControllable> _trim_control;
        boost::shared_ptr<Amp>       _trim;
        boost::shared_ptr<PeakMeter> _meter;
        boost::shared_ptr<DelayLine> _delayline;
index 5e4a3bf236fa4fdbb4c8a0a22c87d75533d69c03..f5d5207cc65a46eaf6321a1466abbaabb222e067 100644 (file)
@@ -166,7 +166,7 @@ AudioTrack::deprecated_use_diskstream_connections ()
        diskstream->deprecated_io_node = 0;
 
        if ((prop = node.property ("gain")) != 0) {
-               _amp->set_gain (atof (prop->value().c_str()), this);
+               _amp->gain_control()->set_value (atof (prop->value().c_str()), PBD::Controllable::NoGroup);
        }
 
        if ((prop = node.property ("input-connection")) != 0) {
index 60de2087f3701a58ec3685789ccc0a01a8d121cb..88705359395ee043df501ecc4d5420362bc7b25d 100644 (file)
@@ -74,10 +74,10 @@ InternalSend::init_gain ()
 {
        if (_role == Listen) {
                /* send to monitor bus is always at unity */
-               _amp->set_gain (GAIN_COEFF_UNITY, this);
+               _gain_control->set_value (GAIN_COEFF_UNITY, PBD::Controllable::NoGroup);
        } else {
                /* aux sends start at -inf dB */
-               _amp->set_gain (GAIN_COEFF_ZERO, this);
+               _gain_control->set_value (GAIN_COEFF_ZERO, PBD::Controllable::NoGroup);
        }
 }
 
index 16efc35a8c67574c237b7f43e7c465e1abd63a4a..a23af603de87eaab2da15579451a0c790820fec4 100644 (file)
@@ -172,8 +172,7 @@ Route::init ()
 
        /* add amp processor  */
 
-       boost::shared_ptr<AutomationList> gl (new AutomationList (Evoral::Parameter (GainAutomation)));
-       _gain_control = boost::shared_ptr<GainControl> (new GainControl (_session, Evoral::Parameter(GainAutomation), gl));
+       _gain_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, GainAutomation, shared_from_this ()));
        add_control (_gain_control);
 
        _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
@@ -185,8 +184,7 @@ Route::init ()
 
        /* and input trim */
 
-       boost::shared_ptr<AutomationList> tl (new AutomationList (Evoral::Parameter (TrimAutomation)));
-       _trim_control = boost::shared_ptr<GainControl> (new GainControl (_session, Evoral::Parameter(TrimAutomation), tl));
+       _trim_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, TrimAutomation, shared_from_this ()));
        add_control (_trim_control);
 
        _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
@@ -389,9 +387,20 @@ Route::ensure_track_or_route_name(string name, Session &session)
 }
 
 void
-Route::inc_gain (gain_t fraction, void *src)
+Route::inc_gain (gain_t factor, void *src)
 {
-       _amp->inc_gain (fraction, src);
+       /* To be used ONLY when doing group-relative gain adjustment, from
+        * ::set_gain()
+        */
+
+       float desired_gain = _gain_control->user_double();
+
+       if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
+               // really?! what's the idea here?
+               _gain_control->route_set_value (0.000001f + (0.000001f * factor));
+       } else {
+               _gain_control->route_set_value (desired_gain + (desired_gain * factor));
+       }
 }
 
 void
@@ -442,24 +451,18 @@ Route::set_gain (gain_t val, void *src)
                return;
        }
 
-       if (val == _amp->gain()) {
+       if (val == _gain_control->get_value()) {
                return;
        }
 
-       _amp->set_gain (val, src);
-}
-
-void
-Route::inc_trim (gain_t fraction, void *src)
-{
-       _trim->inc_gain (fraction, src);
+       _gain_control->route_set_value (val);
 }
 
 void
 Route::set_trim (gain_t val, void * /* src */)
 {
        // TODO route group, see set_gain()
-       _trim->set_gain (val, 0);
+       _trim_control->route_set_value (val);
 }
 
 void
@@ -3891,17 +3894,23 @@ Route::set_latency_compensation (framecnt_t longest_session_latency)
 }
 
 void
-Route::set_control (RouteAutomationControl& control, double val, PBD::Controllable::GroupControlDisposition /*group_override*/)
+Route::set_control (AutomationType type, double val, PBD::Controllable::GroupControlDisposition /*group_override*/)
 {
        boost::shared_ptr<RouteList> rl;
 
-       switch (control.parameter().type()) {
+       switch (type) {
        case GainAutomation:
                /* route must mediate group control */
                set_gain (val, this); /* any "src" argument will do other than our route group */
                return;
                break;
 
+       case TrimAutomation:
+               /* route must mediate group control */
+               set_trim (val, this); /* any "src" argument will do other than our route group */
+               return;
+               break;
+
        case RecEnableAutomation:
                /* session must mediate group control */
                rl.reset (new RouteList);
@@ -3931,19 +3940,12 @@ Route::set_control (RouteAutomationControl& control, double val, PBD::Controllab
                return;
                break;
 
-       case PanAzimuthAutomation:
-       case PanElevationAutomation:
-       case PanWidthAutomation:
-       case PanFrontBackAutomation:
-       case PanLFEAutomation:
-               break;
-
        default:
                /* Not a route automation control */
+               fatal << string_compose (_("programming error: %1%2\n"), X_("illegal type of route automation control passed to Route::set_control(): "), enum_2_string(type)) << endmsg;
+               /*NOTREACHED*/
                return;
        }
-
-       control.route_set_value (val);
 }
 
 
@@ -3958,6 +3960,13 @@ Route::RouteAutomationControl::RouteAutomationControl (const std::string& name,
 {
 }
 
+Route::GainControllable::GainControllable (Session& s, AutomationType atype, boost::shared_ptr<Route> r)
+       : GainControl (s, Evoral::Parameter(atype))
+       , _route (r)
+{
+
+}
+
 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
        : RouteAutomationControl (name, SoloAutomation, boost::shared_ptr<AutomationList>(), r)
 {
@@ -4436,13 +4445,13 @@ Route::panner_shell() const
 boost::shared_ptr<AutomationControl>
 Route::gain_control() const
 {
-       return _amp->gain_control();
+       return _gain_control;
 }
 
 boost::shared_ptr<AutomationControl>
 Route::trim_control() const
 {
-       return _trim->gain_control();
+       return _trim_control;
 }
 
 boost::shared_ptr<AutomationControl>
index bde7208867ee9401dba352cefc6136e454a90268..13d1413b193dc3adbfe671d690f8e9fcfed59470 100644 (file)
@@ -3740,7 +3740,7 @@ Session::config_changed (std::string p, bool ours)
        } else if (p == "click-gain") {
 
                if (_click_gain) {
-                       _click_gain->set_gain (Config->get_click_gain(), this);
+                       _click_gain->gain_control()->set_value (Config->get_click_gain(), Controllable::NoGroup);
                }
 
        } else if (p == "send-mtc") {
index f245a65ad3660ed362e11238a6d38757e99c59e3..31fd146a5f9fb04ccb3102a361c151c209d951ed 100644 (file)
@@ -1109,7 +1109,7 @@ OSC::route_set_send_gain_abs (int rid, int sid, float val)
                boost::shared_ptr<Amp> a = s->amp();
 
                if (a) {
-                       a->set_gain (val, this);
+                       a->gain_control()->set_value (val, PBD::Controllable::NoGroup);
                }
        }
        return 0;
@@ -1141,7 +1141,7 @@ OSC::route_set_send_gain_dB (int rid, int sid, float val)
                boost::shared_ptr<Amp> a = s->amp();
 
                if (a) {
-                       a->set_gain (dB_to_coefficient (val), this);
+                       a->gain_control()->set_value (dB_to_coefficient (val), PBD::Controllable::NoGroup);
                }
        }
        return 0;