-/** Get the latest user-set value, which may not equal get_value() when automation
- * is playing back, etc.
- *
- * Automation write/touch works by periodically sampling this value and adding it
- * to the AutomationList.
- */
-float
-AutomationControl::user_value() const
+void
+AutomationControl::set_automation_state (AutoState as)
+{
+ if (flags() & NotAutomatable) {
+ return;
+ }
+ if (_list && as != alist()->automation_state()) {
+
+ const double val = get_value ();
+
+ alist()->set_automation_state (as);
+ if (_desc.toggled) {
+ return; // No watch for boolean automation
+ }
+
+ if (as == Write) {
+ AutomationWatch::instance().add_automation_watch (shared_from_this());
+ } else if (as == Touch) {
+ if (alist()->empty()) {
+ Control::set_double (val, _session.current_start_frame (), true);
+ Control::set_double (val, _session.current_end_frame (), true);
+ Changed (true, Controllable::NoGroup);
+ }
+ if (!touching()) {
+ AutomationWatch::instance().remove_automation_watch (shared_from_this());
+ } else {
+ /* this seems unlikely, but the combination of
+ * a control surface and the mouse could make
+ * it possible to put the control into Touch
+ * mode *while* touching it.
+ */
+ AutomationWatch::instance().add_automation_watch (shared_from_this());
+ }
+ } else {
+ AutomationWatch::instance().remove_automation_watch (shared_from_this());
+ }
+ }
+}
+
+void
+AutomationControl::set_automation_style (AutoStyle as)
+{
+ if (!_list) return;
+ alist()->set_automation_style (as);
+}
+
+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)