more or less complete restoration of Controllable::_id from XML, with all that implie...
[ardour.git] / libs / pbd / controllable.cc
index 38780bddbe4ea64d8612731085fb1de01c121344..0112ff2b1ccabf76200fdcf30a94e24a196eeac9 100644 (file)
@@ -21,6 +21,7 @@
 #include "pbd/enumwriter.h"
 #include "pbd/xml++.h"
 #include "pbd/error.h"
+#include "pbd/locale_guard.h"
 
 #include "i18n.h"
 
@@ -36,6 +37,7 @@ PBD::Signal1<void,Controllable*> Controllable::DeleteBinding;
 Glib::StaticRWLock Controllable::registry_lock = GLIBMM_STATIC_RW_LOCK_INIT;
 Controllable::Controllables Controllable::registry;
 PBD::ScopedConnectionList registry_connections;
+const std::string Controllable::xml_node_name = X_("Controllable");
 
 Controllable::Controllable (const string& name, Flag f)
        : _name (name)
@@ -100,25 +102,29 @@ Controllable::by_name (const string& str)
 XMLNode&
 Controllable::get_state ()
 {
-       XMLNode* node = new XMLNode (X_("Controllable"));
+       XMLNode* node = new XMLNode (xml_node_name);
+       LocaleGuard lg (X_("POSIX"));
        char buf[64];
 
        node->add_property (X_("name"), _name); // not reloaded from XML state, just there to look at
        _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());
+        node->add_property (X_("value"), buf);
 
        return *node;
 }
 
+
 int
 Controllable::set_state (const XMLNode& node, int /*version*/)
 {
+       LocaleGuard lg (X_("POSIX"));
        const XMLProperty* prop;
 
        if ((prop = node.property (X_("id"))) != 0) {
                _id = prop->value();
-               return 0;
        } else {
                error << _("Controllable state node has no ID property") << endmsg;
                return -1;
@@ -127,6 +133,16 @@ Controllable::set_state (const XMLNode& node, int /*version*/)
        if ((prop = node.property (X_("flags"))) != 0) {
                _flags = (Flag) string_2_enum (prop->value(), _flags);
        }
+
+       if ((prop = node.property (X_("value"))) != 0) {
+               float val;
+
+               if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
+                       set_value (val);
+               } 
+        }
+
+        return 0;
 }
 
 void