first vaguely working version using PresentationInfo
[ardour.git] / gtk2_ardour / export_channel_selector.cc
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include <algorithm>
22
23 #include "pbd/convert.h"
24
25 #include "ardour/audio_track.h"
26 #include "ardour/audioregion.h"
27 #include "ardour/export_channel_configuration.h"
28 #include "ardour/io.h"
29 #include "ardour/route.h"
30 #include "ardour/session.h"
31
32 #include <sstream>
33
34 #include "export_channel_selector.h"
35 #include "route_sorter.h"
36
37 #include "i18n.h"
38
39 using namespace std;
40 using namespace Glib;
41 using namespace ARDOUR;
42 using namespace PBD;
43
44 PortExportChannelSelector::PortExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager) :
45   ExportChannelSelector (session, manager),
46   channels_label (_("Channels:"), Gtk::ALIGN_LEFT),
47   split_checkbox (_("Split to mono files")),
48   max_channels (20),
49   channel_view (max_channels)
50 {
51         channels_hbox.pack_start (channels_label, false, false, 0);
52         channels_hbox.pack_end (channels_spinbutton, false, false, 0);
53
54         channels_vbox.pack_start (channels_hbox, false, false, 0);
55         channels_vbox.pack_start (split_checkbox, false, false, 6);
56
57         channel_alignment.add (channel_scroller);
58         channel_alignment.set_padding (0, 0, 12, 0);
59         channel_scroller.add (channel_view);
60         channel_scroller.set_size_request (-1, 130);
61         channel_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
62
63         pack_start (channels_vbox, false, false, 0);
64         pack_start (channel_alignment, true, true, 0);
65
66         /* Channels spinbutton */
67
68         channels_spinbutton.set_digits (0);
69         channels_spinbutton.set_increments (1, 2);
70         channels_spinbutton.set_range (1, max_channels);
71         channels_spinbutton.set_value (2);
72
73         channels_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &PortExportChannelSelector::update_channel_count));
74
75         /* Other signals */
76
77         split_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &PortExportChannelSelector::update_split_state));
78         channel_view.CriticalSelectionChanged.connect (CriticalSelectionChanged.make_slot());
79
80         /* Finalize */
81
82         sync_with_manager();
83         show_all_children ();
84
85 }
86
87 PortExportChannelSelector::~PortExportChannelSelector ()
88 {
89 //      if (session) {
90 //              session->add_instant_xml (get_state(), false);
91 //      }
92 }
93
94 void
95 PortExportChannelSelector::sync_with_manager ()
96 {
97         state = manager->get_channel_configs().front();
98
99         split_checkbox.set_active (state->config->get_split());
100         channels_spinbutton.set_value (state->config->get_n_chans());
101
102         /* when loading presets, config is ready set here (shared ptr)
103          * fill_route_list () -> update_channel_count () -> set_channel_count () -> update_config()
104          * will call config->clear_channels(); and clear the config
105          */
106         channel_view.set_config (ChannelConfigPtr ());
107         fill_route_list ();
108         channel_view.set_config (state->config);
109 }
110
111 void
112 PortExportChannelSelector::fill_route_list ()
113 {
114         channel_view.clear_routes ();
115         RouteList routes = *_session->get_routes();
116
117         /* Add master bus and then everything else */
118
119         if (_session->master_out()) {
120                 ARDOUR::IO* master = _session->master_out()->output().get();
121                 channel_view.add_route (master);
122         }
123
124         routes.sort (PresentationInfoSorter ());
125
126         for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
127                 if ((*it)->is_master () || (*it)->is_monitor ()) {
128                         continue;
129                 }
130                 channel_view.add_route ((*it)->output().get());
131         }
132
133         update_channel_count ();
134 }
135
136 void
137 PortExportChannelSelector::update_channel_count ()
138 {
139         uint32_t chans = static_cast<uint32_t> (channels_spinbutton.get_value());
140         channel_view.set_channel_count (chans);
141         CriticalSelectionChanged();
142 }
143
144 void
145 PortExportChannelSelector::update_split_state ()
146 {
147         state->config->set_split (split_checkbox.get_active());
148         CriticalSelectionChanged();
149 }
150
151 void
152 PortExportChannelSelector::RouteCols::add_channels (uint32_t chans)
153 {
154         while (chans > 0) {
155                 channels.push_back (Channel (*this));
156                 ++n_channels;
157                 --chans;
158         }
159 }
160
161 PortExportChannelSelector::RouteCols::Channel &
162 PortExportChannelSelector::RouteCols::get_channel (uint32_t channel)
163 {
164         if (channel > n_channels) {
165                 std::cout << "Invalid channel count for get_channel!" << std::endl;
166         }
167
168         std::list<Channel>::iterator it = channels.begin();
169
170         while (channel > 1) { // Channel count starts from one!
171                 ++it;
172                 --channel;
173         }
174
175         return *it;
176 }
177
178 PortExportChannelSelector::ChannelTreeView::ChannelTreeView (uint32_t max_channels) :
179   n_channels (0)
180 {
181         /* Main columns */
182
183         route_cols.add_channels (max_channels);
184
185         route_list = Gtk::ListStore::create(route_cols);
186         set_model (route_list);
187
188         /* Add column with toggle and text */
189
190         append_column_editable (_("Export"), route_cols.selected);
191
192         Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText);
193         text_renderer->property_editable() = false;
194         text_renderer->set_alignment (0.0, 0.5);
195
196         Gtk::TreeView::Column* column = Gtk::manage (new Gtk::TreeView::Column);
197         column->set_title (_("Bus or Track"));
198         column->pack_start (*text_renderer);
199         column->set_expand (true);
200         column->add_attribute (text_renderer->property_text(), route_cols.name);
201         append_column  (*column);
202
203         Gtk::CellRendererToggle *toggle = dynamic_cast<Gtk::CellRendererToggle *>(get_column_cell_renderer (0));
204         toggle->set_alignment (0.0, 0.5);
205         toggle->signal_toggled().connect (sigc::mem_fun (*this, &PortExportChannelSelector::ChannelTreeView::update_toggle_selection));
206
207         static_columns = get_columns().size();
208 }
209
210 void
211 PortExportChannelSelector::ChannelTreeView::set_config (ChannelConfigPtr c)
212 {
213         /* TODO Without the following line, the state might get reset.
214          * Pointing to the same address does not mean the state of the configuration hasn't changed.
215          * In the current code this is safe, but the actual cause of the problem would be good to fix
216          */
217
218         if (config == c) { return; }
219         config = c;
220         if (!config) { return; }
221
222         uint32_t i = 1;
223         ExportChannelConfiguration::ChannelList chan_list = config->get_channels();
224         for (ExportChannelConfiguration::ChannelList::iterator c_it = chan_list.begin(); c_it != chan_list.end(); ++c_it) {
225
226                 for (Gtk::ListStore::Children::iterator r_it = route_list->children().begin(); r_it != route_list->children().end(); ++r_it) {
227
228                         ARDOUR::PortExportChannel * pec;
229                         if (!(pec = dynamic_cast<ARDOUR::PortExportChannel *> (c_it->get()))) {
230                                 continue;
231                         }
232
233                         Glib::RefPtr<Gtk::ListStore> port_list = r_it->get_value (route_cols.port_list_col);
234                         std::set<boost::weak_ptr<AudioPort> > route_ports;
235                         std::set<boost::weak_ptr<AudioPort> > intersection;
236                         std::map<boost::weak_ptr<AudioPort>, string> port_labels;
237
238                         for (Gtk::ListStore::Children::const_iterator p_it = port_list->children().begin(); p_it != port_list->children().end(); ++p_it) {
239                                 route_ports.insert ((*p_it)->get_value (route_cols.port_cols.port));
240                                 port_labels.insert (make_pair ((*p_it)->get_value (route_cols.port_cols.port),
241                                                                (*p_it)->get_value (route_cols.port_cols.label)));
242                         }
243
244                         std::set_intersection (pec->get_ports().begin(), pec->get_ports().end(),
245                                                route_ports.begin(), route_ports.end(),
246                                                std::insert_iterator<std::set<boost::weak_ptr<AudioPort> > > (intersection, intersection.begin()));
247
248                         intersection.erase (boost::weak_ptr<AudioPort> ()); // Remove "none" selection
249
250                         if (intersection.empty()) {
251                                 continue;
252                         }
253
254                         if (!r_it->get_value (route_cols.selected)) {
255                                 r_it->set_value (route_cols.selected, true);
256
257                                 /* Set previous channels (if any) to none */
258
259                                 for (uint32_t chn = 1; chn < i; ++chn) {
260                                         r_it->set_value (route_cols.get_channel (chn).port, boost::weak_ptr<AudioPort> ());
261                                         r_it->set_value (route_cols.get_channel (chn).label, string ("(none)"));
262                                 }
263                         }
264
265                         boost::weak_ptr<AudioPort> port = *intersection.begin();
266                         std::map<boost::weak_ptr<AudioPort>, string>::iterator label_it = port_labels.find (port);
267                         string label = label_it != port_labels.end() ? label_it->second : "error";
268
269                         r_it->set_value (route_cols.get_channel (i).port, port);
270                         r_it->set_value (route_cols.get_channel (i).label, label);
271                 }
272
273                 ++i;
274         }
275 }
276
277 void
278 PortExportChannelSelector::ChannelTreeView::add_route (ARDOUR::IO * io)
279 {
280         Gtk::TreeModel::iterator iter = route_list->append();
281         Gtk::TreeModel::Row row = *iter;
282
283         row[route_cols.selected] = false;
284         row[route_cols.name] = io->name();
285         row[route_cols.io] = io;
286
287         /* Initialize port list */
288
289         Glib::RefPtr<Gtk::ListStore> port_list = Gtk::ListStore::create (route_cols.port_cols);
290         row[route_cols.port_list_col] = port_list;
291
292         uint32_t outs = io->n_ports().n_audio();
293         for (uint32_t i = 0; i < outs; ++i) {
294                 iter = port_list->append();
295                 row = *iter;
296
297                 row[route_cols.port_cols.selected] = false;
298                 row[route_cols.port_cols.port] = io->audio (i);
299
300                 std::ostringstream oss;
301                 oss << "Out-" << (i + 1);
302
303                 row[route_cols.port_cols.label] = oss.str();
304         }
305
306         iter = port_list->append();
307         row = *iter;
308
309         row[route_cols.port_cols.selected] = false;
310         row[route_cols.port_cols.port] = boost::weak_ptr<AudioPort> ();
311         row[route_cols.port_cols.label] = "(none)";
312
313 }
314
315 void
316 PortExportChannelSelector::ChannelTreeView::set_channel_count (uint32_t channels)
317 {
318         int offset = channels - n_channels;
319
320         while (offset > 0) {
321                 ++n_channels;
322
323                 std::ostringstream oss;
324                 oss << n_channels;
325
326                 /* New column */
327
328                 Gtk::TreeView::Column* column = Gtk::manage (new Gtk::TreeView::Column (oss.str()));
329
330                 Gtk::CellRendererCombo* combo_renderer = Gtk::manage (new Gtk::CellRendererCombo);
331                 combo_renderer->property_text_column() = 2;
332                 combo_renderer->property_has_entry() = false;
333                 column->pack_start (*combo_renderer);
334
335                 append_column (*column);
336
337                 column->add_attribute (combo_renderer->property_text(), route_cols.get_channel(n_channels).label);
338                 column->add_attribute (combo_renderer->property_model(), route_cols.port_list_col);
339                 column->add_attribute (combo_renderer->property_editable(), route_cols.selected);
340
341                 combo_renderer->signal_edited().connect (sigc::bind (sigc::mem_fun (*this, &PortExportChannelSelector::ChannelTreeView::update_selection_text), n_channels));
342
343                 /* put data into view */
344
345                 for (Gtk::ListStore::Children::iterator it = route_list->children().begin(); it != route_list->children().end(); ++it) {
346                         std::string label = it->get_value(route_cols.selected) ? "(none)" : "";
347                         it->set_value (route_cols.get_channel (n_channels).label, label);
348                         it->set_value (route_cols.get_channel (n_channels).port, boost::weak_ptr<AudioPort> ());
349                 }
350
351                 /* set column width */
352
353                 get_column (static_columns + n_channels - 1)->set_min_width (80);
354
355                 --offset;
356         }
357
358         while (offset < 0) {
359                 --n_channels;
360
361                 remove_column (*get_column (n_channels + static_columns));
362
363                 ++offset;
364         }
365
366         update_config ();
367 }
368
369 void
370 PortExportChannelSelector::ChannelTreeView::update_config ()
371 {
372         if (!config) { return; }
373
374         config->clear_channels();
375
376         for (uint32_t i = 1; i <= n_channels; ++i) {
377
378                 ExportChannelPtr channel (new PortExportChannel ());
379                 PortExportChannel * pec = static_cast<PortExportChannel *> (channel.get());
380
381                 for (Gtk::ListStore::Children::iterator it = route_list->children().begin(); it != route_list->children().end(); ++it) {
382                         Gtk::TreeModel::Row row = *it;
383
384                         if (!row[route_cols.selected]) {
385                                 continue;
386                         }
387
388                         boost::weak_ptr<AudioPort> weak_port = row[route_cols.get_channel (i).port];
389                         boost::shared_ptr<AudioPort> port = weak_port.lock ();
390                         if (port) {
391                                 pec->add_port (port);
392                         }
393                 }
394
395                 config->register_channel (channel);
396         }
397
398         CriticalSelectionChanged ();
399 }
400
401 void
402 PortExportChannelSelector::ChannelTreeView::update_toggle_selection (std::string const & path)
403 {
404         Gtk::TreeModel::iterator iter = get_model ()->get_iter (path);
405         bool selected = iter->get_value (route_cols.selected);
406
407         for (uint32_t i = 1; i <= n_channels; ++i) {
408
409                 if (!selected) {
410                         iter->set_value (route_cols.get_channel (i).label, std::string (""));
411                         continue;
412                 }
413
414                 iter->set_value (route_cols.get_channel (i).label, std::string("(none)"));
415                 iter->set_value (route_cols.get_channel (i).port, boost::weak_ptr<AudioPort> ());
416
417                 Glib::RefPtr<Gtk::ListStore> port_list = iter->get_value (route_cols.port_list_col);
418                 Gtk::ListStore::Children::iterator port_it;
419                 uint32_t port_number = 1;
420
421                 for (port_it = port_list->children().begin(); port_it != port_list->children().end(); ++port_it) {
422                         if (port_number == i) {
423                                 iter->set_value (route_cols.get_channel (i).label, (std::string) (*port_it)->get_value (route_cols.port_cols.label));
424                                 iter->set_value (route_cols.get_channel (i).port, (*port_it)->get_value (route_cols.port_cols.port));
425                         }
426
427                         ++port_number;
428                 }
429         }
430
431         update_config ();
432 }
433
434 void
435 PortExportChannelSelector::ChannelTreeView::update_selection_text (std::string const & path, std::string const & new_text, uint32_t channel)
436 {
437         Gtk::TreeModel::iterator iter = get_model ()->get_iter (path);
438         iter->set_value (route_cols.get_channel (channel).label, new_text);
439
440         Glib::RefPtr<Gtk::ListStore> port_list = iter->get_value (route_cols.port_list_col);
441         Gtk::ListStore::Children::iterator port_it;
442
443         for (port_it = port_list->children().begin(); port_it != port_list->children().end(); ++port_it) {
444                 std::string label = port_it->get_value (route_cols.port_cols.label);
445                 if (label == new_text) {
446                         boost::weak_ptr<AudioPort> w = (*port_it)[route_cols.port_cols.port];
447                         iter->set_value (route_cols.get_channel (channel).port, w);
448                 }
449         }
450
451         update_config ();
452 }
453
454 RegionExportChannelSelector::RegionExportChannelSelector (ARDOUR::Session * _session,
455                                                           ProfileManagerPtr manager,
456                                                           ARDOUR::AudioRegion const & region,
457                                                           ARDOUR::AudioTrack & track) :
458   ExportChannelSelector (_session, manager),
459   region (region),
460   track (track),
461   region_chans (region.n_channels()),
462   track_chans (track.n_outputs().n_audio()),
463
464   raw_button (type_group),
465   fades_button (type_group),
466   processed_button (type_group)
467 {
468         pack_start (vbox);
469
470         /* make fades+region gain be the default */
471
472         fades_button.set_active ();
473
474         raw_button.set_label (string_compose (_("Region contents without fades nor region gain (channels: %1)"), region_chans));
475         raw_button.signal_toggled ().connect (sigc::mem_fun (*this, &RegionExportChannelSelector::handle_selection));
476         vbox.pack_start (raw_button, false, false);
477
478         fades_button.set_label (string_compose (_("Region contents with fades and region gain (channels: %1)"), region_chans));
479         fades_button.signal_toggled ().connect (sigc::mem_fun (*this, &RegionExportChannelSelector::handle_selection));
480         vbox.pack_start (fades_button, false, false);
481
482         processed_button.set_label (string_compose (_("Track output (channels: %1)"), track_chans));
483         processed_button.signal_toggled ().connect (sigc::mem_fun (*this, &RegionExportChannelSelector::handle_selection));
484         vbox.pack_start (processed_button, false, false);
485
486         sync_with_manager();
487         vbox.show_all_children ();
488         show_all_children ();
489 }
490
491 void
492 RegionExportChannelSelector::sync_with_manager ()
493 {
494         state = manager->get_channel_configs().front();
495
496         if (!state) { return; }
497
498         switch (state->config->region_processing_type()) {
499         case RegionExportChannelFactory::None:
500                 // Do nothing
501                 break;
502         case RegionExportChannelFactory::Raw:
503                 raw_button.set_active (true);
504                 break;
505         case RegionExportChannelFactory::Fades:
506                 fades_button.set_active (true);
507                 break;
508         case RegionExportChannelFactory::Processed:
509                 processed_button.set_active (true);
510                 break;
511         }
512
513         handle_selection ();
514 }
515
516 void
517 RegionExportChannelSelector::handle_selection ()
518 {
519         if (!state) {
520                 return;
521         }
522
523         state->config->clear_channels ();
524
525         RegionExportChannelFactory::Type type = RegionExportChannelFactory::None;
526         if (raw_button.get_active ()) {
527                 type = RegionExportChannelFactory::Raw;
528         } else if (fades_button.get_active ()) {
529                 type = RegionExportChannelFactory::Fades;
530         } else if (processed_button.get_active ()) {
531                 type = RegionExportChannelFactory::Processed;
532         } else {
533                 CriticalSelectionChanged ();
534                 return;
535         }
536
537         factory.reset (new RegionExportChannelFactory (_session, region, track, type));
538         state->config->set_region_processing_type (type);
539
540         const size_t cc = type == RegionExportChannelFactory::Processed ? track_chans : region_chans;
541         for (size_t chan = 0; chan < cc; ++chan) {
542                 state->config->register_channel (factory->create (chan));
543         }
544
545         CriticalSelectionChanged ();
546 }
547
548 /* Track export channel selector */
549
550 TrackExportChannelSelector::TrackExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager)
551   : ExportChannelSelector(session, manager)
552   , track_output_button(_("Apply track/bus processing"))
553   , select_tracks_button (_("Select all tracks"))
554   , select_busses_button (_("Select all busses"))
555   , select_none_button (_("Deselect all"))
556 {
557         pack_start(main_layout);
558
559         // Options
560         options_box.pack_start(track_output_button);
561         options_box.pack_start (select_tracks_button);
562         options_box.pack_start (select_busses_button);
563         options_box.pack_start (select_none_button);
564         main_layout.pack_start(options_box, false, false);
565
566         // Track scroller
567         track_scroller.add (track_view);
568         track_scroller.set_size_request (-1, 130);
569         track_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
570         main_layout.pack_start(track_scroller);
571
572         // Track list
573         track_list = Gtk::ListStore::create (track_cols);
574         track_list->set_sort_column (track_cols.order_key, Gtk::SORT_ASCENDING);
575         track_view.set_model (track_list);
576         track_view.set_headers_visible (true);
577
578         track_view.append_column_editable (_("Export"), track_cols.selected);
579         Gtk::CellRendererToggle *toggle = dynamic_cast<Gtk::CellRendererToggle *>(track_view.get_column_cell_renderer (0));
580         toggle->set_alignment (0.0, 0.5);
581
582         toggle->signal_toggled().connect (sigc::hide (sigc::mem_fun (*this, &TrackExportChannelSelector::update_config)));
583
584         Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText);
585         text_renderer->property_editable() = false;
586         text_renderer->set_alignment (0.0, 0.5);
587
588         Gtk::TreeView::Column* column = Gtk::manage (new Gtk::TreeView::Column);
589         column->set_title (_("Track name"));
590
591         track_view.append_column  (*column);
592         column->pack_start (*text_renderer, false);
593         column->add_attribute (text_renderer->property_text(), track_cols.label);
594
595         select_tracks_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_tracks));
596         select_busses_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_busses));
597         select_none_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_none));
598
599         track_output_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::track_outputs_selected));
600
601         fill_list();
602
603         show_all_children ();
604 }
605
606 void
607 TrackExportChannelSelector::sync_with_manager ()
608 {
609         // TODO implement properly
610         update_config();
611 }
612
613 void
614 TrackExportChannelSelector::select_tracks ()
615 {
616         for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
617                 Gtk::TreeModel::Row row = *it;
618                 boost::shared_ptr<Route> route = row[track_cols.route];
619                 if (boost::dynamic_pointer_cast<Track> (route)) {
620                         // it's a track
621                         row[track_cols.selected] = true;
622                 }
623         }
624         update_config();
625 }
626
627 void
628 TrackExportChannelSelector::select_busses ()
629 {
630         for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
631                 Gtk::TreeModel::Row row = *it;
632                 boost::shared_ptr<Route> route = row[track_cols.route];
633                 if (!boost::dynamic_pointer_cast<Track> (route)) {
634                         // it's not a track, must be a bus
635                         row[track_cols.selected] = true;
636                 }
637         }
638         update_config();
639 }
640
641 void
642 TrackExportChannelSelector::select_none ()
643 {
644         for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
645                 Gtk::TreeModel::Row row = *it;
646                 row[track_cols.selected] = false;
647         }
648         update_config();
649 }
650
651 void
652 TrackExportChannelSelector::track_outputs_selected ()
653 {
654         update_config();
655 }
656
657 void
658 TrackExportChannelSelector::fill_list()
659 {
660         track_list->clear();
661         RouteList routes = *_session->get_routes();
662
663         for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
664                 if (!boost::dynamic_pointer_cast<Track>(*it)) {
665                         // not a track, must be a bus
666                         if ((*it)->is_master () || (*it)->is_monitor ()) {
667                                 continue;
668                         }
669                         if (!(*it)->active ()) {
670                                 // don't include inactive busses
671                                 continue;
672                         }
673
674                         // not monitor or master bus
675                         add_track (*it);
676                 }
677         }
678         for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
679                 if (boost::dynamic_pointer_cast<AudioTrack>(*it)) {
680                         if (!(*it)->active ()) {
681                                 // don't include inactive tracks
682                                 continue;
683                         }
684                         add_track (*it);
685                 }
686         }
687 }
688
689 void
690 TrackExportChannelSelector::add_track (boost::shared_ptr<Route> route)
691 {
692         Gtk::TreeModel::iterator iter = track_list->append();
693         Gtk::TreeModel::Row row = *iter;
694
695         row[track_cols.selected] = false;
696         row[track_cols.label] = route->name();
697         row[track_cols.route] = route;
698         row[track_cols.order_key] = route->presentation_info().global_order();
699 }
700
701 void
702 TrackExportChannelSelector::update_config()
703 {
704         manager->clear_channel_configs();
705
706         for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
707                 Gtk::TreeModel::Row row = *it;
708
709                 if (!row[track_cols.selected]) {
710                         continue;
711                 }
712
713                 ExportProfileManager::ChannelConfigStatePtr state = manager->add_channel_config();
714
715                 boost::shared_ptr<Route> route = row[track_cols.route];
716
717                 if (track_output_button.get_active()) {
718                         uint32_t outs = route->n_outputs().n_audio();
719                         for (uint32_t i = 0; i < outs; ++i) {
720                                 boost::shared_ptr<AudioPort> port = route->output()->audio (i);
721                                 if (port) {
722                                         ExportChannelPtr channel (new PortExportChannel ());
723                                         PortExportChannel * pec = static_cast<PortExportChannel *> (channel.get());
724                                         pec->add_port(port);
725                                         state->config->register_channel(channel);
726                                 }
727                         }
728                 } else {
729                         std::list<ExportChannelPtr> list;
730                         RouteExportChannel::create_from_route (list, route);
731                         state->config->register_channels (list);
732                 }
733
734                 state->config->set_name (route->name());
735
736         }
737
738         CriticalSelectionChanged ();
739 }