enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / export_channel_selector.cc
index 48f696fd35611cf8ba60945d967d19fed1d88cbe..acbed62030a7396ddb91d403f5d2f334ff8ee3d1 100644 (file)
@@ -18,8 +18,6 @@
 
 */
 
-#include "export_channel_selector.h"
-
 #include <algorithm>
 
 #include "pbd/convert.h"
 
 #include <sstream>
 
-#include "i18n.h"
+#include "export_channel_selector.h"
+#include "route_sorter.h"
+
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace Glib;
@@ -98,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);
 }
@@ -115,6 +121,8 @@ PortExportChannelSelector::fill_route_list ()
                channel_view.add_route (master);
        }
 
+       routes.sort (Stripable::PresentationOrderSorter ());
+
        for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
                if ((*it)->is_master () || (*it)->is_monitor ()) {
                        continue;
@@ -154,7 +162,7 @@ PortExportChannelSelector::RouteCols::Channel &
 PortExportChannelSelector::RouteCols::get_channel (uint32_t channel)
 {
        if (channel > n_channels) {
-               std::cout << "Invalid channel cout for get_channel!" << std::endl;
+               std::cout << "Invalid channel count for get_channel!" << std::endl;
        }
 
        std::list<Channel>::iterator it = channels.begin();
@@ -179,16 +187,21 @@ PortExportChannelSelector::ChannelTreeView::ChannelTreeView (uint32_t max_channe
 
        /* Add column with toggle and text */
 
-       append_column_editable (_("Bus or Track"), route_cols.selected);
+       append_column_editable (_("Export"), route_cols.selected);
 
        Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText);
        text_renderer->property_editable() = false;
+       text_renderer->set_alignment (0.0, 0.5);
 
-       Gtk::TreeView::Column* column = get_column (0);
+       Gtk::TreeView::Column* column = Gtk::manage (new Gtk::TreeView::Column);
+       column->set_title (_("Bus or Track"));
        column->pack_start (*text_renderer);
+       column->set_expand (true);
        column->add_attribute (text_renderer->property_text(), route_cols.name);
+       append_column  (*column);
 
        Gtk::CellRendererToggle *toggle = dynamic_cast<Gtk::CellRendererToggle *>(get_column_cell_renderer (0));
+       toggle->set_alignment (0.0, 0.5);
        toggle->signal_toggled().connect (sigc::mem_fun (*this, &PortExportChannelSelector::ChannelTreeView::update_toggle_selection));
 
        static_columns = get_columns().size();
@@ -204,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();
@@ -315,6 +329,7 @@ PortExportChannelSelector::ChannelTreeView::set_channel_count (uint32_t channels
 
                Gtk::CellRendererCombo* combo_renderer = Gtk::manage (new Gtk::CellRendererCombo);
                combo_renderer->property_text_column() = 2;
+               combo_renderer->property_has_entry() = false;
                column->pack_start (*combo_renderer);
 
                append_column (*column);
@@ -522,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));
        }
 
@@ -533,14 +549,18 @@ RegionExportChannelSelector::handle_selection ()
 
 TrackExportChannelSelector::TrackExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager)
   : ExportChannelSelector(session, manager)
-  , region_contents_button(source_group, _("Export region contents"))
-  , track_output_button(source_group, _("Export track output"))
+  , track_output_button(_("Apply track/bus processing"))
+  , select_tracks_button (_("Select all tracks"))
+  , select_busses_button (_("Select all busses"))
+  , select_none_button (_("Deselect all"))
 {
        pack_start(main_layout);
 
        // Options
-       options_box.pack_start(region_contents_button);
        options_box.pack_start(track_output_button);
+       options_box.pack_start (select_tracks_button);
+       options_box.pack_start (select_busses_button);
+       options_box.pack_start (select_none_button);
        main_layout.pack_start(options_box, false, false);
 
        // Track scroller
@@ -572,6 +592,12 @@ TrackExportChannelSelector::TrackExportChannelSelector (ARDOUR::Session * sessio
        column->pack_start (*text_renderer, false);
        column->add_attribute (text_renderer->property_text(), track_cols.label);
 
+       select_tracks_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_tracks));
+       select_busses_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_busses));
+       select_none_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_none));
+
+       track_output_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::track_outputs_selected));
+
        fill_list();
 
        show_all_children ();
@@ -584,6 +610,50 @@ TrackExportChannelSelector::sync_with_manager ()
        update_config();
 }
 
+void
+TrackExportChannelSelector::select_tracks ()
+{
+       for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
+               Gtk::TreeModel::Row row = *it;
+               boost::shared_ptr<Route> route = row[track_cols.route];
+               if (boost::dynamic_pointer_cast<Track> (route)) {
+                       // it's a track
+                       row[track_cols.selected] = true;
+               }
+       }
+       update_config();
+}
+
+void
+TrackExportChannelSelector::select_busses ()
+{
+       for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
+               Gtk::TreeModel::Row row = *it;
+               boost::shared_ptr<Route> route = row[track_cols.route];
+               if (!boost::dynamic_pointer_cast<Track> (route)) {
+                       // it's not a track, must be a bus
+                       row[track_cols.selected] = true;
+               }
+       }
+       update_config();
+}
+
+void
+TrackExportChannelSelector::select_none ()
+{
+       for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
+               Gtk::TreeModel::Row row = *it;
+               row[track_cols.selected] = false;
+       }
+       update_config();
+}
+
+void
+TrackExportChannelSelector::track_outputs_selected ()
+{
+       update_config();
+}
+
 void
 TrackExportChannelSelector::fill_list()
 {
@@ -596,12 +666,21 @@ TrackExportChannelSelector::fill_list()
                        if ((*it)->is_master () || (*it)->is_monitor ()) {
                                continue;
                        }
+                       if (!(*it)->active ()) {
+                               // don't include inactive busses
+                               continue;
+                       }
+
                        // not monitor or master bus
                        add_track (*it);
                }
        }
        for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
                if (boost::dynamic_pointer_cast<AudioTrack>(*it)) {
+                       if (!(*it)->active ()) {
+                               // don't include inactive tracks
+                               continue;
+                       }
                        add_track (*it);
                }
        }
@@ -613,10 +692,10 @@ TrackExportChannelSelector::add_track (boost::shared_ptr<Route> route)
        Gtk::TreeModel::iterator iter = track_list->append();
        Gtk::TreeModel::Row row = *iter;
 
-       row[track_cols.selected] = true;
+       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
@@ -631,7 +710,7 @@ TrackExportChannelSelector::update_config()
                        continue;
                }
 
-               ExportProfileManager::ChannelConfigStatePtr state = manager->add_channel_config();
+               ExportProfileManager::ChannelConfigStatePtr state;
 
                boost::shared_ptr<Route> route = row[track_cols.route];
 
@@ -643,16 +722,26 @@ TrackExportChannelSelector::update_config()
                                        ExportChannelPtr channel (new PortExportChannel ());
                                        PortExportChannel * pec = static_cast<PortExportChannel *> (channel.get());
                                        pec->add_port(port);
+                                       if (!state) {
+                                               state = manager->add_channel_config();
+                                       }
                                        state->config->register_channel(channel);
                                }
                        }
                } else {
                        std::list<ExportChannelPtr> list;
                        RouteExportChannel::create_from_route (list, route);
+                       if (list.size () == 0) {
+                               continue;
+                       }
+                       state = manager->add_channel_config();
                        state->config->register_channels (list);
                }
 
-               state->config->set_name (route->name());
+               if (state) {
+                       state->config->set_name (route->name());
+               }
+
        }
 
        CriticalSelectionChanged ();