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/enumwriter.h"
22 #include "pbd/xml++.h"
23 #include "pbd/error.h"
24 #include "pbd/locale_guard.h"
31 PBD::Signal1<void,Controllable*> Controllable::Destroyed;
32 PBD::Signal1<bool,Controllable*> Controllable::StartLearning;
33 PBD::Signal1<void,Controllable*> Controllable::StopLearning;
34 PBD::Signal3<void,Controllable*,int,int> Controllable::CreateBinding;
35 PBD::Signal1<void,Controllable*> Controllable::DeleteBinding;
37 Glib::Threads::RWLock Controllable::registry_lock;
38 Controllable::Controllables Controllable::registry;
39 PBD::ScopedConnectionList* registry_connections = 0;
40 const std::string Controllable::xml_node_name = X_("Controllable");
42 Controllable::Controllable (const string& name, Flag f)
51 Controllable::add (Controllable& ctl)
53 using namespace boost;
55 Glib::Threads::RWLock::WriterLock lm (registry_lock);
56 registry.insert (&ctl);
58 if (!registry_connections) {
59 registry_connections = new ScopedConnectionList;
62 /* Controllable::remove() is static - no need to manage this connection */
64 ctl.DropReferences.connect_same_thread (*registry_connections, boost::bind (&Controllable::remove, &ctl));
68 Controllable::remove (Controllable* ctl)
70 Glib::Threads::RWLock::WriterLock lm (registry_lock);
72 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
81 Controllable::by_id (const ID& id)
83 Glib::Threads::RWLock::ReaderLock lm (registry_lock);
85 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
86 if ((*i)->id() == id) {
94 Controllable::by_name (const string& str)
96 Glib::Threads::RWLock::ReaderLock lm (registry_lock);
98 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
99 if ((*i)->_name == str) {
107 Controllable::get_state ()
109 XMLNode* node = new XMLNode (xml_node_name);
110 LocaleGuard lg (X_("POSIX"));
113 node->add_property (X_("name"), _name); // not reloaded from XML state, just there to look at
114 id().print (buf, sizeof (buf));
115 node->add_property (X_("id"), buf);
116 node->add_property (X_("flags"), enum_2_string (_flags));
117 snprintf (buf, sizeof (buf), "%2.12f", get_value());
118 node->add_property (X_("value"), buf);
121 node->add_child_copy (*_extra_xml);
129 Controllable::set_state (const XMLNode& node, int /*version*/)
131 LocaleGuard lg (X_("POSIX"));
132 const XMLProperty* prop;
134 Stateful::save_extra_xml (node);
138 if ((prop = node.property (X_("flags"))) != 0) {
139 _flags = (Flag) string_2_enum (prop->value(), _flags);
142 if ((prop = node.property (X_("value"))) != 0) {
145 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
154 Controllable::set_flags (Flag f)