2 Copyright (C) 1999-2005 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <samplerate.h>
28 #include <pbd/convert.h>
29 #include <pbd/xml++.h>
31 #include <gtkmm2ext/utils.h>
32 #include <ardour/export.h>
33 #include <ardour/sndfile_helpers.h>
34 #include <ardour/audio_track.h>
35 #include <ardour/audioregion.h>
36 #include <ardour/audioengine.h>
37 #include <ardour/gdither.h>
38 #include <ardour/utils.h>
40 #include "export_dialog.h"
41 #include "ardour_ui.h"
42 #include "public_editor.h"
47 #define FRAME_NAME "BaseFrame"
50 using namespace ARDOUR;
55 static const gchar *sample_rates[] = {
65 static const gchar *src_quality[] = {
74 static const gchar *dither_types[] = {
82 static const gchar* channel_strings[] = {
88 static const gchar* cue_file_types[] = {
95 ExportDialog::ExportDialog(PublicEditor& e)
96 : ArdourDialog ("export dialog"),
99 format_frame (_("Format")),
100 cue_file_label (_("CD Marker File Type"), 1.0, 0.5),
101 channel_count_label (_("Channels"), 1.0, 0.5),
102 header_format_label (_("File Type"), 1.0, 0.5),
103 bitdepth_format_label (_("Sample Format"), 1.0, 0.5),
104 endian_format_label (_("Sample Endianness"), 1.0, 0.5),
105 sample_rate_label (_("Sample Rate"), 1.0, 0.5),
106 src_quality_label (_("Conversion Quality"), 1.0, 0.5),
107 dither_type_label (_("Dither Type"), 1.0, 0.5),
108 cuefile_only_checkbox (_("Export CD Marker File Only")),
109 file_frame (_("Export to File")),
110 file_browse_button (_("Browse")),
111 track_selector_button (_("Specific tracks ..."))
118 track_and_master_selection_allowed = true;
119 channel_count_selection_allowed = true;
120 export_cd_markers_allowed = true;
122 set_title (_("ardour: export"));
123 set_wmclass (X_("ardour_export"), "Ardour");
124 set_name ("ExportWindow");
125 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
127 spec.running = false;
129 file_entry.set_name ("ExportFileNameEntry");
131 master_list = ListStore::create (exp_cols);
132 master_selector.set_model (master_list);
134 master_selector.set_name ("ExportTrackSelector");
135 master_selector.set_size_request (-1, 100);
136 master_selector.append_column(_("Output"), exp_cols.output);
137 master_selector.append_column_editable(_("Left"), exp_cols.left);
138 master_selector.append_column_editable(_("Right"), exp_cols.right);
139 master_selector.get_column(0)->set_min_width(100);
141 master_selector.get_column(1)->set_min_width(40);
142 master_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
143 master_selector.get_column(2)->set_min_width(40);
144 master_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
145 master_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
147 track_list = ListStore::create (exp_cols);
148 track_selector.set_model (track_list);
150 track_selector.set_name ("ExportTrackSelector");
151 track_selector.set_size_request (-1, 130);
152 track_selector.append_column(_("Output"), exp_cols.output);
153 track_selector.append_column_editable(_("Left"), exp_cols.left);
154 track_selector.append_column_editable(_("Right"), exp_cols.right);
156 track_selector.get_column(0)->set_min_width(100);
157 track_selector.get_column(1)->set_min_width(40);
158 track_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
159 track_selector.get_column(2)->set_min_width(40);
160 track_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
161 track_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
163 progress_bar.set_name ("ExportProgress");
165 format_frame.add (format_table);
166 format_frame.set_name (FRAME_NAME);
168 track_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
169 master_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
171 get_vbox()->pack_start (file_frame, false, false);
173 hpacker.set_spacing (5);
174 hpacker.set_border_width (5);
175 hpacker.pack_start (format_frame, false, false);
177 master_scroll.add (master_selector);
178 track_scroll.add (track_selector);
180 master_scroll.set_size_request (220, 100);
181 track_scroll.set_size_request (220, 100);
183 /* we may hide some of these later */
184 track_vpacker.pack_start (master_scroll);
185 track_vpacker.pack_start (track_scroll);
186 track_vpacker.pack_start (track_selector_button, Gtk::PACK_EXPAND_PADDING);
188 hpacker.pack_start (track_vpacker);
190 get_vbox()->pack_start (hpacker);
192 track_selector_button.set_name ("EditorGTKButton");
193 track_selector_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::track_selector_button_click));
195 get_vbox()->pack_start (progress_bar, false, false);
197 Gtkmm2ext::set_size_request_to_display_given_text (file_entry, X_("Kg/quite/a/reasonable/size/for/files/i/think"), 5, 8);
199 file_hbox.set_spacing (5);
200 file_hbox.set_border_width (5);
201 file_hbox.pack_start (file_entry, true, true);
202 file_hbox.pack_start (file_browse_button, false, false);
204 file_frame.add (file_hbox);
205 file_frame.set_border_width (5);
206 file_frame.set_name (FRAME_NAME);
208 /* pop_strings needs to be created on the stack because set_popdown_strings()
212 vector<string> pop_strings = I18N (sample_rates);
213 Gtkmm2ext::set_popdown_strings (sample_rate_combo, pop_strings);
214 sample_rate_combo.set_active_text (pop_strings.front());
215 pop_strings = I18N (src_quality);
216 Gtkmm2ext::set_popdown_strings (src_quality_combo, pop_strings);
217 src_quality_combo.set_active_text (pop_strings.front());
218 pop_strings = I18N (dither_types);
219 Gtkmm2ext::set_popdown_strings (dither_type_combo, pop_strings);
220 dither_type_combo.set_active_text (pop_strings.front());
221 pop_strings = I18N (channel_strings);
222 Gtkmm2ext::set_popdown_strings (channel_count_combo, pop_strings);
223 channel_count_combo.set_active_text (pop_strings.front());
224 pop_strings = I18N ((const char **) sndfile_header_formats_strings);
225 Gtkmm2ext::set_popdown_strings (header_format_combo, pop_strings);
226 header_format_combo.set_active_text (pop_strings.front());
227 pop_strings = I18N ((const char **) sndfile_bitdepth_formats_strings);
228 Gtkmm2ext::set_popdown_strings (bitdepth_format_combo, pop_strings);
229 bitdepth_format_combo.set_active_text (pop_strings.front());
230 pop_strings = I18N ((const char **) sndfile_endian_formats_strings);
231 Gtkmm2ext::set_popdown_strings (endian_format_combo, pop_strings);
232 endian_format_combo.set_active_text (pop_strings.front());
233 pop_strings = I18N (cue_file_types);
234 Gtkmm2ext::set_popdown_strings (cue_file_combo, pop_strings);
235 cue_file_combo.set_active_text (pop_strings.front());
237 /* this will re-sensitized as soon as a non RIFF/WAV
238 header format is chosen.
241 endian_format_combo.set_sensitive (false);
243 /* determine longest strings at runtime */
246 const char *longest = X_("gl"); /* translators: one ascender, one descender */
249 for (n = 0; n < SNDFILE_HEADER_FORMATS; ++n) {
250 if ((len = strlen (sndfile_header_formats_strings[n])) > maxlen) {
252 longest = sndfile_header_formats_strings[n];
256 for (n = 0; n < SNDFILE_BITDEPTH_FORMATS; ++n) {
257 if ((len = strlen (sndfile_bitdepth_formats_strings[n])) > maxlen) {
259 longest = sndfile_bitdepth_formats_strings[n];
263 for (n = 0; n < SNDFILE_ENDIAN_FORMATS; ++n) {
264 if ((len = strlen (sndfile_endian_formats_strings[n])) > maxlen) {
266 longest = sndfile_endian_formats_strings[n];
270 longest_str = longest;
272 /* force ascender + descender */
274 longest_str[0] = 'g';
275 longest_str[1] = 'l';
277 //Gtkmm2ext::set_size_request_to_display_given_text (header_format_combo, longest_str.c_str(), 5+FUDGE, 5);
279 // TRANSLATORS: "slereg" is "stereo" with ascender and descender substituted
280 //Gtkmm2ext::set_size_request_to_display_given_text (channel_count_combo, _("slereg"), 5+FUDGE, 5);
282 /* header_format_combo.set_focus_on_click (true);
283 bitdepth_format_combo.set_focus_on_click (true);
284 endian_format_combo.set_focus_on_click (true);
285 channel_count_combo.set_focus_on_click (true);
286 src_quality_combo.set_focus_on_click (true);
287 dither_type_combo.set_focus_on_click (true);
288 sample_rate_combo.set_focus_on_click (true);
289 cue_file_combo.set_focus_on_click (true);
291 dither_type_label.set_name ("ExportFormatLabel");
292 sample_rate_label.set_name ("ExportFormatLabel");
293 src_quality_label.set_name ("ExportFormatLabel");
294 channel_count_label.set_name ("ExportFormatLabel");
295 header_format_label.set_name ("ExportFormatLabel");
296 bitdepth_format_label.set_name ("ExportFormatLabel");
297 endian_format_label.set_name ("ExportFormatLabel");
298 cue_file_label.set_name ("ExportFormatLabel");
300 header_format_combo.set_name ("ExportFormatDisplay");
301 bitdepth_format_combo.set_name ("ExportFormatDisplay");
302 endian_format_combo.set_name ("ExportFormatDisplay");
303 channel_count_combo.set_name ("ExportFormatDisplay");
304 dither_type_combo.set_name ("ExportFormatDisplay");
305 src_quality_combo.set_name ("ExportFormatDisplay");
306 sample_rate_combo.set_name ("ExportFormatDisplay");
307 cue_file_combo.set_name ("ExportFormatDisplay");
309 cuefile_only_checkbox.set_name ("ExportCheckbox");
311 format_table.set_homogeneous (false);
312 format_table.set_border_width (5);
313 format_table.set_col_spacings (5);
314 format_table.set_row_spacings (5);
316 format_table.attach (channel_count_label, 0, 1, 0, 1);
317 format_table.attach (channel_count_combo, 1, 2, 0, 1);
319 format_table.attach (header_format_label, 0, 1, 1, 2);
320 format_table.attach (header_format_combo, 1, 2, 1, 2);
322 format_table.attach (bitdepth_format_label, 0, 1, 2, 3);
323 format_table.attach (bitdepth_format_combo, 1, 2, 2, 3);
325 format_table.attach (endian_format_label, 0, 1, 3, 4);
326 format_table.attach (endian_format_combo, 1, 2, 3, 4);
328 format_table.attach (sample_rate_label, 0, 1, 4, 5);
329 format_table.attach (sample_rate_combo, 1, 2, 4, 5);
331 format_table.attach (src_quality_label, 0, 1, 5, 6);
332 format_table.attach (src_quality_combo, 1, 2, 5, 6);
334 format_table.attach (dither_type_label, 0, 1, 6, 7);
335 format_table.attach (dither_type_combo, 1, 2, 6, 7);
337 format_table.attach (cue_file_label, 0, 1, 7, 8);
338 format_table.attach (cue_file_combo, 1, 2, 7, 8);
339 format_table.attach (cuefile_only_checkbox, 0, 2, 8, 9);
341 file_entry.set_name ("ExportFileDisplay");
343 signal_delete_event().connect (mem_fun(*this, &ExportDialog::window_closed));
345 cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
346 cancel_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::end_dialog));
347 ok_button = add_button (_("Export"), RESPONSE_ACCEPT);
348 ok_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::do_export));
350 file_browse_button.set_name ("EditorGTKButton");
351 file_browse_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::browse));
353 channel_count_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::channels_chosen));
354 bitdepth_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::bitdepth_chosen));
355 header_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::header_chosen));
356 sample_rate_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::sample_rate_chosen));
357 cue_file_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::cue_file_type_chosen));
360 ExportDialog::~ExportDialog()
365 ExportDialog::do_not_allow_track_and_master_selection()
367 track_and_master_selection_allowed = false;
368 track_vpacker.set_no_show_all();
372 ExportDialog::do_not_allow_channel_count_selection()
374 channel_count_selection_allowed = false;
375 channel_count_combo.set_no_show_all();
376 channel_count_label.set_no_show_all();
380 ExportDialog::do_not_allow_export_cd_markers()
382 export_cd_markers_allowed = false;
383 cue_file_label.set_no_show_all();
384 cue_file_combo.set_no_show_all();
385 cuefile_only_checkbox.set_no_show_all();
389 ExportDialog::connect_to_session (Session *s)
392 session->GoingAway.connect (mem_fun(*this, &Window::hide_all));
394 switch (session->frame_rate()) {
396 sample_rate_combo.set_active_text (N_("22.05kHz"));
399 sample_rate_combo.set_active_text (N_("44.1kHz"));
402 sample_rate_combo.set_active_text (N_("48kHz"));
405 sample_rate_combo.set_active_text (N_("88.2kHz"));
408 sample_rate_combo.set_active_text (N_("96kHz"));
411 sample_rate_combo.set_active_text (N_("192kHz"));
414 sample_rate_combo.set_active_text (N_("44.1kHz"));
418 src_quality_combo.set_sensitive (false);
424 ExportDialog::set_state()
426 XMLNode* node = session->instant_xml(X_("ExportDialog"), session->path());
431 if ((prop = node->property (X_("sample_rate"))) != 0) {
432 sample_rate_combo.set_active_text(prop->value());
434 if ((prop = node->property (X_("src_quality"))) != 0) {
435 src_quality_combo.set_active_text(prop->value());
437 if ((prop = node->property (X_("dither_type"))) != 0) {
438 dither_type_combo.set_active_text(prop->value());
440 if ((prop = node->property (X_("channel_count"))) != 0) {
441 channel_count_combo.set_active_text(prop->value());
443 if ((prop = node->property (X_("header_format"))) != 0) {
444 header_format_combo.set_active_text(prop->value());
446 if ((prop = node->property (X_("bitdepth_format"))) != 0) {
447 bitdepth_format_combo.set_active_text(prop->value());
449 if ((prop = node->property (X_("endian_format"))) != 0) {
450 endian_format_combo.set_active_text(prop->value());
452 if ((prop = node->property (X_("filename"))) != 0) {
453 file_entry.set_text(prop->value());
455 if ((prop = node->property (X_("cue_file_type"))) != 0) {
456 cue_file_combo.set_active_text(prop->value());
463 sample_rate_chosen();
465 if (session->master_out()) {
466 track_scroll.hide ();
468 master_scroll.hide ();
469 track_selector_button.hide ();
476 if (session->master_out()) {
477 XMLNode* master = find_named_node(*node, (X_("Master")));
482 /* default is to use all */
483 if (channel_count_combo.get_active_text() == _("mono")) {
489 TreeModel::Children rows = master_selector.get_model()->children();
490 for (uint32_t r = 0; r < session->master_out()->n_outputs(); ++r) {
493 rows[r][exp_cols.right] = true;
495 rows[r][exp_cols.left] = true;
498 rows[r][exp_cols.left] = true;
503 /* XXX use XML state */
507 XMLNode* tracks = find_named_node(*node, (X_("Tracks")));
512 XMLNodeList track_list = tracks->children(X_("Track"));
513 TreeModel::Children rows = track_selector.get_model()->children();
514 TreeModel::Children::iterator ri = rows.begin();
517 for (XMLNodeIterator it = track_list.begin(); it != track_list.end(); ++it, ++ri) {
518 if (ri == rows.end()){
522 XMLNode* track = *it;
525 if ((prop = track->property(X_("channel1"))) != 0) {
526 if (prop->value() == X_("on")) {
527 row[exp_cols.left] = true;
529 row[exp_cols.left] = false;
533 if ((prop = track->property(X_("channel2"))) != 0) {
534 if (prop->value() == X_("on")) {
535 row[exp_cols.right] = true;
537 row[exp_cols.right] = false;
544 ExportDialog::save_state()
550 XMLNode* node = new XMLNode(X_("ExportDialog"));
552 node->add_property(X_("sample_rate"), sample_rate_combo.get_active_text());
553 node->add_property(X_("src_quality"), src_quality_combo.get_active_text());
554 node->add_property(X_("dither_type"), dither_type_combo.get_active_text());
555 node->add_property(X_("channel_count"), channel_count_combo.get_active_text());
556 node->add_property(X_("header_format"), header_format_combo.get_active_text());
557 node->add_property(X_("bitdepth_format"), bitdepth_format_combo.get_active_text());
558 node->add_property(X_("endian_format"), endian_format_combo.get_active_text());
559 node->add_property(X_("filename"), file_entry.get_text());
560 node->add_property(X_("cue_file_type"), cue_file_combo.get_active_text());
562 XMLNode* tracks = new XMLNode(X_("Tracks"));
564 TreeModel::Children rows = track_selector.get_model()->children();
566 for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
567 XMLNode* track = new XMLNode(X_("Track"));
570 track->add_property(X_("channel1"), row[exp_cols.left] ? X_("on") : X_("off"));
571 track->add_property(X_("channel2"), row[exp_cols.right] ? X_("on") : X_("off"));
573 tracks->add_child_nocopy(*track);
575 node->add_child_nocopy(*tracks);
577 session->add_instant_xml(*node, session->path());
581 ExportDialog::set_range (nframes_t start, nframes_t end)
583 spec.start_frame = start;
584 spec.end_frame = end;
588 ExportDialog::progress_timeout ()
590 progress_bar.set_fraction (spec.progress);
595 frames_to_cd_frames_string (char* buf, nframes_t when, nframes_t fr)
598 long unsigned int remainder;
599 int mins, secs, frames;
601 mins = when / (60 * fr);
602 remainder = when - (mins * 60 * fr);
603 secs = remainder / fr;
604 remainder -= secs * fr;
605 frames = remainder / (fr / 75);
606 sprintf (buf, " %02d:%02d:%02d", mins, secs, frames);
610 struct LocationSortByStart {
611 bool operator() (Location *a, Location *b) {
612 return a->start() < b->start();
617 ExportDialog::export_toc_file (Locations::LocationList& locations, const string& path)
619 if(!export_cd_markers_allowed){
623 string filepath = path + ".toc";
624 ofstream out (filepath.c_str());
625 long unsigned int last_end_time = spec.start_frame, last_start_time = spec.start_frame;
630 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD toc file"), filepath) << endmsg;
633 out << "CD_DA" << endl;
634 out << "CD_TEXT {" << endl << " LANGUAGE_MAP {" << endl << " 0 : EN" << endl << " }" << endl;
635 out << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl << " }" << endl << "}" << endl;
637 Locations::LocationList::iterator i;
638 Locations::LocationList temp;
640 for (i = locations.begin(); i != locations.end(); ++i) {
641 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
643 if (!(*i)->is_mark()) {
649 if (numtracks == 0 ) {
650 /* the user supplied no track markers.
651 we now treat the session as one track.*/
653 out << endl << "TRACK AUDIO" << endl;
655 out << "COPY" << endl;
657 out << "NO PRE_EMPHASIS" << endl;
659 /* XXX add session properties for catalog etc.
660 (so far only the session name is used) */
662 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl;
663 out << " }" << endl << "}" << endl;
665 out << "FILE \"" << path << "\" ";
667 frames_to_cd_frames_string (buf, spec.end_frame - spec.start_frame, session->frame_rate());
669 out << "START 00:00:00" << endl;
671 last_start_time = spec.start_frame;
672 last_end_time = spec.end_frame;
676 LocationSortByStart cmp;
679 for (i = temp.begin(); i != temp.end(); ++i) {
681 if (!(*i)->is_mark()) {
683 out << endl << "TRACK AUDIO" << endl;
685 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
688 out << "COPY" << endl;
690 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
691 out << "PRE_EMPHASIS" << endl;
693 out << "NO PRE_EMPHASIS" << endl;
696 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
697 out << "ISRC \"" << (*i)->cd_info["isrc"] << "\"" << endl;
700 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << (*i)->name() << "\"" << endl;
701 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
702 out << " PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
704 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
705 out << " COMPOSER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
708 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
710 out << (*i)->cd_info["isrc"].substr(0,2) << "-";
711 out << (*i)->cd_info["isrc"].substr(2,3) << "-";
712 out << (*i)->cd_info["isrc"].substr(5,2) << "-";
713 out << (*i)->cd_info["isrc"].substr(7,5) << "\"" << endl;
716 out << " }" << endl << "}" << endl;
718 frames_to_cd_frames_string (buf, last_end_time - spec.start_frame, session->frame_rate());
719 out << "FILE \"" << path << "\" " << buf;
721 frames_to_cd_frames_string (buf, (*i)->end() - last_end_time, session->frame_rate());
724 frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
725 out << "START" << buf << endl;
727 last_start_time = (*i)->start();
728 last_end_time = (*i)->end();
731 } else if ((*i)->start() < last_end_time) {
732 /* this is an index within a track */
734 frames_to_cd_frames_string (buf, (*i)->start() - last_start_time, session->frame_rate());
735 out << "INDEX" << buf << endl;
743 ExportDialog::export_cue_file (Locations::LocationList& locations, const string& path)
745 if(!export_cd_markers_allowed){
749 string filepath = path + ".cue";
750 ofstream out (filepath.c_str());
752 long unsigned int last_track_end = spec.start_frame;
753 int numtracks = 0, tracknum = 0, indexnum = 0;
756 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD cue file"), filepath) << endmsg;
760 Locations::LocationList::iterator i;
761 Locations::LocationList temp;
763 for (i = locations.begin(); i != locations.end(); ++i) {
764 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
766 if (!(*i)->is_mark()) {
772 out << "REM Cue file generated by Ardour" << endl;
773 out << "TITLE \"" << session->name() << "\"" << endl;
775 if ((header_format_combo.get_active_text() == N_("WAV"))) {
776 out << "FILE " << path << " WAVE" << endl;
778 out << "FILE " << path << ' ' << (header_format_combo.get_active_text()) << endl;
781 if (numtracks == 0) {
782 /* the user has supplied no track markers.
783 the entire export is treated as one track.
789 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
792 out << "DCP " << endl;
794 /* use the session name*/
796 if (session->name() != "") {
797 out << "TITLE \"" << session->name() << "\"" << endl;
800 /* no pregap in this case */
802 out << "INDEX 00 00:00:00" << endl;
804 out << "INDEX 01 00:00:00" << endl;
806 last_track_end = spec.end_frame;
810 LocationSortByStart cmp;
813 for ( i = temp.begin(); i != temp.end(); ++i) {
815 if (!(*i)->is_mark() && ((*i)->start() >= last_track_end)) {
816 /* this is a track and it doesn't start inside another one*/
820 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
823 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
829 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
834 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
835 out << "ISRC " << (*i)->cd_info["isrc"] << endl;
838 if ((*i)->name() != "") {
839 out << "TITLE \"" << (*i)->name() << "\"" << endl;
842 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
843 out << "PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
846 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
847 out << "SONGWRITER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
849 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
851 frames_to_cd_frames_string (buf, last_track_end - spec.start_frame, session->frame_rate());
854 last_track_end = (*i)->end();
856 if ((tracknum > 0) && ((*i)->start() < last_track_end)) {
857 /*this is an index and it lies within a track*/
858 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
860 frames_to_cd_frames_string (buf,(*i)->start() - spec.start_frame, session->frame_rate());
870 ExportDialog::do_export_cd_markers (const string& path,const string& cuefile_type)
872 if (cuefile_type == "TOC") {
873 session->locations()->apply (*this, &ExportDialog::export_toc_file, path);
875 session->locations()->apply (*this, &ExportDialog::export_cue_file, path);
881 ExportDialog::do_export ()
883 string filepath = file_entry.get_text();
885 if(!is_filepath_valid(filepath)){
889 if (export_cd_markers_allowed) {
890 if (cue_file_combo.get_active_text () != _("None")) {
891 do_export_cd_markers (file_entry.get_text(), cue_file_combo.get_active_text ());
894 if (cuefile_only_checkbox.get_active()) {
900 ok_button->set_sensitive(false);
905 // read user input into spec
908 progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
909 cancel_label.set_text (_("Stop Export"));
913 progress_connection.disconnect ();
918 ExportDialog::end_dialog ()
924 while (spec.running) {
925 if (gtk_events_pending()) {
926 gtk_main_iteration ();
933 session->engine().freewheel (false);
938 ok_button->set_sensitive(true);
942 ExportDialog::start_export ()
948 /* If the filename hasn't been set before, use the
949 current session's export directory as a default
950 location for the export.
953 if (file_entry.get_text().length() == 0) {
954 string dir = session->export_dir();
955 string::size_type last_slash;
957 if ((last_slash = dir.find_last_of ('/')) != string::npos && last_slash != 0) {
958 dir = dir.substr (0, last_slash+1);
962 dir = dir + "export.wav";
965 file_entry.set_text (dir);
968 progress_bar.set_fraction (0);
969 cancel_label.set_text (_("Cancel"));
973 if (session->master_out()) {
974 track_scroll.hide ();
976 master_scroll.hide ();
977 track_selector_button.hide ();
982 ExportDialog::header_chosen ()
984 if (sndfile_header_format_from_string (header_format_combo.get_active_text ()) == SF_FORMAT_WAV) {
985 endian_format_combo.set_sensitive (false);
987 endian_format_combo.set_sensitive (true);
992 ExportDialog::bitdepth_chosen ()
994 int format = sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
996 case SF_FORMAT_PCM_24:
997 case SF_FORMAT_PCM_32:
998 case SF_FORMAT_FLOAT:
999 dither_type_combo.set_sensitive (false);
1003 dither_type_combo.set_sensitive (true);
1009 ExportDialog::cue_file_type_chosen ()
1011 if (cue_file_combo.get_active_text () != "None") {
1012 cuefile_only_checkbox.set_sensitive (true);
1014 cuefile_only_checkbox.set_active (false);
1015 cuefile_only_checkbox.set_sensitive (false);
1020 ExportDialog::sample_rate_chosen ()
1022 string sr_str = sample_rate_combo.get_active_text();
1025 if (sr_str == N_("22.05kHz")) {
1027 } else if (sr_str == N_("44.1kHz")) {
1029 } else if (sr_str == N_("48kHz")) {
1031 } else if (sr_str == N_("88.2kHz")) {
1033 } else if (sr_str == N_("96kHz")) {
1035 } else if (sr_str == N_("192kHz")) {
1038 rate = session->frame_rate();
1041 if (rate != session->frame_rate()) {
1042 src_quality_combo.set_sensitive (true);
1044 src_quality_combo.set_sensitive (false);
1049 ExportDialog::channels_chosen ()
1053 mono = (channel_count_combo.get_active_text() == _("mono"));
1056 track_selector.get_column(2)->set_visible(false);
1057 track_selector.get_column(1)->set_title(_("Export"));
1059 if (session->master_out()) {
1060 master_selector.get_column(2)->set_visible(false);
1061 master_selector.get_column(1)->set_title(_("Export"));
1065 track_selector.get_column(2)->set_visible(true);
1066 track_selector.get_column(1)->set_title(_("Left"));
1068 if (session->master_out()) {
1069 master_selector.get_column(2)->set_visible(true);
1070 master_selector.get_column(1)->set_title(_("Left"));
1078 ExportDialog::fill_lists ()
1080 track_list->clear();
1081 master_list->clear();
1083 boost::shared_ptr<Session::RouteList> routes = session->get_routes ();
1085 for (Session::RouteList::iterator ri = routes->begin(); ri != routes->end(); ++ri) {
1087 boost::shared_ptr<Route> route = (*ri);
1089 if (route->hidden()) {
1093 for (uint32_t i=0; i < route->n_outputs(); ++i) {
1095 if (route->n_outputs() == 1) {
1096 name = route->name();
1098 name = string_compose("%1: out-%2", route->name(), i+1);
1101 if (route == session->master_out()) {
1102 TreeModel::iterator iter = master_list->append();
1103 TreeModel::Row row = *iter;
1104 row[exp_cols.output] = name;
1105 row[exp_cols.left] = false;
1106 row[exp_cols.right] = false;
1107 row[exp_cols.port] = route->output (i);
1109 TreeModel::iterator iter = track_list->append();
1110 TreeModel::Row row = *iter;
1111 row[exp_cols.output] = name;
1112 row[exp_cols.left] = false;
1113 row[exp_cols.right] = false;
1114 row[exp_cols.port] = route->output (i);
1122 ExportDialog::is_filepath_valid(string &filepath)
1124 // sanity check file name first
1126 struct stat statbuf;
1128 if (filepath.empty()) {
1129 string txt = _("Please enter a valid filename.");
1130 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1135 // check if file exists already and warn
1137 if (stat (filepath.c_str(), &statbuf) == 0) {
1138 if (S_ISDIR (statbuf.st_mode)) {
1139 string txt = _("Please specify a complete filename for the audio file.");
1140 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1145 string txt = _("File already exists, do you want to overwrite it?");
1146 MessageDialog msg (*this, txt, false, MESSAGE_QUESTION, BUTTONS_YES_NO, true);
1147 if ((ResponseType) msg.run() == Gtk::RESPONSE_NO) {
1153 // directory needs to exist and be writable
1155 string dirpath = Glib::path_get_dirname (filepath);
1156 if (::access (dirpath.c_str(), W_OK) != 0) {
1157 string txt = _("Cannot write file in: ") + dirpath;
1158 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1167 ExportDialog::initSpec(string &filepath)
1169 spec.path = filepath;
1171 spec.running = true;
1173 spec.port_map.clear();
1175 if (channel_count_combo.get_active_text() == _("mono")) {
1183 spec.format |= sndfile_header_format_from_string (header_format_combo.get_active_text ());
1185 if ((spec.format & SF_FORMAT_WAV) == 0) {
1186 /* RIFF/WAV specifies endianess */
1187 spec.format |= sndfile_endian_format_from_string (endian_format_combo.get_active_text ());
1190 spec.format |= sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
1192 string sr_str = sample_rate_combo.get_active_text();
1193 if (sr_str == N_("22.05kHz")) {
1194 spec.sample_rate = 22050;
1195 } else if (sr_str == N_("44.1kHz")) {
1196 spec.sample_rate = 44100;
1197 } else if (sr_str == N_("48kHz")) {
1198 spec.sample_rate = 48000;
1199 } else if (sr_str == N_("88.2kHz")) {
1200 spec.sample_rate = 88200;
1201 } else if (sr_str == N_("96kHz")) {
1202 spec.sample_rate = 96000;
1203 } else if (sr_str == N_("192kHz")) {
1204 spec.sample_rate = 192000;
1206 spec.sample_rate = session->frame_rate();
1209 string src_str = src_quality_combo.get_active_text();
1210 if (src_str == _("fastest")) {
1211 spec.src_quality = SRC_ZERO_ORDER_HOLD;
1212 } else if (src_str == _("linear")) {
1213 spec.src_quality = SRC_LINEAR;
1214 } else if (src_str == _("better")) {
1215 spec.src_quality = SRC_SINC_FASTEST;
1216 } else if (src_str == _("intermediate")) {
1217 spec.src_quality = SRC_SINC_MEDIUM_QUALITY;
1219 spec.src_quality = SRC_SINC_BEST_QUALITY;
1222 string dither_str = dither_type_combo.get_active_text();
1223 if (dither_str == _("None")) {
1224 spec.dither_type = GDitherNone;
1225 } else if (dither_str == _("Rectangular")) {
1226 spec.dither_type = GDitherRect;
1227 } else if (dither_str == _("Triangular")) {
1228 spec.dither_type = GDitherTri;
1230 spec.dither_type = GDitherShaped;
1233 write_track_and_master_selection_to_spec();
1238 ExportDialog::write_track_and_master_selection_to_spec()
1240 if(!track_and_master_selection_allowed){
1245 Port *last_port = 0;
1247 TreeModel::Children rows = master_selector.get_model()->children();
1248 TreeModel::Children::iterator ri;
1250 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1252 Port* port = row[exp_cols.port];
1254 if (last_port != port) {
1258 if (row[exp_cols.left]) {
1259 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1262 if (spec.channels == 2) {
1263 if (row[exp_cols.right]) {
1264 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1270 rows = track_selector.get_model()->children();
1272 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1275 Port* port = row[exp_cols.port];
1277 if (last_port != port) {
1281 if (row[exp_cols.left]) {
1282 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1285 if (spec.channels == 2) {
1286 if (row[exp_cols.right]) {
1287 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1299 ExportDialog::window_closed (GdkEventAny *ignored)
1306 ExportDialog::browse ()
1308 FileChooserDialog dialog("Export to file", FILE_CHOOSER_ACTION_SAVE);
1309 dialog.set_transient_for(*this);
1310 dialog.set_filename (file_entry.get_text());
1312 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1313 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
1315 int result = dialog.run();
1317 if (result == Gtk::RESPONSE_OK) {
1318 string filename = dialog.get_filename();
1320 if (filename.length()) {
1321 file_entry.set_text (filename);
1327 ExportDialog::track_selector_button_click ()
1329 if (track_scroll.is_visible ()) {
1330 track_scroll.hide ();
1332 track_scroll.show_all ();