Fix crash when going from >2 outputs (2D panner) to <= 2 outputs.
[ardour.git] / gtk2_ardour / time_axis_view_item.cc
index 53f8b39ce03cb47e03251d1233ef53e015892e2a..19b599215bb37bbd53a0d2350b7dc8bf5340f1db 100644 (file)
@@ -107,12 +107,13 @@ TimeAxisViewItem::TimeAxisViewItem(const string & it_name, ArdourCanvas::Group&
 
        group = new ArdourCanvas::Group (parent);
 
-       init (it_name, spu, base_color, start, duration, vis, true);
+       init (it_name, spu, base_color, start, duration, vis, true, true);
 
 }
 
 TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other)
        : sigc::trackable(other)
+       , PBD::ScopedConnectionList()
        , trackview (other.trackview)
 {
 
@@ -128,11 +129,18 @@ TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other)
 
        group = new ArdourCanvas::Group (*parent);
 
-       init (other.item_name, other.samples_per_unit, c, other.frame_position, other.item_duration, other.visibility, other.wide_enough_for_name);
+       _selected = other._selected;
+
+       init (
+               other.item_name, other.samples_per_unit, c, other.frame_position,
+               other.item_duration, other.visibility, other.wide_enough_for_name, other.high_enough_for_name
+               );
 }
 
 void
-TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color const & base_color, nframes64_t start, nframes64_t duration, Visibility vis, bool wide)
+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
+       )
 {
        item_name = it_name ;
        samples_per_unit = spu ;
@@ -150,6 +158,7 @@ TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color const & ba
        name_pixbuf_width = 0;
        last_item_width = 0;
        wide_enough_for_name = wide;
+       high_enough_for_name = high;
 
        if (duration == 0) {
                warning << "Time Axis Item Duration == 0" << endl ;
@@ -204,7 +213,7 @@ TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color const & ba
        if (visibility & ShowNameText) {
                name_pixbuf = new ArdourCanvas::Pixbuf(*group);
                name_pixbuf->property_x() = NAME_X_OFFSET;
-               name_pixbuf->property_y() = trackview.current_height() - 1.0 - NAME_Y_OFFSET;
+               name_pixbuf->property_y() = trackview.current_height() + 1 - NAME_Y_OFFSET;
 
        } else {
                name_pixbuf = 0;
@@ -550,15 +559,12 @@ TimeAxisViewItem::set_height (double height)
 {
        if (name_highlight) {
                if (height < NAME_HIGHLIGHT_THRESH) {
-                       name_highlight->hide();
-                       name_pixbuf->hide();
+                       name_highlight->hide ();
+                       high_enough_for_name = false;
 
                } else {
                        name_highlight->show();
-                       if (wide_enough_for_name) {
-                               name_pixbuf->show();
-                       }
-
+                       high_enough_for_name = true;
                }
 
                if (height > NAME_HIGHLIGHT_SIZE) {
@@ -573,7 +579,7 @@ TimeAxisViewItem::set_height (double height)
        }
 
        if (visibility & ShowNameText) {
-               name_pixbuf->property_y() =  height - 1 - NAME_Y_OFFSET;
+               name_pixbuf->property_y() =  height + 1 - NAME_Y_OFFSET;
        }
 
        if (frame) {
@@ -583,6 +589,8 @@ TimeAxisViewItem::set_height (double height)
        }
 
        vestigial_frame->property_y2() = height - 1;
+
+       update_name_pixbuf_visibility ();
 }
 
 /**
@@ -814,7 +822,6 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
 
                if (name_highlight) {
                        name_highlight->hide();
-                       name_pixbuf->hide();
                }
 
                if (frame) {
@@ -826,6 +833,8 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
                        frame_handle_end->hide();
                }
 
+               wide_enough_for_name = false;
+
        } else {
                vestigial_frame->hide();
 
@@ -835,12 +844,13 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width)
 
                        if (height < NAME_HIGHLIGHT_THRESH) {
                                name_highlight->hide();
-                               name_pixbuf->hide();
+                               high_enough_for_name = false;
                        } else {
                                name_highlight->show();
                                if (!get_item_name().empty()) {
                                        reset_name_width (pixel_width);
                                }
+                               high_enough_for_name = true;
                        }
 
                        if (visibility & FullWidthNameHighlight) {
@@ -898,16 +908,16 @@ TimeAxisViewItem::reset_name_width (double /*pixel_width*/)
                pb_width = it_width - NAME_X_OFFSET;
        }
        
-       if (pb_width <= 0 || it_width <= NAME_X_OFFSET) {
+       if (it_width <= NAME_X_OFFSET) {
                wide_enough_for_name = false;
-               name_pixbuf->hide();
-               return;
        } else {
                wide_enough_for_name = true;
-               name_pixbuf->show();
        }
 
-       name_pixbuf->property_pixbuf() = pixbuf_from_ustring(item_name, NAME_FONT, pb_width, NAME_HEIGHT, Gdk::Color ("#000000"));
+       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"));
+       }
 }
 
 
@@ -931,7 +941,7 @@ TimeAxisViewItem::remove_this_item(void* src)
           defer to idle loop, otherwise we'll delete this object
           while we're still inside this function ...
        */
-        Glib::signal_idle().connect(bind (sigc::ptr_fun (&TimeAxisViewItem::idle_remove_this_item), this, src));
+        Glib::signal_idle().connect(sigc::bind (sigc::ptr_fun (&TimeAxisViewItem::idle_remove_this_item), this, src));
 }
 
 /**
@@ -960,5 +970,17 @@ TimeAxisViewItem::set_y (double y)
        }
 }
 
-
+void
+TimeAxisViewItem::update_name_pixbuf_visibility ()
+{
+       if (!name_pixbuf) {
+               return;
+       }
+       
+       if (wide_enough_for_name && high_enough_for_name) {
+               name_pixbuf->show ();
+       } else {
+               name_pixbuf->hide ();
+       }
+}