+ return alist->set_state (node, version);
+}
+
+void
+AutomationLine::view_to_model_coord (double& x, double& y) const
+{
+ x = _time_converter.from (x);
+ view_to_model_coord_y (y);
+}
+
+void
+AutomationLine::view_to_model_coord_y (double& y) const
+{
+ /* TODO: This should be more generic ... */
+ if (alist->parameter().type() == GainAutomation ||
+ alist->parameter().type() == EnvelopeAutomation) {
+ y = slider_position_to_gain (y);
+ y = max (0.0, y);
+ y = min (2.0, y);
+ } else if (alist->parameter().type() == PanAzimuthAutomation ||
+ alist->parameter().type() == PanElevationAutomation ||
+ alist->parameter().type() == PanWidthAutomation) {
+ y = 1.0 - y;
+ } else if (alist->parameter().type() == PluginAutomation) {
+ y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y();
+ } else {
+ y = rint (y * alist->parameter().max());
+ }
+}
+
+void
+AutomationLine::model_to_view_coord (double& x, double& y) const
+{
+ /* TODO: This should be more generic ... */
+ if (alist->parameter().type() == GainAutomation ||
+ alist->parameter().type() == EnvelopeAutomation) {
+ y = gain_to_slider_position (y);
+ } else if (alist->parameter().type() == PanAzimuthAutomation ||
+ alist->parameter().type() == PanElevationAutomation ||
+ alist->parameter().type() == PanWidthAutomation) {
+ // vertical coordinate axis reversal
+ y = 1.0 - y;
+ } else if (alist->parameter().type() == PluginAutomation) {
+ y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y());
+ } else {
+ y = y / (double)alist->parameter().max(); /* ... like this */
+ }
+
+ x = _time_converter.to (x) - _offset;
+}
+
+/** Called when our list has announced that its interpolation style has changed */
+void
+AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
+{
+ if (style == AutomationList::Discrete) {
+ show_all_control_points();
+ line->hide();
+ } else {
+ hide_all_but_selected_control_points();
+ line->show();
+ }
+}
+
+void
+AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty, AutomationList::iterator model, uint32_t npoints)
+{
+ if (view_index >= control_points.size()) {
+
+ /* make sure we have enough control points */
+
+ ControlPoint* ncp = new ControlPoint (*this);
+ ncp->set_size (control_point_box_size ());
+
+ control_points.push_back (ncp);
+ }
+
+ ControlPoint::ShapeType shape;
+
+ if (!terminal_points_can_slide) {
+ if (pi == 0) {
+ control_points[view_index]->set_can_slide(false);
+ if (tx == 0) {
+ shape = ControlPoint::Start;
+ } else {
+ shape = ControlPoint::Full;
+ }
+ } else if (pi == npoints - 1) {
+ control_points[view_index]->set_can_slide(false);
+ shape = ControlPoint::End;
+ } else {
+ control_points[view_index]->set_can_slide(true);
+ shape = ControlPoint::Full;
+ }
+ } else {
+ control_points[view_index]->set_can_slide(true);
+ shape = ControlPoint::Full;
+ }
+
+ control_points[view_index]->reset (tx, ty, model, view_index, shape);
+
+ /* finally, control visibility */
+
+ if (_visible && points_visible) {
+ control_points[view_index]->show ();
+ control_points[view_index]->set_visible (true);
+ } else {
+ if (!points_visible) {
+ control_points[view_index]->set_visible (false);
+ }
+ }
+}
+
+void
+AutomationLine::add_always_in_view (double x)
+{
+ _always_in_view.push_back (x);
+ alist->apply_to_points (*this, &AutomationLine::reset_callback);
+}
+
+void
+AutomationLine::clear_always_in_view ()
+{
+ _always_in_view.clear ();
+ alist->apply_to_points (*this, &AutomationLine::reset_callback);
+}
+
+void
+AutomationLine::connect_to_list ()
+{
+ _list_connections.drop_connections ();
+
+ alist->StateChanged.connect (_list_connections, invalidator (*this), boost::bind (&AutomationLine::list_changed, this), gui_context());
+
+ alist->InterpolationChanged.connect (
+ _list_connections, invalidator (*this), boost::bind (&AutomationLine::interpolation_changed, this, _1), gui_context()
+ );
+}
+
+MementoCommandBinder<AutomationList>*
+AutomationLine::memento_command_binder ()
+{
+ return new SimpleMementoCommandBinder<AutomationList> (*alist.get());
+}
+
+/** Set the maximum time that points on this line can be at, relative
+ * to the start of the track or region that it is on.
+ */
+void
+AutomationLine::set_maximum_time (framecnt_t t)
+{
+ if (_maximum_time == t) {
+ return;
+ }
+
+ _maximum_time = t;
+ reset ();
+}
+
+
+/** @return min and max x positions of points that are in the list, in session frames */
+pair<framepos_t, framepos_t>
+AutomationLine::get_point_x_range () const
+{
+ pair<framepos_t, framepos_t> r (max_framepos, 0);
+
+ for (AutomationList::const_iterator i = the_list()->begin(); i != the_list()->end(); ++i) {
+ r.first = min (r.first, _time_converter.to ((*i)->when) + _offset + _time_converter.origin_b ());
+ r.second = max (r.second, _time_converter.to ((*i)->when) + _offset + _time_converter.origin_b ());
+ }
+
+ return r;
+}
+
+void
+AutomationLine::set_offset (framepos_t off)
+{
+ if (_offset == off) {
+ return;
+ }
+
+ _offset = off;
+ reset ();