move vca assignment up to the Route level (from GainControl)
[ardour.git] / libs / ardour / ardour / vca.h
1 /*
2     Copyright (C) 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_vca_h__
20 #define __ardour_vca_h__
21
22 #include <string>
23 #include <boost/shared_ptr.hpp>
24 #include <boost/enable_shared_from_this.hpp>
25
26 #include "pbd/controllable.h"
27 #include "pbd/statefuldestructible.h"
28
29 #include "ardour/automatable.h"
30 #include "ardour/stripable.h"
31
32 namespace ARDOUR {
33
34 class GainControl;
35 class Route;
36
37 class LIBARDOUR_API VCA : public Stripable, public Automatable, public boost::enable_shared_from_this<VCA> {
38   public:
39         VCA (Session& session,  uint32_t num, const std::string& name);
40         ~VCA();
41
42         uint32_t number () const { return _number; }
43         uint32_t remote_control_id() const;
44
45         int init ();
46         XMLNode& get_state();
47         int set_state (XMLNode const&, int version);
48
49         void add_solo_target (boost::shared_ptr<Route>);
50         void remove_solo_target (boost::shared_ptr<Route>);
51         void add_mute_target (boost::shared_ptr<Route>);
52         void remove_mute_target (boost::shared_ptr<Route>);
53
54         bool soloed () const;
55         bool muted () const;
56
57         static std::string default_name_template ();
58         static int next_vca_number ();
59         static std::string xml_node_name;
60
61         /* used by Session to save/restore the atomic counter */
62         static uint32_t get_next_vca_number ();
63         static void set_next_vca_number (uint32_t);
64
65         virtual boost::shared_ptr<GainControl> gain_control() const { return _gain_control; }
66         virtual boost::shared_ptr<AutomationControl> solo_control() const { return _solo_control; }
67         virtual boost::shared_ptr<AutomationControl> mute_control() const { return _mute_control; }
68
69         /* null Stripable API, because VCAs don't have any of this */
70
71         virtual boost::shared_ptr<PeakMeter>       peak_meter() { return boost::shared_ptr<PeakMeter>(); }
72         virtual boost::shared_ptr<const PeakMeter> peak_meter() const { return boost::shared_ptr<PeakMeter>(); }
73         virtual boost::shared_ptr<AutomationControl> phase_control() const { return boost::shared_ptr<AutomationControl>(); }
74         virtual boost::shared_ptr<AutomationControl> trim_control() const { return boost::shared_ptr<AutomationControl>(); }
75         virtual boost::shared_ptr<AutomationControl> monitoring_control() const { return boost::shared_ptr<AutomationControl>(); }
76         virtual boost::shared_ptr<AutomationControl> recenable_control() const { return boost::shared_ptr<AutomationControl>(); }
77         virtual boost::shared_ptr<AutomationControl> pan_azimuth_control() const { return boost::shared_ptr<AutomationControl>(); }
78         virtual boost::shared_ptr<AutomationControl> pan_elevation_control() const { return boost::shared_ptr<AutomationControl>(); }
79         virtual boost::shared_ptr<AutomationControl> pan_width_control() const { return boost::shared_ptr<AutomationControl>(); }
80         virtual boost::shared_ptr<AutomationControl> pan_frontback_control() const { return boost::shared_ptr<AutomationControl>(); }
81         virtual boost::shared_ptr<AutomationControl> pan_lfe_control() const { return boost::shared_ptr<AutomationControl>(); }
82         virtual uint32_t eq_band_cnt () const { return 0; }
83         virtual std::string eq_band_name (uint32_t) const { return std::string(); }
84         virtual boost::shared_ptr<AutomationControl> eq_gain_controllable (uint32_t band) const { return boost::shared_ptr<AutomationControl>(); }
85         virtual boost::shared_ptr<AutomationControl> eq_freq_controllable (uint32_t band) const { return boost::shared_ptr<AutomationControl>(); }
86         virtual boost::shared_ptr<AutomationControl> eq_q_controllable (uint32_t band) const { return boost::shared_ptr<AutomationControl>(); }
87         virtual boost::shared_ptr<AutomationControl> eq_shape_controllable (uint32_t band) const { return boost::shared_ptr<AutomationControl>(); }
88         virtual boost::shared_ptr<AutomationControl> eq_enable_controllable () const { return boost::shared_ptr<AutomationControl>(); }
89         virtual boost::shared_ptr<AutomationControl> eq_hpf_controllable () const { return boost::shared_ptr<AutomationControl>(); }
90         virtual boost::shared_ptr<AutomationControl> comp_enable_controllable () const { return boost::shared_ptr<AutomationControl>(); }
91         virtual boost::shared_ptr<AutomationControl> comp_threshold_controllable () const { return boost::shared_ptr<AutomationControl>(); }
92         virtual boost::shared_ptr<AutomationControl> comp_speed_controllable () const { return boost::shared_ptr<AutomationControl>(); }
93         virtual boost::shared_ptr<AutomationControl> comp_mode_controllable () const { return boost::shared_ptr<AutomationControl>(); }
94         virtual boost::shared_ptr<AutomationControl> comp_makeup_controllable () const { return boost::shared_ptr<AutomationControl>(); }
95         virtual boost::shared_ptr<AutomationControl> comp_redux_controllable () const { return boost::shared_ptr<AutomationControl>(); }
96         virtual std::string comp_mode_name (uint32_t mode) const { return std::string(); }
97         virtual std::string comp_speed_name (uint32_t mode) const { return std::string(); }
98         virtual boost::shared_ptr<AutomationControl> send_level_controllable (uint32_t n) const { return boost::shared_ptr<AutomationControl>(); }
99         virtual boost::shared_ptr<AutomationControl> send_enable_controllable (uint32_t n) const { return boost::shared_ptr<AutomationControl>(); }
100         virtual std::string send_name (uint32_t n) const { return std::string(); }
101         virtual boost::shared_ptr<AutomationControl> master_send_enable_controllable () const { return boost::shared_ptr<AutomationControl>(); }
102
103   private:
104         class VCASoloControllable : public AutomationControl {
105           public:
106                 VCASoloControllable (std::string const & name, boost::shared_ptr<VCA> vca);
107                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
108                 void set_value_unchecked (double);
109                 double get_value () const;
110           private:
111                 void _set_value (double, PBD::Controllable::GroupControlDisposition group_override);
112                 boost::weak_ptr<VCA> _vca;
113         };
114
115         class VCAMuteControllable : public AutomationControl {
116           public:
117                 VCAMuteControllable (std::string const & name, boost::shared_ptr<VCA> vca);
118                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
119                 void set_value_unchecked (double);
120                 double get_value () const;
121           private:
122                 void _set_value (double, PBD::Controllable::GroupControlDisposition group_override);
123                 boost::weak_ptr<VCA> _vca;
124         };
125
126         friend class VCASoloControllable;
127         friend class VCAMuteControllable;
128
129         uint32_t    _number;
130
131         RouteList solo_targets;
132         PBD::ScopedConnectionList solo_connections;
133         mutable Glib::Threads::RWLock solo_lock;
134
135         RouteList mute_targets;
136         PBD::ScopedConnectionList mute_connections;
137         mutable Glib::Threads::RWLock mute_lock;
138
139         boost::shared_ptr<GainControl> _gain_control;
140         boost::shared_ptr<VCASoloControllable> _solo_control;
141         boost::shared_ptr<VCAMuteControllable> _mute_control;
142         bool _solo_requested;
143         bool _mute_requested;
144
145         static gint next_number;
146
147         void solo_target_going_away (boost::weak_ptr<Route>);
148         void mute_target_going_away (boost::weak_ptr<Route>);
149         bool soloed_locked () const;
150         bool muted_locked () const;
151
152         void set_solo (bool yn);
153         void set_mute (bool yn);
154
155 };
156
157 } /* namespace */
158
159 #endif /* __ardour_vca_h__ */