bring back full mute control (pre/post/control/main) via mute button context click
[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
23 #include "ardour/mute_master.h"
24 #include "ardour/rc_configuration.h"
25
26 #include "i18n.h"
27
28 using namespace ARDOUR;
29
30 const MuteMaster::MutePoint MuteMaster::AllPoints = MutePoint (MuteMaster::PreFader|
31                                                                MuteMaster::PostFader|
32                                                                MuteMaster::Listen|
33                                                                MuteMaster::Main);
34
35 MuteMaster::MuteMaster (Session& s, const std::string& name)
36         : AutomationControl (s, Evoral::Parameter (MuteAutomation), boost::shared_ptr<AutomationList>(), name)
37         , _mute_point (MutePoint (0))
38 {
39         // default range for parameter is fine
40
41         _automation = new AutomationList (MuteAutomation);
42         set_list (boost::shared_ptr<AutomationList>(_automation));
43 }
44
45 void
46 MuteMaster::clear_mute ()
47 {
48         if (_mute_point != MutePoint (0)) {
49                 _mute_point = MutePoint (0);
50                 MutePointChanged (); // EMIT SIGNAL
51         }
52 }
53
54 void
55 MuteMaster::mute_at (MutePoint mp)
56 {
57         if ((_mute_point & mp) != mp) {
58                 _mute_point = MutePoint (_mute_point | mp);
59                 MutePointChanged (); // EMIT SIGNAL
60         }
61 }
62
63 void
64 MuteMaster::unmute_at (MutePoint mp)
65 {
66         if ((_mute_point & mp) == mp) {
67                 _mute_point = MutePoint (_mute_point & ~mp);
68                 MutePointChanged (); // EMIT SIGNAL
69         }
70 }
71
72 void
73 MuteMaster::mute (bool yn)
74 {
75         /* convenience wrapper around AutomationControl method */
76
77         if (yn) {
78                 set_value ((float) 0xffff);
79         } else {
80                 set_value (0.0f);
81         }
82 }
83
84 gain_t
85 MuteMaster::mute_gain_at (MutePoint mp) const
86 {
87         if (_mute_point & mp) {
88                 return Config->get_solo_mute_gain ();
89         } else {
90                 return 1.0;
91         }
92 }
93
94 void
95 MuteMaster::set_value (float f)
96 {
97         MutePoint old = _mute_point;
98         _mute_point = (MutePoint) (rint (f));
99         if (old != _mute_point) {
100                 MutePointChanged (); // EMIT SIGNAL
101         }
102 }
103
104 float
105 MuteMaster::get_value () const
106 {
107         return (float) _mute_point;
108 }
109
110 int
111 MuteMaster::set_state (const XMLNode& node, int /*version*/)
112 {
113         const XMLProperty* prop;
114
115         if ((prop = node.property ("mute-point")) != 0) {
116                 _mute_point = (MutePoint) string_2_enum (prop->value(), _mute_point);
117         }
118
119         return 0;
120 }
121
122 XMLNode&
123 MuteMaster::get_state()
124 {
125         XMLNode* node = new XMLNode (X_("MuteMaster"));
126         node->add_property ("mute-point", enum_2_string (_mute_point));
127         return *node;
128 }