MIDI Transform channel-count 1..16 (not 0..15)
[ardour.git] / libs / canvas / xfade_curve.cc
index d82e6ab973d80e44c5a4fe8984e7046436949480..9f3c158dcd84e3bb4ce75c37d34a1bc26cd35302 100644 (file)
 
 #include "canvas/xfade_curve.h"
 #include "canvas/interpolated_curve.h"
-#include "canvas/utils.h"
 
 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 +51,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 +61,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 +71,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)
 {
 }
 
@@ -112,7 +117,7 @@ XFadeCurve::compute_bounding_box () const
                _bounding_box = bbox.expand (1.0);
 
        } else {
-               _bounding_box = boost::optional<Rect> ();
+               _bounding_box = Rect ();
        }
 
        _bounding_box_dirty = false;
@@ -172,14 +177,15 @@ XFadeCurve::get_path(Rect const & area, Cairo::RefPtr<Cairo::Context> context, C
                Points::size_type left = 0;
                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;) {
-                       --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;
@@ -226,10 +232,10 @@ XFadeCurve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) co
        if (_in.points.size() < 2) { return; }
        if (_out.points.size() < 2) { return; }
 
-       Rect self = item_to_window (_bounding_box.get());
-       boost::optional<Rect> d = self.intersection (area);
+       Rect self = item_to_window (_bounding_box);
+       Rect d = self.intersection (area);
        assert (d);
-       Rect draw = d.get ();
+       Rect draw = d;
 
        context->save ();
        context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
@@ -243,10 +249,10 @@ XFadeCurve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) co
        Cairo::Path *path_in = get_path(draw, context, _in);
        Cairo::Path *path_out = get_path(draw, context, _out);
 
-       Color outline_shaded = _outline_color;
+       Gtkmm2ext::Color outline_shaded = _outline_color;
        outline_shaded = 0.5 * (outline_shaded & 0xff) + (outline_shaded & ~0xff);
 
-       Color fill_shaded = _fill_color;
+       Gtkmm2ext::Color fill_shaded = _fill_color;
        fill_shaded = 0.5 * (fill_shaded & 0xff) + (fill_shaded & ~0xff);
 
 #define IS_START (_xfadeposition == Start)
@@ -255,7 +261,7 @@ XFadeCurve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) co
        context->begin_new_path ();
        context->append_path (IS_START ? *path_in : *path_out);
        close_path(draw, context, IS_START ?_in : _out, false);
-       set_source_rgba (context, _fill_color);
+       Gtkmm2ext::set_source_rgba (context, _fill_color);
        context->fill ();
 
        if (show_background_fade) {
@@ -269,7 +275,7 @@ XFadeCurve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) co
                context->begin_new_path ();
                context->append_path (IS_START ? *path_out: *path_in);
                close_path(draw, context, IS_START ? _out : _in, true);
-               set_source_rgba (context, fill_shaded);
+               Gtkmm2ext::set_source_rgba (context, fill_shaded);
                context->set_fill_rule (Cairo::FILL_RULE_WINDING);
                context->fill ();
                context->restore ();
@@ -278,9 +284,9 @@ XFadeCurve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) co
        /* draw lines over fills */
        /* fade in line */
        if (IS_START || show_background_fade) {
-               set_source_rgba (context, IS_START ? _outline_color : outline_shaded);
+               Gtkmm2ext::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();
@@ -288,7 +294,7 @@ XFadeCurve::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) co
 
        /* fade out line */
        if (!IS_START || show_background_fade) {
-               set_source_rgba (context, IS_START ? outline_shaded :_outline_color);
+               Gtkmm2ext::set_source_rgba (context, IS_START ? outline_shaded :_outline_color);
                context->set_line_width (IS_START ? .5 : 1.0);
 
                context->begin_new_path ();