Use generic sorter.
[ardour.git] / gtk2_ardour / export_channel_selector.cc
index c868d698532843dcfe37a8b23b60291fe458a126..17c54c79a85b735bd77284eb2d1ec242582442df 100644 (file)
@@ -18,8 +18,6 @@
 
 */
 
-#include "export_channel_selector.h"
-
 #include <algorithm>
 
 #include "pbd/convert.h"
@@ -33,6 +31,9 @@
 
 #include <sstream>
 
+#include "export_channel_selector.h"
+#include "route_sorter.h"
+
 #include "i18n.h"
 
 using namespace std;
@@ -40,12 +41,6 @@ using namespace Glib;
 using namespace ARDOUR;
 using namespace PBD;
 
-struct EditorOrderRouteSorter {
-    bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-           return a->order_key () < b->order_key ();
-    }
-};
-
 PortExportChannelSelector::PortExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager) :
   ExportChannelSelector (session, manager),
   channels_label (_("Channels:"), Gtk::ALIGN_LEFT),
@@ -104,6 +99,11 @@ PortExportChannelSelector::sync_with_manager ()
        split_checkbox.set_active (state->config->get_split());
        channels_spinbutton.set_value (state->config->get_n_chans());
 
+       /* when loading presets, config is ready set here (shared ptr)
+        * fill_route_list () -> update_channel_count () -> set_channel_count () -> update_config()
+        * will call config->clear_channels(); and clear the config
+        */
+       channel_view.set_config (ChannelConfigPtr ());
        fill_route_list ();
        channel_view.set_config (state->config);
 }
@@ -121,7 +121,7 @@ PortExportChannelSelector::fill_route_list ()
                channel_view.add_route (master);
        }
 
-       routes.sort (EditorOrderRouteSorter ());
+       routes.sort (Stripable::PresentationOrderSorter ());
 
        for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
                if ((*it)->is_master () || (*it)->is_monitor ()) {
@@ -217,6 +217,7 @@ PortExportChannelSelector::ChannelTreeView::set_config (ChannelConfigPtr c)
 
        if (config == c) { return; }
        config = c;
+       if (!config) { return; }
 
        uint32_t i = 1;
        ExportChannelConfiguration::ChannelList chan_list = config->get_channels();
@@ -536,7 +537,8 @@ RegionExportChannelSelector::handle_selection ()
        factory.reset (new RegionExportChannelFactory (_session, region, track, type));
        state->config->set_region_processing_type (type);
 
-       for (size_t chan = 0; chan < region_chans; ++chan) {
+       const size_t cc = type == RegionExportChannelFactory::Processed ? track_chans : region_chans;
+       for (size_t chan = 0; chan < cc; ++chan) {
                state->config->register_channel (factory->create (chan));
        }
 
@@ -693,7 +695,7 @@ TrackExportChannelSelector::add_track (boost::shared_ptr<Route> route)
        row[track_cols.selected] = false;
        row[track_cols.label] = route->name();
        row[track_cols.route] = route;
-       row[track_cols.order_key] = route->order_key();
+       row[track_cols.order_key] = route->presentation_info().order();
 }
 
 void