provide a real and usable MuteControllable for Routes (so that MIDI can use it)
[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/rc_configuration.h"
27
28 #include "i18n.h"
29
30 using namespace ARDOUR;
31
32 const MuteMaster::MutePoint MuteMaster::AllPoints = MutePoint (MuteMaster::PreFader|
33                                                                MuteMaster::PostFader|
34                                                                MuteMaster::Listen|
35                                                                MuteMaster::Main);
36
37 MuteMaster::MuteMaster (Session& s, const std::string& name)
38         : _mute_point (MutePoint (0))
39 {
40 }
41
42 void
43 MuteMaster::clear_mute ()
44 {
45         if (_mute_point != MutePoint (0)) {
46                 _mute_point = MutePoint (0);
47                 MutePointChanged (); // EMIT SIGNAL
48         }
49 }
50
51 void
52 MuteMaster::mute_at (MutePoint mp)
53 {
54         if ((_mute_point & mp) != mp) {
55                 _mute_point = MutePoint (_mute_point | mp);
56                 MutePointChanged (); // EMIT SIGNAL
57         }
58 }
59
60 void
61 MuteMaster::unmute_at (MutePoint mp)
62 {
63         if ((_mute_point & mp) == mp) {
64                 _mute_point = MutePoint (_mute_point & ~mp);
65                 MutePointChanged (); // EMIT SIGNAL
66         }
67 }
68
69 gain_t
70 MuteMaster::mute_gain_at (MutePoint mp) const
71 {
72         if (_mute_point & mp) {
73                 return Config->get_solo_mute_gain ();
74         } else {
75                 return 1.0;
76         }
77 }
78
79 int
80 MuteMaster::set_state (const XMLNode& node, int /*version*/)
81 {
82         const XMLProperty* prop;
83
84         if ((prop = node.property ("mute-point")) != 0) {
85                 _mute_point = (MutePoint) string_2_enum (prop->value(), _mute_point);
86         }
87
88         return 0;
89 }
90
91 XMLNode&
92 MuteMaster::get_state()
93 {
94         XMLNode* node = new XMLNode (X_("MuteMaster"));
95         node->add_property ("mute-point", enum_2_string (_mute_point));
96         return *node;
97 }