13
0

Use XMLNode::get/set_property API in ARDOUR::AutomationList

This commit is contained in:
Tim Mayberry 2016-08-25 01:37:41 +10:00
parent 02c384d11e
commit c02729de52

View File

@ -26,10 +26,13 @@
#include "ardour/automation_list.h" #include "ardour/automation_list.h"
#include "ardour/event_type_map.h" #include "ardour/event_type_map.h"
#include "ardour/parameter_descriptor.h" #include "ardour/parameter_descriptor.h"
#include "ardour/evoral_types_convert.h"
#include "ardour/types_convert.h"
#include "evoral/Curve.hpp" #include "evoral/Curve.hpp"
#include "pbd/memento_command.h" #include "pbd/memento_command.h"
#include "pbd/stacktrace.h" #include "pbd/stacktrace.h"
#include "pbd/enumwriter.h" #include "pbd/enumwriter.h"
#include "pbd/types_convert.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
@ -302,41 +305,34 @@ XMLNode&
AutomationList::state (bool full) AutomationList::state (bool full)
{ {
XMLNode* root = new XMLNode (X_("AutomationList")); XMLNode* root = new XMLNode (X_("AutomationList"));
char buf[64];
LocaleGuard lg; LocaleGuard lg;
root->add_property ("automation-id", EventTypeMap::instance().to_symbol(_parameter)); root->set_property ("automation-id", EventTypeMap::instance().to_symbol(_parameter));
root->set_property ("id", id());
root->add_property ("id", id().to_s()); root->set_property ("default", _default_value);
root->set_property ("min-yval", _min_yval);
snprintf (buf, sizeof (buf), "%.12g", _default_value); root->set_property ("max-yval", _max_yval);
root->add_property ("default", buf); root->set_property ("interpolation-style", _interpolation);
snprintf (buf, sizeof (buf), "%.12g", _min_yval);
root->add_property ("min-yval", buf);
snprintf (buf, sizeof (buf), "%.12g", _max_yval);
root->add_property ("max-yval", buf);
root->add_property ("interpolation-style", enum_2_string (_interpolation));
if (full) { if (full) {
/* never serialize state with Write enabled - too dangerous /* never serialize state with Write enabled - too dangerous
for the user's data for the user's data
*/ */
if (_state != Write) { if (_state != Write) {
root->add_property ("state", auto_state_to_string (_state)); root->set_property ("state", _state);
} else { } else {
if (_events.empty ()) { if (_events.empty ()) {
root->add_property ("state", auto_state_to_string (Off)); root->set_property ("state", Off);
} else { } else {
root->add_property ("state", auto_state_to_string (Touch)); root->set_property ("state", Touch);
} }
} }
} else { } else {
/* never save anything but Off for automation state to a template */ /* never save anything but Off for automation state to a template */
root->add_property ("state", auto_state_to_string (Off)); root->set_property ("state", Off);
} }
root->add_property ("style", auto_style_to_string (_style)); root->set_property ("style", _style);
if (!_events.empty()) { if (!_events.empty()) {
root->add_child_nocopy (serialize_events()); root->add_child_nocopy (serialize_events());
@ -425,7 +421,6 @@ AutomationList::set_state (const XMLNode& node, int version)
XMLNodeList nlist = node.children(); XMLNodeList nlist = node.children();
XMLNode* nsos; XMLNode* nsos;
XMLNodeIterator niter; XMLNodeIterator niter;
XMLProperty const * prop;
if (node.name() == X_("events")) { if (node.name() == X_("events")) {
/* partial state setting*/ /* partial state setting*/
@ -443,26 +438,23 @@ AutomationList::set_state (const XMLNode& node, int version)
const XMLNodeList& elist = node.children(); const XMLNodeList& elist = node.children();
XMLNodeConstIterator i; XMLNodeConstIterator i;
XMLProperty const * prop;
pframes_t x;
double y;
ControlList::freeze (); ControlList::freeze ();
clear (); clear ();
for (i = elist.begin(); i != elist.end(); ++i) { for (i = elist.begin(); i != elist.end(); ++i) {
if ((prop = (*i)->property ("x")) == 0) { pframes_t x;
if (!(*i)->get_property ("x", x)) {
error << _("automation list: no x-coordinate stored for control point (point ignored)") << endmsg; error << _("automation list: no x-coordinate stored for control point (point ignored)") << endmsg;
continue; continue;
} }
x = atoi (prop->value().c_str());
if ((prop = (*i)->property ("y")) == 0) { double y;
if (!(*i)->get_property ("y", y)) {
error << _("automation list: no y-coordinate stored for control point (point ignored)") << endmsg; error << _("automation list: no y-coordinate stored for control point (point ignored)") << endmsg;
continue; continue;
} }
y = atof (prop->value().c_str());
fast_simple_add (x, y); fast_simple_add (x, y);
} }
@ -482,49 +474,39 @@ AutomationList::set_state (const XMLNode& node, int version)
AutomationListCreated(this); AutomationListCreated(this);
} }
if ((prop = node.property (X_("automation-id"))) != 0){ std::string value;
_parameter = EventTypeMap::instance().from_symbol(prop->value()); if (node.get_property (X_("automation-id"), value)) {
_parameter = EventTypeMap::instance().from_symbol(value);
} else { } else {
warning << "Legacy session: automation list has no automation-id property." << endmsg; warning << "Legacy session: automation list has no automation-id property." << endmsg;
} }
if ((prop = node.property (X_("interpolation-style"))) != 0) { if (!node.get_property (X_("interpolation-style"), _interpolation)) {
_interpolation = (InterpolationStyle)string_2_enum(prop->value(), _interpolation);
} else {
_interpolation = Linear; _interpolation = Linear;
} }
if ((prop = node.property (X_("default"))) != 0){ if (!node.get_property (X_("default"), _default_value)) {
_default_value = atof (prop->value().c_str());
} else {
_default_value = 0.0; _default_value = 0.0;
} }
if ((prop = node.property (X_("style"))) != 0) { if (!node.get_property (X_("style"), _style)) {
_style = string_to_auto_style (prop->value());
} else {
_style = Absolute; _style = Absolute;
} }
if ((prop = node.property (X_("state"))) != 0) { if (node.get_property (X_("state"), _state)) {
_state = string_to_auto_state (prop->value()); if (_state == Write) {
if (_state == Write) { _state = Off;
_state = Off; }
} automation_state_changed (_state);
automation_state_changed(_state);
} else { } else {
_state = Off; _state = Off;
} }
if ((prop = node.property (X_("min-yval"))) != 0) { if (!node.get_property (X_("min-yval"), _min_yval)) {
_min_yval = atof (prop->value ().c_str());
} else {
_min_yval = FLT_MIN; _min_yval = FLT_MIN;
} }
if ((prop = node.property (X_("max-yval"))) != 0) { if (!node.get_property (X_("max-yval"), _max_yval)) {
_max_yval = atof (prop->value ().c_str());
} else {
_max_yval = FLT_MAX; _max_yval = FLT_MAX;
} }