2 Copyright (C) 2016 Paul Davis
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.
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.
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.
20 #ifndef __ardour_slavable_automation_control_h__
21 #define __ardour_slavable_automation_control_h__
23 #include "ardour/automation_control.h"
24 #include "ardour/libardour_visibility.h"
28 class LIBARDOUR_API SlavableAutomationControl : public AutomationControl
31 SlavableAutomationControl(ARDOUR::Session&,
32 const Evoral::Parameter& parameter,
33 const ParameterDescriptor& desc,
34 boost::shared_ptr<ARDOUR::AutomationList> l=boost::shared_ptr<ARDOUR::AutomationList>(),
35 const std::string& name="");
37 double get_value () const;
39 void add_master (boost::shared_ptr<AutomationControl>);
40 void remove_master (boost::shared_ptr<AutomationControl>);
41 void clear_masters ();
42 bool slaved_to (boost::shared_ptr<AutomationControl>) const;
44 double get_masters_value () const {
45 Glib::Threads::RWLock::ReaderLock lm (master_lock);
46 return get_masters_value_locked ();
49 /* for toggled/boolean controls, returns a count of the number of
50 masters currently enabled. For other controls, returns zero.
52 int32_t get_boolean_masters () const;
54 std::vector<PBD::ID> masters () const;
56 PBD::Signal0<void> MasterStatusChange;
62 MasterRecord (boost::shared_ptr<AutomationControl> gc, double r)
67 boost::shared_ptr<AutomationControl> master() const { return _master; }
69 /* for boolean/toggled controls, we store a boolean value to
70 * indicate if this master returned true/false (1.0/0.0) from
71 * ::get_value() after its most recent change.
74 bool yn() const { return _yn; }
75 void set_yn (bool yn) { _yn = yn; }
77 /* for non-boolean/non-toggled controls, we store a ratio that
78 * connects the value of the master with the value of this
79 * slave. See comments in the source for more details on how
80 * this is computed and used.
83 double ratio () const { return _ratio; }
84 void reset_ratio (double r) { _ratio = r; }
86 PBD::ScopedConnection connection;
89 boost::shared_ptr<AutomationControl> _master;
96 mutable Glib::Threads::RWLock master_lock;
97 typedef std::map<PBD::ID,MasterRecord> Masters;
99 PBD::ScopedConnectionList masters_connections;
101 void master_going_away (boost::weak_ptr<AutomationControl>);
102 double get_value_locked() const;
103 void actually_set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
104 void update_boolean_masters_records (boost::shared_ptr<AutomationControl>);
106 virtual void master_changed (bool from_self, GroupControlDisposition gcd, boost::shared_ptr<AutomationControl>);
107 virtual void recompute_masters_ratios (double val) { /* do nothing by default */}
108 virtual double get_masters_value_locked () const;
109 virtual void pre_remove_master (boost::shared_ptr<AutomationControl>) {}
110 virtual void post_add_master (boost::shared_ptr<AutomationControl>) {}
115 } // namespace ARDOUR
117 #endif /* __ardour_slavable_automation_control_h__ */