ca64fb01a591ae318fbe4df28a59ab3a2d520874
[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 "ardour/mute_master.h"
22 #include "ardour/rc_configuration.h"
23
24 #include "i18n.h"
25
26 using namespace ARDOUR;
27
28 MuteMaster::MuteMaster (Session& s, const std::string& name)
29         : AutomationControl (s, Evoral::Parameter (MuteAutomation), boost::shared_ptr<AutomationList>(), name)
30         , _mute_point (MutePoint (0))
31 {
32         // default range for parameter is fine
33
34         _automation = new AutomationList (MuteAutomation);
35         set_list (boost::shared_ptr<AutomationList>(_automation));
36 }
37
38 void
39 MuteMaster::clear_mute ()
40 {
41         if (_mute_point != MutePoint (0)) {
42                 _mute_point = MutePoint (0);
43                 MutePointChanged (); // EMIT SIGNAL
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::mute (bool yn)
67 {
68         /* convenience wrapper around AutomationControl method */
69
70         if (yn) {
71                 set_value (1.0f);
72         } else {
73                 set_value (0.0f);
74         }
75 }
76
77 gain_t
78 MuteMaster::mute_gain_at (MutePoint mp) const
79 {
80         if (_mute_point & mp) {
81                 return Config->get_solo_mute_gain ();
82         } else {
83                 return 1.0;
84         }
85 }
86
87 void
88 MuteMaster::set_value (float f)
89 {
90         mute_at ((MutePoint) ((int) rint (f)));
91 }
92
93 float
94 MuteMaster::get_value () const
95 {
96         return (float) _mute_point;
97 }
98
99 int
100 MuteMaster::set_state (const XMLNode& node)
101 {
102         return 0;
103 }
104
105 XMLNode&
106 MuteMaster::get_state()
107 {
108         return *(new XMLNode (X_("MuteMaster")));
109 }