SiP and "solo overrides mutes" tweak:
[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 "i18n.h"
30
31 using namespace ARDOUR;
32 using namespace std;
33
34 const MuteMaster::MutePoint MuteMaster::AllPoints = MuteMaster::MutePoint(
35         PreFader|PostFader|Listen|Main);
36
37 MuteMaster::MuteMaster (Session& s, const std::string&)
38         : SessionHandleRef (s)
39         , _mute_point (MutePoint (0))
40         , _muted_by_self (false)
41         , _soloed_by_self (false)
42         , _soloed_by_others (false)
43         , _solo_ignore (false)
44 {
45
46         if (Config->get_mute_affects_pre_fader ()) {
47                 _mute_point = MutePoint (_mute_point | PreFader);
48         }
49
50         if (Config->get_mute_affects_post_fader ()) {
51                 _mute_point = MutePoint (_mute_point | PostFader);
52         }
53
54         if (Config->get_mute_affects_control_outs ()) {
55                 _mute_point = MutePoint (_mute_point | Listen);
56         }
57
58         if (Config->get_mute_affects_main_outs ()) {
59                 _mute_point = MutePoint (_mute_point | Main);
60         }
61 }
62
63 void
64 MuteMaster::mute_at (MutePoint mp)
65 {
66         if ((_mute_point & mp) != mp) {
67                 _mute_point = MutePoint (_mute_point | mp);
68                 MutePointChanged (); // EMIT SIGNAL
69         }
70 }
71
72 void
73 MuteMaster::unmute_at (MutePoint mp)
74 {
75         if ((_mute_point & mp) == mp) {
76                 _mute_point = MutePoint (_mute_point & ~mp);
77                 MutePointChanged (); // EMIT SIGNAL
78         }
79 }
80
81 gain_t
82 MuteMaster::mute_gain_at (MutePoint mp) const
83 {
84         gain_t gain;
85
86         if (Config->get_solo_mute_override()) {
87                 if (_soloed_by_self) {
88                         gain = GAIN_COEFF_UNITY;
89                 } else if (muted_by_self_at (mp)) {
90                         gain = GAIN_COEFF_ZERO;
91                 } else {
92                         if (muted_by_others_at (mp) && !_soloed_by_others) {
93                                 gain = Config->get_solo_mute_gain ();
94                         } else {
95                                 gain = GAIN_COEFF_UNITY;
96                         }
97                 }
98         } else {
99                 if (muted_by_self_at (mp)) {
100                         gain = GAIN_COEFF_ZERO;
101                 } else if (_soloed_by_self || _soloed_by_others) {
102                         gain = GAIN_COEFF_UNITY;
103                 } else {
104                         if (muted_by_others_at (mp)) {
105                                 gain = Config->get_solo_mute_gain ();
106                         } else {
107                                 gain = GAIN_COEFF_UNITY;
108                         }
109                 }
110         }
111
112         return gain;
113 }
114
115 void
116 MuteMaster::set_mute_points (const std::string& mute_point)
117 {
118         MutePoint old = _mute_point;
119
120         _mute_point = (MutePoint) string_2_enum (mute_point, _mute_point);
121
122         if (old != _mute_point) {
123                 MutePointChanged(); /* EMIT SIGNAL */
124         }
125 }
126
127 void
128 MuteMaster::set_mute_points (MutePoint mp)
129 {
130         if (_mute_point != mp) {
131                 _mute_point = mp;
132                 MutePointChanged (); /* EMIT SIGNAL */
133         }
134 }
135
136 int
137 MuteMaster::set_state (const XMLNode& node, int /*version*/)
138 {
139         const XMLProperty* prop;
140
141         if ((prop = node.property ("mute-point")) != 0) {
142                 _mute_point = (MutePoint) string_2_enum (prop->value(), _mute_point);
143         }
144
145         if ((prop = node.property ("muted")) != 0) {
146                 _muted_by_self = PBD::string_is_affirmative (prop->value());
147         } else {
148                 _muted_by_self = (_mute_point != MutePoint (0));
149         }
150
151         return 0;
152 }
153
154 XMLNode&
155 MuteMaster::get_state()
156 {
157         XMLNode* node = new XMLNode (X_("MuteMaster"));
158         node->add_property ("mute-point", enum_2_string (_mute_point));
159         node->add_property ("muted", (_muted_by_self ? X_("yes") : X_("no")));
160         return *node;
161 }
162
163 bool
164 MuteMaster::muted_by_others_at (MutePoint mp) const
165 {
166         return (!_solo_ignore && _session.soloing() && (_mute_point & mp));
167 }
168