ardour
controllable.h
Go to the documentation of this file.
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/libpbd_visibility.h"
28 #include "pbd/signals.h"
29 #include <glibmm/threads.h>
30 
32 
33 using std::min;
34 using std::max;
35 
36 class XMLNode;
37 
38 namespace PBD {
39 
41  public:
42  enum Flag {
43  Toggle = 0x1,
44  GainLike = 0x2,
45  };
46 
47  Controllable (const std::string& name, Flag f = Flag (0));
48  virtual ~Controllable() { Destroyed (this); }
49 
50  /* We express Controllable values in one of three ways:
51  * 1. `user' --- as presented to the user (e.g. dB, Hz, etc.)
52  * 2. `interface' --- as used in some cases for the UI representation
53  * (in order to make controls behave logarithmically).
54  * 3. `internal' --- as passed to a processor, track, plugin, or whatever.
55  *
56  * Note that in some cases user and processor may be the same
57  * (and interface different) e.g. frequency, which is presented
58  * to the user and passed to the processor in linear terms, but
59  * which needs log scaling in the interface.
60  *
61  * In other cases, user and interface may be the same (and processor different)
62  * e.g. gain, which is presented to the user in log terms (dB)
63  * but passed to the processor as a linear quantity.
64  */
65 
67  virtual void set_value (double) = 0;
68  virtual double get_value (void) const = 0;
69 
71  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
72  virtual double interface_to_internal (double i) const {return lower() + i*(upper() - lower());}
73  virtual double internal_to_user (double i) const {return i;} //by default the internal value is the same as the user value
74  virtual double user_to_internal (double i) const {return i;} //by default the internal value is the same as the user value
75 
77  virtual float get_interface() const { return (internal_to_interface(get_value())); }
78  virtual void set_interface (float percent) { percent = min( max(0.0f, percent), 1.0f); set_value(interface_to_internal(percent)); }
79 
81  virtual float get_user() const { return (internal_to_user(get_value())); }
82  virtual void set_user (float user_v) { set_value(user_to_internal(user_v)); }
83  virtual std::string get_user_string() const { return std::string(); }
84 
85  PBD::Signal0<void> LearningFinished;
86  static PBD::Signal3<void,PBD::Controllable*,int,int> CreateBinding;
87  static PBD::Signal1<void,PBD::Controllable*> DeleteBinding;
88 
89  static PBD::Signal1<bool,PBD::Controllable*> StartLearning;
90  static PBD::Signal1<void,PBD::Controllable*> StopLearning;
91 
92  static PBD::Signal1<void,Controllable*> Destroyed;
93 
94  PBD::Signal0<void> Changed;
95 
96  int set_state (const XMLNode&, int version);
97  XMLNode& get_state ();
98 
99  std::string name() const { return _name; }
100 
101  bool touching () const { return _touching; }
102  void set_touching (bool yn) { _touching = yn; }
103 
104  bool is_toggle() const { return _flags & Toggle; }
105  bool is_gain_like() const { return _flags & GainLike; }
106 
107  virtual double lower() const { return 0.0; }
108  virtual double upper() const { return 1.0; }
109  virtual double normal() const { return 0.0; } //the default value
110 
111  Flag flags() const { return _flags; }
112  void set_flags (Flag f);
113 
114  static Controllable* by_id (const PBD::ID&);
115  static Controllable* by_name (const std::string&);
116  static const std::string xml_node_name;
117  private:
118  std::string _name;
119 
120  std::string _units;
121 
123  bool _touching;
124 
125  static void add (Controllable&);
126  static void remove (Controllable*);
127 
128  typedef std::set<PBD::Controllable*> Controllables;
129  static Glib::Threads::RWLock registry_lock;
130  static Controllables registry;
131 };
132 
133 /* a utility class for the occasions when you need but do not have
134  a Controllable
135 */
136 
138 {
139  public:
140  IgnorableControllable () : PBD::Controllable ("ignoreMe") {}
142 
143  void set_value (double /*v*/) {}
144  double get_value () const { return 0.0; }
145 };
146 
147 }
148 
149 #endif /* __pbd_controllable_h__ */
virtual float get_interface() const
Definition: controllable.h:77
static PBD::Signal3< void, PBD::Controllable *, int, int > CreateBinding
Definition: controllable.h:86
virtual float get_user() const
Definition: controllable.h:81
static Controllables registry
Definition: controllable.h:130
#define LIBPBD_API
virtual void set_interface(float percent)
Definition: controllable.h:78
std::string _units
Definition: controllable.h:120
bool touching() const
Definition: controllable.h:101
void set_touching(bool yn)
Definition: controllable.h:102
tuple f
Definition: signals.py:35
static PBD::Signal1< bool, PBD::Controllable * > StartLearning
Definition: controllable.h:89
virtual std::string get_user_string() const
Definition: controllable.h:83
virtual double upper() const
Definition: controllable.h:108
bool is_gain_like() const
Definition: controllable.h:105
Definition: id.h:32
virtual double internal_to_interface(double i) const
Definition: controllable.h:71
virtual void set_user(float user_v)
Definition: controllable.h:82
Flag flags() const
Definition: controllable.h:111
static PBD::Signal1< void, PBD::Controllable * > StopLearning
Definition: controllable.h:90
static Glib::Threads::RWLock registry_lock
Definition: controllable.h:129
virtual double normal() const
Definition: controllable.h:109
virtual double lower() const
Definition: controllable.h:107
static PBD::Signal1< void, Controllable * > Destroyed
Definition: controllable.h:92
virtual ~Controllable()
Definition: controllable.h:48
static const std::string xml_node_name
Definition: controllable.h:116
PBD::Signal0< void > LearningFinished
Definition: controllable.h:85
#define upper
Definition: auto_spin.cc:28
const char * name
std::string _name
Definition: controllable.h:118
virtual double user_to_internal(double i) const
Definition: controllable.h:74
Definition: xml++.h:95
PBD::Signal0< void > Changed
Definition: controllable.h:94
virtual double interface_to_internal(double i) const
Definition: controllable.h:72
Definition: debug.h:30
std::set< PBD::Controllable * > Controllables
Definition: controllable.h:128
#define lower
Definition: auto_spin.cc:29
static PBD::Signal1< void, PBD::Controllable * > DeleteBinding
Definition: controllable.h:87
static LilvNode * get_value(LilvWorld *world, const LilvNode *subject, const LilvNode *predicate)
Definition: lv2_plugin.cc:971
std::string name() const
Definition: controllable.h:99
bool is_toggle() const
Definition: controllable.h:104
virtual double internal_to_user(double i) const
Definition: controllable.h:73
double get_value() const
Definition: controllable.h:144