MuteMaster should (a) use a Muteable's own ::muted_by_others_soloing() (b) not try...
[ardour.git] / libs / ardour / mute_master.cc
1 /*
2
3     Copyright (C) 2009 Paul Davis
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
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include "pbd/enumwriter.h"
22 #include "pbd/xml++.h"
23 #include "pbd/convert.h"
24
25 #include "ardour/types.h"
26 #include "ardour/mute_master.h"
27 #include "ardour/session.h"
28
29 #include "pbd/i18n.h"
30
31 using namespace ARDOUR;
32 using namespace std;
33
34 const string MuteMaster::xml_node_name (X_("MuteMaster"));
35
36 const MuteMaster::MutePoint MuteMaster::AllPoints = MuteMaster::MutePoint(
37         PreFader|PostFader|Listen|Main);
38
39 MuteMaster::MuteMaster (Session& s, Muteable& m, const std::string&)
40         : SessionHandleRef (s)
41         , _muteable (&m)
42         , _mute_point (MutePoint (0))
43         , _muted_by_self (false)
44         , _soloed_by_self (false)
45         , _soloed_by_others (false)
46         , _muted_by_masters (0)
47 {
48
49         if (Config->get_mute_affects_pre_fader ()) {
50                 _mute_point = MutePoint (_mute_point | PreFader);
51         }
52
53         if (Config->get_mute_affects_post_fader ()) {
54                 _mute_point = MutePoint (_mute_point | PostFader);
55         }
56
57         if (Config->get_mute_affects_control_outs ()) {
58                 _mute_point = MutePoint (_mute_point | Listen);
59         }
60
61         if (Config->get_mute_affects_main_outs ()) {
62                 _mute_point = MutePoint (_mute_point | Main);
63         }
64 }
65
66 void
67 MuteMaster::mute_at (MutePoint mp)
68 {
69         if ((_mute_point & mp) != mp) {
70                 _mute_point = MutePoint (_mute_point | mp);
71                 MutePointChanged (); // EMIT SIGNAL
72         }
73 }
74
75 void
76 MuteMaster::unmute_at (MutePoint mp)
77 {
78         if ((_mute_point & mp) == mp) {
79                 _mute_point = MutePoint (_mute_point & ~mp);
80                 MutePointChanged (); // EMIT SIGNAL
81         }
82 }
83
84 gain_t
85 MuteMaster::mute_gain_at (MutePoint mp) const
86 {
87         gain_t gain;
88
89         if (Config->get_solo_mute_override()) {
90                 if (_soloed_by_self) {
91                         gain = GAIN_COEFF_UNITY;
92                 } else if (muted_by_self_at (mp) || muted_by_masters_at (mp)) {
93                         gain = GAIN_COEFF_ZERO;
94                 } else {
95                         if (!_soloed_by_others && muted_by_others_soloing_at (mp)) {
96                                 gain = Config->get_solo_mute_gain ();
97                         } else {
98                                 gain = GAIN_COEFF_UNITY;
99                         }
100                 }
101         } else {
102                 if (muted_by_self_at (mp) || muted_by_masters_at (mp)) {
103                         gain = GAIN_COEFF_ZERO;
104                 } else if (_soloed_by_self || _soloed_by_others) {
105                         gain = GAIN_COEFF_UNITY;
106                 } else {
107                         if (muted_by_others_soloing_at (mp)) {
108                                 gain = Config->get_solo_mute_gain ();
109                         } else {
110                                 gain = GAIN_COEFF_UNITY;
111                         }
112                 }
113         }
114
115         return gain;
116 }
117
118 void
119 MuteMaster::set_mute_points (const std::string& mute_point)
120 {
121         MutePoint old = _mute_point;
122
123         _mute_point = (MutePoint) string_2_enum (mute_point, _mute_point);
124
125         if (old != _mute_point) {
126                 MutePointChanged(); /* EMIT SIGNAL */
127         }
128 }
129
130 void
131 MuteMaster::set_mute_points (MutePoint mp)
132 {
133         if (_mute_point != mp) {
134                 _mute_point = mp;
135                 MutePointChanged (); /* EMIT SIGNAL */
136         }
137 }
138
139 int
140 MuteMaster::set_state (const XMLNode& node, int /*version*/)
141 {
142         XMLProperty const * prop;
143
144         if ((prop = node.property ("mute-point")) != 0) {
145                 _mute_point = (MutePoint) string_2_enum (prop->value(), _mute_point);
146         }
147
148         if ((prop = node.property ("muted")) != 0) {
149                 _muted_by_self = PBD::string_is_affirmative (prop->value());
150         } else {
151                 _muted_by_self = (_mute_point != MutePoint (0));
152         }
153
154         return 0;
155 }
156
157 XMLNode&
158 MuteMaster::get_state()
159 {
160         XMLNode* node = new XMLNode (xml_node_name);
161         node->add_property ("mute-point", enum_2_string (_mute_point));
162         node->add_property ("muted", (_muted_by_self ? X_("yes") : X_("no")));
163         return *node;
164 }
165
166 bool
167 MuteMaster::muted_by_others_soloing_at (MutePoint mp) const
168 {
169         return _muteable->muted_by_others_soloing() && (_mute_point & mp);
170 }
171
172 void
173 MuteMaster::set_muted_by_masters (bool yn)
174 {
175         _muted_by_masters = yn;
176 }