MIDI/Controllables for monitor section, and related fixes
[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 "pbd/signals.h"
28 #include <glibmm/thread.h>
29
30 #include "pbd/statefuldestructible.h"
31
32 class XMLNode;
33
34 namespace PBD {
35
36 class Controllable : public PBD::StatefulDestructible {
37   public:
38         enum Flag {
39                 Toggle = 0x1,
40                 Discrete = 0x2,
41                 GainLike = 0x4,
42                 IntegerOnly = 0x8
43         };
44
45         Controllable (const std::string& name, Flag f = Flag (0));
46         virtual ~Controllable() { Destroyed (this); }
47
48         virtual void set_value (float) = 0;
49         virtual float get_value (void) const = 0;
50
51         PBD::Signal0<void> LearningFinished;
52         static PBD::Signal3<void,PBD::Controllable*,int,int> CreateBinding;
53         static PBD::Signal1<void,PBD::Controllable*> DeleteBinding;
54
55         static PBD::Signal1<bool,PBD::Controllable*> StartLearning;
56         static PBD::Signal1<void,PBD::Controllable*> StopLearning;
57
58         static PBD::Signal1<void,Controllable*> Destroyed;
59         
60         PBD::Signal0<void> Changed;
61
62         int set_state (const XMLNode&, int version);
63         XMLNode& get_state ();
64
65         std::string name()      const { return _name; }
66
67         bool touching () const { return _touching; }
68         void set_touching (bool yn) { _touching = yn; }
69
70         bool is_toggle() const { return _flags & Toggle; }
71         bool is_discrete() const { return _flags & Discrete; }
72         bool is_gain_like() const { return _flags & GainLike; }
73         bool is_integral_only() const { return _flags & IntegerOnly; }
74
75         virtual float lower() const { return 0.0f; }
76         virtual float upper() const { return 1.0f; }
77
78         Flag flags() const { return _flags; }
79         void set_flags (Flag f);
80
81         virtual uint32_t get_discrete_values (std::list<float>&) { return 0; /* no values returned */ }
82
83         static Controllable* by_id (const PBD::ID&);
84         static Controllable* by_name (const std::string&);
85
86   private:
87         std::string _name;
88
89         Flag        _flags;
90         bool        _touching;
91
92         static void add (Controllable&);
93         static void remove (Controllable*);
94
95         typedef std::set<PBD::Controllable*> Controllables;
96         static Glib::StaticRWLock registry_lock;
97         static Controllables registry;
98 };
99
100 /* a utility class for the occasions when you need but do not have
101    a Controllable
102 */
103
104 class IgnorableControllable : public Controllable 
105 {
106   public: 
107         IgnorableControllable () : PBD::Controllable ("ignoreMe") {}
108         ~IgnorableControllable () {}
109     
110         void set_value (float /*v*/) {}
111         float get_value () const { return 0.0; }
112 };
113
114 }
115
116 #endif /* __pbd_controllable_h__ */