newly created files for use in recording appear in a .stubs folder, and are moved...
[ardour2.git] / libs / pbd / controllable.cc
blob38780bddbe4ea64d8612731085fb1de01c121344
1 /*
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"
25 #include "i18n.h"
27 using namespace PBD;
28 using namespace std;
30 PBD::Signal1<void,Controllable*> Controllable::Destroyed;
31 PBD::Signal1<bool,Controllable*> Controllable::StartLearning;
32 PBD::Signal1<void,Controllable*> Controllable::StopLearning;
33 PBD::Signal3<void,Controllable*,int,int> Controllable::CreateBinding;
34 PBD::Signal1<void,Controllable*> Controllable::DeleteBinding;
36 Glib::StaticRWLock Controllable::registry_lock = GLIBMM_STATIC_RW_LOCK_INIT;
37 Controllable::Controllables Controllable::registry;
38 PBD::ScopedConnectionList registry_connections;
40 Controllable::Controllable (const string& name, Flag f)
41 : _name (name)
42 , _flags (f)
43 , _touching (false)
45 add (*this);
48 void
49 Controllable::add (Controllable& ctl)
51 using namespace boost;
53 Glib::RWLock::WriterLock lm (registry_lock);
54 registry.insert (&ctl);
56 /* Controllable::remove() is static - no need to manage this connection */
58 ctl.DropReferences.connect_same_thread (registry_connections, boost::bind (&Controllable::remove, &ctl));
61 void
62 Controllable::remove (Controllable* ctl)
64 Glib::RWLock::WriterLock lm (registry_lock);
66 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
67 if ((*i) == ctl) {
68 registry.erase (i);
69 break;
74 Controllable*
75 Controllable::by_id (const ID& id)
77 Glib::RWLock::ReaderLock lm (registry_lock);
79 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
80 if ((*i)->id() == id) {
81 return (*i);
84 return 0;
87 Controllable*
88 Controllable::by_name (const string& str)
90 Glib::RWLock::ReaderLock lm (registry_lock);
92 for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
93 if ((*i)->_name == str) {
94 return (*i);
97 return 0;
100 XMLNode&
101 Controllable::get_state ()
103 XMLNode* node = new XMLNode (X_("Controllable"));
104 char buf[64];
106 node->add_property (X_("name"), _name); // not reloaded from XML state, just there to look at
107 _id.print (buf, sizeof (buf));
108 node->add_property (X_("id"), buf);
109 node->add_property (X_("flags"), enum_2_string (_flags));
111 return *node;
115 Controllable::set_state (const XMLNode& node, int /*version*/)
117 const XMLProperty* prop;
119 if ((prop = node.property (X_("id"))) != 0) {
120 _id = prop->value();
121 return 0;
122 } else {
123 error << _("Controllable state node has no ID property") << endmsg;
124 return -1;
127 if ((prop = node.property (X_("flags"))) != 0) {
128 _flags = (Flag) string_2_enum (prop->value(), _flags);
132 void
133 Controllable::set_flags (Flag f)
135 _flags = f;