fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / automation_control.cc
index 2be0538229e89ca92754d4d455d9a086634996d8..e27da6ab08797f30badbec995de59bb33a57b136 100644 (file)
@@ -31,7 +31,7 @@
 #include "ardour/event_type_map.h"
 #include "ardour/session.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 #ifdef COMPILER_MSVC
 #include <float.h>
@@ -144,6 +144,8 @@ AutomationControl::set_automation_state (AutoState as)
        }
        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
@@ -152,6 +154,11 @@ AutomationControl::set_automation_state (AutoState as)
                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 {