summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2015-06-01 21:27:14 +0200
committerRobin Gareus <robin@gareus.org>2015-06-02 01:01:23 +0200
commitdd07428c48bb4df60b9d0c6c3cd524279ab4e524 (patch)
tree0f1430842bbd01a76d2fb2d9a475bdcff2693646
parent42915c19a494d049457df4a473ae436ccdffa847 (diff)
properly handle integer steps in plugin controls
The integer steps min/max are inclusive. e.g the integer range -1 to +1 has three possible values (not two).
-rw-r--r--libs/ardour/ardour/automation_control.h3
-rw-r--r--libs/ardour/ardour/plugin_insert.h3
-rw-r--r--libs/ardour/automation_control.cc46
-rw-r--r--libs/ardour/plugin_insert.cc32
4 files changed, 49 insertions, 35 deletions
diff --git a/libs/ardour/ardour/automation_control.h b/libs/ardour/ardour/automation_control.h
index e489d701e7..24a9e0de3e 100644
--- a/libs/ardour/ardour/automation_control.h
+++ b/libs/ardour/ardour/automation_control.h
@@ -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; }
diff --git a/libs/ardour/ardour/plugin_insert.h b/libs/ardour/ardour/plugin_insert.h
index c1bf0f18e5..e01f56d8bf 100644
--- a/libs/ardour/ardour/plugin_insert.h
+++ b/libs/ardour/ardour/plugin_insert.h
@@ -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;
};
diff --git a/libs/ardour/automation_control.cc b/libs/ardour/automation_control.cc
index bfa16f9e4a..21952038cf 100644
--- a/libs/ardour/automation_control.cc
+++ b/libs/ardour/automation_control.cc
@@ -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;
+}
+
+
diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc
index 2d53659905..8da0abb00f 100644
--- a/libs/ardour/plugin_insert.cc
+++ b/libs/ardour/plugin_insert.cc
@@ -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 ()
{