properly handle integer steps in plugin controls
authorRobin Gareus <robin@gareus.org>
Mon, 1 Jun 2015 19:27:14 +0000 (21:27 +0200)
committerRobin Gareus <robin@gareus.org>
Mon, 1 Jun 2015 23:01:23 +0000 (01:01 +0200)
The integer steps min/max are inclusive.
e.g the integer range -1 to +1 has three possible values (not two).

libs/ardour/ardour/automation_control.h
libs/ardour/ardour/plugin_insert.h
libs/ardour/automation_control.cc
libs/ardour/plugin_insert.cc

index e489d701e714d8bab8e1fdca6c0e0067c88041e6..24a9e0de3ee84fd497afad4abbf006d52c65f904 100644 (file)
@@ -89,6 +89,9 @@ public:
        double normal()  const { return _desc.normal; }
        bool   toggled() const { return _desc.toggled; }
 
+       double internal_to_interface (double i) const;
+       double interface_to_internal (double i) const;
+
        const ParameterDescriptor& desc() const { return _desc; }
 
        const ARDOUR::Session& session() const { return _session; }
index c1bf0f18e51270016a4fcf7d5fc8c1a4f50cc3c8..e01f56d8bfbf630322f842181805592f321a3b49 100644 (file)
@@ -97,9 +97,6 @@ class LIBARDOUR_API PluginInsert : public Processor
                double get_value (void) const;
                XMLNode& get_state();
 
-               double internal_to_interface (double) const;
-               double interface_to_internal (double) const;
-
        private:
                PluginInsert* _plugin;
        };
index bfa16f9e4aec743c9109721b6ac7293b34f4efce..21952038cfc180a467b1c56141afbd675e9d6ee2 100644 (file)
@@ -139,3 +139,49 @@ AutomationControl::stop_touch(bool mark, double when)
                }
        }
 }
+
+double
+AutomationControl::internal_to_interface (double val) const
+{
+       if (_desc.integer_step) {
+               // both upper and lower are inclusive.
+               val =  (val - lower()) / (1 + upper() - lower());
+       } else {
+               val =  (val - lower()) / (upper() - lower());
+       }
+
+       if (_desc.logarithmic) {
+               if (val > 0) {
+                       val = pow (val, 1/1.5);
+               } else {
+                       val = 0;
+               }
+       }
+
+       return val;
+}
+
+double
+AutomationControl::interface_to_internal (double val) const
+{
+       if (_desc.logarithmic) {
+               if (val <= 0) {
+                       val = 0;
+               } else {
+                       val = pow (val, 1.5);
+               }
+       }
+
+       if (_desc.integer_step) {
+               val =  lower() + val * (1 + upper() - lower());
+       } else {
+               val =  lower() + val * (upper() - lower());
+       }
+
+       if (val < lower()) val = lower();
+       if (val > upper()) val = upper();
+
+       return val;
+}
+
+
index 2d53659905d6bd326c7102f7360ae884ce4c1dca..8da0abb00fac440f58630e57eb383c7d96342449 100644 (file)
@@ -1296,38 +1296,6 @@ PluginInsert::PluginControl::set_value (double user_val)
        AutomationControl::set_value (user_val);
 }
 
-double
-PluginInsert::PluginControl::internal_to_interface (double val) const
-{
-       val = Controllable::internal_to_interface(val);
-       
-       if (_desc.logarithmic) {
-               if (val > 0) {
-                       val = pow (val, 1/1.5);
-               } else {
-                       val = 0;
-               }
-       }
-
-       return val;
-}
-
-double
-PluginInsert::PluginControl::interface_to_internal (double val) const
-{
-       if (_desc.logarithmic) {
-               if (val <= 0) {
-                       val = 0;
-               } else {
-                       val = pow (val, 1.5);
-               }
-       }
-
-       val = Controllable::interface_to_internal(val);
-       
-       return val;
-}
-
 XMLNode&
 PluginInsert::PluginControl::get_state ()
 {