fixes for 98% of all the warnings/errors reported by OS X gcc on tiger
[ardour.git] / gtk2_ardour / time_axis_view_item.cc
index 6fd4be08a5bec4c0622c35039afa19eacd4c82a9..d9b0bfa2cf42c972612d6ea9953f7a898df24afa 100644 (file)
@@ -23,7 +23,8 @@
 #include "ardour/types.h"
 #include "ardour/ardour.h"
 
-#include <gtkmm2ext/utils.h>
+#include "gtkmm2ext/utils.h"
+#include "gtkmm2ext/gui_thread.h"
 
 #include "ardour_ui.h"
 /*
@@ -47,8 +48,9 @@ using namespace Editing;
 using namespace Glib;
 using namespace PBD;
 using namespace ARDOUR;
+using namespace Gtkmm2ext;
 
-Pango::FontDescription* TimeAxisViewItem::NAME_FONT = 0;
+Pango::FontDescription TimeAxisViewItem::NAME_FONT;
 const double TimeAxisViewItem::NAME_X_OFFSET = 15.0;
 const double TimeAxisViewItem::GRAB_HANDLE_LENGTH = 6;
 
@@ -61,18 +63,18 @@ void
 TimeAxisViewItem::set_constant_heights ()
 {
         NAME_FONT = get_font_for_style (X_("TimeAxisViewItemName"));
-        
+
         Gtk::Window win;
         Gtk::Label foo;
         win.add (foo);
-        
+
         Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */
         int width = 0;
         int height = 0;
-        
-        layout->set_font_description (*NAME_FONT);
+
+        layout->set_font_description (NAME_FONT);
         Gtkmm2ext::get_ink_pixel_size (layout, width, height);
-        
+
         NAME_HEIGHT = height;
         NAME_Y_OFFSET = height + 3;
         NAME_HIGHLIGHT_SIZE = height + 2;
@@ -83,19 +85,23 @@ TimeAxisViewItem::set_constant_heights ()
  * Construct a new TimeAxisViewItem.
  *
  * @param it_name the unique name of this item
- * @param parant the parent canvas group
+ * @param parent the parent canvas group
  * @param tv the TimeAxisView we are going to be added to
  * @param spu samples per unit
  * @param base_color
  * @param start the start point of this item
  * @param duration the duration of this item
+ * @param recording true if this is a recording region view
+ * @param automation true if this is an automation region view
  */
-TimeAxisViewItem::TimeAxisViewItem(const string & it_name, ArdourCanvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color const & base_color,
-                                  nframes64_t start, nframes64_t duration, bool recording,
-                                  Visibility vis)
+TimeAxisViewItem::TimeAxisViewItem(
+       const string & it_name, ArdourCanvas::Group& parent, TimeAxisView& tv, double spu, Gdk::Color const & base_color,
+       framepos_t start, framecnt_t duration, bool recording, bool automation, Visibility vis
+       )
        : trackview (tv)
        , _height (1.0)
        , _recregion (recording)
+       , _automation (automation)
 {
        group = new ArdourCanvas::Group (parent);
 
@@ -103,10 +109,11 @@ TimeAxisViewItem::TimeAxisViewItem(const string & it_name, ArdourCanvas::Group&
 }
 
 TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other)
-       : sigc::trackable(other)
+       : Selectable (other)
        , PBD::ScopedConnectionList()
        , trackview (other.trackview)
        , _recregion (other._recregion)
+       , _automation (other._automation)
 {
 
        Gdk::Color c;
@@ -131,17 +138,16 @@ TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other)
 
 void
 TimeAxisViewItem::init (
-       const string& it_name, double spu, Gdk::Color const & base_color, nframes64_t start, nframes64_t duration, Visibility vis, bool wide, bool high)
+       const string& it_name, double spu, Gdk::Color const & base_color, framepos_t start, framepos_t duration, Visibility vis, bool wide, bool high)
 {
        item_name = it_name;
        samples_per_unit = spu;
-       should_show_selection = true;
        frame_position = start;
        item_duration = duration;
        name_connected = false;
        fill_opacity = 60;
        position_locked = false;
-       max_item_duration = ARDOUR::max_frames;
+       max_item_duration = ARDOUR::max_framepos;
        min_item_duration = 0;
        show_vestigial = true;
        visibility = vis;
@@ -150,6 +156,7 @@ TimeAxisViewItem::init (
        last_item_width = 0;
        wide_enough_for_name = wide;
        high_enough_for_name = high;
+        rect_visible = true;
 
        if (duration == 0) {
                warning << "Time Axis Item Duration == 0" << endl;
@@ -163,17 +170,16 @@ TimeAxisViewItem::init (
 
        if (visibility & ShowFrame) {
                frame = new ArdourCanvas::SimpleRect (*group, 0.0, 1.0, trackview.editor().frame_to_pixel(duration), trackview.current_height());
-               
+
                frame->property_outline_pixels() = 1;
                frame->property_outline_what() = 0xF;
-               
-               if(_recregion){
+
+               if (_recregion) {
                        frame->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
-               }
-               else {
+               } else {
                        frame->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get();
                }
-               
+
                frame->property_outline_what() = 0x1|0x2|0x4|0x8;
 
        } else {
@@ -181,14 +187,17 @@ TimeAxisViewItem::init (
        }
 
        if (visibility & ShowNameHighlight) {
-               
+
                if (visibility & FullWidthNameHighlight) {
-                       name_highlight = new ArdourCanvas::SimpleRect (*group, 0.0, trackview.editor().frame_to_pixel(item_duration), trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE, trackview.current_height() - 1);
+                       name_highlight = new ArdourCanvas::SimpleRect (*group, 0.0, trackview.editor().frame_to_pixel(item_duration), trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE, trackview.current_height());
                } else {
-                       name_highlight = new ArdourCanvas::SimpleRect (*group, 1.0, trackview.editor().frame_to_pixel(item_duration) - 1, trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE, trackview.current_height() - 1);
+                       name_highlight = new ArdourCanvas::SimpleRect (*group, 1.0, trackview.editor().frame_to_pixel(item_duration) - 1, trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE, trackview.current_height());
                }
-               
+
                name_highlight->set_data ("timeaxisviewitem", this);
+                name_highlight->property_outline_what() = 0x4;
+                /* we should really use a canvas color property here */
+               name_highlight->property_outline_color_rgba() = RGBA_TO_UINT (0,0,0,255);
 
        } else {
                name_highlight = 0;
@@ -204,16 +213,21 @@ TimeAxisViewItem::init (
        }
 
        /* create our grab handles used for trimming/duration etc */
-       frame_handle_start = new ArdourCanvas::SimpleRect (*group, 0.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH, 5.0, trackview.current_height());
-       frame_handle_start->property_outline_what() = 0x0;
-
-       frame_handle_end = new ArdourCanvas::SimpleRect (*group, 0.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH, 5.0, trackview.current_height());
-       frame_handle_end->property_outline_what() = 0x0;
+       if (!_recregion && !_automation) {
+               frame_handle_start = new ArdourCanvas::SimpleRect (*group, 0.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH, 5.0, trackview.current_height());
+               frame_handle_start->property_outline_what() = 0x0;
+               frame_handle_end = new ArdourCanvas::SimpleRect (*group, 0.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH, 5.0, trackview.current_height());
+               frame_handle_end->property_outline_what() = 0x0;
+       } else {
+               frame_handle_start = frame_handle_end = 0;
+       }
 
        set_color (base_color);
 
        set_duration (item_duration, this);
        set_position (start, this);
+
+       Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&TimeAxisViewItem::parameter_changed, this, _1), gui_context ());
 }
 
 TimeAxisViewItem::~TimeAxisViewItem()
@@ -221,6 +235,30 @@ TimeAxisViewItem::~TimeAxisViewItem()
        delete group;
 }
 
+void
+TimeAxisViewItem::hide_rect ()
+{
+        rect_visible = false;
+        set_frame_color ();
+
+        if (name_highlight) {
+                name_highlight->property_outline_what() = 0x0;
+                name_highlight->property_fill_color_rgba() = UINT_RGBA_CHANGE_A(fill_color,64);
+        }
+}
+
+void
+TimeAxisViewItem::show_rect ()
+{
+        rect_visible = true;
+        set_frame_color ();
+
+        if (name_highlight) {
+                name_highlight->property_outline_what() = 0x4;
+                name_highlight->property_fill_color_rgba() = fill_color;
+        }
+}
+
 
 /**
  * Set the position of this item on the timeline.
@@ -231,7 +269,7 @@ TimeAxisViewItem::~TimeAxisViewItem()
  */
 
 bool
-TimeAxisViewItem::set_position(nframes64_t pos, void* src, double* delta)
+TimeAxisViewItem::set_position(framepos_t pos, void* src, double* delta)
 {
        if (position_locked) {
                return false;
@@ -267,7 +305,7 @@ TimeAxisViewItem::set_position(nframes64_t pos, void* src, double* delta)
 }
 
 /** @return position of this item on the timeline */
-nframes64_t
+framepos_t
 TimeAxisViewItem::get_position() const
 {
        return frame_position;
@@ -282,7 +320,7 @@ TimeAxisViewItem::get_position() const
  */
 
 bool
-TimeAxisViewItem::set_duration (nframes64_t dur, void* src)
+TimeAxisViewItem::set_duration (framepos_t dur, void* src)
 {
        if ((dur > max_item_duration) || (dur < min_item_duration)) {
                warning << string_compose (_("new duration %1 frames is out of bounds for %2"), get_item_name(), dur)
@@ -303,7 +341,7 @@ TimeAxisViewItem::set_duration (nframes64_t dur, void* src)
 }
 
 /** @return duration of this item */
-nframes64_t
+framepos_t
 TimeAxisViewItem::get_duration() const
 {
        return item_duration;
@@ -316,14 +354,14 @@ TimeAxisViewItem::get_duration() const
  * @param src the identity of the object that initiated the change
  */
 void
-TimeAxisViewItem::set_max_duration(nframes64_t dur, void* src)
+TimeAxisViewItem::set_max_duration(framecnt_t dur, void* src)
 {
        max_item_duration = dur;
        MaxDurationChanged(max_item_duration, src); /* EMIT_SIGNAL */
 }
 
 /** @return the maximum duration that this item may have */
-nframes64_t
+framecnt_t
 TimeAxisViewItem::get_max_duration() const
 {
        return max_item_duration;
@@ -336,14 +374,14 @@ TimeAxisViewItem::get_max_duration() const
  * @param src the identity of the object that initiated the change
  */
 void
-TimeAxisViewItem::set_min_duration(nframes64_t dur, void* src)
+TimeAxisViewItem::set_min_duration(framecnt_t dur, void* src)
 {
        min_item_duration = dur;
        MinDurationChanged(max_item_duration, src); /* EMIT_SIGNAL */
 }
 
 /** @return the minimum duration that this item mey have */
-nframes64_t
+framecnt_t
 TimeAxisViewItem::get_min_duration() const
 {
        return min_item_duration;
@@ -448,24 +486,9 @@ TimeAxisViewItem::set_selected(bool yn)
        }
 }
 
-/**
- * Set whether an item should show its selection status.
- *
- * @param yn true if this item should show its selected status
- */
-
-void
-TimeAxisViewItem::set_should_show_selection (bool yn)
-{
-       if (should_show_selection != yn) {
-               should_show_selection = yn;
-               set_frame_color ();
-       }
-}
-
 /** @return the TimeAxisView that this item is on */
 TimeAxisView&
-TimeAxisViewItem::get_time_axis_view()
+TimeAxisViewItem::get_time_axis_view () const
 {
        return trackview;
 }
@@ -478,15 +501,15 @@ TimeAxisViewItem::get_time_axis_view()
  */
 
 void
-TimeAxisViewItem::set_name_text(const ustring& new_name)
+TimeAxisViewItem::set_name_text(const string& new_name)
 {
        if (!name_pixbuf) {
                return;
        }
 
        last_item_width = trackview.editor().frame_to_pixel(item_duration);
-       name_pixbuf_width = pixel_width (new_name, *NAME_FONT) + 2;
-       name_pixbuf->property_pixbuf() = pixbuf_from_ustring(new_name, NAME_FONT, name_pixbuf_width, NAME_HEIGHT, Gdk::Color ("#000000"));
+       name_pixbuf_width = pixel_width (new_name, NAME_FONT) + 2;
+       name_pixbuf->property_pixbuf() = pixbuf_from_string(new_name, NAME_FONT, name_pixbuf_width, NAME_HEIGHT, Gdk::Color ("#000000"));
 }
 
 
@@ -512,7 +535,7 @@ TimeAxisViewItem::set_height (double height)
 
                if (height > NAME_HIGHLIGHT_SIZE) {
                        name_highlight->property_y1() = (double) height - 1 - NAME_HIGHLIGHT_SIZE;
-                       name_highlight->property_y2() = (double) height - 2;
+                       name_highlight->property_y2() = (double) height - 1;
                }
                else {
                        /* it gets hidden now anyway */
@@ -527,13 +550,16 @@ TimeAxisViewItem::set_height (double height)
 
        if (frame) {
                frame->property_y2() = height - 1;
-               frame_handle_start->property_y2() = height - 1;
-               frame_handle_end->property_y2() = height - 1;
+               if (frame_handle_start) {
+                       frame_handle_start->property_y2() = height - 1;
+                       frame_handle_end->property_y2() = height - 1;
+               }
        }
 
        vestigial_frame->property_y2() = height - 1;
 
        update_name_pixbuf_visibility ();
+       set_colors ();
 }
 
 void
@@ -671,7 +697,6 @@ TimeAxisViewItem::set_colors()
 
        if (name_highlight) {
                name_highlight->property_fill_color_rgba() = fill_color;
-               name_highlight->property_outline_color_rgba() = fill_color;
        }
        set_trim_handle_colors();
 }
@@ -682,22 +707,61 @@ TimeAxisViewItem::set_colors()
 void
 TimeAxisViewItem::set_frame_color()
 {
-       if (frame) {
-               uint32_t r,g,b,a;
+        uint32_t f = 0;
+
+       if (!frame) {
+               return;
+       }
+
+       if (_selected) {
+
+                f = ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get();
 
-               if (_selected && should_show_selection) {
-                       UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), &r, &g, &b, &a);
-                       frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
+               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()->canvasvar_RecordingRect.get();
                } else {
-                       if (_recregion) {
-                               UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_RecordingRect.get(), &r, &g, &b, &a);
-                               frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, a);
+
+                       if (high_enough_for_name && !Config->get_color_regions_using_track_color()) {
+                               f = ARDOUR_UI::config()->canvasvar_FrameBase.get();
                        } else {
-                               UINT_TO_RGBA(ARDOUR_UI::config()->canvasvar_FrameBase.get(), &r, &g, &b, &a);
-                               frame->property_fill_color_rgba() = RGBA_TO_UINT(r, g, b, fill_opacity ? fill_opacity : a);
+                               f = fill_color;
                        }
-               }
+
+                       if (fill_opacity) {
+                               f = UINT_RGBA_CHANGE_A (f, fill_opacity);
+                       }
+
+                        if (!rect_visible) {
+                                f = UINT_RGBA_CHANGE_A (f, 0);
+                        }
+                }
        }
+
+        frame->property_fill_color_rgba() = f;
+
+        if (!_recregion) {
+                if (_selected) {
+                        f = ARDOUR_UI::config()->canvasvar_SelectedTimeAxisFrame.get();
+                } else {
+                        f = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get();
+                }
+
+                if (!rect_visible) {
+                        f = UINT_RGBA_CHANGE_A (f, 64);
+                }
+
+                frame->property_outline_color_rgba() = f;
+        }
 }
 
 /**
@@ -787,13 +851,8 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
                                }
                                high_enough_for_name = true;
                        }
-                        
-                       if (visibility & FullWidthNameHighlight) {
-                               name_highlight->property_x2() = pixel_width;
-                       } else {
-                               name_highlight->property_x2() = pixel_width - 1.0;
-                       }
 
+                       name_highlight->property_x2() = pixel_width;
                }
 
                if (frame) {
@@ -811,6 +870,8 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
                        frame_handle_end->show();
                        frame_handle_end->property_x2() = pixel_width;
                }
+
+               wide_enough_for_name = true;
        }
 
         update_name_pixbuf_visibility ();
@@ -835,16 +896,16 @@ TimeAxisViewItem::reset_name_width (double /*pixel_width*/)
 
        if (pixbuf_holds_full_name && (it_width >= pb_width + NAME_X_OFFSET)) {
                /*
-                 we've previously had the full name length showing 
+                 we've previously had the full name length showing
                  and its still showing.
                */
                return;
        }
-       
+
        if (pb_width > it_width - NAME_X_OFFSET) {
                pb_width = it_width - NAME_X_OFFSET;
        }
-       
+
        if (it_width <= NAME_X_OFFSET) {
                wide_enough_for_name = false;
        } else {
@@ -853,7 +914,7 @@ TimeAxisViewItem::reset_name_width (double /*pixel_width*/)
 
        update_name_pixbuf_visibility ();
        if (pb_width > 0) {
-               name_pixbuf->property_pixbuf() = pixbuf_from_ustring(item_name, NAME_FONT, pb_width, NAME_HEIGHT, Gdk::Color ("#000000"));
+               name_pixbuf->property_pixbuf() = pixbuf_from_string(item_name, NAME_FONT, pb_width, NAME_HEIGHT, Gdk::Color ("#000000"));
        }
 }
 
@@ -889,7 +950,7 @@ TimeAxisViewItem::update_name_pixbuf_visibility ()
        if (!name_pixbuf) {
                return;
        }
-       
+
        if (wide_enough_for_name && high_enough_for_name) {
                name_pixbuf->show ();
        } else {
@@ -897,3 +958,10 @@ TimeAxisViewItem::update_name_pixbuf_visibility ()
        }
 }
 
+void
+TimeAxisViewItem::parameter_changed (string p)
+{
+       if (p == "color-regions-using-track-color") {
+               set_frame_color ();
+       }
+}