a couple of debug output statements to help diagnose a crash
[ardour.git] / libs / canvas / xfade_curve.cc
index 4de8115c62f037e117713b0bbdca44b8f6eb40b8..0d7d7a5245b76075ee5a8b009729036bdefdea02 100644 (file)
@@ -30,13 +30,19 @@ using namespace ArdourCanvas;
 using std::min;
 using std::max;
 
+#ifdef USE_TRACKS_CODE_FEATURES
+static const bool show_bg_fades = false;
+#else
+static const bool show_bg_fades = true;
+#endif
+       
 XFadeCurve::XFadeCurve (Canvas* c)
        : Item (c)
        , points_per_segment (32)
        , _xfadeposition (Start)
        , _outline_color (0x000000ff)
        , _fill_color (0x22448880)
-       , show_background_fade (true)
+       , show_background_fade (show_bg_fades)
 {
 }
 
@@ -46,7 +52,7 @@ XFadeCurve::XFadeCurve (Canvas* c, XFadePosition pos)
        , _xfadeposition (pos)
        , _outline_color (0x000000ff)
        , _fill_color (0x22448880)
-       , show_background_fade (true)
+       , show_background_fade (show_bg_fades)
 {
 }
 
@@ -56,7 +62,7 @@ XFadeCurve::XFadeCurve (Item* parent)
        , _xfadeposition (Start)
        , _outline_color (0x000000ff)
        , _fill_color (0x22448880)
-       , show_background_fade (true)
+       , show_background_fade (show_bg_fades)
 {
 }
 
@@ -66,7 +72,7 @@ XFadeCurve::XFadeCurve (Item* parent, XFadePosition pos)
        , _xfadeposition (pos)
        , _outline_color (0x000000ff)
        , _fill_color (0x22448880)
-       , show_background_fade (true)
+       , show_background_fade (show_bg_fades)
 {
 }
 
@@ -170,23 +176,29 @@ XFadeCurve::get_path(Rect const & area, Cairo::RefPtr<Cairo::Context> context, C
 
                /* find left and right-most sample */
                Points::size_type left = 0;
-               Points::size_type right = c.n_samples;
+               Points::size_type right = c.n_samples - 1;
 
+               // we should really really do a binary search rather than iterate
                for (Points::size_type idx = 0; idx < c.n_samples - 1; ++idx) {
                        left = idx;
                        window_space = item_to_window (Duple (c.samples[idx].x, 0.0), false);
                        if (window_space.x >= area.x0) break;
                }
-               for (Points::size_type idx = c.n_samples; idx > left + 1; --idx) {
+               for (Points::size_type idx = c.n_samples; idx >= left;) {
+                       --idx;
                        window_space = item_to_window (Duple (c.samples[idx].x, 0.0), false);
                        if (window_space.x <= area.x1) break;
                        right = idx;
                }
 
+               assert(left < right);
+               assert(left < c.n_samples);
+               assert(right < c.n_samples);
+
                /* draw line between samples */
                window_space = item_to_window (Duple (c.samples[left].x, c.samples[left].y), false);
                context->move_to (window_space.x, window_space.y);
-               for (uint32_t idx = left + 1; idx < right; ++idx) {
+               for (uint32_t idx = left + 1; idx <= right; ++idx) {
                        window_space = item_to_window (Duple (c.samples[idx].x, c.samples[idx].y), false);
                        context->line_to (window_space.x, window_space.y);
                }