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/audiofilesource.h>
41 #include <ardour/gdither.h>
42 #include <ardour/utils.h>
44 #include "export_dialog.h"
45 #include "ardour_ui.h"
46 #include "public_editor.h"
51 #define FRAME_NAME "BaseFrame"
54 using namespace ARDOUR;
58 using namespace Gtkmm2ext;
60 using PBD::internationalize;
62 static const gchar *sample_rates[] = {
72 static const gchar *src_quality[] = {
81 static const gchar *dither_types[] = {
89 static const gchar* channel_strings[] = {
95 static const gchar* cue_file_types[] = {
102 ExportDialog::ExportDialog(PublicEditor& e)
103 : ArdourDialog ("export dialog"),
106 format_frame (_("Format")),
107 cue_file_label (_("CD Marker File Type"), 1.0, 0.5),
108 channel_count_label (_("Channels"), 1.0, 0.5),
109 header_format_label (_("File Type"), 1.0, 0.5),
110 bitdepth_format_label (_("Sample Format"), 1.0, 0.5),
111 endian_format_label (_("Sample Endianness"), 1.0, 0.5),
112 sample_rate_label (_("Sample Rate"), 1.0, 0.5),
113 src_quality_label (_("Conversion Quality"), 1.0, 0.5),
114 dither_type_label (_("Dither Type"), 1.0, 0.5),
115 cuefile_only_checkbox (_("Export CD Marker File Only")),
116 file_chooser (FILE_CHOOSER_ACTION_SAVE),
117 track_selector_button (_("Specific tracks ..."))
124 track_and_master_selection_allowed = true;
125 channel_count_selection_allowed = true;
126 export_cd_markers_allowed = true;
127 set_resizable (false);
129 WindowTitle title(Glib::get_application_name());
130 title += _("Export");
132 set_title (title.get_string());
133 set_wmclass (X_("ardour_export"), "Ardour");
134 set_name ("ExportWindow");
135 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
137 spec.running = false;
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, PACK_EXPAND_WIDGET);
181 hpacker.set_spacing (5);
182 hpacker.set_border_width (5);
183 hpacker.pack_start (format_frame, PACK_SHRINK );
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, PACK_SHRINK);
200 track_selector_button.set_name ("EditorGTKButton");
201 track_selector_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::track_selector_button_click));
203 Gtk::FileFilter filter_wav;
204 filter_wav.set_name("Wav files");
205 filter_wav.add_mime_type("audio/wav");
206 file_chooser.add_filter(filter_wav);
208 Gtk::FileFilter filter_aiff;
209 filter_aiff.set_name("Aiff files");
210 filter_aiff.add_mime_type("audio/aiff");
211 filter_aiff.add_pattern("*.aif");
212 filter_aiff.add_pattern("*.aiff");
213 file_chooser.add_filter(filter_aiff);
215 Gtk::FileFilter filter_any;
216 filter_any.set_name("All files");
217 filter_any.add_pattern("*");
218 file_chooser.add_filter(filter_any);
219 file_chooser.set_no_show_all();
221 get_vbox()->pack_start (progress_bar, false, false, 5);
222 progress_bar.set_no_show_all();
225 file_hbox.set_spacing (5);
226 file_hbox.set_border_width (5);
227 file_hbox.pack_start (file_chooser, PACK_EXPAND_WIDGET);
229 file_frame.add (file_hbox);
230 file_frame.set_border_width (5);
231 file_frame.set_name (FRAME_NAME);
233 /* pop_strings needs to be created on the stack because set_popdown_strings()
237 vector<string> pop_strings = I18N(sample_rates);
238 Gtkmm2ext::set_popdown_strings (sample_rate_combo, pop_strings);
239 sample_rate_combo.set_active_text (pop_strings.front());
240 pop_strings = I18N(src_quality);
241 Gtkmm2ext::set_popdown_strings (src_quality_combo, pop_strings);
242 src_quality_combo.set_active_text (pop_strings.front());
243 pop_strings = I18N(dither_types);
244 Gtkmm2ext::set_popdown_strings (dither_type_combo, pop_strings);
245 dither_type_combo.set_active_text (pop_strings.front());
246 pop_strings = I18N(channel_strings);
247 Gtkmm2ext::set_popdown_strings (channel_count_combo, pop_strings);
248 channel_count_combo.set_active_text (pop_strings.front());
249 pop_strings = I18N((const char **) sndfile_header_formats_strings);
250 Gtkmm2ext::set_popdown_strings (header_format_combo, pop_strings);
251 header_format_combo.set_active_text (pop_strings.front());
252 pop_strings = I18N((const char **) sndfile_bitdepth_formats_strings);
253 Gtkmm2ext::set_popdown_strings (bitdepth_format_combo, pop_strings);
254 bitdepth_format_combo.set_active_text (pop_strings.front());
255 pop_strings = I18N((const char **) sndfile_endian_formats_strings);
256 Gtkmm2ext::set_popdown_strings (endian_format_combo, pop_strings);
257 endian_format_combo.set_active_text (pop_strings.front());
258 pop_strings = I18N(cue_file_types);
259 Gtkmm2ext::set_popdown_strings (cue_file_combo, pop_strings);
260 cue_file_combo.set_active_text (pop_strings.front());
262 /* this will re-sensitized as soon as a non RIFF/WAV
263 header format is chosen.
266 endian_format_combo.set_sensitive (false);
268 /* determine longest strings at runtime */
271 const char *longest = X_("gl"); /* translators: one ascender, one descender */
274 for (n = 0; n < SNDFILE_HEADER_FORMATS; ++n) {
275 if ((len = strlen (sndfile_header_formats_strings[n])) > maxlen) {
277 longest = sndfile_header_formats_strings[n];
281 for (n = 0; n < SNDFILE_BITDEPTH_FORMATS; ++n) {
282 if ((len = strlen (sndfile_bitdepth_formats_strings[n])) > maxlen) {
284 longest = sndfile_bitdepth_formats_strings[n];
288 for (n = 0; n < SNDFILE_ENDIAN_FORMATS; ++n) {
289 if ((len = strlen (sndfile_endian_formats_strings[n])) > maxlen) {
291 longest = sndfile_endian_formats_strings[n];
295 longest_str = longest;
297 /* force ascender + descender */
299 longest_str[0] = 'g';
300 longest_str[1] = 'l';
302 //Gtkmm2ext::set_size_request_to_display_given_text (header_format_combo, longest_str.c_str(), 5+FUDGE, 5);
304 // TRANSLATORS: "slereg" is "stereo" with ascender and descender substituted
305 //Gtkmm2ext::set_size_request_to_display_given_text (channel_count_combo, _("slereg"), 5+FUDGE, 5);
307 /* header_format_combo.set_focus_on_click (true);
308 bitdepth_format_combo.set_focus_on_click (true);
309 endian_format_combo.set_focus_on_click (true);
310 channel_count_combo.set_focus_on_click (true);
311 src_quality_combo.set_focus_on_click (true);
312 dither_type_combo.set_focus_on_click (true);
313 sample_rate_combo.set_focus_on_click (true);
314 cue_file_combo.set_focus_on_click (true);
316 dither_type_label.set_name ("ExportFormatLabel");
317 sample_rate_label.set_name ("ExportFormatLabel");
318 src_quality_label.set_name ("ExportFormatLabel");
319 channel_count_label.set_name ("ExportFormatLabel");
320 header_format_label.set_name ("ExportFormatLabel");
321 bitdepth_format_label.set_name ("ExportFormatLabel");
322 endian_format_label.set_name ("ExportFormatLabel");
323 cue_file_label.set_name ("ExportFormatLabel");
325 header_format_combo.set_name ("ExportFormatDisplay");
326 bitdepth_format_combo.set_name ("ExportFormatDisplay");
327 endian_format_combo.set_name ("ExportFormatDisplay");
328 channel_count_combo.set_name ("ExportFormatDisplay");
329 dither_type_combo.set_name ("ExportFormatDisplay");
330 src_quality_combo.set_name ("ExportFormatDisplay");
331 sample_rate_combo.set_name ("ExportFormatDisplay");
332 cue_file_combo.set_name ("ExportFormatDisplay");
334 cuefile_only_checkbox.set_name ("ExportCheckbox");
336 format_table.set_homogeneous (true);
337 format_table.set_border_width (5);
338 format_table.set_col_spacings (5);
339 format_table.set_row_spacings (5);
341 format_table.attach (channel_count_label, 0, 1, 0, 1, FILL, FILL);
342 format_table.attach (channel_count_combo, 1, 2, 0, 1, FILL, FILL);
344 format_table.attach (header_format_label, 0, 1, 1, 2, FILL, FILL);
345 format_table.attach (header_format_combo, 1, 2, 1, 2, FILL, FILL);
347 format_table.attach (bitdepth_format_label, 0, 1, 2, 3, FILL, FILL);
348 format_table.attach (bitdepth_format_combo, 1, 2, 2, 3, FILL, FILL);
350 format_table.attach (endian_format_label, 0, 1, 3, 4, FILL, FILL);
351 format_table.attach (endian_format_combo, 1, 2, 3, 4, FILL, FILL);
353 format_table.attach (sample_rate_label, 0, 1, 4, 5, FILL, FILL);
354 format_table.attach (sample_rate_combo, 1, 2, 4, 5, FILL, FILL);
356 format_table.attach (src_quality_label, 0, 1, 5, 6, FILL, FILL);
357 format_table.attach (src_quality_combo, 1, 2, 5, 6, FILL, FILL);
359 format_table.attach (dither_type_label, 0, 1, 6, 7, FILL, FILL);
360 format_table.attach (dither_type_combo, 1, 2, 6, 7, FILL, FILL);
362 format_table.attach (cue_file_label, 0, 1, 7, 8, FILL, FILL);
363 format_table.attach (cue_file_combo, 1, 2, 7, 8, FILL, FILL);
364 format_table.attach (cuefile_only_checkbox, 0, 2, 8, 9, FILL, FILL);
366 signal_delete_event().connect (mem_fun(*this, &ExportDialog::window_closed));
368 cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
369 cancel_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::end_dialog));
370 ok_button = add_button (_("Export"), RESPONSE_ACCEPT);
371 ok_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::do_export));
372 channel_count_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::channels_chosen));
373 bitdepth_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::bitdepth_chosen));
374 header_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::header_chosen));
375 sample_rate_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::sample_rate_chosen));
376 cue_file_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::cue_file_type_chosen));
378 file_chooser.signal_update_preview().connect (mem_fun(*this, &ExportDialog::file_chooser_selection_changed));
382 ExportDialog::~ExportDialog()
387 ExportDialog::do_not_allow_track_and_master_selection()
389 track_and_master_selection_allowed = false;
393 ExportDialog::do_not_allow_channel_count_selection()
395 channel_count_selection_allowed = false;
399 ExportDialog::do_not_allow_export_cd_markers()
401 export_cd_markers_allowed = false;
405 ExportDialog::connect_to_session (Session *s)
408 session->GoingAway.connect (mem_fun(*this, &Window::hide_all));
410 switch (session->frame_rate()) {
412 sample_rate_combo.set_active_text (_("22.05kHz"));
415 sample_rate_combo.set_active_text (_("44.1kHz"));
418 sample_rate_combo.set_active_text (_("48kHz"));
421 sample_rate_combo.set_active_text (_("88.2kHz"));
424 sample_rate_combo.set_active_text (_("96kHz"));
427 sample_rate_combo.set_active_text (_("192kHz"));
430 sample_rate_combo.set_active_text (_("44.1kHz"));
434 src_quality_combo.set_sensitive (false);
440 ExportDialog::set_state()
442 XMLNode* node = session->instant_xml(X_("ExportDialog"));
444 bool fc_location_requested = false;
447 if ((prop = node->property (X_("sample_rate"))) != 0) {
448 sample_rate_combo.set_active_text(prop->value());
450 if ((prop = node->property (X_("src_quality"))) != 0) {
451 src_quality_combo.set_active_text(prop->value());
453 if ((prop = node->property (X_("dither_type"))) != 0) {
454 dither_type_combo.set_active_text(prop->value());
456 if ((prop = node->property (X_("channel_count"))) != 0) {
457 channel_count_combo.set_active_text(prop->value());
459 if ((prop = node->property (X_("header_format"))) != 0) {
460 header_format_combo.set_active_text(prop->value());
462 if ((prop = node->property (X_("bitdepth_format"))) != 0) {
463 bitdepth_format_combo.set_active_text(prop->value());
465 if ((prop = node->property (X_("endian_format"))) != 0) {
466 endian_format_combo.set_active_text(prop->value());
468 if ((prop = node->property (X_("filename"))) != 0) {
469 file_chooser.set_filename(prop->value());
470 fc_location_requested = true;
471 file_chooser.set_current_folder(Glib::path_get_basename(prop->value()));
474 if ((prop = node->property (X_("cue_file_type"))) != 0) {
475 cue_file_combo.set_active_text(prop->value());
479 if (!fc_location_requested) {
482 If the filename hasn't been set before, use the
483 current session's export directory as a default
484 location for the export.
487 file_chooser.set_current_folder (session->session_directory().export_path().to_string());
488 file_chooser.set_current_name (_("export.wav"));
494 sample_rate_chosen();
496 if (session->master_out()) {
497 track_scroll.hide ();
499 master_scroll.hide ();
500 track_selector_button.hide ();
507 if (session->master_out()) {
508 XMLNode* master = find_named_node(*node, (X_("Master")));
513 /* default is to use all */
514 if (channel_count_combo.get_active_text() == _("Mono")) {
520 TreeModel::Children rows = master_selector.get_model()->children();
521 for (uint32_t r = 0; r < session->master_out()->n_outputs().n_audio(); ++r) {
524 rows[r][exp_cols.right] = true;
526 rows[r][exp_cols.left] = true;
529 rows[r][exp_cols.left] = true;
534 /* XXX use XML state */
538 XMLNode* tracks = find_named_node(*node, (X_("Tracks")));
543 XMLNodeList track_list = tracks->children(X_("Track"));
544 TreeModel::Children rows = track_selector.get_model()->children();
545 TreeModel::Children::iterator ri = rows.begin();
548 for (XMLNodeIterator it = track_list.begin(); it != track_list.end(); ++it, ++ri) {
549 if (ri == rows.end()){
553 XMLNode* track = *it;
556 if ((prop = track->property(X_("channel1"))) != 0) {
557 if (prop->value() == X_("on")) {
558 row[exp_cols.left] = true;
560 row[exp_cols.left] = false;
564 if ((prop = track->property(X_("channel2"))) != 0) {
565 if (prop->value() == X_("on")) {
566 row[exp_cols.right] = true;
568 row[exp_cols.right] = false;
575 ExportDialog::save_state()
581 XMLNode* node = new XMLNode(X_("ExportDialog"));
583 node->add_property(X_("sample_rate"), sample_rate_combo.get_active_text());
584 node->add_property(X_("src_quality"), src_quality_combo.get_active_text());
585 node->add_property(X_("dither_type"), dither_type_combo.get_active_text());
586 node->add_property(X_("channel_count"), channel_count_combo.get_active_text());
587 node->add_property(X_("header_format"), header_format_combo.get_active_text());
588 node->add_property(X_("bitdepth_format"), bitdepth_format_combo.get_active_text());
589 node->add_property(X_("endian_format"), endian_format_combo.get_active_text());
590 node->add_property(X_("filename"), file_chooser.get_filename());
591 node->add_property(X_("cue_file_type"), cue_file_combo.get_active_text());
593 XMLNode* tracks = new XMLNode(X_("Tracks"));
595 TreeModel::Children rows = track_selector.get_model()->children();
597 for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
598 XMLNode* track = new XMLNode(X_("Track"));
601 track->add_property(X_("channel1"), row[exp_cols.left] ? X_("on") : X_("off"));
602 track->add_property(X_("channel2"), row[exp_cols.right] ? X_("on") : X_("off"));
604 tracks->add_child_nocopy(*track);
606 node->add_child_nocopy(*tracks);
608 session->add_instant_xml(*node);
612 ExportDialog::set_range (nframes_t start, nframes_t end)
614 spec.start_frame = start;
615 spec.end_frame = end;
619 ExportDialog::progress_timeout ()
621 progress_bar.set_fraction (spec.progress);
626 frames_to_cd_frames_string (char* buf, nframes_t when, nframes_t fr)
629 long unsigned int remainder;
630 int mins, secs, frames;
632 mins = when / (60 * fr);
633 remainder = when - (mins * 60 * fr);
634 secs = remainder / fr;
635 remainder -= secs * fr;
636 frames = remainder / (fr / 75);
637 sprintf (buf, " %02d:%02d:%02d", mins, secs, frames);
641 struct LocationSortByStart {
642 bool operator() (Location *a, Location *b) {
643 return a->start() < b->start();
648 ExportDialog::export_toc_file (Locations::LocationList& locations, const string& path)
650 if(!export_cd_markers_allowed){
654 string filepath = path + ".toc";
655 ofstream out (filepath.c_str());
656 long unsigned int last_end_time = spec.start_frame, last_start_time = spec.start_frame;
661 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD toc file"), filepath) << endmsg;
664 out << "CD_DA" << endl;
665 out << "CD_TEXT {" << endl << " LANGUAGE_MAP {" << endl << " 0 : EN" << endl << " }" << endl;
666 out << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl << " }" << endl << "}" << endl;
668 Locations::LocationList::iterator i;
669 Locations::LocationList temp;
671 for (i = locations.begin(); i != locations.end(); ++i) {
672 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
674 if (!(*i)->is_mark()) {
680 if (numtracks == 0 ) {
681 /* the user supplied no track markers.
682 we now treat the session as one track.*/
684 out << endl << "TRACK AUDIO" << endl;
686 out << "COPY" << endl;
688 out << "NO PRE_EMPHASIS" << endl;
690 /* XXX add session properties for catalog etc.
691 (so far only the session name is used) */
693 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl;
694 out << " }" << endl << "}" << endl;
696 out << "FILE \"" << path << "\" ";
698 frames_to_cd_frames_string (buf, spec.end_frame - spec.start_frame, session->frame_rate());
700 out << "START 00:00:00" << endl;
702 last_start_time = spec.start_frame;
703 last_end_time = spec.end_frame;
707 LocationSortByStart cmp;
710 for (i = temp.begin(); i != temp.end(); ++i) {
712 if (!(*i)->is_mark()) {
714 out << endl << "TRACK AUDIO" << endl;
716 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
719 out << "COPY" << endl;
721 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
722 out << "PRE_EMPHASIS" << endl;
724 out << "NO PRE_EMPHASIS" << endl;
727 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
728 out << "ISRC \"" << (*i)->cd_info["isrc"] << "\"" << endl;
731 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << (*i)->name() << "\"" << endl;
732 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
733 out << " PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
735 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
736 out << " COMPOSER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
739 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
741 out << (*i)->cd_info["isrc"].substr(0,2) << "-";
742 out << (*i)->cd_info["isrc"].substr(2,3) << "-";
743 out << (*i)->cd_info["isrc"].substr(5,2) << "-";
744 out << (*i)->cd_info["isrc"].substr(7,5) << "\"" << endl;
747 out << " }" << endl << "}" << endl;
749 frames_to_cd_frames_string (buf, last_end_time - spec.start_frame, session->frame_rate());
750 out << "FILE \"" << path << "\" " << buf;
752 frames_to_cd_frames_string (buf, (*i)->end() - last_end_time, session->frame_rate());
755 frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
756 out << "START" << buf << endl;
758 last_start_time = (*i)->start();
759 last_end_time = (*i)->end();
762 } else if ((*i)->start() < last_end_time) {
763 /* this is an index within a track */
765 frames_to_cd_frames_string (buf, (*i)->start() - last_start_time, session->frame_rate());
766 out << "INDEX" << buf << endl;
774 ExportDialog::export_cue_file (Locations::LocationList& locations, const string& path)
776 if(!export_cd_markers_allowed){
780 string filepath = path + ".cue";
781 ofstream out (filepath.c_str());
783 long unsigned int last_track_end = spec.start_frame;
784 int numtracks = 0, tracknum = 0, indexnum = 0;
787 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD cue file"), filepath) << endmsg;
791 Locations::LocationList::iterator i;
792 Locations::LocationList temp;
794 for (i = locations.begin(); i != locations.end(); ++i) {
795 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
797 if (!(*i)->is_mark()) {
803 out << "REM Cue file generated by Ardour" << endl;
804 out << "TITLE \"" << session->name() << "\"" << endl;
806 if ((header_format_combo.get_active_text() == N_("WAV"))) {
807 out << "FILE " << path << " WAVE" << endl;
809 out << "FILE " << path << ' ' << (header_format_combo.get_active_text()) << endl;
812 if (numtracks == 0) {
813 /* the user has supplied no track markers.
814 the entire export is treated as one track.
820 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
823 out << "DCP " << endl;
825 /* use the session name*/
827 if (session->name() != "") {
828 out << "TITLE \"" << session->name() << "\"" << endl;
831 /* no pregap in this case */
833 out << "INDEX 00 00:00:00" << endl;
835 out << "INDEX 01 00:00:00" << endl;
837 last_track_end = spec.end_frame;
841 LocationSortByStart cmp;
844 for ( i = temp.begin(); i != temp.end(); ++i) {
846 if (!(*i)->is_mark() && ((*i)->start() >= last_track_end)) {
847 /* this is a track and it doesn't start inside another one*/
851 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
854 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
860 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
865 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
866 out << "ISRC " << (*i)->cd_info["isrc"] << endl;
869 if ((*i)->name() != "") {
870 out << "TITLE \"" << (*i)->name() << "\"" << endl;
873 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
874 out << "PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
877 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
878 out << "SONGWRITER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
880 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
882 frames_to_cd_frames_string (buf, last_track_end - spec.start_frame, session->frame_rate());
885 last_track_end = (*i)->end();
887 if ((tracknum > 0) && ((*i)->start() < last_track_end)) {
888 /*this is an index and it lies within a track*/
889 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
891 frames_to_cd_frames_string (buf,(*i)->start() - spec.start_frame, session->frame_rate());
901 ExportDialog::do_export_cd_markers (const string& path,const string& cuefile_type)
903 if (cuefile_type == _("TOC")) {
904 session->locations()->apply (*this, &ExportDialog::export_toc_file, path);
906 session->locations()->apply (*this, &ExportDialog::export_cue_file, path);
912 ExportDialog::do_export ()
914 string filepath = file_chooser.get_filename();
916 if(!is_filepath_valid(filepath)){
920 if (export_cd_markers_allowed) {
921 if (cue_file_combo.get_active_text () != _("None")) {
922 do_export_cd_markers (file_chooser.get_filename(), cue_file_combo.get_active_text ());
925 if (cuefile_only_checkbox.get_active()) {
931 ok_button->set_sensitive(false);
936 // read user input into spec
940 progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
941 cancel_label.set_text (_("Stop Export"));
945 progress_connection.disconnect ();
946 session->engine().freewheel (false);
952 ExportDialog::end_dialog ()
957 while (spec.running) {
958 if (gtk_events_pending()) {
959 gtk_main_iteration ();
968 session->finalize_audio_export ();
971 ok_button->set_sensitive(true);
975 ExportDialog::start_export ()
981 /* If the filename hasn't been set before, use the
982 current session's export directory as a default
983 location for the export.
986 if (file_entry.get_text().length() == 0) {
988 sys::path export_file_path = session->session_directory().export_path();
991 export_file_path /= "export.wav";
994 file_entry.set_text (export_file_path.to_string());
997 progress_bar.set_fraction (0);
999 progress_bar.set_no_show_all();
1000 cancel_label.set_text (_("Cancel"));
1004 if (track_and_master_selection_allowed) {
1005 track_vpacker.show();
1007 track_vpacker.hide();
1010 file_chooser.show();
1012 if (channel_count_selection_allowed) {
1013 channel_count_combo.show();
1014 channel_count_label.show();
1016 channel_count_combo.hide();
1017 channel_count_label.hide();
1020 if (export_cd_markers_allowed) {
1021 cue_file_label.show();
1022 cue_file_combo.show();
1023 cuefile_only_checkbox.show();
1025 cue_file_label.hide();
1026 cue_file_combo.hide();
1027 cuefile_only_checkbox.hide();
1030 if (session->master_out()) {
1031 track_scroll.hide ();
1033 master_scroll.hide ();
1034 track_selector_button.hide ();
1037 track_and_master_selection_allowed = true;
1038 channel_count_selection_allowed = true;
1039 export_cd_markers_allowed = true;
1043 ExportDialog::header_chosen ()
1045 if (sndfile_header_format_from_string (header_format_combo.get_active_text ()) == SF_FORMAT_WAV) {
1046 endian_format_combo.set_active_text (N_("Little-endian (Intel)"));
1047 endian_format_combo.set_sensitive (false);
1049 endian_format_combo.set_sensitive (true);
1050 endian_format_combo.set_active_text (N_("Big-endian (Mac)"));
1055 ExportDialog::bitdepth_chosen ()
1057 int format = sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
1059 case SF_FORMAT_PCM_24:
1060 case SF_FORMAT_PCM_32:
1061 case SF_FORMAT_FLOAT:
1062 dither_type_combo.set_sensitive (false);
1066 dither_type_combo.set_sensitive (true);
1072 ExportDialog::cue_file_type_chosen ()
1074 if (cue_file_combo.get_active_text () != "None") {
1075 cuefile_only_checkbox.set_sensitive (true);
1077 cuefile_only_checkbox.set_active (false);
1078 cuefile_only_checkbox.set_sensitive (false);
1083 ExportDialog::file_chooser_selection_changed ()
1087 if the user selects an existing file from the 'browse for other folders' tab,
1088 change the format settings to match the file.
1090 if (file_chooser.get_filename().length() == 0) {
1093 if (Glib::file_test(file_chooser.get_preview_filename(),Glib::FILE_TEST_IS_DIR)){
1094 file_chooser.set_current_name (_(""));
1097 if (!Glib::file_test(file_chooser.get_preview_filename(),Glib::FILE_TEST_EXISTS)) {
1101 SoundFileInfo finfo;
1102 string error_msg, format_str;
1104 if (!AudioFileSource::get_soundfile_info (file_chooser.get_preview_filename(), finfo, error_msg)) {
1105 error << string_compose(_("Export: cannot open file \"%1\"."), error_msg ) << endmsg;
1109 if (finfo.samplerate == 22050) {
1110 sample_rate_combo.set_active_text (N_("22.05kHz"));
1111 } else if (finfo.samplerate == 44100) {
1112 sample_rate_combo.set_active_text (N_("44.1kHz"));
1113 } else if (finfo.samplerate == 48000) {
1114 sample_rate_combo.set_active_text (N_("48kHz"));
1115 } else if (finfo.samplerate == 88200) {
1116 sample_rate_combo.set_active_text (N_("88.2kHz"));
1117 } else if (finfo.samplerate == 96000) {
1118 sample_rate_combo.set_active_text (N_("96kHz"));
1119 } else if (finfo.samplerate == 192000) {
1120 sample_rate_combo.set_active_text (N_("192kHz"));
1123 if (finfo.channels == 1) {
1124 channel_count_combo.set_active_text(N_("Mono"));
1126 channel_count_combo.set_active_text(N_("Stereo"));
1129 string::size_type pos;
1131 pos = finfo.format_name.find_first_of (" ");
1132 format_str = finfo.format_name.substr(pos + 1, 255);
1133 pos = format_str.find_first_of (" ");
1134 header_format_combo.set_active_text(format_str.substr(0, pos));
1136 format_str = finfo.format_name;
1137 pos = format_str.find_first_of (",");
1138 bitdepth_format_combo.set_active_text(format_str.substr(pos + 2, 255));
1142 ExportDialog::sample_rate_chosen ()
1144 string sr_str = sample_rate_combo.get_active_text();
1147 if (sr_str == N_("22.05kHz")) {
1149 } else if (sr_str == _("44.1kHz")) {
1151 } else if (sr_str == _("48kHz")) {
1153 } else if (sr_str == _("88.2kHz")) {
1155 } else if (sr_str == _("96kHz")) {
1157 } else if (sr_str == _("192kHz")) {
1160 rate = session->frame_rate();
1163 if (rate != session->frame_rate()) {
1164 src_quality_combo.set_sensitive (true);
1166 src_quality_combo.set_sensitive (false);
1171 ExportDialog::channels_chosen ()
1175 mono = (channel_count_combo.get_active_text() == _("Mono"));
1178 track_selector.get_column(2)->set_visible(false);
1179 track_selector.get_column(1)->set_title(_("Export"));
1181 if (session->master_out()) {
1182 master_selector.get_column(2)->set_visible(false);
1183 master_selector.get_column(1)->set_title(_("Export"));
1187 track_selector.get_column(2)->set_visible(true);
1188 track_selector.get_column(1)->set_title(_("Left"));
1190 if (session->master_out()) {
1191 master_selector.get_column(2)->set_visible(true);
1192 master_selector.get_column(1)->set_title(_("Left"));
1200 ExportDialog::fill_lists ()
1202 track_list->clear();
1203 master_list->clear();
1205 boost::shared_ptr<Session::RouteList> routes = session->get_routes ();
1207 for (Session::RouteList::iterator ri = routes->begin(); ri != routes->end(); ++ri) {
1209 boost::shared_ptr<Route> route = (*ri);
1211 if (route->is_hidden()) {
1215 for (uint32_t i=0; i < route->n_outputs().n_audio(); ++i) {
1217 if (route->n_outputs().n_audio() == 1) {
1218 name = route->name();
1220 name = string_compose("%1: out-%2", route->name(), i+1);
1223 if (route == session->master_out()) {
1224 TreeModel::iterator iter = master_list->append();
1225 TreeModel::Row row = *iter;
1226 row[exp_cols.output] = name;
1227 row[exp_cols.left] = false;
1228 row[exp_cols.right] = false;
1229 row[exp_cols.port] = route->output (i);
1231 TreeModel::iterator iter = track_list->append();
1232 TreeModel::Row row = *iter;
1233 row[exp_cols.output] = name;
1234 row[exp_cols.left] = false;
1235 row[exp_cols.right] = false;
1236 row[exp_cols.port] = route->output (i);
1244 ExportDialog::is_filepath_valid(string &filepath)
1246 // sanity check file name first
1248 struct stat statbuf;
1250 if (filepath.empty()) {
1251 string txt = _("Please enter a valid filename.");
1252 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1257 // check if file exists already and warn
1259 if (stat (filepath.c_str(), &statbuf) == 0) {
1260 if (S_ISDIR (statbuf.st_mode)) {
1261 string txt = _("Please specify a complete filename for the audio file.");
1262 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1267 string txt = _("File ") + filepath + _(" already exists, do you want to overwrite it?");
1268 MessageDialog msg (*this, txt, false, MESSAGE_QUESTION, BUTTONS_YES_NO, true);
1269 if ((ResponseType) msg.run() == Gtk::RESPONSE_NO) {
1275 // directory needs to exist and be writable
1277 string dirpath = Glib::path_get_dirname (filepath);
1278 if (::access (dirpath.c_str(), W_OK) != 0) {
1279 string txt = _("Cannot write file in: ") + dirpath;
1280 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
1289 ExportDialog::initSpec(string &filepath)
1291 spec.path = filepath;
1293 spec.running = true;
1295 spec.port_map.clear();
1297 if (channel_count_combo.get_active_text() == _("Mono")) {
1305 spec.format |= sndfile_header_format_from_string (header_format_combo.get_active_text ());
1307 if ((spec.format & SF_FORMAT_WAV) == 0) {
1308 /* RIFF/WAV specifies endianess */
1309 spec.format |= sndfile_endian_format_from_string (endian_format_combo.get_active_text ());
1312 spec.format |= sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
1314 string sr_str = sample_rate_combo.get_active_text();
1315 if (sr_str == N_("22.05kHz")) {
1316 spec.sample_rate = 22050;
1317 } else if (sr_str == _("44.1kHz")) {
1318 spec.sample_rate = 44100;
1319 } else if (sr_str == _("48kHz")) {
1320 spec.sample_rate = 48000;
1321 } else if (sr_str == _("88.2kHz")) {
1322 spec.sample_rate = 88200;
1323 } else if (sr_str == _("96kHz")) {
1324 spec.sample_rate = 96000;
1325 } else if (sr_str == _("192kHz")) {
1326 spec.sample_rate = 192000;
1328 spec.sample_rate = session->frame_rate();
1331 string src_str = src_quality_combo.get_active_text();
1332 if (src_str == _("fastest")) {
1333 spec.src_quality = SRC_ZERO_ORDER_HOLD;
1334 } else if (src_str == _("linear")) {
1335 spec.src_quality = SRC_LINEAR;
1336 } else if (src_str == _("better")) {
1337 spec.src_quality = SRC_SINC_FASTEST;
1338 } else if (src_str == _("intermediate")) {
1339 spec.src_quality = SRC_SINC_MEDIUM_QUALITY;
1341 spec.src_quality = SRC_SINC_BEST_QUALITY;
1344 string dither_str = dither_type_combo.get_active_text();
1345 if (dither_str == _("None")) {
1346 spec.dither_type = GDitherNone;
1347 } else if (dither_str == _("Rectangular")) {
1348 spec.dither_type = GDitherRect;
1349 } else if (dither_str == _("Triangular")) {
1350 spec.dither_type = GDitherTri;
1352 spec.dither_type = GDitherShaped;
1355 write_track_and_master_selection_to_spec();
1360 ExportDialog::write_track_and_master_selection_to_spec()
1362 if(!track_and_master_selection_allowed){
1367 Port *last_port = 0;
1369 TreeModel::Children rows = master_selector.get_model()->children();
1370 TreeModel::Children::iterator ri;
1372 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1374 Port* port = row[exp_cols.port];
1376 if (last_port != port) {
1380 if (row[exp_cols.left]) {
1381 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1384 if (spec.channels == 2) {
1385 if (row[exp_cols.right]) {
1386 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1392 rows = track_selector.get_model()->children();
1394 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1397 Port* port = row[exp_cols.port];
1399 if (last_port != port) {
1403 if (row[exp_cols.left]) {
1404 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1407 if (spec.channels == 2) {
1408 if (row[exp_cols.right]) {
1409 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1421 ExportDialog::window_closed (GdkEventAny *ignored)
1428 ExportDialog::track_selector_button_click ()
1430 if (track_scroll.is_visible ()) {
1431 track_scroll.hide ();
1433 track_scroll.show_all ();