Clamp values in ControlList
[ardour.git] / gtk2_ardour / editor_routes.cc
index 365dd8d9ef8356e60df44405a19c1b249ec8368c..45b9797f78d9b51e0d59793fc1f3095958462e0f 100644 (file)
@@ -87,7 +87,6 @@ EditorRoutes::EditorRoutes (Editor* e)
        , _queue_tv_update (0)
        , _menu (0)
        , old_focus (0)
-       , selection_countdown (0)
        , name_editable (0)
 {
        static const int column_width = 22;
@@ -261,7 +260,6 @@ EditorRoutes::EditorRoutes (Editor* e)
        _display.set_name (X_("EditGroupList"));
        _display.set_rules_hint (true);
        _display.set_size_request (100, -1);
-       _display.add_object_drag (_columns.stripable.index(), "routes");
 
        CellRendererText* name_cell = dynamic_cast<CellRendererText*> (_display.get_column_cell_renderer (_name_column));
 
@@ -360,7 +358,6 @@ EditorRoutes::enter_notify (GdkEventCrossing*)
        /* arm counter so that ::selection_filter() will deny selecting anything for the
         * next two attempts to change selection status.
         */
-       selection_countdown = 2;
        _scroller.grab_focus ();
        Keyboard::magic_widget_grab_focus ();
        return false;
@@ -369,8 +366,6 @@ EditorRoutes::enter_notify (GdkEventCrossing*)
 bool
 EditorRoutes::leave_notify (GdkEventCrossing*)
 {
-       selection_countdown = 0;
-
        if (old_focus) {
                old_focus->grab_focus ();
                old_focus = 0;
@@ -836,7 +831,6 @@ EditorRoutes::time_axis_views_added (list<TimeAxisView*> tavs)
 
        {
                PBD::Unwinder<bool> uw (_ignore_selection_change, true);
-               cerr << "Should ignore model/selection change\n";
                _display.set_model (_model);
        }
 
@@ -950,8 +944,7 @@ EditorRoutes::update_visibility ()
                (*i)[_columns.visible] = tv->marked_for_display ();
        }
 
-       /* force route order keys catch up with visibility changes
-        */
+       /* force route order keys catch up with visibility changes */
 
        sync_presentation_info_from_treeview ();
 }
@@ -1004,85 +997,36 @@ EditorRoutes::sync_presentation_info_from_treeview ()
 
        DEBUG_TRACE (DEBUG::OrderKeys, "editor sync presentation info from treeview\n");
 
-       TreeModel::Children::iterator ri;
        bool change = false;
        PresentationInfo::order_t order = 0;
-       bool master_is_first = false;
-       uint32_t count = 0;
-
-       OrderingKeys sorted;
-       const size_t cmp_max = rows.size ();
 
        PresentationInfo::ChangeSuspender cs;
 
-       // special case master if it's got PI order 0 lets keep it there
-       if (_session->master_out() && (_session->master_out()->presentation_info().order() == 0)) {
-               order++;
-               master_is_first = true;
-       }
-
-       for (ri = rows.begin(); ri != rows.end(); ++ri) {
-
+       for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
                boost::shared_ptr<Stripable> stripable = (*ri)[_columns.stripable];
                bool visible = (*ri)[_columns.visible];
 
-               /* Monitor and Auditioner do not get their presentation
-                * info reset here.
-                */
-
+#ifndef NDEBUG // these should not exist in the treeview
+               assert (stripable);
                if (stripable->is_monitor() || stripable->is_auditioner()) {
+                       assert (0);
                        continue;
                }
+#endif
 
                stripable->presentation_info().set_hidden (!visible);
 
-               /* special case master if it's got PI order 0 lets keep it there
-                * but still allow master to move if first non-master route has
-                * presentation order 1
-                */
-               if ((count == 0) && master_is_first && (stripable->presentation_info().order()  == 1)) {
-                       master_is_first = false; // someone has moved master
-                       order = 0;
-               }
-
-               if (stripable->is_master() && master_is_first) {
-                       if (count) {
-                               continue;
-                       } else {
-                               count++;
-                               continue;
-                       }
-               }
-
                if (order != stripable->presentation_info().order()) {
                        stripable->set_presentation_order (order);
                        change = true;
                }
-
-               sorted.push_back (OrderKeys (order, stripable, cmp_max));
-
                ++order;
-               ++count;
        }
 
-       if (!change) {
-               // VCA (and Mixbus) special cases according to SortByNewDisplayOrder
-               uint32_t n = 0;
-               SortByNewDisplayOrder cmp;
-               sort (sorted.begin(), sorted.end(), cmp);
-               for (OrderingKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
-                       if (sr->old_display_order != n) {
-                               change = true;
-                       }
-               }
-               if (change) {
-                       n = 0;
-                       for (OrderingKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
-                               if (sr->stripable->presentation_info().order() != n) {
-                                       sr->stripable->set_presentation_order (n);
-                               }
-                       }
-               }
+       change |= _session->ensure_stripable_sort_order ();
+
+       if (change) {
+               _session->set_dirty();
        }
 }
 
@@ -1105,33 +1049,31 @@ EditorRoutes::sync_treeview_from_presentation_info (PropertyChange const & what_
 
        TreeModel::Children rows = _model->children();
 
-       if (what_changed.contains (hidden_or_order)) {
+       bool changed = false;
 
+       if (what_changed.contains (hidden_or_order)) {
                vector<int> neworder;
                uint32_t old_order = 0;
-               bool changed = false;
 
                if (rows.empty()) {
                        return;
                }
 
-               OrderingKeys sorted;
-               const size_t cmp_max = rows.size ();
-
+               TreeOrderKeys sorted;
                for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri, ++old_order) {
                        boost::shared_ptr<Stripable> stripable = (*ri)[_columns.stripable];
                        /* use global order */
-                       sorted.push_back (OrderKeys (old_order, stripable, cmp_max));
+                       sorted.push_back (TreeOrderKey (old_order, stripable));
                }
 
-               SortByNewDisplayOrder cmp;
+               TreeOrderKeySorter cmp;
 
                sort (sorted.begin(), sorted.end(), cmp);
                neworder.assign (sorted.size(), 0);
 
                uint32_t n = 0;
 
-               for (OrderingKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
+               for (TreeOrderKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
 
                        neworder[n] = sr->old_display_order;
 
@@ -1158,24 +1100,16 @@ EditorRoutes::sync_treeview_from_presentation_info (PropertyChange const & what_
                }
        }
 
-       if (what_changed.contains (Properties::selected)) {
-
+       if (changed || what_changed.contains (Properties::selected)) {
                /* by the time this is invoked, the GUI Selection model has
                 * already updated itself.
                 */
-
-               TrackViewList tvl;
                PBD::Unwinder<bool> uw (_ignore_selection_change, true);
 
                /* set the treeview model selection state */
-
                for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
                        boost::shared_ptr<Stripable> stripable = (*ri)[_columns.stripable];
                        if (stripable && stripable->is_selected()) {
-                               TimeAxisView* tav = (*ri)[_columns.tv];
-                               if (tav) {
-                                       tvl.push_back (tav);
-                               }
                                _display.get_selection()->select (*ri);
                        } else {
                                _display.get_selection()->unselect (*ri);
@@ -1524,15 +1458,6 @@ EditorRoutes::selection_changed ()
 bool
 EditorRoutes::selection_filter (Glib::RefPtr<TreeModel> const& model, TreeModel::Path const& path, bool /*selected*/)
 {
-       if (selection_countdown) {
-               if (--selection_countdown == 0) {
-                       return true;
-               } else {
-                       /* no selection yet ... */
-                       return false;
-               }
-       }
-
        TreeModel::iterator iter = model->get_iter (path);
        if (iter) {
                boost::shared_ptr<Stripable> stripable = (*iter)[_columns.stripable];
@@ -1544,27 +1469,6 @@ EditorRoutes::selection_filter (Glib::RefPtr<TreeModel> const& model, TreeModel:
        return true;
 }
 
-struct PresentationInfoRouteSorter
-{
-       bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-               if (a->is_master()) {
-                       /* master before everything else */
-                       return true;
-               } else if (b->is_master()) {
-                       /* everything else before master */
-                       return false;
-               }
-               return a->presentation_info().order () < b->presentation_info().order ();
-       }
-};
-
-struct PresentationInfoVCASorter
-{
-       bool operator() (boost::shared_ptr<VCA> a, boost::shared_ptr<VCA> b) {
-               return a->presentation_info().order () < b->presentation_info().order ();
-       }
-};
-
 void
 EditorRoutes::initial_display ()
 {
@@ -1594,20 +1498,6 @@ EditorRoutes::initial_display ()
        sync_treeview_from_presentation_info (Properties::order);
 }
 
-void
-EditorRoutes::display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
-                                            int x, int y,
-                                            const SelectionData& data,
-                                            guint info, guint time)
-{
-       if (data.get_target() == "GTK_TREE_MODEL_ROW") {
-               _display.on_drag_data_received (context, x, y, data, info, time);
-               return;
-       }
-
-       context->drag_finish (true, false, time);
-}
-
 struct ViewStripable {
        TimeAxisView* tav;
        boost::shared_ptr<Stripable> stripable;
@@ -1628,7 +1518,7 @@ EditorRoutes::move_selected_tracks (bool up)
                return;
        }
 
-       sl.sort (Stripable::PresentationOrderSorter());
+       sl.sort (Stripable::Sorter());
 
        std::list<ViewStripable> view_stripables;