move ownership of an RT MIDI buffer from DiskIO to MidiPlaylist
[ardour.git] / libs / ardour / mute_master.cc
1 /*
2  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2009-2015 David Robillard <d@drobilla.net>
4  * Copyright (C) 2009-2016 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include "pbd/enumwriter.h"
23 #include "pbd/xml++.h"
24 #include "pbd/enum_convert.h"
25
26 #include "ardour/types.h"
27 #include "ardour/mute_master.h"
28 #include "ardour/session.h"
29
30 #include "pbd/i18n.h"
31
32 namespace PBD {
33         DEFINE_ENUM_CONVERT(ARDOUR::MuteMaster::MutePoint);
34 }
35
36 using namespace ARDOUR;
37 using namespace std;
38
39 const string MuteMaster::xml_node_name (X_("MuteMaster"));
40
41 const MuteMaster::MutePoint MuteMaster::AllPoints = MuteMaster::MutePoint(
42         PreFader|PostFader|Listen|Main);
43
44 MuteMaster::MuteMaster (Session& s, Muteable& m, const std::string&)
45         : SessionHandleRef (s)
46         , _muteable (&m)
47         , _mute_point (MutePoint (0))
48         , _muted_by_self (false)
49         , _soloed_by_self (false)
50         , _soloed_by_others (false)
51         , _muted_by_masters (0)
52 {
53
54         if (Config->get_mute_affects_pre_fader ()) {
55                 _mute_point = MutePoint (_mute_point | PreFader);
56         }
57
58         if (Config->get_mute_affects_post_fader ()) {
59                 _mute_point = MutePoint (_mute_point | PostFader);
60         }
61
62         if (Config->get_mute_affects_control_outs ()) {
63                 _mute_point = MutePoint (_mute_point | Listen);
64         }
65
66         if (Config->get_mute_affects_main_outs ()) {
67                 _mute_point = MutePoint (_mute_point | Main);
68         }
69 }
70
71 void
72 MuteMaster::mute_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::unmute_at (MutePoint mp)
82 {
83         if ((_mute_point & mp) == mp) {
84                 _mute_point = MutePoint (_mute_point & ~mp);
85                 MutePointChanged (); // EMIT SIGNAL
86         }
87 }
88
89 gain_t
90 MuteMaster::mute_gain_at (MutePoint mp) const
91 {
92         gain_t gain;
93
94         if (Config->get_solo_mute_override()) {
95                 if (_soloed_by_self) {
96                         gain = GAIN_COEFF_UNITY;
97                 } else if (muted_by_self_at (mp) || muted_by_masters_at (mp)) {
98                         gain = GAIN_COEFF_ZERO;
99                 } else {
100                         if (!_soloed_by_others && muted_by_others_soloing_at (mp)) {
101                                 gain = Config->get_solo_mute_gain ();
102                         } else {
103                                 gain = GAIN_COEFF_UNITY;
104                         }
105                 }
106         } else {
107                 if (muted_by_self_at (mp) || muted_by_masters_at (mp)) {
108                         gain = GAIN_COEFF_ZERO;
109                 } else if (_soloed_by_self || _soloed_by_others) {
110                         gain = GAIN_COEFF_UNITY;
111                 } else {
112                         if (muted_by_others_soloing_at (mp)) {
113                                 gain = Config->get_solo_mute_gain ();
114                         } else {
115                                 gain = GAIN_COEFF_UNITY;
116                         }
117                 }
118         }
119
120         return gain;
121 }
122
123 void
124 MuteMaster::set_mute_points (const std::string& mute_point)
125 {
126         MutePoint old = _mute_point;
127
128         _mute_point = (MutePoint) string_2_enum (mute_point, _mute_point);
129
130         if (old != _mute_point) {
131                 MutePointChanged(); /* EMIT SIGNAL */
132         }
133 }
134
135 void
136 MuteMaster::set_mute_points (MutePoint mp)
137 {
138         if (_mute_point != mp) {
139                 _mute_point = mp;
140                 MutePointChanged (); /* EMIT SIGNAL */
141         }
142 }
143
144 int
145 MuteMaster::set_state (const XMLNode& node, int /*version*/)
146 {
147         node.get_property ("mute-point", _mute_point);
148
149         if (!node.get_property ("muted", _muted_by_self)) {
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 (xml_node_name);
160         node->set_property ("mute-point", _mute_point);
161         node->set_property ("muted", _muted_by_self);
162         return *node;
163 }
164
165 bool
166 MuteMaster::muted_by_others_soloing_at (MutePoint mp) const
167 {
168         return _muteable->muted_by_others_soloing() && (_mute_point & mp);
169 }
170
171 void
172 MuteMaster::set_muted_by_masters (bool yn)
173 {
174         _muted_by_masters = yn;
175 }