2 Copyright (C) 2007 Paul Davis
3 Author: David Robillard
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
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "ardour/automation_control.h"
23 #include "ardour/automation_watch.h"
24 #include "ardour/event_type_map.h"
25 #include "ardour/session.h"
27 #include "pbd/memento_command.h"
32 using namespace ARDOUR;
35 AutomationControl::AutomationControl(ARDOUR::Session& session,
36 const Evoral::Parameter& parameter,
37 const ParameterDescriptor& desc,
38 boost::shared_ptr<ARDOUR::AutomationList> list,
40 : Controllable (name.empty() ? EventTypeMap::instance().to_symbol(parameter) : name)
41 , Evoral::Control(parameter, desc, list)
47 AutomationControl::~AutomationControl ()
51 /** Get the current effective `user' value based on automation state */
53 AutomationControl::get_value() const
55 bool from_list = _list && ((AutomationList*)_list.get())->automation_playback();
56 return Control::get_double (from_list, _session.transport_frame());
59 /** Set the value and do the right thing based on automation state
60 * (e.g. record if necessary, etc.)
61 * @param value `user' value
64 AutomationControl::set_value (double value)
66 bool to_list = _list && ((AutomationList*)_list.get())->automation_write();
68 Control::set_double (value, _session.transport_frame(), to_list);
70 Changed(); /* EMIT SIGNAL */
74 AutomationControl::set_list (boost::shared_ptr<Evoral::ControlList> list)
76 Control::set_list (list);
77 Changed(); /* EMIT SIGNAL */
81 AutomationControl::set_automation_state (AutoState as)
83 if (_list && as != alist()->automation_state()) {
85 alist()->set_automation_state (as);
87 return; // No watch for boolean automation
91 AutomationWatch::instance().add_automation_watch (shared_from_this());
92 } else if (as == Touch) {
94 AutomationWatch::instance().remove_automation_watch (shared_from_this());
96 /* this seems unlikely, but the combination of
97 * a control surface and the mouse could make
98 * it possible to put the control into Touch
99 * mode *while* touching it.
101 AutomationWatch::instance().add_automation_watch (shared_from_this());
104 AutomationWatch::instance().remove_automation_watch (shared_from_this());
110 AutomationControl::set_automation_style (AutoStyle as)
113 alist()->set_automation_style (as);
117 AutomationControl::start_touch(double when)
125 if (alist()->automation_state() == Touch) {
126 /* subtle. aligns the user value with the playback */
127 set_value (get_value ());
128 alist()->start_touch (when);
129 if (!_desc.toggled) {
130 AutomationWatch::instance().add_automation_watch (shared_from_this());
138 AutomationControl::stop_touch(bool mark, double when)
142 set_touching (false);
144 if (alist()->automation_state() == Touch) {
145 alist()->stop_touch (mark, when);
146 if (!_desc.toggled) {
147 AutomationWatch::instance().remove_automation_watch (shared_from_this());
155 AutomationControl::commit_transaction ()
157 if (alist ()->before ()) {
158 _session.begin_reversible_command (string_compose (_("record %1 automation"), name ()));
159 _session.commit_reversible_command (new MementoCommand<AutomationList> (*alist ().get (), alist ()->before (), &alist ()->get_state ()));
164 AutomationControl::internal_to_interface (double val) const
166 if (_desc.integer_step) {
167 // both upper and lower are inclusive.
168 val = (val - lower()) / (1 + upper() - lower());
170 val = (val - lower()) / (upper() - lower());
173 if (_desc.logarithmic) {
175 val = pow (val, 1./2.0);
185 AutomationControl::interface_to_internal (double val) const
187 if (_desc.logarithmic) {
191 val = pow (val, 2.0);
195 if (_desc.integer_step) {
196 val = lower() + val * (1 + upper() - lower());
198 val = lower() + val * (upper() - lower());
201 if (val < lower()) val = lower();
202 if (val > upper()) val = upper();