2 Copyright (C) 2000-2007 Paul Davis
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.
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/libpbd_visibility.h"
28 #include "pbd/signals.h"
29 #include <glibmm/threads.h>
31 #include "pbd/statefuldestructible.h"
37 class LIBPBD_API Controllable : public PBD::StatefulDestructible {
44 Controllable (const std::string& name, Flag f = Flag (0));
45 virtual ~Controllable() { Destroyed (this); }
47 /* We express Controllable values in one of three ways:
48 * 1. `user' --- as presented to the user (e.g. dB, Hz, etc.)
49 * 2. `interface' --- as used in some cases for the UI representation
50 * (in order to make controls behave logarithmically).
51 * 3. `internal' --- as passed to a processor, track, plugin, or whatever.
53 * Note that in some cases user and processor may be the same
54 * (and interface different) e.g. frequency, which is presented
55 * to the user and passed to the processor in linear terms, but
56 * which needs log scaling in the interface.
58 * In other cases, user and interface may be the same (and processor different)
59 * e.g. gain, which is presented to the user in log terms (dB)
60 * but passed to the processor as a linear quantity.
63 /** Get and Set `internal' value */
64 virtual void set_value (double) = 0;
65 virtual double get_value (void) const = 0;
67 /** Conversions between `internal', 'interface', and 'user' values */
68 virtual double internal_to_interface (double i) const {return (i-lower())/(upper() - lower());} //by default, the interface range is just a linear interpolation between lower and upper values
69 virtual double interface_to_internal (double i) const {return lower() + i*(upper() - lower());}
70 virtual double internal_to_user (double i) const {return i;} //by default the internal value is the same as the user value
71 virtual double user_to_internal (double i) const {return i;} //by default the internal value is the same as the user value
73 /** Get and Set `interface' value (typically, percent of knob travel) */
74 virtual float get_interface() const { return (internal_to_interface(get_value())); }
75 virtual void set_interface (float percent) { percent = std::min( std::max(0.0f, percent), 1.0f); set_value(interface_to_internal(percent)); }
77 /** Get and Set `user' value ( dB or milliseconds, etc. This MIGHT be the same as the internal value, but in a few cases it is not ) */
78 virtual float get_user() const { return (internal_to_user(get_value())); }
79 virtual void set_user (float user_v) { set_value(user_to_internal(user_v)); }
80 virtual std::string get_user_string() const { return std::string(); }
82 PBD::Signal0<void> LearningFinished;
83 static PBD::Signal3<void,PBD::Controllable*,int,int> CreateBinding;
84 static PBD::Signal1<void,PBD::Controllable*> DeleteBinding;
86 static PBD::Signal1<bool,PBD::Controllable*> StartLearning;
87 static PBD::Signal1<void,PBD::Controllable*> StopLearning;
89 static PBD::Signal1<void,Controllable*> Destroyed;
91 PBD::Signal0<void> Changed;
93 int set_state (const XMLNode&, int version);
94 XMLNode& get_state ();
96 std::string name() const { return _name; }
98 bool touching () const { return _touching; }
99 void set_touching (bool yn) { _touching = yn; }
101 bool is_toggle() const { return _flags & Toggle; }
102 bool is_gain_like() const { return _flags & GainLike; }
104 virtual double lower() const { return 0.0; }
105 virtual double upper() const { return 1.0; }
107 Flag flags() const { return _flags; }
108 void set_flags (Flag f);
110 static Controllable* by_id (const PBD::ID&);
111 static Controllable* by_name (const std::string&);
112 static const std::string xml_node_name;
121 static void add (Controllable&);
122 static void remove (Controllable*);
124 typedef std::set<PBD::Controllable*> Controllables;
125 static Glib::Threads::RWLock registry_lock;
126 static Controllables registry;
129 /* a utility class for the occasions when you need but do not have
133 class LIBPBD_API IgnorableControllable : public Controllable
136 IgnorableControllable () : PBD::Controllable ("ignoreMe") {}
137 ~IgnorableControllable () {}
139 void set_value (double /*v*/) {}
140 double get_value () const { return 0.0; }
145 #endif /* __pbd_controllable_h__ */