fix crash when copy'ing latent plugins
[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         _session.set_dirty ();
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)
70 {
71         XMLProperty const * prop;
72
73         if ((prop = node.property ("solo-safe")) != 0) {
74                 _solo_safe = string_is_affirmative (prop->value());
75         }
76
77         return 0;
78 }
79
80 XMLNode&
81 SoloSafeControl::get_state ()
82 {
83         XMLNode& node (SlavableAutomationControl::get_state());
84         node.add_property (X_("solo-safe"), _solo_safe ? X_("yes") : X_("no"));
85         return node;
86 }