Use Stripable::Sorter in GUI consistently.
authorRobin Gareus <robin@gareus.org>
Fri, 16 Jun 2017 21:45:16 +0000 (23:45 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 17 Jun 2017 02:36:39 +0000 (04:36 +0200)
gtk2_ardour/editor.cc
gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_routes.cc
gtk2_ardour/export_channel_selector.cc
gtk2_ardour/group_tabs.cc
gtk2_ardour/meterbridge.cc
gtk2_ardour/mixer_ui.cc
gtk2_ardour/route_sorter.h
gtk2_ardour/stripable_treemodel.cc

index 6ff757c1b79aaddb9734a4b788132f670c761ccf..ea74b2d970780de6cc629434f2b52b48aad64461 100644 (file)
@@ -5332,7 +5332,7 @@ Editor::add_stripables (StripableList& sl)
        TrackViewList new_selection;
        bool from_scratch = (track_views.size() == 0);
 
-       sl.sort (StripablePresentationInfoSorter());
+       sl.sort (Stripable::Sorter());
 
        for (StripableList::iterator s = sl.begin(); s != sl.end(); ++s) {
 
index 419e48da219179e95053ecd4d3716371371bc50e..c9604b13dfb5320caab2603c8ed3020358902c1d 100644 (file)
@@ -546,9 +546,11 @@ Drag::add_midi_region (MidiTimeAxisView* view, bool commit)
        return boost::shared_ptr<Region>();
 }
 
-struct PresentationInfoTimeAxisViewSorter {
-       bool operator() (TimeAxisView* a, TimeAxisView* b) {
-               return a->stripable()->presentation_info().order() < b->stripable()->presentation_info().order();
+struct TimeAxisViewStripableSorter {
+       bool operator() (TimeAxisView* tav_a, TimeAxisView* tav_b) {
+               boost::shared_ptr<ARDOUR::Stripable> const& a = tav_a->stripable ();
+               boost::shared_ptr<ARDOUR::Stripable> const& b = tav_b->stripable ();
+               return ARDOUR::Stripable::Sorter () (a, b);
        }
 };
 
@@ -564,7 +566,7 @@ RegionDrag::RegionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<Re
        */
 
        TrackViewList track_views = _editor->track_views;
-       track_views.sort (PresentationInfoTimeAxisViewSorter ());
+       track_views.sort (TimeAxisViewStripableSorter ());
 
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                _time_axis_views.push_back (*i);
index 487f3aff2b7a8e3a90d069c2023a7219fa9b5111..aaa7daf80f074a007d10a8f7b7498ab2a28622ae 100644 (file)
@@ -1006,82 +1006,37 @@ EditorRoutes::sync_presentation_info_from_treeview ()
        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 ();
+       TreeOrderKeys sorted;
 
        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) {
-
                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
                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));
-
+               sorted.push_back (TreeOrderKey (order, stripable));
                ++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();
        }
 }
 
@@ -1114,23 +1069,21 @@ EditorRoutes::sync_treeview_from_presentation_info (PropertyChange const & what_
                        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;
 
@@ -1543,27 +1496,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 ()
 {
@@ -1627,7 +1559,7 @@ EditorRoutes::move_selected_tracks (bool up)
                return;
        }
 
-       sl.sort (Stripable::PresentationOrderSorter());
+       sl.sort (Stripable::Sorter());
 
        std::list<ViewStripable> view_stripables;
 
index acbed62030a7396ddb91d403f5d2f334ff8ee3d1..347882501c5959892859ba18593bd07bb26114e0 100644 (file)
@@ -121,7 +121,7 @@ PortExportChannelSelector::fill_route_list ()
                channel_view.add_route (master);
        }
 
-       routes.sort (Stripable::PresentationOrderSorter ());
+       routes.sort (Stripable::Sorter ());
 
        for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
                if ((*it)->is_master () || (*it)->is_monitor ()) {
index 8f076fe84efcb8dd6d79a938c5fe4bffda6f9fe4..17667da6503dcc22222ec87caa32b825ff63b88d 100644 (file)
@@ -679,12 +679,12 @@ void
 GroupTabs::collect (RouteGroup* g)
 {
        boost::shared_ptr<RouteList> group_routes = g->route_list ();
-       group_routes->sort (Stripable::PresentationOrderSorter());
+       group_routes->sort (Stripable::Sorter());
        int const N = group_routes->size ();
 
        RouteList::iterator i = group_routes->begin ();
        boost::shared_ptr<RouteList> routes = _session->get_routes ();
-       routes->sort (Stripable::PresentationOrderSorter());
+       routes->sort (Stripable::Sorter());
        RouteList::const_iterator j = routes->begin ();
 
        int diff = 0;
index 09ad83350dd1c76113c1ab492ab60e47c8e8942f..69006eda57ec66497d63a755569d196fc4328887 100644 (file)
@@ -408,22 +408,6 @@ Meterbridge::on_scroll()
        metrics_right.set_metric_mode(mm_right, mt_right);
 }
 
-struct PresentationInfoRouteSorter
-{
-       bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-               if (a->is_master() || a->is_monitor()) {
-                       /* "a" is a special route (master, monitor, etc), and comes
-                        * last in the mixer ordering
-                        */
-                       return false;
-               } else if (b->is_master() || b->is_monitor()) {
-                       /* everything comes before b */
-                       return true;
-               }
-               return a->presentation_info().order() < b->presentation_info().order();
-       }
-};
-
 void
 Meterbridge::set_session (Session* s)
 {
@@ -449,7 +433,7 @@ Meterbridge::set_session (Session* s)
        boost::shared_ptr<RouteList> routes = _session->get_routes();
 
        RouteList copy (*routes);
-       copy.sort (PresentationInfoRouteSorter());
+       copy.sort (Stripable::Sorter (true));
        add_strips (copy);
 
        _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&Meterbridge::add_strips, this, _1), gui_context());
index 11bc38609bd8dfe2c8156c0a5c2628156ba80afb..6a156d7d8bc607505f3225ffc0b88e3e1884575d 100644 (file)
@@ -498,7 +498,7 @@ Mixer_UI::add_stripables (StripableList& slist)
        bool from_scratch = (track_model->children().size() == 0);
        uint32_t nroutes = 0;
 
-       slist.sort (StripablePresentationInfoSorter());
+       slist.sort (Stripable::Sorter());
 
        for (Gtk::TreeModel::Children::iterator it = track_model->children().begin(); it != track_model->children().end(); ++it) {
                boost::shared_ptr<Stripable> s = (*it)[stripable_columns.stripable];
@@ -509,6 +509,7 @@ Mixer_UI::add_stripables (StripableList& slist)
 
                nroutes++;
 
+               // XXX what does this special case do?
                if (s->presentation_info().order() == (slist.front()->presentation_info().order() + slist.size())) {
                        insert_iter = it;
                        break;
@@ -722,15 +723,12 @@ Mixer_UI::sync_presentation_info_from_treeview ()
 
        TreeModel::Children::iterator ri;
        bool change = false;
-       uint32_t order = 0;
 
-       OrderingKeys sorted;
-       const size_t cmp_max = rows.size ();
+       PresentationInfo::order_t master_key = _session->master_order_key ();
+       PresentationInfo::order_t order = 0;
+       uint32_t count = 0;
 
-       // 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++;
-       }
+       TreeOrderKeys sorted;
 
        PresentationInfo::ChangeSuspender cs;
 
@@ -738,27 +736,26 @@ Mixer_UI::sync_presentation_info_from_treeview ()
                bool visible = (*ri)[stripable_columns.visible];
                boost::shared_ptr<Stripable> stripable = (*ri)[stripable_columns.stripable];
 
+#ifndef NDEBUG // these should not exist in the mixer's treeview
                if (!stripable) {
+                       assert (0);
                        continue;
                }
-
-               /* Monitor and Auditioner do not get their presentation
-                * info reset here.
-                */
-
                if (stripable->is_monitor() || stripable->is_auditioner()) {
+                       assert (0);
                        continue;
                }
-
-               /* Master also doesn't get set here but since the editor allows
-                * it to be reordered, we need to preserve its ordering.
-                */
+               if (stripable->is_master()) {
+                       assert (0);
+                       continue;
+               }
+#endif
 
                stripable->presentation_info().set_hidden (!visible);
 
-               // master may not get set here, but if it is zero keep it there
-               if (stripable->is_master() && (stripable->presentation_info().order() == 0)) {
-                       continue;
+               // leave master where it is.
+               if (order == master_key) {
+                       ++order;
                }
 
                if (order != stripable->presentation_info().order()) {
@@ -766,37 +763,12 @@ Mixer_UI::sync_presentation_info_from_treeview ()
                        change = true;
                }
 
-               sorted.push_back (OrderKeys (order, stripable, cmp_max));
-
+               sorted.push_back (TreeOrderKey (count, stripable));
                ++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 (_session->master_out() && (_session->master_out()->presentation_info().order() == n)) {
-                               ++n;
-                       }
-                       if (sr->old_display_order != n) {
-                               change = true;
-                               break;
-                       }
-               }
-               if (change) {
-                       n = 0;
-                       for (OrderingKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
-                               if (_session->master_out() && (_session->master_out()->presentation_info().order() == n)) {
-                                       ++n;
-                               }
-                               if (sr->stripable->presentation_info().order() != n) {
-                                       sr->stripable->set_presentation_order (n);
-                               }
-                       }
-               }
-       }
+       change |= _session->ensure_stripable_sort_order ();
 
        if (change) {
                DEBUG_TRACE (DEBUG::OrderKeys, "... notify PI change from mixer GUI\n");
@@ -827,22 +799,20 @@ Mixer_UI::sync_treeview_from_presentation_info (PropertyChange const & what_chan
                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)[stripable_columns.stripable];
-               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;
 
@@ -926,6 +896,15 @@ Mixer_UI::axis_view_by_control (boost::shared_ptr<AutomationControl> c) const
        return 0;
 }
 
+struct MixerStripSorter {
+       bool operator() (const MixerStrip* ms_a, const MixerStrip* ms_b)
+       {
+               boost::shared_ptr<ARDOUR::Stripable> const& a = ms_a->stripable ();
+               boost::shared_ptr<ARDOUR::Stripable> const& b = ms_b->stripable ();
+               return ARDOUR::Stripable::Sorter(true)(a, b);
+       }
+};
+
 bool
 Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
 {
@@ -949,16 +928,10 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
                                bool accumulate = false;
                                bool found_another = false;
 
-                               OrderingKeys sorted;
-                               const size_t cmp_max = strips.size ();
-                               for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
-                                       sorted.push_back (OrderKeys (-1, (*i)->stripable(), cmp_max));
-                               }
-                               SortByNewDisplayOrder cmp;
-                               sort (sorted.begin(), sorted.end(), cmp);
+                               strips.sort (MixerStripSorter());
 
-                               for (OrderingKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr) {
-                                       MixerStrip* ms = strip_by_stripable (sr->stripable);
+                               for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
+                                       MixerStrip* ms = *i;
                                        assert (ms);
 
                                        if (ms == strip) {
index bf054b1ad4ab3f46d7512131588c7ddf78925d27..fb7f574d720a4026160236c1466ce325fa4074ad 100644 (file)
 
 #include "ardour/stripable.h"
 
-struct OrderKeys {
+/* This is used to keep numerical tree-order in sync
+ * with Stripable ordering (mixer_ui.cc editor_routes.cc)
+ */
+
+struct TreeOrderKey {
     uint32_t old_display_order;
-    uint32_t new_display_order;
-    uint32_t compare_order;
                boost::shared_ptr<ARDOUR::Stripable> stripable;
 
-       OrderKeys (uint32_t ok, boost::shared_ptr<ARDOUR::Stripable> s, uint32_t cmp_max)
+       TreeOrderKey (uint32_t ok, boost::shared_ptr<ARDOUR::Stripable> s)
                : old_display_order (ok)
                , stripable (s)
-       {
-               new_display_order = s->presentation_info().order();
-               compare_order = new_display_order;
-
-               if (s->presentation_info().flags () & ARDOUR::PresentationInfo::VCA) {
-                       compare_order += 2 * cmp_max;
-               }
-#ifdef MIXBUS
-               if (s->presentation_info().flags () & ARDOUR::PresentationInfo::Mixbus || s->mixbus()) {
-                       compare_order += cmp_max;
-               }
-               if (s->presentation_info().flags () & ARDOUR::PresentationInfo::MasterOut) {
-                       compare_order += 3 * cmp_max;
-               }
-#endif
-       }
+       {}
 };
 
-typedef std::vector<OrderKeys> OrderingKeys;
+typedef std::vector<TreeOrderKey> TreeOrderKeys;
 
-struct SortByNewDisplayOrder {
-    bool operator() (const OrderKeys& a, const OrderKeys& b) {
-           return a.compare_order < b.compare_order;
-    }
-};
-
-struct StripablePresentationInfoSorter {
-       bool operator() (boost::shared_ptr<ARDOUR::Stripable> a, boost::shared_ptr<ARDOUR::Stripable> b) {
-               return a->presentation_info().order () < b->presentation_info().order ();
+struct TreeOrderKeySorter
+{
+       bool operator() (const TreeOrderKey& ok_a, const TreeOrderKey& ok_b)
+       {
+               boost::shared_ptr<ARDOUR::Stripable> const& a = ok_a.stripable;
+               boost::shared_ptr<ARDOUR::Stripable> const& b = ok_b.stripable;
+               return ARDOUR::Stripable::Sorter () (a, b);
        }
 };
 
index 197683577cf84a0bd588bb3fc7b84bc6d6d84ae7..8b31d809963ceb886dd3310b34e9686ec99bb36a 100644 (file)
@@ -129,7 +129,7 @@ StripableTreeModel::iter_next_vfunc (const iterator& iter, iterator& iter_next)
        if (sl.empty()) {
                return false;
        }
-       sl.sort (Stripable::PresentationOrderSorter());
+       sl.sort (Stripable::Sorter());
 
        for (StripableList::const_iterator s = sl.begin(); s != sl.end(); ++s) {
 
@@ -199,7 +199,7 @@ StripableTreeModel::iter_nth_root_child_vfunc(int n, iterator& iter) const
                return false;
        }
 
-       sl.sort (Stripable::PresentationOrderSorter());
+       sl.sort (Stripable::Sorter());
 
        StripableList::const_iterator s;