Less code.
[ardour.git] / libs / ardour / automatable.cc
index 5ae4e96b4e1f87436e53a0356ba9ed350e6d22b6..03e5ad97c31e7d511222931fb86e24a3085652d5 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "pbd/error.h"
 #include "pbd/enumwriter.h"
+#include "pbd/stacktrace.h"
 
 #include "midi++/names.h"
 
@@ -44,7 +45,7 @@ using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
-nframes_t Automatable::_automation_interval = 0;
+framecnt_t Automatable::_automation_interval = 0;
 
 Automatable::Automatable(Session& session)
        : _a_session(session)
@@ -223,7 +224,7 @@ Automatable::mark_automation_visible (Evoral::Parameter what, bool yn)
  * pass that type and it will be used for the untyped AutomationList found.
  */
 int
-Automatable::set_automation_state (const XMLNode& node, Evoral::Parameter legacy_param)
+Automatable::set_automation_xml_state (const XMLNode& node, Evoral::Parameter legacy_param)
 {
        Glib::Mutex::Lock lm (control_lock());
 
@@ -252,7 +253,7 @@ Automatable::set_automation_state (const XMLNode& node, Evoral::Parameter legacy
                        if (param.type() == NullAutomation) {
                                warning << "Automation has null type" << endl;
                                continue;
-                       }
+                        }
 
                        boost::shared_ptr<AutomationList> al (new AutomationList(**niter, param));
 
@@ -271,7 +272,7 @@ Automatable::set_automation_state (const XMLNode& node, Evoral::Parameter legacy
                        }
 
                } else {
-                       error << "Expected AutomationList node, got '" << (*niter)->name() << endmsg;
+                       error << "Expected AutomationList node, got '" << (*niter)->name() << "'" << endmsg;
                }
        }
 
@@ -281,7 +282,7 @@ Automatable::set_automation_state (const XMLNode& node, Evoral::Parameter legacy
 }
 
 XMLNode&
-Automatable::get_automation_state ()
+Automatable::get_automation_xml_state ()
 {
        Glib::Mutex::Lock lm (control_lock());
        XMLNode* node = new XMLNode (X_("Automation"));
@@ -386,14 +387,14 @@ Automatable::protect_automation ()
 }
 
 void
-Automatable::automation_snapshot (nframes_t now, bool force)
+Automatable::automation_snapshot (framepos_t now, bool force)
 {
        if (force || _last_automation_snapshot > now || (now - _last_automation_snapshot) > _automation_interval) {
 
                for (Controls::iterator i = controls().begin(); i != controls().end(); ++i) {
                        boost::shared_ptr<AutomationControl> c
                                        = boost::dynamic_pointer_cast<AutomationControl>(i->second);
-                       if (c->automation_write()) {
+                       if (_a_session.transport_rolling() && c->automation_write()) {
                                c->list()->rt_add (now, i->second->user_double());
                        }
                }
@@ -403,20 +404,28 @@ Automatable::automation_snapshot (nframes_t now, bool force)
 }
 
 void
-Automatable::transport_stopped (sframes_t now)
+Automatable::transport_stopped (framepos_t now)
 {
        for (Controls::iterator li = controls().begin(); li != controls().end(); ++li) {
 
                boost::shared_ptr<AutomationControl> c
                                = boost::dynamic_pointer_cast<AutomationControl>(li->second);
-               boost::shared_ptr<AutomationList> l
+                if (c) {
+                        boost::shared_ptr<AutomationList> l
                                = boost::dynamic_pointer_cast<AutomationList>(c->list());
-
-               c->list()->reposition_for_rt_add (now);
-
-               if (c->automation_state() != Off) {
-                       c->set_value(c->list()->eval(now));
-               }
+                        
+                        if (l) {
+                                l->write_pass_finished (now);
+                                
+                                if (l->automation_playback()) {
+                                        c->set_value(c->list()->eval(now));
+                                }
+                                
+                                if (l->automation_state() == Write) {
+                                        l->set_automation_state (Touch);
+                                }
+                        }
+                }
        }
 }
 
@@ -447,9 +456,10 @@ Automatable::control_factory(const Evoral::Parameter& param)
                        warning << "GainAutomation for non-Amp" << endl;
                }
        } else if (param.type() == PanAutomation) {
-               Panner* me = dynamic_cast<Panner*>(this);
-               if (me) {
-                       control = new Panner::PanControllable(me->session(), X_("panner"), *me, param);
+               Panner* panner = dynamic_cast<Panner*>(this);
+               if (panner) {
+                        StreamPanner& sp (panner->streampanner (param.channel()));
+                       control = new StreamPanner::PanControllable (_a_session, X_("direction"), &sp, param);
                } else {
                        warning << "PanAutomation for non-Panner" << endl;
                }