Ardour  9.0-pre0-582-g084a23a80d
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/signals.h"
31 #include <glibmm/threads.h>
32 
33 
35 
36 class XMLNode;
37 
38 namespace PBD {
39 
40 class Controllable;
41 typedef std::set<std::shared_ptr<Controllable>> ControllableSet;
42 
71 class LIBPBD_API Controllable : public PBD::StatefulDestructible, public std::enable_shared_from_this<Controllable>
72 {
73 public:
74  enum Flag {
75  Toggle = 0x01,
76  GainLike = 0x02,
77  RealTime = 0x04,
78  NotAutomatable = 0x08,
79  InlineControl = 0x10,
80  HiddenControl = 0x20,
81  MonitorControl = 0x40,
82  };
83 
84  Controllable (const std::string& name, Flag f = Flag (0));
85 
94  ForGroup
95  };
96 
109  virtual void set_value (double value, GroupControlDisposition group_override) = 0;
110 
114  virtual double get_value (void) const = 0;
115 
121  virtual double get_save_value () const { return get_value(); }
122 
124  virtual double internal_to_interface (double i, bool rotary = false) const {
125  /* by default, the interface range is just a linear
126  * interpolation between lower and upper values */
127  return (i-lower())/(upper() - lower());
128  }
129 
130  virtual double interface_to_internal (double i, bool rotary = false) const {
131  return lower() + i*(upper() - lower());
132  }
133 
135  virtual float get_interface(bool rotary=false) const { return (internal_to_interface(get_value(), rotary)); }
136 
137  virtual void set_interface (float fraction, bool rotary=false, GroupControlDisposition gcd = NoGroup);
138 
139  virtual std::string get_user_string() const { return std::string(); }
140 
142 
143  static PBD::Signal<bool(std::weak_ptr<PBD::Controllable> )> StartLearning;
144  static PBD::Signal<void(std::weak_ptr<PBD::Controllable> )> StopLearning;
145 
146  static PBD::Signal<void(std::weak_ptr<PBD::Controllable> )> GUIFocusChanged;
147  static PBD::Signal<void(std::weak_ptr<PBD::Controllable> )> ControlTouched;
148 
150 
151  int set_state (const XMLNode&, int version);
152  virtual XMLNode& get_state () const;
153 
154  std::string name() const { return _name; }
155 
156  bool touching () const { return _touching; }
158 
159  bool is_toggle() const { return _flags & Toggle; }
160  bool is_gain_like() const { return _flags & GainLike; }
161 
162  virtual double lower() const { return 0.0; }
163  virtual double upper() const { return 1.0; }
164  virtual double normal() const { return 0.0; } //the default value
165 
166  Flag flags() const { return _flags; }
167  void set_flags (Flag f);
168 
169  void set_flag (Flag f);
170  void clear_flag (Flag f);
171 
172  static std::shared_ptr<Controllable> by_id (const PBD::ID&);
173  static void dump_registry ();
175 
176  static const std::string xml_node_name;
177 
178 protected:
179  void set_touching (bool yn) {
180  if (_touching == yn) { return; }
181  _touching = yn;
182  TouchChanged (); /* EMIT SIGNAL */
183  }
184 
185 private:
186  std::string _name;
187  std::string _units;
189  bool _touching;
190 
191  typedef std::set<PBD::Controllable*> Controllables;
192 
194  static Glib::Threads::RWLock registry_lock;
196 
197  static void add (Controllable&);
198  static void remove (Controllable*);
199 };
200 
201 }
202 
void set_touching(bool yn)
Definition: controllable.h:179
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:147
void clear_flag(Flag f)
_flags &= ~f;
Flag flags() const
Definition: controllable.h:166
virtual double interface_to_internal(double i, bool rotary=false) const
Definition: controllable.h:130
static ScopedConnectionList registry_connections
Definition: controllable.h:193
static void remove(Controllable *)
static std::shared_ptr< Controllable > by_id(const PBD::ID &)
virtual double get_save_value() const
Definition: controllable.h:121
bool is_gain_like() const
Definition: controllable.h:160
std::string name() const
Definition: controllable.h:154
static PBD::Signal< bool(std::weak_ptr< PBD::Controllable >)> StartLearning
Definition: controllable.h:143
virtual std::string get_user_string() const
Definition: controllable.h:139
std::string _units
Definition: controllable.h:187
std::set< PBD::Controllable * > Controllables
Definition: controllable.h:191
static ControllableSet registered_controllables()
virtual void set_value(double value, GroupControlDisposition group_override)=0
virtual double lower() const
Definition: controllable.h:162
virtual double normal() const
Definition: controllable.h:164
std::string _name
Definition: controllable.h:186
virtual double get_value(void) const =0
virtual float get_interface(bool rotary=false) const
Definition: controllable.h:135
PBD::Signal< void()> TouchChanged
Definition: controllable.h:157
int set_state(const XMLNode &, int version)
virtual double internal_to_interface(double i, bool rotary=false) const
Definition: controllable.h:124
virtual void set_interface(float fraction, bool rotary=false, GroupControlDisposition gcd=NoGroup)
static const std::string xml_node_name
Definition: controllable.h:176
static PBD::Signal< void(std::weak_ptr< PBD::Controllable >)> GUIFocusChanged
Definition: controllable.h:146
bool touching() const
Definition: controllable.h:156
static PBD::Signal< void(std::weak_ptr< PBD::Controllable >)> StopLearning
Definition: controllable.h:144
static void add(Controllable &)
void set_flags(Flag f)
static Controllables registry
Definition: controllable.h:195
static Glib::Threads::RWLock registry_lock
Definition: controllable.h:194
bool is_toggle() const
Definition: controllable.h:159
void set_flag(Flag f)
_flags |= f;
PBD::Signal< void(bool, PBD::Controllable::GroupControlDisposition)> Changed
Definition: controllable.h:149
virtual double upper() const
Definition: controllable.h:163
PBD::Signal< void()> LearningFinished
Definition: controllable.h:141
Definition: id.h:34
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:40