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"
29 sigc::signal<void,Controllable*> Controllable::Destroyed;
30 sigc::signal<bool,Controllable*> Controllable::StartLearning;
31 sigc::signal<void,Controllable*> Controllable::StopLearning;
32 sigc::signal<void,Controllable*,int,int> Controllable::CreateBinding;
33 sigc::signal<void,Controllable*> Controllable::DeleteBinding;
35 Glib::StaticRWLock Controllable::registry_lock = GLIBMM_STATIC_RW_LOCK_INIT;
36 Controllable::Controllables Controllable::registry;
37 Controllable::ControllablesByURI Controllable::registry_by_uri;
39 Controllable::Controllable (const string& name, const string& uri)
50 Glib::RWLock::WriterLock lm (registry_lock);
51 registry.insert (this);
54 pair<string,Controllable*> newpair;
56 newpair.second = this;
57 registry_by_uri.insert (newpair);
60 this->GoingAway.connect (mem_fun (this, &Controllable::remove));
64 Controllable::remove ()
66 Glib::RWLock::WriterLock lm (registry_lock);
68 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
76 ControllablesByURI::iterator i = registry_by_uri.find (_uri);
77 if (i != registry_by_uri.end()) {
78 registry_by_uri.erase (i);
86 Controllable::set_uri (const string& new_uri)
88 Glib::RWLock::WriterLock lm (registry_lock);
91 ControllablesByURI::iterator i = registry_by_uri.find (_uri);
92 if (i != registry_by_uri.end()) {
93 registry_by_uri.erase (i);
100 pair<string,Controllable*> newpair;
101 newpair.first = _uri;
102 newpair.second = this;
103 registry_by_uri.insert (newpair);
108 Controllable::by_id (const ID& id)
110 Glib::RWLock::ReaderLock lm (registry_lock);
112 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
113 if ((*i)->id() == id) {
121 Controllable::by_uri (const string& uri)
123 Glib::RWLock::ReaderLock lm (registry_lock);
124 ControllablesByURI::iterator i;
126 if ((i = registry_by_uri.find (uri)) != registry_by_uri.end()) {
133 Controllable::by_name (const string& str)
135 Glib::RWLock::ReaderLock lm (registry_lock);
137 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
138 if ((*i)->_name == str) {
146 Controllable::get_state ()
148 XMLNode* node = new XMLNode (X_("Controllable"));
151 node->add_property (X_("name"), _name); // not reloaded from XML state, just there to look at
152 _id.print (buf, sizeof (buf));
153 node->add_property (X_("id"), buf);
156 node->add_property (X_("uri"), _uri);
163 Controllable::set_state (const XMLNode& node, int /*version*/)
165 const XMLProperty* prop;
167 if ((prop = node.property (X_("id"))) != 0) {
171 error << _("Controllable state node has no ID property") << endmsg;
175 if ((prop = node.property (X_("uri"))) != 0) {
176 set_uri (prop->value());