fix up details of time axis view item drawing.
[ardour.git] / gtk2_ardour / audio_region_view.cc
index 0159022f87c0276999dc3f8783a2f1e69153bbbc..bbe3c87c29411303db9fe6a2c1c492dafbff3d3b 100644 (file)
@@ -19,6 +19,7 @@
 #include <cmath>
 #include <cassert>
 #include <algorithm>
+#include <vector>
 
 #include <boost/scoped_array.hpp>
 
@@ -62,7 +63,7 @@
 
 #include "i18n.h"
 
-#define MUTED_ALPHA 10
+#define MUTED_ALPHA 48
 
 using namespace std;
 using namespace ARDOUR;
@@ -159,30 +160,30 @@ AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
 
        create_waves ();
 
-       fade_in_shape = new ArdourCanvas::Polygon (group);
+       fade_in_shape = new ArdourCanvas::PolyLine (group);
        CANVAS_DEBUG_NAME (fade_in_shape, string_compose ("fade in shape for %1", region()->name()));
-       fade_in_shape->set_fill_color (fade_color);
+       fade_in_shape->set_outline_color (fade_color);
        fade_in_shape->set_data ("regionview", this);
 
-       fade_out_shape = new ArdourCanvas::Polygon (group);
+       fade_out_shape = new ArdourCanvas::PolyLine (group);
        CANVAS_DEBUG_NAME (fade_out_shape, string_compose ("fade out shape for %1", region()->name()));
-       fade_out_shape->set_fill_color (fade_color);
+       fade_out_shape->set_outline_color (fade_color);
        fade_out_shape->set_data ("regionview", this);
 
        if (!_recregion) {
                fade_in_handle = new ArdourCanvas::Rectangle (group);
                CANVAS_DEBUG_NAME (fade_in_handle, string_compose ("fade in handle for %1", region()->name()));
-               fade_in_handle->set_fill_color (UINT_RGBA_CHANGE_A (fill_color, 0));
-               fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
-
+               fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
+               fade_in_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
                fade_in_handle->set_data ("regionview", this);
+               fade_in_handle->hide ();
 
                fade_out_handle = new ArdourCanvas::Rectangle (group);
                CANVAS_DEBUG_NAME (fade_out_handle, string_compose ("fade out handle for %1", region()->name()));
-               fade_out_handle->set_fill_color (UINT_RGBA_CHANGE_A (fill_color, 0));
-               fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
-
+               fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
+               fade_out_handle->set_fill_color (ARDOUR_UI::config()->get_canvasvar_InactiveFadeHandle());
                fade_out_handle->set_data ("regionview", this);
+               fade_out_handle->hide ();
        }
 
        setup_fade_handle_positions ();
@@ -315,10 +316,10 @@ AudioRegionView::fade_in_active_changed ()
 {
        if (audio_region()->fade_in_active()) {
                /* XXX: make a themable colour */
-               fade_in_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 90));
+               fade_in_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 90));
        } else {
                /* XXX: make a themable colour */
-               fade_in_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 20));
+               fade_in_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 20));
        }
 }
 
@@ -327,10 +328,10 @@ AudioRegionView::fade_out_active_changed ()
 {
        if (audio_region()->fade_out_active()) {
                /* XXX: make a themable colour */
-               fade_out_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 90));
+               fade_out_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 90));
        } else {
                /* XXX: make a themable colour */
-               fade_out_shape->set_fill_color (RGBA_TO_UINT (45, 45, 45, 20));
+               fade_out_shape->set_outline_color (RGBA_TO_UINT (45, 45, 45, 20));
        }
 }
 
@@ -410,10 +411,9 @@ AudioRegionView::reset_width_dependent_items (double pixel_width)
                if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
                        fade_in_handle->hide();
                        fade_out_handle->hide();
-               }
-               else {
-                       fade_in_handle->show();
-                       fade_out_handle->show();
+               } else {
+                       //fade_in_handle->show();
+                       //fade_out_handle->show();
                }
        }
 
@@ -449,7 +449,7 @@ void
 AudioRegionView::setup_fade_handle_positions()
 {
        /* position of fade handle offset from the top of the region view */
-       double const handle_pos = 2;
+       double const handle_pos = 1.0;
 
        if (fade_in_handle) {
                fade_in_handle->set_y0 (handle_pos);
@@ -504,8 +504,13 @@ AudioRegionView::set_height (gdouble height)
 
                float pos_x = trackview.editor().sample_to_pixel((*l).first);
 
-               (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
-                                 ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
+               if (height >= NAME_HIGHLIGHT_THRESH) {
+                       (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
+                                         ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
+               } else {
+                       (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0),
+                                         ArdourCanvas::Duple (pos_x, _height - 1));
+               }
        }
 
        if (name_text) {
@@ -533,8 +538,6 @@ AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, f
                return;
        }
 
-       fade_in_handle->show ();
-
        /* smallest size for a fade is 64 frames */
 
        width = std::max ((framecnt_t) 64, width);
@@ -559,14 +562,14 @@ AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, f
 
        uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
        double effective_height;
-       float curve[npoints];
+       std::vector<float> curve(npoints);
 
-       audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
+       audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, &curve[0], npoints);
 
        if (_height >= NAME_HIGHLIGHT_THRESH) {
-               effective_height = _height - NAME_HIGHLIGHT_SIZE - 2;
+               effective_height = _height - NAME_HIGHLIGHT_SIZE;
        } else {
-               effective_height = _height - 2;
+               effective_height = _height;
        }
 
        Points points;
@@ -579,35 +582,15 @@ AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, f
        double xdelta = pwidth/npoints;
 
        for (pi = 0, pc = 0; pc < npoints; ++pc) {
-               points[pi].x = 1 + (pc * xdelta);
-               points[pi++].y = 2 + (effective_height - (curve[pc] * effective_height));
+               points[pi].x = 1.0 + (pc * xdelta);
+               points[pi++].y = 1.0 + effective_height - (curve[pc] * effective_height);
        }
 
        /* draw the line */
 
-       redraw_start_xfade_to (ar, width, points, effective_height);
-
-       /* add 3 more points */
-
-       points.push_back (Duple());
-       points.push_back (Duple());
-       points.push_back (Duple());
+       redraw_start_xfade_to (ar, width, points, effective_height, handle_left);
 
-       /* fold back */
-
-       points[pi].x = pwidth;
-       points[pi].y = 2;
-       pi++;
-
-       points[pi].x = 1;
-       points[pi].y = 2;
-       pi++;
-
-       /* connect the dots ... */
-
-       points[pi] = points[0];
-
-       fade_in_shape->set (points);
+       // fade_in_shape->set (points);
 
        /* ensure trim handle stays on top */
        if (frame_handle_start) {
@@ -629,8 +612,6 @@ AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar,
                return;
        }
 
-       fade_out_handle->show ();
-
        /* smallest size for a fade is 64 frames */
 
        width = std::max ((framecnt_t) 64, width);
@@ -659,57 +640,35 @@ AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar,
 
        uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
        double effective_height;
-       float curve[npoints];
+       std::vector<float> curve(npoints);
 
-       audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
+       audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, &curve[0], npoints);
 
        if (_height >= NAME_HIGHLIGHT_THRESH) {
-               effective_height = _height - NAME_HIGHLIGHT_SIZE - 2;
+               effective_height = _height - NAME_HIGHLIGHT_SIZE;
        } else {
-               effective_height = _height - 2;
+               effective_height = _height;
        }
 
        /* points *MUST* be in anti-clockwise order */
-
+       
        Points points;
-
+       
        uint32_t pi, pc;
        double xdelta = pwidth/npoints;
-
+       
        points.assign (npoints, Duple ());
-
+       
        for (pi = 0, pc = 0; pc < npoints; ++pc, ++pi) {
-               points[pi].x = _pixel_width - pwidth + (pc * xdelta);
-               points[pi].y = 2 + (effective_height - (curve[pc] * effective_height));
+               points[pi].x = 1.0 + _pixel_width - pwidth + (pc * xdelta);
+               points[pi].y = 1.0 + effective_height - (curve[pc] * effective_height);
        }
 
        /* draw the line */
 
-       redraw_end_xfade_to (ar, width, points, effective_height);
-
-       /* fill the polygon*/
-
-       /* add 3 more points */
-
-       points.push_back (Duple());
-       points.push_back (Duple());
-       points.push_back (Duple());
-
-       /* fold back */
-
-       points[pi].x = _pixel_width;
-       points[pi].y = effective_height;
-       pi++;
-
-       points[pi].x = _pixel_width;
-       points[pi].y = 2;
-       pi++;
-
-       /* connect the dots ... */
-
-       points[pi] = points[0];
+       redraw_end_xfade_to (ar, width, points, effective_height, handle_right, pwidth-1);
 
-       fade_out_shape->set (points);
+       // fade_out_shape->set (points);
 
        /* ensure trim handle stays on top */
        if (frame_handle_end) {
@@ -745,7 +704,8 @@ AudioRegionView::redraw_start_xfade ()
 }
 
 void
-AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t /*width*/, Points& points, double effective_height)
+AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t /*width*/, Points& points, double effective_height,
+                                       double rect_width)
 {
        if (points.size() < 3) {
                return;
@@ -776,7 +736,7 @@ AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, frame
                start_xfade_rect->set_data ("regionview", this);
        }
 
-       start_xfade_rect->set (ArdourCanvas::Rect (points.front().x, 1.0, points.back().x, effective_height));
+       start_xfade_rect->set (ArdourCanvas::Rect (1.0, 1.0, rect_width, effective_height));
        start_xfade_rect->show ();
 
        start_xfade_in->set (points);
@@ -792,20 +752,23 @@ AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, frame
 
        if (!inverse) {
 
+               /* no inverse curve defined, show the inverse of the normal one */
+
                for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
                        ArdourCanvas::Duple &p (ipoints[pci]);
-                       p.x = i;
-                       p.y = effective_height - points[pci].y;
+                       p.x = 1.0 + i;
+                       /* invert with respect to y-axis */
+                       p.y = 1.0 + effective_height - points[pci].y;
                }
 
        } else {
 
-               float vec[npoints];
-               inverse->curve().get_vector (0, inverse->back()->when, vec, npoints);
+               std::vector<float> vec(npoints);
+               inverse->curve().get_vector (0, inverse->back()->when, &vec[0], npoints);
                
                for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
                        ArdourCanvas::Duple &p (ipoints[pci]);
-                       p.x = i;
+                       p.x = 1.0 + i;
                        p.y = 1.0 + effective_height - (effective_height * vec[i]);
                }
        }
@@ -831,7 +794,8 @@ AudioRegionView::redraw_end_xfade ()
 }
 
 void
-AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t width, Points& points, double effective_height)
+AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecnt_t width, Points& points, double effective_height,
+                                     double rect_edge, double rect_width)
 {
        if (points.size() < 3) {
                return;
@@ -862,7 +826,7 @@ AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecn
                end_xfade_rect->set_data ("regionview", this);
        }
 
-       end_xfade_rect->set (ArdourCanvas::Rect (points.front().x, 1.0, points.back().x, effective_height));
+       end_xfade_rect->set (ArdourCanvas::Rect (rect_edge, 1.0, rect_edge + rect_width + TimeAxisViewItem::RIGHT_EDGE_SHIFT, effective_height));
        end_xfade_rect->show ();
 
        end_xfade_in->set (points);
@@ -883,8 +847,8 @@ AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecn
 
                for (Points::size_type i = 0, pci = 0; i < npoints; ++i, ++pci) {
                        ArdourCanvas::Duple &p (ipoints[pci]);
-                       p.x = rend + i;
-                       p.y = effective_height - points[pci].y;
+                       p.x = 1.0 + rend + i;
+                       p.y = 1.0 + effective_height - points[pci].y;
                }
 
        } else {
@@ -898,7 +862,7 @@ AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecn
 
                for (Points::size_type i = 0, pci = 0; i < npoints; ++i) {
                        ArdourCanvas::Duple& p (ipoints[pci++]);
-                       p.x = rend + i;
+                       p.x = 1.0 + rend + i;
                        p.y = 1.0 + effective_height - (effective_height * vp[i]);
                }
        }
@@ -1183,7 +1147,7 @@ AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
        wave->set_y_position (yoff);
        wave->set_height (ht);
        wave->set_samples_per_pixel (samples_per_pixel);
-       wave->set_show_zero_line (true);
+       wave->set_show_zero_line (false);
 
        switch (Config->get_waveform_shape()) {
        case Rectified:
@@ -1293,7 +1257,7 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
 }
 
 void
-AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
+AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent/*ev*/)
 {
        ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
        audio_region()->envelope()->erase (cp->model());
@@ -1370,15 +1334,16 @@ AudioRegionView::entered (bool internal_editing)
        trackview.editor().set_current_trimmable (_region);
        trackview.editor().set_current_movable (_region);
        
-       if (gain_line && trackview.editor().current_mouse_mode() == Editing::MouseGain) {
+       if (gain_line) {
+               /* these may or may not be visible depending on mouse mode */
                gain_line->add_visibility (AutomationLine::ControlPoints);
        }
 
        if (fade_in_handle && !internal_editing) {
-               fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
-               fade_in_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 255));
-               fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 255));
-               fade_out_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 255));
+               fade_in_handle->show ();
+               fade_out_handle->show ();
+               fade_out_handle->raise_to_top ();
+               fade_in_handle->raise_to_top ();
        }
 }
 
@@ -1388,15 +1353,13 @@ AudioRegionView::exited ()
        trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
        trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
 
-       if (gain_line && trackview.editor().current_mouse_mode() == Editing::MouseGain) {
+       if (gain_line) {
                gain_line->remove_visibility (AutomationLine::ControlPoints);
        }
 
        if (fade_in_handle) {
-               fade_in_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
-               fade_in_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 0));
-               fade_out_handle->set_outline_color (RGBA_TO_UINT (0, 0, 0, 0));
-               fade_out_handle->set_fill_color (UINT_RGBA_CHANGE_A (fade_color, 0));
+               fade_in_handle->hide ();
+               fade_out_handle->hide ();
        }
 }
 
@@ -1441,22 +1404,26 @@ AudioRegionView::set_one_waveform_color (ArdourCanvas::WaveView* wave)
        
        if (_selected) {
                if (_region->muted()) {
-                       outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), MUTED_ALPHA);
+                       /* hide outline with zero alpha */
+                       outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), 0);
+                       fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill(), MUTED_ALPHA);
                } else {
                        outline = ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm();
+                       fill = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
                }
-               fill = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
        } else {
                if (_recregion) {
                        outline = ARDOUR_UI::config()->get_canvasvar_RecWaveForm();
                        fill = ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill();
                } else {
                        if (_region->muted()) {
-                               outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA);
+                               /* hide outline with zero alpha */
+                               outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), 0); 
+                               fill = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveFormFill(), MUTED_ALPHA);
                        } else {
                                outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
+                               fill = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
                        }
-                       fill = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
                }
        }
 
@@ -1469,9 +1436,9 @@ AudioRegionView::set_one_waveform_color (ArdourCanvas::WaveView* wave)
                double r, g, b, a;
                ArdourCanvas::color_to_rgba (fill, r, g, b, a);
                fill = ArdourCanvas::rgba_to_color (r, g, b, 0.85); /* magic number, not user controllable */
-               
+               outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
        }
-               
+
        wave->set_fill_color (fill);
        wave->set_outline_color (outline);
        wave->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
@@ -1563,12 +1530,6 @@ AudioRegionView::transients_changed ()
                canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
                                  ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
 
-               canvas_item->property_first_arrowhead() = TRUE;
-               canvas_item->property_last_arrowhead() = TRUE;
-               canvas_item->property_arrow_shape_a() = 11.0;
-               canvas_item->property_arrow_shape_b() = 0.0;
-               canvas_item->property_arrow_shape_c() = 4.0;
-
                canvas_item->raise_to_top ();
                canvas_item->show ();