Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[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 MuteMaster::MuteMaster (Session& s, const std::string& name)
31         : AutomationControl (s, Evoral::Parameter (MuteAutomation), boost::shared_ptr<AutomationList>(), name)
32         , _mute_point (MutePoint (0))
33 {
34         // default range for parameter is fine
35
36         _automation = new AutomationList (MuteAutomation);
37         set_list (boost::shared_ptr<AutomationList>(_automation));
38 }
39
40 void
41 MuteMaster::clear_mute ()
42 {
43         if (_mute_point != MutePoint (0)) {
44                 _mute_point = MutePoint (0);
45                 MutePointChanged (); // EMIT SIGNAL
46         }
47 }
48
49 void
50 MuteMaster::mute_at (MutePoint mp)
51 {
52         if ((_mute_point & mp) != mp) {
53                 _mute_point = MutePoint (_mute_point | mp);
54                 MutePointChanged (); // EMIT SIGNAL
55         }
56 }
57
58 void
59 MuteMaster::unmute_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::mute (bool yn)
69 {
70         /* convenience wrapper around AutomationControl method */
71
72         if (yn) {
73                 set_value ((float) 0xffff);
74         } else {
75                 set_value (0.0f);
76         }
77 }
78
79 gain_t
80 MuteMaster::mute_gain_at (MutePoint mp) const
81 {
82         if (_mute_point & mp) {
83                 return Config->get_solo_mute_gain ();
84         } else {
85                 return 1.0;
86         }
87 }
88
89 void
90 MuteMaster::set_value (float f)
91 {
92         MutePoint old = _mute_point;
93         _mute_point = (MutePoint) (rint (f));
94         if (old != _mute_point) {
95                 MutePointChanged (); // EMIT SIGNAL
96         }
97 }
98
99 float
100 MuteMaster::get_value () const
101 {
102         return (float) _mute_point;
103 }
104
105 int
106 MuteMaster::set_state (const XMLNode& node)
107 {
108         const XMLProperty* prop;
109
110         if ((prop = node.property ("mute-point")) != 0) {
111                 _mute_point = (MutePoint) string_2_enum (prop->value(), _mute_point);
112         }
113
114         return 0;
115 }
116
117 XMLNode&
118 MuteMaster::get_state()
119 {
120         XMLNode* node = new XMLNode (X_("MuteMaster"));
121         node->add_property ("mute-point", enum_2_string (_mute_point));
122         return *node;
123 }