better comments
[ardour.git] / libs / ardour / solo_safe_control.cc
1 /*
2  * Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #include "ardour/debug.h"
21 #include "ardour/mute_master.h"
22 #include "ardour/session.h"
23 #include "ardour/solo_isolate_control.h"
24
25 #include "pbd/i18n.h"
26
27 using namespace ARDOUR;
28 using namespace std;
29 using namespace PBD;
30
31 SoloSafeControl::SoloSafeControl (Session& session, std::string const & name)
32         : SlavableAutomationControl (session, SoloSafeAutomation, ParameterDescriptor (SoloSafeAutomation),
33                                      boost::shared_ptr<AutomationList>(new AutomationList(Evoral::Parameter(SoloSafeAutomation))),
34                                      name)
35         , _solo_safe (false)
36 {
37         _list->set_interpolation(Evoral::ControlList::Discrete);
38 }
39
40 void
41 SoloSafeControl::actually_set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
42 {
43         _solo_safe = (val ? true : false);
44
45         /* this sets the Evoral::Control::_user_value for us, which will
46            be retrieved by AutomationControl::get_value (), and emits Changed
47         */
48
49         AutomationControl::actually_set_value (val, gcd);
50 }
51
52 double
53 SoloSafeControl::get_value () const
54 {
55         if (slaved()) {
56                 Glib::Threads::RWLock::ReaderLock lm (master_lock);
57                 return get_masters_value_locked () ? 1.0 : 0.0;
58         }
59
60         if (_list && boost::dynamic_pointer_cast<AutomationList>(_list)->automation_playback()) {
61                 // Playing back automation, get the value from the list
62                 return AutomationControl::get_value();
63         }
64
65         return _solo_safe ? 1.0 : 0.0;
66 }
67
68 int
69 SoloSafeControl::set_state (XMLNode const & node, int version)
70 {
71         if (SlavableAutomationControl::set_state(node, version)) {
72                 return -1;
73         }
74
75         node.get_property ("solo-safe", _solo_safe);
76         return 0;
77 }
78
79 XMLNode&
80 SoloSafeControl::get_state ()
81 {
82         XMLNode& node (SlavableAutomationControl::get_state());
83         node.set_property (X_("solo-safe"), _solo_safe);
84         return node;
85 }