summaryrefslogtreecommitdiff
path: root/libs/pbd/controllable.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/pbd/controllable.cc')
-rw-r--r--libs/pbd/controllable.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/libs/pbd/controllable.cc b/libs/pbd/controllable.cc
index 049ad0aa21..00638e6c06 100644
--- a/libs/pbd/controllable.cc
+++ b/libs/pbd/controllable.cc
@@ -10,9 +10,64 @@ sigc::signal<void,Controllable*> Controllable::Destroyed;
sigc::signal<bool,Controllable*> Controllable::StartLearning;
sigc::signal<void,Controllable*> Controllable::StopLearning;
+Glib::Mutex* Controllable::registry_lock = 0;
+Controllable::Controllables Controllable::registry;
+
Controllable::Controllable (std::string name)
: _name (name)
{
+ if (registry_lock == 0) {
+ registry_lock = new Glib::Mutex;
+ }
+
+ add ();
+}
+
+void
+Controllable::add ()
+{
+ Glib::Mutex::Lock lm (*registry_lock);
+ registry.insert (this);
+ this->GoingAway.connect (mem_fun (this, &Controllable::remove));
+}
+
+void
+Controllable::remove ()
+{
+ Glib::Mutex::Lock lm (*registry_lock);
+ for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
+ if ((*i) == this) {
+ registry.erase (i);
+ break;
+ }
+ }
+}
+
+Controllable*
+Controllable::by_id (const ID& id)
+{
+ Glib::Mutex::Lock lm (*registry_lock);
+
+ for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
+ if ((*i)->id() == id) {
+ return (*i);
+ }
+ }
+ return 0;
+}
+
+
+Controllable*
+Controllable::by_name (const std::string& str)
+{
+ Glib::Mutex::Lock lm (*registry_lock);
+
+ for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
+ if ((*i)->_name == str) {
+ return (*i);
+ }
+ }
+ return 0;
}
XMLNode&