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);
48 /* route must mediate group control */
49 set_trim (val, group_override);
53 case RecEnableAutomation:
54 /* session must mediate group control */
55 rl.reset (new RouteList);
56 rl->push_back (shared_from_this());
57 _session.set_record_enabled (rl, val >= 0.5 ? true : false, Session::rt_cleanup, group_override);
62 /* session must mediate group control */
63 rl.reset (new RouteList);
64 rl->push_back (shared_from_this());
65 if (Config->get_solo_control_is_listen_control()) {
66 _session.set_listen (rl, val >= 0.5 ? true : false, Session::rt_cleanup, group_override);
68 _session.set_solo (rl, val >= 0.5 ? true : false);
75 /* session must mediate group control */
76 rl.reset (new RouteList);
77 rl->push_back (shared_from_this());
78 _session.set_mute (rl, !muted(), Session::rt_cleanup, group_override);
83 /* Not a route automation control */
84 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;
91 Route::RouteAutomationControl::RouteAutomationControl (const std::string& name,
93 boost::shared_ptr<AutomationList> alist,
94 boost::shared_ptr<Route> r)
95 : AutomationControl (r->session(), Evoral::Parameter (atype),
96 ParameterDescriptor (Evoral::Parameter (atype)),
102 Route::RouteAutomationControl::RouteAutomationControl (const std::string& name,
103 AutomationType atype,
104 const ParameterDescriptor& desc,
105 boost::shared_ptr<AutomationList> alist,
106 boost::shared_ptr<Route> r)
107 : AutomationControl (r->session(), Evoral::Parameter (atype), desc, alist, name)
112 Route::GainControllable::GainControllable (Session& s, AutomationType atype, boost::shared_ptr<Route> r)
113 : GainControl (s, Evoral::Parameter(atype))
119 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
120 : RouteAutomationControl (name, SoloAutomation, boost::shared_ptr<AutomationList>(), r)
122 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
123 gl->set_interpolation(Evoral::ControlList::Discrete);
128 Route::SoloControllable::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
131 _set_value (val, group_override);
136 Route::SoloControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
138 const bool bval = ((val >= 0.5) ? true : false);
140 boost::shared_ptr<RouteList> rl (new RouteList);
142 boost::shared_ptr<Route> r = _route.lock ();
149 if (Config->get_solo_control_is_listen_control()) {
150 _session.set_listen (rl, bval, Session::rt_cleanup, group_override);
152 _session.set_solo (rl, bval, Session::rt_cleanup, group_override);
157 Route::SoloControllable::set_value_unchecked (double val)
159 /* Used only by automation playback */
161 _set_value (val, Controllable::NoGroup);
165 Route::SoloControllable::get_value () const
167 boost::shared_ptr<Route> r = _route.lock ();
172 if (Config->get_solo_control_is_listen_control()) {
173 return r->listening_via_monitor() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
175 return r->self_soloed() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
179 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
180 : RouteAutomationControl (name, MuteAutomation, boost::shared_ptr<AutomationList>(), r)
183 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
184 gl->set_interpolation(Evoral::ControlList::Discrete);
189 Route::MuteControllable::set_superficial_value(bool muted)
191 /* Note we can not use AutomationControl::set_value here since it will emit
192 Changed(), but the value will not be correct to the observer. */
194 const bool to_list = _list && ((AutomationList*)_list.get ())->automation_write ();
195 const double where = _session.audible_frame ();
197 /* Note that we really need this:
198 * if (as == Touch && _list->in_new_write_pass ()) {
199 * alist->start_write_pass (_session.audible_frame ());
201 * here in the case of the user calling from a GUI or whatever.
202 * Without the ability to distinguish between user and
203 * automation-initiated changes, we lose the "touch mute"
204 * behaviour we have in AutomationController::toggled ().
206 _list->set_in_write_pass (true, false, where);
209 Control::set_double (muted, where, to_list);
213 Route::MuteControllable::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
216 _set_value (val, group_override);
221 Route::MuteControllable::set_value_unchecked (double val)
223 /* used only automation playback */
224 _set_value (val, Controllable::NoGroup);
228 Route::MuteControllable::_set_value (double val, Controllable::GroupControlDisposition group_override)
230 const bool bval = ((val >= 0.5) ? true : false);
232 boost::shared_ptr<Route> r = _route.lock ();
237 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
238 // Set superficial/automation value to drive controller (and possibly record)
239 set_superficial_value (bval);
240 // Playing back automation, set route mute directly
241 r->set_mute (bval, Controllable::NoGroup);
243 // Set from user, queue mute event
244 boost::shared_ptr<RouteList> rl (new RouteList);
246 _session.set_mute (rl, bval, Session::rt_cleanup, group_override);
251 Route::MuteControllable::get_value () const
253 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
254 // Playing back automation, get the value from the list
255 return AutomationControl::get_value();
258 // Not playing back automation, get the actual route mute value
259 boost::shared_ptr<Route> r = _route.lock ();
260 return (r && r->muted()) ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
263 Route::PhaseControllable::PhaseControllable (std::string name, boost::shared_ptr<Route> r)
264 : RouteAutomationControl (name, PhaseAutomation, boost::shared_ptr<AutomationList>(), r)
266 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(PhaseAutomation)));
267 gl->set_interpolation(Evoral::ControlList::Discrete);
272 Route::PhaseControllable::set_value (double v, PBD::Controllable::GroupControlDisposition /* group_override */)
274 boost::shared_ptr<Route> r = _route.lock ();
275 if (r->phase_invert().size()) {
276 if (v == 0 || (v < 1 && v > 0.9) ) {
277 r->set_phase_invert (_current_phase, false);
279 r->set_phase_invert (_current_phase, true);
285 Route::PhaseControllable::get_value () const
287 boost::shared_ptr<Route> r = _route.lock ();
288 return (double) r->phase_invert (_current_phase);
292 Route::PhaseControllable::set_channel (uint32_t c)
298 Route::PhaseControllable::channel () const
300 return _current_phase;