summaryrefslogtreecommitdiff
path: root/libs/ardour/solo_safe_control.cc
blob: 971b97033dd224659d47445c3a925d78fe6a1d97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
    Copyright (C) 2016 Paul Davis

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the Free
    Software Foundation; either version 2 of the License, or (at your option)
    any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "ardour/debug.h"
#include "ardour/mute_master.h"
#include "ardour/session.h"
#include "ardour/solo_isolate_control.h"

#include "pbd/i18n.h"

using namespace ARDOUR;
using namespace std;
using namespace PBD;

SoloSafeControl::SoloSafeControl (Session& session, std::string const & name)
	: SlavableAutomationControl (session, SoloSafeAutomation, ParameterDescriptor (SoloSafeAutomation),
	                             boost::shared_ptr<AutomationList>(new AutomationList(Evoral::Parameter(SoloSafeAutomation))),
	                             name)
	, _solo_safe (false)
{
	_list->set_interpolation(Evoral::ControlList::Discrete);
}

void
SoloSafeControl::actually_set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
{
	_solo_safe = (val ? true : false);

	/* this sets the Evoral::Control::_user_value for us, which will
	   be retrieved by AutomationControl::get_value (), and emits Changed
	*/

	AutomationControl::actually_set_value (val, gcd);
}

double
SoloSafeControl::get_value () const
{
	if (slaved()) {
		Glib::Threads::RWLock::ReaderLock lm (master_lock);
		return get_masters_value_locked () ? 1.0 : 0.0;
	}

	if (_list && boost::dynamic_pointer_cast<AutomationList>(_list)->automation_playback()) {
		// Playing back automation, get the value from the list
		return AutomationControl::get_value();
	}

	return _solo_safe ? 1.0 : 0.0;
}

int
SoloSafeControl::set_state (XMLNode const & node, int version)
{
	if (SlavableAutomationControl::set_state(node, version)) {
		return -1;
	}

	XMLProperty const * prop;

	if ((prop = node.property ("solo-safe")) != 0) {
		_solo_safe = string_is_affirmative (prop->value());
	}

	return 0;
}

XMLNode&
SoloSafeControl::get_state ()
{
	XMLNode& node (SlavableAutomationControl::get_state());
	node.add_property (X_("solo-safe"), _solo_safe ? X_("yes") : X_("no"));
	return node;
}