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