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