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/sndfile_helpers.h>
36 #include <ardour/audio_track.h>
37 #include <ardour/audioregion.h>
38 #include <ardour/audioengine.h>
39 #include <ardour/gdither.h>
40 #include <ardour/utils.h>
42 #include "export_dialog.h"
43 #include "ardour_ui.h"
44 #include "public_editor.h"
49 #define FRAME_NAME "BaseFrame"
52 using namespace ARDOUR;
56 using namespace Gtkmm2ext;
58 static const gchar *sample_rates[] = {
68 static const gchar *src_quality[] = {
77 static const gchar *dither_types[] = {
85 static const gchar* channel_strings[] = {
91 static const gchar* cue_file_types[] = {
98 ExportDialog::ExportDialog(PublicEditor& e)
99 : ArdourDialog ("export dialog"),
102 format_frame (_("Format")),
103 cue_file_label (_("CD Marker File Type"), 1.0, 0.5),
104 channel_count_label (_("Channels"), 1.0, 0.5),
105 header_format_label (_("File Type"), 1.0, 0.5),
106 bitdepth_format_label (_("Sample Format"), 1.0, 0.5),
107 endian_format_label (_("Sample Endianness"), 1.0, 0.5),
108 sample_rate_label (_("Sample Rate"), 1.0, 0.5),
109 src_quality_label (_("Conversion Quality"), 1.0, 0.5),
110 dither_type_label (_("Dither Type"), 1.0, 0.5),
111 cuefile_only_checkbox (_("Export CD Marker File Only")),
112 file_browse_button (_("Browse")),
113 track_selector_button (_("Specific tracks ..."))
120 track_and_master_selection_allowed = true;
121 channel_count_selection_allowed = true;
122 export_cd_markers_allowed = true;
124 WindowTitle title(Glib::get_application_name());
125 title += _("Export");
127 set_title (title.get_string());
128 set_wmclass (X_("ardour_export"), "Ardour");
129 set_name ("ExportWindow");
130 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
132 spec.running = false;
134 file_entry.set_name ("ExportFileNameEntry");
136 master_list = ListStore::create (exp_cols);
137 master_selector.set_model (master_list);
139 master_selector.set_name ("ExportTrackSelector");
140 master_selector.set_size_request (-1, 100);
141 master_selector.append_column(_("Output"), exp_cols.output);
142 master_selector.append_column_editable(_("Left"), exp_cols.left);
143 master_selector.append_column_editable(_("Right"), exp_cols.right);
144 master_selector.get_column(0)->set_min_width(100);
146 master_selector.get_column(1)->set_min_width(40);
147 master_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
148 master_selector.get_column(2)->set_min_width(40);
149 master_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
150 master_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
152 track_list = ListStore::create (exp_cols);
153 track_selector.set_model (track_list);
155 track_selector.set_name ("ExportTrackSelector");
156 track_selector.set_size_request (-1, 130);
157 track_selector.append_column(_("Output"), exp_cols.output);
158 track_selector.append_column_editable(_("Left"), exp_cols.left);
159 track_selector.append_column_editable(_("Right"), exp_cols.right);
161 track_selector.get_column(0)->set_min_width(100);
162 track_selector.get_column(1)->set_min_width(40);
163 track_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
164 track_selector.get_column(2)->set_min_width(40);
165 track_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
166 track_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
168 progress_bar.set_name ("ExportProgress");
170 format_frame.add (format_table);
171 format_frame.set_name (FRAME_NAME);
173 track_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
174 master_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
176 get_vbox()->pack_start (file_frame, false, false);
178 hpacker.set_spacing (5);
179 hpacker.set_border_width (5);
180 hpacker.pack_start (format_frame, false, false);
182 master_scroll.add (master_selector);
183 track_scroll.add (track_selector);
185 master_scroll.set_size_request (220, 100);
186 track_scroll.set_size_request (220, 100);
188 /* we may hide some of these later */
189 track_vpacker.pack_start (master_scroll);
190 track_vpacker.pack_start (track_scroll);
191 track_vpacker.pack_start (track_selector_button, Gtk::PACK_EXPAND_PADDING);
193 hpacker.pack_start (track_vpacker);
195 get_vbox()->pack_start (hpacker);
197 track_selector_button.set_name ("EditorGTKButton");
198 track_selector_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::track_selector_button_click));
200 get_vbox()->pack_start (progress_bar, false, false);
202 Gtkmm2ext::set_size_request_to_display_given_text (file_entry, X_("Kg/quite/a/reasonable/size/for/files/i/think"), 5, 8);
204 file_hbox.set_spacing (5);
205 file_hbox.set_border_width (5);
206 file_hbox.pack_start (file_entry, true, true);
207 file_hbox.pack_start (file_browse_button, false, false);
209 file_frame.add (file_hbox);
210 file_frame.set_border_width (5);
211 file_frame.set_name (FRAME_NAME);
213 /* pop_strings needs to be created on the stack because set_popdown_strings()
217 vector<string> pop_strings = I18N (sample_rates);
218 Gtkmm2ext::set_popdown_strings (sample_rate_combo, pop_strings);
219 sample_rate_combo.set_active_text (pop_strings.front());
220 pop_strings = I18N (src_quality);
221 Gtkmm2ext::set_popdown_strings (src_quality_combo, pop_strings);
222 src_quality_combo.set_active_text (pop_strings.front());
223 pop_strings = I18N (dither_types);
224 Gtkmm2ext::set_popdown_strings (dither_type_combo, pop_strings);
225 dither_type_combo.set_active_text (pop_strings.front());
226 pop_strings = I18N (channel_strings);
227 Gtkmm2ext::set_popdown_strings (channel_count_combo, pop_strings);
228 channel_count_combo.set_active_text (pop_strings.front());
229 pop_strings = I18N ((const char **) sndfile_header_formats_strings);
230 Gtkmm2ext::set_popdown_strings (header_format_combo, pop_strings);
231 header_format_combo.set_active_text (pop_strings.front());
232 pop_strings = I18N ((const char **) sndfile_bitdepth_formats_strings);
233 Gtkmm2ext::set_popdown_strings (bitdepth_format_combo, pop_strings);
234 bitdepth_format_combo.set_active_text (pop_strings.front());
235 pop_strings = I18N ((const char **) sndfile_endian_formats_strings);
236 Gtkmm2ext::set_popdown_strings (endian_format_combo, pop_strings);
237 endian_format_combo.set_active_text (pop_strings.front());
238 pop_strings = I18N (cue_file_types);
239 Gtkmm2ext::set_popdown_strings (cue_file_combo, pop_strings);
240 cue_file_combo.set_active_text (pop_strings.front());
242 /* this will re-sensitized as soon as a non RIFF/WAV
243 header format is chosen.
246 endian_format_combo.set_sensitive (false);
248 /* determine longest strings at runtime */
251 const char *longest = X_("gl"); /* translators: one ascender, one descender */
254 for (n = 0; n < SNDFILE_HEADER_FORMATS; ++n) {
255 if ((len = strlen (sndfile_header_formats_strings[n])) > maxlen) {
257 longest = sndfile_header_formats_strings[n];
261 for (n = 0; n < SNDFILE_BITDEPTH_FORMATS; ++n) {
262 if ((len = strlen (sndfile_bitdepth_formats_strings[n])) > maxlen) {
264 longest = sndfile_bitdepth_formats_strings[n];
268 for (n = 0; n < SNDFILE_ENDIAN_FORMATS; ++n) {
269 if ((len = strlen (sndfile_endian_formats_strings[n])) > maxlen) {
271 longest = sndfile_endian_formats_strings[n];
275 longest_str = longest;
277 /* force ascender + descender */
279 longest_str[0] = 'g';
280 longest_str[1] = 'l';
282 //Gtkmm2ext::set_size_request_to_display_given_text (header_format_combo, longest_str.c_str(), 5+FUDGE, 5);
284 // TRANSLATORS: "slereg" is "stereo" with ascender and descender substituted
285 //Gtkmm2ext::set_size_request_to_display_given_text (channel_count_combo, _("slereg"), 5+FUDGE, 5);
287 /* header_format_combo.set_focus_on_click (true);
288 bitdepth_format_combo.set_focus_on_click (true);
289 endian_format_combo.set_focus_on_click (true);
290 channel_count_combo.set_focus_on_click (true);
291 src_quality_combo.set_focus_on_click (true);
292 dither_type_combo.set_focus_on_click (true);
293 sample_rate_combo.set_focus_on_click (true);
294 cue_file_combo.set_focus_on_click (true);
296 dither_type_label.set_name ("ExportFormatLabel");
297 sample_rate_label.set_name ("ExportFormatLabel");
298 src_quality_label.set_name ("ExportFormatLabel");
299 channel_count_label.set_name ("ExportFormatLabel");
300 header_format_label.set_name ("ExportFormatLabel");
301 bitdepth_format_label.set_name ("ExportFormatLabel");
302 endian_format_label.set_name ("ExportFormatLabel");
303 cue_file_label.set_name ("ExportFormatLabel");
305 header_format_combo.set_name ("ExportFormatDisplay");
306 bitdepth_format_combo.set_name ("ExportFormatDisplay");
307 endian_format_combo.set_name ("ExportFormatDisplay");
308 channel_count_combo.set_name ("ExportFormatDisplay");
309 dither_type_combo.set_name ("ExportFormatDisplay");
310 src_quality_combo.set_name ("ExportFormatDisplay");
311 sample_rate_combo.set_name ("ExportFormatDisplay");
312 cue_file_combo.set_name ("ExportFormatDisplay");
314 cuefile_only_checkbox.set_name ("ExportCheckbox");
316 format_table.set_homogeneous (false);
317 format_table.set_border_width (5);
318 format_table.set_col_spacings (5);
319 format_table.set_row_spacings (5);
321 format_table.attach (channel_count_label, 0, 1, 0, 1);
322 format_table.attach (channel_count_combo, 1, 2, 0, 1);
324 format_table.attach (header_format_label, 0, 1, 1, 2);
325 format_table.attach (header_format_combo, 1, 2, 1, 2);
327 format_table.attach (bitdepth_format_label, 0, 1, 2, 3);
328 format_table.attach (bitdepth_format_combo, 1, 2, 2, 3);
330 format_table.attach (endian_format_label, 0, 1, 3, 4);
331 format_table.attach (endian_format_combo, 1, 2, 3, 4);
333 format_table.attach (sample_rate_label, 0, 1, 4, 5);
334 format_table.attach (sample_rate_combo, 1, 2, 4, 5);
336 format_table.attach (src_quality_label, 0, 1, 5, 6);
337 format_table.attach (src_quality_combo, 1, 2, 5, 6);
339 format_table.attach (dither_type_label, 0, 1, 6, 7);
340 format_table.attach (dither_type_combo, 1, 2, 6, 7);
342 format_table.attach (cue_file_label, 0, 1, 7, 8);
343 format_table.attach (cue_file_combo, 1, 2, 7, 8);
344 format_table.attach (cuefile_only_checkbox, 0, 2, 8, 9);
346 file_entry.set_name ("ExportFileDisplay");
348 signal_delete_event().connect (mem_fun(*this, &ExportDialog::window_closed));
350 cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
351 cancel_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::end_dialog));
352 ok_button = add_button (_("Export"), RESPONSE_ACCEPT);
353 ok_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::do_export));
355 file_browse_button.set_name ("EditorGTKButton");
356 file_browse_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::browse));
358 channel_count_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::channels_chosen));
359 bitdepth_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::bitdepth_chosen));
360 header_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::header_chosen));
361 sample_rate_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::sample_rate_chosen));
362 cue_file_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::cue_file_type_chosen));
365 ExportDialog::~ExportDialog()
370 ExportDialog::do_not_allow_track_and_master_selection()
372 track_and_master_selection_allowed = false;
373 track_vpacker.set_no_show_all();
377 ExportDialog::do_not_allow_channel_count_selection()
379 channel_count_selection_allowed = false;
380 channel_count_combo.set_no_show_all();
381 channel_count_label.set_no_show_all();
385 ExportDialog::do_not_allow_export_cd_markers()
387 export_cd_markers_allowed = false;
388 cue_file_label.set_no_show_all();
389 cue_file_combo.set_no_show_all();
390 cuefile_only_checkbox.set_no_show_all();
394 ExportDialog::connect_to_session (Session *s)
397 session->GoingAway.connect (mem_fun(*this, &Window::hide_all));
399 switch (session->frame_rate()) {
401 sample_rate_combo.set_active_text (_("22.05kHz"));
404 sample_rate_combo.set_active_text (_("44.1kHz"));
407 sample_rate_combo.set_active_text (_("48kHz"));
410 sample_rate_combo.set_active_text (_("88.2kHz"));
413 sample_rate_combo.set_active_text (_("96kHz"));
416 sample_rate_combo.set_active_text (_("192kHz"));
419 sample_rate_combo.set_active_text (_("44.1kHz"));
423 src_quality_combo.set_sensitive (false);
429 ExportDialog::set_state()
431 XMLNode* node = session->instant_xml(X_("ExportDialog"), session->path());
436 if ((prop = node->property (X_("sample_rate"))) != 0) {
437 sample_rate_combo.set_active_text(prop->value());
439 if ((prop = node->property (X_("src_quality"))) != 0) {
440 src_quality_combo.set_active_text(prop->value());
442 if ((prop = node->property (X_("dither_type"))) != 0) {
443 dither_type_combo.set_active_text(prop->value());
445 if ((prop = node->property (X_("channel_count"))) != 0) {
446 channel_count_combo.set_active_text(prop->value());
448 if ((prop = node->property (X_("header_format"))) != 0) {
449 header_format_combo.set_active_text(prop->value());
451 if ((prop = node->property (X_("bitdepth_format"))) != 0) {
452 bitdepth_format_combo.set_active_text(prop->value());
454 if ((prop = node->property (X_("endian_format"))) != 0) {
455 endian_format_combo.set_active_text(prop->value());
457 if ((prop = node->property (X_("filename"))) != 0) {
458 file_entry.set_text(prop->value());
460 if ((prop = node->property (X_("cue_file_type"))) != 0) {
461 cue_file_combo.set_active_text(prop->value());
468 sample_rate_chosen();
470 if (session->master_out()) {
471 track_scroll.hide ();
473 master_scroll.hide ();
474 track_selector_button.hide ();
481 if (session->master_out()) {
482 XMLNode* master = find_named_node(*node, (X_("Master")));
487 /* default is to use all */
488 if (channel_count_combo.get_active_text() == _("mono")) {
494 TreeModel::Children rows = master_selector.get_model()->children();
495 for (uint32_t r = 0; r < session->master_out()->n_outputs(); ++r) {
498 rows[r][exp_cols.right] = true;
500 rows[r][exp_cols.left] = true;
503 rows[r][exp_cols.left] = true;
508 /* XXX use XML state */
512 XMLNode* tracks = find_named_node(*node, (X_("Tracks")));
517 XMLNodeList track_list = tracks->children(X_("Track"));
518 TreeModel::Children rows = track_selector.get_model()->children();
519 TreeModel::Children::iterator ri = rows.begin();
522 for (XMLNodeIterator it = track_list.begin(); it != track_list.end(); ++it, ++ri) {
523 if (ri == rows.end()){
527 XMLNode* track = *it;
530 if ((prop = track->property(X_("channel1"))) != 0) {
531 if (prop->value() == X_("on")) {
532 row[exp_cols.left] = true;
534 row[exp_cols.left] = false;
538 if ((prop = track->property(X_("channel2"))) != 0) {
539 if (prop->value() == X_("on")) {
540 row[exp_cols.right] = true;
542 row[exp_cols.right] = false;
549 ExportDialog::save_state()
555 XMLNode* node = new XMLNode(X_("ExportDialog"));
557 node->add_property(X_("sample_rate"), sample_rate_combo.get_active_text());
558 node->add_property(X_("src_quality"), src_quality_combo.get_active_text());
559 node->add_property(X_("dither_type"), dither_type_combo.get_active_text());
560 node->add_property(X_("channel_count"), channel_count_combo.get_active_text());
561 node->add_property(X_("header_format"), header_format_combo.get_active_text());
562 node->add_property(X_("bitdepth_format"), bitdepth_format_combo.get_active_text());
563 node->add_property(X_("endian_format"), endian_format_combo.get_active_text());
564 node->add_property(X_("filename"), file_entry.get_text());
565 node->add_property(X_("cue_file_type"), cue_file_combo.get_active_text());
567 XMLNode* tracks = new XMLNode(X_("Tracks"));
569 TreeModel::Children rows = track_selector.get_model()->children();
571 for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
572 XMLNode* track = new XMLNode(X_("Track"));
575 track->add_property(X_("channel1"), row[exp_cols.left] ? X_("on") : X_("off"));
576 track->add_property(X_("channel2"), row[exp_cols.right] ? X_("on") : X_("off"));
578 tracks->add_child_nocopy(*track);
580 node->add_child_nocopy(*tracks);
582 session->add_instant_xml(*node, session->path());
586 ExportDialog::set_range (nframes_t start, nframes_t end)
588 spec.start_frame = start;
589 spec.end_frame = end;
593 ExportDialog::progress_timeout ()
595 progress_bar.set_fraction (spec.progress);
600 frames_to_cd_frames_string (char* buf, nframes_t when, nframes_t fr)
603 long unsigned int remainder;
604 int mins, secs, frames;
606 mins = when / (60 * fr);
607 remainder = when - (mins * 60 * fr);
608 secs = remainder / fr;
609 remainder -= secs * fr;
610 frames = remainder / (fr / 75);
611 sprintf (buf, " %02d:%02d:%02d", mins, secs, frames);
615 struct LocationSortByStart {
616 bool operator() (Location *a, Location *b) {
617 return a->start() < b->start();
622 ExportDialog::export_toc_file (Locations::LocationList& locations, const string& path)
624 if(!export_cd_markers_allowed){
628 string filepath = path + ".toc";
629 ofstream out (filepath.c_str());
630 long unsigned int last_end_time = spec.start_frame, last_start_time = spec.start_frame;
635 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD toc file"), filepath) << endmsg;
638 out << "CD_DA" << endl;
639 out << "CD_TEXT {" << endl << " LANGUAGE_MAP {" << endl << " 0 : EN" << endl << " }" << endl;
640 out << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl << " }" << endl << "}" << endl;
642 Locations::LocationList::iterator i;
643 Locations::LocationList temp;
645 for (i = locations.begin(); i != locations.end(); ++i) {
646 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
648 if (!(*i)->is_mark()) {
654 if (numtracks == 0 ) {
655 /* the user supplied no track markers.
656 we now treat the session as one track.*/
658 out << endl << "TRACK AUDIO" << endl;
660 out << "COPY" << endl;
662 out << "NO PRE_EMPHASIS" << endl;
664 /* XXX add session properties for catalog etc.
665 (so far only the session name is used) */
667 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl;
668 out << " }" << endl << "}" << endl;
670 out << "FILE \"" << path << "\" ";
672 frames_to_cd_frames_string (buf, spec.end_frame - spec.start_frame, session->frame_rate());
674 out << "START 00:00:00" << endl;
676 last_start_time = spec.start_frame;
677 last_end_time = spec.end_frame;
681 LocationSortByStart cmp;
684 for (i = temp.begin(); i != temp.end(); ++i) {
686 if (!(*i)->is_mark()) {
688 out << endl << "TRACK AUDIO" << endl;
690 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
693 out << "COPY" << endl;
695 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
696 out << "PRE_EMPHASIS" << endl;
698 out << "NO PRE_EMPHASIS" << endl;
701 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
702 out << "ISRC \"" << (*i)->cd_info["isrc"] << "\"" << endl;
705 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << (*i)->name() << "\"" << endl;
706 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
707 out << " PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
709 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
710 out << " COMPOSER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
713 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
715 out << (*i)->cd_info["isrc"].substr(0,2) << "-";
716 out << (*i)->cd_info["isrc"].substr(2,3) << "-";
717 out << (*i)->cd_info["isrc"].substr(5,2) << "-";
718 out << (*i)->cd_info["isrc"].substr(7,5) << "\"" << endl;
721 out << " }" << endl << "}" << endl;
723 frames_to_cd_frames_string (buf, last_end_time - spec.start_frame, session->frame_rate());
724 out << "FILE \"" << path << "\" " << buf;
726 frames_to_cd_frames_string (buf, (*i)->end() - last_end_time, session->frame_rate());
729 frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
730 out << "START" << buf << endl;
732 last_start_time = (*i)->start();
733 last_end_time = (*i)->end();
736 } else if ((*i)->start() < last_end_time) {
737 /* this is an index within a track */
739 frames_to_cd_frames_string (buf, (*i)->start() - last_start_time, session->frame_rate());
740 out << "INDEX" << buf << endl;
748 ExportDialog::export_cue_file (Locations::LocationList& locations, const string& path)
750 if(!export_cd_markers_allowed){
754 string filepath = path + ".cue";
755 ofstream out (filepath.c_str());
757 long unsigned int last_track_end = spec.start_frame;
758 int numtracks = 0, tracknum = 0, indexnum = 0;
761 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD cue file"), filepath) << endmsg;
765 Locations::LocationList::iterator i;
766 Locations::LocationList temp;
768 for (i = locations.begin(); i != locations.end(); ++i) {
769 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
771 if (!(*i)->is_mark()) {
777 out << "REM Cue file generated by Ardour" << endl;
778 out << "TITLE \"" << session->name() << "\"" << endl;
780 if ((header_format_combo.get_active_text() == N_("WAV"))) {
781 out << "FILE " << path << " WAVE" << endl;
783 out << "FILE " << path << ' ' << (header_format_combo.get_active_text()) << endl;
786 if (numtracks == 0) {
787 /* the user has supplied no track markers.
788 the entire export is treated as one track.
794 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
797 out << "DCP " << endl;
799 /* use the session name*/
801 if (session->name() != "") {
802 out << "TITLE \"" << session->name() << "\"" << endl;
805 /* no pregap in this case */
807 out << "INDEX 00 00:00:00" << endl;
809 out << "INDEX 01 00:00:00" << endl;
811 last_track_end = spec.end_frame;
815 LocationSortByStart cmp;
818 for ( i = temp.begin(); i != temp.end(); ++i) {
820 if (!(*i)->is_mark() && ((*i)->start() >= last_track_end)) {
821 /* this is a track and it doesn't start inside another one*/
825 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
828 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
834 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
839 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
840 out << "ISRC " << (*i)->cd_info["isrc"] << endl;
843 if ((*i)->name() != "") {
844 out << "TITLE \"" << (*i)->name() << "\"" << endl;
847 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
848 out << "PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
851 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
852 out << "SONGWRITER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
854 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
856 frames_to_cd_frames_string (buf, last_track_end - spec.start_frame, session->frame_rate());
859 last_track_end = (*i)->end();
861 if ((tracknum > 0) && ((*i)->start() < last_track_end)) {
862 /*this is an index and it lies within a track*/
863 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
865 frames_to_cd_frames_string (buf,(*i)->start() - spec.start_frame, session->frame_rate());
875 ExportDialog::do_export_cd_markers (const string& path,const string& cuefile_type)
877 if (cuefile_type == _("TOC")) {
878 session->locations()->apply (*this, &ExportDialog::export_toc_file, path);
880 session->locations()->apply (*this, &ExportDialog::export_cue_file, path);
886 ExportDialog::do_export ()
888 string filepath = file_entry.get_text();
890 if(!is_filepath_valid(filepath)){
894 if (export_cd_markers_allowed) {
895 if (cue_file_combo.get_active_text () != _("None")) {
896 do_export_cd_markers (file_entry.get_text(), cue_file_combo.get_active_text ());
899 if (cuefile_only_checkbox.get_active()) {
905 ok_button->set_sensitive(false);
910 // read user input into spec
913 progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
914 cancel_label.set_text (_("Stop Export"));
918 progress_connection.disconnect ();
923 ExportDialog::end_dialog ()
928 while (spec.running) {
929 if (gtk_events_pending()) {
930 gtk_main_iteration ();
937 session->finalize_audio_export ();
942 ok_button->set_sensitive(true);
946 ExportDialog::start_export ()
952 /* If the filename hasn't been set before, use the
953 current session's export directory as a default
954 location for the export.
957 if (file_entry.get_text().length() == 0) {
958 string dir = session->export_dir();
959 string::size_type last_slash;
961 if ((last_slash = dir.find_last_of ('/')) != string::npos && last_slash != 0) {
962 dir = dir.substr (0, last_slash+1);
966 dir = dir + "export.wav";
969 file_entry.set_text (dir);
972 progress_bar.set_fraction (0);
973 cancel_label.set_text (_("Cancel"));
977 if (session->master_out()) {
978 track_scroll.hide ();
980 master_scroll.hide ();
981 track_selector_button.hide ();
986 ExportDialog::header_chosen ()
988 if (sndfile_header_format_from_string (header_format_combo.get_active_text ()) == SF_FORMAT_WAV) {
989 endian_format_combo.set_sensitive (false);
991 endian_format_combo.set_sensitive (true);
996 ExportDialog::bitdepth_chosen ()
998 int format = sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
1000 case SF_FORMAT_PCM_24:
1001 case SF_FORMAT_PCM_32:
1002 case SF_FORMAT_FLOAT:
1003 dither_type_combo.set_sensitive (false);
1007 dither_type_combo.set_sensitive (true);
1013 ExportDialog::cue_file_type_chosen ()
1015 if (cue_file_combo.get_active_text () != "None") {
1016 cuefile_only_checkbox.set_sensitive (true);
1018 cuefile_only_checkbox.set_active (false);
1019 cuefile_only_checkbox.set_sensitive (false);
1024 ExportDialog::sample_rate_chosen ()
1026 string sr_str = sample_rate_combo.get_active_text();
1029 if (sr_str == N_("22.05kHz")) {
1031 } else if (sr_str == _("44.1kHz")) {
1033 } else if (sr_str == _("48kHz")) {
1035 } else if (sr_str == _("88.2kHz")) {
1037 } else if (sr_str == _("96kHz")) {
1039 } else if (sr_str == _("192kHz")) {
1042 rate = session->frame_rate();
1045 if (rate != session->frame_rate()) {
1046 src_quality_combo.set_sensitive (true);
1048 src_quality_combo.set_sensitive (false);
1053 ExportDialog::channels_chosen ()
1057 mono = (channel_count_combo.get_active_text() == _("mono"));
1060 track_selector.get_column(2)->set_visible(false);
1061 track_selector.get_column(1)->set_title(_("Export"));
1063 if (session->master_out()) {
1064 master_selector.get_column(2)->set_visible(false);
1065 master_selector.get_column(1)->set_title(_("Export"));
1069 track_selector.get_column(2)->set_visible(true);
1070 track_selector.get_column(1)->set_title(_("Left"));
1072 if (session->master_out()) {
1073 master_selector.get_column(2)->set_visible(true);
1074 master_selector.get_column(1)->set_title(_("Left"));
1082 ExportDialog::fill_lists ()
1084 track_list->clear();
1085 master_list->clear();
1087 boost::shared_ptr<Session::RouteList> routes = session->get_routes ();
1089 for (Session::RouteList::iterator ri = routes->begin(); ri != routes->end(); ++ri) {
1091 boost::shared_ptr<Route> route = (*ri);
1093 if (route->hidden()) {
1097 for (uint32_t i=0; i < route->n_outputs(); ++i) {
1099 if (route->n_outputs() == 1) {
1100 name = route->name();
1102 name = string_compose("%1: out-%2", route->name(), i+1);
1105 if (route == session->master_out()) {
1106 TreeModel::iterator iter = master_list->append();
1107 TreeModel::Row row = *iter;
1108 row[exp_cols.output] = name;
1109 row[exp_cols.left] = false;
1110 row[exp_cols.right] = false;
1111 row[exp_cols.port] = route->output (i);
1113 TreeModel::iterator iter = track_list->append();
1114 TreeModel::Row row = *iter;
1115 row[exp_cols.output] = name;
1116 row[exp_cols.left] = false;
1117 row[exp_cols.right] = false;
1118 row[exp_cols.port] = route->output (i);
1126 ExportDialog::is_filepath_valid(string &filepath)
1128 // sanity check file name first
1130 struct stat statbuf;
1132 if (filepath.empty()) {
1133 string txt = _("Please enter a valid filename.");
1134 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1139 // check if file exists already and warn
1141 if (stat (filepath.c_str(), &statbuf) == 0) {
1142 if (S_ISDIR (statbuf.st_mode)) {
1143 string txt = _("Please specify a complete filename for the audio file.");
1144 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1149 string txt = _("File already exists, do you want to overwrite it?");
1150 MessageDialog msg (*this, txt, false, MESSAGE_QUESTION, BUTTONS_YES_NO, true);
1151 if ((ResponseType) msg.run() == Gtk::RESPONSE_NO) {
1157 // directory needs to exist and be writable
1159 string dirpath = Glib::path_get_dirname (filepath);
1160 if (::access (dirpath.c_str(), W_OK) != 0) {
1161 string txt = _("Cannot write file in: ") + dirpath;
1162 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1171 ExportDialog::initSpec(string &filepath)
1173 spec.path = filepath;
1175 spec.running = true;
1177 spec.port_map.clear();
1179 if (channel_count_combo.get_active_text() == _("mono")) {
1187 spec.format |= sndfile_header_format_from_string (header_format_combo.get_active_text ());
1189 if ((spec.format & SF_FORMAT_WAV) == 0) {
1190 /* RIFF/WAV specifies endianess */
1191 spec.format |= sndfile_endian_format_from_string (endian_format_combo.get_active_text ());
1194 spec.format |= sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
1196 string sr_str = sample_rate_combo.get_active_text();
1197 if (sr_str == N_("22.05kHz")) {
1198 spec.sample_rate = 22050;
1199 } else if (sr_str == _("44.1kHz")) {
1200 spec.sample_rate = 44100;
1201 } else if (sr_str == _("48kHz")) {
1202 spec.sample_rate = 48000;
1203 } else if (sr_str == _("88.2kHz")) {
1204 spec.sample_rate = 88200;
1205 } else if (sr_str == _("96kHz")) {
1206 spec.sample_rate = 96000;
1207 } else if (sr_str == _("192kHz")) {
1208 spec.sample_rate = 192000;
1210 spec.sample_rate = session->frame_rate();
1213 string src_str = src_quality_combo.get_active_text();
1214 if (src_str == _("fastest")) {
1215 spec.src_quality = SRC_ZERO_ORDER_HOLD;
1216 } else if (src_str == _("linear")) {
1217 spec.src_quality = SRC_LINEAR;
1218 } else if (src_str == _("better")) {
1219 spec.src_quality = SRC_SINC_FASTEST;
1220 } else if (src_str == _("intermediate")) {
1221 spec.src_quality = SRC_SINC_MEDIUM_QUALITY;
1223 spec.src_quality = SRC_SINC_BEST_QUALITY;
1226 string dither_str = dither_type_combo.get_active_text();
1227 if (dither_str == _("None")) {
1228 spec.dither_type = GDitherNone;
1229 } else if (dither_str == _("Rectangular")) {
1230 spec.dither_type = GDitherRect;
1231 } else if (dither_str == _("Triangular")) {
1232 spec.dither_type = GDitherTri;
1234 spec.dither_type = GDitherShaped;
1237 write_track_and_master_selection_to_spec();
1242 ExportDialog::write_track_and_master_selection_to_spec()
1244 if(!track_and_master_selection_allowed){
1249 Port *last_port = 0;
1251 TreeModel::Children rows = master_selector.get_model()->children();
1252 TreeModel::Children::iterator ri;
1254 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1256 Port* port = row[exp_cols.port];
1258 if (last_port != port) {
1262 if (row[exp_cols.left]) {
1263 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1266 if (spec.channels == 2) {
1267 if (row[exp_cols.right]) {
1268 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1274 rows = track_selector.get_model()->children();
1276 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1279 Port* port = row[exp_cols.port];
1281 if (last_port != port) {
1285 if (row[exp_cols.left]) {
1286 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1289 if (spec.channels == 2) {
1290 if (row[exp_cols.right]) {
1291 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1303 ExportDialog::window_closed (GdkEventAny *ignored)
1310 ExportDialog::browse ()
1312 FileChooserDialog dialog("Export to file", browse_action());
1313 dialog.set_transient_for(*this);
1314 dialog.set_filename (file_entry.get_text());
1316 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1317 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
1319 int result = dialog.run();
1321 if (result == Gtk::RESPONSE_OK) {
1322 string filename = dialog.get_filename();
1324 if (filename.length()) {
1325 file_entry.set_text (filename);
1331 ExportDialog::track_selector_button_click ()
1333 if (track_scroll.is_visible ()) {
1334 track_scroll.hide ();
1336 track_scroll.show_all ();