Use XMLNode::get/set_property API in MIDIControllable class

This commit is contained in:
Tim Mayberry 2016-08-30 10:57:18 +10:00
parent 3be0170e82
commit f82cb87f0c

View file

@ -25,6 +25,7 @@
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/xml++.h" #include "pbd/xml++.h"
#include "pbd/stacktrace.h" #include "pbd/stacktrace.h"
#include "pbd/types_convert.h"
#include "pbd/compose.h" #include "pbd/compose.h"
#include "midi++/types.h" // Added by JE - 06-01-2009. All instances of 'byte' changed to 'MIDI::byte' (for clarification) #include "midi++/types.h" // Added by JE - 06-01-2009. All instances of 'byte' changed to 'MIDI::byte' (for clarification)
@ -719,25 +720,24 @@ MIDIControllable::write_feedback (MIDI::byte* buf, int32_t& bufsize, bool /*forc
int int
MIDIControllable::set_state (const XMLNode& node, int /*version*/) MIDIControllable::set_state (const XMLNode& node, int /*version*/)
{ {
const XMLProperty* prop;
int xx; int xx;
if ((prop = node.property ("event")) != 0) { std::string str;
sscanf (prop->value().c_str(), "0x%x", &xx); if (node.get_property ("event", str)) {
sscanf (str.c_str(), "0x%x", &xx);
control_type = (MIDI::eventType) xx; control_type = (MIDI::eventType) xx;
} else { } else {
return -1; return -1;
} }
if ((prop = node.property ("channel")) != 0) { if (node.get_property ("channel", xx)) {
sscanf (prop->value().c_str(), "%d", &xx); control_channel = xx;
control_channel = (MIDI::channel_t) xx;
} else { } else {
return -1; return -1;
} }
if ((prop = node.property ("additional")) != 0) { if (node.get_property ("additional", str)) {
sscanf (prop->value().c_str(), "0x%x", &xx); sscanf (str.c_str(), "0x%x", &xx);
control_additional = (MIDI::byte) xx; control_additional = (MIDI::byte) xx;
} else { } else {
return -1; return -1;
@ -756,18 +756,17 @@ MIDIControllable::get_state ()
XMLNode* node = new XMLNode ("MIDIControllable"); XMLNode* node = new XMLNode ("MIDIControllable");
if (_current_uri.empty()) { if (_current_uri.empty()) {
node->add_property ("id", controllable->id().to_s()); node->set_property ("id", controllable->id ());
} else { } else {
node->add_property ("uri", _current_uri); node->set_property ("uri", _current_uri);
} }
if (controllable) { if (controllable) {
snprintf (buf, sizeof(buf), "0x%x", (int) control_type); snprintf (buf, sizeof(buf), "0x%x", (int) control_type);
node->add_property ("event", buf); node->set_property ("event", (const char *)buf);
snprintf (buf, sizeof(buf), "%d", (int) control_channel); node->set_property ("channel", (int16_t)control_channel);
node->add_property ("channel", buf);
snprintf (buf, sizeof(buf), "0x%x", (int) control_additional); snprintf (buf, sizeof(buf), "0x%x", (int) control_additional);
node->add_property ("additional", buf); node->set_property ("additional", (const char *)buf);
} }
return *node; return *node;