0007e04fd3ae3a2e825829aff3de82cf193995b7
[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     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
26 #include <sigc++/trackable.h>
27 #include <sigc++/signal.h>
28
29 #include "pbd/statefuldestructible.h"
30
31 class XMLNode;
32
33 namespace PBD {
34
35 class Controllable : public PBD::StatefulDestructible {
36   public:
37         Controllable (std::string name);
38         virtual ~Controllable() { Destroyed (this); }
39
40         virtual void set_value (float) = 0;
41         virtual float get_value (void) const = 0;
42
43         sigc::signal<void> LearningFinished;
44         static sigc::signal<void,PBD::Controllable*,int,int> CreateBinding;
45         static sigc::signal<void,PBD::Controllable*> DeleteBinding;
46
47         static sigc::signal<bool,PBD::Controllable*> StartLearning;
48         static sigc::signal<void,PBD::Controllable*> StopLearning;
49
50         static sigc::signal<void,Controllable*> Destroyed;
51
52         sigc::signal<void> Changed;
53
54         int set_state (const XMLNode&);
55         XMLNode& get_state ();
56
57         std::string name()      const { return _name; }
58         bool        touching () const { return _touching; }
59         
60         void set_touching (bool yn) { _touching = yn; }
61
62         static Controllable* by_id (const PBD::ID&);
63         static Controllable* by_name (const std::string&);
64
65   private:
66         std::string _name;
67         bool        _touching;
68
69         void add ();
70         void remove ();
71
72         typedef std::set<PBD::Controllable*> Controllables;
73         static Glib::Mutex* registry_lock;
74         static Controllables registry;
75 };
76
77 /* a utility class for the occasions when you need but do not have
78    a Controllable
79 */
80
81 class IgnorableControllable : public Controllable 
82 {
83   public: 
84     IgnorableControllable () : PBD::Controllable ("ignoreMe") {}
85     ~IgnorableControllable () {}
86     
87     void set_value (float v){}
88     float get_value () const { return 0.0; }
89 };
90
91 }
92
93 #endif /* __pbd_controllable_h__ */