fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / automation_control.cc
index 97765a7070f032e7a0bdca6565a573c44f95080b..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>
@@ -55,6 +55,9 @@ AutomationControl::AutomationControl(ARDOUR::Session&                          s
        , _session(session)
        , _desc(desc)
 {
+       if (_desc.toggled) {
+               set_flags (Controllable::Toggle);
+       }
 }
 
 AutomationControl::~AutomationControl ()
@@ -115,12 +118,14 @@ void
 AutomationControl::actually_set_value (double value, PBD::Controllable::GroupControlDisposition gcd)
 {
        bool to_list = _list && boost::dynamic_pointer_cast<AutomationList>(_list)->automation_write();
+       //const double old_value = Control::user_double ();
 
        Control::set_double (value, _session.transport_frame(), to_list);
 
-       AutomationType at = (AutomationType) _parameter.type();
+       //AutomationType at = (AutomationType) _parameter.type();
+       //std::cerr << "++++ Changed (" << enum_2_string (at) << ", " << enum_2_string (gcd) << ") = " << value 
+       //<< " (was " << old_value << ") @ " << this << std::endl;
 
-       std::cerr << "++++ Changed (" << enum_2_string (at) << ", " << enum_2_string (gcd) << ") = " << value << " @ " << this << std::endl;
        Changed (true, gcd);
 }
 
@@ -134,8 +139,13 @@ AutomationControl::set_list (boost::shared_ptr<Evoral::ControlList> list)
 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
@@ -144,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 {
@@ -282,7 +297,6 @@ AutomationControl::check_rt (double val, Controllable::GroupControlDisposition g
 {
        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;
        }