make MMC work again, make tracing MIDI input work again, add GUI control for MMC...
[ardour.git] / libs / pbd / controllable.cc
index 049ad0aa213543677b907de12146e34e8bd509c8..00638e6c06cc3312b159723913b3671523ef49aa 100644 (file)
@@ -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&