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::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
136 _set_value (val, group_override);
141 Route::SoloControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
143 boost::shared_ptr<Route> r = _route.lock ();
147 r->set_control (SoloAutomation, val, group_override);
151 Route::SoloControllable::set_value_unchecked (double val)
153 /* Used only by automation playback */
155 _set_value (val, Controllable::NoGroup);
159 Route::SoloControllable::get_value () const
162 Glib::Threads::RWLock::ReaderLock lm (master_lock);
163 return get_masters_value_locked () ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
166 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
167 // Playing back automation, get the value from the list
168 return AutomationControl::get_value();
171 boost::shared_ptr<Route> r = _route.lock ();
177 if (Config->get_solo_control_is_listen_control()) {
178 return r->listening_via_monitor() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
180 return r->self_soloed() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
184 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
185 : BooleanRouteAutomationControl (name, MuteAutomation, boost::shared_ptr<AutomationList>(), r)
188 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
189 gl->set_interpolation(Evoral::ControlList::Discrete);
194 Route::MuteControllable::set_superficial_value(bool muted)
196 /* Note we can not use AutomationControl::set_value here since it will emit
197 Changed(), but the value will not be correct to the observer. */
199 const bool to_list = _list && ((AutomationList*)_list.get ())->automation_write ();
200 const double where = _session.audible_frame ();
202 /* Note that we really need this:
203 * if (as == Touch && _list->in_new_write_pass ()) {
204 * alist->start_write_pass (_session.audible_frame ());
206 * here in the case of the user calling from a GUI or whatever.
207 * Without the ability to distinguish between user and
208 * automation-initiated changes, we lose the "touch mute"
209 * behaviour we have in AutomationController::toggled ().
211 _list->set_in_write_pass (true, false, where);
214 Control::set_double (muted, where, to_list);
218 Route::MuteControllable::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
221 _set_value (val, group_override);
226 Route::MuteControllable::set_value_unchecked (double val)
228 /* used only automation playback */
229 _set_value (val, Controllable::NoGroup);
233 Route::MuteControllable::_set_value (double val, Controllable::GroupControlDisposition group_override)
235 boost::shared_ptr<Route> r = _route.lock ();
241 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
242 // Set superficial/automation value to drive controller (and possibly record)
243 const bool bval = ((val >= 0.5) ? true : false);
244 set_superficial_value (bval);
245 // Playing back automation, set route mute directly
246 r->set_mute (bval, Controllable::NoGroup);
248 r->set_control (MuteAutomation, val, group_override);
253 Route::MuteControllable::get_value () const
256 Glib::Threads::RWLock::ReaderLock lm (master_lock);
257 return get_masters_value_locked () ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
260 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
261 // Playing back automation, get the value from the list
262 return AutomationControl::get_value();
265 // Not playing back automation, get the actual route mute value
266 boost::shared_ptr<Route> r = _route.lock ();
267 return (r && r->muted()) ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
270 Route::PhaseControllable::PhaseControllable (std::string name, boost::shared_ptr<Route> r)
271 : BooleanRouteAutomationControl (name, PhaseAutomation, boost::shared_ptr<AutomationList>(), r)
274 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(PhaseAutomation)));
275 gl->set_interpolation(Evoral::ControlList::Discrete);
280 Route::PhaseControllable::set_value (double v, PBD::Controllable::GroupControlDisposition /* group_override */)
282 boost::shared_ptr<Route> r = _route.lock ();
283 if (r->phase_invert().size()) {
284 if (v == 0 || (v < 1 && v > 0.9) ) {
285 r->set_phase_invert (_current_phase, false);
287 r->set_phase_invert (_current_phase, true);
293 Route::PhaseControllable::get_value () const
295 boost::shared_ptr<Route> r = _route.lock ();
299 return (double) r->phase_invert (_current_phase);
303 Route::PhaseControllable::set_channel (uint32_t c)
309 Route::PhaseControllable::channel () const
311 return _current_phase;
314 Route::SoloIsolateControllable::SoloIsolateControllable (std::string name, boost::shared_ptr<Route> r)
315 : BooleanRouteAutomationControl (name, SoloIsolateAutomation, boost::shared_ptr<AutomationList>(), r)
317 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloIsolateAutomation)));
318 gl->set_interpolation(Evoral::ControlList::Discrete);
324 Route::SoloIsolateControllable::get_value () const
326 boost::shared_ptr<Route> r = _route.lock ();
328 return 0.0; /* "false" */
331 return r->solo_isolated() ? 1.0 : 0.0;
335 Route::SoloIsolateControllable::set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
337 _set_value (val, gcd);
341 Route::SoloIsolateControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition)
343 boost::shared_ptr<Route> r = _route.lock ();
348 /* no group semantics yet */
349 r->set_solo_isolated (val >= 0.5 ? true : false);
352 Route::SoloSafeControllable::SoloSafeControllable (std::string name, boost::shared_ptr<Route> r)
353 : BooleanRouteAutomationControl (name, SoloSafeAutomation, boost::shared_ptr<AutomationList>(), r)
355 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloSafeAutomation)));
356 gl->set_interpolation(Evoral::ControlList::Discrete);
361 Route::SoloSafeControllable::set_value (double val, PBD::Controllable::GroupControlDisposition gcd)
363 _set_value (val, gcd);
367 Route::SoloSafeControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition)
369 boost::shared_ptr<Route> r = _route.lock ();
374 /* no group semantics yet */
375 r->set_solo_safe (val >= 0.5 ? true : false);
379 Route::SoloSafeControllable::get_value () const
381 boost::shared_ptr<Route> r = _route.lock ();
383 return 0.0; /* "false" */
386 return r->solo_safe() ? 1.0 : 0.0;