make middle-click on piano roll track header more usefully select/unselect notes
[ardour.git] / gtk2_ardour / audio_region_view.cc
index 2f6959429f23ce0beead867e9aec4789942f7689..0159022f87c0276999dc3f8783a2f1e69153bbbc 100644 (file)
@@ -42,6 +42,8 @@
 #include "canvas/poly_line.h"
 #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,21 +160,25 @@ AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
        create_waves ();
 
        fade_in_shape = new ArdourCanvas::Polygon (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_data ("regionview", this);
 
        fade_out_shape = new ArdourCanvas::Polygon (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_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_data ("regionview", this);
 
                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));
 
@@ -227,7 +233,13 @@ AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
 
        setup_waveform_visibility ();
        setup_waveform_shape ();
-       setup_waveform_scale ();
+
+       if (frame_handle_start) {
+               frame_handle_start->raise_to_top ();
+       }
+       if (frame_handle_end) {
+               frame_handle_end->raise_to_top ();
+       }
 
        /* XXX sync mark drag? */
 }
@@ -360,10 +372,9 @@ AudioRegionView::region_resized (const PropertyChange& what_changed)
        interesting_stuff.add (ARDOUR::Properties::length);
 
        if (what_changed.contains (interesting_stuff)) {
-
+               
                for (uint32_t n = 0; n < waves.size(); ++n) {
                        waves[n]->region_resized ();
-                       waves[n]->set_region_start (region()->start ());
                }
 
                for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
@@ -371,7 +382,6 @@ AudioRegionView::region_resized (const PropertyChange& what_changed)
 
                                for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
                                        (*w)->region_resized ();
-                                       (*w)->set_region_start (region()->start ());
                                }
                        }
                }
@@ -432,14 +442,7 @@ void
 AudioRegionView::region_muted ()
 {
        RegionView::region_muted();
-
-       for (uint32_t n=0; n < waves.size(); ++n) {
-               if (_region->muted()) {
-                       waves[n]->set_outline_color (UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA));
-               } else {
-                       waves[n]->set_outline_color (ARDOUR_UI::config()->get_canvasvar_WaveForm());
-               }
-       }
+       set_waveform_colors ();
 }
 
 void
@@ -750,19 +753,22 @@ AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, frame
 
        if (!start_xfade_in) {
                start_xfade_in = new ArdourCanvas::PolyLine (group);
+               CANVAS_DEBUG_NAME (start_xfade_in, string_compose ("xfade start in line for %1", region()->name()));
                start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
-               start_xfade_in->set_outline_width (2.5);
+               start_xfade_in->set_outline_width (1.5);
        }
 
        if (!start_xfade_out) {
                start_xfade_out = new ArdourCanvas::PolyLine (group);
+               CANVAS_DEBUG_NAME (start_xfade_out, string_compose ("xfade start out line for %1", region()->name()));
                uint32_t col = UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
                start_xfade_out->set_outline_color (col);
-               start_xfade_out->set_outline_width (2.5);
+               start_xfade_out->set_outline_width (2.0);
        }
 
        if (!start_xfade_rect) {
                start_xfade_rect = new ArdourCanvas::Rectangle (group);
+               CANVAS_DEBUG_NAME (start_xfade_rect, string_compose ("xfade start rect for %1", region()->name()));
                start_xfade_rect->set_fill (true);
                start_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
                start_xfade_rect->set_outline (false);
@@ -775,7 +781,6 @@ AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, frame
 
        start_xfade_in->set (points);
        start_xfade_in->show ();
-       start_xfade_in->raise_to_top ();
 
        /* fade out line */
 
@@ -807,9 +812,6 @@ AudioRegionView::redraw_start_xfade_to (boost::shared_ptr<AudioRegion> ar, frame
 
        start_xfade_out->set (ipoints);
        start_xfade_out->show ();
-       start_xfade_out->raise_to_top ();
-
-       start_xfade_rect->raise_to_top ();  //this needs to be topmost so the lines don't steal mouse focus
 
        show_start_xfade();
 }
@@ -837,19 +839,22 @@ AudioRegionView::redraw_end_xfade_to (boost::shared_ptr<AudioRegion> ar, framecn
 
        if (!end_xfade_in) {
                end_xfade_in = new ArdourCanvas::PolyLine (group);
+               CANVAS_DEBUG_NAME (end_xfade_in, string_compose ("xfade end in line for %1", region()->name()));
                uint32_t col UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine(), 128);
                end_xfade_in->set_outline_color (col);
-               end_xfade_in->set_outline_width (2.5);
+               end_xfade_in->set_outline_width (1.5);
        }
 
        if (!end_xfade_out) {
                end_xfade_out = new ArdourCanvas::PolyLine (group);
+               CANVAS_DEBUG_NAME (end_xfade_out, string_compose ("xfade end out line for %1", region()->name()));
                end_xfade_out->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
-               end_xfade_out->set_outline_width (2.5);
+               end_xfade_out->set_outline_width (2.0);
        }
 
        if (!end_xfade_rect) {
                end_xfade_rect = new ArdourCanvas::Rectangle (group);
+               CANVAS_DEBUG_NAME (end_xfade_rect, string_compose ("xfade end rect for %1", region()->name()));
                end_xfade_rect->set_fill (true);
                end_xfade_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_ActiveCrossfade());
                end_xfade_rect->set_outline (0);
@@ -1025,16 +1030,7 @@ AudioRegionView::set_colors ()
                                           ARDOUR_UI::config()->get_canvasvar_GainLineInactive());
        }
 
-       for (uint32_t n=0; n < waves.size(); ++n) {
-               if (_region->muted()) {
-                       waves[n]->set_outline_color (UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA));
-               } else {
-                       waves[n]->set_outline_color (ARDOUR_UI::config()->get_canvasvar_WaveForm());
-               }
-
-               waves[n]->set_clip_color (ARDOUR_UI::config()->get_canvasvar_WaveFormClip());
-               waves[n]->set_zero_color (ARDOUR_UI::config()->get_canvasvar_ZeroLine());
-       }
+       set_waveform_colors ();
 
        if (start_xfade_in) {
                start_xfade_in->set_outline_color (ARDOUR_UI::config()->get_canvasvar_CrossfadeLine());
@@ -1181,27 +1177,13 @@ AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
        gdouble yoff = which * ht;
 
        WaveView *wave = new WaveView (group, audio_region ());
-
+       CANVAS_DEBUG_NAME (wave, string_compose ("wave view for chn %1 of %2", which, get_item_name()));
+       
        wave->set_channel (which);
-       wave->set_x_position (0);
        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_region_start (_region->start());
+       wave->set_show_zero_line (true);
 
        switch (Config->get_waveform_shape()) {
        case Rectified:
@@ -1337,11 +1319,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)
@@ -1362,12 +1347,11 @@ AudioRegionView::add_ghost (TimeAxisView& tv)
                }
 
                WaveView *wave = new WaveView (ghost->group, audio_region());
+               CANVAS_DEBUG_NAME (wave, string_compose ("ghost wave for %1", get_item_name()));
 
                wave->set_channel (n);
-               wave->set_x_position (0);
                wave->set_samples_per_pixel (samples_per_pixel);
                wave->set_amplitude_above_axis (_amplitude_above_axis);
-               wave->set_region_start (_region->start());
 
                ghost->waves.push_back(wave);
        }
@@ -1441,6 +1425,59 @@ AudioRegionView::color_handler ()
 
 }
 
+void
+AudioRegionView::set_waveform_colors ()
+{
+        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();
+       } 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);
+                       } else {
+                               outline = ARDOUR_UI::config()->get_canvasvar_WaveForm();
+                       }
+                       fill = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
+               }
+       }
+
+       if (ARDOUR_UI::config()->get_color_regions_using_track_color()) {
+
+               /* 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
 AudioRegionView::set_frame_color ()
 {
@@ -1456,40 +1493,7 @@ AudioRegionView::set_frame_color ()
 
        TimeAxisViewItem::set_frame_color ();
 
-        uint32_t wc;
-        uint32_t fc;
-
-       if (_selected) {
-                if (_region->muted()) {
-                        wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm(), MUTED_ALPHA);
-                } else {
-                        wc = ARDOUR_UI::config()->get_canvasvar_SelectedWaveForm();
-                }
-                fc = ARDOUR_UI::config()->get_canvasvar_SelectedWaveFormFill();
-       } else {
-               if (_recregion) {
-                        if (_region->muted()) {
-                                wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_RecWaveForm(), MUTED_ALPHA);
-                        } else {
-                                wc = ARDOUR_UI::config()->get_canvasvar_RecWaveForm();
-                        }
-                        fc = ARDOUR_UI::config()->get_canvasvar_RecWaveFormFill();
-               } else {
-                        if (_region->muted()) {
-                                wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->get_canvasvar_WaveForm(), MUTED_ALPHA);
-                        } else {
-                                wc = ARDOUR_UI::config()->get_canvasvar_WaveForm();
-                        }
-                        fc = ARDOUR_UI::config()->get_canvasvar_WaveFormFill();
-               }
-       }
-
-        for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
-               (*w)->set_outline_color (wc);
-                if (!_region->muted()) {
-                        (*w)->set_fill_color (fc);
-                }
-        }
+       set_waveform_colors ();
 }
 
 void
@@ -1543,7 +1547,6 @@ AudioRegionView::show_region_editor ()
        }
 
        editor->present ();
-       editor->set_position (Gtk::WIN_POS_MOUSE);
        editor->show_all();
 }
 
@@ -1555,6 +1558,7 @@ AudioRegionView::transients_changed ()
        while (feature_lines.size() < analysis_features.size()) {
 
                ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group);
+               CANVAS_DEBUG_NAME (canvas_item, string_compose ("transient group for %1", region()->name()));
 
                canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0),
                                  ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
@@ -1681,5 +1685,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 ();
        }
 }