9750ebe56ed1c66faccbc5d1f2fd934150bd035f
[ardour.git] / libs / pbd / pbd / controllable.h
1 /*
2     Copyright (C) 2000-2007 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5 v    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.
8
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.
13
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.
17
18 */
19
20 #ifndef __pbd_controllable_h__
21 #define __pbd_controllable_h__
22
23 #include <string>
24 #include <set>
25 #include <map>
26
27 #include <sigc++/trackable.h>
28 #include <sigc++/signal.h>
29 #include <glibmm/thread.h>
30
31 #include "pbd/statefuldestructible.h"
32
33 class XMLNode;
34
35 namespace PBD {
36
37 class Controllable : public PBD::StatefulDestructible {
38   public:
39         Controllable (const std::string& name, const std::string& uri);
40         virtual ~Controllable() { Destroyed (this); }
41
42         void set_uri (const std::string&);
43         const std::string& uri() const { return _uri; }
44
45         virtual void set_value (float) = 0;
46         virtual float get_value (void) const = 0;
47
48         sigc::signal<void> LearningFinished;
49         static sigc::signal<void,PBD::Controllable*,int,int> CreateBinding;
50         static sigc::signal<void,PBD::Controllable*> DeleteBinding;
51
52         static sigc::signal<bool,PBD::Controllable*> StartLearning;
53         static sigc::signal<void,PBD::Controllable*> StopLearning;
54
55         static sigc::signal<void,Controllable*> Destroyed;
56
57         sigc::signal<void> Changed;
58
59         int set_state (const XMLNode&, int version);
60         XMLNode& get_state ();
61
62         std::string name()      const { return _name; }
63         bool        touching () const { return _touching; }
64         
65         void set_touching (bool yn) { _touching = yn; }
66
67         static Controllable* by_id (const PBD::ID&);
68         static Controllable* by_name (const std::string&);
69         static Controllable* by_uri (const std::string&);
70
71   private:
72         std::string _name;
73         std::string _uri;
74         bool        _touching;
75
76         void add ();
77         void remove ();
78
79         typedef std::set<PBD::Controllable*> Controllables;
80         typedef std::map<std::string,PBD::Controllable*> ControllablesByURI;
81         static Glib::StaticRWLock registry_lock;
82         static Controllables registry;
83         static ControllablesByURI registry_by_uri;
84 };
85
86 /* a utility class for the occasions when you need but do not have
87    a Controllable
88 */
89
90 class IgnorableControllable : public Controllable 
91 {
92   public: 
93         IgnorableControllable () : PBD::Controllable ("ignoreMe", std::string()) {}
94         ~IgnorableControllable () {}
95     
96         void set_value (float /*v*/) {}
97         float get_value () const { return 0.0; }
98 };
99
100 }
101
102 #endif /* __pbd_controllable_h__ */