NO-OP: whitespace/comments
[ardour.git] / libs / ardour / solo_isolate_control.cc
1 /*
2  * Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #include "ardour/debug.h"
21 #include "ardour/mute_master.h"
22 #include "ardour/session.h"
23 #include "ardour/solo_isolate_control.h"
24
25 #include "pbd/i18n.h"
26
27 using namespace ARDOUR;
28 using namespace std;
29 using namespace PBD;
30
31 SoloIsolateControl::SoloIsolateControl (Session& session, std::string const & name, Soloable& s, Muteable& m)
32         : SlavableAutomationControl (session, SoloIsolateAutomation, ParameterDescriptor (SoloIsolateAutomation),
33                                      boost::shared_ptr<AutomationList>(new AutomationList(Evoral::Parameter(SoloIsolateAutomation))),
34                                      name)
35         , _soloable (s)
36         , _muteable (m)
37         , _solo_isolated (false)
38         , _solo_isolated_by_upstream (0)
39 {
40         _list->set_interpolation (Evoral::ControlList::Discrete);
41         /* isolate changes must be synchronized by the process cycle */
42         set_flags (Controllable::Flag (flags() | Controllable::RealTime));
43 }
44
45 void
46 SoloIsolateControl::master_changed (bool from_self, PBD::Controllable::GroupControlDisposition gcd, boost::weak_ptr<AutomationControl>)
47 {
48         if (!_soloable.can_solo()) {
49                 return;
50         }
51
52         bool master_soloed;
53
54         {
55                 Glib::Threads::RWLock::ReaderLock lm (master_lock);
56                 master_soloed = (bool) get_masters_value_locked ();
57         }
58
59         /* Master is considered equivalent to an upstream solo control, not
60          * direct control over self-soloed.
61          */
62
63         mod_solo_isolated_by_upstream (master_soloed ? 1 : -1);
64
65         /* no need to call AutomationControl::master_changed() since it just
66            emits Changed() which we already did in mod_solo_by_others_upstream()
67         */
68 }
69
70 void
71 SoloIsolateControl::mod_solo_isolated_by_upstream (int32_t delta)
72 {
73         bool old = solo_isolated ();
74         DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
75                                                   name(), _solo_isolated_by_upstream, delta));
76
77         if (delta < 0) {
78                 if (_solo_isolated_by_upstream >= (uint32_t) abs(delta)) {
79                         _solo_isolated_by_upstream += delta;
80                 } else {
81                         _solo_isolated_by_upstream = 0;
82                 }
83         } else {
84                 _solo_isolated_by_upstream += delta;
85         }
86
87         if (solo_isolated() != old) {
88                 Changed (false, Controllable::NoGroup); /* EMIT SIGNAL */
89         }
90 }
91
92 void
93 SoloIsolateControl::actually_set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
94 {
95         if (!_soloable.can_solo()) {
96                 return;
97         }
98
99         set_solo_isolated (val, gcd);
100
101         /* this sets the Evoral::Control::_user_value for us, which will
102            be retrieved by AutomationControl::get_value (), and emits Changed
103         */
104
105         AutomationControl::actually_set_value (val, gcd);
106 }
107
108 void
109 SoloIsolateControl::set_solo_isolated (bool yn, Controllable::GroupControlDisposition group_override)
110 {
111         if (!_soloable.can_solo()) {
112                 return;
113         }
114
115         bool changed = false;
116
117         if (yn) {
118                 if (_solo_isolated == false) {
119                         changed = true;
120                 }
121                 _solo_isolated = true;
122         } else {
123                 if (_solo_isolated == true) {
124                         _solo_isolated = false;
125                         changed = true;
126                 }
127         }
128
129         if (!changed) {
130                 return;
131         }
132
133         _soloable.push_solo_isolate_upstream (yn ? 1 : -1);
134
135         /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
136
137         Changed (true, group_override); /* EMIT SIGNAL */
138 }
139
140
141 double
142 SoloIsolateControl::get_value () const
143 {
144         if (slaved()) {
145                 return solo_isolated() || get_masters_value ();
146         }
147
148         if (_list && boost::dynamic_pointer_cast<AutomationList>(_list)->automation_playback()) {
149                 // Playing back automation, get the value from the list
150                 return AutomationControl::get_value();
151         }
152
153         return solo_isolated ();
154 }
155
156 int
157 SoloIsolateControl::set_state (XMLNode const & node, int version)
158 {
159         if (SlavableAutomationControl::set_state(node, version)) {
160                 return -1;
161         }
162
163         node.get_property ("solo-isolated", _solo_isolated);
164         return 0;
165 }
166
167 XMLNode&
168 SoloIsolateControl::get_state ()
169 {
170         XMLNode& node (SlavableAutomationControl::get_state());
171         node.set_property (X_("solo-isolated"), _solo_isolated);
172         return node;
173 }