add new API to PBD::Controllable, ::get_save_value()
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 6 Feb 2017 15:41:15 +0000 (16:41 +0100)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 6 Feb 2017 15:49:08 +0000 (16:49 +0100)
Designed to allow derived classes to *save* a different value
than would be reported by ::get_value().

Specifically there so that slaved controls can save/restore
their *own* state, not the value that ::get_value() would
return.

libs/pbd/controllable.cc
libs/pbd/pbd/controllable.h

index b730a42980ffa08b05b8ec3390c22690113088c5..5f7350da63659cc0a1421b32da7aec9204dbe840 100644 (file)
@@ -124,7 +124,7 @@ Controllable::get_state ()
        id().print (buf, sizeof (buf));
        node->add_property (X_("id"), buf);
        node->add_property (X_("flags"), enum_2_string (_flags));
-       snprintf (buf, sizeof (buf), "%2.12f", get_value());
+       snprintf (buf, sizeof (buf), "%2.12f", get_save_value());
         node->add_property (X_("value"), buf);
 
        if (_extra_xml) {
@@ -134,7 +134,6 @@ Controllable::get_state ()
        return *node;
 }
 
-
 int
 Controllable::set_state (const XMLNode& node, int /*version*/)
 {
index 51aa28a4fe7c9b8a1f40ccd952c72fefbe04e110..3b416b07fda7e6eb281041bfa37e9ca3218a7240 100644 (file)
@@ -104,6 +104,13 @@ class LIBPBD_API Controllable : public PBD::StatefulDestructible {
         virtual void set_value (double, GroupControlDisposition group_override) = 0;
        virtual double get_value (void) const = 0;
 
+       /** This is used when saving state. By default it just calls
+        * get_value(), but a class with more complex semantics might override
+        * this to save some value that differs from what get_value() would 
+        * return.
+        */
+       virtual double get_save_value () const { return get_value(); }
+
        /** 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());}