+void
+AutomationControl::start_touch(double when)
+{
+ if (!_list) {
+ return;
+ }
+
+ if (!touching()) {
+
+ if (alist()->automation_state() == Touch) {
+ /* subtle. aligns the user value with the playback */
+ set_value (get_value (), Controllable::NoGroup);
+ alist()->start_touch (when);
+ if (!_desc.toggled) {
+ AutomationWatch::instance().add_automation_watch (shared_from_this());
+ }
+ }
+ set_touching (true);
+ }
+}
+
+void
+AutomationControl::stop_touch(bool mark, double when)
+{
+ if (!_list) return;
+ if (touching()) {
+ set_touching (false);
+
+ if (alist()->automation_state() == Touch) {
+ alist()->stop_touch (mark, when);
+ if (!_desc.toggled) {
+ AutomationWatch::instance().remove_automation_watch (shared_from_this());
+
+ }
+ }
+ }
+}
+
+void
+AutomationControl::commit_transaction (bool did_write)
+{
+ if (did_write) {
+ if (alist ()->before ()) {
+ _session.begin_reversible_command (string_compose (_("record %1 automation"), name ()));
+ _session.commit_reversible_command (new MementoCommand<AutomationList> (*alist ().get (), alist ()->before (), &alist ()->get_state ()));
+ }
+ } else {
+ alist ()->clear_history ();
+ }
+}
+
+double
+AutomationControl::internal_to_interface (double val) const
+{
+ if (_desc.integer_step) {
+ // both upper and lower are inclusive.
+ val = (val - lower()) / (1 + upper() - lower());
+ } else {
+ val = (val - lower()) / (upper() - lower());
+ }
+
+ if (_desc.logarithmic) {
+ if (val > 0) {
+ val = pow (val, 1./2.0);
+ } else {
+ val = 0;
+ }
+ }
+
+ return val;
+}
+
+double
+AutomationControl::interface_to_internal (double val) const
+{
+ if (!isfinite_local (val)) {
+ val = 0;
+ }
+ if (_desc.logarithmic) {
+ if (val <= 0) {
+ val = 0;
+ } else {
+ val = pow (val, 2.0);
+ }
+ }
+
+ if (_desc.integer_step) {
+ val = lower() + val * (1 + upper() - lower());
+ } else {
+ val = lower() + val * (upper() - lower());
+ }
+
+ if (val < lower()) val = lower();
+ if (val > upper()) val = upper();
+
+ return val;
+}
+
+void
+AutomationControl::set_group (boost::shared_ptr<ControlGroup> cg)
+{
+ /* this method can only be called by a ControlGroup. We do not need
+ to ensure consistency by calling ControlGroup::remove_control(),
+ since we are guaranteed that the ControlGroup will take care of that
+ for us.
+ */
+
+ _group = cg;
+}
+
+bool
+AutomationControl::check_rt (double val, Controllable::GroupControlDisposition gcd)
+{
+ if (!_session.loading() && (flags() & Controllable::RealTime) && !AudioEngine::instance()->in_process_thread()) {
+ /* queue change in RT context */
+ std::cerr << "::set_value (" << val << ", " << enum_2_string (gcd) << ") called for " << enum_2_string ((AutomationType) _parameter.type()) << ", queueing in RT context\n";
+ _session.set_control (shared_from_this(), val, gcd);
+ return true;
+ }
+
+ return false;
+}