Include pbd/crossthread.cc in the mingw build
[ardour.git] / gtk2_ardour / automation_line.cc
index 12ca73ca95f90cf4fc5ef0944a9a84e7b72a8d0a..aa4f25129934a88b472751e4f05e1fe811cf82c1 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>
@@ -142,6 +145,13 @@ AutomationLine::event_handler (GdkEvent* event)
        return PublicEditor::instance().canvas_line_event (event, line, this);
 }
 
+bool
+AutomationLine::is_stepped() const
+{
+       return (_desc.toggled ||
+               (alist && alist->interpolation() == AutomationList::Discrete));
+}
+
 void
 AutomationLine::update_visibility ()
 {
@@ -150,7 +160,7 @@ AutomationLine::update_visibility ()
                   when automation points have been removed (the line will still follow the shape of the
                   old points).
                */
-               if (alist->interpolation() != AutomationList::Discrete && control_points.size() >= 2) {
+               if (control_points.size() >= 2) {
                        line->show();
                } else {
                        line->hide ();
@@ -177,7 +187,11 @@ AutomationLine::update_visibility ()
        } else {
                line->hide ();
                for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
-                       (*i)->hide ();
+                       if (_visible & ControlPoints) {
+                               (*i)->show ();
+                       } else {
+                               (*i)->hide ();
+                       }
                }
        }
 
@@ -196,11 +210,6 @@ AutomationLine::hide ()
 double
 AutomationLine::control_point_box_size ()
 {
-       if (alist->interpolation() == AutomationList::Discrete) {
-               return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()),
-                          4.0);
-       }
-
        if (_height > TimeAxisView::preset_height (HeightLarger)) {
                return 8.0;
        } else if (_height > (guint32) TimeAxisView::preset_height (HeightNormal)) {
@@ -283,7 +292,7 @@ AutomationLine::modify_point_y (ControlPoint& cp, double y)
        reset_line_coords (cp);
 
        if (line_points.size() > 1) {
-               line->set (line_points);
+               line->set_steps (line_points, is_stepped());
        }
 
        alist->freeze ();
@@ -712,7 +721,7 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool
                 */
 
                if (line_points.size() > 1) {
-                       line->set (line_points);
+                       line->set_steps (line_points, is_stepped());
                }
        }
        
@@ -970,7 +979,7 @@ 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;
@@ -1025,7 +1034,7 @@ AutomationLine::reset_callback (const Evoral::ControlList& events)
                        line_points[n].y = control_points[n]->get_y();
                }
 
-               line->set (line_points);
+               line->set_steps (line_points, is_stepped());
 
                update_visibility ();
        }
@@ -1079,11 +1088,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)
 {
@@ -1128,17 +1132,13 @@ AutomationLine::remove_visibility (VisibleAspects va)
 void
 AutomationLine::track_entered()
 {
-       if (alist->interpolation() != AutomationList::Discrete) {
-               add_visibility (ControlPoints);
-       }
+       add_visibility (ControlPoints);
 }
 
 void
 AutomationLine::track_exited()
 {
-       if (alist->interpolation() != AutomationList::Discrete) {
-               remove_visibility (ControlPoints);
-       }
+       remove_visibility (ControlPoints);
 }
 
 XMLNode &
@@ -1178,14 +1178,14 @@ 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 (ARDOUR::parameter_is_midi((ARDOUR::AutomationType)alist->parameter().type())) {
+               if (_desc.toggled || _desc.integer_step) {
                        y = round(y);
                }
        }
 }
 
 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 ||
@@ -1199,7 +1199,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;
 }
 
@@ -1207,11 +1212,8 @@ AutomationLine::model_to_view_coord (double& x, double& y) const
 void
 AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
 {
-       if (style == AutomationList::Discrete) {
-               set_visibility (ControlPoints);
-               line->hide();
-       } else {
-               set_visibility (Line);
+       if (line_points.size() > 1) {
+               line->set_steps(line_points, is_stepped());
        }
 }