fix processed region export (track output)
[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 "export_channel_selector.h"
22
23 #include <algorithm>
24
25 #include "pbd/convert.h"
26
27 #include "ardour/audio_track.h"
28 #include "ardour/audioregion.h"
29 #include "ardour/export_channel_configuration.h"
30 #include "ardour/io.h"
31 #include "ardour/route.h"
32 #include "ardour/session.h"
33
34 #include <sstream>
35
36 #include "i18n.h"
37
38 using namespace std;
39 using namespace Glib;
40 using namespace ARDOUR;
41 using namespace PBD;
42
43 struct EditorOrderRouteSorter {
44     bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
45             return a->order_key () < b->order_key ();
46     }
47 };
48
49 PortExportChannelSelector::PortExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager) :
50   ExportChannelSelector (session, manager),
51   channels_label (_("Channels:"), Gtk::ALIGN_LEFT),
52   split_checkbox (_("Split to mono files")),
53   max_channels (20),
54   channel_view (max_channels)
55 {
56         channels_hbox.pack_start (channels_label, false, false, 0);
57         channels_hbox.pack_end (channels_spinbutton, false, false, 0);
58
59         channels_vbox.pack_start (channels_hbox, false, false, 0);
60         channels_vbox.pack_start (split_checkbox, false, false, 6);
61
62         channel_alignment.add (channel_scroller);
63         channel_alignment.set_padding (0, 0, 12, 0);
64         channel_scroller.add (channel_view);
65         channel_scroller.set_size_request (-1, 130);
66         channel_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
67
68         pack_start (channels_vbox, false, false, 0);
69         pack_start (channel_alignment, true, true, 0);
70
71         /* Channels spinbutton */
72
73         channels_spinbutton.set_digits (0);
74         channels_spinbutton.set_increments (1, 2);
75         channels_spinbutton.set_range (1, max_channels);
76         channels_spinbutton.set_value (2);
77
78         channels_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &PortExportChannelSelector::update_channel_count));
79
80         /* Other signals */
81
82         split_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &PortExportChannelSelector::update_split_state));
83         channel_view.CriticalSelectionChanged.connect (CriticalSelectionChanged.make_slot());
84
85         /* Finalize */
86
87         sync_with_manager();
88         show_all_children ();
89
90 }
91
92 PortExportChannelSelector::~PortExportChannelSelector ()
93 {
94 //      if (session) {
95 //              session->add_instant_xml (get_state(), false);
96 //      }
97 }
98
99 void
100 PortExportChannelSelector::sync_with_manager ()
101 {
102         state = manager->get_channel_configs().front();
103
104         split_checkbox.set_active (state->config->get_split());
105         channels_spinbutton.set_value (state->config->get_n_chans());
106
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 (EditorOrderRouteSorter ());
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
221         uint32_t i = 1;
222         ExportChannelConfiguration::ChannelList chan_list = config->get_channels();
223         for (ExportChannelConfiguration::ChannelList::iterator c_it = chan_list.begin(); c_it != chan_list.end(); ++c_it) {
224
225                 for (Gtk::ListStore::Children::iterator r_it = route_list->children().begin(); r_it != route_list->children().end(); ++r_it) {
226
227                         ARDOUR::PortExportChannel * pec;
228                         if (!(pec = dynamic_cast<ARDOUR::PortExportChannel *> (c_it->get()))) {
229                                 continue;
230                         }
231
232                         Glib::RefPtr<Gtk::ListStore> port_list = r_it->get_value (route_cols.port_list_col);
233                         std::set<boost::weak_ptr<AudioPort> > route_ports;
234                         std::set<boost::weak_ptr<AudioPort> > intersection;
235                         std::map<boost::weak_ptr<AudioPort>, string> port_labels;
236
237                         for (Gtk::ListStore::Children::const_iterator p_it = port_list->children().begin(); p_it != port_list->children().end(); ++p_it) {
238                                 route_ports.insert ((*p_it)->get_value (route_cols.port_cols.port));
239                                 port_labels.insert (make_pair ((*p_it)->get_value (route_cols.port_cols.port),
240                                                                (*p_it)->get_value (route_cols.port_cols.label)));
241                         }
242
243                         std::set_intersection (pec->get_ports().begin(), pec->get_ports().end(),
244                                                route_ports.begin(), route_ports.end(),
245                                                std::insert_iterator<std::set<boost::weak_ptr<AudioPort> > > (intersection, intersection.begin()));
246
247                         intersection.erase (boost::weak_ptr<AudioPort> ()); // Remove "none" selection
248
249                         if (intersection.empty()) {
250                                 continue;
251                         }
252
253                         if (!r_it->get_value (route_cols.selected)) {
254                                 r_it->set_value (route_cols.selected, true);
255
256                                 /* Set previous channels (if any) to none */
257
258                                 for (uint32_t chn = 1; chn < i; ++chn) {
259                                         r_it->set_value (route_cols.get_channel (chn).port, boost::weak_ptr<AudioPort> ());
260                                         r_it->set_value (route_cols.get_channel (chn).label, string ("(none)"));
261                                 }
262                         }
263
264                         boost::weak_ptr<AudioPort> port = *intersection.begin();
265                         std::map<boost::weak_ptr<AudioPort>, string>::iterator label_it = port_labels.find (port);
266                         string label = label_it != port_labels.end() ? label_it->second : "error";
267
268                         r_it->set_value (route_cols.get_channel (i).port, port);
269                         r_it->set_value (route_cols.get_channel (i).label, label);
270                 }
271
272                 ++i;
273         }
274 }
275
276 void
277 PortExportChannelSelector::ChannelTreeView::add_route (ARDOUR::IO * io)
278 {
279         Gtk::TreeModel::iterator iter = route_list->append();
280         Gtk::TreeModel::Row row = *iter;
281
282         row[route_cols.selected] = false;
283         row[route_cols.name] = io->name();
284         row[route_cols.io] = io;
285
286         /* Initialize port list */
287
288         Glib::RefPtr<Gtk::ListStore> port_list = Gtk::ListStore::create (route_cols.port_cols);
289         row[route_cols.port_list_col] = port_list;
290
291         uint32_t outs = io->n_ports().n_audio();
292         for (uint32_t i = 0; i < outs; ++i) {
293                 iter = port_list->append();
294                 row = *iter;
295
296                 row[route_cols.port_cols.selected] = false;
297                 row[route_cols.port_cols.port] = io->audio (i);
298
299                 std::ostringstream oss;
300                 oss << "Out-" << (i + 1);
301
302                 row[route_cols.port_cols.label] = oss.str();
303         }
304
305         iter = port_list->append();
306         row = *iter;
307
308         row[route_cols.port_cols.selected] = false;
309         row[route_cols.port_cols.port] = boost::weak_ptr<AudioPort> ();
310         row[route_cols.port_cols.label] = "(none)";
311
312 }
313
314 void
315 PortExportChannelSelector::ChannelTreeView::set_channel_count (uint32_t channels)
316 {
317         int offset = channels - n_channels;
318
319         while (offset > 0) {
320                 ++n_channels;
321
322                 std::ostringstream oss;
323                 oss << n_channels;
324
325                 /* New column */
326
327                 Gtk::TreeView::Column* column = Gtk::manage (new Gtk::TreeView::Column (oss.str()));
328
329                 Gtk::CellRendererCombo* combo_renderer = Gtk::manage (new Gtk::CellRendererCombo);
330                 combo_renderer->property_text_column() = 2;
331                 combo_renderer->property_has_entry() = false;
332                 column->pack_start (*combo_renderer);
333
334                 append_column (*column);
335
336                 column->add_attribute (combo_renderer->property_text(), route_cols.get_channel(n_channels).label);
337                 column->add_attribute (combo_renderer->property_model(), route_cols.port_list_col);
338                 column->add_attribute (combo_renderer->property_editable(), route_cols.selected);
339
340                 combo_renderer->signal_edited().connect (sigc::bind (sigc::mem_fun (*this, &PortExportChannelSelector::ChannelTreeView::update_selection_text), n_channels));
341
342                 /* put data into view */
343
344                 for (Gtk::ListStore::Children::iterator it = route_list->children().begin(); it != route_list->children().end(); ++it) {
345                         std::string label = it->get_value(route_cols.selected) ? "(none)" : "";
346                         it->set_value (route_cols.get_channel (n_channels).label, label);
347                         it->set_value (route_cols.get_channel (n_channels).port, boost::weak_ptr<AudioPort> ());
348                 }
349
350                 /* set column width */
351
352                 get_column (static_columns + n_channels - 1)->set_min_width (80);
353
354                 --offset;
355         }
356
357         while (offset < 0) {
358                 --n_channels;
359
360                 remove_column (*get_column (n_channels + static_columns));
361
362                 ++offset;
363         }
364
365         update_config ();
366 }
367
368 void
369 PortExportChannelSelector::ChannelTreeView::update_config ()
370 {
371         if (!config) { return; }
372
373         config->clear_channels();
374
375         for (uint32_t i = 1; i <= n_channels; ++i) {
376
377                 ExportChannelPtr channel (new PortExportChannel ());
378                 PortExportChannel * pec = static_cast<PortExportChannel *> (channel.get());
379
380                 for (Gtk::ListStore::Children::iterator it = route_list->children().begin(); it != route_list->children().end(); ++it) {
381                         Gtk::TreeModel::Row row = *it;
382
383                         if (!row[route_cols.selected]) {
384                                 continue;
385                         }
386
387                         boost::weak_ptr<AudioPort> weak_port = row[route_cols.get_channel (i).port];
388                         boost::shared_ptr<AudioPort> port = weak_port.lock ();
389                         if (port) {
390                                 pec->add_port (port);
391                         }
392                 }
393
394                 config->register_channel (channel);
395         }
396
397         CriticalSelectionChanged ();
398 }
399
400 void
401 PortExportChannelSelector::ChannelTreeView::update_toggle_selection (std::string const & path)
402 {
403         Gtk::TreeModel::iterator iter = get_model ()->get_iter (path);
404         bool selected = iter->get_value (route_cols.selected);
405
406         for (uint32_t i = 1; i <= n_channels; ++i) {
407
408                 if (!selected) {
409                         iter->set_value (route_cols.get_channel (i).label, std::string (""));
410                         continue;
411                 }
412
413                 iter->set_value (route_cols.get_channel (i).label, std::string("(none)"));
414                 iter->set_value (route_cols.get_channel (i).port, boost::weak_ptr<AudioPort> ());
415
416                 Glib::RefPtr<Gtk::ListStore> port_list = iter->get_value (route_cols.port_list_col);
417                 Gtk::ListStore::Children::iterator port_it;
418                 uint32_t port_number = 1;
419
420                 for (port_it = port_list->children().begin(); port_it != port_list->children().end(); ++port_it) {
421                         if (port_number == i) {
422                                 iter->set_value (route_cols.get_channel (i).label, (std::string) (*port_it)->get_value (route_cols.port_cols.label));
423                                 iter->set_value (route_cols.get_channel (i).port, (*port_it)->get_value (route_cols.port_cols.port));
424                         }
425
426                         ++port_number;
427                 }
428         }
429
430         update_config ();
431 }
432
433 void
434 PortExportChannelSelector::ChannelTreeView::update_selection_text (std::string const & path, std::string const & new_text, uint32_t channel)
435 {
436         Gtk::TreeModel::iterator iter = get_model ()->get_iter (path);
437         iter->set_value (route_cols.get_channel (channel).label, new_text);
438
439         Glib::RefPtr<Gtk::ListStore> port_list = iter->get_value (route_cols.port_list_col);
440         Gtk::ListStore::Children::iterator port_it;
441
442         for (port_it = port_list->children().begin(); port_it != port_list->children().end(); ++port_it) {
443                 std::string label = port_it->get_value (route_cols.port_cols.label);
444                 if (label == new_text) {
445                         boost::weak_ptr<AudioPort> w = (*port_it)[route_cols.port_cols.port];
446                         iter->set_value (route_cols.get_channel (channel).port, w);
447                 }
448         }
449
450         update_config ();
451 }
452
453 RegionExportChannelSelector::RegionExportChannelSelector (ARDOUR::Session * _session,
454                                                           ProfileManagerPtr manager,
455                                                           ARDOUR::AudioRegion const & region,
456                                                           ARDOUR::AudioTrack & track) :
457   ExportChannelSelector (_session, manager),
458   region (region),
459   track (track),
460   region_chans (region.n_channels()),
461   track_chans (track.n_outputs().n_audio()),
462
463   raw_button (type_group),
464   fades_button (type_group),
465   processed_button (type_group)
466 {
467         pack_start (vbox);
468
469         /* make fades+region gain be the default */
470
471         fades_button.set_active ();
472
473         raw_button.set_label (string_compose (_("Region contents without fades nor region gain (channels: %1)"), region_chans));
474         raw_button.signal_toggled ().connect (sigc::mem_fun (*this, &RegionExportChannelSelector::handle_selection));
475         vbox.pack_start (raw_button, false, false);
476
477         fades_button.set_label (string_compose (_("Region contents with fades and region gain (channels: %1)"), region_chans));
478         fades_button.signal_toggled ().connect (sigc::mem_fun (*this, &RegionExportChannelSelector::handle_selection));
479         vbox.pack_start (fades_button, false, false);
480
481         processed_button.set_label (string_compose (_("Track output (channels: %1)"), track_chans));
482         processed_button.signal_toggled ().connect (sigc::mem_fun (*this, &RegionExportChannelSelector::handle_selection));
483         vbox.pack_start (processed_button, false, false);
484
485         sync_with_manager();
486         vbox.show_all_children ();
487         show_all_children ();
488 }
489
490 void
491 RegionExportChannelSelector::sync_with_manager ()
492 {
493         state = manager->get_channel_configs().front();
494
495         if (!state) { return; }
496
497         switch (state->config->region_processing_type()) {
498         case RegionExportChannelFactory::None:
499                 // Do nothing
500                 break;
501         case RegionExportChannelFactory::Raw:
502                 raw_button.set_active (true);
503                 break;
504         case RegionExportChannelFactory::Fades:
505                 fades_button.set_active (true);
506                 break;
507         case RegionExportChannelFactory::Processed:
508                 processed_button.set_active (true);
509                 break;
510         }
511
512         handle_selection ();
513 }
514
515 void
516 RegionExportChannelSelector::handle_selection ()
517 {
518         if (!state) {
519                 return;
520         }
521
522         state->config->clear_channels ();
523
524         RegionExportChannelFactory::Type type = RegionExportChannelFactory::None;
525         if (raw_button.get_active ()) {
526                 type = RegionExportChannelFactory::Raw;
527         } else if (fades_button.get_active ()) {
528                 type = RegionExportChannelFactory::Fades;
529         } else if (processed_button.get_active ()) {
530                 type = RegionExportChannelFactory::Processed;
531         } else {
532                 CriticalSelectionChanged ();
533                 return;
534         }
535
536         factory.reset (new RegionExportChannelFactory (_session, region, track, type));
537         state->config->set_region_processing_type (type);
538
539         const size_t cc = type == RegionExportChannelFactory::Processed ? track_chans : region_chans;
540         for (size_t chan = 0; chan < cc; ++chan) {
541                 state->config->register_channel (factory->create (chan));
542         }
543
544         CriticalSelectionChanged ();
545 }
546
547 /* Track export channel selector */
548
549 TrackExportChannelSelector::TrackExportChannelSelector (ARDOUR::Session * session, ProfileManagerPtr manager)
550   : ExportChannelSelector(session, manager)
551   , track_output_button(_("Apply track/bus processing"))
552   , select_tracks_button (_("Select all tracks"))
553   , select_busses_button (_("Select all busses"))
554   , select_none_button (_("Deselect all"))
555 {
556         pack_start(main_layout);
557
558         // Options
559         options_box.pack_start(track_output_button);
560         options_box.pack_start (select_tracks_button);
561         options_box.pack_start (select_busses_button);
562         options_box.pack_start (select_none_button);
563         main_layout.pack_start(options_box, false, false);
564
565         // Track scroller
566         track_scroller.add (track_view);
567         track_scroller.set_size_request (-1, 130);
568         track_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
569         main_layout.pack_start(track_scroller);
570
571         // Track list
572         track_list = Gtk::ListStore::create (track_cols);
573         track_list->set_sort_column (track_cols.order_key, Gtk::SORT_ASCENDING);
574         track_view.set_model (track_list);
575         track_view.set_headers_visible (true);
576
577         track_view.append_column_editable (_("Export"), track_cols.selected);
578         Gtk::CellRendererToggle *toggle = dynamic_cast<Gtk::CellRendererToggle *>(track_view.get_column_cell_renderer (0));
579         toggle->set_alignment (0.0, 0.5);
580
581         toggle->signal_toggled().connect (sigc::hide (sigc::mem_fun (*this, &TrackExportChannelSelector::update_config)));
582
583         Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText);
584         text_renderer->property_editable() = false;
585         text_renderer->set_alignment (0.0, 0.5);
586
587         Gtk::TreeView::Column* column = Gtk::manage (new Gtk::TreeView::Column);
588         column->set_title (_("Track name"));
589
590         track_view.append_column  (*column);
591         column->pack_start (*text_renderer, false);
592         column->add_attribute (text_renderer->property_text(), track_cols.label);
593
594         select_tracks_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_tracks));
595         select_busses_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_busses));
596         select_none_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::select_none));
597
598         track_output_button.signal_clicked().connect (sigc::mem_fun (*this, &TrackExportChannelSelector::track_outputs_selected));
599
600         fill_list();
601
602         show_all_children ();
603 }
604
605 void
606 TrackExportChannelSelector::sync_with_manager ()
607 {
608         // TODO implement properly
609         update_config();
610 }
611
612 void
613 TrackExportChannelSelector::select_tracks ()
614 {
615         for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
616                 Gtk::TreeModel::Row row = *it;
617                 boost::shared_ptr<Route> route = row[track_cols.route];
618                 if (boost::dynamic_pointer_cast<Track> (route)) {
619                         // it's a track
620                         row[track_cols.selected] = true;
621                 }
622         }
623         update_config();
624 }
625
626 void
627 TrackExportChannelSelector::select_busses ()
628 {
629         for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
630                 Gtk::TreeModel::Row row = *it;
631                 boost::shared_ptr<Route> route = row[track_cols.route];
632                 if (!boost::dynamic_pointer_cast<Track> (route)) {
633                         // it's not a track, must be a bus
634                         row[track_cols.selected] = true;
635                 }
636         }
637         update_config();
638 }
639
640 void
641 TrackExportChannelSelector::select_none ()
642 {
643         for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
644                 Gtk::TreeModel::Row row = *it;
645                 row[track_cols.selected] = false;
646         }
647         update_config();
648 }
649
650 void
651 TrackExportChannelSelector::track_outputs_selected ()
652 {
653         update_config();
654 }
655
656 void
657 TrackExportChannelSelector::fill_list()
658 {
659         track_list->clear();
660         RouteList routes = *_session->get_routes();
661
662         for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
663                 if (!boost::dynamic_pointer_cast<Track>(*it)) {
664                         // not a track, must be a bus
665                         if ((*it)->is_master () || (*it)->is_monitor ()) {
666                                 continue;
667                         }
668                         if (!(*it)->active ()) {
669                                 // don't include inactive busses
670                                 continue;
671                         }
672
673                         // not monitor or master bus
674                         add_track (*it);
675                 }
676         }
677         for (RouteList::iterator it = routes.begin(); it != routes.end(); ++it) {
678                 if (boost::dynamic_pointer_cast<AudioTrack>(*it)) {
679                         if (!(*it)->active ()) {
680                                 // don't include inactive tracks
681                                 continue;
682                         }
683                         add_track (*it);
684                 }
685         }
686 }
687
688 void
689 TrackExportChannelSelector::add_track (boost::shared_ptr<Route> route)
690 {
691         Gtk::TreeModel::iterator iter = track_list->append();
692         Gtk::TreeModel::Row row = *iter;
693
694         row[track_cols.selected] = false;
695         row[track_cols.label] = route->name();
696         row[track_cols.route] = route;
697         row[track_cols.order_key] = route->order_key();
698 }
699
700 void
701 TrackExportChannelSelector::update_config()
702 {
703         manager->clear_channel_configs();
704
705         for (Gtk::ListStore::Children::iterator it = track_list->children().begin(); it != track_list->children().end(); ++it) {
706                 Gtk::TreeModel::Row row = *it;
707
708                 if (!row[track_cols.selected]) {
709                         continue;
710                 }
711
712                 ExportProfileManager::ChannelConfigStatePtr state = manager->add_channel_config();
713
714                 boost::shared_ptr<Route> route = row[track_cols.route];
715
716                 if (track_output_button.get_active()) {
717                         uint32_t outs = route->n_outputs().n_audio();
718                         for (uint32_t i = 0; i < outs; ++i) {
719                                 boost::shared_ptr<AudioPort> port = route->output()->audio (i);
720                                 if (port) {
721                                         ExportChannelPtr channel (new PortExportChannel ());
722                                         PortExportChannel * pec = static_cast<PortExportChannel *> (channel.get());
723                                         pec->add_port(port);
724                                         state->config->register_channel(channel);
725                                 }
726                         }
727                 } else {
728                         std::list<ExportChannelPtr> list;
729                         RouteExportChannel::create_from_route (list, route);
730                         state->config->register_channels (list);
731                 }
732
733                 state->config->set_name (route->name());
734
735         }
736
737         CriticalSelectionChanged ();
738 }