2 Copyright (C) 2000-2007 Paul Davis
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.
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 #ifndef __pbd_controllable_h__
21 #define __pbd_controllable_h__
27 #include "pbd/signals.h"
28 #include <glibmm/thread.h>
30 #include "pbd/statefuldestructible.h"
36 class Controllable : public PBD::StatefulDestructible {
43 Controllable (const std::string& name, Flag f = Flag (0));
44 virtual ~Controllable() { Destroyed (this); }
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. `UI' --- as used in some cases for the internal representation
49 * of the UI. This may be the same as `user', or may be something
50 * like the natural log of frequency in order that sliders operate
51 * in a logarithmic fashion.
52 * 3. `plugin' --- as passed to a plugin.
55 /** Set `user' value */
56 virtual void set_value (double) = 0;
57 /** @return `user' value */
58 virtual double get_value (void) const = 0;
60 PBD::Signal0<void> LearningFinished;
61 static PBD::Signal3<void,PBD::Controllable*,int,int> CreateBinding;
62 static PBD::Signal1<void,PBD::Controllable*> DeleteBinding;
64 static PBD::Signal1<bool,PBD::Controllable*> StartLearning;
65 static PBD::Signal1<void,PBD::Controllable*> StopLearning;
67 static PBD::Signal1<void,Controllable*> Destroyed;
69 PBD::Signal0<void> Changed;
71 int set_state (const XMLNode&, int version);
72 XMLNode& get_state ();
74 std::string name() const { return _name; }
76 bool touching () const { return _touching; }
77 void set_touching (bool yn) { _touching = yn; }
79 bool is_toggle() const { return _flags & Toggle; }
80 bool is_gain_like() const { return _flags & GainLike; }
82 virtual double lower() const { return 0.0; }
83 virtual double upper() const { return 1.0; }
85 Flag flags() const { return _flags; }
86 void set_flags (Flag f);
88 static Controllable* by_id (const PBD::ID&);
89 static Controllable* by_name (const std::string&);
90 static const std::string xml_node_name;
97 static void add (Controllable&);
98 static void remove (Controllable*);
100 typedef std::set<PBD::Controllable*> Controllables;
101 static Glib::StaticRWLock registry_lock;
102 static Controllables registry;
105 /* a utility class for the occasions when you need but do not have
109 class IgnorableControllable : public Controllable
112 IgnorableControllable () : PBD::Controllable ("ignoreMe") {}
113 ~IgnorableControllable () {}
115 void set_value (double /*v*/) {}
116 double get_value () const { return 0.0; }
121 #endif /* __pbd_controllable_h__ */