2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "pbd/controllable.h"
21 #include "pbd/xml++.h"
22 #include "pbd/error.h"
28 sigc::signal<void,Controllable*> Controllable::Destroyed;
29 sigc::signal<bool,Controllable*> Controllable::StartLearning;
30 sigc::signal<void,Controllable*> Controllable::StopLearning;
31 sigc::signal<void,Controllable*,int,int> Controllable::CreateBinding;
32 sigc::signal<void,Controllable*> Controllable::DeleteBinding;
34 Glib::Mutex* Controllable::registry_lock = 0;
35 Controllable::Controllables Controllable::registry;
37 Controllable::Controllable (std::string name)
41 if (registry_lock == 0) {
42 registry_lock = new Glib::Mutex;
51 Glib::Mutex::Lock lm (*registry_lock);
52 registry.insert (this);
53 this->GoingAway.connect (mem_fun (this, &Controllable::remove));
57 Controllable::remove ()
59 Glib::Mutex::Lock lm (*registry_lock);
60 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
69 Controllable::by_id (const ID& id)
71 Glib::Mutex::Lock lm (*registry_lock);
73 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
74 if ((*i)->id() == id) {
83 Controllable::by_name (const std::string& str)
85 Glib::Mutex::Lock lm (*registry_lock);
87 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
88 if ((*i)->_name == str) {
96 Controllable::get_state ()
98 XMLNode* node = new XMLNode (X_("Controllable"));
101 node->add_property (X_("name"), _name); // not reloaded from XML state, just there to look at
102 _id.print (buf, sizeof (buf));
103 node->add_property (X_("id"), buf);
108 Controllable::set_state (const XMLNode& node, int version)
110 const XMLProperty* prop = node.property (X_("id"));
116 error << _("Controllable state node has no ID property") << endmsg;