don't override user naming of send/return/port inserts
[ardour2.git] / gtk2_ardour / export_format_dialog.cc
blob9cb2a9cb5d289a17b44526f2da80e16305c8f9ed
1 /*
2 Copyright (C) 2008 Paul Davis
3 Author: Sakari Bergen
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.
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.
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.
21 #include "ardour/session.h"
22 #include "ardour/export_format_specification.h"
24 #include "export_format_dialog.h"
25 #include "gui_thread.h"
26 #include "i18n.h"
28 using namespace ARDOUR;
30 ExportFormatDialog::ExportFormatDialog (FormatPtr format, bool new_dialog) :
31 ArdourDialog (new_dialog ? _("New export format profile") : _("Edit export format profile")),
32 format (format),
33 manager (format),
34 original_state (format->get_state()),
36 applying_changes_from_engine (0),
38 name_label (_("Label: "), Gtk::ALIGN_LEFT),
40 normalize_checkbox (_("Normalize to:")),
41 normalize_adjustment (0.00, -90.00, 0.00, 0.1, 0.2),
42 normalize_db_label (_("dBFS"), Gtk::ALIGN_LEFT),
44 silence_table (2, 4),
45 trim_start_checkbox (_("Trim silence at start")),
46 silence_start_checkbox (_("Add silence at start:")),
47 silence_start_clock ("silence_start", true, "PreRollClock", true, false, true),
49 trim_end_checkbox (_("Trim silence at end")),
50 silence_end_checkbox (_("Add silence at end:")),
51 silence_end_clock ("silence_end", true, "PreRollClock", true, false, true),
53 format_table (3, 4),
54 compatibility_label (_("Compatibility"), Gtk::ALIGN_LEFT),
55 quality_label (_("Quality"), Gtk::ALIGN_LEFT),
56 format_label (_("File format"), Gtk::ALIGN_LEFT),
57 sample_rate_label (_("Sample rate"), Gtk::ALIGN_LEFT),
58 src_quality_label (_("Sample rate conversion quality:"), Gtk::ALIGN_RIGHT),
60 encoding_options_label (_(""), Gtk::ALIGN_LEFT),
62 /* Changing encoding options from here on */
64 sample_format_label (_("Sample Format"), Gtk::ALIGN_LEFT),
65 dither_label (_("Dithering"), Gtk::ALIGN_LEFT),
67 tag_checkbox (_("Tag file with session's metadata"))
70 /* Pack containers in dialog */
72 get_vbox()->pack_start (name_hbox, false, false, 0);
73 get_vbox()->pack_start (silence_table, false, false, 6);
74 get_vbox()->pack_start (format_table, false, false, 6);
75 get_vbox()->pack_start (encoding_options_vbox, false, false, 0);
77 /* Name, new and remove */
79 name_hbox.pack_start (name_label, false, false, 0);
80 name_hbox.pack_start (name_entry, true, true, 0);
82 /* Normalize */
84 normalize_hbox.pack_start (normalize_checkbox, false, false, 0);
85 normalize_hbox.pack_start (normalize_spinbutton, false, false, 6);
86 normalize_hbox.pack_start (normalize_db_label, false, false, 0);
88 normalize_spinbutton.configure (normalize_adjustment, 0.1, 2);
90 /* Silence */
92 silence_table.set_row_spacings (6);
93 silence_table.set_col_spacings (12);
95 silence_table.attach (normalize_hbox, 0, 3, 0, 1);
97 silence_table.attach (trim_start_checkbox, 0, 1, 1, 2);
98 silence_table.attach (silence_start_checkbox, 1, 2, 1, 2);
99 silence_table.attach (silence_start_clock, 2, 3, 1, 2);
101 silence_table.attach (trim_end_checkbox, 0, 1, 2, 3);
102 silence_table.attach (silence_end_checkbox, 1, 2, 2, 3);
103 silence_table.attach (silence_end_clock, 2, 3, 2, 3);
105 /* Format table */
107 init_format_table();
109 /* Encoding options */
111 init_encoding_option_widgets();
113 encoding_options_table.set_spacings (1);
115 encoding_options_vbox.pack_start (encoding_options_label, false, false, 0);
116 encoding_options_vbox.pack_start (encoding_options_table, false, false, 12);
118 Pango::AttrList bold;
119 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
120 bold.insert (b);
121 encoding_options_label.set_attributes (bold);
123 /* Buttons */
125 revert_button = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
126 revert_button->signal_clicked().connect (sigc::mem_fun(*this, &ExportFormatDialog::revert));
127 close_button = add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_APPLY);
128 close_button->set_sensitive (false);
129 close_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportFormatDialog::end_dialog));
130 manager.CompleteChanged.connect (*this, invalidator (*this), ui_bind (&Gtk::Button::set_sensitive, close_button, _1), gui_context());
132 /* Load state before hooking up the rest of the signals */
134 load_state (format);
136 /* Name entry */
138 name_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_name));
140 /* Normalize, silence and src_quality signals */
142 trim_start_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_trim_start_selection));
143 trim_end_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_trim_end_selection));
145 normalize_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_normalize_selection));
146 normalize_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_normalize_selection));
148 silence_start_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_silence_start_selection));
149 silence_start_clock.ValueChanged.connect (sigc::mem_fun (*this, &ExportFormatDialog::update_silence_start_selection));
151 silence_end_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_silence_end_selection));
152 silence_end_clock.ValueChanged.connect (sigc::mem_fun (*this, &ExportFormatDialog::update_silence_end_selection));
154 src_quality_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_src_quality_selection));
156 /* Format table signals */
158 Gtk::CellRendererToggle *toggle = dynamic_cast<Gtk::CellRendererToggle *>(compatibility_view.get_column_cell_renderer (0));
159 toggle->signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_compatibility_selection));
160 compatibility_select_connection = compatibility_view.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::prohibit_compatibility_selection));
162 quality_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_quality_selection));
163 format_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_format_selection));
164 sample_rate_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_sample_rate_selection));
166 /* Encoding option signals */
168 sample_format_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_sample_format_selection));
169 dither_type_view.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &ExportFormatDialog::update_dither_type_selection));
171 tag_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_tagging_selection));
173 /* Finalize */
175 show_all_children();
178 ExportFormatDialog::~ExportFormatDialog ()
183 void
184 ExportFormatDialog::revert ()
186 ++applying_changes_from_engine;
188 format->set_state (original_state);
189 load_state (format);
191 --applying_changes_from_engine;
194 void
195 ExportFormatDialog::set_session (ARDOUR::Session* s)
197 SessionHandlePtr::set_session (s);
198 silence_start_clock.set_session (s);
199 silence_end_clock.set_session (s);
201 if (!_session) {
202 return;
205 update_clock (silence_start_clock, silence_start);
206 update_clock (silence_end_clock, silence_end);
208 /* Select native samplerate if no selection is yet made */
210 if (sample_rate_view.get_selection()->count_selected_rows() == 0) {
211 Gtk::ListStore::Children::iterator it;
212 for (it = sample_rate_list->children().begin(); it != sample_rate_list->children().end(); ++it) {
213 if ((nframes_t) (*it)->get_value (sample_rate_cols.ptr)->rate == _session->nominal_frame_rate()) {
214 sample_rate_view.get_selection()->select (it);
215 break;
221 void
222 ExportFormatDialog::load_state (FormatPtr spec)
224 name_entry.set_text (spec->name());
226 normalize_checkbox.set_active (spec->normalize());
227 normalize_spinbutton.set_value (spec->normalize_target());
229 trim_start_checkbox.set_active (spec->trim_beginning());
230 silence_start = spec->silence_beginning_time();
231 silence_start_checkbox.set_active (spec->silence_beginning() > 0);
233 trim_end_checkbox.set_active (spec->trim_end());
234 silence_end = spec->silence_end_time();
235 silence_end_checkbox.set_active (spec->silence_end() > 0);
237 for (Gtk::ListStore::Children::iterator it = src_quality_list->children().begin(); it != src_quality_list->children().end(); ++it) {
238 if (it->get_value (src_quality_cols.id) == spec->src_quality()) {
239 src_quality_combo.set_active (it);
240 break;
244 for (Gtk::ListStore::Children::iterator it = format_list->children().begin(); it != format_list->children().end(); ++it) {
245 if (it->get_value (format_cols.ptr)->get_format_id() == spec->format_id()) {
246 it->get_value (format_cols.ptr)->set_selected (true);
247 break;
251 for (Gtk::ListStore::Children::iterator it = sample_rate_list->children().begin(); it != sample_rate_list->children().end(); ++it) {
252 if (it->get_value (sample_rate_cols.ptr)->rate == spec->sample_rate()) {
253 it->get_value (sample_rate_cols.ptr)->set_selected (true);
254 break;
258 if (spec->sample_format()) {
259 for (Gtk::ListStore::Children::iterator it = sample_format_list->children().begin(); it != sample_format_list->children().end(); ++it) {
260 if (it->get_value (sample_format_cols.ptr)->format == spec->sample_format()) {
261 it->get_value (sample_format_cols.ptr)->set_selected (true);
262 break;
266 for (Gtk::ListStore::Children::iterator it = dither_type_list->children().begin(); it != dither_type_list->children().end(); ++it) {
267 if (it->get_value (dither_type_cols.ptr)->type == spec->dither_type()) {
268 it->get_value (dither_type_cols.ptr)->set_selected (true);
269 break;
274 tag_checkbox.set_active (spec->tag());
277 void
278 ExportFormatDialog::init_format_table ()
281 format_table.set_spacings (1);
283 format_table.attach (compatibility_label, 0, 1, 0, 1);
284 format_table.attach (quality_label, 1, 2, 0, 1);
285 format_table.attach (format_label, 2, 3, 0, 1);
286 format_table.attach (sample_rate_label, 3, 4, 0, 1);
288 format_table.attach (compatibility_view, 0, 1, 1, 2);
289 format_table.attach (quality_view, 1, 2, 1, 2);
290 format_table.attach (format_view, 2, 3, 1, 2);
291 format_table.attach (sample_rate_view, 3, 4, 1, 2);
293 format_table.attach (src_quality_label, 0, 3, 2, 3);
294 format_table.attach (src_quality_combo, 3, 4, 2, 3);
296 compatibility_view.set_headers_visible (false);
297 quality_view.set_headers_visible (false);
298 format_view.set_headers_visible (false);
299 sample_rate_view.set_headers_visible (false);
301 /*** Table entries ***/
303 Gtk::TreeModel::iterator iter;
304 Gtk::TreeModel::Row row;
306 /* Compatibilities */
308 compatibility_list = Gtk::ListStore::create (compatibility_cols);
309 compatibility_view.set_model (compatibility_list);
311 ExportFormatManager::CompatList const & compat_list = manager.get_compatibilities();
313 for (ExportFormatManager::CompatList::const_iterator it = compat_list.begin(); it != compat_list.end(); ++it) {
314 iter = compatibility_list->append();
315 row = *iter;
317 row[compatibility_cols.ptr] = *it;
318 row[compatibility_cols.selected] = false;
319 row[compatibility_cols.label] = (*it)->name();
321 WeakCompatPtr ptr (*it);
322 (*it)->SelectChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_compatibility_selection, this, _1, ptr), gui_context());
325 compatibility_view.append_column_editable ("", compatibility_cols.selected);
327 Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText);
328 text_renderer->property_editable() = false;
330 Gtk::TreeView::Column* column = compatibility_view.get_column (0);
331 column->pack_start (*text_renderer);
332 column->add_attribute (text_renderer->property_text(), compatibility_cols.label);
334 /* Qualities */
336 quality_list = Gtk::ListStore::create (quality_cols);
337 quality_view.set_model (quality_list);
339 ExportFormatManager::QualityList const & qualities = manager.get_qualities ();
341 for (ExportFormatManager::QualityList::const_iterator it = qualities.begin(); it != qualities.end(); ++it) {
342 iter = quality_list->append();
343 row = *iter;
345 row[quality_cols.ptr] = *it;
346 row[quality_cols.color] = "white";
347 row[quality_cols.label] = (*it)->name();
349 WeakQualityPtr ptr (*it);
350 (*it)->SelectChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_quality_selection, this, _1, ptr), gui_context());
351 (*it)->CompatibleChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_quality_compatibility, this, _1, ptr), gui_context());
354 quality_view.append_column ("", quality_cols.label);
356 /* Formats */
358 format_list = Gtk::ListStore::create (format_cols);
359 format_view.set_model (format_list);
361 ExportFormatManager::FormatList const & formats = manager.get_formats ();
363 for (ExportFormatManager::FormatList::const_iterator it = formats.begin(); it != formats.end(); ++it) {
364 iter = format_list->append();
365 row = *iter;
367 row[format_cols.ptr] = *it;
368 row[format_cols.color] = "white";
369 row[format_cols.label] = (*it)->name();
371 WeakFormatPtr ptr (*it);
372 (*it)->SelectChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_format_selection, this, _1, ptr), gui_context());
373 (*it)->CompatibleChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_format_compatibility, this, _1, ptr), gui_context());
375 /* Encoding options */
377 boost::shared_ptr<HasSampleFormat> hsf;
379 if (hsf = boost::dynamic_pointer_cast<HasSampleFormat> (*it)) {
380 hsf->SampleFormatSelectChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_sample_format_selection, this, _1, _2), gui_context());
381 hsf->SampleFormatCompatibleChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_sample_format_compatibility, this, _1, _2), gui_context());
383 hsf->DitherTypeSelectChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_dither_type_selection, this, _1, _2), gui_context());
384 hsf->DitherTypeCompatibleChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_dither_type_compatibility, this, _1, _2), gui_context());
388 format_view.append_column ("", format_cols.label);
390 /* Sample Rates */
392 sample_rate_list = Gtk::ListStore::create (sample_rate_cols);
393 sample_rate_view.set_model (sample_rate_list);
395 ExportFormatManager::SampleRateList const & rates = manager.get_sample_rates ();
397 for (ExportFormatManager::SampleRateList::const_iterator it = rates.begin(); it != rates.end(); ++it) {
398 iter = sample_rate_list->append();
399 row = *iter;
401 row[sample_rate_cols.ptr] = *it;
402 row[sample_rate_cols.color] = "white";
403 row[sample_rate_cols.label] = (*it)->name();
405 WeakSampleRatePtr ptr (*it);
406 (*it)->SelectChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_sample_rate_selection, this, _1, ptr), gui_context());
407 (*it)->CompatibleChanged.connect (*this, invalidator (*this), ui_bind (&ExportFormatDialog::change_sample_rate_compatibility, this, _1, ptr), gui_context());
410 sample_rate_view.append_column ("", sample_rate_cols.label);
412 /* Color rendering */
414 Gtk::TreeViewColumn * label_col;
415 Gtk::CellRendererText * renderer;
417 label_col = quality_view.get_column(0);
418 renderer = dynamic_cast<Gtk::CellRendererText*> (quality_view.get_column_cell_renderer (0));
419 label_col->add_attribute(renderer->property_foreground(), quality_cols.color);
421 label_col = format_view.get_column(0);
422 renderer = dynamic_cast<Gtk::CellRendererText*> (format_view.get_column_cell_renderer (0));
423 label_col->add_attribute(renderer->property_foreground(), format_cols.color);
425 label_col = sample_rate_view.get_column(0);
426 renderer = dynamic_cast<Gtk::CellRendererText*> (sample_rate_view.get_column_cell_renderer (0));
427 label_col->add_attribute(renderer->property_foreground(), sample_rate_cols.color);
429 /* SRC Qualities */
431 src_quality_list = Gtk::ListStore::create (src_quality_cols);
432 src_quality_combo.set_model (src_quality_list);
434 iter = src_quality_list->append();
435 row = *iter;
436 row[src_quality_cols.id] = ExportFormatBase::SRC_SincBest;
437 row[src_quality_cols.label] = _("Best (sinc)");
439 iter = src_quality_list->append();
440 row = *iter;
441 row[src_quality_cols.id] = ExportFormatBase::SRC_SincMedium;
442 row[src_quality_cols.label] = _("Medium (sinc)");
444 iter = src_quality_list->append();
445 row = *iter;
446 row[src_quality_cols.id] = ExportFormatBase::SRC_SincFast;
447 row[src_quality_cols.label] = _("Fast (sinc)");
449 iter = src_quality_list->append();
450 row = *iter;
451 row[src_quality_cols.id] = ExportFormatBase::SRC_Linear;
452 row[src_quality_cols.label] = _("Linear");
454 iter = src_quality_list->append();
455 row = *iter;
456 row[src_quality_cols.id] = ExportFormatBase::SRC_ZeroOrderHold;
457 row[src_quality_cols.label] = _("Zero order hold");
459 src_quality_combo.pack_start (src_quality_cols.label);
460 src_quality_combo.set_active (0);
463 void
464 ExportFormatDialog::init_encoding_option_widgets ()
466 Gtk::TreeViewColumn * label_col;
467 Gtk::CellRendererText * renderer;
469 sample_format_list = Gtk::ListStore::create (sample_format_cols);
470 sample_format_view.set_model (sample_format_list);
471 sample_format_view.set_headers_visible (false);
472 sample_format_view.append_column ("", sample_format_cols.label);
473 label_col = sample_format_view.get_column(0);
474 renderer = dynamic_cast<Gtk::CellRendererText*> (sample_format_view.get_column_cell_renderer (0));
475 label_col->add_attribute(renderer->property_foreground(), sample_format_cols.color);
477 dither_type_list = Gtk::ListStore::create (dither_type_cols);
478 dither_type_view.set_model (dither_type_list);
479 dither_type_view.set_headers_visible (false);
480 dither_type_view.append_column ("", dither_type_cols.label);
481 label_col = dither_type_view.get_column(0);
482 renderer = dynamic_cast<Gtk::CellRendererText*> (dither_type_view.get_column_cell_renderer (0));
483 label_col->add_attribute(renderer->property_foreground(), dither_type_cols.color);
487 void
488 ExportFormatDialog::update_compatibility_selection (Glib::ustring const & path)
491 Gtk::TreeModel::iterator iter = compatibility_view.get_model ()->get_iter (path);
492 ExportFormatManager::CompatPtr ptr = iter->get_value (compatibility_cols.ptr);
493 bool state = iter->get_value (compatibility_cols.selected);
495 iter->set_value (compatibility_cols.selected, state);
496 ptr->set_selected (state);
500 void
501 ExportFormatDialog::update_quality_selection ()
503 update_selection<QualityCols> (quality_list, quality_view, quality_cols);
506 void
507 ExportFormatDialog::update_format_selection ()
509 update_selection<FormatCols> (format_list, format_view, format_cols);
512 void
513 ExportFormatDialog::update_sample_rate_selection ()
515 update_selection<SampleRateCols> (sample_rate_list, sample_rate_view, sample_rate_cols);
518 void
519 ExportFormatDialog::update_sample_format_selection ()
521 update_selection<SampleFormatCols> (sample_format_list, sample_format_view, sample_format_cols);
524 void
525 ExportFormatDialog::update_dither_type_selection ()
527 update_selection<DitherTypeCols> (dither_type_list, dither_type_view, dither_type_cols);
530 template<typename ColsT>
531 void
532 ExportFormatDialog::update_selection (Glib::RefPtr<Gtk::ListStore> & list, Gtk::TreeView & view, ColsT & cols)
534 if (applying_changes_from_engine) {
535 return;
538 Gtk::ListStore::Children::iterator it;
539 Glib::RefPtr<Gtk::TreeSelection> selection = view.get_selection();
541 for (it = list->children().begin(); it != list->children().end(); ++it) {
542 bool selected = selection->is_selected (it);
543 it->get_value (cols.ptr)->set_selected (selected);
547 void
548 ExportFormatDialog::change_compatibility_selection (bool select, WeakCompatPtr compat)
550 ++applying_changes_from_engine;
552 ExportFormatManager::CompatPtr ptr = compat.lock();
554 for (Gtk::ListStore::Children::iterator it = compatibility_list->children().begin(); it != compatibility_list->children().end(); ++it) {
555 if (it->get_value (compatibility_cols.ptr) == ptr) {
556 it->set_value (compatibility_cols.selected, select);
557 break;
561 --applying_changes_from_engine;
564 void
565 ExportFormatDialog::change_quality_selection (bool select, WeakQualityPtr quality)
567 change_selection<ExportFormatManager::QualityState, QualityCols> (select, quality, quality_list, quality_view, quality_cols);
570 void
571 ExportFormatDialog::change_format_selection (bool select, WeakFormatPtr format)
573 change_selection<ExportFormat, FormatCols> (select, format, format_list, format_view, format_cols);
575 ExportFormatManager::FormatPtr ptr = format.lock();
577 if (select && ptr) {
578 change_encoding_options (ptr);
582 void
583 ExportFormatDialog::change_sample_rate_selection (bool select, WeakSampleRatePtr rate)
585 change_selection<ExportFormatManager::SampleRateState, SampleRateCols> (select, rate, sample_rate_list, sample_rate_view, sample_rate_cols);
587 if (select) {
588 ExportFormatManager::SampleRatePtr ptr = rate.lock();
589 if (ptr && _session) {
590 src_quality_combo.set_sensitive ((uint32_t) ptr->rate != _session->frame_rate());
595 void
596 ExportFormatDialog::change_sample_format_selection (bool select, WeakSampleFormatPtr format)
598 change_selection<HasSampleFormat::SampleFormatState, SampleFormatCols> (select, format, sample_format_list, sample_format_view, sample_format_cols);
601 void
602 ExportFormatDialog::change_dither_type_selection (bool select, WeakDitherTypePtr type)
604 change_selection<HasSampleFormat::DitherTypeState, DitherTypeCols> (select, type, dither_type_list, dither_type_view, dither_type_cols);
607 template<typename T, typename ColsT>
608 void
609 ExportFormatDialog::change_selection (bool select, boost::weak_ptr<T> w_ptr, Glib::RefPtr<Gtk::ListStore> & list, Gtk::TreeView & view, ColsT & cols)
611 ++applying_changes_from_engine;
613 boost::shared_ptr<T> ptr = w_ptr.lock();
615 Gtk::ListStore::Children::iterator it;
616 Glib::RefPtr<Gtk::TreeSelection> selection;
618 selection = view.get_selection();
620 if (!ptr) {
621 selection->unselect_all();
622 } else {
623 for (it = list->children().begin(); it != list->children().end(); ++it) {
624 if (it->get_value (cols.ptr) == ptr) {
625 if (select) {
626 selection->select (it);
627 } else {
628 selection->unselect (it);
630 break;
635 --applying_changes_from_engine;
638 void
639 ExportFormatDialog::change_quality_compatibility (bool compatibility, WeakQualityPtr quality)
641 change_compatibility<ExportFormatManager::QualityState, QualityCols> (compatibility, quality, quality_list, quality_cols);
644 void
645 ExportFormatDialog::change_format_compatibility (bool compatibility, WeakFormatPtr format)
647 change_compatibility<ExportFormat, FormatCols> (compatibility, format, format_list, format_cols);
650 void
651 ExportFormatDialog::change_sample_rate_compatibility (bool compatibility, WeakSampleRatePtr rate)
653 change_compatibility<ExportFormatManager::SampleRateState, SampleRateCols> (compatibility, rate, sample_rate_list, sample_rate_cols);
656 void
657 ExportFormatDialog::change_sample_format_compatibility (bool compatibility, WeakSampleFormatPtr format)
659 change_compatibility<HasSampleFormat::SampleFormatState, SampleFormatCols> (compatibility, format, sample_format_list, sample_format_cols);
662 void
663 ExportFormatDialog::change_dither_type_compatibility (bool compatibility, WeakDitherTypePtr type)
665 change_compatibility<HasSampleFormat::DitherTypeState, DitherTypeCols> (compatibility, type, dither_type_list, dither_type_cols, "red");
668 template<typename T, typename ColsT>
669 void
670 ExportFormatDialog::change_compatibility (bool compatibility, boost::weak_ptr<T> w_ptr, Glib::RefPtr<Gtk::ListStore> & list, ColsT & cols,
671 Glib::ustring const & c_incompatible, Glib::ustring const & c_compatible)
673 boost::shared_ptr<T> ptr = w_ptr.lock();
675 Gtk::ListStore::Children::iterator it;
676 for (it = list->children().begin(); it != list->children().end(); ++it) {
677 if (it->get_value (cols.ptr) == ptr) {
678 it->set_value (cols.color, compatibility ? c_compatible : c_incompatible);
679 break;
684 void
685 ExportFormatDialog::update_name ()
687 manager.set_name (name_entry.get_text());
690 void
691 ExportFormatDialog::update_trim_start_selection ()
693 manager.select_trim_beginning (trim_start_checkbox.get_active());
696 void
697 ExportFormatDialog::update_trim_end_selection ()
699 manager.select_trim_end (trim_end_checkbox.get_active());
702 void
703 ExportFormatDialog::update_normalize_selection ()
705 manager.select_normalize (normalize_checkbox.get_active());
706 manager.select_normalize_target (normalize_spinbutton.get_value ());
709 void
710 ExportFormatDialog::update_silence_start_selection ()
712 update_time (silence_start, silence_start_clock);
713 AnyTime zero;
714 zero.type = AnyTime::Timecode;
715 manager.select_silence_beginning (silence_start_checkbox.get_active() ? silence_start : zero);
718 void
719 ExportFormatDialog::update_silence_end_selection ()
721 update_time (silence_end, silence_end_clock);
722 AnyTime zero;
723 zero.type = AnyTime::Timecode;
724 manager.select_silence_end (silence_end_checkbox.get_active() ? silence_end : zero);
727 void
728 ExportFormatDialog::update_clock (AudioClock & clock, ARDOUR::AnyTime const & time)
730 // TODO position
731 clock.set (_session->convert_to_frames_at (0, time), true);
733 AudioClock::Mode mode(AudioClock::Timecode);
735 switch (time.type) {
736 case AnyTime::Timecode:
737 mode = AudioClock::Timecode;
738 break;
739 case AnyTime::BBT:
740 mode = AudioClock::BBT;
741 break;
742 case AnyTime::Frames:
743 mode = AudioClock::Frames;
744 break;
745 case AnyTime::Seconds:
746 mode = AudioClock::MinSec;
747 break;
750 clock.set_mode (mode);
753 void
754 ExportFormatDialog::update_time (AnyTime & time, AudioClock const & clock)
756 if (!_session) {
757 return;
760 nframes_t frames = clock.current_duration();
762 switch (clock.mode()) {
763 case AudioClock::Timecode:
764 time.type = AnyTime::Timecode;
765 _session->timecode_time (frames, time.timecode);
766 break;
767 case AudioClock::BBT:
768 time.type = AnyTime::BBT;
769 _session->bbt_time (frames, time.bbt);
770 break;
771 case AudioClock::MinSec:
772 time.type = AnyTime::Seconds;
773 time.seconds = (double) frames / _session->frame_rate();
774 break;
775 case AudioClock::Frames:
776 time.type = AnyTime::Frames;
777 time.frames = frames;
778 break;
779 case AudioClock::Off:
780 silence_end_checkbox.set_active (false);
781 return;
785 void
786 ExportFormatDialog::update_src_quality_selection ()
788 Gtk::TreeModel::const_iterator iter = src_quality_combo.get_active();
789 ExportFormatBase::SRCQuality quality = iter->get_value (src_quality_cols.id);
790 manager.select_src_quality (quality);
793 void
794 ExportFormatDialog::update_tagging_selection ()
796 manager.select_tagging (tag_checkbox.get_active());
799 void
800 ExportFormatDialog::change_encoding_options (ExportFormatManager::FormatPtr ptr)
802 empty_encoding_option_table ();
804 boost::shared_ptr<ARDOUR::ExportFormatLinear> linear_ptr;
805 boost::shared_ptr<ARDOUR::ExportFormatOggVorbis> ogg_ptr;
806 boost::shared_ptr<ARDOUR::ExportFormatFLAC> flac_ptr;
807 boost::shared_ptr<ARDOUR::ExportFormatBWF> bwf_ptr;
809 if (linear_ptr = boost::dynamic_pointer_cast<ExportFormatLinear> (ptr)) {
810 show_linear_enconding_options (linear_ptr);
811 } else if (ogg_ptr = boost::dynamic_pointer_cast<ExportFormatOggVorbis> (ptr)) {
812 show_ogg_enconding_options (ogg_ptr);
813 } else if (flac_ptr = boost::dynamic_pointer_cast<ExportFormatFLAC> (ptr)) {
814 show_flac_enconding_options (flac_ptr);
815 } else if (bwf_ptr = boost::dynamic_pointer_cast<ExportFormatBWF> (ptr)) {
816 show_bwf_enconding_options (bwf_ptr);
817 } else {
818 std::cout << "Unrecognized format!" << std::endl;
822 void
823 ExportFormatDialog::empty_encoding_option_table ()
825 encoding_options_table.foreach (sigc::bind (sigc::mem_fun (*this, &ExportFormatDialog::remove_widget), &encoding_options_table));
828 void
829 ExportFormatDialog::remove_widget (Gtk::Widget & to_remove, Gtk::Container * remove_from)
831 remove_from->remove (to_remove);
834 void
835 ExportFormatDialog::show_linear_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatLinear> ptr)
837 /* Set label and pack table */
839 encoding_options_label.set_label (_("Linear encoding options"));
841 encoding_options_table.resize (2, 2);
842 encoding_options_table.attach (sample_format_label, 0, 1, 0, 1);
843 encoding_options_table.attach (dither_label, 1, 2, 0, 1);
844 encoding_options_table.attach (sample_format_view, 0, 1, 1, 2);
845 encoding_options_table.attach (dither_type_view, 1, 2, 1, 2);
847 fill_sample_format_lists (boost::dynamic_pointer_cast<HasSampleFormat> (ptr));
849 show_all_children ();
852 void
853 ExportFormatDialog::show_ogg_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatOggVorbis> /*ptr*/)
855 encoding_options_label.set_label (_("Ogg Vorbis options"));
857 encoding_options_table.resize (1, 1);
858 encoding_options_table.attach (tag_checkbox, 0, 1, 0, 1);
860 update_tagging_selection ();
862 show_all_children ();
865 void
866 ExportFormatDialog::show_flac_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatFLAC> ptr)
868 encoding_options_label.set_label (_("FLAC options"));
870 encoding_options_table.resize (3, 2);
871 encoding_options_table.attach (sample_format_label, 0, 1, 0, 1);
872 encoding_options_table.attach (dither_label, 1, 2, 0, 1);
873 encoding_options_table.attach (sample_format_view, 0, 1, 1, 2);
874 encoding_options_table.attach (dither_type_view, 1, 2, 1, 2);
875 encoding_options_table.attach (tag_checkbox, 0, 2, 2, 3);
877 fill_sample_format_lists (boost::dynamic_pointer_cast<HasSampleFormat> (ptr));
879 show_all_children ();
882 void
883 ExportFormatDialog::show_bwf_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatBWF> ptr)
885 encoding_options_label.set_label (_("Broadcast Wave options"));
887 encoding_options_table.resize (2, 2);
888 encoding_options_table.attach (sample_format_label, 0, 1, 0, 1);
889 encoding_options_table.attach (dither_label, 1, 2, 0, 1);
890 encoding_options_table.attach (sample_format_view, 0, 1, 1, 2);
891 encoding_options_table.attach (dither_type_view, 1, 2, 1, 2);
893 fill_sample_format_lists (boost::dynamic_pointer_cast<HasSampleFormat> (ptr));
895 show_all_children ();
898 void
899 ExportFormatDialog::fill_sample_format_lists (boost::shared_ptr<ARDOUR::HasSampleFormat> ptr)
901 /* Fill lists */
903 Gtk::TreeModel::iterator iter;
904 Gtk::TreeModel::Row row;
906 sample_format_list->clear ();
908 HasSampleFormat::SampleFormatList const & formats = ptr->get_sample_formats ();
910 for (HasSampleFormat::SampleFormatList::const_iterator it = formats.begin(); it != formats.end(); ++it) {
911 iter = sample_format_list->append();
912 row = *iter;
914 row[sample_format_cols.ptr] = *it;
915 row[sample_format_cols.color] = (*it)->compatible() ? "white" : "red";
916 row[sample_format_cols.label] = (*it)->name();
918 if ((*it)->selected()) {
919 sample_format_view.get_selection()->select (iter);
923 dither_type_list->clear ();
925 HasSampleFormat::DitherTypeList const & types = ptr->get_dither_types ();
927 for (HasSampleFormat::DitherTypeList::const_iterator it = types.begin(); it != types.end(); ++it) {
928 iter = dither_type_list->append();
929 row = *iter;
931 row[dither_type_cols.ptr] = *it;
932 row[dither_type_cols.color] = "white";
933 row[dither_type_cols.label] = (*it)->name();
935 if ((*it)->selected()) {
936 dither_type_view.get_selection()->select (iter);
941 void
942 ExportFormatDialog::end_dialog ()
944 hide_all ();
947 void
948 ExportFormatDialog::prohibit_compatibility_selection ()
950 compatibility_select_connection.block (true);
951 compatibility_view.get_selection()->unselect_all ();
952 compatibility_select_connection.block (false);