Ardour  9.2-654-gd2ed0bd940
controllable.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2008-2009 David Robillard <d@drobilla.net>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2014 Ben Loftis <ben@harrisonconsoles.com>
6  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
25 #include <memory>
26 #include <string>
27 #include <set>
28 
29 #include "pbd/libpbd_visibility.h"
30 #include "pbd/rwlock.h"
31 #include "pbd/signals.h"
32 
34 
35 class XMLNode;
36 
37 namespace PBD {
38 
39 class Controllable;
40 typedef std::set<std::shared_ptr<Controllable>> ControllableSet;
41 
70 class LIBPBD_API Controllable : public PBD::StatefulDestructible, public std::enable_shared_from_this<Controllable>
71 {
72 public:
73  enum Flag {
74  Toggle = 0x01,
75  GainLike = 0x02,
76  RealTime = 0x04,
77  NotAutomatable = 0x08,
78  InlineControl = 0x10,
79  HiddenControl = 0x20,
80  MonitorControl = 0x40,
81  };
82 
83  Controllable (const std::string& name, Flag f = Flag (0));
84 
93  ForGroup
94  };
95 
108  virtual void set_value (double value, GroupControlDisposition group_override) = 0;
109 
113  virtual double get_value (void) const = 0;
114 
120  virtual double get_save_value () const { return get_value(); }
121 
123  virtual double internal_to_interface (double i, bool rotary = false) const {
124  /* by default, the interface range is just a linear
125  * interpolation between lower and upper values */
126  return (i-lower())/(upper() - lower());
127  }
128 
129  virtual double interface_to_internal (double i, bool rotary = false) const {
130  return lower() + i*(upper() - lower());
131  }
132 
134  virtual float get_interface(bool rotary=false) const { return (internal_to_interface(get_value(), rotary)); }
135 
136  virtual void set_interface (float fraction, bool rotary=false, GroupControlDisposition gcd = NoGroup);
137 
138  virtual std::string get_user_string() const { return std::string(); }
139 
140  virtual float numeric_entry_convert (float, bool to_user_value);
141 
143 
144  static PBD::Signal<bool(std::weak_ptr<PBD::Controllable> )> StartLearning;
145  static PBD::Signal<void(std::weak_ptr<PBD::Controllable> )> StopLearning;
146 
147  static PBD::Signal<void(std::weak_ptr<PBD::Controllable> )> GUIFocusChanged;
148  static PBD::Signal<void(std::weak_ptr<PBD::Controllable> )> ControlTouched;
149 
151 
152  int set_state (const XMLNode&, int version);
153  virtual XMLNode& get_state () const;
154 
155  std::string name() const { return _name; }
156 
157  bool touching () const { return _touching; }
159 
160  bool is_toggle() const { return _flags & Toggle; }
161  bool is_gain_like() const { return _flags & GainLike; }
162 
163  virtual double lower() const { return 0.0; }
164  virtual double upper() const { return 1.0; }
165  virtual double normal() const { return 0.0; } //the default value
166 
167  Flag flags() const { return _flags; }
168  void set_flags (Flag f);
169 
170  void set_flag (Flag f);
171  void clear_flag (Flag f);
172 
173  static std::shared_ptr<Controllable> by_id (const PBD::ID&);
174  static void dump_registry ();
176 
177  static const std::string xml_node_name;
178 
179 protected:
180  void set_touching (bool yn) {
181  if (_touching == yn) { return; }
182  _touching = yn;
183  TouchChanged (); /* EMIT SIGNAL */
184  }
185 
186  std::function<float (float, bool)> _numeric_entry_convert;
187 
188 private:
189  std::string _name;
190  std::string _units;
192  bool _touching;
193 
194 
195  typedef std::set<PBD::Controllable*> Controllables;
196 
200 
201  static void add (Controllable&);
202  static void remove (Controllable*);
203 };
204 
205 }
206 
std::function< float(float, bool)> _numeric_entry_convert
Definition: controllable.h:186
void set_touching(bool yn)
Definition: controllable.h:180
virtual XMLNode & get_state() const
static void dump_registry()
Controllable(const std::string &name, Flag f=Flag(0))
static PBD::Signal< void(std::weak_ptr< PBD::Controllable >)> ControlTouched
Definition: controllable.h:148
void clear_flag(Flag f)
_flags &= ~f;
Flag flags() const
Definition: controllable.h:167
virtual double interface_to_internal(double i, bool rotary=false) const
Definition: controllable.h:129
static ScopedConnectionList registry_connections
Definition: controllable.h:197
static void remove(Controllable *)
static std::shared_ptr< Controllable > by_id(const PBD::ID &)
virtual double get_save_value() const
Definition: controllable.h:120
bool is_gain_like() const
Definition: controllable.h:161
std::string name() const
Definition: controllable.h:155
static PBD::Signal< bool(std::weak_ptr< PBD::Controllable >)> StartLearning
Definition: controllable.h:144
virtual std::string get_user_string() const
Definition: controllable.h:138
std::string _units
Definition: controllable.h:190
std::set< PBD::Controllable * > Controllables
Definition: controllable.h:195
static ControllableSet registered_controllables()
static PBD::RWLock registry_lock
Definition: controllable.h:198
virtual void set_value(double value, GroupControlDisposition group_override)=0
virtual double lower() const
Definition: controllable.h:163
virtual double normal() const
Definition: controllable.h:165
std::string _name
Definition: controllable.h:189
virtual double get_value(void) const =0
virtual float get_interface(bool rotary=false) const
Definition: controllable.h:134
PBD::Signal< void()> TouchChanged
Definition: controllable.h:158
int set_state(const XMLNode &, int version)
virtual double internal_to_interface(double i, bool rotary=false) const
Definition: controllable.h:123
virtual void set_interface(float fraction, bool rotary=false, GroupControlDisposition gcd=NoGroup)
static const std::string xml_node_name
Definition: controllable.h:177
static PBD::Signal< void(std::weak_ptr< PBD::Controllable >)> GUIFocusChanged
Definition: controllable.h:147
bool touching() const
Definition: controllable.h:157
virtual float numeric_entry_convert(float, bool to_user_value)
static PBD::Signal< void(std::weak_ptr< PBD::Controllable >)> StopLearning
Definition: controllable.h:145
static void add(Controllable &)
void set_flags(Flag f)
static Controllables registry
Definition: controllable.h:199
bool is_toggle() const
Definition: controllable.h:160
void set_flag(Flag f)
_flags |= f;
PBD::Signal< void(bool, PBD::Controllable::GroupControlDisposition)> Changed
Definition: controllable.h:150
virtual double upper() const
Definition: controllable.h:164
PBD::Signal< void()> LearningFinished
Definition: controllable.h:142
Definition: id.h:33
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBPBD_API
std::shared_ptr< PBD::Controllable > Controllable
Definition: console1.h:80
Definition: axis_view.h:42
std::set< std::shared_ptr< Controllable > > ControllableSet
Definition: controllable.h:39