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