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.
28 #include <samplerate.h>
29 #include <pbd/pthread_utils.h>
30 #include <pbd/xml++.h>
31 #include <pbd/dirname.h>
33 #include <gtkmm2ext/utils.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"
46 #include "ardour_message.h"
50 #define FRAME_NAME "BaseFrame"
54 using namespace ARDOUR;
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, AudioRegion* r)
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_frame (_("EXPORT TO FILE")),
113 file_browse_button (_("Browse")),
114 track_selector_button (_("Specific tracks ..."))
124 set_title (_("ardour: export"));
125 set_wmclass (_("ardour_export"), "Ardour");
126 set_name ("ExportWindow");
127 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
130 spec.running = false;
132 file_entry.set_name ("ExportFileNameEntry");
134 master_list = ListStore::create (exp_cols);
135 master_selector.set_model (master_list);
137 master_selector.set_name ("ExportTrackSelector");
138 master_selector.set_size_request (-1, 100);
139 master_selector.append_column(_("Output"), exp_cols.output);
140 master_selector.append_column_editable(_("Left"), exp_cols.left);
141 master_selector.append_column_editable(_("Right"), exp_cols.right);
142 master_selector.get_column(0)->set_min_width(100);
144 master_selector.get_column(1)->set_min_width(40);
145 master_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
146 master_selector.get_column(2)->set_min_width(40);
147 master_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
148 master_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
150 track_list = ListStore::create (exp_cols);
151 track_selector.set_model (track_list);
153 track_selector.set_name ("ExportTrackSelector");
154 track_selector.set_size_request (-1, 130);
155 track_selector.append_column(_("Output"), exp_cols.output);
156 track_selector.append_column_editable(_("Left"), exp_cols.left);
157 track_selector.append_column_editable(_("Right"), exp_cols.right);
159 track_selector.get_column(0)->set_min_width(100);
160 track_selector.get_column(1)->set_min_width(40);
161 track_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
162 track_selector.get_column(2)->set_min_width(40);
163 track_selector.get_column(2)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
164 track_selector.get_selection()->set_mode (Gtk::SELECTION_NONE);
166 progress_bar.set_name ("ExportProgress");
168 format_frame.add (format_table);
169 format_frame.set_name (FRAME_NAME);
171 track_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
172 master_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
174 get_vbox()->pack_start (file_frame, false, false);
176 hpacker.set_spacing (5);
177 hpacker.set_border_width (5);
178 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);
190 /* we may hide some of these later */
191 track_vpacker.pack_start (master_scroll);
192 track_vpacker.pack_start (track_scroll);
193 track_vpacker.pack_start (track_selector_button, Gtk::PACK_EXPAND_PADDING);
195 hpacker.pack_start (track_vpacker);
198 get_vbox()->pack_start (hpacker);
200 track_selector_button.set_name ("EditorGTKButton");
201 track_selector_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::track_selector_button_click));
203 get_vbox()->pack_start (progress_bar, false, false);
205 Gtkmm2ext::set_size_request_to_display_given_text (file_entry, X_("Kg/quite/a/reasonable/size/for/files/i/think"), 5, 8);
207 file_hbox.set_spacing (5);
208 file_hbox.set_border_width (5);
209 file_hbox.pack_start (file_entry, true, true);
210 file_hbox.pack_start (file_browse_button, false, false);
212 file_frame.add (file_hbox);
213 file_frame.set_border_width (5);
214 file_frame.set_name (FRAME_NAME);
216 /* pop_strings needs to be created on the stack because set_popdown_strings()
220 vector<string> pop_strings = internationalize(sample_rates);
221 Gtkmm2ext::set_popdown_strings (sample_rate_combo, pop_strings);
222 sample_rate_combo.set_active_text (pop_strings.front());
223 pop_strings = internationalize(src_quality);
224 Gtkmm2ext::set_popdown_strings (src_quality_combo, pop_strings);
225 src_quality_combo.set_active_text (pop_strings.front());
226 pop_strings = internationalize(dither_types);
227 Gtkmm2ext::set_popdown_strings (dither_type_combo, pop_strings);
228 dither_type_combo.set_active_text (pop_strings.front());
229 pop_strings = internationalize(channel_strings);
230 Gtkmm2ext::set_popdown_strings (channel_count_combo, pop_strings);
231 channel_count_combo.set_active_text (pop_strings.front());
232 pop_strings = internationalize((const char **) sndfile_header_formats_strings);
233 Gtkmm2ext::set_popdown_strings (header_format_combo, pop_strings);
234 header_format_combo.set_active_text (pop_strings.front());
235 pop_strings = internationalize((const char **) sndfile_bitdepth_formats_strings);
236 Gtkmm2ext::set_popdown_strings (bitdepth_format_combo, pop_strings);
237 bitdepth_format_combo.set_active_text (pop_strings.front());
238 pop_strings = internationalize((const char **) sndfile_endian_formats_strings);
239 Gtkmm2ext::set_popdown_strings (endian_format_combo, pop_strings);
240 endian_format_combo.set_active_text (pop_strings.front());
241 pop_strings = internationalize(cue_file_types);
242 Gtkmm2ext::set_popdown_strings (cue_file_combo, pop_strings);
243 cue_file_combo.set_active_text (pop_strings.front());
245 /* this will re-sensitized as soon as a non RIFF/WAV
246 header format is chosen.
249 endian_format_combo.set_sensitive (false);
251 /* determine longest strings at runtime */
253 const guint32 FUDGE = 10; // Combo's are stupid - they steal space from the entry for the button
256 const char *longest = "gl";
259 for (n = 0; n < SNDFILE_HEADER_FORMATS; ++n) {
260 if ((len = strlen (sndfile_header_formats_strings[n])) > maxlen) {
262 longest = sndfile_header_formats_strings[n];
266 for (n = 0; n < SNDFILE_BITDEPTH_FORMATS; ++n) {
267 if ((len = strlen (sndfile_bitdepth_formats_strings[n])) > maxlen) {
269 longest = sndfile_bitdepth_formats_strings[n];
273 for (n = 0; n < SNDFILE_ENDIAN_FORMATS; ++n) {
274 if ((len = strlen (sndfile_endian_formats_strings[n])) > maxlen) {
276 longest = sndfile_endian_formats_strings[n];
280 longest_str = longest;
282 /* force ascender + descender */
284 longest_str[0] = 'g';
285 longest_str[1] = 'l';
287 //Gtkmm2ext::set_size_request_to_display_given_text (header_format_combo, longest_str.c_str(), 5+FUDGE, 5);
289 // TRANSLATORS: "slereg" is "stereo" with ascender and descender substituted
290 //Gtkmm2ext::set_size_request_to_display_given_text (channel_count_combo, _("slereg"), 5+FUDGE, 5);
292 /* header_format_combo.set_focus_on_click (true);
293 bitdepth_format_combo.set_focus_on_click (true);
294 endian_format_combo.set_focus_on_click (true);
295 channel_count_combo.set_focus_on_click (true);
296 src_quality_combo.set_focus_on_click (true);
297 dither_type_combo.set_focus_on_click (true);
298 sample_rate_combo.set_focus_on_click (true);
299 cue_file_combo.set_focus_on_click (true);
301 dither_type_label.set_name ("ExportFormatLabel");
302 sample_rate_label.set_name ("ExportFormatLabel");
303 src_quality_label.set_name ("ExportFormatLabel");
304 channel_count_label.set_name ("ExportFormatLabel");
305 header_format_label.set_name ("ExportFormatLabel");
306 bitdepth_format_label.set_name ("ExportFormatLabel");
307 endian_format_label.set_name ("ExportFormatLabel");
308 cue_file_label.set_name ("ExportFormatLabel");
310 header_format_combo.set_name ("ExportFormatDisplay");
311 bitdepth_format_combo.set_name ("ExportFormatDisplay");
312 endian_format_combo.set_name ("ExportFormatDisplay");
313 channel_count_combo.set_name ("ExportFormatDisplay");
314 dither_type_combo.set_name ("ExportFormatDisplay");
315 src_quality_combo.set_name ("ExportFormatDisplay");
316 sample_rate_combo.set_name ("ExportFormatDisplay");
317 cue_file_combo.set_name ("ExportFormatDisplay");
319 cuefile_only_checkbox.set_name ("ExportCheckbox");
321 format_table.set_homogeneous (false);
322 format_table.set_border_width (5);
323 format_table.set_col_spacings (5);
324 format_table.set_row_spacings (5);
327 format_table.attach (channel_count_label, 0, 1, 0, 1);
328 format_table.attach (channel_count_combo, 1, 2, 0, 1);
331 format_table.attach (header_format_label, 0, 1, 1, 2);
332 format_table.attach (header_format_combo, 1, 2, 1, 2);
334 format_table.attach (bitdepth_format_label, 0, 1, 2, 3);
335 format_table.attach (bitdepth_format_combo, 1, 2, 2, 3);
337 format_table.attach (endian_format_label, 0, 1, 3, 4);
338 format_table.attach (endian_format_combo, 1, 2, 3, 4);
340 format_table.attach (sample_rate_label, 0, 1, 4, 5);
341 format_table.attach (sample_rate_combo, 1, 2, 4, 5);
343 format_table.attach (src_quality_label, 0, 1, 5, 6);
344 format_table.attach (src_quality_combo, 1, 2, 5, 6);
346 format_table.attach (dither_type_label, 0, 1, 6, 7);
347 format_table.attach (dither_type_combo, 1, 2, 6, 7);
349 format_table.attach (cue_file_label, 0, 1, 7, 8);
350 format_table.attach (cue_file_combo, 1, 2, 7, 8);
351 format_table.attach (cuefile_only_checkbox, 0, 2, 8, 9);
353 file_entry.set_name ("ExportFileDisplay");
355 signal_delete_event().connect (mem_fun(*this, &ExportDialog::window_closed));
357 ok_button = add_button (Stock::OK, RESPONSE_ACCEPT);
358 ok_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::do_export));
359 cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
360 cancel_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::end_dialog));
362 file_browse_button.set_name ("EditorGTKButton");
363 file_browse_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::initiate_browse));
365 channel_count_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::channels_chosen));
366 bitdepth_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::bitdepth_chosen));
367 header_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::header_chosen));
368 sample_rate_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::sample_rate_chosen));
369 cue_file_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::cue_file_type_chosen));
372 ExportDialog::~ExportDialog()
375 delete file_selector;
380 ExportDialog::connect_to_session (Session *s)
383 session->going_away.connect (mem_fun(*this, &Window::hide_all));
385 switch (session->frame_rate()) {
387 sample_rate_combo.set_active_text (N_("22.05kHz"));
390 sample_rate_combo.set_active_text (N_("44.1kHz"));
393 sample_rate_combo.set_active_text (N_("48kHz"));
396 sample_rate_combo.set_active_text (N_("88.2kHz"));
399 sample_rate_combo.set_active_text (N_("96kHz"));
402 sample_rate_combo.set_active_text (N_("192kHz"));
405 sample_rate_combo.set_active_text (N_("44.1kHz"));
409 src_quality_combo.set_sensitive (false);
415 ExportDialog::set_state()
417 XMLNode* node = session->instant_xml(X_("ExportDialog"), session->path());
422 if ((prop = node->property (X_("sample_rate"))) != 0) {
423 sample_rate_combo.set_active_text(prop->value());
425 if ((prop = node->property (X_("src_quality"))) != 0) {
426 src_quality_combo.set_active_text(prop->value());
428 if ((prop = node->property (X_("dither_type"))) != 0) {
429 dither_type_combo.set_active_text(prop->value());
431 if ((prop = node->property (X_("channel_count"))) != 0) {
432 channel_count_combo.set_active_text(prop->value());
434 if ((prop = node->property (X_("header_format"))) != 0) {
435 header_format_combo.set_active_text(prop->value());
437 if ((prop = node->property (X_("bitdepth_format"))) != 0) {
438 bitdepth_format_combo.set_active_text(prop->value());
440 if ((prop = node->property (X_("endian_format"))) != 0) {
441 endian_format_combo.set_active_text(prop->value());
443 if ((prop = node->property (X_("filename"))) != 0) {
444 file_entry.set_text(prop->value());
446 if ((prop = node->property (X_("cue_file_type"))) != 0) {
447 cue_file_combo.set_active_text(prop->value());
454 sample_rate_chosen();
456 if (session->master_out()) {
457 track_scroll.hide ();
459 master_scroll.hide ();
460 track_selector_button.hide ();
467 if (session->master_out()) {
468 XMLNode* master = find_named_node(*node, (X_("Master")));
473 /* default is to use all */
474 if (channel_count_combo.get_active_text() == _("mono")) {
480 TreeModel::Children rows = master_selector.get_model()->children();
481 for (uint32_t r = 0; r < session->master_out()->n_outputs(); ++r) {
484 rows[r][exp_cols.right] = true;
486 rows[r][exp_cols.left] = true;
489 rows[r][exp_cols.left] = true;
494 /* XXX use XML state */
498 XMLNode* tracks = find_named_node(*node, (X_("Tracks")));
503 XMLNodeList track_list = tracks->children(X_("Track"));
504 TreeModel::Children rows = track_selector.get_model()->children();
505 TreeModel::Children::iterator ri = rows.begin();
508 for (XMLNodeIterator it = track_list.begin(); it != track_list.end(); ++it, ++ri) {
509 if (ri == rows.end()){
513 XMLNode* track = *it;
516 if ((prop = track->property(X_("channel1"))) != 0) {
517 if (prop->value() == X_("on")) {
518 row[exp_cols.left] = true;
520 row[exp_cols.left] = false;
524 if ((prop = track->property(X_("channel2"))) != 0) {
525 if (prop->value() == X_("on")) {
526 row[exp_cols.right] = true;
528 row[exp_cols.right] = false;
535 ExportDialog::save_state()
541 XMLNode* node = new XMLNode(X_("ExportDialog"));
543 node->add_property(X_("sample_rate"), sample_rate_combo.get_active_text());
544 node->add_property(X_("src_quality"), src_quality_combo.get_active_text());
545 node->add_property(X_("dither_type"), dither_type_combo.get_active_text());
546 node->add_property(X_("channel_count"), channel_count_combo.get_active_text());
547 node->add_property(X_("header_format"), header_format_combo.get_active_text());
548 node->add_property(X_("bitdepth_format"), bitdepth_format_combo.get_active_text());
549 node->add_property(X_("endian_format"), endian_format_combo.get_active_text());
550 node->add_property(X_("filename"), file_entry.get_text());
551 node->add_property(X_("cue_file_type"), cue_file_combo.get_active_text());
553 XMLNode* tracks = new XMLNode(X_("Tracks"));
555 TreeModel::Children rows = track_selector.get_model()->children();
557 for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
558 XMLNode* track = new XMLNode(X_("Track"));
561 track->add_property(X_("channel1"), row[exp_cols.left] ? X_("on") : X_("off"));
562 track->add_property(X_("channel1"), row[exp_cols.right] ? X_("on") : X_("off"));
564 tracks->add_child_nocopy(*track);
566 node->add_child_nocopy(*tracks);
568 session->add_instant_xml(*node, session->path());
572 ExportDialog::set_range (jack_nframes_t start, jack_nframes_t end)
574 spec.start_frame = start;
575 spec.end_frame = end;
578 // XXX: this is a hack until we figure out what is really wrong
579 session->request_locate (spec.start_frame, false);
584 ExportDialog::progress_timeout ()
586 progress_bar.set_fraction (spec.progress/100);
591 ExportDialog::_export_region_thread (void *arg)
593 PBD::ThreadCreated (pthread_self(), X_("Export Region"));
595 static_cast<ExportDialog*>(arg)->export_region ();
600 ExportDialog::export_region ()
602 audio_region->exportme (*session, spec);
606 frames_to_cd_frames_string (char* buf, jack_nframes_t when, jack_nframes_t fr)
609 long unsigned int remainder;
610 int mins, secs, frames;
612 mins = when / (60 * fr);
613 remainder = when - (mins * 60 * fr);
614 secs = remainder / fr;
615 remainder -= secs * fr;
616 frames = remainder / (fr / 75);
617 sprintf (buf, " %02d:%02d:%02d", mins, secs, frames);
621 struct LocationSortByStart {
622 bool operator() (Location *a, Location *b) {
623 return a->start() < b->start();
628 ExportDialog::export_toc_file (Locations::LocationList& locations, const string& path)
631 string filepath = path + ".toc";
632 ofstream out (filepath.c_str());
633 long unsigned int last_end_time = spec.start_frame, last_start_time = spec.start_frame;
638 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD toc file"), filepath) << endmsg;
641 out << "CD_DA" << endl;
642 out << "CD_TEXT {" << endl << " LANGUAGE_MAP {" << endl << " 0 : EN" << endl << " }" << endl;
643 out << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl << " }" << endl << "}" << endl;
645 Locations::LocationList::iterator i;
646 Locations::LocationList temp;
648 for (i = locations.begin(); i != locations.end(); ++i) {
649 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
651 if (!(*i)->is_mark()) {
657 if (numtracks == 0 ) {
658 /* the user supplied no track markers.
659 we now treat the session as one track.*/
661 out << endl << "TRACK AUDIO" << endl;
663 out << "COPY" << endl;
665 out << "NO PRE_EMPHASIS" << endl;
667 /* XXX add session properties for catalog etc.
668 (so far only the session name is used) */
670 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << session->name() << "\"" << endl;
671 out << " }" << endl << "}" << endl;
673 out << "FILE \"" << path << "\" ";
675 frames_to_cd_frames_string (buf, spec.end_frame - spec.start_frame, session->frame_rate());
677 out << "START 00:00:00" << endl;
679 last_start_time = spec.start_frame;
680 last_end_time = spec.end_frame;
684 LocationSortByStart cmp;
687 for (i = temp.begin(); i != temp.end(); ++i) {
689 if (!(*i)->is_mark()) {
691 out << endl << "TRACK AUDIO" << endl;
693 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
696 out << "COPY" << endl;
698 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
699 out << "PRE_EMPHASIS" << endl;
701 out << "NO PRE_EMPHASIS" << endl;
704 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
705 out << "ISRC \"" << (*i)->cd_info["isrc"] << "\"" << endl;
708 out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE \"" << (*i)->name() << "\"" << endl;
709 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
710 out << " PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
712 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
713 out << " COMPOSER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
716 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
718 out << (*i)->cd_info["isrc"].substr(0,2) << "-";
719 out << (*i)->cd_info["isrc"].substr(2,3) << "-";
720 out << (*i)->cd_info["isrc"].substr(5,2) << "-";
721 out << (*i)->cd_info["isrc"].substr(7,5) << "\"" << endl;
724 out << " }" << endl << "}" << endl;
726 frames_to_cd_frames_string (buf, last_end_time - spec.start_frame, session->frame_rate());
727 out << "FILE \"" << path << "\" " << buf;
729 frames_to_cd_frames_string (buf, (*i)->end() - last_end_time, session->frame_rate());
732 frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
733 out << "START" << buf << endl;
735 last_start_time = (*i)->start();
736 last_end_time = (*i)->end();
739 } else if ((*i)->start() < last_end_time) {
740 /* this is an index within a track */
742 frames_to_cd_frames_string (buf, (*i)->start() - last_start_time, session->frame_rate());
743 out << "INDEX" << buf << endl;
751 ExportDialog::export_cue_file (Locations::LocationList& locations, const string& path)
753 string filepath = path + ".cue";
754 ofstream out (filepath.c_str());
756 long unsigned int last_track_end = spec.start_frame;
757 int numtracks = 0, tracknum = 0, indexnum = 0;
760 error << string_compose(_("Editor: cannot open \"%1\" as export file for CD cue file"), filepath) << endmsg;
764 Locations::LocationList::iterator i;
765 Locations::LocationList temp;
767 for (i = locations.begin(); i != locations.end(); ++i) {
768 if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
770 if (!(*i)->is_mark()) {
776 out << "REM Cue file generated by Ardour" << endl;
777 out << "TITLE \"" << session->name() << "\"" << endl;
779 if ((header_format_combo.get_active_text() == N_("WAV"))) {
780 out << "FILE " << path << " WAVE" << endl;
782 out << "FILE " << path << ' ' << (header_format_combo.get_active_text()) << endl;
785 if (numtracks == 0) {
786 /* the user has supplied no track markers.
787 the entire export is treated as one track.
793 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
796 out << "DCP " << endl;
798 /* use the session name*/
800 if (session->name() != "") {
801 out << "TITLE \"" << session->name() << "\"" << endl;
804 /* no pregap in this case */
806 out << "INDEX 00 00:00:00" << endl;
808 out << "INDEX 01 00:00:00" << endl;
810 last_track_end = spec.end_frame;
814 LocationSortByStart cmp;
817 for ( i = temp.begin(); i != temp.end(); ++i) {
819 if (!(*i)->is_mark() && ((*i)->start() >= last_track_end)) {
820 /* this is a track and it doesn't start inside another one*/
824 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
827 if ((*i)->cd_info.find("scms") != (*i)->cd_info.end()) {
833 if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end()) {
838 if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {
839 out << "ISRC " << (*i)->cd_info["isrc"] << endl;
842 if ((*i)->name() != "") {
843 out << "TITLE \"" << (*i)->name() << "\"" << endl;
846 if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
847 out << "PERFORMER \"" << (*i)->cd_info["performer"] << "\"" << endl;
850 if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
851 out << "SONGWRITER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
853 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
855 frames_to_cd_frames_string (buf, last_track_end - spec.start_frame, session->frame_rate());
858 last_track_end = (*i)->end();
860 if ((tracknum > 0) && ((*i)->start() < last_track_end)) {
861 /*this is an index and it lies within a track*/
862 snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
864 frames_to_cd_frames_string (buf,(*i)->start() - spec.start_frame, session->frame_rate());
874 ExportDialog::do_export_cd_markers (const string& path,const string& cuefile_type)
876 if (cuefile_type == "TOC") {
877 session->locations()->apply (*this, &ExportDialog::export_toc_file, path);
879 session->locations()->apply (*this, &ExportDialog::export_cue_file, path);
885 ExportDialog::do_export ()
887 // sanity check file name first
888 string filepath = file_entry.get_text();
891 if (filepath.empty()) {
893 string txt = _("Please enter a valid filename.");
894 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
899 // check if file exists already and warn
900 if (stat (filepath.c_str(), &statbuf) == 0) {
901 if (S_ISDIR (statbuf.st_mode)) {
902 string txt = _("Please specify a complete filename for the audio file.");
903 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
908 string txt = _("File already exists, do you want to overwrite it?");
909 MessageDialog msg (*this, txt, false, MESSAGE_QUESTION, BUTTONS_YES_NO, true);
910 //ArdourMessage msg (this, X_("exportoverwrite"), txt, true, false, Gtk::BUTTONS_YES_NO);
911 if ((ResponseType) msg.run() == Gtk::RESPONSE_NO) {
917 // directory needs to exist and be writable
918 string dirpath = PBD::dirname (filepath);
919 if (::access (dirpath.c_str(), W_OK) != 0) {
920 string txt = _("Cannot write file in: ") + dirpath;
921 MessageDialog msg (*this, txt, false, MESSAGE_ERROR, BUTTONS_OK, true);
926 if (cue_file_combo.get_active_text () != _("None")) {
927 do_export_cd_markers (file_entry.get_text(), cue_file_combo.get_active_text ());
930 if (cuefile_only_checkbox.get_active()) {
935 ok_button->set_sensitive(false);
940 spec.path = filepath;
944 spec.port_map.clear();
946 if (channel_count_combo.get_active_text() == _("mono")) {
954 spec.format |= sndfile_header_format_from_string (header_format_combo.get_active_text ());
956 if ((spec.format & SF_FORMAT_WAV) == 0) {
957 /* RIFF/WAV specifies endianess */
958 spec.format |= sndfile_endian_format_from_string (endian_format_combo.get_active_text ());
961 spec.format |= sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
963 string sr_str = sample_rate_combo.get_active_text();
964 if (sr_str == N_("22.05kHz")) {
965 spec.sample_rate = 22050;
966 } else if (sr_str == N_("44.1kHz")) {
967 spec.sample_rate = 44100;
968 } else if (sr_str == N_("48kHz")) {
969 spec.sample_rate = 48000;
970 } else if (sr_str == N_("88.2kHz")) {
971 spec.sample_rate = 88200;
972 } else if (sr_str == N_("96kHz")) {
973 spec.sample_rate = 96000;
974 } else if (sr_str == N_("192kHz")) {
975 spec.sample_rate = 192000;
977 spec.sample_rate = session->frame_rate();
980 string src_str = src_quality_combo.get_active_text();
981 if (src_str == _("fastest")) {
982 spec.src_quality = SRC_ZERO_ORDER_HOLD;
983 } else if (src_str == _("linear")) {
984 spec.src_quality = SRC_LINEAR;
985 } else if (src_str == _("better")) {
986 spec.src_quality = SRC_SINC_FASTEST;
987 } else if (src_str == _("intermediate")) {
988 spec.src_quality = SRC_SINC_MEDIUM_QUALITY;
990 spec.src_quality = SRC_SINC_BEST_QUALITY;
993 string dither_str = dither_type_combo.get_active_text();
994 if (dither_str == _("None")) {
995 spec.dither_type = GDitherNone;
996 } else if (dither_str == _("Rectangular")) {
997 spec.dither_type = GDitherRect;
998 } else if (dither_str == _("Triangular")) {
999 spec.dither_type = GDitherTri;
1001 spec.dither_type = GDitherShaped;
1004 if (!audio_region) {
1007 Port *last_port = 0;
1009 TreeModel::Children rows = master_selector.get_model()->children();
1010 TreeModel::Children::iterator ri;
1012 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1014 Port* port = row[exp_cols.port];
1016 if (last_port != port) {
1020 if (row[exp_cols.left]) {
1021 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1024 if (spec.channels == 2) {
1025 if (row[exp_cols.right]) {
1026 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1033 rows = track_selector.get_model()->children();
1034 for (ri = rows.begin(); ri != rows.end(); ++ri) {
1037 Port* port = row[exp_cols.port];
1039 if (last_port != port) {
1043 if (row[exp_cols.left]) {
1044 spec.port_map[0].push_back (std::pair<Port*,uint32_t>(port, chan));
1047 if (spec.channels == 2) {
1048 if (row[exp_cols.right]) {
1049 spec.port_map[1].push_back (std::pair<Port*,uint32_t>(port, chan));
1059 progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
1060 cancel_label.set_text (_("Stop Export"));
1062 if (!audio_region) {
1063 if (session->start_audio_export (spec)) {
1068 pthread_create_and_store ("region export", &thr, 0, ExportDialog::_export_region_thread, this);
1071 gtk_main_iteration ();
1072 while (spec.running) {
1073 if (gtk_events_pending()) {
1074 gtk_main_iteration ();
1081 progress_connection.disconnect ();
1087 ExportDialog::end_dialog ()
1093 while (spec.running) {
1094 if (gtk_events_pending()) {
1095 gtk_main_iteration ();
1102 session->engine().freewheel (false);
1106 if (file_selector) {
1107 file_selector->hide_all ();
1111 ok_button->set_sensitive(true);
1115 ExportDialog::start_export ()
1121 /* If it the filename hasn't been set before, use the
1122 directory above the current session as a default
1123 location for the export.
1126 if (file_entry.get_text().length() == 0) {
1127 string dir = session->path();
1128 string::size_type last_slash;
1130 if ((last_slash = dir.find_last_of ('/')) != string::npos) {
1131 dir = dir.substr (0, last_slash+1);
1134 dir = dir + "export.wav";
1136 file_entry.set_text (dir);
1139 progress_bar.set_fraction (0);
1140 cancel_label.set_text (_("Cancel"));
1144 if (session->master_out()) {
1145 track_scroll.hide ();
1147 master_scroll.hide ();
1148 track_selector_button.hide ();
1153 ExportDialog::header_chosen ()
1155 if (sndfile_header_format_from_string (header_format_combo.get_active_text ()) == SF_FORMAT_WAV) {
1156 endian_format_combo.set_sensitive (false);
1158 endian_format_combo.set_sensitive (true);
1163 ExportDialog::bitdepth_chosen ()
1165 int format = sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
1167 case SF_FORMAT_PCM_24:
1168 case SF_FORMAT_PCM_32:
1169 case SF_FORMAT_FLOAT:
1170 dither_type_combo.set_sensitive (false);
1174 dither_type_combo.set_sensitive (true);
1180 ExportDialog::cue_file_type_chosen ()
1182 if (cue_file_combo.get_active_text () != "None") {
1183 cuefile_only_checkbox.set_sensitive (true);
1185 cuefile_only_checkbox.set_active (false);
1186 cuefile_only_checkbox.set_sensitive (false);
1191 ExportDialog::sample_rate_chosen ()
1193 string sr_str = sample_rate_combo.get_active_text();
1194 jack_nframes_t rate;
1196 if (sr_str == N_("22.05kHz")) {
1198 } else if (sr_str == N_("44.1kHz")) {
1200 } else if (sr_str == N_("48kHz")) {
1202 } else if (sr_str == N_("88.2kHz")) {
1204 } else if (sr_str == N_("96kHz")) {
1206 } else if (sr_str == N_("192kHz")) {
1209 rate = session->frame_rate();
1212 if (rate != session->frame_rate()) {
1213 src_quality_combo.set_sensitive (true);
1215 src_quality_combo.set_sensitive (false);
1220 ExportDialog::channels_chosen ()
1224 mono = (channel_count_combo.get_active_text() == _("mono"));
1227 track_selector.get_column(2)->set_visible(false);
1228 track_selector.get_column(1)->set_title(_("Export"));
1230 if (session->master_out()) {
1231 master_selector.get_column(2)->set_visible(false);
1232 master_selector.get_column(1)->set_title(_("Export"));
1236 track_selector.get_column(2)->set_visible(true);
1237 track_selector.get_column(1)->set_title(_("Left"));
1239 if (session->master_out()) {
1240 master_selector.get_column(2)->set_visible(true);
1241 master_selector.get_column(1)->set_title(_("Left"));
1249 ExportDialog::fill_lists ()
1251 track_list->clear();
1252 master_list->clear();
1254 Session::RouteList routes = session->get_routes ();
1256 for (Session::RouteList::iterator ri = routes.begin(); ri != routes.end(); ++ri) {
1258 Route* route = (*ri);
1260 if (route->hidden()) {
1264 for (uint32_t i=0; i < route->n_outputs(); ++i) {
1266 if (route->n_outputs() == 1) {
1267 name = route->name();
1269 name = string_compose("%1: out-%2", route->name(), i+1);
1272 if (route == session->master_out()) {
1273 TreeModel::iterator iter = master_list->append();
1274 TreeModel::Row row = *iter;
1275 row[exp_cols.output] = name;
1276 row[exp_cols.left] = false;
1277 row[exp_cols.right] = false;
1278 row[exp_cols.port] = route->output (i);
1280 TreeModel::iterator iter = track_list->append();
1281 TreeModel::Row row = *iter;
1282 row[exp_cols.output] = name;
1283 row[exp_cols.left] = false;
1284 row[exp_cols.right] = false;
1285 row[exp_cols.port] = route->output (i);
1292 ExportDialog::window_closed (GdkEventAny *ignored)
1298 ExportDialog::initiate_browse ()
1300 if (file_selector == 0) {
1301 file_selector = new FileSelection;
1302 file_selector->set_modal (true);
1304 file_selector->get_cancel_button()->signal_clicked().connect (bind (mem_fun(*this, &ExportDialog::finish_browse), -1));
1305 file_selector->get_ok_button()->signal_clicked().connect (bind (mem_fun(*this, &ExportDialog::finish_browse), 1));
1307 file_selector->set_filename (file_entry.get_text());
1308 file_selector->show_all ();
1312 ExportDialog::finish_browse (int status)
1314 if (file_selector) {
1316 string result = file_selector->get_filename();
1318 if (result.length()) {
1319 file_entry.set_text (result);
1322 file_selector->hide_all();
1327 ExportDialog::track_selector_button_click ()
1329 if (track_scroll.is_visible ()) {
1330 track_scroll.hide ();
1332 track_scroll.show_all ();