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