2 Copyright (C) 2016 Paul Davis
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)
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
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.
19 #include "ardour/debug.h"
20 #include "ardour/mute_master.h"
21 #include "ardour/session.h"
22 #include "ardour/solo_control.h"
26 using namespace ARDOUR;
30 SoloControl::SoloControl (Session& session, std::string const & name, Soloable& s, Muteable& m)
31 : SlavableAutomationControl (session, SoloAutomation, ParameterDescriptor (SoloAutomation),
32 boost::shared_ptr<AutomationList>(new AutomationList(Evoral::Parameter(SoloAutomation))),
37 , _soloed_by_others_upstream (0)
38 , _soloed_by_others_downstream (0)
40 _list->set_interpolation (Evoral::ControlList::Discrete);
41 /* solo changes must be synchronized by the process cycle */
42 set_flags (Controllable::Flag (flags() | Controllable::RealTime));
46 SoloControl::set_self_solo (bool yn)
48 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
50 set_mute_master_solo ();
54 SoloControl::set_mute_master_solo ()
56 _muteable.mute_master()->set_soloed_by_self (self_soloed());
58 if (Config->get_solo_control_is_listen_control()) {
59 _muteable.mute_master()->set_soloed_by_others (false);
61 _muteable.mute_master()->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
66 SoloControl::mod_solo_by_others_downstream (int32_t delta)
68 if (_soloable.is_safe() || !_soloable.can_solo()) {
72 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
73 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
76 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
77 _soloed_by_others_downstream += delta;
79 _soloed_by_others_downstream = 0;
82 _soloed_by_others_downstream += delta;
85 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
87 set_mute_master_solo ();
88 Changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
92 SoloControl::mod_solo_by_others_upstream (int32_t delta)
94 if (_soloable.is_safe() || !_soloable.can_solo()) {
98 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
99 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
101 uint32_t old_sbu = _soloed_by_others_upstream;
104 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
105 _soloed_by_others_upstream += delta;
107 _soloed_by_others_upstream = 0;
110 _soloed_by_others_upstream += delta;
113 DEBUG_TRACE (DEBUG::Solo, string_compose (
114 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
115 name(), delta, _soloed_by_others_upstream, old_sbu,
116 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
119 /* push the inverse solo change to everything that feeds us.
121 This is important for solo-within-group. When we solo 1 track out of N that
122 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
123 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
124 tracks that feed it. This will silence them if they were audible because
125 of a bus solo, but the newly soloed track will still be audible (because
128 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
132 if ((_self_solo || _soloed_by_others_downstream) &&
133 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
134 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
136 if (delta > 0 || !Config->get_exclusive_solo()) {
137 _soloable.push_solo_upstream (delta);
141 set_mute_master_solo ();
142 Changed (false, Controllable::NoGroup); /* EMIT SIGNAL */
146 SoloControl::actually_set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
148 if (_soloable.is_safe() || !_soloable.can_solo()) {
152 set_self_solo (val == 1.0);
154 /* this sets the Evoral::Control::_user_value for us, which will
155 be retrieved by AutomationControl::get_value (), and emits Changed
158 SlavableAutomationControl::actually_set_value (val, group_override);
162 SoloControl::get_value () const
165 Glib::Threads::RWLock::ReaderLock lm (master_lock);
166 return get_masters_value_locked () ? 1.0 : 0.0;
169 if (_list && boost::dynamic_pointer_cast<AutomationList>(_list)->automation_playback()) {
170 // Playing back automation, get the value from the list
171 return AutomationControl::get_value();
174 return self_soloed() ? 1.0 : 0.0;
178 SoloControl::clear_all_solo_state ()
180 // ideally this function will never do anything, it only exists to forestall Murphy
183 // these are really debug messages, but of possible interest.
185 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
187 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
188 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
189 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
193 _soloed_by_others_upstream = 0;
194 _soloed_by_others_downstream = 0;
196 set_self_solo (false);
198 Changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
202 SoloControl::set_state (XMLNode const & node, int)
204 XMLProperty const * prop;
206 if ((prop = node.property ("self-solo")) != 0) {
207 set_self_solo (string_is_affirmative (prop->value()));
210 if ((prop = node.property ("soloed-by-upstream")) != 0) {
211 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
212 mod_solo_by_others_upstream (atoi (prop->value()));
215 if ((prop = node.property ("soloed-by-downstream")) != 0) {
216 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
217 mod_solo_by_others_downstream (atoi (prop->value()));
224 SoloControl::get_state ()
226 XMLNode& node (SlavableAutomationControl::get_state());
228 node.add_property (X_("self-solo"), _self_solo ? X_("yes") : X_("no"));
230 snprintf (buf, sizeof(buf), "%d", _soloed_by_others_upstream);
231 node.add_property (X_("soloed-by-upstream"), buf);
232 snprintf (buf, sizeof(buf), "%d", _soloed_by_others_downstream);
233 node.add_property (X_("soloed-by-downstream"), buf);