Ardour  9.0-pre0-582-g084a23a80d
slavable_automation_control.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
24 
25 namespace ARDOUR {
26 
28 {
29 public:
31  const Evoral::Parameter& parameter,
32  const ParameterDescriptor& desc,
33  std::shared_ptr<ARDOUR::AutomationList> l=std::shared_ptr<ARDOUR::AutomationList>(),
34  const std::string& name="",
36  );
37 
39 
40  double get_value () const;
41 
42  void add_master (std::shared_ptr<AutomationControl>);
43  void remove_master (std::shared_ptr<AutomationControl>);
44  void clear_masters ();
45  bool slaved_to (std::shared_ptr<AutomationControl>) const;
46  bool slaved () const;
47 
48  std::set<std::shared_ptr<AutomationControl>> masters () const;
49 
50  virtual void automation_run (samplepos_t start, pframes_t nframes);
51 
52  double get_masters_value () const {
53  Glib::Threads::RWLock::ReaderLock lm (master_lock);
54  return get_masters_value_locked ();
55  }
56 
57  /* factor out get_masters_value() */
58  double reduce_by_masters (double val, bool ignore_automation_state = false) const {
59  Glib::Threads::RWLock::ReaderLock lm (master_lock);
60  return reduce_by_masters_locked (val, ignore_automation_state);
61  }
62 
63  bool get_masters_curve (samplepos_t s, samplepos_t e, float* v, samplecnt_t l) const {
64  Glib::Threads::RWLock::ReaderLock lm (master_lock);
65  return get_masters_curve_locked (s, e, v, l);
66  }
67 
68  /* for toggled/boolean controls, returns a count of the number of
69  masters currently enabled. For other controls, returns zero.
70  */
71  int32_t get_boolean_masters () const;
72 
74 
76 
77  int set_state (XMLNode const&, int);
78  XMLNode& get_state() const;
79 
81  {
82  Glib::Threads::RWLock::ReaderLock lm (master_lock);
83  return find_next_event_locked (n, e, ev);
84  }
85 
86  bool find_next_event_locked (Temporal::timepos_t const & now, Temporal::timepos_t const & end, Evoral::ControlEvent& next_event) const;
87 
88 protected:
89 
90  class MasterRecord {
91  public:
92  MasterRecord (std::weak_ptr<AutomationControl> gc, double vc, double vm)
93  : _master (gc)
94  , _yn (false)
95  , _val_ctrl (vc)
96  , _val_master (vm)
97  {}
98 
99  std::shared_ptr<AutomationControl> master() const { assert(_master.lock()); return _master.lock(); }
100 
101  double val_ctrl () const { return _val_ctrl; }
102  double val_master () const { return _val_master; }
103 
104  double val_master_inv () const { return _val_master == 0 ? 0 : 1.0 / _val_master; }
105  double master_ratio () const { return _val_master == 0 ? 0 : master()->get_value() / _val_master; }
106 
107  int set_state (XMLNode const&, int);
108 
109  /* for boolean/toggled controls, we store a boolean value to
110  * indicate if this master returned true/false (1.0/0.0) from
111  * ::get_value() after its most recent change.
112  */
113 
114  bool yn() const { return _yn; }
115  void set_yn (bool yn) { _yn = yn; }
116 
119 
120  private:
121  std::weak_ptr<AutomationControl> _master;
122  /* holds most recently seen master value for boolean/toggle controls */
123  bool _yn;
124 
125  /* values at time of assignment */
126  double _val_ctrl;
127  double _val_master;
128  };
129 
130  mutable Glib::Threads::RWLock master_lock;
131  typedef std::map<PBD::ID,MasterRecord> Masters;
133 
134  void master_going_away (std::weak_ptr<AutomationControl>);
135  double get_value_locked() const;
137  void update_boolean_masters_records (std::shared_ptr<AutomationControl>);
138 
140  bool masters_curve_multiply (timepos_t const &, timepos_t const &, float*, samplecnt_t) const;
141 
142  virtual double reduce_by_masters_locked (double val, bool) const;
143  virtual double scale_automation_callback (double val, double ratio) const;
144 
145  virtual bool handle_master_change (std::shared_ptr<AutomationControl>);
148 
149  virtual void master_changed (bool from_self, GroupControlDisposition gcd, std::weak_ptr<AutomationControl>);
150  virtual double get_masters_value_locked () const;
151  virtual void pre_remove_master (std::shared_ptr<AutomationControl>) {}
152  virtual void post_add_master (std::shared_ptr<AutomationControl>) {}
153 
154  XMLNode* _masters_node; /* used to store master ratios in ::set_state() for later use */
155 };
156 
157 } // namespace ARDOUR
158 
MasterRecord(std::weak_ptr< AutomationControl > gc, double vc, double vm)
std::shared_ptr< AutomationControl > master() const
void actually_set_value(double value, PBD::Controllable::GroupControlDisposition)
void update_boolean_masters_records(std::shared_ptr< AutomationControl >)
bool get_masters_curve(samplepos_t s, samplepos_t e, float *v, samplecnt_t l) const
std::map< PBD::ID, MasterRecord > Masters
virtual void post_add_master(std::shared_ptr< AutomationControl >)
void master_going_away(std::weak_ptr< AutomationControl >)
virtual bool get_masters_curve_locked(samplepos_t, samplepos_t, float *, samplecnt_t) const
bool slaved_to(std::shared_ptr< AutomationControl >) const
bool masters_curve_multiply(timepos_t const &, timepos_t const &, float *, samplecnt_t) const
virtual void pre_remove_master(std::shared_ptr< AutomationControl >)
int set_state(XMLNode const &, int)
virtual void automation_run(samplepos_t start, pframes_t nframes)
bool boolean_automation_run(samplepos_t start, pframes_t len)
SlavableAutomationControl(ARDOUR::Session &, const Evoral::Parameter &parameter, const ParameterDescriptor &desc, std::shared_ptr< ARDOUR::AutomationList > l=std::shared_ptr< ARDOUR::AutomationList >(), const std::string &name="", PBD::Controllable::Flag flags=PBD::Controllable::Flag(0))
virtual bool boolean_automation_run_locked(samplepos_t start, pframes_t len)
bool find_next_event(Temporal::timepos_t const &n, Temporal::timepos_t const &e, Evoral::ControlEvent &ev) const
virtual double get_masters_value_locked() const
void remove_master(std::shared_ptr< AutomationControl >)
virtual double scale_automation_callback(double val, double ratio) const
bool find_next_event_locked(Temporal::timepos_t const &now, Temporal::timepos_t const &end, Evoral::ControlEvent &next_event) const
virtual void master_changed(bool from_self, GroupControlDisposition gcd, std::weak_ptr< AutomationControl >)
virtual bool handle_master_change(std::shared_ptr< AutomationControl >)
std::set< std::shared_ptr< AutomationControl > > masters() const
void add_master(std::shared_ptr< AutomationControl >)
double reduce_by_masters(double val, bool ignore_automation_state=false) const
virtual double reduce_by_masters_locked(double val, bool) const
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
PBD::PropertyDescriptor< timepos_t > start
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t