initialize some uninitialized variables
[ardour.git] / libs / canvas / xfade_curve.cc
index 0b6b4811d00a9ce82209afba298e2587deb188f4..e93331e7f987ce8430fb8e5af573d7a137a48e8d 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 (false)
+       , 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 (false)
+       , 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 (false)
+       , 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 (false)
+       , show_background_fade (show_bg_fades)
 {
 }
 
@@ -170,23 +176,30 @@ 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;
 
+               assert (left < right);
+               // 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 - 1; right > left;) {
+                       if (--idx <= left) break;
                        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);
                }
@@ -274,7 +287,7 @@ XFadeCurve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) co
        if (IS_START || show_background_fade) {
                set_source_rgba (context, IS_START ? _outline_color : outline_shaded);
                context->set_line_width (IS_START ? 1.0 : .5);
-        
+
                context->begin_new_path ();
                context->append_path (*path_in);
                context->stroke();