Use XMLProperty::get/set_property API in CC121 Surface module
authorTim Mayberry <mojofunk@gmail.com>
Wed, 7 Dec 2016 05:48:57 +0000 (15:48 +1000)
committerTim Mayberry <mojofunk@gmail.com>
Tue, 18 Apr 2017 23:36:54 +0000 (09:36 +1000)
libs/surfaces/cc121/cc121.cc

index 241abb1518e2d05b6e575d610699eaa09901bee6..3f563db2512b8f3e4b40c6f1b279aed27ae70b65 100644 (file)
@@ -778,13 +778,12 @@ CC121::set_state (const XMLNode& node, int version)
 
        for (XMLNodeList::const_iterator n = node.children().begin(); n != node.children().end(); ++n) {
                if ((*n)->name() == X_("Button")) {
-                       XMLProperty const * prop = (*n)->property (X_("id"));
-                       if (!prop) {
+                       int32_t xid;
+                       if (!node.get_property ("id", xid)) {
                                continue;
                        }
-                       int xid = atoi (prop->value());
                        ButtonMap::iterator b = buttons.find (ButtonID (xid));
-                       if (b == buttons.end()) {
+                       if (b == buttons.end ()) {
                                continue;
                        }
                        b->second.set_state (**n);
@@ -979,13 +978,8 @@ CC121::Button::set_led_state (boost::shared_ptr<MIDI::Port> port, bool onoff)
 int
 CC121::Button::set_state (XMLNode const& node)
 {
-       const XMLProperty* prop = node.property ("id");
-       if (!prop) {
-               return -1;
-       }
-
-       int xid = atoi (prop->value());
-       if (xid != id) {
+       int32_t xid;
+       if (node.get_property ("id", xid) && xid != id) {
                return -1;
        }
 
@@ -995,16 +989,17 @@ CC121::Button::set_state (XMLNode const& node)
        state_pairs.push_back (make_pair (string ("plain"), ButtonState (0)));
 
        for (vector<state_pair_t>::const_iterator sp = state_pairs.begin(); sp != state_pairs.end(); ++sp) {
-               string propname;
+               string prop_name;
+               string prop_value;
 
-               propname = sp->first + X_("-press");
-               if ((prop = node.property (propname)) != 0) {
-                       set_action (prop->value(), true, sp->second);
+               prop_name = sp->first + X_("-press");
+               if (node.get_property (prop_name.c_str(), prop_value)) {
+                       set_action (prop_value, true, sp->second);
                }
 
-               propname = sp->first + X_("-release");
-               if ((prop = node.property (propname)) != 0) {
-                       set_action (prop->value(), false, sp->second);
+               prop_name = sp->first + X_("-release");
+               if (node.get_property (prop_name.c_str(), prop_value)) {
+                       set_action (prop_value, false, sp->second);
                }
        }
 
@@ -1015,10 +1010,8 @@ XMLNode&
 CC121::Button::get_state () const
 {
        XMLNode* node = new XMLNode (X_("Button"));
-       char buf[16];
-       snprintf (buf, sizeof (buf), "%d", id);
 
-       node->add_property (X_("id"), buf);
+       node->set_property (X_("id"), (int32_t)id);
 
        ToDoMap::const_iterator x;
        ToDo null;
@@ -1032,13 +1025,13 @@ CC121::Button::get_state () const
        for (vector<state_pair_t>::const_iterator sp = state_pairs.begin(); sp != state_pairs.end(); ++sp) {
                if ((x = on_press.find (sp->second)) != on_press.end()) {
                        if (x->second.type == NamedAction) {
-                               node->add_property (string (sp->first + X_("-press")).c_str(), x->second.action_name);
+                               node->set_property (string (sp->first + X_("-press")).c_str(), x->second.action_name);
                        }
                }
 
                if ((x = on_release.find (sp->second)) != on_release.end()) {
                        if (x->second.type == NamedAction) {
-                               node->add_property (string (sp->first + X_("-release")).c_str(), x->second.action_name);
+                               node->set_property (string (sp->first + X_("-release")).c_str(), x->second.action_name);
                        }
                }
        }