variable name change: percent is 0..100, 0..1.0 is a fraction
[ardour.git] / libs / pbd / pbd / controllable.h
index eb4b7ff14291c00df03b9b1c7b42720d28371a55..2dfe7d8785389f469cac07817a9dac4b5d014248 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000-2007 Paul Davis 
+    Copyright (C) 2000-2007 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -30,6 +30,9 @@
 
 #include "pbd/statefuldestructible.h"
 
+using std::min;
+using std::max;
+
 class XMLNode;
 
 namespace PBD {
@@ -60,11 +63,25 @@ class LIBPBD_API Controllable : public PBD::StatefulDestructible {
         * but passed to the processor as a linear quantity.
         */
 
-       /** Set `internal' value */
+       /** Get and Set `internal' value */
        virtual void set_value (double) = 0;
-       /** @return `internal' value */
        virtual double get_value (void) const = 0;
 
+       /** Conversions between `internal', 'interface', and 'user' values */
+       virtual double internal_to_interface (double i) const {return  (i-lower())/(upper() - lower());}  //by default, the interface range is just a linear interpolation between lower and upper values
+       virtual double interface_to_internal (double i) const {return lower() + i*(upper() - lower());}
+       virtual double internal_to_user (double i) const {return i;}  //by default the internal value is the same as the user value
+       virtual double user_to_internal (double i) const {return i;}  //by default the internal value is the same as the user value
+
+       /** Get and Set `interface' value  (typically, fraction of knob travel) */
+       virtual float get_interface() const { return (internal_to_interface(get_value())); }
+       virtual void set_interface (float fraction) { fraction = min( max(0.0f, fraction), 1.0f);  set_value(interface_to_internal(fraction)); }
+
+       /** Get and Set `user' value  ( dB or milliseconds, etc.  This MIGHT be the same as the internal value, but in a few cases it is not ) */
+       virtual float get_user() const { return (internal_to_user(get_value())); }
+       virtual void set_user (float user_v) { set_value(user_to_internal(user_v)); }
+       virtual std::string get_user_string() const { return std::string(); }
+
        PBD::Signal0<void> LearningFinished;
        static PBD::Signal3<void,PBD::Controllable*,int,int> CreateBinding;
        static PBD::Signal1<void,PBD::Controllable*> DeleteBinding;
@@ -73,7 +90,7 @@ class LIBPBD_API Controllable : public PBD::StatefulDestructible {
        static PBD::Signal1<void,PBD::Controllable*> StopLearning;
 
        static PBD::Signal1<void,Controllable*> Destroyed;
-       
+
        PBD::Signal0<void> Changed;
 
        int set_state (const XMLNode&, int version);
@@ -89,6 +106,7 @@ class LIBPBD_API Controllable : public PBD::StatefulDestructible {
 
         virtual double lower() const { return 0.0; }
         virtual double upper() const { return 1.0; }
+        virtual double normal() const { return 0.0; }  //the default value
 
        Flag flags() const { return _flags; }
        void set_flags (Flag f);
@@ -99,6 +117,8 @@ class LIBPBD_API Controllable : public PBD::StatefulDestructible {
   private:
        std::string _name;
 
+       std::string _units;
+
        Flag        _flags;
        bool        _touching;
 
@@ -114,12 +134,12 @@ class LIBPBD_API Controllable : public PBD::StatefulDestructible {
    a Controllable
 */
 
-class LIBPBD_API IgnorableControllable : public Controllable 
+class LIBPBD_API IgnorableControllable : public Controllable
 {
-  public: 
+  public:
        IgnorableControllable () : PBD::Controllable ("ignoreMe") {}
        ~IgnorableControllable () {}
-    
+
        void set_value (double /*v*/) {}
        double get_value () const { return 0.0; }
 };