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/types_convert.h"
25 #include "pbd/string_convert.h"
32 PBD::Signal1<void,Controllable*> Controllable::Destroyed;
33 PBD::Signal1<bool,Controllable*> Controllable::StartLearning;
34 PBD::Signal1<void,Controllable*> Controllable::StopLearning;
35 PBD::Signal3<void,Controllable*,int,int> Controllable::CreateBinding;
36 PBD::Signal1<void,Controllable*> Controllable::DeleteBinding;
37 PBD::Signal1<void, boost::weak_ptr<PBD::Controllable> > Controllable::GUIFocusChanged;
39 Glib::Threads::RWLock Controllable::registry_lock;
40 Controllable::Controllables Controllable::registry;
41 PBD::ScopedConnectionList* registry_connections = 0;
42 const std::string Controllable::xml_node_name = X_("Controllable");
44 Controllable::Controllable (const string& name, Flag f)
53 Controllable::add (Controllable& ctl)
55 using namespace boost;
57 Glib::Threads::RWLock::WriterLock lm (registry_lock);
58 registry.insert (&ctl);
60 if (!registry_connections) {
61 registry_connections = new ScopedConnectionList;
64 /* Controllable::remove() is static - no need to manage this connection */
66 ctl.DropReferences.connect_same_thread (*registry_connections, boost::bind (&Controllable::remove, &ctl));
70 Controllable::remove (Controllable* ctl)
72 Glib::Threads::RWLock::WriterLock lm (registry_lock);
74 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
83 Controllable::by_id (const ID& id)
85 Glib::Threads::RWLock::ReaderLock lm (registry_lock);
87 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
88 if ((*i)->id() == id) {
96 Controllable::by_name (const string& str)
98 Glib::Threads::RWLock::ReaderLock lm (registry_lock);
100 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
101 if ((*i)->_name == str) {
109 Controllable::get_state ()
111 XMLNode* node = new XMLNode (xml_node_name);
113 /* Waves' "Pressure3" has a parameter called "µ-iness"
114 * which causes a parser error : Input is not proper UTF-8, indicate encoding !
115 * Bytes: 0xB5 0x2D 0x69 0x6E
116 * <Controllable name="�-iness" id="2391" flags="" value="0.000000000000" p
119 // this is not reloaded from XML, but it must be present because it is
120 // used to find and identify XML nodes by various Controllable-derived objects
122 node->set_property (X_("name"), _name);
123 node->set_property (X_("id"), id());
124 node->set_property (X_("flags"), _flags);
125 node->set_property (X_("value"), get_save_value());
128 node->add_child_copy (*_extra_xml);
135 Controllable::set_state (const XMLNode& node, int /*version*/)
137 Stateful::save_extra_xml (node);
141 if (node.get_property (X_("flags"), _flags)) {
142 _flags = Flag(_flags | (_flags & Controllable::RealTime));
146 if (node.get_property (X_("value"), val)) {
147 set_value (val, NoGroup);
153 Controllable::set_flags (Flag f)