e565dd33c93708d342cb18f0df62d4f32627b96a
[ardour.git] / libs / ardour / ardour / gain_control.h
1 /*
2     Copyright (C) 2006-2016 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify it
5     under the terms of the GNU General Public License as published by the Free
6     Software Foundation; either version 2 of the License, or (at your option)
7     any later version.
8
9     This program is distributed in the hope that it will be useful, but WITHOUT
10     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12     for more details.
13
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #ifndef __ardour_gain_control_h__
20 #define __ardour_gain_control_h__
21
22 #include <string>
23 #include <map>
24
25 #include <boost/shared_ptr.hpp>
26 #include <glibmm/threads.h>
27
28 #include "pbd/controllable.h"
29
30 #include "evoral/Parameter.hpp"
31
32 #include "ardour/automation_control.h"
33 #include "ardour/libardour_visibility.h"
34
35 namespace ARDOUR {
36
37 class Session;
38
39 class LIBARDOUR_API GainControl : public AutomationControl {
40   public:
41         GainControl (Session& session, const Evoral::Parameter &param,
42                      boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>());
43
44         double get_value () const;
45         void set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
46         void set_value_unchecked (double);
47
48         double internal_to_interface (double) const;
49         double interface_to_internal (double) const;
50         double internal_to_user (double) const;
51         double user_to_internal (double) const;
52         std::string get_user_string () const;
53
54         double lower_db;
55         double range_db;
56
57         gain_t get_master_gain () const;
58         void add_master (boost::shared_ptr<VCA>);
59         void remove_master (boost::shared_ptr<VCA>);
60         void clear_masters ();
61         bool slaved_to (boost::shared_ptr<VCA>) const;
62         bool slaved () const;
63         std::vector<uint32_t> masters () const;
64
65         PBD::Signal0<void> VCAStatusChange;
66
67         int set_state (XMLNode const&, int);
68         XMLNode& get_state();
69
70   private:
71         class MasterRecord {
72           public:
73                 MasterRecord (boost::shared_ptr<AutomationControl> gc, double r)
74                         : _master (gc)
75                         , _ratio (r)
76                 {}
77
78                 boost::shared_ptr<AutomationControl> master() const { return _master; }
79                 double ratio () const { return _ratio; }
80                 void reset_ratio (double r) { _ratio = r; }
81
82                 PBD::ScopedConnection connection;
83
84          private:
85                 boost::shared_ptr<AutomationControl> _master;
86                 double _ratio;
87
88         };
89
90         mutable Glib::Threads::RWLock master_lock;
91         typedef std::map<uint32_t,MasterRecord> Masters;
92         Masters _masters;
93         PBD::ScopedConnectionList masters_connections;
94         std::string masters_string;
95         PBD::ScopedConnection vca_loaded_connection;
96
97         gain_t get_value_locked () const;
98         gain_t get_master_gain_locked () const;
99         void master_going_away (boost::weak_ptr<VCA>);
100         void recompute_masters_ratios (double val);
101         void vcas_loaded();
102
103         void _set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
104 };
105
106 } /* namespace */
107
108 #endif /* __ardour_gain_control_h__ */