fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / automatable.cc
index 0fb048b9ef879c8aa149d3e944c09428127523b4..10d2565c90c4be3ce7f96e965e42856cf59ac8f7 100644 (file)
 #include "ardour/amp.h"
 #include "ardour/automatable.h"
 #include "ardour/event_type_map.h"
+#include "ardour/gain_control.h"
+#include "ardour/monitor_control.h"
 #include "ardour/midi_track.h"
 #include "ardour/pan_controllable.h"
 #include "ardour/pannable.h"
 #include "ardour/plugin.h"
 #include "ardour/plugin_insert.h"
+#include "ardour/record_enable_control.h"
 #include "ardour/session.h"
 #include "ardour/uri_map.h"
 #include "ardour/value_as_string.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -76,7 +79,7 @@ Automatable::~Automatable ()
 int
 Automatable::old_set_automation_state (const XMLNode& node)
 {
-       const XMLProperty *prop;
+       XMLProperty const * prop;
 
        if ((prop = node.property ("path")) != 0) {
                load_automation (prop->value());
@@ -147,7 +150,9 @@ Automatable::add_control(boost::shared_ptr<Evoral::Control> ac)
 
        boost::shared_ptr<AutomationList> al = boost::dynamic_pointer_cast<AutomationList> (ac->list ());
 
-       if (al) {
+       boost::shared_ptr<AutomationControl> actl (boost::dynamic_pointer_cast<AutomationControl> (ac));
+
+       if ((!actl || !(actl->flags() & Controllable::NotAutomatable)) && al) {
                al->automation_state_changed.connect_same_thread (
                        _list_connections,
                        boost::bind (&Automatable::automation_list_automation_state_changed,
@@ -156,7 +161,7 @@ Automatable::add_control(boost::shared_ptr<Evoral::Control> ac)
 
        ControlSet::add_control (ac);
 
-       if (al) {
+       if ((!actl || !(actl->flags() & Controllable::NotAutomatable)) && al) {
                _can_automate_list.insert (param);
                automation_list_automation_state_changed (param, al->automation_state ()); // sync everything up
        }
@@ -219,7 +224,7 @@ Automatable::set_automation_xml_state (const XMLNode& node, Evoral::Parameter le
 
                if ((*niter)->name() == "AutomationList") {
 
-                       const XMLProperty* id_prop = (*niter)->property("automation-id");
+                       XMLProperty const * id_prop = (*niter)->property("automation-id");
 
                        Evoral::Parameter param = (id_prop
                                        ? EventTypeMap::instance().from_symbol(id_prop->value())
@@ -228,7 +233,12 @@ Automatable::set_automation_xml_state (const XMLNode& node, Evoral::Parameter le
                        if (param.type() == NullAutomation) {
                                warning << "Automation has null type" << endl;
                                continue;
-                        }
+                       }
+
+                       if (_can_automate_list.find (param) == _can_automate_list.end ()) {
+                               warning << "Ignored automation data for non-automatable parameter" << endl;
+                               continue;
+                       }
 
                        if (!id_prop) {
                                warning << "AutomationList node without automation-id property, "
@@ -365,7 +375,7 @@ Automatable::transport_located (framepos_t now)
                         boost::shared_ptr<AutomationList> l
                                = boost::dynamic_pointer_cast<AutomationList>(c->list());
 
-                       if (l && l->automation_state () == Write) {
+                       if (l) {
                                l->start_write_pass (now);
                        }
                }
@@ -398,9 +408,7 @@ Automatable::transport_stopped (framepos_t now)
 
                l->stop_touch (true, now);
 
-               if (list_did_write) {
-                       c->commit_transaction ();
-               }
+               c->commit_transaction (list_did_write);
 
                l->write_pass_finished (now, Config->get_automation_thinning_factor ());
 
@@ -409,7 +417,7 @@ Automatable::transport_stopped (framepos_t now)
                }
 
                if (l->automation_playback ()) {
-                       c->set_value (c->list ()->eval (now));
+                       c->set_value_unchecked (c->list ()->eval (now));
                }
        }
 }
@@ -421,6 +429,7 @@ Automatable::control_factory(const Evoral::Parameter& param)
        bool                              make_list = true;
        ParameterDescriptor               desc(param);
        boost::shared_ptr<AutomationList> list;
+
        if (param.type() >= MidiCCAutomation && param.type() <= MidiChannelPressureAutomation) {
                MidiTrack* mt = dynamic_cast<MidiTrack*>(this);
                if (mt) {
@@ -451,19 +460,9 @@ Automatable::control_factory(const Evoral::Parameter& param)
                        warning << "PluginPropertyAutomation for non-Plugin" << endl;
                }
        } else if (param.type() == GainAutomation) {
-               Amp* amp = dynamic_cast<Amp*>(this);
-               if (amp) {
-                       control = new Amp::GainControl(X_("gaincontrol"), _a_session, amp, param);
-               } else {
-                       warning << "GainAutomation for non-Amp" << endl;
-               }
+               control = new GainControl(_a_session, param);
        } else if (param.type() == TrimAutomation) {
-               Amp* amp = dynamic_cast<Amp*>(this);
-               if (amp) {
-                       control = new Amp::GainControl(X_("trimcontrol"), _a_session, amp, param);
-               } else {
-                       warning << "TrimAutomation for non-Amp" << endl;
-               }
+               control = new GainControl(_a_session, param);
        } else if (param.type() == PanAzimuthAutomation || param.type() == PanWidthAutomation || param.type() == PanElevationAutomation) {
                Pannable* pannable = dynamic_cast<Pannable*>(this);
                if (pannable) {
@@ -471,6 +470,27 @@ Automatable::control_factory(const Evoral::Parameter& param)
                } else {
                        warning << "PanAutomation for non-Pannable" << endl;
                }
+       } else if (param.type() == RecEnableAutomation) {
+               Recordable* re = dynamic_cast<Recordable*> (this);
+               if (re) {
+                       control = new RecordEnableControl (_a_session, X_("recenable"), *re);
+               }
+       } else if (param.type() == MonitoringAutomation) {
+               Monitorable* m = dynamic_cast<Monitorable*>(this);
+               if (m) {
+                       control = new MonitorControl (_a_session, X_("monitor"), *m);
+               }
+       } else if (param.type() == SoloAutomation) {
+               Soloable* s = dynamic_cast<Soloable*>(this);
+               Muteable* m = dynamic_cast<Muteable*>(this);
+               if (s && m) {
+                       control = new SoloControl (_a_session, X_("solo"), *s, *m);
+               }
+       } else if (param.type() == MuteAutomation) {
+               Muteable* m = dynamic_cast<Muteable*>(this);
+               if (m) {
+                       control = new MuteControl (_a_session, X_("mute"), *m);
+               }
        }
 
        if (make_list && !list) {
@@ -504,7 +524,7 @@ Automatable::clear_controls ()
 }
 
 string
-Automatable::value_as_string (boost::shared_ptr<AutomationControl> ac) const
+Automatable::value_as_string (boost::shared_ptr<const AutomationControl> ac) const
 {
        return ARDOUR::value_as_string(ac->desc(), ac->get_value());
 }