2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
24 #include "ardour/automation_control.h"
25 #include "ardour/parameter_descriptor.h"
26 #include "ardour/route.h"
27 #include "ardour/session.h"
32 using namespace ARDOUR;
36 Route::set_control (AutomationType type, double val, PBD::Controllable::GroupControlDisposition group_override)
38 boost::shared_ptr<RouteList> rl;
42 /* route must mediate group control */
43 set_gain (val, group_override);
47 /* route must mediate group control */
48 set_trim (val, group_override);
51 case RecEnableAutomation:
52 /* session must mediate group control */
53 rl.reset (new RouteList);
54 rl->push_back (shared_from_this());
55 _session.set_record_enabled (rl, val >= 0.5 ? true : false, Session::rt_cleanup, group_override);
59 /* session must mediate group control */
60 rl.reset (new RouteList);
61 rl->push_back (shared_from_this());
62 if (Config->get_solo_control_is_listen_control()) {
63 _session.set_listen (rl, val >= 0.5 ? true : false, Session::rt_cleanup, group_override);
65 _session.set_solo (rl, val >= 0.5 ? true : false, Session::rt_cleanup, group_override);
70 /* session must mediate group control */
71 rl.reset (new RouteList);
72 rl->push_back (shared_from_this());
73 _session.set_mute (rl, val >= 0.5 ? true : false, Session::rt_cleanup, group_override);
78 /* Not a route automation control */
79 fatal << string_compose (_("programming error: %1%2\n"), X_("illegal type of route automation control passed to Route::set_control(): "), enum_2_string(type)) << endmsg;
86 Route::RouteAutomationControl::RouteAutomationControl (const std::string& name,
88 boost::shared_ptr<AutomationList> alist,
89 boost::shared_ptr<Route> r)
90 : AutomationControl (r->session(), Evoral::Parameter (atype),
91 ParameterDescriptor (Evoral::Parameter (atype)),
98 Route::BooleanRouteAutomationControl::get_masters_value_locked () const
100 /* masters (read/write) lock must be held */
102 /* if any master is enabled (val > 0.0) then we consider the master
106 for (Masters::const_iterator mr = _masters.begin(); mr != _masters.end(); ++mr) {
107 if (mr->second.master()->get_value()) {
117 Route::GainControllable::GainControllable (Session& s, AutomationType atype, boost::shared_ptr<Route> r)
118 : GainControl (s, Evoral::Parameter(atype))
124 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
125 : BooleanRouteAutomationControl (name, SoloAutomation, boost::shared_ptr<AutomationList>(), r)
127 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
128 gl->set_interpolation(Evoral::ControlList::Discrete);
133 Route::SoloControllable::master_changed (bool from_self, PBD::Controllable::GroupControlDisposition gcd)
135 boost::shared_ptr<Route> r = _route.lock ();
144 Glib::Threads::RWLock::ReaderLock lm (master_lock);
145 master_soloed = (bool) get_masters_value_locked ();
148 /* Master is considered equivalent to an upstream solo control, not
149 * direct control over self-soloed.
152 r->mod_solo_by_others_upstream (master_soloed ? 1 : -1);
154 AutomationControl::master_changed (false, gcd);
158 Route::SoloControllable::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
161 _set_value (val, group_override);
166 Route::SoloControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
168 boost::shared_ptr<Route> r = _route.lock ();
172 r->set_control (SoloAutomation, val, group_override);
176 Route::SoloControllable::set_value_unchecked (double val)
178 /* Used only by automation playback */
180 _set_value (val, Controllable::NoGroup);
184 Route::SoloControllable::get_value () const
187 Glib::Threads::RWLock::ReaderLock lm (master_lock);
188 return get_masters_value_locked () ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
191 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
192 // Playing back automation, get the value from the list
193 return AutomationControl::get_value();
196 boost::shared_ptr<Route> r = _route.lock ();
202 if (Config->get_solo_control_is_listen_control()) {
203 return r->listening_via_monitor() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
205 return r->self_soloed() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
209 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
210 : BooleanRouteAutomationControl (name, MuteAutomation, boost::shared_ptr<AutomationList>(), r)
213 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
214 gl->set_interpolation(Evoral::ControlList::Discrete);
219 Route::MuteControllable::set_superficial_value(bool muted)
221 /* Note we can not use AutomationControl::set_value here since it will emit
222 Changed(), but the value will not be correct to the observer. */
224 const bool to_list = _list && ((AutomationList*)_list.get ())->automation_write ();
225 const double where = _session.audible_frame ();
228 /* Note that we really need this:
229 * if (as == Touch && _list->in_new_write_pass ()) {
230 * alist->start_write_pass (_session.audible_frame ());
232 * here in the case of the user calling from a GUI or whatever.
233 * Without the ability to distinguish between user and
234 * automation-initiated changes, we lose the "touch mute"
235 * behaviour we have in AutomationController::toggled ().
237 _list->set_in_write_pass (true, false, where);
240 Control::set_double (muted, where, to_list);
244 Route::MuteControllable::master_changed (bool from_self, PBD::Controllable::GroupControlDisposition gcd)
249 Glib::Threads::RWLock::ReaderLock lm (master_lock);
250 master_muted = (bool) get_masters_value_locked ();
253 boost::shared_ptr<Route> r (_route.lock());
255 r->mute_master()->mod_muted_by_others (master_muted ? 1 : -1);
258 AutomationControl::master_changed (false, gcd);
262 Route::MuteControllable::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
265 _set_value (val, group_override);
270 Route::MuteControllable::set_value_unchecked (double val)
272 /* used only automation playback */
273 _set_value (val, Controllable::NoGroup);
277 Route::MuteControllable::_set_value (double val, Controllable::GroupControlDisposition group_override)
279 boost::shared_ptr<Route> r = _route.lock ();
285 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
286 // Set superficial/automation value to drive controller (and possibly record)
287 const bool bval = ((val >= 0.5) ? true : false);
288 set_superficial_value (bval);
289 // Playing back automation, set route mute directly
290 r->set_mute (bval, Controllable::NoGroup);
292 r->set_control (MuteAutomation, val, group_override);
297 Route::MuteControllable::get_value () const
300 Glib::Threads::RWLock::ReaderLock lm (master_lock);
301 return get_masters_value_locked () ? 1.0 : 0.0;
304 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
305 // Playing back automation, get the value from the list
306 return AutomationControl::get_value();
309 // Not playing back automation, get the actual route mute value
310 boost::shared_ptr<Route> r = _route.lock ();
311 return (r && r->muted()) ? 1.0 : 0.0;
314 Route::PhaseControllable::PhaseControllable (std::string name, boost::shared_ptr<Route> r)
315 : BooleanRouteAutomationControl (name, PhaseAutomation, boost::shared_ptr<AutomationList>(), r)
318 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(PhaseAutomation)));
319 gl->set_interpolation(Evoral::ControlList::Discrete);
324 Route::PhaseControllable::set_value (double v, PBD::Controllable::GroupControlDisposition /* group_override */)
326 boost::shared_ptr<Route> r = _route.lock ();
327 if (r->phase_invert().size()) {
328 if (v == 0 || (v < 1 && v > 0.9) ) {
329 r->set_phase_invert (_current_phase, false);
331 r->set_phase_invert (_current_phase, true);
337 Route::PhaseControllable::get_value () const
339 boost::shared_ptr<Route> r = _route.lock ();
343 return (double) r->phase_invert (_current_phase);
347 Route::PhaseControllable::set_channel (uint32_t c)
353 Route::PhaseControllable::channel () const
355 return _current_phase;
358 Route::SoloIsolateControllable::SoloIsolateControllable (std::string name, boost::shared_ptr<Route> r)
359 : BooleanRouteAutomationControl (name, SoloIsolateAutomation, boost::shared_ptr<AutomationList>(), r)
361 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloIsolateAutomation)));
362 gl->set_interpolation(Evoral::ControlList::Discrete);
368 Route::SoloIsolateControllable::get_value () const
370 boost::shared_ptr<Route> r = _route.lock ();
372 return 0.0; /* "false" */
375 return r->solo_isolated() ? 1.0 : 0.0;
379 Route::SoloIsolateControllable::set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
381 _set_value (val, gcd);
385 Route::SoloIsolateControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition)
387 boost::shared_ptr<Route> r = _route.lock ();
392 /* no group semantics yet */
393 r->set_solo_isolated (val >= 0.5 ? true : false);
396 Route::SoloSafeControllable::SoloSafeControllable (std::string name, boost::shared_ptr<Route> r)
397 : BooleanRouteAutomationControl (name, SoloSafeAutomation, boost::shared_ptr<AutomationList>(), r)
399 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloSafeAutomation)));
400 gl->set_interpolation(Evoral::ControlList::Discrete);
405 Route::SoloSafeControllable::set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
407 _set_value (val, gcd);
411 Route::SoloSafeControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition)
413 boost::shared_ptr<Route> r = _route.lock ();
418 /* no group semantics yet */
419 r->set_solo_safe (val >= 0.5 ? true : false);
423 Route::SoloSafeControllable::get_value () const
425 boost::shared_ptr<Route> r = _route.lock ();
427 return 0.0; /* "false" */
430 return r->solo_safe() ? 1.0 : 0.0;