Switch to PBD control-math and prefer Controllable API
authorRobin Gareus <robin@gareus.org>
Sun, 18 Jun 2017 22:57:53 +0000 (00:57 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 21 Jun 2017 16:12:04 +0000 (18:12 +0200)
Note: Control-surfaces should always use interface_to_internal()
and internal_to_interface().

gtk2_ardour/gain_meter.cc
libs/ardour/gain_control.cc
libs/ardour/parameter_descriptor.cc
libs/surfaces/generic_midi/midicontrollable.cc
libs/surfaces/osc/osc.cc
libs/surfaces/osc/osc_cue_observer.cc
libs/surfaces/osc/osc_global_observer.cc
libs/surfaces/osc/osc_route_observer.cc
libs/surfaces/osc/osc_select_observer.cc

index f03a001b1ad04913bfa6846f41b62ec25f33d82d..9bc31e97608c4e574b9ecc577c3d63630501321b 100644 (file)
@@ -310,7 +310,7 @@ GainMeterBase::setup_gain_adjustment ()
                gain_adjustment.set_upper (GAIN_COEFF_UNITY);
                gain_adjustment.set_step_increment (dB_coeff_step(Config->get_max_gain()) / 10.0);
                gain_adjustment.set_page_increment (dB_coeff_step(Config->get_max_gain()));
-               gain_slider->set_default_value (gain_to_slider_position (GAIN_COEFF_UNITY));
+               gain_slider->set_default_value (gain_to_slider_position_with_max (GAIN_COEFF_UNITY, Config->get_max_gain()));
        } else {
                _data_type = DataType::MIDI;
                gain_adjustment.set_lower (0.0);
index 7b0f4e404c0d0c93d5d09e58a685b1858eef0d29..35f666bdf10c23222ed24e905b9d6e1491e8dee7 100644 (file)
@@ -50,7 +50,7 @@ double
 GainControl::internal_to_interface (double v) const
 {
        if (_desc.type == GainAutomation) {
-               return gain_to_slider_position (v);
+               return gain_to_slider_position_with_max (v, _desc.upper);
        } else {
                return (accurate_coefficient_to_dB (v) - lower_db) / range_db;
        }
@@ -60,7 +60,7 @@ double
 GainControl::interface_to_internal (double v) const
 {
        if (_desc.type == GainAutomation) {
-               return slider_position_to_gain (v);
+               return slider_position_to_gain_with_max (v, _desc.upper);
        } else {
                return dB_to_coefficient (lower_db + v * range_db);
        }
index 16c618dec62c2c1fede78f5c02e23a94ac609d5d..f6460a514efe96762f908016f32d7640a3b7f312 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <boost/algorithm/string.hpp>
 
+#include "pbd/control_math.h"
+
 #include "ardour/amp.h"
 #include "ardour/dB.h"
 #include "ardour/parameter_descriptor.h"
@@ -157,8 +159,8 @@ ParameterDescriptor::update_steps()
                /* dB_coeff_step gives a step normalized for [0, max_gain].  This is
                   like "slider position", so we convert from "slider position" to gain
                   to have the correct unit here. */
-               largestep = slider_position_to_gain(dB_coeff_step(upper));
-               step      = slider_position_to_gain(largestep / 10.0);
+               largestep = position_to_gain (dB_coeff_step(upper));
+               step      = position_to_gain (largestep / 10.0);
                smallstep = step;
        } else {
                /* note that LV2Plugin::get_parameter_descriptor ()
index 0a7caac3bc89bceae0cb9d399030ab440d8785e0..92c86d665c0fe3123163ef207b844a29b9859100 100644 (file)
 #include <iostream>
 
 #include "pbd/error.h"
-#include "pbd/xml++.h"
+#include "pbd/compose.h"
 #include "pbd/stacktrace.h"
 #include "pbd/types_convert.h"
-#include "pbd/compose.h"
+#include "pbd/xml++.h"
 
 #include "midi++/types.h" // Added by JE - 06-01-2009. All instances of 'byte' changed to 'MIDI::byte' (for clarification)
 #include "midi++/port.h"
@@ -36,7 +36,6 @@
 #include "ardour/automation_control.h"
 #include "ardour/controllable_descriptor.h"
 #include "ardour/midi_ui.h"
-#include "ardour/utils.h"
 #include "ardour/debug.h"
 
 #include "midicontrollable.h"
@@ -175,7 +174,7 @@ int
 MIDIControllable::control_to_midi (float val)
 {
        if (controllable->is_gain_like()) {
-               return gain_to_slider_position (val) * max_value_for_type ();
+               return controllable->internal_to_interface (val) * max_value_for_type ();
        }
 
        float control_min = controllable->lower ();
index ec4966c8c07c779dd4f86f788be58a068ca4d983..1e67d746ef26e4f477024dd334548386c36d9606 100644 (file)
@@ -28,6 +28,7 @@
 #include "pbd/gstdio_compat.h"
 #include <glibmm.h>
 
+#include "pbd/control_math.h"
 #include <pbd/convert.h>
 #include <pbd/pthread_utils.h>
 #include <pbd/file_utils.h>
@@ -586,7 +587,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/select/eq_q", "if", sel_eq_q);
                REGISTER_CALLBACK (serv, "/select/eq_shape", "if", sel_eq_shape);
 
-               /* These commands require the route index in addition to the arg; TouchOSC (et al) can't use these  */ 
+               /* These commands require the route index in addition to the arg; TouchOSC (et al) can't use these  */
                REGISTER_CALLBACK (serv, "/strip/mute", "ii", route_mute);
                REGISTER_CALLBACK (serv, "/strip/solo", "ii", route_solo);
                REGISTER_CALLBACK (serv, "/strip/solo_iso", "ii", route_solo_iso);
@@ -613,7 +614,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/strip/send/enable", "iif", route_set_send_enable);
                REGISTER_CALLBACK(serv, "/strip/name", "is", route_rename);
                REGISTER_CALLBACK(serv, "/strip/sends", "i", route_get_sends);
-               REGISTER_CALLBACK(serv, "/strip/receives", "i", route_get_receives);                
+               REGISTER_CALLBACK(serv, "/strip/receives", "i", route_get_receives);
                REGISTER_CALLBACK(serv, "/strip/plugin/list", "i", route_plugin_list);
                REGISTER_CALLBACK(serv, "/strip/plugin/descriptor", "ii", route_plugin_descriptor);
                REGISTER_CALLBACK(serv, "/strip/plugin/reset", "ii", route_plugin_reset);
@@ -2297,7 +2298,7 @@ OSC::master_set_fader (float position)
        if (!session) return -1;
        boost::shared_ptr<Stripable> s = session->master_out();
        if (s) {
-               s->gain_control()->set_value (slider_position_to_gain_with_max (position, 2.0), PBD::Controllable::NoGroup);
+               s->gain_control()->set_value (slider_position_to_gain_with_max (position, 2.0), PBD::Controllable::NoGroup); // XXX use interface_to_internal, unhardcode 2.0
        }
        return 0;
 }
@@ -2378,7 +2379,7 @@ OSC::monitor_set_fader (float position)
        if (!session) return -1;
        boost::shared_ptr<Stripable> s = session->monitor_out();
        if (s) {
-               s->gain_control()->set_value (slider_position_to_gain_with_max (position, 2.0), PBD::Controllable::NoGroup);
+               s->gain_control()->set_value (slider_position_to_gain_with_max (position, 2.0), PBD::Controllable::NoGroup); // XXX use internal_to_interface, unhardcode 2.0
        }
        return 0;
 }
@@ -2456,7 +2457,7 @@ OSC::route_get_sends(lo_message msg) {
                        lo_message_add_string(reply, isend->name().c_str());
                        lo_message_add_int32(reply, i);
                        boost::shared_ptr<Amp> a = isend->amp();
-                       lo_message_add_float(reply, gain_to_slider_position(a->gain_control()->get_value()));
+                       lo_message_add_float(reply, gain_to_position(a->gain_control()->get_value())); // XXX use internal_to_interface
                        lo_message_add_int32(reply, p->active() ? 1 : 0);
                }
        }
@@ -2516,7 +2517,7 @@ OSC::route_get_receives(lo_message msg) {
                                        lo_message_add_int32(reply, get_sid(tr, get_address(msg)));
                                        lo_message_add_string(reply, tr->name().c_str());
                                        lo_message_add_int32(reply, j);
-                                       lo_message_add_float(reply, gain_to_slider_position(a->gain_control()->get_value()));
+                                       lo_message_add_float(reply, gain_to_position(a->gain_control()->get_value())); // XXX use internal_to_interface
                                        lo_message_add_int32(reply, p->active() ? 1 : 0);
                                }
                        }
@@ -3285,7 +3286,7 @@ OSC::route_set_gain_fader (int ssid, float pos, lo_message msg)
                return -1;
        }
        int ret;
-       ret = route_set_gain_abs (ssid, slider_position_to_gain_with_max (pos, 2.0), msg);
+       ret = route_set_gain_abs (ssid, slider_position_to_gain_with_max (pos, 2.0), msg); // XXX use interface_to_internal, unhardcode 2.0
        if (ret != 0) {
                return route_send_fail ("fader", ssid, 0, get_address (msg));
        }
@@ -3304,7 +3305,7 @@ OSC::sel_fader (float val, lo_message msg)
        }
        if (s) {
                float abs;
-               abs = slider_position_to_gain_with_max (val, 2.0);
+               abs = slider_position_to_gain_with_max (val, 2.0); // XXX use interface_to_internal, unhardcode 2.0
                if (s->gain_control()) {
                        fake_touch (s->gain_control());
                        s->gain_control()->set_value (abs, PBD::Controllable::NoGroup);
@@ -3479,7 +3480,7 @@ OSC::route_set_send_fader (int ssid, int id, float val, lo_message msg)
 #ifdef MIXBUS
                        abs = s->send_level_controllable(id)->interface_to_internal (val);
 #else
-                       abs = slider_position_to_gain_with_max (val, 2.0);
+                       abs = slider_position_to_gain_with_max (val, 2.0); // XXX use interface_to_internal, unhardcode 2.0
 #endif
                        s->send_level_controllable (id)->set_value (abs, PBD::Controllable::NoGroup);
                        return 0;
@@ -3555,7 +3556,7 @@ OSC::sel_sendfader (int id, float val, lo_message msg)
 #ifdef MIXBUS
                        abs = s->send_level_controllable(send_id)->interface_to_internal (val);
 #else
-                       abs = slider_position_to_gain_with_max (val, 2.0);
+                       abs = slider_position_to_gain_with_max (val, 2.0); // XXX interface_to_internal, unhardcode 2.0
 #endif
                        s->send_level_controllable (send_id)->set_value (abs, PBD::Controllable::NoGroup);
                        return 0;
@@ -5005,7 +5006,7 @@ OSC::cue_aux_fader (float position, lo_message msg)
 
                        if (s) {
                                float abs;
-                               abs = slider_position_to_gain_with_max (position, 2.0);
+                               abs = slider_position_to_gain_with_max (position, 2.0); // XXX use interface_to_internal, unhardcode 2.0
                                if (s->gain_control()) {
                                        s->gain_control()->set_value (abs, PBD::Controllable::NoGroup);
                                        return 0;
@@ -5048,7 +5049,7 @@ OSC::cue_send_fader (uint32_t id, float val, lo_message msg)
        float abs;
        if (s) {
                if (s->gain_control()) {
-                       abs = slider_position_to_gain_with_max (val, 2.0);
+                       abs = slider_position_to_gain_with_max (val, 2.0); // XXX use interface_to_internal, unhardcode 2.0
                        s->gain_control()->set_value (abs, PBD::Controllable::NoGroup);
                        return 0;
                }
index 40f97d7c3bd91b218d42b6a91c4090a927fd65f1..727eb8d37b2f5fcba6934968c3101f13d5a1c40d 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "boost/lambda/lambda.hpp"
 
+#include "pbd/control_math.h"
+
 #include "ardour/track.h"
 #include "ardour/dB.h"
 #include "ardour/meter.h"
@@ -221,7 +223,7 @@ OSCCueObserver::send_gain_message (uint32_t id,  boost::shared_ptr<Controllable>
                path = string_compose ("%1/%2", path, id);
        }
        lo_message msg = lo_message_new ();
-       lo_message_add_float (msg, gain_to_slider_position (controllable->get_value()));
+       lo_message_add_float (msg, gain_to_position (controllable->get_value())); // XXX use internal_to_interface
        gain_timeout[id] = 8;
 
        lo_send_message (addr, path.c_str(), msg);
index d73fd1a043437b52c030ee7c687ad3a2af009d2c..5f5632b2a4cbaa1010436b0a61bf2e312559408f 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "boost/lambda/lambda.hpp"
 
+#include "pbd/control_math.h"
+
 #include "ardour/session.h"
 #include "ardour/dB.h"
 #include "ardour/meter.h"
@@ -259,7 +261,7 @@ void
 OSCGlobalObserver::send_gain_message (string path, boost::shared_ptr<Controllable> controllable)
 {
        if (gainmode) {
-               float_message (string_compose ("%1fader", path), gain_to_slider_position (controllable->get_value()));
+               float_message (string_compose ("%1fader", path), gain_to_position (controllable->get_value())); // XXX use internal_to_interface
                text_message (string_compose ("%1name", path), string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())));
                if (path.find("master") != std::string::npos) {
                        master_timeout = 8;
index c33ad7cc2bf0f831c10cc8f9517e5d6fbc0ab6df..9075737b374f09b456caf942424874fab125e569 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "boost/lambda/lambda.hpp"
 
+#include "pbd/control_math.h"
+
 #include "ardour/session.h"
 #include "ardour/track.h"
 #include "ardour/monitor_control.h"
@@ -358,7 +360,7 @@ OSCRouteObserver::send_gain_message (string path, boost::shared_ptr<Controllable
        }
 
        if (gainmode) {
-               lo_message_add_float (msg, gain_to_slider_position (controllable->get_value()));
+               lo_message_add_float (msg, gain_to_position (controllable->get_value())); // XXX use internal_to_interface
                text_with_id ("/strip/name", ssid, string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())));
                gain_timeout = 8;
        } else {
index 66974c75c806c650dee75e7bae3876fc9c99eacf..84388478960829672d2bf8522c99a2aa7e5dcab0 100644 (file)
@@ -20,6 +20,8 @@
 #include <vector>
 #include "boost/lambda/lambda.hpp"
 
+#include "pbd/control_math.h"
+
 #include "ardour/session.h"
 #include "ardour/track.h"
 #include "ardour/monitor_control.h"
@@ -634,7 +636,7 @@ OSCSelectObserver::gain_message ()
        if (gainmode) {
                text_message ("/select/name", string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (value)));
                gain_timeout = 8;
-               send_float ("/select/fader", gain_to_slider_position (value));
+               send_float ("/select/fader", gain_to_position (value)); // XXX use internal_to_interface
        } else {
                if (value < 1e-15) {
                        send_float ("/select/gain", -200);
@@ -704,7 +706,7 @@ OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable>
 #ifdef MIXBUS
                value = controllable->internal_to_interface (controllable->get_value());
 #else
-               value = gain_to_slider_position (controllable->get_value());
+               value = gain_to_position (controllable->get_value()); // XXX use internal_to_interface
 #endif
        text_with_id ("/select/send_name" , id, string_compose ("%1%2%3", std::fixed, std::setprecision(2), db));
        if (send_timeout.size() > id) {