summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-06-02 11:40:01 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-06-02 11:40:01 +0000
commit3012d86672876734f7e25bd3411ba323c221ead6 (patch)
tree8f93edee147812c03780be119e7814c3b71ab032
parent4175a9bfb5073d9c7491613e1807b35c4fd0810b (diff)
specialize ConfigVariable<bool> to use string_is_affirmative() and thus get consistency about how XML state is interpreted when setting *all* Configuration variables
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@7204 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--libs/ardour/ardour/configuration_variable.h98
-rw-r--r--libs/ardour/ardour/utils.h6
2 files changed, 103 insertions, 1 deletions
diff --git a/libs/ardour/ardour/configuration_variable.h b/libs/ardour/ardour/configuration_variable.h
index fa149672be..c9b9890c81 100644
--- a/libs/ardour/ardour/configuration_variable.h
+++ b/libs/ardour/ardour/configuration_variable.h
@@ -25,6 +25,8 @@
#include <pbd/xml++.h>
+#include "ardour/utils.h"
+
namespace ARDOUR {
class ConfigVariableBase {
@@ -157,6 +159,102 @@ class ConfigVariable : public ConfigVariableBase
T value;
};
+/* full specialization for bool, required because ::set_from_node() needs
+ special handling.
+*/
+
+template<>
+class ConfigVariable<bool> : public ConfigVariableBase
+{
+ public:
+ ConfigVariable (std::string str) : ConfigVariableBase (str), value (false) {}
+ ConfigVariable (std::string str, bool val) : ConfigVariableBase (str), value (val) {}
+
+ virtual bool set (bool val, Owner owner) {
+ if (val == value) {
+ miss ();
+ return false;
+ }
+ value = val;
+ _owner = (ConfigVariableBase::Owner)(_owner |owner);
+ notify ();
+ return true;
+ }
+
+ bool get() const {
+ return value;
+ }
+
+ void add_to_node (XMLNode& node) {
+ XMLNode* child = new XMLNode ("Option");
+ child->add_property ("name", _name);
+ child->add_property ("value", (value ? "yes" : "no"));
+ node.add_child_nocopy (*child);
+ }
+
+ bool set_from_node (const XMLNode& node, Owner owner) {
+
+ if (node.name() == "Config") {
+
+ /* ardour.rc */
+
+ const XMLProperty* prop;
+ XMLNodeList nlist;
+ XMLNodeConstIterator niter;
+ XMLNode* child;
+
+ nlist = node.children();
+
+ for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
+
+ child = *niter;
+
+ if (child->name() == "Option") {
+ if ((prop = child->property ("name")) != 0) {
+ if (prop->value() == _name) {
+ if ((prop = child->property ("value")) != 0) {
+ value = ::string_is_affirmative (prop->value());
+ _owner = (ConfigVariableBase::Owner)(_owner |owner);
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ } else if (node.name() == "Options") {
+
+ /* session file */
+
+ XMLNodeList olist;
+ XMLNodeConstIterator oiter;
+ XMLNode* option;
+ const XMLProperty* opt_prop;
+
+ olist = node.children();
+
+ for (oiter = olist.begin(); oiter != olist.end(); ++oiter) {
+
+ option = *oiter;
+
+ if (option->name() == _name) {
+ if ((opt_prop = option->property ("val")) != 0) {
+ value = ::string_is_affirmative (opt_prop->value());
+ _owner = (ConfigVariableBase::Owner)(_owner |owner);
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ protected:
+ virtual bool get_for_save() { return value; }
+ bool value;
+};
+
template<class T>
class ConfigVariableWithMutation : public ConfigVariable<T>
{
diff --git a/libs/ardour/ardour/utils.h b/libs/ardour/ardour/utils.h
index eccfc33d25..17ca139fb1 100644
--- a/libs/ardour/ardour/utils.h
+++ b/libs/ardour/ardour/utils.h
@@ -28,6 +28,11 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
+/* this needs to come before ardour.h, since it may include
+ headers that use this function.
+*/
+bool string_is_affirmative (const std::string& str);
+
#include "ardour.h"
class XMLNode;
@@ -37,7 +42,6 @@ Glib::ustring legalize_for_path (Glib::ustring);
void elapsed_time_to_str (char *buf, uint32_t seconds);
std::ostream& operator<< (std::ostream& o, const ARDOUR::BBT_Time& bbt);
XMLNode* find_named_node (const XMLNode& node, std::string name);
-bool string_is_affirmative (const std::string& str);
static inline float f_max(float x, float a) {
x -= a;