fix mistaken "do not roll" conclusion in TransportFSM::compute_should_roll()
[ardour.git] / gtk2_ardour / export_format_dialog.cc
1 /*
2  * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
5  * Copyright (C) 2009-2013 Sakari Bergen <sakari.bergen@beatwaves.net>
6  * Copyright (C) 2013-2014 Colin Fletcher <colin.m.fletcher@googlemail.com>
7  * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include <gtkmm/stock.h>
25
26 #include "ardour/session.h"
27 #include "ardour/export_format_specification.h"
28
29 #include "widgets/tooltips.h"
30
31 #include "export_format_dialog.h"
32 #include "gui_thread.h"
33
34 #include "pbd/i18n.h"
35
36 using namespace ARDOUR;
37
38 ExportFormatDialog::ExportFormatDialog (FormatPtr format, bool new_dialog) :
39   ArdourDialog (new_dialog ? _("New Export Format Profile") : _("Edit Export Format Profile")),
40   format (format),
41   manager (format),
42   original_state (format->get_state()),
43
44   applying_changes_from_engine (0),
45
46   name_label (_("Label: "), Gtk::ALIGN_LEFT),
47   name_generated_part ("", Gtk::ALIGN_LEFT),
48
49   normalize_checkbox (_("Normalize:")),
50   normalize_peak_rb (_("Peak")),
51   normalize_loudness_rb (_("Loudness")),
52   normalize_dbfs_adjustment ( 0.00, -90.00, 0.00, 0.1, 0.2),
53   normalize_lufs_adjustment (-23.0, -90.00, 0.00, 0.1, 1.0),
54   normalize_dbtp_adjustment ( -1.0, -90.00, 0.00, 0.1, 0.2),
55
56   normalize_dbfs_label (_("dBFS"), Gtk::ALIGN_LEFT),
57   normalize_lufs_label (_("LUFS"), Gtk::ALIGN_LEFT),
58   normalize_dbtp_label (_("dBTP"), Gtk::ALIGN_LEFT),
59
60   silence_table (2, 4),
61   trim_start_checkbox (_("Trim silence at start")),
62   silence_start_checkbox (_("Add silence at start:")),
63   silence_start_clock ("silence_start", true, "", true, false, true),
64
65   trim_end_checkbox (_("Trim silence at end")),
66   silence_end_checkbox (_("Add silence at end:")),
67   silence_end_clock ("silence_end", true, "", true, false, true),
68
69   command_label(_("Command to run post-export\n(%f=file path, %d=directory, %b=basename, see tooltip for more):"), Gtk::ALIGN_LEFT),
70
71   format_table (3, 4),
72   compatibility_label (_("Compatibility"), Gtk::ALIGN_LEFT),
73   quality_label (_("Quality"), Gtk::ALIGN_LEFT),
74   format_label (_("File format"), Gtk::ALIGN_LEFT),
75   sample_rate_label (_("Sample rate"), Gtk::ALIGN_LEFT),
76   src_quality_label (_("Sample rate conversion quality:"), Gtk::ALIGN_RIGHT),
77
78   encoding_options_label ("", Gtk::ALIGN_LEFT),
79
80   /* Changing encoding options from here on */
81
82   sample_format_label (_("Sample Format"), Gtk::ALIGN_LEFT),
83   dither_label (_("Dithering"), Gtk::ALIGN_LEFT),
84
85   with_cue (_("Create CUE file for disk-at-once CD/DVD creation")),
86   with_toc (_("Create TOC file for disk-at-once CD/DVD creation")),
87   with_mp4chaps (_("Create chapter mark file for MP4 chapter marks")),
88
89   tag_checkbox (_("Tag file with session's metadata"))
90 {
91
92         /* Pack containers in dialog */
93
94         get_vbox()->pack_start (silence_table, false, false, 6);
95         get_vbox()->pack_start (format_table, false, false, 6);
96         get_vbox()->pack_start (encoding_options_vbox, false, false, 0);
97         get_vbox()->pack_start (cue_toc_vbox, false, false, 0);
98         get_vbox()->pack_start (name_hbox, false, false, 6);
99
100         /* Name, new and remove */
101
102         name_hbox.pack_start (name_label, false, false, 0);
103         name_hbox.pack_start (name_entry, false, false, 0);
104         name_hbox.pack_start (name_generated_part, true, true, 0);
105         name_entry.set_width_chars(20);
106         update_description();
107         manager.DescriptionChanged.connect(
108                 *this, invalidator (*this),
109                 boost::bind (&ExportFormatDialog::update_description, this), gui_context());
110
111         /* Normalize */
112
113         Gtk::RadioButtonGroup normalize_group = normalize_loudness_rb.get_group();
114         normalize_peak_rb.set_group (normalize_group);
115
116         normalize_hbox.pack_start (normalize_checkbox, false, false, 2);
117         normalize_hbox.pack_start (normalize_peak_rb, false, false, 0);
118         normalize_hbox.pack_start (normalize_dbfs_spinbutton, false, false, 2);
119         normalize_hbox.pack_start (normalize_dbfs_label, false, false, 0);
120
121         normalize_hbox.pack_start (*Gtk::manage (new Gtk::Label ("")), false, false, 6); // separator
122
123         normalize_hbox.pack_start (normalize_loudness_rb, false, false, 0);
124         normalize_hbox.pack_start (normalize_lufs_spinbutton, false, false, 2);
125         normalize_hbox.pack_start (normalize_lufs_label, false, false, 0);
126         normalize_hbox.pack_start (*Gtk::manage (new Gtk::Label (_("\u2227"))), false, false, 4);
127         normalize_hbox.pack_start (normalize_dbtp_spinbutton, false, false, 2);
128         normalize_hbox.pack_start (normalize_dbtp_label, false, false, 0);
129
130         ArdourWidgets::set_tooltip (normalize_loudness_rb,
131                         _("Normalize to EBU-R128 LUFS target loudness without exceeding the given true-peak limit. EBU-R128 normalization is only available for mono and stereo targets, true-peak works for any channel layout."));
132
133         normalize_dbfs_spinbutton.configure (normalize_dbfs_adjustment, 0.1, 2);
134         normalize_lufs_spinbutton.configure (normalize_lufs_adjustment, 0.1, 2);
135         normalize_dbtp_spinbutton.configure (normalize_dbtp_adjustment, 0.1, 2);
136
137         /* Silence  */
138
139         silence_table.set_row_spacings (6);
140         silence_table.set_col_spacings (12);
141
142         silence_table.attach (normalize_hbox, 0, 3, 0, 1);
143
144         silence_table.attach (trim_start_checkbox, 0, 1, 1, 2);
145         silence_table.attach (silence_start_checkbox, 1, 2, 1, 2);
146         silence_table.attach (silence_start_clock, 2, 3, 1, 2);
147
148         silence_table.attach (trim_end_checkbox, 0, 1, 2, 3);
149         silence_table.attach (silence_end_checkbox, 1, 2, 2, 3);
150         silence_table.attach (silence_end_clock, 2, 3, 2, 3);
151
152         /* Post-export hook script */
153
154         get_vbox()->pack_start (command_label, false, false);
155         get_vbox()->pack_start (command_entry, false, false);
156
157         ArdourWidgets::set_tooltip (command_entry,
158                         _(
159                                 "%a Artist name\n"
160                                 "%b File's base-name\n"
161                                 "%c Copyright\n"
162                                 "%d File's directory\n"
163                                 "%f File's full absolute path\n"
164                                 "%l Lyricist\n"
165                                 "%n Session name\n"
166                                 "%o Conductor\n"
167                                 "%t Title\n"
168                                 "%z Organization\n"
169                                 "%A Album\n"
170                                 "%C Comment\n"
171                                 "%E Engineer\n"
172                                 "%G Genre\n"
173                                 "%L Total track count\n"
174                                 "%M Mixer\n"
175                                 "%N Timespan name\n"
176                                 "%O Composer\n"
177                                 "%P Producer\n"
178                                 "%S Disc subtitle\n"
179                                 "%T Track number\n"
180                                 "%Y Year\n"
181                                 "%Z Country"
182                          ));
183
184         /* Format table */
185
186         init_format_table();
187
188         /* Encoding options */
189
190         init_encoding_option_widgets();
191
192         encoding_options_table.set_spacings (1);
193
194         encoding_options_vbox.pack_start (encoding_options_label, false, false, 0);
195         encoding_options_vbox.pack_start (encoding_options_table, false, false, 12);
196
197         Pango::AttrList bold;
198         Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
199         bold.insert (b);
200         encoding_options_label.set_attributes (bold);
201
202         /* Codec options */
203
204         codec_quality_list = Gtk::ListStore::create (codec_quality_cols);
205         codec_quality_combo.set_model (codec_quality_list);
206         codec_quality_combo.pack_start (codec_quality_cols.label);
207         //codec_quality_combo.set_active (0);
208
209         /* Buttons */
210
211         revert_button = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
212         revert_button->signal_clicked().connect (sigc::mem_fun(*this, &ExportFormatDialog::revert));
213         close_button = add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_APPLY);
214         close_button->set_sensitive (false);
215         close_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportFormatDialog::end_dialog));
216         manager.CompleteChanged.connect (*this, invalidator (*this), boost::bind (&Gtk::Button::set_sensitive, close_button, _1), gui_context());
217
218         with_cue.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_with_cue));
219         with_toc.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_with_toc));
220         with_mp4chaps.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_with_mp4chaps));
221         command_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_command));
222
223         cue_toc_vbox.pack_start (with_cue, false, false);
224         cue_toc_vbox.pack_start (with_toc, false, false);
225         cue_toc_vbox.pack_start (with_mp4chaps, false, false);
226
227         /* Load state before hooking up the rest of the signals */
228
229         load_state (format);
230
231         /* Name entry */
232
233         name_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_name));
234
235         /* Normalize, silence and src_quality signals */
236
237         trim_start_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_trim_start_selection));
238         trim_end_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_trim_end_selection));
239
240         normalize_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_normalize_selection));
241         normalize_peak_rb.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_normalize_selection));
242         normalize_loudness_rb.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_normalize_selection));
243         normalize_dbfs_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_normalize_selection));
244         normalize_lufs_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_normalize_selection));
245         normalize_dbtp_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_normalize_selection));
246
247         silence_start_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_silence_start_selection));
248         silence_start_clock.ValueChanged.connect (sigc::mem_fun (*this, &ExportFormatDialog::update_silence_start_selection));
249
250         silence_end_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_silence_end_selection));
251         silence_end_clock.ValueChanged.connect (sigc::mem_fun (*this, &ExportFormatDialog::update_silence_end_selection));
252
253         src_quality_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_src_quality_selection));
254         codec_quality_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_codec_quality_selection));
255
256         /* Format table signals */
257
258         Gtk::CellRendererToggle *toggle = dynamic_cast<Gtk::CellRendererToggle *>(compatibility_view.get_column_cell_renderer (0));
259         toggle->signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_compatibility_selection));
260         compatibility_select_connection = compatibility_view.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::prohibit_compatibility_selection));
261
262         quality_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_quality_selection));
263         format_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_format_selection));
264         sample_rate_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_sample_rate_selection));
265
266         /* Encoding option signals */
267
268         sample_format_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_sample_format_selection));
269         dither_type_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_dither_type_selection));
270
271         tag_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_tagging_selection));
272
273         /* Finalize */
274
275         show_all_children();
276         update_normalize_sensitivity ();
277 }
278
279 ExportFormatDialog::~ExportFormatDialog ()
280 {
281
282 }
283
284 void
285 ExportFormatDialog::revert ()
286 {
287         ++applying_changes_from_engine;
288
289         format->set_state (original_state);
290         load_state (format);
291
292         --applying_changes_from_engine;
293 }
294
295 void
296 ExportFormatDialog::set_session (ARDOUR::Session* s)
297 {
298         SessionHandlePtr::set_session (s);
299         silence_start_clock.set_session (s);
300         silence_end_clock.set_session (s);
301
302         if (!_session) {
303                 return;
304         }
305
306         update_clock (silence_start_clock, silence_start);
307         update_clock (silence_end_clock, silence_end);
308
309         /* Select native samplerate if no selection is yet made */
310
311         if (sample_rate_view.get_selection()->count_selected_rows() == 0) {
312                 Gtk::ListStore::Children::iterator it;
313                 for (it = sample_rate_list->children().begin(); it != sample_rate_list->children().end(); ++it) {
314                         if ((samplecnt_t) (*it)->get_value (sample_rate_cols.ptr)->rate == _session->nominal_sample_rate()) {
315                                 sample_rate_view.get_selection()->select (it);
316                                 break;
317                         }
318                 }
319         }
320 }
321
322 void
323 ExportFormatDialog::load_state (FormatPtr spec)
324 {
325         name_entry.set_text (spec->name());
326
327         normalize_checkbox.set_active (spec->normalize());
328         normalize_peak_rb.set_active (!spec->normalize_loudness());
329         normalize_loudness_rb.set_active (spec->normalize_loudness());
330         normalize_dbfs_spinbutton.set_value (spec->normalize_dbfs());
331         normalize_lufs_spinbutton.set_value (spec->normalize_lufs());
332         normalize_dbtp_spinbutton.set_value (spec->normalize_dbtp());
333
334         trim_start_checkbox.set_active (spec->trim_beginning());
335         silence_start = spec->silence_beginning_time();
336         silence_start_checkbox.set_active (spec->silence_beginning_time().not_zero());
337
338         trim_end_checkbox.set_active (spec->trim_end());
339         silence_end = spec->silence_end_time();
340         silence_end_checkbox.set_active (spec->silence_end_time().not_zero());
341
342         with_cue.set_active (spec->with_cue());
343         with_toc.set_active (spec->with_toc());
344         with_mp4chaps.set_active (spec->with_mp4chaps());
345
346         for (Gtk::ListStore::Children::iterator it = src_quality_list->children().begin(); it != src_quality_list->children().end(); ++it) {
347                 if (it->get_value (src_quality_cols.id) == spec->src_quality()) {
348                         src_quality_combo.set_active (it);
349                         break;
350                 }
351         }
352
353         for (Gtk::ListStore::Children::iterator it = codec_quality_list->children().begin(); it != codec_quality_list->children().end(); ++it) {
354                 if (it->get_value (codec_quality_cols.quality) == spec->codec_quality()) {
355                         codec_quality_combo.set_active (it);
356                         break;
357                 }
358         }
359
360         for (Gtk::ListStore::Children::iterator it = format_list->children().begin(); it != format_list->children().end(); ++it) {
361                 boost::shared_ptr<ARDOUR::ExportFormat> format_in_list = it->get_value (format_cols.ptr);
362                 if (format_in_list->get_format_id() == spec->format_id() &&
363                     // BWF has the same format id with wav, so we need to check this.
364                     format_in_list->has_broadcast_info() == spec->has_broadcast_info()) {
365
366                         format_in_list->set_selected (true);
367                         break;
368                 }
369         }
370
371         for (Gtk::ListStore::Children::iterator it = sample_rate_list->children().begin(); it != sample_rate_list->children().end(); ++it) {
372                 if (it->get_value (sample_rate_cols.ptr)->rate == spec->sample_rate()) {
373                         it->get_value (sample_rate_cols.ptr)->set_selected (true);
374                         break;
375                 }
376         }
377
378         if (spec->sample_format()) {
379                 for (Gtk::ListStore::Children::iterator it = sample_format_list->children().begin(); it != sample_format_list->children().end(); ++it) {
380                         if (it->get_value (sample_format_cols.ptr)->format == spec->sample_format()) {
381                                 it->get_value (sample_format_cols.ptr)->set_selected (true);
382                                 break;
383                         }
384                 }
385
386                 for (Gtk::ListStore::Children::iterator it = dither_type_list->children().begin(); it != dither_type_list->children().end(); ++it) {
387                         if (it->get_value (dither_type_cols.ptr)->type == spec->dither_type()) {
388                                 it->get_value (dither_type_cols.ptr)->set_selected (true);
389                                 break;
390                         }
391                 }
392         }
393
394         update_normalize_sensitivity ();
395         tag_checkbox.set_active (spec->tag());
396         command_entry.set_text (spec->command());
397 }
398
399 void
400 ExportFormatDialog::init_format_table ()
401 {
402
403         format_table.set_spacings (1);
404
405         format_table.attach (compatibility_label, 0, 1, 0, 1);
406         format_table.attach (quality_label, 1, 2, 0, 1);
407         format_table.attach (format_label, 2, 3, 0, 1);
408         format_table.attach (sample_rate_label, 3, 4, 0, 1);
409
410         format_table.attach (compatibility_view, 0, 1, 1, 2);
411         format_table.attach (quality_view, 1, 2, 1, 2);
412         format_table.attach (format_view, 2, 3, 1, 2);
413         format_table.attach (sample_rate_view, 3, 4, 1, 2);
414
415         format_table.attach (src_quality_label, 0, 3, 2, 3);
416         format_table.attach (src_quality_combo, 3, 4, 2, 3);
417
418         compatibility_view.set_headers_visible (false);
419         quality_view.set_headers_visible (false);
420         format_view.set_headers_visible (false);
421         sample_rate_view.set_headers_visible (false);
422
423         /*** Table entries ***/
424
425         Gtk::TreeModel::iterator iter;
426         Gtk::TreeModel::Row row;
427
428         /* Compatibilities */
429
430         compatibility_list = Gtk::ListStore::create (compatibility_cols);
431         compatibility_view.set_model (compatibility_list);
432
433         ExportFormatManager::CompatList const & compat_list = manager.get_compatibilities();
434
435         for (ExportFormatManager::CompatList::const_iterator it = compat_list.begin(); it != compat_list.end(); ++it) {
436                 iter = compatibility_list->append();
437                 row = *iter;
438
439                 row[compatibility_cols.ptr] = *it;
440                 row[compatibility_cols.selected] = false;
441                 row[compatibility_cols.label] = (*it)->name();
442
443                 WeakCompatPtr ptr (*it);
444                 (*it)->SelectChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_compatibility_selection, this, _1, ptr), gui_context());
445         }
446
447         compatibility_view.append_column_editable ("", compatibility_cols.selected);
448
449         Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText);
450         text_renderer->property_editable() = false;
451
452         Gtk::TreeView::Column* column = compatibility_view.get_column (0);
453         column->pack_start (*text_renderer);
454         column->add_attribute (text_renderer->property_text(), compatibility_cols.label);
455
456         /* Qualities */
457
458         quality_list = Gtk::ListStore::create (quality_cols);
459         quality_view.set_model (quality_list);
460
461         ExportFormatManager::QualityList const & qualities = manager.get_qualities ();
462
463         for (ExportFormatManager::QualityList::const_iterator it = qualities.begin(); it != qualities.end(); ++it) {
464                 iter = quality_list->append();
465                 row = *iter;
466
467                 row[quality_cols.ptr] = *it;
468                 row[quality_cols.color] = "white";
469                 row[quality_cols.label] = (*it)->name();
470
471                 WeakQualityPtr ptr (*it);
472                 (*it)->SelectChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_quality_selection, this, _1, ptr), gui_context());
473                 (*it)->CompatibleChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_quality_compatibility, this, _1, ptr), gui_context());
474         }
475
476         quality_view.append_column ("", quality_cols.label);
477
478         /* Formats */
479
480         format_list = Gtk::ListStore::create (format_cols);
481         format_view.set_model (format_list);
482
483         ExportFormatManager::FormatList const & formats = manager.get_formats ();
484
485         for (ExportFormatManager::FormatList::const_iterator it = formats.begin(); it != formats.end(); ++it) {
486                 iter = format_list->append();
487                 row = *iter;
488
489                 row[format_cols.ptr] = *it;
490                 row[format_cols.color] = "white";
491                 row[format_cols.label] = (*it)->name();
492
493                 WeakFormatPtr ptr (*it);
494                 (*it)->SelectChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_format_selection, this, _1, ptr), gui_context());
495                 (*it)->CompatibleChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_format_compatibility, this, _1, ptr), gui_context());
496
497                 /* Encoding options */
498
499                 boost::shared_ptr<HasSampleFormat> hsf;
500
501                 if ((hsf = boost::dynamic_pointer_cast<HasSampleFormat> (*it))) {
502                         hsf->SampleFormatSelectChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_sample_format_selection, this, _1, _2), gui_context());
503                         hsf->SampleFormatCompatibleChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_sample_format_compatibility, this, _1, _2), gui_context());
504
505                         hsf->DitherTypeSelectChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_dither_type_selection, this, _1, _2), gui_context());
506                         hsf->DitherTypeCompatibleChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_dither_type_compatibility, this, _1, _2), gui_context());
507                 }
508         }
509
510         format_view.append_column ("", format_cols.label);
511
512         /* Sample Rates */
513
514         sample_rate_list = Gtk::ListStore::create (sample_rate_cols);
515         sample_rate_view.set_model (sample_rate_list);
516
517         ExportFormatManager::SampleRateList const & rates = manager.get_sample_rates ();
518
519         for (ExportFormatManager::SampleRateList::const_iterator it = rates.begin(); it != rates.end(); ++it) {
520                 iter = sample_rate_list->append();
521                 row = *iter;
522
523                 row[sample_rate_cols.ptr] = *it;
524                 row[sample_rate_cols.color] = "white";
525                 row[sample_rate_cols.label] = (*it)->name();
526
527                 WeakSampleRatePtr ptr (*it);
528                 (*it)->SelectChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_sample_rate_selection, this, _1, ptr), gui_context());
529                 (*it)->CompatibleChanged.connect (*this, invalidator (*this), boost::bind (&ExportFormatDialog::change_sample_rate_compatibility, this, _1, ptr), gui_context());
530         }
531
532         sample_rate_view.append_column ("", sample_rate_cols.label);
533
534         /* Color rendering */
535
536         Gtk::TreeViewColumn * label_col;
537         Gtk::CellRendererText * renderer;
538
539         label_col = quality_view.get_column(0);
540         renderer = dynamic_cast<Gtk::CellRendererText*> (quality_view.get_column_cell_renderer (0));
541         label_col->add_attribute(renderer->property_foreground(), quality_cols.color);
542
543         label_col = format_view.get_column(0);
544         renderer = dynamic_cast<Gtk::CellRendererText*> (format_view.get_column_cell_renderer (0));
545         label_col->add_attribute(renderer->property_foreground(), format_cols.color);
546
547         label_col = sample_rate_view.get_column(0);
548         renderer = dynamic_cast<Gtk::CellRendererText*> (sample_rate_view.get_column_cell_renderer (0));
549         label_col->add_attribute(renderer->property_foreground(), sample_rate_cols.color);
550
551         /* SRC Qualities */
552
553         src_quality_list = Gtk::ListStore::create (src_quality_cols);
554         src_quality_combo.set_model (src_quality_list);
555
556         iter = src_quality_list->append();
557         row = *iter;
558         row[src_quality_cols.id] = ExportFormatBase::SRC_SincBest;
559         row[src_quality_cols.label] = _("Best (sinc)");
560
561         iter = src_quality_list->append();
562         row = *iter;
563         row[src_quality_cols.id] = ExportFormatBase::SRC_SincMedium;
564         row[src_quality_cols.label] = _("Medium (sinc)");
565
566         iter = src_quality_list->append();
567         row = *iter;
568         row[src_quality_cols.id] = ExportFormatBase::SRC_SincFast;
569         row[src_quality_cols.label] = _("Fast (sinc)");
570
571         iter = src_quality_list->append();
572         row = *iter;
573         row[src_quality_cols.id] = ExportFormatBase::SRC_Linear;
574         row[src_quality_cols.label] = _("Linear");
575
576         iter = src_quality_list->append();
577         row = *iter;
578         row[src_quality_cols.id] = ExportFormatBase::SRC_ZeroOrderHold;
579         row[src_quality_cols.label] = _("Zero order hold");
580
581         src_quality_combo.pack_start (src_quality_cols.label);
582         src_quality_combo.set_active (0);
583 }
584
585 void
586 ExportFormatDialog::init_encoding_option_widgets ()
587 {
588         Gtk::TreeViewColumn * label_col;
589         Gtk::CellRendererText * renderer;
590
591         sample_format_list = Gtk::ListStore::create (sample_format_cols);
592         sample_format_view.set_model (sample_format_list);
593         sample_format_view.set_headers_visible (false);
594         sample_format_view.append_column ("", sample_format_cols.label);
595         label_col = sample_format_view.get_column(0);
596         renderer = dynamic_cast<Gtk::CellRendererText*> (sample_format_view.get_column_cell_renderer (0));
597         label_col->add_attribute(renderer->property_foreground(), sample_format_cols.color);
598
599         dither_type_list = Gtk::ListStore::create (dither_type_cols);
600         dither_type_view.set_model (dither_type_list);
601         dither_type_view.set_headers_visible (false);
602         dither_type_view.append_column ("", dither_type_cols.label);
603         label_col = dither_type_view.get_column(0);
604         renderer = dynamic_cast<Gtk::CellRendererText*> (dither_type_view.get_column_cell_renderer (0));
605         label_col->add_attribute(renderer->property_foreground(), dither_type_cols.color);
606
607 }
608
609 void
610 ExportFormatDialog::update_compatibility_selection (std::string const & path)
611 {
612
613         Gtk::TreeModel::iterator iter = compatibility_view.get_model ()->get_iter (path);
614         ExportFormatCompatibilityPtr ptr = iter->get_value (compatibility_cols.ptr);
615         bool state = iter->get_value (compatibility_cols.selected);
616
617         iter->set_value (compatibility_cols.selected, state);
618         ptr->set_selected (state);
619
620 }
621
622 void
623 ExportFormatDialog::update_quality_selection ()
624 {
625         update_selection<QualityCols> (quality_list, quality_view, quality_cols);
626 }
627
628 void
629 ExportFormatDialog::update_format_selection ()
630 {
631         update_selection<FormatCols> (format_list, format_view, format_cols);
632 }
633
634 void
635 ExportFormatDialog::update_sample_rate_selection ()
636 {
637         update_selection<SampleRateCols> (sample_rate_list, sample_rate_view, sample_rate_cols);
638 }
639
640 void
641 ExportFormatDialog::update_sample_format_selection ()
642 {
643         update_selection<SampleFormatCols> (sample_format_list, sample_format_view, sample_format_cols);
644 }
645
646 void
647 ExportFormatDialog::update_dither_type_selection ()
648 {
649         update_selection<DitherTypeCols> (dither_type_list, dither_type_view, dither_type_cols);
650 }
651
652 template<typename ColsT>
653 void
654 ExportFormatDialog::update_selection (Glib::RefPtr<Gtk::ListStore> & list, Gtk::TreeView & view, ColsT & cols)
655 {
656         if (applying_changes_from_engine) {
657                 return;
658         }
659
660         Gtk::ListStore::Children::iterator it;
661         Glib::RefPtr<Gtk::TreeSelection> selection = view.get_selection();
662
663         for (it = list->children().begin(); it != list->children().end(); ++it) {
664                 bool selected = selection->is_selected (it);
665                 it->get_value (cols.ptr)->set_selected (selected);
666         }
667
668         set_codec_quality_selection ();
669 }
670
671 void
672 ExportFormatDialog::change_compatibility_selection (bool select, WeakCompatPtr compat)
673 {
674         ++applying_changes_from_engine;
675
676         ExportFormatCompatibilityPtr ptr = compat.lock();
677
678         for (Gtk::ListStore::Children::iterator it = compatibility_list->children().begin(); it != compatibility_list->children().end(); ++it) {
679                 if (it->get_value (compatibility_cols.ptr) == ptr) {
680                         it->set_value (compatibility_cols.selected, select);
681                         break;
682                 }
683         }
684
685         --applying_changes_from_engine;
686 }
687
688 void
689 ExportFormatDialog::change_quality_selection (bool select, WeakQualityPtr quality)
690 {
691         change_selection<ExportFormatManager::QualityState, QualityCols> (select, quality, quality_list, quality_view, quality_cols);
692 }
693
694 void
695 ExportFormatDialog::change_format_selection (bool select, WeakFormatPtr format)
696 {
697         change_selection<ExportFormat, FormatCols> (select, format, format_list, format_view, format_cols);
698
699         ExportFormatPtr ptr = format.lock();
700
701         if (select && ptr) {
702                 change_encoding_options (ptr);
703         }
704 }
705
706 void
707 ExportFormatDialog::change_sample_rate_selection (bool select, WeakSampleRatePtr rate)
708 {
709         change_selection<ExportFormatManager::SampleRateState, SampleRateCols> (select, rate, sample_rate_list, sample_rate_view, sample_rate_cols);
710
711         if (select) {
712                 ExportFormatManager::SampleRatePtr ptr = rate.lock();
713                 if (ptr && _session) {
714                         src_quality_combo.set_sensitive ((uint32_t) ptr->rate != _session->sample_rate());
715                 }
716         }
717 }
718
719 void
720 ExportFormatDialog::change_sample_format_selection (bool select, WeakSampleFormatPtr format)
721 {
722         change_selection<HasSampleFormat::SampleFormatState, SampleFormatCols> (select, format, sample_format_list, sample_format_view, sample_format_cols);
723 }
724
725 void
726 ExportFormatDialog::change_dither_type_selection (bool select, WeakDitherTypePtr type)
727 {
728         change_selection<HasSampleFormat::DitherTypeState, DitherTypeCols> (select, type, dither_type_list, dither_type_view, dither_type_cols);
729 }
730
731 template<typename T, typename ColsT>
732 void
733 ExportFormatDialog::change_selection (bool select, boost::weak_ptr<T> w_ptr, Glib::RefPtr<Gtk::ListStore> & list, Gtk::TreeView & view, ColsT & cols)
734 {
735         ++applying_changes_from_engine;
736
737         boost::shared_ptr<T> ptr = w_ptr.lock();
738
739         Gtk::ListStore::Children::iterator it;
740         Glib::RefPtr<Gtk::TreeSelection> selection;
741
742         selection = view.get_selection();
743
744         if (!ptr) {
745                 selection->unselect_all();
746         } else {
747                 for (it = list->children().begin(); it != list->children().end(); ++it) {
748                         if (it->get_value (cols.ptr) == ptr) {
749                                 if (select) {
750                                         selection->select (it);
751                                 } else {
752                                         selection->unselect (it);
753                                 }
754                                 break;
755                         }
756                 }
757         }
758
759         --applying_changes_from_engine;
760 }
761
762 void
763 ExportFormatDialog::change_quality_compatibility (bool compatibility, WeakQualityPtr quality)
764 {
765         change_compatibility<ExportFormatManager::QualityState, QualityCols> (compatibility, quality, quality_list, quality_cols);
766 }
767
768 void
769 ExportFormatDialog::change_format_compatibility (bool compatibility, WeakFormatPtr format)
770 {
771         change_compatibility<ExportFormat, FormatCols> (compatibility, format, format_list, format_cols);
772 }
773
774 void
775 ExportFormatDialog::change_sample_rate_compatibility (bool compatibility, WeakSampleRatePtr rate)
776 {
777         change_compatibility<ExportFormatManager::SampleRateState, SampleRateCols> (compatibility, rate, sample_rate_list, sample_rate_cols);
778 }
779
780 void
781 ExportFormatDialog::change_sample_format_compatibility (bool compatibility, WeakSampleFormatPtr format)
782 {
783         change_compatibility<HasSampleFormat::SampleFormatState, SampleFormatCols> (compatibility, format, sample_format_list, sample_format_cols);
784 }
785
786 void
787 ExportFormatDialog::change_dither_type_compatibility (bool compatibility, WeakDitherTypePtr type)
788 {
789         change_compatibility<HasSampleFormat::DitherTypeState, DitherTypeCols> (compatibility, type, dither_type_list, dither_type_cols, "red");
790 }
791
792 template<typename T, typename ColsT>
793 void
794 ExportFormatDialog::change_compatibility (bool compatibility, boost::weak_ptr<T> w_ptr, Glib::RefPtr<Gtk::ListStore> & list, ColsT & cols,
795                                           std::string const & c_incompatible, std::string const & c_compatible)
796 {
797         boost::shared_ptr<T> ptr = w_ptr.lock();
798
799         Gtk::ListStore::Children::iterator it;
800         for (it = list->children().begin(); it != list->children().end(); ++it) {
801                 if (it->get_value (cols.ptr) == ptr) {
802                         it->set_value (cols.color, compatibility ? c_compatible : c_incompatible);
803                         break;
804                 }
805         }
806 }
807
808 void
809 ExportFormatDialog::update_with_cue ()
810 {
811         manager.select_with_cue (with_cue.get_active());
812 }
813
814 void
815 ExportFormatDialog::update_with_toc ()
816 {
817         manager.select_with_toc (with_toc.get_active());
818 }
819
820 void
821 ExportFormatDialog::update_with_mp4chaps ()
822 {
823         manager.select_with_mp4chaps (with_mp4chaps.get_active());
824 }
825
826 void
827 ExportFormatDialog::update_command ()
828 {
829         manager.set_command (command_entry.get_text());
830 }
831
832 void
833 ExportFormatDialog::update_description()
834 {
835         std::string text = ": " + format->description(false);
836         name_generated_part.set_text(text);
837 }
838
839 void
840 ExportFormatDialog::update_name ()
841 {
842         manager.set_name (name_entry.get_text());
843 }
844
845 void
846 ExportFormatDialog::update_trim_start_selection ()
847 {
848         manager.select_trim_beginning (trim_start_checkbox.get_active());
849 }
850
851 void
852 ExportFormatDialog::update_trim_end_selection ()
853 {
854         manager.select_trim_end (trim_end_checkbox.get_active());
855 }
856
857 void
858 ExportFormatDialog::update_normalize_sensitivity ()
859 {
860         bool en = normalize_checkbox.get_active();
861         bool loudness = normalize_loudness_rb.get_active();
862         normalize_dbfs_spinbutton.set_sensitive (!loudness && en);
863         normalize_lufs_spinbutton.set_sensitive (loudness && en);
864         normalize_dbtp_spinbutton.set_sensitive (loudness && en);
865 }
866
867 void
868 ExportFormatDialog::update_normalize_selection ()
869 {
870         manager.select_normalize (normalize_checkbox.get_active());
871         manager.select_normalize_loudness (normalize_loudness_rb.get_active());
872         manager.select_normalize_dbfs (normalize_dbfs_spinbutton.get_value ());
873         manager.select_normalize_lufs (normalize_lufs_spinbutton.get_value ());
874         manager.select_normalize_dbtp (normalize_dbtp_spinbutton.get_value ());
875         update_normalize_sensitivity ();
876 }
877
878 void
879 ExportFormatDialog::update_silence_start_selection ()
880 {
881         update_time (silence_start, silence_start_clock);
882         AnyTime zero;
883         zero.type = AnyTime::Timecode;
884         manager.select_silence_beginning (silence_start_checkbox.get_active() ? silence_start : zero);
885 }
886
887 void
888 ExportFormatDialog::update_silence_end_selection ()
889 {
890         update_time (silence_end, silence_end_clock);
891         AnyTime zero;
892         zero.type = AnyTime::Timecode;
893         manager.select_silence_end (silence_end_checkbox.get_active() ? silence_end : zero);
894 }
895
896 void
897 ExportFormatDialog::update_clock (AudioClock & clock, ARDOUR::AnyTime const & time)
898 {
899         // TODO position
900         clock.set (_session->convert_to_samples (time), true);
901
902         AudioClock::Mode mode(AudioClock::Timecode);
903
904         switch (time.type) {
905           case AnyTime::Timecode:
906                 mode = AudioClock::Timecode;
907                 break;
908           case AnyTime::BBT:
909                 mode = AudioClock::BBT;
910                 break;
911           case AnyTime::Samples:
912                 mode = AudioClock::Samples;
913                 break;
914           case AnyTime::Seconds:
915                 mode = AudioClock::MinSec;
916                 break;
917         }
918
919         clock.set_mode (mode);
920 }
921
922 void
923 ExportFormatDialog::update_time (AnyTime & time, AudioClock const & clock)
924 {
925         if (!_session) {
926                 return;
927         }
928
929         samplecnt_t samples = clock.current_duration();
930
931         switch (clock.mode()) {
932           case AudioClock::Timecode:
933                 time.type = AnyTime::Timecode;
934                 _session->timecode_time (samples, time.timecode);
935                 break;
936           case AudioClock::BBT:
937                 time.type = AnyTime::BBT;
938                 _session->bbt_time (samples, time.bbt);
939                 break;
940           case AudioClock::Seconds:
941           case AudioClock::MinSec:
942                 time.type = AnyTime::Seconds;
943                 time.seconds = (double) samples / _session->sample_rate();
944                 break;
945           case AudioClock::Samples:
946                 time.type = AnyTime::Samples;
947                 time.samples = samples;
948                 break;
949         }
950 }
951
952 void
953 ExportFormatDialog::update_src_quality_selection ()
954 {
955         Gtk::TreeModel::const_iterator iter = src_quality_combo.get_active();
956         ExportFormatBase::SRCQuality quality = iter->get_value (src_quality_cols.id);
957         manager.select_src_quality (quality);
958 }
959
960 void
961 ExportFormatDialog::update_codec_quality_selection ()
962 {
963         Gtk::TreeModel::const_iterator iter = codec_quality_combo.get_active();
964         if (!iter) {
965                 return;
966         }
967         int quality = iter->get_value (codec_quality_cols.quality);
968         manager.select_codec_quality (quality);
969 }
970
971 void
972 ExportFormatDialog::update_tagging_selection ()
973 {
974         manager.select_tagging (tag_checkbox.get_active());
975 }
976
977 void
978 ExportFormatDialog::change_encoding_options (ExportFormatPtr ptr)
979 {
980         empty_encoding_option_table ();
981
982         boost::shared_ptr<ARDOUR::ExportFormatLinear> linear_ptr;
983         boost::shared_ptr<ARDOUR::ExportFormatOggVorbis> ogg_ptr;
984         boost::shared_ptr<ARDOUR::ExportFormatFLAC> flac_ptr;
985         boost::shared_ptr<ARDOUR::ExportFormatBWF> bwf_ptr;
986         boost::shared_ptr<ARDOUR::ExportFormatFFMPEG> ffmpeg_ptr;
987
988         if ((linear_ptr = boost::dynamic_pointer_cast<ExportFormatLinear> (ptr))) {
989                 show_linear_enconding_options (linear_ptr);
990         } else if ((ogg_ptr = boost::dynamic_pointer_cast<ExportFormatOggVorbis> (ptr))) {
991                 show_ogg_enconding_options (ogg_ptr);
992         } else if ((flac_ptr = boost::dynamic_pointer_cast<ExportFormatFLAC> (ptr))) {
993                 show_flac_enconding_options (flac_ptr);
994         } else if ((bwf_ptr = boost::dynamic_pointer_cast<ExportFormatBWF> (ptr))) {
995                 show_bwf_enconding_options (bwf_ptr);
996         } else if ((ffmpeg_ptr = boost::dynamic_pointer_cast<ExportFormatFFMPEG> (ptr))) {
997                 show_ffmpeg_enconding_options (ffmpeg_ptr);
998         } else {
999                 std::cout << "Unrecognized format!" << std::endl;
1000         }
1001 }
1002
1003 void
1004 ExportFormatDialog::empty_encoding_option_table ()
1005 {
1006         encoding_options_table.foreach (sigc::bind (sigc::mem_fun (*this, &ExportFormatDialog::remove_widget), &encoding_options_table));
1007 }
1008
1009 void
1010 ExportFormatDialog::remove_widget (Gtk::Widget & to_remove, Gtk::Container * remove_from)
1011 {
1012         remove_from->remove (to_remove);
1013 }
1014
1015 void
1016 ExportFormatDialog::show_linear_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatLinear> ptr)
1017 {
1018         /* Set label and pack table */
1019
1020         encoding_options_label.set_label (_("Linear encoding options"));
1021
1022         encoding_options_table.resize (2, 2);
1023         encoding_options_table.attach (sample_format_label, 0, 1, 0, 1);
1024         encoding_options_table.attach (dither_label, 1, 2, 0, 1);
1025         encoding_options_table.attach (sample_format_view, 0, 1, 1, 2);
1026         encoding_options_table.attach (dither_type_view, 1, 2, 1, 2);
1027
1028         fill_sample_format_lists (boost::dynamic_pointer_cast<HasSampleFormat> (ptr));
1029
1030         show_all_children ();
1031 }
1032
1033 void
1034 ExportFormatDialog::show_ogg_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatOggVorbis> ptr)
1035 {
1036         encoding_options_label.set_label (_("Ogg Vorbis options"));
1037
1038         encoding_options_table.resize (2, 1);
1039         encoding_options_table.attach (codec_quality_combo, 0, 1, 0, 1);
1040         encoding_options_table.attach (tag_checkbox, 0, 1, 1, 2);
1041         fill_codec_quality_lists (ptr);
1042         show_all_children ();
1043 }
1044
1045 void
1046 ExportFormatDialog::show_flac_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatFLAC> ptr)
1047 {
1048         encoding_options_label.set_label (_("FLAC options"));
1049
1050         encoding_options_table.resize (3, 2);
1051         encoding_options_table.attach (sample_format_label, 0, 1, 0, 1);
1052         encoding_options_table.attach (dither_label, 1, 2, 0, 1);
1053         encoding_options_table.attach (sample_format_view, 0, 1, 1, 2);
1054         encoding_options_table.attach (dither_type_view, 1, 2, 1, 2);
1055         encoding_options_table.attach (tag_checkbox, 0, 2, 2, 3);
1056
1057         fill_sample_format_lists (boost::dynamic_pointer_cast<HasSampleFormat> (ptr));
1058
1059         show_all_children ();
1060 }
1061
1062 void
1063 ExportFormatDialog::show_bwf_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatBWF> ptr)
1064 {
1065         encoding_options_label.set_label (_("Broadcast Wave options"));
1066
1067         encoding_options_table.resize (2, 2);
1068         encoding_options_table.attach (sample_format_label, 0, 1, 0, 1);
1069         encoding_options_table.attach (dither_label, 1, 2, 0, 1);
1070         encoding_options_table.attach (sample_format_view, 0, 1, 1, 2);
1071         encoding_options_table.attach (dither_type_view, 1, 2, 1, 2);
1072
1073         fill_sample_format_lists (boost::dynamic_pointer_cast<HasSampleFormat> (ptr));
1074
1075         show_all_children ();
1076 }
1077
1078 void
1079 ExportFormatDialog::show_ffmpeg_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatFFMPEG> ptr)
1080 {
1081         encoding_options_label.set_label (_("FFMPEG/MP3 options"));
1082         encoding_options_table.resize (1, 1);
1083         encoding_options_table.attach (codec_quality_combo, 0, 1, 0, 1);
1084         encoding_options_table.attach (tag_checkbox, 0, 1, 1, 2);
1085         fill_codec_quality_lists (ptr);
1086         show_all_children ();
1087 }
1088
1089 void
1090 ExportFormatDialog::fill_sample_format_lists (boost::shared_ptr<ARDOUR::HasSampleFormat> ptr)
1091 {
1092         /* Fill lists */
1093
1094         Gtk::TreeModel::iterator iter;
1095         Gtk::TreeModel::Row row;
1096
1097         sample_format_list->clear ();
1098
1099         HasSampleFormat::SampleFormatList const & formats = ptr->get_sample_formats ();
1100
1101         for (HasSampleFormat::SampleFormatList::const_iterator it = formats.begin(); it != formats.end(); ++it) {
1102                 iter = sample_format_list->append();
1103                 row = *iter;
1104
1105                 row[sample_format_cols.ptr] = *it;
1106                 row[sample_format_cols.color] = (*it)->compatible() ? "white" : "red";
1107                 row[sample_format_cols.label] = (*it)->name();
1108
1109                 if ((*it)->selected()) {
1110                         sample_format_view.get_selection()->select (iter);
1111                 }
1112         }
1113
1114         dither_type_list->clear ();
1115
1116         HasSampleFormat::DitherTypeList const & types = ptr->get_dither_types ();
1117
1118         for (HasSampleFormat::DitherTypeList::const_iterator it = types.begin(); it != types.end(); ++it) {
1119                 iter = dither_type_list->append();
1120                 row = *iter;
1121
1122                 row[dither_type_cols.ptr] = *it;
1123                 row[dither_type_cols.color] = "white";
1124                 row[dither_type_cols.label] = (*it)->name();
1125
1126                 if ((*it)->selected()) {
1127                         dither_type_view.get_selection()->select (iter);
1128                 }
1129         }
1130 }
1131
1132 void
1133 ExportFormatDialog::fill_codec_quality_lists (boost::shared_ptr<ARDOUR::HasCodecQuality> ptr)
1134 {
1135         HasCodecQuality::CodecQualityList const & codecs = ptr->get_codec_qualities();
1136
1137         codec_quality_list->clear();
1138         for (HasCodecQuality::CodecQualityList::const_iterator it = codecs.begin(); it != codecs.end(); ++it) {
1139
1140         Gtk::TreeModel::iterator iter = codec_quality_list->append();
1141         Gtk::TreeModel::Row row = *iter;
1142                 row[codec_quality_cols.quality] = (*it)->quality;
1143                 row[codec_quality_cols.label] = (*it)->name;
1144         }
1145         set_codec_quality_selection ();
1146 }
1147
1148 void
1149 ExportFormatDialog::set_codec_quality_selection ()
1150 {
1151         for (Gtk::ListStore::Children::iterator it = codec_quality_list->children().begin(); it != codec_quality_list->children().end(); ++it) {
1152                 if (it->get_value (codec_quality_cols.quality) == format->codec_quality()) {
1153                         codec_quality_combo.set_active (it);
1154                         break;
1155                 }
1156         }
1157 }
1158
1159 void
1160 ExportFormatDialog::end_dialog ()
1161 {
1162         hide_all ();
1163 }
1164
1165 void
1166 ExportFormatDialog::prohibit_compatibility_selection ()
1167 {
1168         compatibility_select_connection.block (true);
1169         compatibility_view.get_selection()->unselect_all ();
1170         compatibility_select_connection.block (false);
1171 }