add VU and IEC meter DSP (from jmeters)
[ardour.git] / gtk2_ardour / time_axis_view_item.cc
index b25ed5a934b33528e6285de25c661f60e0ac22dd..23c17476d3470881620e3838c523bf8a10afe859 100644 (file)
@@ -265,7 +265,7 @@ TimeAxisViewItem::~TimeAxisViewItem()
 }
 
 bool
-TimeAxisViewItem::canvas_group_event (GdkEvent* ev)
+TimeAxisViewItem::canvas_group_event (GdkEvent* /*ev*/)
 {
        return false;
 }
@@ -728,53 +728,110 @@ TimeAxisViewItem::set_colors()
        if (name_highlight) {
                name_highlight->set_fill_color (fill_color);
        }
+
+       if (name_text) {
+               double r, g, b, a;
+
+               const double black_r = 0.0;
+               const double black_g = 0.0;
+               const double black_b = 0.0;
+
+               const double white_r = 1.0;
+               const double white_g = 1.0;
+               const double white_b = 1.0;
+
+               ArdourCanvas::color_to_rgba (fill_color, r, g, b, a);
+               
+               /* Use W3C contrast guideline calculation */
+
+               double white_contrast = (max (r, white_r) - min (r, white_r)) +
+                       (max (g, white_g) - min (g, white_g)) + 
+                       (max (b, white_b) - min (b, white_b));
+
+               double black_contrast = (max (r, black_r) - min (r, black_r)) +
+                       (max (g, black_g) - min (g, black_g)) + 
+                       (max (b, black_b) - min (b, black_b));
+
+               if (white_contrast > black_contrast) {          
+                       /* use white */
+                       name_text->set_color (ArdourCanvas::rgba_to_color (1.0, 1.0, 1.0, 1.0));
+               } else {
+                       /* use black */
+                       name_text->set_color (ArdourCanvas::rgba_to_color (0.0, 0.0, 0.0, 1.0));
+               }
+
+#if 0
+               double h, s, v;
+
+               ArdourCanvas::color_to_hsv (fill_color, h, s, v);
+
+               if (v == 0.0) {
+                       /* fill is black, set text to white */
+                       name_text->set_color (ArdourCanvas::rgba_to_color (1.0, 1.0, 1.0, 1.0));
+               } else if (v == 1.0) {
+                       /* fill is white, set text to black */
+                       name_text->set_color (ArdourCanvas::rgba_to_color (0.0, 0.0, 0.0, 1.0));
+               } else {
+
+                       h = fabs (fmod ((h - 180), 360.0)); /* complementary color */
+                       s = 1.0; /* fully saturate */
+                       v = 0.9; /* increase lightness/brightness/value */
+
+                       name_text->set_color (ArdourCanvas::hsv_to_color (h, s, v, 1.0));
+               }
+#endif
+
+       }
+       
        set_trim_handle_colors();
 }
 
-/**
- * Sets the frame color depending on whether this item is selected
- */
-void
-TimeAxisViewItem::set_frame_color()
+uint32_t
+TimeAxisViewItem::get_fill_color () const
 {
         uint32_t f = 0;
 
-       if (!frame) {
-               return;
-       }
-
        if (_selected) {
 
                 f = ARDOUR_UI::config()->get_canvasvar_SelectedFrameBase();
 
-               if (fill_opacity) {
-                        f = UINT_RGBA_CHANGE_A (f, fill_opacity);
-               }
-
-                if (!rect_visible) {
-                        f = UINT_RGBA_CHANGE_A (f, 0);
-                }
-
        } else {
 
                if (_recregion) {
                        f = ARDOUR_UI::config()->get_canvasvar_RecordingRect();
                } else {
 
-                       if (high_enough_for_name && !Config->get_color_regions_using_track_color()) {
+                       if (high_enough_for_name && !ARDOUR_UI::config()->get_color_regions_using_track_color()) {
                                f = ARDOUR_UI::config()->get_canvasvar_FrameBase();
                        } else {
                                f = fill_color;
                        }
+               }
+       }
 
-                       if (fill_opacity) {
-                               f = UINT_RGBA_CHANGE_A (f, fill_opacity);
-                       }
+       return f;
+}
 
-                        if (!rect_visible) {
-                                f = UINT_RGBA_CHANGE_A (f, 0);
-                        }
-                }
+/**
+ * Sets the frame color depending on whether this item is selected
+ */
+void
+TimeAxisViewItem::set_frame_color()
+{
+        uint32_t f = 0;
+
+       if (!frame) {
+               return;
+       }
+
+       f = get_fill_color ();
+
+       if (fill_opacity) {
+               f = UINT_RGBA_CHANGE_A (f, fill_opacity);
+       }
+       
+       if (!rect_visible) {
+               f = UINT_RGBA_CHANGE_A (f, 0);
        }
 
         frame->set_fill_color (f);
@@ -806,7 +863,7 @@ TimeAxisViewItem::set_frame_gradient ()
        ArdourCanvas::Fill::StopList stops;
        double r, g, b, a;
        double h, s, v;
-       ArdourCanvas::Color f (frame->fill_color());
+       ArdourCanvas::Color f (get_fill_color());
 
        /* need to get alpha value */
        ArdourCanvas::color_to_rgba (f, r, g, b, a);
@@ -816,15 +873,13 @@ TimeAxisViewItem::set_frame_gradient ()
        /* now a darker version */
        
        ArdourCanvas::color_to_hsv (f, h, s, v);
-       s *= ARDOUR_UI::config()->get_timeline_item_gradient_depth();
-       if (s > 1.0) {
-               s = 1.0;
-       }
+
+       v = min (1.0, v * (1.0 - ARDOUR_UI::config()->get_timeline_item_gradient_depth()));
        
        ArdourCanvas::Color darker = ArdourCanvas::hsv_to_color (h, s, v, a);
        stops.push_back (std::make_pair (1.0, darker));
        
-       frame->set_gradient (stops, _height);
+       frame->set_gradient (stops, true);
 }
 
 /**
@@ -1039,7 +1094,7 @@ void
 TimeAxisViewItem::parameter_changed (string p)
 {
        if (p == "color-regions-using-track-color") {
-               set_frame_color ();
+               set_colors ();
        } else if (p == "timeline-item-gradient-depth") {
                set_frame_gradient ();
        }