+void
+Automatable::transport_located (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);
+ if (c) {
+ boost::shared_ptr<AutomationList> l
+ = boost::dynamic_pointer_cast<AutomationList>(c->list());
+
+ if (l) {
+ l->start_write_pass (now);
+ }
+ }
+ }
+}
+
+void
+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);
+ if (!c) {
+ continue;
+ }
+
+ boost::shared_ptr<AutomationList> l =
+ boost::dynamic_pointer_cast<AutomationList>(c->list());
+ if (!l) {
+ continue;
+ }
+
+ /* Stop any active touch gesture just before we mark the write pass
+ as finished. If we don't do this, the transport can end up stopped with
+ an AutomationList thinking that a touch is still in progress and,
+ when the transport is re-started, a touch will magically
+ be happening without it ever have being started in the usual way.
+ */
+ const bool list_did_write = !l->in_new_write_pass ();
+
+ l->stop_touch (true, now);
+
+ c->commit_transaction (list_did_write);
+
+ l->write_pass_finished (now, Config->get_automation_thinning_factor ());
+
+ if (l->automation_state () == Write) {
+ l->set_automation_state (Touch);
+ }
+
+ if (l->automation_playback ()) {
+ c->set_value_unchecked (c->list ()->eval (now));
+ }
+ }
+}
+
+boost::shared_ptr<Evoral::Control>
+Automatable::control_factory(const Evoral::Parameter& param)
+{
+ Evoral::Control* control = NULL;
+ 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) {
+ control = new MidiTrack::MidiControl(mt, param);
+ make_list = false; // No list, this is region "automation"
+ }
+ } else if (param.type() == PluginAutomation) {
+ PluginInsert* pi = dynamic_cast<PluginInsert*>(this);
+ if (pi) {
+ pi->plugin(0)->get_parameter_descriptor(param.id(), desc);
+ control = new PluginInsert::PluginControl(pi, param, desc);
+ } else {
+ warning << "PluginAutomation for non-Plugin" << endl;
+ }
+ } else if (param.type() == PluginPropertyAutomation) {
+ PluginInsert* pi = dynamic_cast<PluginInsert*>(this);
+ if (pi) {
+ desc = pi->plugin(0)->get_property_descriptor(param.id());
+ if (desc.datatype != Variant::NOTHING) {
+ if (!Variant::type_is_numeric(desc.datatype)) {
+ make_list = false; // Can't automate non-numeric data yet
+ } else {
+ list = boost::shared_ptr<AutomationList>(new AutomationList(param, desc));
+ }
+ control = new PluginInsert::PluginPropertyControl(pi, param, desc, list);
+ }
+ } else {
+ warning << "PluginPropertyAutomation for non-Plugin" << endl;
+ }
+ } else if (param.type() == GainAutomation) {
+ control = new GainControl(_a_session, param);
+ } else if (param.type() == TrimAutomation) {
+ 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) {
+ control = new PanControllable (_a_session, pannable->describe_parameter (param), pannable, param);
+ } else {
+ warning << "PanAutomation for non-Pannable" << endl;
+ }
+ }
+
+ if (make_list && !list) {
+ list = boost::shared_ptr<AutomationList>(new AutomationList(param, desc));
+ }
+
+ if (!control) {
+ control = new AutomationControl(_a_session, param, desc, list);
+ }
+
+ return boost::shared_ptr<Evoral::Control>(control);
+}
+
+boost::shared_ptr<AutomationControl>
+Automatable::automation_control (const Evoral::Parameter& id, bool create)
+{
+ return boost::dynamic_pointer_cast<AutomationControl>(Evoral::ControlSet::control(id, create));
+}
+
+boost::shared_ptr<const AutomationControl>
+Automatable::automation_control (const Evoral::Parameter& id) const
+{
+ return boost::dynamic_pointer_cast<const AutomationControl>(Evoral::ControlSet::control(id));
+}
+
+void
+Automatable::clear_controls ()
+{
+ _control_connections.drop_connections ();
+ ControlSet::clear_controls ();
+}
+
+string
+Automatable::value_as_string (boost::shared_ptr<AutomationControl> ac) const
+{
+ return ARDOUR::value_as_string(ac->desc(), ac->get_value());
+}
+
+bool
+Automatable::find_next_event (double now, double end, Evoral::ControlEvent& next_event, bool only_active) const
+{
+ Controls::const_iterator li;
+
+ next_event.when = std::numeric_limits<double>::max();
+
+ for (li = _controls.begin(); li != _controls.end(); ++li) {
+ boost::shared_ptr<AutomationControl> c
+ = boost::dynamic_pointer_cast<AutomationControl>(li->second);
+
+ if (only_active && (!c || !c->automation_playback())) {
+ continue;
+ }
+
+ Evoral::ControlList::const_iterator i;
+ boost::shared_ptr<const Evoral::ControlList> alist (li->second->list());
+ Evoral::ControlEvent cp (now, 0.0f);
+ if (!alist) {
+ continue;
+ }
+
+ for (i = lower_bound (alist->begin(), alist->end(), &cp, Evoral::ControlList::time_comparator);
+ i != alist->end() && (*i)->when < end; ++i) {
+ if ((*i)->when > now) {
+ break;
+ }
+ }
+
+ if (i != alist->end() && (*i)->when < end) {
+ if ((*i)->when < next_event.when) {
+ next_event.when = (*i)->when;
+ }
+ }
+ }
+
+ return next_event.when != std::numeric_limits<double>::max();
+}