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