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::StaticRWLock Controllable::registry_lock = GLIBMM_STATIC_RW_LOCK_INIT;
35 Controllable::Controllables Controllable::registry;
36 Controllable::ControllablesByURI Controllable::registry_by_uri;
38 Controllable::Controllable (const std::string& name, const std::string& uri)
49 Glib::RWLock::WriterLock lm (*registry_lock);
50 registry.insert (this);
53 pair<string,Controllable*> newpair;
55 newpair.second = this;
56 registry_by_uri.insert (newpair);
59 this->GoingAway.connect (mem_fun (this, &Controllable::remove));
63 Controllable::remove ()
65 Glib::RWLock::WriterLock lm (*registry_lock);
67 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
75 ControllablesByURI::iterator i = registry_by_uri.find (_uri);
76 if (i != registry_by_uri.end()) {
77 registry_by_uri.erase (i);
85 Controllable::set_uri (const std::string& new_uri)
87 Glib::RWLock::WriterLock lm (*registry_lock);
90 ControllablesByURI::iterator i = registry_by_uri.find (_uri);
91 if (i != registry_by_uri.end()) {
92 registry_by_uri.erase (i);
99 pair<string,Controllable*> newpair;
100 newpair.first = _uri;
101 newpair.second = this;
102 registry_by_uri.insert (newpair);
107 Controllable::by_id (const ID& id)
109 Glib::RWLock::ReaderLock lm (*registry_lock);
111 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
112 if ((*i)->id() == id) {
120 Controllable::by_uri (const string& uri)
122 Glib::RWLock::ReaderLock lm (*registry_lock);
123 ControllablesByURI::iterator i;
125 if ((i = registry_by_ui.find (uri)) != registry_by_uri.end()) {
132 Controllable::by_name (const std::string& str)
134 Glib::RWLock::ReaderLock lm (*registry_lock);
136 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
137 if ((*i)->_name == str) {
145 Controllable::get_state ()
147 XMLNode* node = new XMLNode (X_("Controllable"));
150 node->add_property (X_("name"), _name); // not reloaded from XML state, just there to look at
151 _id.print (buf, sizeof (buf));
152 node->add_property (X_("id"), buf);
155 node->add_property (X_("uri"), _uri);
162 Controllable::set_state (const XMLNode& node, int /*version*/)
164 const XMLProperty* prop;
166 if ((prop = node.property (X_("id"))) != 0) {
170 error << _("Controllable state node has no ID property") << endmsg;
174 if ((prop = node.property (X_("uri"))) != 0) {
175 set_uri (prop->value());