Fix crash when adding automation tracks caused by route ordering.
[ardour.git] / gtk2_ardour / time_axis_view.cc
index 1f50e938818ec4a0549781660a8619fcb491afda..56f23a0ac2daacc2f94660c51516c5a8411ba2a8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000 Paul Davis 
+    Copyright (C) 2000 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -57,7 +57,7 @@
 using namespace std;
 using namespace Gtk;
 using namespace Gdk;
-using namespace sigc; 
+using namespace sigc;
 using namespace ARDOUR;
 using namespace PBD;
 using namespace Editing;
@@ -74,8 +74,8 @@ uint32_t TimeAxisView::hSmall = 0;
 bool TimeAxisView::need_size_info = true;
 int const TimeAxisView::_max_order = 512;
 
-TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisViewPtr rent, Canvas& canvas) 
-       : AxisView (sess), 
+TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* rent, Canvas& /*canvas*/)
+       : AxisView (sess),
          controls_table (2, 8),
          _y_position (0),
          _editor (ed),
@@ -133,6 +133,7 @@ TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisVie
 
        name_hbox.show ();
 
+       controls_table.set_size_request (200);
        controls_table.set_border_width (2);
        controls_table.set_row_spacings (0);
        controls_table.set_col_spacings (0);
@@ -338,7 +339,7 @@ void
 TimeAxisView::selection_click (GdkEventButton* ev)
 {
        Selection::Operation op = Keyboard::selection_type (ev->state);
-       _editor.set_selected_track (shared_from_this (), op, false);
+       _editor.set_selected_track (*this, op, false);
 }
 
 void
@@ -367,7 +368,7 @@ TimeAxisView::hide ()
 
        /* if its hidden, it cannot be selected */
 
-       _editor.get_selection().remove (shared_from_this ());
+       _editor.get_selection().remove (this);
 
        Hiding ();
 }
@@ -430,15 +431,15 @@ TimeAxisView::name_entry_key_release (GdkEventKey* ev)
                return true;
 
        /* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
-        * generates a different ev->keyval, rather than setting 
+        * generates a different ev->keyval, rather than setting
         * ev->state.
         */
        case GDK_ISO_Left_Tab:
        case GDK_Tab:
                name_entry_changed ();
-               allviews = _editor.get_valid_views (TimeAxisViewPtr ());
+               allviews = _editor.get_valid_views (0);
                if (allviews != 0) {
-                       i = find (allviews->begin(), allviews->end(), shared_from_this ());
+                       i = find (allviews->begin(), allviews->end(), this);
                        if (ev->keyval == GDK_Tab) {
                                if (i != allviews->end()) {
                                        do {
@@ -473,7 +474,7 @@ TimeAxisView::name_entry_key_release (GdkEventKey* ev)
                break;
        }
 
-#ifdef TIMEOUT_NAME_EDIT       
+#ifdef TIMEOUT_NAME_EDIT
        /* adapt the timeout to reflect the user's typing speed */
 
        guint32 name_entry_timeout;
@@ -498,7 +499,7 @@ TimeAxisView::name_entry_key_release (GdkEventKey* ev)
 }
 
 bool
-TimeAxisView::name_entry_focus_in (GdkEventFocus* ev)
+TimeAxisView::name_entry_focus_in (GdkEventFocus*)
 {
        name_entry.select_region (0, -1);
        name_entry.set_name ("EditorActiveTrackNameDisplay");
@@ -506,7 +507,7 @@ TimeAxisView::name_entry_focus_in (GdkEventFocus* ev)
 }
 
 bool
-TimeAxisView::name_entry_focus_out (GdkEventFocus* ev)
+TimeAxisView::name_entry_focus_out (GdkEventFocus*)
 {
        /* clean up */
 
@@ -564,8 +565,8 @@ TimeAxisView::conditionally_add_to_selection ()
 {
        Selection& s (_editor.get_selection ());
 
-       if (!s.selected (shared_from_this ())) {
-               _editor.set_selected_track (shared_from_this (), Selection::Set);
+       if (!s.selected (this)) {
+               _editor.set_selected_track (*this, Selection::Set);
        }
 }
 
@@ -577,7 +578,7 @@ TimeAxisView::popup_display_menu (guint32 when)
        }
 
        conditionally_add_to_selection ();
-       display_menu->popup (1, when);  
+       display_menu->popup (1, when);
 }
 
 gint
@@ -870,7 +871,7 @@ TimeAxisView::get_selection_rect (uint32_t id)
                rect->rect->signal_event().connect (bind (mem_fun (_editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
                rect->start_trim->signal_event().connect (bind (mem_fun (_editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
                rect->end_trim->signal_event().connect (bind (mem_fun (_editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
-       } 
+       }
 
        rect = free_selection_rects.front();
        rect->id = id;
@@ -878,10 +879,12 @@ TimeAxisView::get_selection_rect (uint32_t id)
        return rect;
 }
 
+struct null_deleter { void operator()(void const *) const {} };
+
 bool
-TimeAxisView::is_child (TimeAxisViewPtr tav)
+TimeAxisView::is_child (TimeAxisView* tav)
 {
-       return find (children.begin(), children.end(), tav) != children.end();
+       return find (children.begin(), children.end(), boost::shared_ptr<TimeAxisView>(tav, null_deleter())) != children.end();
 }
 
 void
@@ -901,13 +904,13 @@ TimeAxisView::remove_child (boost::shared_ptr<TimeAxisView> child)
 }
 
 void
-TimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& result)
+TimeAxisView::get_selectables (nframes_t /*start*/, nframes_t /*end*/, double /*top*/, double /*bot*/, list<Selectable*>& /*result*/)
 {
        return;
 }
 
 void
-TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
+TimeAxisView::get_inverted_selectables (Selection& /*sel*/, list<Selectable*>& /*result*/)
 {
        return;
 }
@@ -915,7 +918,7 @@ TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& resul
 void
 TimeAxisView::add_ghost (RegionView* rv)
 {
-       GhostRegion* gr = rv->add_ghost (shared_from_this ());
+       GhostRegion* gr = rv->add_ghost (*this);
 
        if(gr) {
                ghosts.push_back(gr);
@@ -924,9 +927,8 @@ TimeAxisView::add_ghost (RegionView* rv)
 }
 
 void
-TimeAxisView::remove_ghost (RegionView* rv)
-{
-       rv->remove_ghost_in (shared_from_this ());
+TimeAxisView::remove_ghost (RegionView* rv) {
+       rv->remove_ghost_in (*this);
 }
 
 void
@@ -953,16 +955,16 @@ TimeAxisView::touched (double top, double bot)
        */
 
        double mybot = _y_position + current_height();
-       
-       return ((_y_position <= bot && _y_position >= top) || 
-               ((mybot <= bot) && (top < mybot)) || 
+
+       return ((_y_position <= bot && _y_position >= top) ||
+               ((mybot <= bot) && (top < mybot)) ||
                (mybot >= bot && _y_position < top));
-}              
+}
 
 void
-TimeAxisView::set_parent (TimeAxisViewPtr p)
+TimeAxisView::set_parent (TimeAxisView& p)
 {
-       parent = p;
+       parent = &p;
 }
 
 bool
@@ -971,10 +973,14 @@ TimeAxisView::has_state () const
        return _has_state;
 }
 
-TimeAxisViewPtr
+TimeAxisView*
 TimeAxisView::get_parent_with_state ()
 {
-       if (parent == 0 || parent->has_state()) {
+       if (parent == 0) {
+               return 0;
+       }
+
+       if (parent->has_state()) {
                return parent;
        }
 
@@ -995,7 +1001,7 @@ TimeAxisView::get_state ()
 }
 
 int
-TimeAxisView::set_state (const XMLNode& node)
+TimeAxisView::set_state (const XMLNode& node, int /*version*/)
 {
        const XMLProperty *prop;
 
@@ -1025,7 +1031,7 @@ TimeAxisView::set_state (const XMLNode& node)
        } else if ((prop = node.property ("height")) != 0) {
 
                set_height (atoi (prop->value()));
-               
+
        } else {
 
                set_height (hNormal);
@@ -1043,7 +1049,7 @@ TimeAxisView::reset_height()
                (*i)->set_height ((*i)->height);
        }
 }
-       
+
 void
 TimeAxisView::compute_controls_size_info ()
 {
@@ -1074,7 +1080,7 @@ TimeAxisView::compute_controls_size_info ()
        }
 
        one_row_table.attach (*buttons[0], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
-       
+
        one_row_table.show_all ();
        Gtk::Requisition req(one_row_table.size_request ());
 
@@ -1094,11 +1100,11 @@ TimeAxisView::compute_controls_size_info ()
        two_row_table.show_all ();
        req = two_row_table.size_request ();
 
-       // height required to show all normal buttons 
+       // height required to show all normal buttons
 
        hNormal = /*req.height*/ 48 + extra_height;
 
-       // these heights are all just larger than normal. no more 
+       // these heights are all just larger than normal. no more
        // elements are visible (yet).
 
        hLarger = hNormal + 50;
@@ -1189,11 +1195,11 @@ TimeAxisView::color_handler ()
  * Layer index is the layer number if the TimeAxisView is valid and is in stacked
  * region display mode, otherwise 0.
  */
-std::pair<TimeAxisViewPtr, layer_t>
+std::pair<TimeAxisView*, layer_t>
 TimeAxisView::covers_y_position (double y)
 {
        if (hidden()) {
-               return std::make_pair (TimeAxisViewPtr (), 0);
+               return std::make_pair ( (TimeAxisView *) 0, 0);
        }
 
        if (_y_position <= y && y < (_y_position + height)) {
@@ -1209,19 +1215,19 @@ TimeAxisView::covers_y_position (double y)
                                l = view()->layers() - 1;
                        }
                }
-                       
-               return std::make_pair (shared_from_this (), l);
+
+               return std::make_pair (this, l);
        }
 
        for (Children::const_iterator i = children.begin(); i != children.end(); ++i) {
 
-               std::pair<TimeAxisViewPtr, int> const r = (*i)->covers_y_position (y);
+               std::pair<TimeAxisView*, int> const r = (*i)->covers_y_position (y);
                if (r.first) {
                        return r;
                }
        }
 
-       return std::make_pair (TimeAxisViewPtr (), 0);
+       return std::make_pair ( (TimeAxisView *) 0, 0);
 }
 
 void
@@ -1277,7 +1283,7 @@ TimeAxisView::resizer_button_press (GdkEventButton* event)
 }
 
 bool
-TimeAxisView::resizer_button_release (GdkEventButton* ev)
+TimeAxisView::resizer_button_release (GdkEventButton*)
 {
        _resize_drag_start = -1;
        return true;
@@ -1297,7 +1303,7 @@ TimeAxisView::resizer_motion (GdkEventMotion* ev)
        }
 
        int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start);
-       _editor.add_to_idle_resize (shared_from_this (), delta);
+       _editor.add_to_idle_resize (this, delta);
        _resize_drag_start = ev->y_root;
 
        return true;
@@ -1321,7 +1327,7 @@ TimeAxisView::resizer_expose (GdkEventExpose* event)
        win->get_geometry (x, y, w, h, d);
 
        /* handle/line #1 */
-       
+
        win->draw_line (dark, 0, 0, w - 2, 0);
        win->draw_point (dark, 0, 1);
        win->draw_line (light, 1, 1, w - 1, 1);
@@ -1344,17 +1350,3 @@ TimeAxisView::resizer_expose (GdkEventExpose* event)
        return true;
 }
 
-TimeAxisViewPtr
-TimeAxisView::find_time_axis (TimeAxisView* v)
-{
-       Children::iterator i = children.begin ();
-       while (i != children.end() && i->get() != v) {
-               ++i;
-       }
-
-       if (i == children.end()) {
-               return TimeAxisViewPtr ();
-       }
-
-       return *i;
-}