Various changes to PresentationInfo and a small consolidation of sorters.
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 10 Jun 2016 17:50:19 +0000 (13:50 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 10 Jun 2016 17:57:18 +0000 (13:57 -0400)
The semantics for sorting PresentationInfo are up to the caller, not the
PresentationInfo object, so operator<() was removed and callers specifically
invoke ::order() for sorting.

gtk2_ardour/group_tabs.cc
gtk2_ardour/meterbridge.cc
gtk2_ardour/meterbridge.h
libs/ardour/ardour/presentation_info.h
libs/ardour/ardour/stripable.h
libs/ardour/presentation_info.cc
libs/ardour/session.cc
libs/ardour/session_midi.cc
libs/surfaces/mackie/mackie_control_protocol.cc

index 06e50f274b18d0ffcfeec6bc39621eeb8c542a60..f7ceb9e9961421b7ac57e8e0d6c46b53e27b4116 100644 (file)
@@ -663,18 +663,6 @@ GroupTabs::un_subgroup (RouteGroup* g)
        g->destroy_subgroup ();
 }
 
-struct CollectSorter {
-       bool operator () (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-               return a->presentation_info () < b->presentation_info();
-       }
-};
-
-struct OrderSorter {
-       bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-               return a->presentation_info() < b->presentation_info();
-       }
-};
-
 /** Collect all members of a RouteGroup so that they are together in the Editor or Mixer.
  *  @param g Group to collect.
  */
@@ -682,12 +670,12 @@ void
 GroupTabs::collect (RouteGroup* g)
 {
        boost::shared_ptr<RouteList> group_routes = g->route_list ();
-       group_routes->sort (CollectSorter ());
+       group_routes->sort (Stripable::PresentationOrderSorter());
        int const N = group_routes->size ();
 
        RouteList::iterator i = group_routes->begin ();
        boost::shared_ptr<RouteList> routes = _session->get_routes ();
-       routes->sort (OrderSorter ());
+       routes->sort (Stripable::PresentationOrderSorter());
        RouteList::const_iterator j = routes->begin ();
 
        int diff = 0;
index f687d0c72d5a37bafe6894b580ee885962586a9c..07553ced18283aea4af08ade83fb0c68bc2c7686 100644 (file)
@@ -401,14 +401,16 @@ Meterbridge::on_scroll()
 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 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() < b->presentation_info();
+               return a->presentation_info().order() < b->presentation_info().order();
        }
 };
 
@@ -434,12 +436,11 @@ Meterbridge::set_session (Session* s)
        _show_master = _session->config.get_show_master_on_meterbridge();
        _show_midi = _session->config.get_show_midi_on_meterbridge();
 
-       PresentationInfoRouteSorter sorter;
        boost::shared_ptr<RouteList> routes = _session->get_routes();
 
-       RouteList copy(*routes);
-       copy.sort(sorter);
-       add_strips(copy);
+       RouteList copy (*routes);
+       copy.sort (PresentationInfoRouteSorter());
+       add_strips (copy);
 
        _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&Meterbridge::add_strips, this, _1), gui_context());
        _session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&Meterbridge::update_title, this), gui_context());
index 5e0690791738170cc6001181e66e8f4da6ae3b3f..a1715b2633941499082b2850a72386d1fe05e1ec 100644 (file)
@@ -107,7 +107,7 @@ class Meterbridge :
                                /* everything comes before b */
                                return true;
                        }
-                       return a->presentation_info() < b->presentation_info ();
+                       return a->presentation_info().order() < b->presentation_info().order();
                }
        };
 
index 8a3c3674489146005e562dd7126dc007694771d3..91238e6537d0fb840453ff6b7f2c9ade33a68886 100644 (file)
@@ -128,6 +128,7 @@ class LIBARDOUR_API PresentationInfo : public PBD::Stateful
                StatusMask = (Selected|Hidden)
        };
 
+       static const Flag AllStripables; /* mask to use for any route or VCA (but not auditioner) */
        static const Flag AllRoutes; /* mask to use for any route include master+monitor, but not auditioner */
        static const Flag Route;     /* mask for any route (bus or track */
        static const Flag Track;     /* mask to use for any track */
@@ -142,6 +143,7 @@ class LIBARDOUR_API PresentationInfo : public PBD::Stateful
 
        static const order_t max_order;
 
+       PresentationInfo::Flag flags() const { return _flags; }
        order_t  order() const { return _order; }
        color_t  color() const { return _color; }
 
@@ -150,8 +152,7 @@ class LIBARDOUR_API PresentationInfo : public PBD::Stateful
        void set_color (color_t);
        void set_selected (bool yn);
        void set_hidden (bool yn);
-
-       PresentationInfo::Flag flags() const { return _flags; }
+       void set_flags (Flag f) { _flags = f; }
 
        bool order_set() const { return _flags & OrderSet; }
 
@@ -159,18 +160,6 @@ class LIBARDOUR_API PresentationInfo : public PBD::Stateful
        bool selected() const { return _flags & Selected; }
        bool special() const { return _flags & (MasterOut|MonitorOut|Auditioner); }
 
-       void set_flag (PresentationInfo::Flag f) {
-               _flags = PresentationInfo::Flag (_flags | f);
-       }
-
-       void unset_flag (PresentationInfo::Flag f) {
-               _flags = PresentationInfo::Flag (_flags & ~f);
-       }
-
-       void set_flags (Flag f) {
-               _flags = f;
-       }
-
        bool flag_match (Flag f) const {
                /* no flags, match all */
 
@@ -209,6 +198,13 @@ class LIBARDOUR_API PresentationInfo : public PBD::Stateful
                        return true;
                }
 
+               if (f == AllStripables && (_flags & AllStripables)) {
+                       /* any kind of stripable, but not auditioner. Ask for that
+                          specifically.
+                       */
+                       return true;
+               }
+
                /* compare without status mask - we already checked that above 
                 */
 
@@ -218,14 +214,6 @@ class LIBARDOUR_API PresentationInfo : public PBD::Stateful
        int set_state (XMLNode const&, int);
        XMLNode& get_state ();
 
-       bool operator< (PresentationInfo const& other) const {
-               return order() < other.order();
-       }
-
-       bool match (PresentationInfo const& other) const {
-               return (_order == other.order()) && flag_match (other.flags());
-       }
-
        bool operator==(PresentationInfo const& other) {
                return (_order == other.order()) && (_flags == other.flags());
        }
index 5447d8322b942e5135c495517dac0b31c4dc8b2c..8ad02c98b3cb1be00bbfd5e4efd8fa94cedd9306 100644 (file)
@@ -79,6 +79,12 @@ class LIBARDOUR_API Stripable : public SessionObject {
        void  set_presentation_order (PresentationInfo::order_t, bool notify_class_listeners = true);
        void  set_presentation_order_explicit (PresentationInfo::order_t);
 
+       struct PresentationOrderSorter {
+               bool operator() (boost::shared_ptr<Stripable> a, boost::shared_ptr<Stripable> b) {
+                       return a->presentation_info().order() < b->presentation_info().order();
+               }
+       };
+
        /* gui's call this for their own purposes. */
 
        PBD::Signal2<void,std::string,void*> gui_changed;
@@ -179,13 +185,6 @@ class LIBARDOUR_API Stripable : public SessionObject {
        PresentationInfo _presentation_info;
 };
 
-struct PresentationInfoSorter {
-       bool operator() (boost::shared_ptr<Stripable> a, boost::shared_ptr<Stripable> b) {
-               return a->presentation_info() < b->presentation_info();
-       }
-};
-
-
 }
 
 #endif /* __libardour_stripable_h__ */
index cfed463d83b7e5f5fea76fce05583a0a70c2b29c..4fdbd4111aaa2ccf5859c2110316655a7096e172 100644 (file)
@@ -52,6 +52,7 @@ const PresentationInfo::Flag PresentationInfo::Bus = PresentationInfo::Flag (Pre
 const PresentationInfo::Flag PresentationInfo::Track = PresentationInfo::Flag (PresentationInfo::AudioTrack|PresentationInfo::MidiTrack);
 const PresentationInfo::Flag PresentationInfo::Route = PresentationInfo::Flag (PresentationInfo::Bus|PresentationInfo::Track);
 const PresentationInfo::Flag PresentationInfo::AllRoutes = PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::MasterOut|PresentationInfo::MonitorOut);
+const PresentationInfo::Flag PresentationInfo::AllStripables = PresentationInfo::Flag (PresentationInfo::AllRoutes|PresentationInfo::VCA);
 
 void
 PresentationInfo::make_property_quarks ()
index 6b8c7f3ed86ce468f85adaf0b80530e8f2bb0c42..88c958495ee3e38e627f442472690c4cea43124e 100644 (file)
@@ -4225,11 +4225,23 @@ Session::get_remote_nth_route (PresentationInfo::order_t n) const
        return boost::dynamic_pointer_cast<Route> (get_remote_nth_stripable (n, PresentationInfo::Route));
 }
 
-struct GlobalPresentationOrderSorter {
-       bool operator() (boost::shared_ptr<Stripable> a, boost::shared_ptr<Stripable> b) {
-               return a->presentation_info() < b->presentation_info();
+boost::shared_ptr<Stripable>
+Session::get_nth_stripable (PresentationInfo::order_t n) const
+{
+       StripableList sl;
+
+       get_stripables (sl);
+
+       for (StripableList::const_iterator s = sl.begin(); s != sl.end(); ++s) {
+               if ((*s)->presentation_info().order() == n) {
+                       return *s;
+               }
        }
-};
+
+       /* there is no nth stripable */
+
+       return boost::shared_ptr<Stripable>();
+}
 
 boost::shared_ptr<Stripable>
 Session::get_remote_nth_stripable (PresentationInfo::order_t n, PresentationInfo::Flag flags) const
@@ -4238,7 +4250,7 @@ Session::get_remote_nth_stripable (PresentationInfo::order_t n, PresentationInfo
        PresentationInfo::order_t match_cnt = 0;
 
        get_stripables (sl);
-       sl.sort (GlobalPresentationOrderSorter());
+       sl.sort (Stripable::PresentationOrderSorter());
 
        for (StripableList::const_iterator s = sl.begin(); s != sl.end(); ++s) {
                if ((*s)->presentation_info().flag_match (flags)) {
@@ -5370,7 +5382,7 @@ Session::RoutePublicOrderSorter::operator() (boost::shared_ptr<Route> a, boost::
        if (b->is_monitor()) {
                return false;
        }
-       return a->presentation_info() < b->presentation_info();
+       return a->presentation_info().order() < b->presentation_info().order();
 }
 
 bool
index f3a8d7dd81bd58d2e538535406b7cd8fdbc4eaa8..e53970840b36399fbda788633fc35394a71db125 100644 (file)
@@ -338,21 +338,24 @@ Session::mmc_shuttle (MIDI::MachineControl &/*mmc*/, float speed, bool forw)
 boost::shared_ptr<Route>
 Session::get_midi_nth_route_by_id (PresentationInfo::order_t n) const
 {
-       PresentationInfo id (PresentationInfo::Flag (0));
+       PresentationInfo::Flag f;
 
        if (n == 318) {
-               id.set_flags (PresentationInfo::MasterOut);
+               f = PresentationInfo::MasterOut;
        } else if (n == 319) {
-               id.set_flags (PresentationInfo::MonitorOut);
+               f = PresentationInfo::MonitorOut;
        } else {
-               id = PresentationInfo (n, PresentationInfo::Route);
+               f = PresentationInfo::Route;
        }
 
        boost::shared_ptr<RouteList> r = routes.reader ();
+       PresentationInfo::order_t match_cnt = 0;
 
        for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
-               if ((*i)->presentation_info().match (id)) {
-                       return *i;
+               if ((*i)->presentation_info().flag_match (f)) {
+                       if (match_cnt++ == n) {
+                               return *i;
+                       }
                }
        }
 
index 86af49cc09a682d63404a81c4b383428bd1638bc..40897761df6b55429d64dc62c20174abda34c36f 100644 (file)
@@ -246,17 +246,17 @@ struct StripableByPresentationOrder
 {
        bool operator () (const boost::shared_ptr<Stripable> & a, const boost::shared_ptr<Stripable> & b) const
        {
-               return a->presentation_info() < b->presentation_info();
+               return a->presentation_info().order() < b->presentation_info().order();
        }
 
        bool operator () (const Stripable & a, const Stripable & b) const
        {
-               return a.presentation_info() < b.presentation_info();
+               return a.presentation_info().order() < b.presentation_info().order();
        }
 
        bool operator () (const Stripable * a, const Stripable * b) const
        {
-               return a->presentation_info() < b->presentation_info();
+               return a->presentation_info().order() < b->presentation_info().order();
        }
 };