Ardour  9.2-129-gdf5e1050bd
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 
141 
142  static PBD::Signal<bool(std::weak_ptr<PBD::Controllable> )> StartLearning;
143  static PBD::Signal<void(std::weak_ptr<PBD::Controllable> )> StopLearning;
144 
145  static PBD::Signal<void(std::weak_ptr<PBD::Controllable> )> GUIFocusChanged;
146  static PBD::Signal<void(std::weak_ptr<PBD::Controllable> )> ControlTouched;
147 
149 
150  int set_state (const XMLNode&, int version);
151  virtual XMLNode& get_state () const;
152 
153  std::string name() const { return _name; }
154 
155  bool touching () const { return _touching; }
157 
158  bool is_toggle() const { return _flags & Toggle; }
159  bool is_gain_like() const { return _flags & GainLike; }
160 
161  virtual double lower() const { return 0.0; }
162  virtual double upper() const { return 1.0; }
163  virtual double normal() const { return 0.0; } //the default value
164 
165  Flag flags() const { return _flags; }
166  void set_flags (Flag f);
167 
168  void set_flag (Flag f);
169  void clear_flag (Flag f);
170 
171  static std::shared_ptr<Controllable> by_id (const PBD::ID&);
172  static void dump_registry ();
174 
175  static const std::string xml_node_name;
176 
177 protected:
178  void set_touching (bool yn) {
179  if (_touching == yn) { return; }
180  _touching = yn;
181  TouchChanged (); /* EMIT SIGNAL */
182  }
183 
184 private:
185  std::string _name;
186  std::string _units;
188  bool _touching;
189 
190  typedef std::set<PBD::Controllable*> Controllables;
191 
195 
196  static void add (Controllable&);
197  static void remove (Controllable*);
198 };
199 
200 }
201 
void set_touching(bool yn)
Definition: controllable.h:178
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:146
void clear_flag(Flag f)
_flags &= ~f;
Flag flags() const
Definition: controllable.h:165
virtual double interface_to_internal(double i, bool rotary=false) const
Definition: controllable.h:129
static ScopedConnectionList registry_connections
Definition: controllable.h:192
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:159
std::string name() const
Definition: controllable.h:153
static PBD::Signal< bool(std::weak_ptr< PBD::Controllable >)> StartLearning
Definition: controllable.h:142
virtual std::string get_user_string() const
Definition: controllable.h:138
std::string _units
Definition: controllable.h:186
std::set< PBD::Controllable * > Controllables
Definition: controllable.h:190
static ControllableSet registered_controllables()
static PBD::RWLock registry_lock
Definition: controllable.h:193
virtual void set_value(double value, GroupControlDisposition group_override)=0
virtual double lower() const
Definition: controllable.h:161
virtual double normal() const
Definition: controllable.h:163
std::string _name
Definition: controllable.h:185
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:156
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:175
static PBD::Signal< void(std::weak_ptr< PBD::Controllable >)> GUIFocusChanged
Definition: controllable.h:145
bool touching() const
Definition: controllable.h:155
static PBD::Signal< void(std::weak_ptr< PBD::Controllable >)> StopLearning
Definition: controllable.h:143
static void add(Controllable &)
void set_flags(Flag f)
static Controllables registry
Definition: controllable.h:194
bool is_toggle() const
Definition: controllable.h:158
void set_flag(Flag f)
_flags |= f;
PBD::Signal< void(bool, PBD::Controllable::GroupControlDisposition)> Changed
Definition: controllable.h:148
virtual double upper() const
Definition: controllable.h:162
PBD::Signal< void()> LearningFinished
Definition: controllable.h:140
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