GenericUI: replace if() by assert()
[ardour.git] / gtk2_ardour / automation_line.cc
index 4d39ff9b874d623f20be310e8efd5e26053502d9..a422bf972331c5e284510b31a8200b481684ff60 100644 (file)
 
 */
 
+#include <cmath>
+
 #ifdef COMPILER_MSVC
 #include <float.h>
-/* isinf() & isnan() are C99 standards, which older MSVC doesn't provide */
-#define isinf(val) !((bool)_finite((double)val))
-#define isnan(val) (bool)_isnan((double)val)
+
+// 'std::isnan()' is not available in MSVC.
+#define isnan_local(val) (bool)_isnan((double)val)
+#else
+#define isnan_local std::isnan
 #endif
 
-#include <cmath>
 #include <climits>
 #include <vector>
-#include <fstream>
 
 #include "boost/shared_ptr.hpp"
 
 #include "control_point.h"
 #include "gui_thread.h"
 #include "rgb_macros.h"
-#include "ardour_ui.h"
 #include "public_editor.h"
 #include "selection.h"
 #include "time_axis_view.h"
 #include "point_selection.h"
 #include "automation_time_axis.h"
+#include "ui_config.h"
 
 #include "ardour/event_type_map.h"
 #include "ardour/session.h"
 #include "ardour/value_as_string.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -84,6 +86,7 @@ AutomationLine::AutomationLine (const string&                              name,
        , _parent_group (parent)
        , _offset (0)
        , _maximum_time (max_framepos)
+       , _fill (false)
        , _desc (desc)
 {
        if (converter) {
@@ -91,7 +94,7 @@ AutomationLine::AutomationLine (const string&                              name,
        } else {
                _our_time_converter = true;
        }
-       
+
        _visible = Line;
 
        update_pending = false;
@@ -102,7 +105,7 @@ AutomationLine::AutomationLine (const string&                              name,
        terminal_points_can_slide = true;
        _height = 0;
 
-       group = new ArdourCanvas::Container (&parent);
+       group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple(0, 1.5));
        CANVAS_DEBUG_NAME (group, "region gain envelope group");
 
        line = new ArdourCanvas::PolyLine (group);
@@ -116,8 +119,8 @@ AutomationLine::AutomationLine (const string&                              name,
        trackview.session()->register_with_memento_command_factory(alist->id(), this);
 
        if (alist->parameter().type() == GainAutomation ||
-           alist->parameter().type() == EnvelopeAutomation ||
-           desc.unit == ParameterDescriptor::DB) {
+           alist->parameter().type() == TrimAutomation ||
+           alist->parameter().type() == EnvelopeAutomation) {
                set_uses_gain_mapping (true);
        }
 
@@ -153,7 +156,7 @@ void
 AutomationLine::update_visibility ()
 {
        if (_visible & Line) {
-               /* Only show the line there are some points, otherwise we may show an out-of-date line
+               /* Only show the line when there are some points, otherwise we may show an out-of-date line
                   when automation points have been removed (the line will still follow the shape of the
                   old points).
                */
@@ -169,7 +172,7 @@ AutomationLine::update_visibility ()
                        }
                } else if (_visible & SelectedControlPoints) {
                        for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
-                               if ((*i)->get_selected()) {
+                               if ((*i)->selected()) {
                                        (*i)->show ();
                                } else {
                                        (*i)->hide ();
@@ -198,9 +201,9 @@ void
 AutomationLine::hide ()
 {
        /* leave control points setting unchanged, we are just hiding the
-          overall line 
+          overall line
        */
-       
+
        set_visibility (AutomationLine::VisibleAspects (_visible & ~Line));
 }
 
@@ -227,6 +230,11 @@ AutomationLine::set_height (guint32 h)
                        (*i)->set_size (bsz);
                }
 
+               if (_fill) {
+                       line->set_fill_y1 (_height);
+               } else {
+                       line->set_fill_y1 (0);
+               }
                reset ();
        }
 }
@@ -236,6 +244,7 @@ AutomationLine::set_line_color (uint32_t color)
 {
        _line_color = color;
        line->set_outline_color (color);
+       line->set_fill_color ((color & 0xffff00) + 80); // XXX TODO configurable transparency
 }
 
 void
@@ -280,28 +289,28 @@ AutomationLine::modify_point_y (ControlPoint& cp, double y)
 
        double const x = trackview.editor().sample_to_pixel_unrounded (_time_converter->to((*cp.model())->when) - _offset);
 
-       trackview.editor().session()->begin_reversible_command (_("automation event move"));
+       trackview.editor().begin_reversible_command (_("automation event move"));
        trackview.editor().session()->add_command (
                new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
 
        cp.move_to (x, y, ControlPoint::Full);
 
+       alist->freeze ();
+       sync_model_with_view_point (cp);
+       alist->thaw ();
+
        reset_line_coords (cp);
 
        if (line_points.size() > 1) {
                line->set_steps (line_points, is_stepped());
        }
 
-       alist->freeze ();
-       sync_model_with_view_point (cp);
-       alist->thaw ();
-
        update_pending = false;
 
        trackview.editor().session()->add_command (
                new MementoCommand<AutomationList> (memento_command_binder(), 0, &alist->get_state()));
 
-       trackview.editor().session()->commit_reversible_command ();
+       trackview.editor().commit_reversible_command ();
        trackview.editor().session()->set_dirty ();
 }
 
@@ -314,14 +323,17 @@ AutomationLine::reset_line_coords (ControlPoint& cp)
        }
 }
 
-void
+bool
 AutomationLine::sync_model_with_view_points (list<ControlPoint*> cp)
 {
        update_pending = true;
 
+       bool moved = false;
        for (list<ControlPoint*>::iterator i = cp.begin(); i != cp.end(); ++i) {
-               sync_model_with_view_point (**i);
+               moved = sync_model_with_view_point (**i) || moved;
        }
+
+       return moved;
 }
 
 string
@@ -369,10 +381,16 @@ AutomationLine::fraction_to_string (double fraction) const
 {
        if (_uses_gain_mapping) {
                char buf[32];
-               if (fraction == 0.0) {
-                       snprintf (buf, sizeof (buf), "-inf");
+               if (_desc.type == GainAutomation || _desc.type == EnvelopeAutomation || _desc.lower == 0) {
+                       if (fraction == 0.0) {
+                               snprintf (buf, sizeof (buf), "-inf");
+                       } else {
+                               snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, _desc.upper)));
+                       }
                } else {
-                       snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain())));
+                       const double lower_db = accurate_coefficient_to_dB (_desc.lower);
+                       const double range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db;
+                       snprintf (buf, sizeof (buf), "%.1f", lower_db + fraction * range_db);
                }
                return buf;
        } else {
@@ -453,16 +471,15 @@ AutomationLine::string_to_fraction (string const & s) const
 void
 AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction)
 {
-       trackview.editor().session()->begin_reversible_command (_("automation event move"));
        trackview.editor().session()->add_command (
                new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
 
        _drag_points.clear ();
        _drag_points.push_back (cp);
 
-       if (cp->get_selected ()) {
+       if (cp->selected ()) {
                for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
-                       if (*i != cp && (*i)->get_selected()) {
+                       if (*i != cp && (*i)->selected()) {
                                _drag_points.push_back (*i);
                        }
                }
@@ -479,7 +496,6 @@ AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction)
 void
 AutomationLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction)
 {
-       trackview.editor().session()->begin_reversible_command (_("automation range move"));
        trackview.editor().session()->add_command (
                new MementoCommand<AutomationList> (memento_command_binder (), &get_state(), 0));
 
@@ -499,7 +515,6 @@ AutomationLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction)
 void
 AutomationLine::start_drag_multiple (list<ControlPoint*> cp, float fraction, XMLNode* state)
 {
-       trackview.editor().session()->begin_reversible_command (_("automation range move"));
        trackview.editor().session()->add_command (
                new MementoCommand<AutomationList> (memento_command_binder(), state, 0));
 
@@ -512,13 +527,13 @@ struct ControlPointSorter
        bool operator() (ControlPoint const * a, ControlPoint const * b) const {
                if (floateq (a->get_x(), b->get_x(), 1)) {
                        return a->view_index() < b->view_index();
-               } 
+               }
                return a->get_x() < b->get_x();
        }
 };
 
 AutomationLine::ContiguousControlPoints::ContiguousControlPoints (AutomationLine& al)
-       : line (al), before_x (0), after_x (DBL_MAX) 
+       : line (al), before_x (0), after_x (DBL_MAX)
 {
 }
 
@@ -530,7 +545,7 @@ AutomationLine::ContiguousControlPoints::compute_x_bounds (PublicEditor& e)
        if (sz > 0 && sz < line.npoints()) {
                const TempoMap& map (e.session()->tempo_map());
 
-               /* determine the limits on x-axis motion for this 
+               /* determine the limits on x-axis motion for this
                   contiguous range of control points
                */
 
@@ -538,8 +553,8 @@ AutomationLine::ContiguousControlPoints::compute_x_bounds (PublicEditor& e)
                        before_x = line.nth (front()->view_index() - 1)->get_x();
 
                        const framepos_t pos = e.pixel_to_sample(before_x);
-                       const Meter& meter = map.meter_at (pos);
-                       const framecnt_t len = ceil (meter.frames_per_bar (map.tempo_at (pos), e.session()->frame_rate())
+                       const Meter& meter = map.meter_at_frame (pos);
+                       const framecnt_t len = ceil (meter.frames_per_bar (map.tempo_at_frame (pos), e.session()->frame_rate())
                                        / (Timecode::BBT_Time::ticks_per_beat * meter.divisions_per_bar()) );
                        const double one_tick_in_pixels = e.sample_to_pixel_unrounded (len);
 
@@ -554,8 +569,8 @@ AutomationLine::ContiguousControlPoints::compute_x_bounds (PublicEditor& e)
                        after_x = line.nth (back()->view_index() + 1)->get_x();
 
                        const framepos_t pos = e.pixel_to_sample(after_x);
-                       const Meter& meter = map.meter_at (pos);
-                       const framecnt_t len = ceil (meter.frames_per_bar (map.tempo_at (pos), e.session()->frame_rate())
+                       const Meter& meter = map.meter_at_frame (pos);
+                       const framecnt_t len = ceil (meter.frames_per_bar (map.tempo_at_frame (pos), e.session()->frame_rate())
                                        / (Timecode::BBT_Time::ticks_per_beat * meter.divisions_per_bar()));
                        const double one_tick_in_pixels = e.sample_to_pixel_unrounded (len);
 
@@ -564,8 +579,8 @@ AutomationLine::ContiguousControlPoints::compute_x_bounds (PublicEditor& e)
        }
 }
 
-double 
-AutomationLine::ContiguousControlPoints::clamp_dx (double dx) 
+double
+AutomationLine::ContiguousControlPoints::clamp_dx (double dx)
 {
        if (empty()) {
                return dx;
@@ -573,10 +588,10 @@ AutomationLine::ContiguousControlPoints::clamp_dx (double dx)
 
        /* get the maximum distance we can move any of these points along the x-axis
         */
-       
+
        double tx; /* possible position a point would move to, given dx */
        ControlPoint* cp;
-       
+
        if (dx > 0) {
                /* check the last point, since we're moving later in time */
                cp = back();
@@ -585,14 +600,14 @@ AutomationLine::ContiguousControlPoints::clamp_dx (double dx)
                cp = front();
        }
 
-       tx = cp->get_x() + dx; // new possible position if we just add the motion 
+       tx = cp->get_x() + dx; // new possible position if we just add the motion
        tx = max (tx, before_x); // can't move later than following point
        tx = min (tx, after_x);  // can't move earlier than preceeding point
-       return  tx - cp->get_x (); 
+       return  tx - cp->get_x ();
 }
 
-void 
-AutomationLine::ContiguousControlPoints::move (double dx, double dy) 
+void
+AutomationLine::ContiguousControlPoints::move (double dx, double dy)
 {
        for (std::list<ControlPoint*>::iterator i = begin(); i != end(); ++i) {
                (*i)->move_to ((*i)->get_x() + dx, (*i)->get_y() - line.height() * dy, ControlPoint::Full);
@@ -636,19 +651,19 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool
 
        if (!_drag_had_movement) {
 
-               /* "first move" ... do some stuff that we don't want to do if 
+               /* "first move" ... do some stuff that we don't want to do if
                   no motion ever took place, but need to do before we handle
                   motion.
                */
-       
+
                /* partition the points we are dragging into (potentially several)
                 * set(s) of contiguous points. this will not happen with a normal
                 * drag, but if the user does a discontiguous selection, it can.
                 */
-               
+
                uint32_t expected_view_index = 0;
                CCP contig;
-               
+
                for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
                        if (i == _drag_points.begin() || (*i)->view_index() != expected_view_index) {
                                contig.reset (new ContiguousControlPoints (*this));
@@ -665,13 +680,14 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool
                for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
                        (*ccp)->compute_x_bounds (trackview.editor());
                }
-       }       
+               _drag_had_movement = true;
+       }
 
        /* OK, now on to the stuff related to *this* motion event. First, for
         * each contiguous range, figure out the maximum x-axis motion we are
         * allowed (because of neighbouring points that are not moving.
-        * 
-        * if we are moving forwards with push, we don't need to do this, 
+        *
+        * if we are moving forwards with push, we don't need to do this,
         * since all later points will move too.
         */
 
@@ -685,7 +701,6 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool
        }
 
        /* clamp y */
-       
        for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
                double const y = ((_height - (*i)->get_y()) / _height) + dy;
                if (y < 0) {
@@ -699,7 +714,7 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool
        if (dx || dy) {
 
                /* and now move each section */
-               
+
                for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
                        (*ccp)->move (dx, dy);
                }
@@ -721,14 +736,13 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool
                        line->set_steps (line_points, is_stepped());
                }
        }
-       
+       double const result_frac = _last_drag_fraction + dy;
        _drag_distance += dx;
        _drag_x += dx;
-       _last_drag_fraction = fraction;
-       _drag_had_movement = true;
+       _last_drag_fraction = result_frac;
        did_push = with_push;
 
-       return pair<double, float> (_drag_x + dx, _last_drag_fraction + dy);
+       return pair<double, float> (_drag_x + dx, result_frac);
 }
 
 /** Should be called to indicate the end of a drag */
@@ -740,13 +754,13 @@ AutomationLine::end_drag (bool with_push, uint32_t final_index)
        }
 
        alist->freeze ();
-       sync_model_with_view_points (_drag_points);
+       bool moved = sync_model_with_view_points (_drag_points);
 
        if (with_push) {
                ControlPoint* p;
                uint32_t i = final_index;
                while ((p = nth (i)) != 0 && p->can_slide()) {
-                       sync_model_with_view_point (*p);
+                       moved = sync_model_with_view_point (*p) || moved;
                        ++i;
                }
        }
@@ -755,6 +769,12 @@ AutomationLine::end_drag (bool with_push, uint32_t final_index)
 
        update_pending = false;
 
+       if (moved) {
+               /* A point has moved as a result of sync (clamped to integer or boolean
+                  value), update line accordingly. */
+               line->set_steps (line_points, is_stepped());
+       }
+
        trackview.editor().session()->add_command (
                new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state()));
 
@@ -764,7 +784,7 @@ AutomationLine::end_drag (bool with_push, uint32_t final_index)
        contiguous_points.clear ();
 }
 
-void
+bool
 AutomationLine::sync_model_with_view_point (ControlPoint& cp)
 {
        /* find out where the visual control point is.
@@ -789,6 +809,17 @@ AutomationLine::sync_model_with_view_point (ControlPoint& cp)
        view_to_model_coord_y (view_y);
 
        alist->modify (cp.model(), view_x, view_y);
+
+       /* convert back from model to view y for clamping position (for integer/boolean/etc) */
+       model_to_view_coord_y (view_y);
+       const double point_y = _height - (view_y * _height);
+       if (point_y != cp.get_y()) {
+               cp.move_to (cp.get_x(), point_y, ControlPoint::Full);
+               reset_line_coords (cp);
+               return true;
+       }
+
+       return false;
 }
 
 bool
@@ -854,15 +885,16 @@ AutomationLine::is_first_point (ControlPoint& cp)
 void
 AutomationLine::remove_point (ControlPoint& cp)
 {
-       trackview.editor().session()->begin_reversible_command (_("remove control point"));
+       trackview.editor().begin_reversible_command (_("remove control point"));
        XMLNode &before = alist->get_state();
 
+       trackview.editor ().get_selection ().clear_points ();
        alist->erase (cp.model());
-       
+
        trackview.editor().session()->add_command(
                new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
 
-       trackview.editor().session()->commit_reversible_command ();
+       trackview.editor().commit_reversible_command ();
        trackview.editor().session()->set_dirty ();
 }
 
@@ -886,7 +918,7 @@ AutomationLine::get_selectables (framepos_t start, framepos_t end, double botfra
                /* model_when is relative to the start of the source, so we just need to add on the origin_b here
                   (as it is the session frame position of the start of the source)
                */
-               
+
                framepos_t const session_frames_when = _time_converter->to (model_when) + _time_converter->origin_b ();
 
                if (session_frames_when >= start && session_frames_when <= end && (*i)->get_y() >= bot_track && (*i)->get_y() <= top_track) {
@@ -921,9 +953,10 @@ AutomationLine::set_selected_points (PointSelection const & points)
        set_colors ();
 }
 
-void AutomationLine::set_colors ()
+void
+AutomationLine::set_colors ()
 {
-       set_line_color (ARDOUR_UI::config()->get_AutomationLine());
+       set_line_color (UIConfiguration::instance().color ("automation line"));
        for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
                (*i)->set_color ();
        }
@@ -966,7 +999,7 @@ AutomationLine::reset_callback (const Evoral::ControlList& events)
        np = events.size();
 
        Evoral::ControlList& e = const_cast<Evoral::ControlList&> (events);
-       
+
        for (AutomationList::iterator ai = e.begin(); ai != e.end(); ++ai, ++pi) {
 
                double tx = (*ai)->when;
@@ -976,22 +1009,22 @@ AutomationLine::reset_callback (const Evoral::ControlList& events)
 
                model_to_view_coord (tx, ty);
 
-               if (isnan (tx) || isnan (ty)) {
+               if (isnan_local (tx) || isnan_local (ty)) {
                        warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
                                                   _name) << endmsg;
                        continue;
                }
-               
+
                if (tx >= max_framepos || tx < 0 || tx >= _maximum_time) {
                        continue;
                }
-               
+
                /* convert x-coordinate to a canvas unit coordinate (this takes
                 * zoom and scroll into account).
                 */
-                       
+
                tx = trackview.editor().sample_to_pixel_unrounded (tx);
-               
+
                /* convert from canonical view height (0..1.0) to actual
                 * height coordinates (using X11's top-left rooted system)
                 */
@@ -1085,11 +1118,6 @@ AutomationLine::clear ()
                new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
 }
 
-void
-AutomationLine::change_model (AutomationList::iterator /*i*/, double /*x*/, double /*y*/)
-{
-}
-
 void
 AutomationLine::set_list (boost::shared_ptr<ARDOUR::AutomationList> list)
 {
@@ -1167,12 +1195,22 @@ AutomationLine::view_to_model_coord (double& x, double& y) const
 void
 AutomationLine::view_to_model_coord_y (double& y) const
 {
-       /* TODO: This should be more generic (use ParameterDescriptor) */
-       if (alist->parameter().type() == GainAutomation ||
-           alist->parameter().type() == EnvelopeAutomation) {
-               y = slider_position_to_gain_with_max (y, Config->get_max_gain());
+       /* TODO: This should be more generic (use ParameterDescriptor)
+        * or better yet:  Controllable -> set_interface();
+        */
+       if (   alist->parameter().type() == GainAutomation
+           || alist->parameter().type() == EnvelopeAutomation
+           || (_desc.logarithmic && _desc.lower == 0. && _desc.upper > _desc.lower)) {
+               y = slider_position_to_gain_with_max (y, _desc.upper);
+               y = max ((double)_desc.lower, y);
+               y = min ((double)_desc.upper, y);
+       } else if (alist->parameter().type() == TrimAutomation
+                  || (_desc.logarithmic && _desc.lower * _desc.upper > 0 && _desc.upper > _desc.lower)) {
+               const double lower_db = accurate_coefficient_to_dB (_desc.lower);
+               const double range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db;
                y = max (0.0, y);
-               y = min (2.0, y);
+               y = min (1.0, y);
+               y = dB_to_coefficient (lower_db + y * range_db);
        } else if (alist->parameter().type() == PanAzimuthAutomation ||
                   alist->parameter().type() == PanElevationAutomation) {
                y = 1.0 - y;
@@ -1180,19 +1218,27 @@ AutomationLine::view_to_model_coord_y (double& y) const
                y = 2.0 * y - 1.0;
        } else {
                y = y * (double)(alist->get_max_y() - alist->get_min_y()) + alist->get_min_y();
-               if (_desc.toggled || _desc.integer_step) {
+               if (_desc.integer_step) {
                        y = round(y);
+               } else if (_desc.toggled) {
+                       y = (y > 0.5) ? 1.0 : 0.0;
                }
        }
 }
 
 void
-AutomationLine::model_to_view_coord (double& x, double& y) const
+AutomationLine::model_to_view_coord_y (double& y) const
 {
        /* TODO: This should be more generic (use ParameterDescriptor) */
-       if (alist->parameter().type() == GainAutomation ||
-           alist->parameter().type() == EnvelopeAutomation) {
-               y = gain_to_slider_position_with_max (y, Config->get_max_gain());
+       if (   alist->parameter().type() == GainAutomation
+           || alist->parameter().type() == EnvelopeAutomation
+           || (_desc.logarithmic && _desc.lower == 0. && _desc.upper > _desc.lower)) {
+               y = gain_to_slider_position_with_max (y, _desc.upper);
+       } else if (alist->parameter().type() == TrimAutomation
+                  || (_desc.logarithmic && _desc.lower * _desc.upper > 0 && _desc.upper > _desc.lower)) {
+               const double lower_db = accurate_coefficient_to_dB (_desc.lower);
+               const double range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db;
+               y = (accurate_coefficient_to_dB (y) - lower_db) / range_db;
        } else if (alist->parameter().type() == PanAzimuthAutomation ||
                   alist->parameter().type() == PanElevationAutomation) {
                y = 1.0 - y;
@@ -1201,7 +1247,12 @@ AutomationLine::model_to_view_coord (double& x, double& y) const
        } else {
                y = (y - alist->get_min_y()) / (double)(alist->get_max_y() - alist->get_min_y());
        }
+}
 
+void
+AutomationLine::model_to_view_coord (double& x, double& y) const
+{
+       model_to_view_coord_y (y);
        x = _time_converter->to (x) - _offset;
 }
 
@@ -1215,7 +1266,7 @@ AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
 }
 
 void
-AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty, 
+AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty,
                                            AutomationList::iterator model, uint32_t npoints)
 {
        ControlPoint::ShapeType shape;