summaryrefslogtreecommitdiff
path: root/libs/ardour/parameter_descriptor.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-06-20 23:41:05 +0200
committerRobin Gareus <robin@gareus.org>2017-06-21 18:12:55 +0200
commit16624f31391bae51db770a9e9bd8899e7746b068 (patch)
tree226a06a506befb9a4a6d426e5db2eeb26f37dc36 /libs/ardour/parameter_descriptor.cc
parent37905d82a611a09342faf52d01378c9b4e86a2ac (diff)
Add API to compute parameter delta, depending on AutomationType
Diffstat (limited to 'libs/ardour/parameter_descriptor.cc')
-rw-r--r--libs/ardour/parameter_descriptor.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/libs/ardour/parameter_descriptor.cc b/libs/ardour/parameter_descriptor.cc
index 7ed0c78512..a63c90d1db 100644
--- a/libs/ardour/parameter_descriptor.cc
+++ b/libs/ardour/parameter_descriptor.cc
@@ -354,4 +354,43 @@ ParameterDescriptor::from_interface (float val) const
return val;
}
+bool
+ParameterDescriptor::is_linear () const
+{
+ if (logarithmic) {
+ return false;
+ }
+ switch(type) {
+ case GainAutomation:
+ case EnvelopeAutomation:
+ case BusSendLevel:
+ return false;
+ default:
+ break;
+ }
+ return true;
+}
+
+float
+ParameterDescriptor::compute_delta (float from, float to) const
+{
+ if (is_linear ()) {
+ return to - from;
+ }
+ if (from == 0) {
+ return 0;
+ }
+ return to / from;
+}
+
+float
+ParameterDescriptor::apply_delta (float val, float delta) const
+{
+ if (is_linear ()) {
+ return val + delta;
+ } else {
+ return val * delta;
+ }
+}
+
} // namespace ARDOUR