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>
27 #include <pbd/pthread_utils.h>
28 #include <pbd/xml++.h>
29 #include <pbd/dirname.h>
31 #include <gtkmm2ext/utils.h>
32 #include <ardour/export.h>
33 #include <ardour/sndfile_helpers.h>
34 #include <ardour/audio_track.h>
35 #include <ardour/audioregion.h>
36 #include <ardour/audioengine.h>
37 #include <ardour/gdither.h>
38 #include <ardour/utils.h>
40 #include "export_dialog.h"
41 #include "ardour_ui.h"
42 #include "public_editor.h"
44 #include "ardour_message.h"
48 #define FRAME_NAME "BaseFrame"
52 using namespace ARDOUR;
56 static const gchar *sample_rates[] = {
66 static const gchar *src_quality[] = {
75 static const gchar *dither_types[] = {
83 static const gchar* channel_strings[] = {
89 static const gchar* cue_file_types[] = {
96 ExportDialog::ExportDialog(PublicEditor& e, AudioRegion* r)
97 : ArdourDialog ("export dialog"),
100 format_frame (_("FORMAT")),
101 channel_count_label (_("CHANNELS")),
102 channel_count_align(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, 0.0, 0.0),
103 header_format_label (_("FILE TYPE")),
104 header_format_align(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, 0.0, 0.0),
105 bitdepth_format_label (_("SAMPLE FORMAT")),
106 bitdepth_format_align(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, 0.0, 0.0),
107 endian_format_label (_("SAMPLE ENDIANNESS")),
108 endian_format_align(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, 0.0, 0.0),
109 sample_rate_label (_("SAMPLE RATE")),
110 sample_rate_align(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, 0.0, 0.0),
111 src_quality_label (_("CONVERSION QUALITY")),
112 src_quality_align(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, 0.0, 0.0),
113 dither_type_label (_("DITHER TYPE")),
114 dither_type_align(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, 0.0, 0.0),
115 cue_file_label (_("CD MARKER FILE TYPE")),
116 cue_file_align(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, 0.0, 0.0),
117 cuefile_only_checkbox (_("EXPORT CD MARKER FILE ONLY")),
118 file_frame (_("EXPORT TO FILE")),
119 file_browse_button (_("Browse")),
120 ok_button (_("Export")),
121 track_selector_button (_("Specific tracks ..."))
131 set_title (_("ardour: export"));
132 set_wmclass (_("ardour_export"), "Ardour");
133 set_name ("ExportWindow");
134 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
137 spec.running = false;
139 file_entry.set_name ("ExportFileNameEntry");
141 master_list = ListStore::create (exp_cols);
142 master_selector.set_model (master_list);
144 master_selector.set_name ("ExportTrackSelector");
145 master_selector.set_size_request (-1, 100);
146 master_selector.append_column(_("Output"), exp_cols.output);
147 master_selector.append_column_editable(_("Left"), exp_cols.left);
148 master_selector.append_column_editable(_("Right"), exp_cols.right);
149 master_selector.get_column(0)->set_min_width(100);
151 master_selector.get_column(1)->set_min_width(40);
152 master_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
153 master_selector.get_column(2)->set_min_width(40);
154 master_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
155 master_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
157 track_list = ListStore::create (exp_cols);
158 track_selector.set_model (track_list);
160 track_selector.set_name ("ExportTrackSelector");
161 track_selector.set_size_request (-1, 130);
162 track_selector.append_column(_("Output"), exp_cols.output);
163 track_selector.append_column_editable(_("Left"), exp_cols.left);
164 track_selector.append_column_editable(_("Right"), exp_cols.right);
166 track_selector.get_column(0)->set_min_width(100);
167 track_selector.get_column(1)->set_min_width(40);
168 track_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
169 track_selector.get_column(2)->set_min_width(40);
170 track_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
171 track_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
173 progress_bar.set_name ("ExportProgress");
175 format_frame.add (format_table);
176 format_frame.set_name (FRAME_NAME);
178 track_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
179 master_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
181 get_vbox()->pack_start (file_frame, false, false);
183 hpacker.set_spacing (5);
184 hpacker.set_border_width (5);
185 hpacker.pack_start (format_frame, false, false);
189 master_scroll.add (master_selector);
190 track_scroll.add (track_selector);
192 master_scroll.set_size_request (220, 100);
193 track_scroll.set_size_request (220, 100);
197 /* we may hide some of these later */
198 track_vpacker.pack_start (master_scroll);
199 track_vpacker.pack_start (track_scroll);
200 track_vpacker.pack_start (track_selector_button, Gtk::PACK_EXPAND_PADDING);
202 hpacker.pack_start (track_vpacker);
205 get_vbox()->pack_start (hpacker);
207 track_selector_button.set_name ("EditorGTKButton");
208 track_selector_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::track_selector_button_click));
210 get_vbox()->pack_start (button_box, false, false);
211 get_vbox()->pack_start (progress_bar, false, false);
213 Gtkmm2ext::set_size_request_to_display_given_text (file_entry, X_("Kg/quite/a/reasonable/size/for/files/i/think"), 5, 8);
215 file_hbox.set_spacing (5);
216 file_hbox.set_border_width (5);
217 file_hbox.pack_start (file_entry, true, true);
218 file_hbox.pack_start (file_browse_button, false, false);
220 file_frame.add (file_hbox);
221 file_frame.set_border_width (5);
222 file_frame.set_name (FRAME_NAME);
224 /* pop_strings needs to be created on the stack because set_popdown_strings()
225 * takes a reference. */
226 vector<string> pop_strings = internationalize(sample_rates);
227 Gtkmm2ext::set_popdown_strings (sample_rate_combo, pop_strings);
228 pop_strings = internationalize(sample_rates);
229 Gtkmm2ext::set_popdown_strings (src_quality_combo, pop_strings);
230 pop_strings = internationalize(dither_types);
231 Gtkmm2ext::set_popdown_strings (dither_type_combo, pop_strings);
232 pop_strings = internationalize(channel_strings);
233 Gtkmm2ext::set_popdown_strings (channel_count_combo, pop_strings);
234 pop_strings = internationalize((const char **) sndfile_header_formats_strings);
235 Gtkmm2ext::set_popdown_strings (header_format_combo, pop_strings);
236 pop_strings = internationalize((const char **) sndfile_bitdepth_formats_strings);
237 Gtkmm2ext::set_popdown_strings (bitdepth_format_combo, pop_strings);
238 pop_strings = internationalize((const char **) sndfile_endian_formats_strings);
239 Gtkmm2ext::set_popdown_strings (endian_format_combo, pop_strings);
240 pop_strings = internationalize(cue_file_types);
241 Gtkmm2ext::set_popdown_strings (cue_file_combo, pop_strings);
243 /* this will re-sensitized as soon as a non RIFF/WAV
244 header format is chosen.
247 endian_format_combo.set_sensitive (false);
249 /* determine longest strings at runtime */
251 const guint32 FUDGE = 10; // Combo's are stupid - they steal space from the entry for the button
254 const char *longest = "gl";
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);
325 channel_count_align.add(channel_count_label);
326 format_table.attach (channel_count_align, 0, 1, 0, 1);
327 format_table.attach (channel_count_combo, 1, 2, 0, 1);
330 header_format_align.add(header_format_label);
331 format_table.attach (header_format_align, 0, 1, 1, 2);
332 format_table.attach (header_format_combo, 1, 2, 1, 2);
334 bitdepth_format_align.add(bitdepth_format_label);
335 format_table.attach (bitdepth_format_align, 0, 1, 2, 3);
336 format_table.attach (bitdepth_format_combo, 1, 2, 2, 3);
338 endian_format_align.add(endian_format_label);
339 format_table.attach (endian_format_align, 0, 1, 3, 4);
340 format_table.attach (endian_format_combo, 1, 2, 3, 4);
342 sample_rate_align.add(sample_rate_label);
343 format_table.attach (sample_rate_align, 0, 1, 4, 5);
344 format_table.attach (sample_rate_combo, 1, 2, 4, 5);
346 src_quality_align.add(src_quality_label);
347 format_table.attach (src_quality_align, 0, 1, 5, 6);
348 format_table.attach (src_quality_combo, 1, 2, 5, 6);
350 dither_type_align.add(dither_type_label);
351 format_table.attach (dither_type_align, 0, 1, 6, 7);
352 format_table.attach (dither_type_combo, 1, 2, 6, 7);
354 cue_file_align.add(cue_file_label);
355 format_table.attach (cue_file_align, 0, 1, 7, 8);
356 format_table.attach (cue_file_combo, 1, 2, 7, 8);
357 format_table.attach (cuefile_only_checkbox, 0, 2, 8, 9);
360 button_box.set_border_width (6);
361 button_box.set_spacing (20);
362 button_box.set_homogeneous (true);
364 cancel_button.add (cancel_label);
366 button_box.pack_start (ok_button, false, true);
367 button_box.pack_start (cancel_button, false, true);
369 ok_button.set_name ("EditorGTKButton");
370 cancel_button.set_name ("EditorGTKButton");
371 file_entry.set_name ("ExportFileDisplay");
373 signal_delete_event().connect (mem_fun(*this, &ExportDialog::window_closed));
374 ok_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::do_export));
375 cancel_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::end_dialog));
377 file_browse_button.set_name ("EditorGTKButton");
378 file_browse_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::initiate_browse));
380 channel_count_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::channels_chosen));
381 bitdepth_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::bitdepth_chosen));
382 header_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::header_chosen));
383 sample_rate_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::sample_rate_chosen));
384 cue_file_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::cue_file_type_chosen));
387 ExportDialog::~ExportDialog()
390 delete file_selector;
395 ExportDialog::connect_to_session (Session *s)
398 session->going_away.connect (mem_fun(*this, &Window::hide_all));
400 switch (session->frame_rate()) {
402 sample_rate_combo.set_active_text (N_("22.05kHz"));
405 sample_rate_combo.set_active_text (N_("44.1kHz"));
408 sample_rate_combo.set_active_text (N_("48kHz"));
411 sample_rate_combo.set_active_text (N_("88.2kHz"));
414 sample_rate_combo.set_active_text (N_("96kHz"));
417 sample_rate_combo.set_active_text (N_("192kHz"));
420 sample_rate_combo.set_active_text (N_("44.1kHz"));
424 src_quality_combo.set_sensitive (false);
430 ExportDialog::set_state()
432 XMLNode* node = session->instant_xml(X_("ExportDialog"), session->path());
437 if ((prop = node->property (X_("sample_rate"))) != 0) {
438 sample_rate_combo.set_active_text(prop->value());
440 if ((prop = node->property (X_("src_quality"))) != 0) {
441 src_quality_combo.set_active_text(prop->value());
443 if ((prop = node->property (X_("dither_type"))) != 0) {
444 dither_type_combo.set_active_text(prop->value());
446 if ((prop = node->property (X_("channel_count"))) != 0) {
447 channel_count_combo.set_active_text(prop->value());
449 if ((prop = node->property (X_("header_format"))) != 0) {
450 header_format_combo.set_active_text(prop->value());
452 if ((prop = node->property (X_("bitdepth_format"))) != 0) {
453 bitdepth_format_combo.set_active_text(prop->value());
455 if ((prop = node->property (X_("endian_format"))) != 0) {
456 endian_format_combo.set_active_text(prop->value());
458 if ((prop = node->property (X_("filename"))) != 0) {
459 file_entry.set_text(prop->value());
461 if ((prop = node->property (X_("cue_file_type"))) != 0) {
462 cue_file_combo.set_active_text(prop->value());
469 sample_rate_chosen();
471 if (session->master_out()) {
472 track_scroll.hide ();
474 master_scroll.hide ();
475 track_selector_button.hide ();
482 if (session->master_out()) {
483 XMLNode* master = find_named_node(*node, (X_("Master")));
488 /* default is to use all */
489 if (channel_count_combo.get_active_text() == _("mono")) {
495 TreeModel::Children rows = master_selector.get_model()->children();
496 for (uint32_t r = 0; r < session->master_out()->n_outputs(); ++r) {
499 rows[r][exp_cols.right] = true;
501 rows[r][exp_cols.left] = true;
504 rows[r][exp_cols.left] = true;
509 /* XXX use XML state */
513 XMLNode* tracks = find_named_node(*node, (X_("Tracks")));
518 XMLNodeList track_list = tracks->children(X_("Track"));
519 TreeModel::Children rows = track_selector.get_model()->children();
520 TreeModel::Children::iterator ri = rows.begin();
523 for (XMLNodeIterator it = track_list.begin(); it != track_list.end(); ++it, ++ri) {
524 if (ri == rows.end()){
528 XMLNode* track = *it;
531 if ((prop = track->property(X_("channel1"))) != 0) {
532 if (prop->value() == X_("on")) {
533 row[exp_cols.left] = true;
535 row[exp_cols.left] = false;
539 if ((prop = track->property(X_("channel2"))) != 0) {
540 if (prop->value() == X_("on")) {
541 row[exp_cols.right] = true;
543 row[exp_cols.right] = false;
550 ExportDialog::save_state()
556 XMLNode* node = new XMLNode(X_("ExportDialog"));
558 node->add_property(X_("sample_rate"), sample_rate_combo.get_active_text());
559 node->add_property(X_("src_quality"), src_quality_combo.get_active_text());
560 node->add_property(X_("dither_type"), dither_type_combo.get_active_text());
561 node->add_property(X_("channel_count"), channel_count_combo.get_active_text());
562 node->add_property(X_("header_format"), header_format_combo.get_active_text());
563 node->add_property(X_("bitdepth_format"), bitdepth_format_combo.get_active_text());
564 node->add_property(X_("endian_format"), endian_format_combo.get_active_text());
565 node->add_property(X_("filename"), file_entry.get_text());
566 node->add_property(X_("cue_file_type"), cue_file_combo.get_active_text());
568 XMLNode* tracks = new XMLNode(X_("Tracks"));
570 TreeModel::Children rows = track_selector.get_model()->children();
572 for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
573 XMLNode* track = new XMLNode(X_("Track"));
576 track->add_property(X_("channel1"), row[exp_cols.left] ? X_("on") : X_("off"));
577 track->add_property(X_("channel1"), row[exp_cols.right] ? X_("on") : X_("off"));
579 tracks->add_child_nocopy(*track);
581 node->add_child_nocopy(*tracks);
583 session->add_instant_xml(*node, session->path());
587 ExportDialog::set_range (jack_nframes_t start, jack_nframes_t end)
589 spec.start_frame = start;
590 spec.end_frame = end;
593 // XXX: this is a hack until we figure out what is really wrong
594 session->request_locate (spec.start_frame, false);
599 ExportDialog::progress_timeout ()
601 progress_bar.set_fraction (spec.progress/100);
606 ExportDialog::_export_region_thread (void *arg)
608 PBD::ThreadCreated (pthread_self(), X_("Export Region"));
610 static_cast<ExportDialog*>(arg)->export_region ();
615 ExportDialog::export_region ()
617 audio_region->exportme (*session, spec);
621 frames_to_cd_frames_string (char* buf, jack_nframes_t when, jack_nframes_t fr)
624 long unsigned int remainder;
625 int mins, secs, frames;
627 mins = when / (60 * fr);
628 remainder = when - (mins * 60 * fr);
629 secs = remainder / fr;
630 remainder -= secs * fr;
631 frames = remainder / (fr / 75);
632 sprintf (buf, " %02d:%02d:%02d", mins, secs, frames);
636 struct LocationSortByStart {
637 bool operator() (Location *a, Location *b) {
638 return a->start() < b->start();
643 ExportDialog::export_toc_file (Locations::LocationList& locations, const string& path)
646 string filepath = path + ".toc";
647 ofstream out (filepath.c_str());
648 long unsigned int last_end_time = spec.start_frame, last_start_time = spec.start_frame;
653 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD toc file"), filepath) << endmsg;
656 out << "CD_DA" << endl;
657 out << "CD_TEXT {" << endl << " LANGUAGE_MAP {" << endl << " 0 : EN" << endl << " }" << endl;
658 out << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl << " }" << endl << "}" << endl;
660 Locations::LocationList::iterator i;
661 Locations::LocationList temp;
663 for (i = locations.begin(); i != locations.end(); ++i) {
664 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
666 if (!(*i)->is_mark()) {
672 if (numtracks == 0 ) {
673 /* the user supplied no track markers.
674 we now treat the session as one track.*/
676 out << endl << "TRACK AUDIO" << endl;
678 out << "COPY" << endl;
680 out << "NO PRE_EMPHASIS" << endl;
682 /* XXX add session properties for catalog etc.
683 (so far only the session name is used) */
685 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl;
686 out << " }" << endl << "}" << endl;
688 out << "FILE \"" << path << "\" ";
690 frames_to_cd_frames_string (buf, spec.end_frame - spec.start_frame, session->frame_rate());
692 out << "START 00:00:00" << endl;
694 last_start_time = spec.start_frame;
695 last_end_time = spec.end_frame;
699 LocationSortByStart cmp;
702 for (i = temp.begin(); i != temp.end(); ++i) {
704 if (!(*i)->is_mark()) {
706 out << endl << "TRACK AUDIO" << endl;
708 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
711 out << "COPY" << endl;
713 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
714 out << "PRE_EMPHASIS" << endl;
716 out << "NO PRE_EMPHASIS" << endl;
719 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
720 out << "ISRC \"" << (*i)->cd_info["isrc"] << "\"" << endl;
723 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << (*i)->name() << "\"" << endl;
724 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
725 out << " PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
727 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
728 out << " COMPOSER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
731 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
733 out << (*i)->cd_info["isrc"].substr(0,2) << "-";
734 out << (*i)->cd_info["isrc"].substr(2,3) << "-";
735 out << (*i)->cd_info["isrc"].substr(5,2) << "-";
736 out << (*i)->cd_info["isrc"].substr(7,5) << "\"" << endl;
739 out << " }" << endl << "}" << endl;
741 frames_to_cd_frames_string (buf, last_end_time - spec.start_frame, session->frame_rate());
742 out << "FILE \"" << path << "\" " << buf;
744 frames_to_cd_frames_string (buf, (*i)->end() - last_end_time, session->frame_rate());
747 frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
748 out << "START" << buf << endl;
750 last_start_time = (*i)->start();
751 last_end_time = (*i)->end();
754 } else if ((*i)->start() < last_end_time) {
755 /* this is an index within a track */
757 frames_to_cd_frames_string (buf, (*i)->start() - last_start_time, session->frame_rate());
758 out << "INDEX" << buf << endl;
766 ExportDialog::export_cue_file (Locations::LocationList& locations, const string& path)
768 string filepath = path + ".cue";
769 ofstream out (filepath.c_str());
771 long unsigned int last_track_end = spec.start_frame;
772 int numtracks = 0, tracknum = 0, indexnum = 0;
775 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD cue file"), filepath) << endmsg;
779 Locations::LocationList::iterator i;
780 Locations::LocationList temp;
782 for (i = locations.begin(); i != locations.end(); ++i) {
783 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
785 if (!(*i)->is_mark()) {
791 out << "REM Cue file generated by Ardour" << endl;
792 out << "TITLE \"" << session->name() << "\"" << endl;
794 if ((header_format_combo.get_active_text() == N_("WAV"))) {
795 out << "FILE " << path << " WAVE" << endl;
797 out << "FILE " << path << ' ' << (header_format_combo.get_active_text()) << endl;
800 if (numtracks == 0) {
801 /* the user has supplied no track markers.
802 the entire export is treated as one track.
808 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
811 out << "DCP " << endl;
813 /* use the session name*/
815 if (session->name() != "") {
816 out << "TITLE \"" << session->name() << "\"" << endl;
819 /* no pregap in this case */
821 out << "INDEX 00 00:00:00" << endl;
823 out << "INDEX 01 00:00:00" << endl;
825 last_track_end = spec.end_frame;
829 LocationSortByStart cmp;
832 for ( i = temp.begin(); i != temp.end(); ++i) {
834 if (!(*i)->is_mark() && ((*i)->start() >= last_track_end)) {
835 /* this is a track and it doesn't start inside another one*/
839 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
842 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
848 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
853 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
854 out << "ISRC " << (*i)->cd_info["isrc"] << endl;
857 if ((*i)->name() != "") {
858 out << "TITLE \"" << (*i)->name() << "\"" << endl;
861 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
862 out << "PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
865 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
866 out << "SONGWRITER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
868 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
870 frames_to_cd_frames_string (buf, last_track_end - spec.start_frame, session->frame_rate());
873 last_track_end = (*i)->end();
875 if ((tracknum > 0) && ((*i)->start() < last_track_end)) {
876 /*this is an index and it lies within a track*/
877 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
879 frames_to_cd_frames_string (buf,(*i)->start() - spec.start_frame, session->frame_rate());
889 ExportDialog::do_export_cd_markers (const string& path,const string& cuefile_type)
891 if (cuefile_type == "TOC") {
892 session->locations()->apply (*this, &ExportDialog::export_toc_file, path);
894 session->locations()->apply (*this, &ExportDialog::export_cue_file, path);
900 ExportDialog::do_export ()
902 // sanity check file name first
903 string filepath = file_entry.get_text();
906 if (filepath.empty()) {
908 string txt = _("Please enter a valid filename.");
909 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
914 // check if file exists already and warn
915 if (stat (filepath.c_str(), &statbuf) == 0) {
916 if (S_ISDIR (statbuf.st_mode)) {
917 string txt = _("Please specify a complete filename for the audio file.");
918 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
923 string txt = _("File already exists, do you want to overwrite it?");
924 MessageDialog msg (*this, txt, false, MESSAGE_QUESTION, BUTTONS_YES_NO, true);
925 //ArdourMessage msg (this, X_("exportoverwrite"), txt, true, false, Gtk::BUTTONS_YES_NO);
926 if ((ResponseType) msg.run() == Gtk::RESPONSE_NO) {
932 // directory needs to exist and be writable
933 string dirpath = PBD::dirname (filepath);
934 if (::access (dirpath.c_str(), W_OK) != 0) {
935 string txt = _("Cannot write file in: ") + dirpath;
936 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
941 if (cue_file_combo.get_active_text () != _("None")) {
942 do_export_cd_markers (file_entry.get_text(), cue_file_combo.get_active_text ());
945 if (cuefile_only_checkbox.get_active()) {
950 ok_button.set_sensitive(false);
955 spec.path = filepath;
959 spec.port_map.clear();
961 if (channel_count_combo.get_active_text() == _("mono")) {
969 spec.format |= sndfile_header_format_from_string (header_format_combo.get_active_text ());
971 if ((spec.format & SF_FORMAT_WAV) == 0) {
972 /* RIFF/WAV specifies endianess */
973 spec.format |= sndfile_endian_format_from_string (endian_format_combo.get_active_text ());
976 spec.format |= sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
978 string sr_str = sample_rate_combo.get_active_text();
979 if (sr_str == N_("22.05kHz")) {
980 spec.sample_rate = 22050;
981 } else if (sr_str == N_("44.1kHz")) {
982 spec.sample_rate = 44100;
983 } else if (sr_str == N_("48kHz")) {
984 spec.sample_rate = 48000;
985 } else if (sr_str == N_("88.2kHz")) {
986 spec.sample_rate = 88200;
987 } else if (sr_str == N_("96kHz")) {
988 spec.sample_rate = 96000;
989 } else if (sr_str == N_("192kHz")) {
990 spec.sample_rate = 192000;
992 spec.sample_rate = session->frame_rate();
995 string src_str = src_quality_combo.get_active_text();
996 if (src_str == _("fastest")) {
997 spec.src_quality = SRC_ZERO_ORDER_HOLD;
998 } else if (src_str == _("linear")) {
999 spec.src_quality = SRC_LINEAR;
1000 } else if (src_str == _("better")) {
1001 spec.src_quality = SRC_SINC_FASTEST;
1002 } else if (src_str == _("intermediate")) {
1003 spec.src_quality = SRC_SINC_MEDIUM_QUALITY;
1005 spec.src_quality = SRC_SINC_BEST_QUALITY;
1008 string dither_str = dither_type_combo.get_active_text();
1009 if (dither_str == _("None")) {
1010 spec.dither_type = GDitherNone;
1011 } else if (dither_str == _("Rectangular")) {
1012 spec.dither_type = GDitherRect;
1013 } else if (dither_str == _("Triangular")) {
1014 spec.dither_type = GDitherTri;
1016 spec.dither_type = GDitherShaped;
1019 if (!audio_region) {
1022 Port *last_port = 0;
1024 TreeModel::Children rows = master_selector.get_model()->children();
1025 TreeModel::Children::iterator ri;
1027 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1029 Port* port = row[exp_cols.port];
1031 if (last_port != port) {
1035 if (row[exp_cols.left]) {
1036 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1039 if (spec.channels == 2) {
1040 if (row[exp_cols.right]) {
1041 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1048 rows = track_selector.get_model()->children();
1049 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1052 Port* port = row[exp_cols.port];
1054 if (last_port != port) {
1058 if (row[exp_cols.left]) {
1059 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1062 if (spec.channels == 2) {
1063 if (row[exp_cols.right]) {
1064 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1074 progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
1075 cancel_label.set_text (_("Stop Export"));
1077 if (!audio_region) {
1078 if (session->start_audio_export (spec)) {
1083 pthread_create_and_store ("region export", &thr, 0, ExportDialog::_export_region_thread, this);
1086 gtk_main_iteration ();
1087 while (spec.running) {
1088 if (gtk_events_pending()) {
1089 gtk_main_iteration ();
1096 progress_connection.disconnect ();
1102 ExportDialog::end_dialog ()
1108 while (spec.running) {
1109 if (gtk_events_pending()) {
1110 gtk_main_iteration ();
1117 session->engine().freewheel (false);
1121 if (file_selector) {
1122 file_selector->hide_all ();
1126 ok_button.set_sensitive(true);
1130 ExportDialog::start_export ()
1136 /* If it the filename hasn't been set before, use the
1137 directory above the current session as a default
1138 location for the export.
1141 if (file_entry.get_text().length() == 0) {
1142 string dir = session->path();
1143 string::size_type last_slash;
1145 if ((last_slash = dir.find_last_of ('/')) != string::npos) {
1146 dir = dir.substr (0, last_slash+1);
1149 dir = dir + "export.wav";
1151 file_entry.set_text (dir);
1154 progress_bar.set_fraction (0);
1155 cancel_label.set_text (_("Cancel"));
1159 if (session->master_out()) {
1160 track_scroll.hide ();
1162 master_scroll.hide ();
1163 track_selector_button.hide ();
1168 ExportDialog::header_chosen ()
1170 if (sndfile_header_format_from_string (header_format_combo.get_active_text ()) == SF_FORMAT_WAV) {
1171 endian_format_combo.set_sensitive (false);
1173 endian_format_combo.set_sensitive (true);
1178 ExportDialog::bitdepth_chosen ()
1180 int format = sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
1182 case SF_FORMAT_PCM_24:
1183 case SF_FORMAT_PCM_32:
1184 case SF_FORMAT_FLOAT:
1185 dither_type_combo.set_sensitive (false);
1189 dither_type_combo.set_sensitive (true);
1195 ExportDialog::cue_file_type_chosen ()
1197 if (cue_file_combo.get_active_text () != "None") {
1198 cuefile_only_checkbox.set_sensitive (true);
1200 cuefile_only_checkbox.set_active (false);
1201 cuefile_only_checkbox.set_sensitive (false);
1206 ExportDialog::sample_rate_chosen ()
1208 string sr_str = sample_rate_combo.get_active_text();
1209 jack_nframes_t rate;
1211 if (sr_str == N_("22.05kHz")) {
1213 } else if (sr_str == N_("44.1kHz")) {
1215 } else if (sr_str == N_("48kHz")) {
1217 } else if (sr_str == N_("88.2kHz")) {
1219 } else if (sr_str == N_("96kHz")) {
1221 } else if (sr_str == N_("192kHz")) {
1224 rate = session->frame_rate();
1227 if (rate != session->frame_rate()) {
1228 src_quality_combo.set_sensitive (true);
1230 src_quality_combo.set_sensitive (false);
1235 ExportDialog::channels_chosen ()
1239 mono = (channel_count_combo.get_active_text() == _("mono"));
1242 track_selector.get_column(2)->set_visible(false);
1243 track_selector.get_column(1)->set_title(_("Export"));
1245 if (session->master_out()) {
1246 master_selector.get_column(2)->set_visible(false);
1247 master_selector.get_column(1)->set_title(_("Export"));
1251 track_selector.get_column(2)->set_visible(true);
1252 track_selector.get_column(1)->set_title(_("Left"));
1254 if (session->master_out()) {
1255 master_selector.get_column(2)->set_visible(true);
1256 master_selector.get_column(1)->set_title(_("Left"));
1264 ExportDialog::fill_lists ()
1266 track_list->clear();
1267 master_list->clear();
1269 Session::RouteList routes = session->get_routes ();
1271 for (Session::RouteList::iterator ri = routes.begin(); ri != routes.end(); ++ri) {
1273 Route* route = (*ri);
1275 if (route->hidden()) {
1279 for (uint32_t i=0; i < route->n_outputs(); ++i) {
1281 if (route->n_outputs() == 1) {
1282 name = route->name();
1284 name = string_compose("%1: out-%2", route->name(), i+1);
1287 if (route == session->master_out()) {
1288 TreeModel::iterator iter = master_list->append();
1289 TreeModel::Row row = *iter;
1290 row[exp_cols.output] = name;
1291 row[exp_cols.left] = false;
1292 row[exp_cols.right] = false;
1293 row[exp_cols.port] = route->output (i);
1295 TreeModel::iterator iter = track_list->append();
1296 TreeModel::Row row = *iter;
1297 row[exp_cols.output] = name;
1298 row[exp_cols.left] = false;
1299 row[exp_cols.right] = false;
1300 row[exp_cols.port] = route->output (i);
1307 ExportDialog::window_closed (GdkEventAny *ignored)
1313 ExportDialog::initiate_browse ()
1315 if (file_selector == 0) {
1316 file_selector = new FileSelection;
1317 file_selector->set_modal (true);
1319 file_selector->get_cancel_button()->signal_clicked().connect (bind (mem_fun(*this, &ExportDialog::finish_browse), -1));
1320 file_selector->get_ok_button()->signal_clicked().connect (bind (mem_fun(*this, &ExportDialog::finish_browse), 1));
1322 file_selector->set_filename (file_entry.get_text());
1323 file_selector->show_all ();
1327 ExportDialog::finish_browse (int status)
1329 if (file_selector) {
1331 string result = file_selector->get_filename();
1333 if (result.length()) {
1334 file_entry.set_text (result);
1337 file_selector->hide_all();
1342 ExportDialog::track_selector_button_click ()
1344 if (track_scroll.is_visible ()) {
1345 track_scroll.hide ();
1347 track_scroll.show_all ();