Merge branch 'master' into cairocanvas
[ardour.git] / gtk2_ardour / audio_region_view.cc
index bfce754b706473b14e0b2b2b8135aeb7610b6ddb..7d45e8c262840dd55281ec5539cf9db381e18299 100644 (file)
@@ -43,6 +43,7 @@
 #include "canvas/line.h"
 #include "canvas/text.h"
 #include "canvas/debug.h"
+#include "canvas/utils.h"
 
 #include "streamview.h"
 #include "audio_region_view.h"
@@ -158,30 +159,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 (UINT_RGBA_CHANGE_A (fade_color, 255));
                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 (UINT_RGBA_CHANGE_A (fade_color, 255)); 
                fade_out_handle->set_data ("regionview", this);
+               fade_out_handle->hide ();
        }
 
        setup_fade_handle_positions ();
@@ -232,10 +233,13 @@ AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
 
        setup_waveform_visibility ();
        setup_waveform_shape ();
-       setup_waveform_scale ();
 
-       frame_handle_start->raise_to_top ();
-       frame_handle_end->raise_to_top ();
+       if (frame_handle_start) {
+               frame_handle_start->raise_to_top ();
+       }
+       if (frame_handle_end) {
+               frame_handle_end->raise_to_top ();
+       }
 
        /* XXX sync mark drag? */
 }
@@ -311,10 +315,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));
        }
 }
 
@@ -323,10 +327,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));
        }
 }
 
@@ -406,10 +410,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();
                }
        }
 
@@ -529,8 +532,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);
@@ -583,26 +584,6 @@ AudioRegionView::reset_fade_in_shape_width (boost::shared_ptr<AudioRegion> ar, f
 
        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());
-
-       /* 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);
 
        /* ensure trim handle stays on top */
@@ -625,8 +606,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);
@@ -683,28 +662,6 @@ AudioRegionView::reset_fade_out_shape_width (boost::shared_ptr<AudioRegion> ar,
 
        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];
-
        fade_out_shape->set (points);
 
        /* ensure trim handle stays on top */
@@ -1179,19 +1136,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);
-
-       if (_recregion) {
-               wave->set_outline_color (_region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_RecWaveForm(), MUTED_ALPHA) : ARDOUR_UI::config()->get_canvasvar_RecWaveForm());
-               wave->set_fill_color (ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill());
-       } else {
-               wave->set_outline_color (_region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA) : ARDOUR_UI::config()->get_canvasvar_WaveForm());
-               wave->set_fill_color (ARDOUR_UI::config()->get_canvasvar_WaveFormFill());
-       }
-
-       wave->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
-       wave->set_zero_color (ARDOUR_UI::config()->get_canvasvar_ZeroLine());
-       // CAIROCANVAS
-       // wave->property_zero_line() = true;
+       wave->set_show_zero_line (true);
 
        switch (Config->get_waveform_shape()) {
        case Rectified:
@@ -1327,11 +1272,14 @@ AudioRegionView::setup_waveform_shape ()
 void
 AudioRegionView::setup_waveform_scale ()
 {
-       for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
-               (*wave)->set_logscaled (Config->get_waveform_scale() == Logarithmic);
-       }
+       WaveView::set_global_logscaled (Config->get_waveform_scale() == Logarithmic);
 }
 
+void
+AudioRegionView::setup_waveform_clipping ()
+{
+       WaveView::set_global_show_waveform_clipping (ARDOUR_UI::config()->get_show_waveform_clipping());
+}
 
 GhostRegion*
 AudioRegionView::add_ghost (TimeAxisView& tv)
@@ -1380,10 +1328,10 @@ AudioRegionView::entered (bool internal_editing)
        }
 
        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 ();
        }
 }
 
@@ -1398,10 +1346,8 @@ AudioRegionView::exited ()
        }
 
        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 ();
        }
 }
 
@@ -1433,42 +1379,54 @@ AudioRegionView::color_handler ()
 void
 AudioRegionView::set_waveform_colors ()
 {
-       ArdourCanvas::Color fill, outline, clip, zero;
+        for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
+               set_one_waveform_color (*w);
+       }
+}
+
+void
+AudioRegionView::set_one_waveform_color (ArdourCanvas::WaveView* wave)
+{
+       ArdourCanvas::Color fill;
+       ArdourCanvas::Color outline;
        
        if (_selected) {
-                if (_region->muted()) {
-                        outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), MUTED_ALPHA);
-                } else {
-                        outline = ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm();
-                }
-                fill = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
+               if (_region->muted()) {
+                       outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), MUTED_ALPHA);
+               } else {
+                       outline = ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm();
+               }
+               fill = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
        } else {
                if (_recregion) {
-                        if (_region->muted()) {
-                                outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_RecWaveForm(), MUTED_ALPHA);
-                        } else {
-                                outline = ARDOUR_UI::config()->get_canvasvar_RecWaveForm();
-                        }
-                        fill = ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill();
+                       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);
-                        } else {
-                                outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
-                        }
-                        fill = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
+                       if (_region->muted()) {
+                               outline = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA);
+                       } else {
+                               outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
+                       }
+                       fill = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
                }
        }
 
-       clip = ARDOUR_UI::config()->get_canvasvar_WaveFormClip();
-       zero = ARDOUR_UI::config()->get_canvasvar_ZeroLine();
+       if (ARDOUR_UI::config()->get_color_regions_using_track_color()) {
 
-        for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
-               (*w)->set_outline_color (outline);
-               (*w)->set_fill_color (fill);
-               (*w)->set_clip_color (clip);
-               (*w)->set_zero_color (zero);
+               /* just use a slightly transparent version of the selected
+                * color so that some of the track color bleeds through
+                */
+
+               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 */
+               
        }
+               
+       wave->set_fill_color (fill);
+       wave->set_outline_color (outline);
+       wave->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
+       wave->set_zero_color (ARDOUR_UI::config()->get_canvasvar_ZeroLine());
 }
 
 void
@@ -1678,5 +1636,7 @@ AudioRegionView::parameter_changed (string const & p)
                setup_waveform_scale ();
        } else if (p == "waveform-shape") {
                setup_waveform_shape ();
+       } else if (p == "show-waveform-clipping") {
+               setup_waveform_clipping ();
        }
 }