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 <gtkmm2ext/window_title.h>
34 #include <ardour/export.h>
35 #include <ardour/session_directory.h>
36 #include <ardour/sndfile_helpers.h>
37 #include <ardour/audio_track.h>
38 #include <ardour/audioregion.h>
39 #include <ardour/audioengine.h>
40 #include <ardour/gdither.h>
41 #include <ardour/utils.h>
43 #include "export_dialog.h"
44 #include "ardour_ui.h"
45 #include "public_editor.h"
50 #define FRAME_NAME "BaseFrame"
53 using namespace ARDOUR;
57 using namespace Gtkmm2ext;
59 using PBD::internationalize;
61 static const gchar *sample_rates[] = {
71 static const gchar *src_quality[] = {
80 static const gchar *dither_types[] = {
88 static const gchar* channel_strings[] = {
94 static const gchar* cue_file_types[] = {
101 ExportDialog::ExportDialog(PublicEditor& e)
102 : ArdourDialog ("export dialog"),
105 format_frame (_("Format")),
106 cue_file_label (_("CD Marker File Type"), 1.0, 0.5),
107 channel_count_label (_("Channels"), 1.0, 0.5),
108 header_format_label (_("File Type"), 1.0, 0.5),
109 bitdepth_format_label (_("Sample Format"), 1.0, 0.5),
110 endian_format_label (_("Sample Endianness"), 1.0, 0.5),
111 sample_rate_label (_("Sample Rate"), 1.0, 0.5),
112 src_quality_label (_("Conversion Quality"), 1.0, 0.5),
113 dither_type_label (_("Dither Type"), 1.0, 0.5),
114 cuefile_only_checkbox (_("Export CD Marker File Only")),
115 file_browse_button (_("Browse")),
116 track_selector_button (_("Specific tracks ..."))
123 track_and_master_selection_allowed = true;
124 channel_count_selection_allowed = true;
125 export_cd_markers_allowed = true;
127 WindowTitle title(Glib::get_application_name());
128 title += _("Export");
130 set_title (title.get_string());
131 set_wmclass (X_("ardour_export"), "Ardour");
132 set_name ("ExportWindow");
133 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
135 spec.running = false;
137 file_entry.set_name ("ExportFileNameEntry");
139 master_list = ListStore::create (exp_cols);
140 master_selector.set_model (master_list);
142 master_selector.set_name ("ExportTrackSelector");
143 master_selector.set_size_request (-1, 100);
144 master_selector.append_column(_("Output"), exp_cols.output);
145 master_selector.append_column_editable(_("Left"), exp_cols.left);
146 master_selector.append_column_editable(_("Right"), exp_cols.right);
147 master_selector.get_column(0)->set_min_width(100);
149 master_selector.get_column(1)->set_min_width(40);
150 master_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
151 master_selector.get_column(2)->set_min_width(40);
152 master_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
153 master_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
155 track_list = ListStore::create (exp_cols);
156 track_selector.set_model (track_list);
158 track_selector.set_name ("ExportTrackSelector");
159 track_selector.set_size_request (-1, 130);
160 track_selector.append_column(_("Output"), exp_cols.output);
161 track_selector.append_column_editable(_("Left"), exp_cols.left);
162 track_selector.append_column_editable(_("Right"), exp_cols.right);
164 track_selector.get_column(0)->set_min_width(100);
165 track_selector.get_column(1)->set_min_width(40);
166 track_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
167 track_selector.get_column(2)->set_min_width(40);
168 track_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
169 track_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
171 progress_bar.set_name ("ExportProgress");
173 format_frame.add (format_table);
174 format_frame.set_name (FRAME_NAME);
176 track_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
177 master_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
179 get_vbox()->pack_start (file_frame, false, false);
181 hpacker.set_spacing (5);
182 hpacker.set_border_width (5);
183 hpacker.pack_start (format_frame, false, false);
185 master_scroll.add (master_selector);
186 track_scroll.add (track_selector);
188 master_scroll.set_size_request (220, 100);
189 track_scroll.set_size_request (220, 100);
191 /* we may hide some of these later */
192 track_vpacker.pack_start (master_scroll);
193 track_vpacker.pack_start (track_scroll);
194 track_vpacker.pack_start (track_selector_button, Gtk::PACK_EXPAND_PADDING);
196 hpacker.pack_start (track_vpacker);
198 get_vbox()->pack_start (hpacker);
200 track_selector_button.set_name ("EditorGTKButton");
201 track_selector_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::track_selector_button_click));
203 get_vbox()->pack_start (progress_bar, false, false);
205 Gtkmm2ext::set_size_request_to_display_given_text (file_entry, X_("Kg/quite/a/reasonable/size/for/files/i/think"), 5, 8);
207 file_hbox.set_spacing (5);
208 file_hbox.set_border_width (5);
209 file_hbox.pack_start (file_entry, true, true);
210 file_hbox.pack_start (file_browse_button, false, false);
212 file_frame.add (file_hbox);
213 file_frame.set_border_width (5);
214 file_frame.set_name (FRAME_NAME);
216 /* pop_strings needs to be created on the stack because set_popdown_strings()
220 vector<string> pop_strings = I18N(sample_rates);
221 Gtkmm2ext::set_popdown_strings (sample_rate_combo, pop_strings);
222 sample_rate_combo.set_active_text (pop_strings.front());
223 pop_strings = I18N(src_quality);
224 Gtkmm2ext::set_popdown_strings (src_quality_combo, pop_strings);
225 src_quality_combo.set_active_text (pop_strings.front());
226 pop_strings = I18N(dither_types);
227 Gtkmm2ext::set_popdown_strings (dither_type_combo, pop_strings);
228 dither_type_combo.set_active_text (pop_strings.front());
229 pop_strings = I18N(channel_strings);
230 Gtkmm2ext::set_popdown_strings (channel_count_combo, pop_strings);
231 channel_count_combo.set_active_text (pop_strings.front());
232 pop_strings = I18N((const char **) sndfile_header_formats_strings);
233 Gtkmm2ext::set_popdown_strings (header_format_combo, pop_strings);
234 header_format_combo.set_active_text (pop_strings.front());
235 pop_strings = I18N((const char **) sndfile_bitdepth_formats_strings);
236 Gtkmm2ext::set_popdown_strings (bitdepth_format_combo, pop_strings);
237 bitdepth_format_combo.set_active_text (pop_strings.front());
238 pop_strings = I18N((const char **) sndfile_endian_formats_strings);
239 Gtkmm2ext::set_popdown_strings (endian_format_combo, pop_strings);
240 endian_format_combo.set_active_text (pop_strings.front());
241 pop_strings = I18N(cue_file_types);
242 Gtkmm2ext::set_popdown_strings (cue_file_combo, pop_strings);
243 cue_file_combo.set_active_text (pop_strings.front());
245 /* this will re-sensitized as soon as a non RIFF/WAV
246 header format is chosen.
249 endian_format_combo.set_sensitive (false);
251 /* determine longest strings at runtime */
254 const char *longest = X_("gl"); /* translators: one ascender, one descender */
257 for (n = 0; n < SNDFILE_HEADER_FORMATS; ++n) {
258 if ((len = strlen (sndfile_header_formats_strings[n])) > maxlen) {
260 longest = sndfile_header_formats_strings[n];
264 for (n = 0; n < SNDFILE_BITDEPTH_FORMATS; ++n) {
265 if ((len = strlen (sndfile_bitdepth_formats_strings[n])) > maxlen) {
267 longest = sndfile_bitdepth_formats_strings[n];
271 for (n = 0; n < SNDFILE_ENDIAN_FORMATS; ++n) {
272 if ((len = strlen (sndfile_endian_formats_strings[n])) > maxlen) {
274 longest = sndfile_endian_formats_strings[n];
278 longest_str = longest;
280 /* force ascender + descender */
282 longest_str[0] = 'g';
283 longest_str[1] = 'l';
285 //Gtkmm2ext::set_size_request_to_display_given_text (header_format_combo, longest_str.c_str(), 5+FUDGE, 5);
287 // TRANSLATORS: "slereg" is "stereo" with ascender and descender substituted
288 //Gtkmm2ext::set_size_request_to_display_given_text (channel_count_combo, _("slereg"), 5+FUDGE, 5);
290 /* header_format_combo.set_focus_on_click (true);
291 bitdepth_format_combo.set_focus_on_click (true);
292 endian_format_combo.set_focus_on_click (true);
293 channel_count_combo.set_focus_on_click (true);
294 src_quality_combo.set_focus_on_click (true);
295 dither_type_combo.set_focus_on_click (true);
296 sample_rate_combo.set_focus_on_click (true);
297 cue_file_combo.set_focus_on_click (true);
299 dither_type_label.set_name ("ExportFormatLabel");
300 sample_rate_label.set_name ("ExportFormatLabel");
301 src_quality_label.set_name ("ExportFormatLabel");
302 channel_count_label.set_name ("ExportFormatLabel");
303 header_format_label.set_name ("ExportFormatLabel");
304 bitdepth_format_label.set_name ("ExportFormatLabel");
305 endian_format_label.set_name ("ExportFormatLabel");
306 cue_file_label.set_name ("ExportFormatLabel");
308 header_format_combo.set_name ("ExportFormatDisplay");
309 bitdepth_format_combo.set_name ("ExportFormatDisplay");
310 endian_format_combo.set_name ("ExportFormatDisplay");
311 channel_count_combo.set_name ("ExportFormatDisplay");
312 dither_type_combo.set_name ("ExportFormatDisplay");
313 src_quality_combo.set_name ("ExportFormatDisplay");
314 sample_rate_combo.set_name ("ExportFormatDisplay");
315 cue_file_combo.set_name ("ExportFormatDisplay");
317 cuefile_only_checkbox.set_name ("ExportCheckbox");
319 format_table.set_homogeneous (false);
320 format_table.set_border_width (5);
321 format_table.set_col_spacings (5);
322 format_table.set_row_spacings (5);
324 format_table.attach (channel_count_label, 0, 1, 0, 1);
325 format_table.attach (channel_count_combo, 1, 2, 0, 1);
327 format_table.attach (header_format_label, 0, 1, 1, 2);
328 format_table.attach (header_format_combo, 1, 2, 1, 2);
330 format_table.attach (bitdepth_format_label, 0, 1, 2, 3);
331 format_table.attach (bitdepth_format_combo, 1, 2, 2, 3);
333 format_table.attach (endian_format_label, 0, 1, 3, 4);
334 format_table.attach (endian_format_combo, 1, 2, 3, 4);
336 format_table.attach (sample_rate_label, 0, 1, 4, 5);
337 format_table.attach (sample_rate_combo, 1, 2, 4, 5);
339 format_table.attach (src_quality_label, 0, 1, 5, 6);
340 format_table.attach (src_quality_combo, 1, 2, 5, 6);
342 format_table.attach (dither_type_label, 0, 1, 6, 7);
343 format_table.attach (dither_type_combo, 1, 2, 6, 7);
345 format_table.attach (cue_file_label, 0, 1, 7, 8);
346 format_table.attach (cue_file_combo, 1, 2, 7, 8);
347 format_table.attach (cuefile_only_checkbox, 0, 2, 8, 9);
349 file_entry.set_name ("ExportFileDisplay");
351 signal_delete_event().connect (mem_fun(*this, &ExportDialog::window_closed));
353 cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
354 cancel_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::end_dialog));
355 ok_button = add_button (_("Export"), RESPONSE_ACCEPT);
356 ok_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::do_export));
358 file_browse_button.set_name ("EditorGTKButton");
359 file_browse_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::browse));
361 channel_count_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::channels_chosen));
362 bitdepth_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::bitdepth_chosen));
363 header_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::header_chosen));
364 sample_rate_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::sample_rate_chosen));
365 cue_file_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::cue_file_type_chosen));
368 ExportDialog::~ExportDialog()
373 ExportDialog::do_not_allow_track_and_master_selection()
375 track_and_master_selection_allowed = false;
376 track_vpacker.set_no_show_all();
380 ExportDialog::do_not_allow_channel_count_selection()
382 channel_count_selection_allowed = false;
383 channel_count_combo.set_no_show_all();
384 channel_count_label.set_no_show_all();
388 ExportDialog::do_not_allow_export_cd_markers()
390 export_cd_markers_allowed = false;
391 cue_file_label.set_no_show_all();
392 cue_file_combo.set_no_show_all();
393 cuefile_only_checkbox.set_no_show_all();
397 ExportDialog::connect_to_session (Session *s)
400 session->GoingAway.connect (mem_fun(*this, &Window::hide_all));
402 switch (session->frame_rate()) {
404 sample_rate_combo.set_active_text (_("22.05kHz"));
407 sample_rate_combo.set_active_text (_("44.1kHz"));
410 sample_rate_combo.set_active_text (_("48kHz"));
413 sample_rate_combo.set_active_text (_("88.2kHz"));
416 sample_rate_combo.set_active_text (_("96kHz"));
419 sample_rate_combo.set_active_text (_("192kHz"));
422 sample_rate_combo.set_active_text (_("44.1kHz"));
426 src_quality_combo.set_sensitive (false);
432 ExportDialog::set_state()
434 XMLNode* node = session->instant_xml(X_("ExportDialog"));
439 if ((prop = node->property (X_("sample_rate"))) != 0) {
440 sample_rate_combo.set_active_text(prop->value());
442 if ((prop = node->property (X_("src_quality"))) != 0) {
443 src_quality_combo.set_active_text(prop->value());
445 if ((prop = node->property (X_("dither_type"))) != 0) {
446 dither_type_combo.set_active_text(prop->value());
448 if ((prop = node->property (X_("channel_count"))) != 0) {
449 channel_count_combo.set_active_text(prop->value());
451 if ((prop = node->property (X_("header_format"))) != 0) {
452 header_format_combo.set_active_text(prop->value());
454 if ((prop = node->property (X_("bitdepth_format"))) != 0) {
455 bitdepth_format_combo.set_active_text(prop->value());
457 if ((prop = node->property (X_("endian_format"))) != 0) {
458 endian_format_combo.set_active_text(prop->value());
460 if ((prop = node->property (X_("filename"))) != 0) {
461 file_entry.set_text(prop->value());
463 if ((prop = node->property (X_("cue_file_type"))) != 0) {
464 cue_file_combo.set_active_text(prop->value());
471 sample_rate_chosen();
473 if (session->master_out()) {
474 track_scroll.hide ();
476 master_scroll.hide ();
477 track_selector_button.hide ();
484 if (session->master_out()) {
485 XMLNode* master = find_named_node(*node, (X_("Master")));
490 /* default is to use all */
491 if (channel_count_combo.get_active_text() == _("mono")) {
497 TreeModel::Children rows = master_selector.get_model()->children();
498 for (uint32_t r = 0; r < session->master_out()->n_outputs().n_audio(); ++r) {
501 rows[r][exp_cols.right] = true;
503 rows[r][exp_cols.left] = true;
506 rows[r][exp_cols.left] = true;
511 /* XXX use XML state */
515 XMLNode* tracks = find_named_node(*node, (X_("Tracks")));
520 XMLNodeList track_list = tracks->children(X_("Track"));
521 TreeModel::Children rows = track_selector.get_model()->children();
522 TreeModel::Children::iterator ri = rows.begin();
525 for (XMLNodeIterator it = track_list.begin(); it != track_list.end(); ++it, ++ri) {
526 if (ri == rows.end()){
530 XMLNode* track = *it;
533 if ((prop = track->property(X_("channel1"))) != 0) {
534 if (prop->value() == X_("on")) {
535 row[exp_cols.left] = true;
537 row[exp_cols.left] = false;
541 if ((prop = track->property(X_("channel2"))) != 0) {
542 if (prop->value() == X_("on")) {
543 row[exp_cols.right] = true;
545 row[exp_cols.right] = false;
552 ExportDialog::save_state()
558 XMLNode* node = new XMLNode(X_("ExportDialog"));
560 node->add_property(X_("sample_rate"), sample_rate_combo.get_active_text());
561 node->add_property(X_("src_quality"), src_quality_combo.get_active_text());
562 node->add_property(X_("dither_type"), dither_type_combo.get_active_text());
563 node->add_property(X_("channel_count"), channel_count_combo.get_active_text());
564 node->add_property(X_("header_format"), header_format_combo.get_active_text());
565 node->add_property(X_("bitdepth_format"), bitdepth_format_combo.get_active_text());
566 node->add_property(X_("endian_format"), endian_format_combo.get_active_text());
567 node->add_property(X_("filename"), file_entry.get_text());
568 node->add_property(X_("cue_file_type"), cue_file_combo.get_active_text());
570 XMLNode* tracks = new XMLNode(X_("Tracks"));
572 TreeModel::Children rows = track_selector.get_model()->children();
574 for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
575 XMLNode* track = new XMLNode(X_("Track"));
578 track->add_property(X_("channel1"), row[exp_cols.left] ? X_("on") : X_("off"));
579 track->add_property(X_("channel2"), row[exp_cols.right] ? X_("on") : X_("off"));
581 tracks->add_child_nocopy(*track);
583 node->add_child_nocopy(*tracks);
585 session->add_instant_xml(*node);
589 ExportDialog::set_range (nframes_t start, nframes_t end)
591 spec.start_frame = start;
592 spec.end_frame = end;
596 ExportDialog::progress_timeout ()
598 progress_bar.set_fraction (spec.progress);
603 frames_to_cd_frames_string (char* buf, nframes_t when, nframes_t fr)
606 long unsigned int remainder;
607 int mins, secs, frames;
609 mins = when / (60 * fr);
610 remainder = when - (mins * 60 * fr);
611 secs = remainder / fr;
612 remainder -= secs * fr;
613 frames = remainder / (fr / 75);
614 sprintf (buf, " %02d:%02d:%02d", mins, secs, frames);
618 struct LocationSortByStart {
619 bool operator() (Location *a, Location *b) {
620 return a->start() < b->start();
625 ExportDialog::export_toc_file (Locations::LocationList& locations, const string& path)
627 if(!export_cd_markers_allowed){
631 string filepath = path + ".toc";
632 ofstream out (filepath.c_str());
633 long unsigned int last_end_time = spec.start_frame, last_start_time = spec.start_frame;
638 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD toc file"), filepath) << endmsg;
641 out << "CD_DA" << endl;
642 out << "CD_TEXT {" << endl << " LANGUAGE_MAP {" << endl << " 0 : EN" << endl << " }" << endl;
643 out << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl << " }" << endl << "}" << endl;
645 Locations::LocationList::iterator i;
646 Locations::LocationList temp;
648 for (i = locations.begin(); i != locations.end(); ++i) {
649 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
651 if (!(*i)->is_mark()) {
657 if (numtracks == 0 ) {
658 /* the user supplied no track markers.
659 we now treat the session as one track.*/
661 out << endl << "TRACK AUDIO" << endl;
663 out << "COPY" << endl;
665 out << "NO PRE_EMPHASIS" << endl;
667 /* XXX add session properties for catalog etc.
668 (so far only the session name is used) */
670 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl;
671 out << " }" << endl << "}" << endl;
673 out << "FILE \"" << path << "\" ";
675 frames_to_cd_frames_string (buf, spec.end_frame - spec.start_frame, session->frame_rate());
677 out << "START 00:00:00" << endl;
679 last_start_time = spec.start_frame;
680 last_end_time = spec.end_frame;
684 LocationSortByStart cmp;
687 for (i = temp.begin(); i != temp.end(); ++i) {
689 if (!(*i)->is_mark()) {
691 out << endl << "TRACK AUDIO" << endl;
693 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
696 out << "COPY" << endl;
698 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
699 out << "PRE_EMPHASIS" << endl;
701 out << "NO PRE_EMPHASIS" << endl;
704 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
705 out << "ISRC \"" << (*i)->cd_info["isrc"] << "\"" << endl;
708 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << (*i)->name() << "\"" << endl;
709 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
710 out << " PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
712 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
713 out << " COMPOSER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
716 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
718 out << (*i)->cd_info["isrc"].substr(0,2) << "-";
719 out << (*i)->cd_info["isrc"].substr(2,3) << "-";
720 out << (*i)->cd_info["isrc"].substr(5,2) << "-";
721 out << (*i)->cd_info["isrc"].substr(7,5) << "\"" << endl;
724 out << " }" << endl << "}" << endl;
726 frames_to_cd_frames_string (buf, last_end_time - spec.start_frame, session->frame_rate());
727 out << "FILE \"" << path << "\" " << buf;
729 frames_to_cd_frames_string (buf, (*i)->end() - last_end_time, session->frame_rate());
732 frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
733 out << "START" << buf << endl;
735 last_start_time = (*i)->start();
736 last_end_time = (*i)->end();
739 } else if ((*i)->start() < last_end_time) {
740 /* this is an index within a track */
742 frames_to_cd_frames_string (buf, (*i)->start() - last_start_time, session->frame_rate());
743 out << "INDEX" << buf << endl;
751 ExportDialog::export_cue_file (Locations::LocationList& locations, const string& path)
753 if(!export_cd_markers_allowed){
757 string filepath = path + ".cue";
758 ofstream out (filepath.c_str());
760 long unsigned int last_track_end = spec.start_frame;
761 int numtracks = 0, tracknum = 0, indexnum = 0;
764 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD cue file"), filepath) << endmsg;
768 Locations::LocationList::iterator i;
769 Locations::LocationList temp;
771 for (i = locations.begin(); i != locations.end(); ++i) {
772 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
774 if (!(*i)->is_mark()) {
780 out << "REM Cue file generated by Ardour" << endl;
781 out << "TITLE \"" << session->name() << "\"" << endl;
783 if ((header_format_combo.get_active_text() == N_("WAV"))) {
784 out << "FILE " << path << " WAVE" << endl;
786 out << "FILE " << path << ' ' << (header_format_combo.get_active_text()) << endl;
789 if (numtracks == 0) {
790 /* the user has supplied no track markers.
791 the entire export is treated as one track.
797 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
800 out << "DCP " << endl;
802 /* use the session name*/
804 if (session->name() != "") {
805 out << "TITLE \"" << session->name() << "\"" << endl;
808 /* no pregap in this case */
810 out << "INDEX 00 00:00:00" << endl;
812 out << "INDEX 01 00:00:00" << endl;
814 last_track_end = spec.end_frame;
818 LocationSortByStart cmp;
821 for ( i = temp.begin(); i != temp.end(); ++i) {
823 if (!(*i)->is_mark() && ((*i)->start() >= last_track_end)) {
824 /* this is a track and it doesn't start inside another one*/
828 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
831 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
837 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
842 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
843 out << "ISRC " << (*i)->cd_info["isrc"] << endl;
846 if ((*i)->name() != "") {
847 out << "TITLE \"" << (*i)->name() << "\"" << endl;
850 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
851 out << "PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
854 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
855 out << "SONGWRITER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
857 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
859 frames_to_cd_frames_string (buf, last_track_end - spec.start_frame, session->frame_rate());
862 last_track_end = (*i)->end();
864 if ((tracknum > 0) && ((*i)->start() < last_track_end)) {
865 /*this is an index and it lies within a track*/
866 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
868 frames_to_cd_frames_string (buf,(*i)->start() - spec.start_frame, session->frame_rate());
878 ExportDialog::do_export_cd_markers (const string& path,const string& cuefile_type)
880 if (cuefile_type == _("TOC")) {
881 session->locations()->apply (*this, &ExportDialog::export_toc_file, path);
883 session->locations()->apply (*this, &ExportDialog::export_cue_file, path);
889 ExportDialog::do_export ()
891 string filepath = file_entry.get_text();
893 if(!is_filepath_valid(filepath)){
897 if (export_cd_markers_allowed) {
898 if (cue_file_combo.get_active_text () != _("None")) {
899 do_export_cd_markers (file_entry.get_text(), cue_file_combo.get_active_text ());
902 if (cuefile_only_checkbox.get_active()) {
908 ok_button->set_sensitive(false);
913 // read user input into spec
916 progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
917 cancel_label.set_text (_("Stop Export"));
921 progress_connection.disconnect ();
926 ExportDialog::end_dialog ()
931 while (spec.running) {
932 if (gtk_events_pending()) {
933 gtk_main_iteration ();
940 session->finalize_audio_export ();
945 ok_button->set_sensitive(true);
949 ExportDialog::start_export ()
955 /* If the filename hasn't been set before, use the
956 current session's export directory as a default
957 location for the export.
960 if (file_entry.get_text().length() == 0) {
962 sys::path export_file_path = session->session_directory().export_path();
965 export_file_path /= "export.wav";
968 file_entry.set_text (export_file_path.to_string());
971 progress_bar.set_fraction (0);
972 cancel_label.set_text (_("Cancel"));
976 if (session->master_out()) {
977 track_scroll.hide ();
979 master_scroll.hide ();
980 track_selector_button.hide ();
985 ExportDialog::header_chosen ()
987 if (sndfile_header_format_from_string (header_format_combo.get_active_text ()) == SF_FORMAT_WAV) {
988 endian_format_combo.set_sensitive (false);
990 endian_format_combo.set_sensitive (true);
995 ExportDialog::bitdepth_chosen ()
997 int format = sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
999 case SF_FORMAT_PCM_24:
1000 case SF_FORMAT_PCM_32:
1001 case SF_FORMAT_FLOAT:
1002 dither_type_combo.set_sensitive (false);
1006 dither_type_combo.set_sensitive (true);
1012 ExportDialog::cue_file_type_chosen ()
1014 if (cue_file_combo.get_active_text () != "None") {
1015 cuefile_only_checkbox.set_sensitive (true);
1017 cuefile_only_checkbox.set_active (false);
1018 cuefile_only_checkbox.set_sensitive (false);
1023 ExportDialog::sample_rate_chosen ()
1025 string sr_str = sample_rate_combo.get_active_text();
1028 if (sr_str == N_("22.05kHz")) {
1030 } else if (sr_str == _("44.1kHz")) {
1032 } else if (sr_str == _("48kHz")) {
1034 } else if (sr_str == _("88.2kHz")) {
1036 } else if (sr_str == _("96kHz")) {
1038 } else if (sr_str == _("192kHz")) {
1041 rate = session->frame_rate();
1044 if (rate != session->frame_rate()) {
1045 src_quality_combo.set_sensitive (true);
1047 src_quality_combo.set_sensitive (false);
1052 ExportDialog::channels_chosen ()
1056 mono = (channel_count_combo.get_active_text() == _("mono"));
1059 track_selector.get_column(2)->set_visible(false);
1060 track_selector.get_column(1)->set_title(_("Export"));
1062 if (session->master_out()) {
1063 master_selector.get_column(2)->set_visible(false);
1064 master_selector.get_column(1)->set_title(_("Export"));
1068 track_selector.get_column(2)->set_visible(true);
1069 track_selector.get_column(1)->set_title(_("Left"));
1071 if (session->master_out()) {
1072 master_selector.get_column(2)->set_visible(true);
1073 master_selector.get_column(1)->set_title(_("Left"));
1081 ExportDialog::fill_lists ()
1083 track_list->clear();
1084 master_list->clear();
1086 boost::shared_ptr<Session::RouteList> routes = session->get_routes ();
1088 for (Session::RouteList::iterator ri = routes->begin(); ri != routes->end(); ++ri) {
1090 boost::shared_ptr<Route> route = (*ri);
1092 if (route->hidden()) {
1096 for (uint32_t i=0; i < route->n_outputs().n_audio(); ++i) {
1098 if (route->n_outputs().n_audio() == 1) {
1099 name = route->name();
1101 name = string_compose("%1: out-%2", route->name(), i+1);
1104 if (route == session->master_out()) {
1105 TreeModel::iterator iter = master_list->append();
1106 TreeModel::Row row = *iter;
1107 row[exp_cols.output] = name;
1108 row[exp_cols.left] = false;
1109 row[exp_cols.right] = false;
1110 row[exp_cols.port] = route->output (i);
1112 TreeModel::iterator iter = track_list->append();
1113 TreeModel::Row row = *iter;
1114 row[exp_cols.output] = name;
1115 row[exp_cols.left] = false;
1116 row[exp_cols.right] = false;
1117 row[exp_cols.port] = route->output (i);
1125 ExportDialog::is_filepath_valid(string &filepath)
1127 // sanity check file name first
1129 struct stat statbuf;
1131 if (filepath.empty()) {
1132 string txt = _("Please enter a valid filename.");
1133 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1138 // check if file exists already and warn
1140 if (stat (filepath.c_str(), &statbuf) == 0) {
1141 if (S_ISDIR (statbuf.st_mode)) {
1142 string txt = _("Please specify a complete filename for the audio file.");
1143 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1148 string txt = _("File already exists, do you want to overwrite it?");
1149 MessageDialog msg (*this, txt, false, MESSAGE_QUESTION, BUTTONS_YES_NO, true);
1150 if ((ResponseType) msg.run() == Gtk::RESPONSE_NO) {
1156 // directory needs to exist and be writable
1158 string dirpath = Glib::path_get_dirname (filepath);
1159 if (::access (dirpath.c_str(), W_OK) != 0) {
1160 string txt = _("Cannot write file in: ") + dirpath;
1161 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1170 ExportDialog::initSpec(string &filepath)
1172 spec.path = filepath;
1174 spec.running = true;
1176 spec.port_map.clear();
1178 if (channel_count_combo.get_active_text() == _("mono")) {
1186 spec.format |= sndfile_header_format_from_string (header_format_combo.get_active_text ());
1188 if ((spec.format & SF_FORMAT_WAV) == 0) {
1189 /* RIFF/WAV specifies endianess */
1190 spec.format |= sndfile_endian_format_from_string (endian_format_combo.get_active_text ());
1193 spec.format |= sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
1195 string sr_str = sample_rate_combo.get_active_text();
1196 if (sr_str == N_("22.05kHz")) {
1197 spec.sample_rate = 22050;
1198 } else if (sr_str == _("44.1kHz")) {
1199 spec.sample_rate = 44100;
1200 } else if (sr_str == _("48kHz")) {
1201 spec.sample_rate = 48000;
1202 } else if (sr_str == _("88.2kHz")) {
1203 spec.sample_rate = 88200;
1204 } else if (sr_str == _("96kHz")) {
1205 spec.sample_rate = 96000;
1206 } else if (sr_str == _("192kHz")) {
1207 spec.sample_rate = 192000;
1209 spec.sample_rate = session->frame_rate();
1212 string src_str = src_quality_combo.get_active_text();
1213 if (src_str == _("fastest")) {
1214 spec.src_quality = SRC_ZERO_ORDER_HOLD;
1215 } else if (src_str == _("linear")) {
1216 spec.src_quality = SRC_LINEAR;
1217 } else if (src_str == _("better")) {
1218 spec.src_quality = SRC_SINC_FASTEST;
1219 } else if (src_str == _("intermediate")) {
1220 spec.src_quality = SRC_SINC_MEDIUM_QUALITY;
1222 spec.src_quality = SRC_SINC_BEST_QUALITY;
1225 string dither_str = dither_type_combo.get_active_text();
1226 if (dither_str == _("None")) {
1227 spec.dither_type = GDitherNone;
1228 } else if (dither_str == _("Rectangular")) {
1229 spec.dither_type = GDitherRect;
1230 } else if (dither_str == _("Triangular")) {
1231 spec.dither_type = GDitherTri;
1233 spec.dither_type = GDitherShaped;
1236 write_track_and_master_selection_to_spec();
1241 ExportDialog::write_track_and_master_selection_to_spec()
1243 if(!track_and_master_selection_allowed){
1248 Port *last_port = 0;
1250 TreeModel::Children rows = master_selector.get_model()->children();
1251 TreeModel::Children::iterator ri;
1253 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1255 Port* port = row[exp_cols.port];
1257 if (last_port != port) {
1261 if (row[exp_cols.left]) {
1262 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1265 if (spec.channels == 2) {
1266 if (row[exp_cols.right]) {
1267 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1273 rows = track_selector.get_model()->children();
1275 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1278 Port* port = row[exp_cols.port];
1280 if (last_port != port) {
1284 if (row[exp_cols.left]) {
1285 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1288 if (spec.channels == 2) {
1289 if (row[exp_cols.right]) {
1290 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1302 ExportDialog::window_closed (GdkEventAny *ignored)
1309 ExportDialog::browse ()
1311 FileChooserDialog dialog("Export to file", browse_action());
1312 dialog.set_transient_for(*this);
1313 dialog.set_filename (file_entry.get_text());
1315 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1316 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
1318 int result = dialog.run();
1320 if (result == Gtk::RESPONSE_OK) {
1321 string filename = dialog.get_filename();
1323 if (filename.length()) {
1324 file_entry.set_text (filename);
1330 ExportDialog::track_selector_button_click ()
1332 if (track_scroll.is_visible ()) {
1333 track_scroll.hide ();
1335 track_scroll.show_all ();