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