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