Fix a tiny memory-leak when calling vfork
[ardour.git] / libs / ardour / solo_safe_control.cc
1 /*
2     Copyright (C) 2016 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify it
5     under the terms of the GNU General Public License as published by the Free
6     Software Foundation; either version 2 of the License, or (at your option)
7     any later version.
8
9     This program is distributed in the hope that it will be useful, but WITHOUT
10     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12     for more details.
13
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include "ardour/debug.h"
20 #include "ardour/mute_master.h"
21 #include "ardour/session.h"
22 #include "ardour/solo_isolate_control.h"
23
24 #include "pbd/i18n.h"
25
26 using namespace ARDOUR;
27 using namespace std;
28 using namespace PBD;
29
30 SoloSafeControl::SoloSafeControl (Session& session, std::string const & name)
31         : SlavableAutomationControl (session, SoloSafeAutomation, ParameterDescriptor (SoloSafeAutomation),
32                                      boost::shared_ptr<AutomationList>(new AutomationList(Evoral::Parameter(SoloSafeAutomation))),
33                                      name)
34         , _solo_safe (false)
35 {
36         _list->set_interpolation(Evoral::ControlList::Discrete);
37 }
38
39 void
40 SoloSafeControl::actually_set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
41 {
42         _solo_safe = (val ? true : false);
43
44         /* this sets the Evoral::Control::_user_value for us, which will
45            be retrieved by AutomationControl::get_value (), and emits Changed
46         */
47
48         AutomationControl::actually_set_value (val, gcd);
49 }
50
51 double
52 SoloSafeControl::get_value () const
53 {
54         if (slaved()) {
55                 Glib::Threads::RWLock::ReaderLock lm (master_lock);
56                 return get_masters_value_locked () ? 1.0 : 0.0;
57         }
58
59         if (_list && boost::dynamic_pointer_cast<AutomationList>(_list)->automation_playback()) {
60                 // Playing back automation, get the value from the list
61                 return AutomationControl::get_value();
62         }
63
64         return _solo_safe ? 1.0 : 0.0;
65 }
66
67 int
68 SoloSafeControl::set_state (XMLNode const & node, int version)
69 {
70         if (SlavableAutomationControl::set_state(node, version)) {
71                 return -1;
72         }
73
74         node.get_property ("solo-safe", _solo_safe);
75         return 0;
76 }
77
78 XMLNode&
79 SoloSafeControl::get_state ()
80 {
81         XMLNode& node (SlavableAutomationControl::get_state());
82         node.set_property (X_("solo-safe"), _solo_safe);
83         return node;
84 }