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)
39 , _transition_into_solo (false)
41 _list->set_interpolation (Evoral::ControlList::Discrete);
42 /* solo changes must be synchronized by the process cycle */
43 set_flags (Controllable::Flag (flags() | Controllable::RealTime));
47 SoloControl::set_self_solo (bool yn)
49 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
51 set_mute_master_solo ();
53 _transition_into_solo = 0;
56 if (get_masters_value() == 0) {
57 _transition_into_solo = 1;
60 if (get_masters_value() == 0) {
61 _transition_into_solo = -1;
67 SoloControl::set_mute_master_solo ()
69 _muteable.mute_master()->set_soloed_by_self (self_soloed() || get_masters_value());
71 if (Config->get_solo_control_is_listen_control()) {
72 _muteable.mute_master()->set_soloed_by_others (false);
74 _muteable.mute_master()->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream() || get_masters_value());
79 SoloControl::mod_solo_by_others_downstream (int32_t delta)
81 if (_soloable.is_safe() || !_soloable.can_solo()) {
85 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
86 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
89 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
90 _soloed_by_others_downstream += delta;
92 _soloed_by_others_downstream = 0;
95 _soloed_by_others_downstream += delta;
98 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
100 set_mute_master_solo ();
101 _transition_into_solo = 0;
102 Changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
106 SoloControl::mod_solo_by_others_upstream (int32_t delta)
108 if (_soloable.is_safe() || !_soloable.can_solo()) {
112 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
113 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
115 uint32_t old_sbu = _soloed_by_others_upstream;
118 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
119 _soloed_by_others_upstream += delta;
121 _soloed_by_others_upstream = 0;
124 _soloed_by_others_upstream += delta;
127 DEBUG_TRACE (DEBUG::Solo, string_compose (
128 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
129 name(), delta, _soloed_by_others_upstream, old_sbu,
130 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
133 /* push the inverse solo change to everything that feeds us.
135 This is important for solo-within-group. When we solo 1 track out of N that
136 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
137 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
138 tracks that feed it. This will silence them if they were audible because
139 of a bus solo, but the newly soloed track will still be audible (because
142 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
146 if ((_self_solo || _soloed_by_others_downstream) &&
147 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
148 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
150 if (delta > 0 || !Config->get_exclusive_solo()) {
151 _soloable.push_solo_upstream (delta);
155 set_mute_master_solo ();
156 _transition_into_solo = 0;
157 Changed (false, Controllable::NoGroup); /* EMIT SIGNAL */
161 SoloControl::actually_set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
163 if (_soloable.is_safe() || !_soloable.can_solo()) {
167 set_self_solo (val == 1.0);
169 /* this sets the Evoral::Control::_user_value for us, which will
170 be retrieved by AutomationControl::get_value (), and emits Changed
173 SlavableAutomationControl::actually_set_value (val, group_override);
177 SoloControl::get_value () const
180 return self_soloed() || get_masters_value ();
183 if (_list && boost::dynamic_pointer_cast<AutomationList>(_list)->automation_playback()) {
184 // Playing back automation, get the value from the list
185 return AutomationControl::get_value();
192 SoloControl::clear_all_solo_state ()
197 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name()) << endmsg;
198 actually_set_value (0.0, Controllable::NoGroup);
202 if (_soloed_by_others_upstream) {
203 PBD::info << string_compose (_("Cleared upstream solo: %1 up:%2\n"), name(), _soloed_by_others_upstream)
205 _soloed_by_others_upstream = 0;
209 if (_soloed_by_others_downstream) {
210 PBD::info << string_compose (_("Cleared downstream solo: %1 down:%2\n"), name(), _soloed_by_others_downstream)
212 _soloed_by_others_downstream = 0;
216 _transition_into_solo = 0; /* Session does not need to propagate */
219 Changed (false, Controllable::NoGroup); /* EMIT SIGNAL */
224 SoloControl::set_state (XMLNode const & node, int version)
226 if (SlavableAutomationControl::set_state(node, version)) {
230 XMLProperty const * prop;
232 if ((prop = node.property ("self-solo")) != 0) {
233 set_self_solo (string_is_affirmative (prop->value()));
236 if ((prop = node.property ("soloed-by-upstream")) != 0) {
237 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
238 mod_solo_by_others_upstream (atoi (prop->value()));
241 if ((prop = node.property ("soloed-by-downstream")) != 0) {
242 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
243 mod_solo_by_others_downstream (atoi (prop->value()));
250 SoloControl::get_state ()
252 XMLNode& node (SlavableAutomationControl::get_state());
254 node.add_property (X_("self-solo"), _self_solo ? X_("yes") : X_("no"));
256 snprintf (buf, sizeof(buf), "%d", _soloed_by_others_upstream);
257 node.add_property (X_("soloed-by-upstream"), buf);
258 snprintf (buf, sizeof(buf), "%d", _soloed_by_others_downstream);
259 node.add_property (X_("soloed-by-downstream"), buf);
265 SoloControl::master_changed (bool /*from self*/, GroupControlDisposition, boost::shared_ptr<AutomationControl> m)
267 bool send_signal = false;
269 _transition_into_solo = 0;
271 /* Notice that we call get_boolean_masters() BEFORE we call
272 * update_boolean_masters_records(), in order to know what
273 * our master state was BEFORE it gets changed.
277 if (m->get_value()) {
278 /* this master is now enabled */
279 if (!self_soloed() && get_boolean_masters() == 0) {
280 /* not self-soloed, wasn't soloed by masters before */
282 _transition_into_solo = 1;
285 if (!self_soloed() && get_boolean_masters() == 1) {
286 /* not self-soloed, soloed by just 1 master before */
287 _transition_into_solo = -1;
292 update_boolean_masters_records (m);
295 set_mute_master_solo ();
296 Changed (false, Controllable::UseGroup);
302 SoloControl::post_add_master (boost::shared_ptr<AutomationControl> m)
304 if (m->get_value()) {
306 /* boolean masters records are not updated until AFTER
307 * ::post_add_master() is called, so we can use them to check
308 * on whether any master was already enabled before the new
312 if (!self_soloed() && !get_boolean_masters()) {
313 _transition_into_solo = 1;
314 Changed (false, Controllable::NoGroup);
320 SoloControl::pre_remove_master (boost::shared_ptr<AutomationControl> m)
323 /* null control ptr means we're removing all masters. Nothing
324 * to do. Changed will be emitted in
325 * SlavableAutomationControl::clear_masters()
330 if (m->get_value()) {
331 if (!self_soloed() && (get_boolean_masters() == 1)) {
332 /* we're not self-soloed, this master is, and we're
334 it. SlavableAutomationControl::remove_master() will
335 ensure that we reset our own value after actually
336 removing the master, so that our state does not
337 change (this is a precondition of the
338 SlavableAutomationControl API). This will emit
339 Changed(), and we need to make sure that any
340 listener knows that there has been no transition.
342 _transition_into_solo = 0;
344 _transition_into_solo = 1;
347 _transition_into_solo = 0;
352 SoloControl::can_solo () const
354 return _soloable.can_solo ();