Amp control: power-scale (fader) and dB-scale (knob)
authorRobin Gareus <robin@gareus.org>
Fri, 24 Apr 2015 19:44:52 +0000 (21:44 +0200)
committerRobin Gareus <robin@gareus.org>
Fri, 24 Apr 2015 20:37:03 +0000 (22:37 +0200)
libs/ardour/amp.cc
libs/ardour/ardour/amp.h

index ac970fc581562b060cace450b9e88ee04e172ffe..f2381cdefb5c631f15fb48316e6a537810b65fbc 100644 (file)
 
 using namespace ARDOUR;
 using namespace PBD;
-using std::min;
 
-Amp::Amp (Session& s)
+Amp::Amp (Session& s, std::string type)
        : Processor(s, "Amp")
        , _apply_gain(true)
        , _apply_gain_automation(false)
        , _current_gain(GAIN_COEFF_UNITY)
        , _current_automation_frame (INT64_MAX)
        , _gain_automation_buffer(0)
+       , _type(type)
 {
-       Evoral::Parameter p (GainAutomation);
+       Evoral::Parameter p (_type == "trim" ? TrimAutomation : GainAutomation);
        boost::shared_ptr<AutomationList> gl (new AutomationList (p));
        _gain_control = boost::shared_ptr<GainControl> (new GainControl (X_("gaincontrol"), s, this, p, gl));
        _gain_control->set_flags (Controllable::GainLike);
@@ -351,7 +351,7 @@ XMLNode&
 Amp::state (bool full_state)
 {
        XMLNode& node (Processor::state (full_state));
-       node.add_property("type", "amp");
+       node.add_property("type", _type);
         node.add_child_nocopy (_gain_control->get_state());
 
        return node;
@@ -374,20 +374,28 @@ Amp::set_state (const XMLNode& node, int version)
 void
 Amp::GainControl::set_value (double val)
 {
-       AutomationControl::set_value (min (val, (double) Config->get_max_gain()));
+       AutomationControl::set_value (std::max (std::min (val, (double)_desc.upper), (double)_desc.lower));
        _amp->session().set_dirty ();
 }
 
 double
 Amp::GainControl::internal_to_interface (double v) const
 {
-       return gain_to_slider_position (v);
+       if (_desc.type == GainAutomation) {
+               return gain_to_slider_position (v);
+       } else {
+               return (accurate_coefficient_to_dB (v) - lower_db) / range_db;
+       }
 }
 
 double
 Amp::GainControl::interface_to_internal (double v) const
 {
-       return slider_position_to_gain (v);
+       if (_desc.type == GainAutomation) {
+               return slider_position_to_gain (v);
+       } else {
+               return dB_to_coefficient (lower_db + v * range_db);
+       }
 }
 
 double
index 5bfcf1d3111566d1ba260acabea5d115f6ba7ca6..7a24e69edb8212984fc9c51491c16251c604a1c9 100644 (file)
@@ -19,6 +19,7 @@
 #ifndef __ardour_amp_h__
 #define __ardour_amp_h__
 
+#include "ardour/dB.h"
 #include "ardour/libardour_visibility.h"
 #include "ardour/types.h"
 #include "ardour/chan_count.h"
@@ -35,7 +36,7 @@ class IO;
  */
 class LIBARDOUR_API Amp : public Processor {
 public:
-       Amp(Session& s);
+       Amp(Session& s, std::string type = "amp");
 
        std::string display_name() const;
 
@@ -83,6 +84,9 @@ public:
                        , _amp (a) {
                        set_flags (Controllable::Flag (flags() | Controllable::GainLike));
                        alist()->reset_default (1.0);
+
+                       lower_db = accurate_coefficient_to_dB (_desc.lower);
+                       range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db;
                }
 
                void set_value (double val);
@@ -94,6 +98,8 @@ public:
                std::string get_user_string () const;
 
                Amp* _amp;
+               double lower_db;
+               double range_db;
        };
 
        boost::shared_ptr<GainControl> gain_control() {
@@ -117,6 +123,7 @@ private:
 
        /** Buffer that we should use for gain automation */
        gain_t* _gain_automation_buffer;
+       std::string _type;
 };