summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/controllable.cc6
-rw-r--r--libs/pbd/id.cc10
-rw-r--r--libs/pbd/pbd/id.h2
-rw-r--r--libs/pbd/pbd/stateful.h9
-rw-r--r--libs/pbd/stateful.cc24
5 files changed, 43 insertions, 8 deletions
diff --git a/libs/pbd/controllable.cc b/libs/pbd/controllable.cc
index 959abe443d..51877ee206 100644
--- a/libs/pbd/controllable.cc
+++ b/libs/pbd/controllable.cc
@@ -107,7 +107,7 @@ Controllable::get_state ()
char buf[64];
node->add_property (X_("name"), _name); // not reloaded from XML state, just there to look at
- _id.print (buf, sizeof (buf));
+ 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());
@@ -129,9 +129,7 @@ Controllable::set_state (const XMLNode& node, int /*version*/)
Stateful::save_extra_xml (node);
- if ((prop = node.property (X_("id"))) != 0) {
- _id = prop->value();
- } else {
+ if (!set_id (node)) {
error << _("Controllable state node has no ID property") << endmsg;
return -1;
}
diff --git a/libs/pbd/id.cc b/libs/pbd/id.cc
index b96863b0fa..d7ac1560a1 100644
--- a/libs/pbd/id.cc
+++ b/libs/pbd/id.cc
@@ -44,8 +44,7 @@ ID::init ()
ID::ID ()
{
- Glib::Mutex::Lock lm (*counter_lock);
- _id = _counter++;
+ reset ();
}
ID::ID (const ID& other)
@@ -58,6 +57,13 @@ ID::ID (string str)
string_assign (str);
}
+void
+ID::reset ()
+{
+ Glib::Mutex::Lock lm (*counter_lock);
+ _id = _counter++;
+}
+
int
ID::string_assign (string str)
{
diff --git a/libs/pbd/pbd/id.h b/libs/pbd/pbd/id.h
index 7a32a29002..6296fc2981 100644
--- a/libs/pbd/pbd/id.h
+++ b/libs/pbd/pbd/id.h
@@ -33,6 +33,8 @@ class ID {
ID (std::string);
ID (const ID&);
+ void reset ();
+
bool operator== (const ID& other) const {
return _id == other._id;
}
diff --git a/libs/pbd/pbd/stateful.h b/libs/pbd/pbd/stateful.h
index dd1659db55..2d5b2a0990 100644
--- a/libs/pbd/pbd/stateful.h
+++ b/libs/pbd/pbd/stateful.h
@@ -65,7 +65,10 @@ class Stateful {
void save_extra_xml (const XMLNode&);
const PBD::ID& id() const { return _id; }
-
+ bool set_id (const XMLNode&);
+ void set_id (const std::string&);
+ void reset_id ();
+
/* history management */
void clear_changes ();
@@ -106,7 +109,6 @@ class Stateful {
XMLNode *_extra_xml;
XMLNode *_instant_xml;
- PBD::ID _id;
int32_t _frozen;
PBD::PropertyChange _pending_changed;
Glib::Mutex _lock;
@@ -120,6 +122,9 @@ class Stateful {
*/
virtual void mid_thaw (const PropertyChange&) { }
bool property_changes_suspended() const { return g_atomic_int_get (&_frozen) > 0; }
+
+ private:
+ PBD::ID _id;
};
} // namespace PBD
diff --git a/libs/pbd/stateful.cc b/libs/pbd/stateful.cc
index 47d1e66ef4..b2c76f452f 100644
--- a/libs/pbd/stateful.cc
+++ b/libs/pbd/stateful.cc
@@ -369,5 +369,29 @@ Stateful::clear_owned_changes ()
}
}
+bool
+Stateful::set_id (const XMLNode& node)
+{
+ const XMLProperty* prop;
+
+ if ((prop = node.property ("id")) != 0) {
+ _id = prop->value ();
+ return true;
+ }
+
+ return false;
+}
+
+void
+Stateful::reset_id ()
+{
+ _id = ID ();
+}
+
+void
+Stateful::set_id (const string& str)
+{
+ _id = str;
+}
} // namespace PBD