2 * Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "ardour/debug.h"
21 #include "ardour/mute_master.h"
22 #include "ardour/session.h"
23 #include "ardour/solo_control.h"
27 using namespace ARDOUR;
31 SoloControl::SoloControl (Session& session, std::string const & name, Soloable& s, Muteable& m)
32 : SlavableAutomationControl (session, SoloAutomation, ParameterDescriptor (SoloAutomation),
33 boost::shared_ptr<AutomationList>(new AutomationList(Evoral::Parameter(SoloAutomation))),
38 , _soloed_by_others_upstream (0)
39 , _soloed_by_others_downstream (0)
40 , _transition_into_solo (false)
42 _list->set_interpolation (Evoral::ControlList::Discrete);
43 /* solo changes must be synchronized by the process cycle */
44 set_flags (Controllable::Flag (flags() | Controllable::RealTime));
48 SoloControl::set_self_solo (bool yn)
50 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
52 set_mute_master_solo ();
54 _transition_into_solo = 0;
57 if (get_masters_value() == 0) {
58 _transition_into_solo = 1;
61 if (get_masters_value() == 0) {
62 _transition_into_solo = -1;
68 SoloControl::set_mute_master_solo ()
70 _muteable.mute_master()->set_soloed_by_self (self_soloed() || get_masters_value());
72 if (Config->get_solo_control_is_listen_control()) {
73 _muteable.mute_master()->set_soloed_by_others (false);
75 _muteable.mute_master()->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream() || get_masters_value());
80 SoloControl::mod_solo_by_others_downstream (int32_t delta)
82 if (_soloable.is_safe() || !_soloable.can_solo()) {
86 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
87 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
90 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
91 _soloed_by_others_downstream += delta;
93 _soloed_by_others_downstream = 0;
96 _soloed_by_others_downstream += delta;
99 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
101 set_mute_master_solo ();
102 _transition_into_solo = 0;
103 Changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
107 SoloControl::mod_solo_by_others_upstream (int32_t delta)
109 if (_soloable.is_safe() || !_soloable.can_solo()) {
113 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
114 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
116 uint32_t old_sbu = _soloed_by_others_upstream;
119 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
120 _soloed_by_others_upstream += delta;
122 _soloed_by_others_upstream = 0;
125 _soloed_by_others_upstream += delta;
128 DEBUG_TRACE (DEBUG::Solo, string_compose (
129 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
130 name(), delta, _soloed_by_others_upstream, old_sbu,
131 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
134 /* push the inverse solo change to everything that feeds us.
136 This is important for solo-within-group. When we solo 1 track out of N that
137 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
138 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
139 tracks that feed it. This will silence them if they were audible because
140 of a bus solo, but the newly soloed track will still be audible (because
143 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
147 if ((_self_solo || _soloed_by_others_downstream) &&
148 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
149 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
151 if (delta > 0 || !Config->get_exclusive_solo()) {
152 _soloable.push_solo_upstream (delta);
156 set_mute_master_solo ();
157 _transition_into_solo = 0;
158 Changed (false, Controllable::NoGroup); /* EMIT SIGNAL */
162 SoloControl::actually_set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
164 if (_soloable.is_safe() || !_soloable.can_solo()) {
168 set_self_solo (val == 1.0);
170 /* this sets the Evoral::Control::_user_value for us, which will
171 be retrieved by AutomationControl::get_value (), and emits Changed
174 SlavableAutomationControl::actually_set_value (val, group_override);
178 SoloControl::get_value () const
181 return self_soloed() || get_masters_value ();
184 if (_list && boost::dynamic_pointer_cast<AutomationList>(_list)->automation_playback()) {
185 // Playing back automation, get the value from the list
186 return AutomationControl::get_value();
193 SoloControl::clear_all_solo_state ()
198 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name()) << endmsg;
199 actually_set_value (0.0, Controllable::NoGroup);
203 if (_soloed_by_others_upstream) {
204 PBD::info << string_compose (_("Cleared upstream solo: %1 up:%2\n"), name(), _soloed_by_others_upstream)
206 _soloed_by_others_upstream = 0;
210 if (_soloed_by_others_downstream) {
211 PBD::info << string_compose (_("Cleared downstream solo: %1 down:%2\n"), name(), _soloed_by_others_downstream)
213 _soloed_by_others_downstream = 0;
217 _transition_into_solo = 0; /* Session does not need to propagate */
220 Changed (false, Controllable::NoGroup); /* EMIT SIGNAL */
225 SoloControl::set_state (XMLNode const & node, int version)
227 if (SlavableAutomationControl::set_state(node, version)) {
232 if (node.get_property ("self-solo", yn)) {
237 if (node.get_property ("soloed-by-upstream", val)) {
238 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
239 mod_solo_by_others_upstream (val);
242 if (node.get_property ("soloed-by-downstream", val)) {
243 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
244 mod_solo_by_others_downstream (val);
251 SoloControl::get_state ()
253 XMLNode& node (SlavableAutomationControl::get_state());
255 node.set_property (X_("self-solo"), _self_solo);
256 node.set_property (X_("soloed-by-upstream"), _soloed_by_others_upstream);
257 node.set_property (X_("soloed-by-downstream"), _soloed_by_others_downstream);
263 SoloControl::master_changed (bool /*from self*/, GroupControlDisposition, boost::weak_ptr<AutomationControl> wm)
265 boost::shared_ptr<AutomationControl> m = wm.lock ();
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 ();