exercise subsurface rendering for x-fade curves
[ardour.git] / gtk2_ardour / automation_line.cc
index 02ce72149f09776f0a42e371ddcea4ee42dc0086..7e37c32eb734f3a37d22a0ad5e51f86a2623e7f4 100644 (file)
 
 */
 
+#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)
+#endif
+
 #include <cmath>
 #include <climits>
 #include <vector>
@@ -35,6 +42,8 @@
 
 #include "evoral/Curve.hpp"
 
+#include "canvas/debug.h"
+
 #include "automation_line.h"
 #include "control_point.h"
 #include "gui_thread.h"
@@ -61,8 +70,8 @@ using namespace Editing;
  *  This will not be deleted by AutomationLine.
  */
 AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanvas::Group& parent,
-               boost::shared_ptr<AutomationList> al,
-               Evoral::TimeConverter<double, framepos_t>* converter)
+                                boost::shared_ptr<AutomationList> al,
+                                Evoral::TimeConverter<double, framepos_t>* converter)
        : trackview (tv)
        , _name (name)
        , alist (al)
@@ -90,10 +99,13 @@ AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanv
        _height = 0;
 
        group = new ArdourCanvas::Group (&parent);
+       CANVAS_DEBUG_NAME (group, "region gain envelope group");
 
        line = new ArdourCanvas::PolyLine (group);
-       line->set_outline_width (1);
+       CANVAS_DEBUG_NAME (line, "region gain envelope line");
        line->set_data ("line", this);
+       line->set_outline_width (2.0);
+       line->set_covers_threshold (4.0);
 
        line->Event.connect (sigc::mem_fun (*this, &AutomationLine::event_handler));
 
@@ -126,7 +138,7 @@ AutomationLine::event_handler (GdkEvent* event)
 }
 
 void
-AutomationLine::show ()
+AutomationLine::update_visibility ()
 {
        if (_visible & Line) {
                /* Only show the line there are some points, otherwise we may show an out-of-date line
@@ -138,30 +150,42 @@ AutomationLine::show ()
                } else {
                        line->hide ();
                }
-       } else {
-               line->hide();
-       }
 
-       if (_visible & ControlPoints) {
-               for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
-                       (*i)->set_visible (true);
-                       (*i)->show ();
-               }
-       } else if (_visible & SelectedControlPoints) {
-               for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
-                       (*i)->set_visible ((*i)->get_selected());
+               if (_visible & ControlPoints) {
+                       for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
+                               (*i)->show ();
+                       }
+               } else if (_visible & SelectedControlPoints) {
+                       for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
+                               if ((*i)->get_selected()) {
+                                       (*i)->show ();
+                               } else {
+                                       (*i)->hide ();
+                               }
+                       }
+               } else {
+                       for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
+                               (*i)->hide ();
+                       }
                }
+
        } else {
+               line->hide ();
                for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
-                       (*i)->set_visible (false);
+                       (*i)->hide ();
                }
        }
+
 }
 
 void
 AutomationLine::hide ()
 {
-       set_visibility (VisibleAspects (0));
+       /* leave control points setting unchanged, we are just hiding the
+          overall line 
+       */
+       
+       set_visibility (AutomationLine::VisibleAspects (_visible & ~Line));
 }
 
 double
@@ -169,7 +193,7 @@ AutomationLine::control_point_box_size ()
 {
        if (alist->interpolation() == AutomationList::Discrete) {
                return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()),
-                               4.0);
+                          4.0);
        }
 
        if (_height > TimeAxisView::preset_height (HeightLarger)) {
@@ -243,12 +267,11 @@ AutomationLine::modify_point_y (ControlPoint& cp, double y)
        y = min (1.0, y);
        y = _height - (y * _height);
 
-       double const x = trackview.editor().frame_to_unit_unrounded (_time_converter->to((*cp.model())->when) - _offset);
+       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().session()->add_command (
-               new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0)
-               );
+               new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
 
        cp.move_to (x, y, ControlPoint::Full);
 
@@ -265,8 +288,7 @@ AutomationLine::modify_point_y (ControlPoint& cp, double y)
        update_pending = false;
 
        trackview.editor().session()->add_command (
-               new MementoCommand<AutomationList> (memento_command_binder(), 0, &alist->get_state())
-               );
+               new MementoCommand<AutomationList> (memento_command_binder(), 0, &alist->get_state()));
 
        trackview.editor().session()->commit_reversible_command ();
        trackview.editor().session()->set_dirty ();
@@ -430,8 +452,7 @@ 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)
-               );
+               new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
 
        _drag_points.clear ();
        _drag_points.push_back (cp);
@@ -457,8 +478,7 @@ 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)
-               );
+               new MementoCommand<AutomationList> (memento_command_binder (), &get_state(), 0));
 
        _drag_points.clear ();
 
@@ -478,8 +498,7 @@ AutomationLine::start_drag_multiple (list<ControlPoint*> cp, float fraction, XML
 {
        trackview.editor().session()->begin_reversible_command (_("automation range move"));
        trackview.editor().session()->add_command (
-               new MementoCommand<AutomationList> (memento_command_binder(), state, 0)
-               );
+               new MementoCommand<AutomationList> (memento_command_binder(), state, 0));
 
        _drag_points = cp;
        start_drag_common (0, fraction);
@@ -717,8 +736,7 @@ AutomationLine::end_drag (bool with_push, uint32_t final_index)
        update_pending = false;
 
        trackview.editor().session()->add_command (
-               new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state())
-               );
+               new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state()));
 
        trackview.editor().session()->set_dirty ();
        did_push = false;
@@ -739,10 +757,10 @@ AutomationLine::sync_model_with_view_point (ControlPoint& cp)
 
        /* if xval has not changed, set it directly from the model to avoid rounding errors */
 
-       if (view_x == trackview.editor().frame_to_unit_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) {
+       if (view_x == trackview.editor().sample_to_pixel_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) {
                view_x = (*cp.model())->when - _offset;
        } else {
-               view_x = trackview.editor().unit_to_frame (view_x);
+               view_x = trackview.editor().pixel_to_sample (view_x);
                view_x = _time_converter->from (view_x + _offset);
        }
 
@@ -760,7 +778,7 @@ AutomationLine::control_points_adjacent (double xval, uint32_t & before, uint32_
        ControlPoint *acp = 0;
        double unit_xval;
 
-       unit_xval = trackview.editor().frame_to_unit_unrounded (xval);
+       unit_xval = trackview.editor().sample_to_pixel_unrounded (xval);
 
        for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
 
@@ -822,8 +840,7 @@ AutomationLine::remove_point (ControlPoint& cp)
        alist->erase (cp.model());
        
        trackview.editor().session()->add_command(
-               new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
-               );
+               new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
 
        trackview.editor().session()->commit_reversible_command ();
        trackview.editor().session()->set_dirty ();
@@ -880,7 +897,7 @@ AutomationLine::set_selected_points (PointSelection const & points)
 
 void AutomationLine::set_colors ()
 {
-       set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
+       set_line_color (ARDOUR_UI::config()->get_canvasvar_AutomationLine());
        for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
                (*i)->set_color ();
        }
@@ -933,9 +950,9 @@ AutomationLine::reset_callback (const Evoral::ControlList& events)
 
                model_to_view_coord (tx, ty);
 
-               if (std::isnan (tx) || std::isnan (ty)) {
+               if (isnan (tx) || isnan (ty)) {
                        warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
-                                                  _name) << endmsg;
+                                                  _name) << endmsg;
                        continue;
                }
                
@@ -947,7 +964,7 @@ AutomationLine::reset_callback (const Evoral::ControlList& events)
                 * zoom and scroll into account).
                 */
                        
-               tx = trackview.editor().frame_to_unit_unrounded (tx);
+               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)
@@ -990,9 +1007,7 @@ AutomationLine::reset_callback (const Evoral::ControlList& events)
 
                line->set (line_points);
 
-               if (_visible && alist->interpolation() != AutomationList::Discrete) {
-                       line->show();
-               }
+               update_visibility ();
        }
 
        set_selected_points (trackview.editor().get_selection().points);
@@ -1041,8 +1056,7 @@ AutomationLine::clear ()
        alist->clear();
 
        trackview.editor().session()->add_command (
-               new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
-               );
+               new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
 }
 
 void
@@ -1061,22 +1075,34 @@ AutomationLine::set_list (boost::shared_ptr<ARDOUR::AutomationList> list)
 void
 AutomationLine::add_visibility (VisibleAspects va)
 {
+       VisibleAspects old = _visible;
+
        _visible = VisibleAspects (_visible | va);
-       show ();
+
+       if (old != _visible) {
+               update_visibility ();
+       }
 }
 
 void
 AutomationLine::set_visibility (VisibleAspects va)
 {
-       _visible = va;
-       show ();
+       if (_visible != va) {
+               _visible = va;
+               update_visibility ();
+       }
 }
 
 void
 AutomationLine::remove_visibility (VisibleAspects va)
 {
+       VisibleAspects old = _visible;
+
        _visible = VisibleAspects (_visible & ~va);
-       show ();
+
+       if (old != _visible) {
+               update_visibility ();
+       }
 }
 
 void
@@ -1126,9 +1152,10 @@ AutomationLine::view_to_model_coord_y (double& y) const
                y = max (0.0, y);
                y = min (2.0, y);
        } else if (alist->parameter().type() == PanAzimuthAutomation ||
-                   alist->parameter().type() == PanElevationAutomation ||
-                   alist->parameter().type() == PanWidthAutomation) {
+                  alist->parameter().type() == PanElevationAutomation) {
                y = 1.0 - y;
+       } else if (alist->parameter().type() == PanWidthAutomation) {
+               y = 2.0 * y - 1.0;
        } else if (alist->parameter().type() == PluginAutomation) {
                y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y();
        } else {
@@ -1144,10 +1171,10 @@ AutomationLine::model_to_view_coord (double& x, double& y) const
            alist->parameter().type() == EnvelopeAutomation) {
                y = gain_to_slider_position_with_max (y, Config->get_max_gain());
        } else if (alist->parameter().type() == PanAzimuthAutomation ||
-                   alist->parameter().type() == PanElevationAutomation ||
-                   alist->parameter().type() == PanWidthAutomation) {
-               // vertical coordinate axis reversal
+                  alist->parameter().type() == PanElevationAutomation) {
                y = 1.0 - y;
+       } else if (alist->parameter().type() == PanWidthAutomation) {
+               y = .5 + y * .5;
        } else if (alist->parameter().type() == PluginAutomation) {
                y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y());
        } else {
@@ -1171,7 +1198,7 @@ AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
 
 void
 AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty, 
-                                          AutomationList::iterator model, uint32_t npoints)
+                                           AutomationList::iterator model, uint32_t npoints)
 {
        ControlPoint::ShapeType shape;
 
@@ -1211,9 +1238,8 @@ AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, dou
 
        if (_visible & ControlPoints) {
                control_points[view_index]->show ();
-               control_points[view_index]->set_visible (true);
        } else {
-               control_points[view_index]->set_visible (false);
+               control_points[view_index]->hide ();
        }
 }
 
@@ -1225,8 +1251,7 @@ AutomationLine::connect_to_list ()
        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()
-               );
+               _list_connections, invalidator (*this), boost::bind (&AutomationLine::interpolation_changed, this, _1), gui_context());
 }
 
 MementoCommandBinder<AutomationList>*