Declick before the end of seamless loops, not after the end, so that loops are render...
[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 #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                 GainLike = 0x2,
41         };
42
43         Controllable (const std::string& name, Flag f = Flag (0));
44         virtual ~Controllable() { Destroyed (this); }
45
46         /* We express Controllable values in one of three ways:
47          * 1. `user' --- as presented to the user (e.g. dB, Hz, etc.)
48          * 2. `interface' --- as used in some cases for the UI representation
49          * (in order to make controls behave logarithmically).
50          * 3. `internal' --- as passed to a processor, track, plugin, or whatever.
51          *
52          * Note that in some cases user and processor may be the same
53          * (and interface different) e.g. frequency, which is presented
54          * to the user and passed to the processor in linear terms, but
55          * which needs log scaling in the interface.
56          *
57          * In other cases, user and interface may be the same (and processor different)
58          * e.g. gain, which is presented to the user in log terms (dB)
59          * but passed to the processor as a linear quantity.
60          */
61
62         /** Set `internal' value */
63         virtual void set_value (double) = 0;
64         /** @return `internal' value */
65         virtual double get_value (void) const = 0;
66
67         PBD::Signal0<void> LearningFinished;
68         static PBD::Signal3<void,PBD::Controllable*,int,int> CreateBinding;
69         static PBD::Signal1<void,PBD::Controllable*> DeleteBinding;
70
71         static PBD::Signal1<bool,PBD::Controllable*> StartLearning;
72         static PBD::Signal1<void,PBD::Controllable*> StopLearning;
73
74         static PBD::Signal1<void,Controllable*> Destroyed;
75         
76         PBD::Signal0<void> Changed;
77
78         int set_state (const XMLNode&, int version);
79         XMLNode& get_state ();
80
81         std::string name()      const { return _name; }
82
83         bool touching () const { return _touching; }
84         void set_touching (bool yn) { _touching = yn; }
85
86         bool is_toggle() const { return _flags & Toggle; }
87         bool is_gain_like() const { return _flags & GainLike; }
88
89         virtual double lower() const { return 0.0; }
90         virtual double upper() const { return 1.0; }
91
92         Flag flags() const { return _flags; }
93         void set_flags (Flag f);
94
95         static Controllable* by_id (const PBD::ID&);
96         static Controllable* by_name (const std::string&);
97         static const std::string xml_node_name;
98   private:
99         std::string _name;
100
101         Flag        _flags;
102         bool        _touching;
103
104         static void add (Controllable&);
105         static void remove (Controllable*);
106
107         typedef std::set<PBD::Controllable*> Controllables;
108         static Glib::StaticRWLock registry_lock;
109         static Controllables registry;
110 };
111
112 /* a utility class for the occasions when you need but do not have
113    a Controllable
114 */
115
116 class IgnorableControllable : public Controllable 
117 {
118   public: 
119         IgnorableControllable () : PBD::Controllable ("ignoreMe") {}
120         ~IgnorableControllable () {}
121     
122         void set_value (double /*v*/) {}
123         double get_value () const { return 0.0; }
124 };
125
126 }
127
128 #endif /* __pbd_controllable_h__ */