add JAG to author list
[ardour.git] / gtk2_ardour / export_dialog.cc
index e5493a2272ae11b172d574b39fb9f7a46a812dbf..eba1fdbd147de9ce0d11816cfd79cff380f0fa67 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 
 */
 
 #include <fstream>
 
 #include <samplerate.h>
-
 #include <pbd/convert.h>
 #include <pbd/xml++.h>
 
 #include <gtkmm2ext/utils.h>
+
 #include <ardour/export.h>
 #include <ardour/sndfile_helpers.h>
 #include <ardour/audio_track.h>
 #include <ardour/audioengine.h>
 #include <ardour/gdither.h>
 #include <ardour/utils.h>
+#include <ardour/profile.h>
 
 #include "export_dialog.h"
 #include "ardour_ui.h"
 #include "public_editor.h"
 #include "keyboard.h"
+#include "nag.h"
 
 #include "i18n.h"
 
@@ -52,8 +53,7 @@ using namespace ARDOUR;
 using namespace PBD;
 using namespace sigc;
 using namespace Gtk;
-
-using PBD::internationalize;
+using namespace Gtkmm2ext;
 
 static const gchar *sample_rates[] = {
        N_("22.05kHz"),
@@ -109,7 +109,6 @@ ExportDialog::ExportDialog(PublicEditor& e)
          src_quality_label (_("Conversion Quality"), 1.0, 0.5),
          dither_type_label (_("Dither Type"), 1.0, 0.5),
          cuefile_only_checkbox (_("Export CD Marker File Only")),
-         file_frame (_("Export to File")),
          file_browse_button (_("Browse")),
          track_selector_button (_("Specific tracks ..."))
 {
@@ -121,15 +120,16 @@ ExportDialog::ExportDialog(PublicEditor& e)
        track_and_master_selection_allowed = true;
        channel_count_selection_allowed = true;
        export_cd_markers_allowed = true;
-       
-       set_title (_("ardour: export"));
-       set_wmclass (_("ardour_export"), "Ardour");
+
+       set_title (_("Export"));
+       set_wmclass (X_("ardour_export"), "Ardour");
        set_name ("ExportWindow");
        add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
-
+       
        spec.running = false;
 
        file_entry.set_name ("ExportFileNameEntry");
+       file_entry.set_activates_default (true);
 
        master_list = ListStore::create (exp_cols);
        master_selector.set_model (master_list);
@@ -140,7 +140,7 @@ ExportDialog::ExportDialog(PublicEditor& e)
        master_selector.append_column_editable(_("Left"), exp_cols.left);
        master_selector.append_column_editable(_("Right"), exp_cols.right);
        master_selector.get_column(0)->set_min_width(100);
-       
+
        master_selector.get_column(1)->set_min_width(40);
        master_selector.get_column(1)->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
        master_selector.get_column(2)->set_min_width(40);
@@ -212,28 +212,28 @@ ExportDialog::ExportDialog(PublicEditor& e)
           takes a reference. 
        */
 
-       vector<string> pop_strings = internationalize(sample_rates);
+       vector<string> pop_strings = I18N (sample_rates);
        Gtkmm2ext::set_popdown_strings (sample_rate_combo, pop_strings);
        sample_rate_combo.set_active_text (pop_strings.front());
-       pop_strings = internationalize(src_quality);
+       pop_strings = I18N (src_quality);
        Gtkmm2ext::set_popdown_strings (src_quality_combo, pop_strings);
        src_quality_combo.set_active_text (pop_strings.front());
-       pop_strings = internationalize(dither_types);
+       pop_strings = I18N (dither_types);
        Gtkmm2ext::set_popdown_strings (dither_type_combo, pop_strings);
        dither_type_combo.set_active_text (pop_strings.front());
-       pop_strings = internationalize(channel_strings);
+       pop_strings = I18N (channel_strings);
        Gtkmm2ext::set_popdown_strings (channel_count_combo, pop_strings);
        channel_count_combo.set_active_text (pop_strings.front());
-       pop_strings = internationalize((const char **) sndfile_header_formats_strings);
+       pop_strings = I18N ((const char **) sndfile_header_formats_strings);
        Gtkmm2ext::set_popdown_strings (header_format_combo, pop_strings);
        header_format_combo.set_active_text (pop_strings.front());
-       pop_strings = internationalize((const char **) sndfile_bitdepth_formats_strings);
+       pop_strings = I18N ((const char **) sndfile_bitdepth_formats_strings);
        Gtkmm2ext::set_popdown_strings (bitdepth_format_combo, pop_strings);
        bitdepth_format_combo.set_active_text (pop_strings.front());
-       pop_strings = internationalize((const char **) sndfile_endian_formats_strings);
+       pop_strings = I18N ((const char **) sndfile_endian_formats_strings);
        Gtkmm2ext::set_popdown_strings (endian_format_combo, pop_strings);
        endian_format_combo.set_active_text (pop_strings.front());
-       pop_strings = internationalize(cue_file_types);
+       pop_strings = I18N (cue_file_types);
        Gtkmm2ext::set_popdown_strings (cue_file_combo, pop_strings);
        cue_file_combo.set_active_text (pop_strings.front());
 
@@ -316,30 +316,52 @@ ExportDialog::ExportDialog(PublicEditor& e)
        format_table.set_col_spacings (5);
        format_table.set_row_spacings (5);
 
-       format_table.attach (channel_count_label, 0, 1, 0, 1);
-       format_table.attach (channel_count_combo, 1, 2, 0, 1);
+       int row = 0;
+
+       format_table.attach (channel_count_label, 0, 1, row, row+1);
+       format_table.attach (channel_count_combo, 1, 2, row, row+1);
+
+       row++;
        
-       format_table.attach (header_format_label, 0, 1, 1, 2);
-       format_table.attach (header_format_combo, 1, 2, 1, 2);
+       format_table.attach (header_format_label, 0, 1, row, row+1);
+       format_table.attach (header_format_combo, 1, 2, row, row+1);
+
+       row++;
+
+       format_table.attach (bitdepth_format_label, 0, 1, row, row+1);
+       format_table.attach (bitdepth_format_combo, 1, 2, row, row+1);
+
+       row++;
+
+       if (!Profile->get_sae()) {
+               format_table.attach (endian_format_label, 0, 1, row, row+1);
+               format_table.attach (endian_format_combo, 1, 2, row, row+1);
+               row++;
+       }
 
-       format_table.attach (bitdepth_format_label, 0, 1, 2, 3);
-       format_table.attach (bitdepth_format_combo, 1, 2, 2, 3);
+       format_table.attach (sample_rate_label, 0, 1, row, row+1);
+       format_table.attach (sample_rate_combo, 1, 2, row, row+1);
 
-       format_table.attach (endian_format_label, 0, 1, 3, 4);
-       format_table.attach (endian_format_combo, 1, 2, 3, 4);
+       row++;
 
-       format_table.attach (sample_rate_label, 0, 1, 4, 5);
-       format_table.attach (sample_rate_combo, 1, 2, 4, 5);
+       if (!Profile->get_sae()) {
+               format_table.attach (src_quality_label, 0, 1, row, row+1);
+               format_table.attach (src_quality_combo, 1, 2, row, row+1);
+               row++;
+       }
 
-       format_table.attach (src_quality_label, 0, 1, 5, 6);
-       format_table.attach (src_quality_combo, 1, 2, 5, 6);
+       format_table.attach (dither_type_label, 0, 1, row, row+1);
+       format_table.attach (dither_type_combo, 1, 2, row, row+1);
 
-       format_table.attach (dither_type_label, 0, 1, 6, 7);
-       format_table.attach (dither_type_combo, 1, 2, 6, 7);
+       row++;
 
-       format_table.attach (cue_file_label, 0, 1, 7, 8);
-       format_table.attach (cue_file_combo, 1, 2, 7, 8);
-       format_table.attach (cuefile_only_checkbox, 0, 2, 8, 9);
+       if (!Profile->get_sae()) {
+               format_table.attach (cue_file_label, 0, 1, row, row+1);
+               format_table.attach (cue_file_combo, 1, 2, row, row+1);
+               row++;
+       
+               format_table.attach (cuefile_only_checkbox, 0, 2, row, row+1);
+       }
 
        file_entry.set_name ("ExportFileDisplay");
 
@@ -348,6 +370,7 @@ ExportDialog::ExportDialog(PublicEditor& e)
        cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
        cancel_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::end_dialog));
        ok_button = add_button (_("Export"), RESPONSE_ACCEPT);
+       set_default_response (RESPONSE_ACCEPT);
        ok_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::do_export));
        
        file_browse_button.set_name ("EditorGTKButton");
@@ -396,25 +419,25 @@ ExportDialog::connect_to_session (Session *s)
 
        switch (session->frame_rate()) {
        case 22050:
-               sample_rate_combo.set_active_text (N_("22.05kHz"));
+               sample_rate_combo.set_active_text (_("22.05kHz"));
                break;
        case 44100:
-               sample_rate_combo.set_active_text (N_("44.1kHz"));
+               sample_rate_combo.set_active_text (_("44.1kHz"));
                break;
        case 48000:
-               sample_rate_combo.set_active_text (N_("48kHz"));
+               sample_rate_combo.set_active_text (_("48kHz"));
                break;
        case 88200:
-               sample_rate_combo.set_active_text (N_("88.2kHz"));
+               sample_rate_combo.set_active_text (_("88.2kHz"));
                break;
        case 96000:
-               sample_rate_combo.set_active_text (N_("96kHz"));
+               sample_rate_combo.set_active_text (_("96kHz"));
                break;
        case 192000:
-               sample_rate_combo.set_active_text (N_("192kHz"));
+               sample_rate_combo.set_active_text (_("192kHz"));
                break;
        default:
-               sample_rate_combo.set_active_text (N_("44.1kHz"));
+               sample_rate_combo.set_active_text (_("44.1kHz"));
                break;
        }
 
@@ -571,7 +594,7 @@ ExportDialog::save_state()
 
                row = *ri;
                track->add_property(X_("channel1"), row[exp_cols.left] ? X_("on") : X_("off"));
-               track->add_property(X_("channel1"), row[exp_cols.right] ? X_("on") : X_("off"));
+               track->add_property(X_("channel2"), row[exp_cols.right] ? X_("on") : X_("off"));
 
                tracks->add_child_nocopy(*track);
        }
@@ -623,12 +646,18 @@ ExportDialog::export_toc_file (Locations::LocationList& locations, const string&
                return;
        }
        
-    string filepath = path + ".toc";
-       ofstream out (filepath.c_str());
        long unsigned int last_end_time = spec.start_frame, last_start_time = spec.start_frame;
-       int numtracks = 0;
        gchar buf[18];
-
+       
+       /* Build the toc's file name from the specified audio file name. */
+       string basename = Glib::path_get_basename(path);        
+       size_t ext_pos = basename.rfind('.');
+       if (ext_pos != string::npos) {
+               basename = basename.substr(0, ext_pos); /* strip file extension, if there is one */
+       }
+       string filepath = Glib::build_filename(Glib::path_get_dirname(path), basename + ".toc");
+       
+       ofstream out (filepath.c_str());
        if (!out) {
                error << string_compose(_("Editor: cannot open \"%1\" as export file for CD toc file"), filepath) << endmsg;
                return;
@@ -641,102 +670,110 @@ ExportDialog::export_toc_file (Locations::LocationList& locations, const string&
        Locations::LocationList temp;
 
        for (i = locations.begin(); i != locations.end(); ++i) {
-         if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
-           temp.push_back (*i);
-           if (!(*i)->is_mark()) {
-             numtracks ++;
-           }
-         }
+               if ((*i)->start() >= spec.start_frame && (*i)->end() <= spec.end_frame && (*i)->is_cd_marker() && !(*i)->is_end()) {
+                       temp.push_back (*i);
+               }
        }
 
-       if (numtracks == 0 ) {
-                   /* the user supplied no track markers.
-                      we now treat the session as one track.*/
-
-                   out << endl << "TRACK AUDIO" << endl;
-                  
-                   out << "COPY" << endl;
-
-                   out << "NO PRE_EMPHASIS" << endl;
-   
-                   /* XXX add session properties for catalog etc.
-                      (so far only the session name is used) */
-                   
-                   out << "CD_TEXT {" << endl << "  LANGUAGE 0 {" << endl << "     TITLE \"" << session->name() << "\"" << endl;
-                   out << "  }" << endl << "}" << endl;
-
-                   out << "FILE \"" << path << "\" ";
-                   out << "00:00:00 " ;
-                   frames_to_cd_frames_string (buf, spec.end_frame - spec.start_frame, session->frame_rate());
-                   out << buf << endl;
-                   out << "START 00:00:00" << endl;
-
-                   last_start_time = spec.start_frame;
-                   last_end_time = spec.end_frame;
-       } 
-
-       if (temp.size()) {
+       if (temp.size() > 0) {
                LocationSortByStart cmp;
                temp.sort (cmp);
+               Location * curr_range = 0;
+               Locations::LocationList::iterator nexti;
 
                for (i = temp.begin(); i != temp.end(); ++i) {
-       
-                     if (!(*i)->is_mark()) {
-                       /*this is a track */
-                       out << endl << "TRACK AUDIO" << endl;
 
-                       if ((*i)->cd_info.find("scms") != (*i)->cd_info.end())  {
-                         out << "NO ";
-                       }
-                       out << "COPY" << endl;
-
-                       if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end())  {
-                         out << "PRE_EMPHASIS" << endl;
-                       } else {
-                         out << "NO PRE_EMPHASIS" << endl;
-                       }
-
-                       if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end())  {
-                         out << "ISRC \"" << (*i)->cd_info["isrc"] << "\"" << endl;
-                       }
+                       if ((*i)->start() >= last_end_time)
+                       {
+                               /* this is a track, defined by a cd range marker or a cd location marker outside of a cd range */
+                               out << endl << "TRACK AUDIO" << endl;
+                               
+                               if ((*i)->cd_info.find("scms") != (*i)->cd_info.end())  {
+                                       out << "NO ";
+                               }
+                               out << "COPY" << endl;
+                               
+                               if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end())  {
+                                       out << "PRE_EMPHASIS" << endl;
+                               } else {
+                                       out << "NO PRE_EMPHASIS" << endl;
+                               }
+                               
+                               if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end())  {
+                                       out << "ISRC \"" << (*i)->cd_info["isrc"] << "\"" << endl;
+                               }
+                               
+                               out << "CD_TEXT {" << endl << "  LANGUAGE 0 {" << endl << "     TITLE \"" << (*i)->name() << "\"" << endl;
+                               if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
+                                       out << "     PERFORMER \"" << (*i)->cd_info["performer"]  << "\"" << endl;
+                               }
+                               if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
+                                       out  << "     COMPOSER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
+                               }
+                               
+                               if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {                          
+                                       out  << "     ISRC \"";
+                                       out << (*i)->cd_info["isrc"].substr(0,2) << "-";
+                                       out << (*i)->cd_info["isrc"].substr(2,3) << "-";
+                                       out << (*i)->cd_info["isrc"].substr(5,2) << "-";
+                                       out << (*i)->cd_info["isrc"].substr(7,5) << "\"" << endl;
+                               }
+                               
+                               out << "  }" << endl << "}" << endl;
+                               
+                               frames_to_cd_frames_string (buf, last_end_time - spec.start_frame, session->frame_rate());
+                               out << "FILE \"" << Glib::path_get_basename(path) << "\"" << buf;
+                               
+                               if ((*i)->is_mark()) {
+                                       // a mark track location needs to look ahead to the next marker's start to determine length
+                                       nexti = i;
+                                       ++nexti;
+                                       if (nexti != temp.end()) {
+                                               frames_to_cd_frames_string (buf, (*nexti)->start() - last_end_time, session->frame_rate());
+                                               out << buf << endl;
+                                               
+                                               frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
+                                               out << "START" << buf << endl;
+                                               
+                                               last_start_time = (*i)->start();
+                                               last_end_time = (*nexti)->start();
+                                       }
+                                       else {
+                                               // this was the last marker, use session end
+                                               frames_to_cd_frames_string (buf, spec.end_frame - last_end_time, session->frame_rate());
+                                               out << buf << endl;
+                                               
+                                               frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
+                                               out << "START" << buf << endl;
+                                               
+                                               last_start_time = (*i)->start();
+                                               last_end_time = spec.end_frame;
+                                       }
 
-                       out << "CD_TEXT {" << endl << "  LANGUAGE 0 {" << endl << "     TITLE \"" << (*i)->name() << "\"" << endl;
-                       if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
-                         out << "     PERFORMER \"" << (*i)->cd_info["performer"]  << "\"" << endl;
-                       }
-                       if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
-                         out  << "     COMPOSER \"" << (*i)->cd_info["string_composer"] << "\"" << endl;
+                                       curr_range = 0;
+                               }
+                               else {
+                                       // range
+                                       frames_to_cd_frames_string (buf, (*i)->end() - last_end_time, session->frame_rate());
+                                       out << buf << endl;
+                                       
+                                       frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
+                                       out << "START" << buf << endl;
+                                       
+                                       last_start_time = (*i)->start();
+                                       last_end_time = (*i)->end();
+
+                                       curr_range = (*i);
+                               }
+                               
                        }
-
-                       if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end()) {                          
-                         out  << "     ISRC \"";
-                         out << (*i)->cd_info["isrc"].substr(0,2) << "-";
-                         out << (*i)->cd_info["isrc"].substr(2,3) << "-";
-                         out << (*i)->cd_info["isrc"].substr(5,2) << "-";
-                         out << (*i)->cd_info["isrc"].substr(7,5) << "\"" << endl;
+                       else if ((*i)->is_mark()) 
+                       {
+                               /* this is an index within a track */
+                               
+                               frames_to_cd_frames_string (buf, (*i)->start() - last_start_time, session->frame_rate());
+                               out << "INDEX" << buf << endl;
                        }
-
-                       out << "  }" << endl << "}" << endl;
-
-                       frames_to_cd_frames_string (buf, last_end_time - spec.start_frame, session->frame_rate());
-                       out << "FILE \"" << path << "\" " << buf;
-
-                       frames_to_cd_frames_string (buf, (*i)->end() - last_end_time, session->frame_rate());
-                       out << buf << endl;
-
-                       frames_to_cd_frames_string (buf, (*i)->start() - last_end_time, session->frame_rate());
-                       out << "START" << buf << endl;
-                       
-                       last_start_time = (*i)->start();
-                       last_end_time = (*i)->end();
-                
-
-                     } else  if ((*i)->start() < last_end_time) {
-                       /* this is an index within a track */
-                       
-                       frames_to_cd_frames_string (buf, (*i)->start() - last_start_time, session->frame_rate());
-                       out << "INDEX" << buf << endl;
-                     }
                }
        }
        
@@ -749,12 +786,19 @@ ExportDialog::export_cue_file (Locations::LocationList& locations, const string&
                return;
        }
        
-    string filepath = path + ".cue";
-       ofstream out (filepath.c_str());
        gchar buf[18];
        long unsigned int last_track_end = spec.start_frame;
        int numtracks = 0, tracknum = 0, indexnum = 0;
-
+       
+       /* Build the cue sheet's file name from the specified audio file name. */
+       string basename = Glib::path_get_basename(path);        
+       size_t ext_pos = basename.rfind('.');
+       if (ext_pos != string::npos) {
+               basename = basename.substr(0, ext_pos); /* strip file extension, if there is one */
+       }
+       string filepath = Glib::build_filename(Glib::path_get_dirname(path), basename + ".cue");
+       
+       ofstream out (filepath.c_str());
        if (!out) {
                error << string_compose(_("Editor: cannot open \"%1\" as export file for CD cue file"), filepath) << endmsg;
                return;
@@ -774,96 +818,147 @@ ExportDialog::export_cue_file (Locations::LocationList& locations, const string&
        
        out << "REM Cue file generated by Ardour" << endl;
        out << "TITLE \"" << session->name() << "\"" << endl;
+       
+       out << "FILE \"" << Glib::path_get_basename(path) << "\" ";
+       
+       /*  The cue sheet syntax has originally five file types:
+                       WAVE     : 44.1 kHz, 16 Bit (little endian)
+                       AIFF     : 44.1 kHz, 16 Bit (big endian) 
+                       BINARY   : 44.1 kHz, 16 Bit (little endian)
+                       MOTOROLA : 44.1 kHz, 16 Bit (big endian)
+                       MP3
+       
+               We want to use cue sheets not only as CD images but also as general playlyist
+               format, thus for WAVE and AIFF we don't care if it's really 44.1 kHz/16 Bit, the
+               soundfile's header shows it anyway.  But for the raw formats, i.e. BINARY 
+               and MOTOROLA we do care, because no header would tell us about a different format.
 
-       if ((header_format_combo.get_active_text() == N_("WAV"))) {
-                 out << "FILE " << path  << " WAVE" << endl;
+               For all other formats we just make up our own file type.  MP3 is not supported 
+               at the moment.
+       */
+       int file_format = sndfile_header_format_from_string (header_format_combo.get_active_text ());
+       if ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV) {
+               out << "WAVE";
+       } else if ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AIFF) {
+               out << "AIFF";
+       } else if ( ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW) 
+                               && (sndfile_bitdepth_format_from_string(bitdepth_format_combo.get_active_text()) == SF_FORMAT_PCM_16)
+                               && (sample_rate_combo.get_active_text() == _("44.1kHz")) ) {
+               /* raw audio, 16 Bit, 44.1 kHz */
+               if (sndfile_endian_format_from_string(endian_format_combo.get_active_text()) == SF_ENDIAN_LITTLE) {
+                       out << "BINARY";
+               } else {
+                       out << "MOTOROLA";
+               }
        } else {
-                 out << "FILE " << path  << ' ' << (header_format_combo.get_active_text()) << endl;
+               out << (header_format_combo.get_active_text());
        }
+       out << endl;
+
+       if (false && numtracks == 0) {
+               /* the user has supplied no track markers.
+                  the entire export is treated as one track. 
+               */
+
+               numtracks++;
+               tracknum++;
+               indexnum = 0;
+
+               snprintf (buf, sizeof(buf), "  TRACK %02d AUDIO", tracknum);
+               out << buf << endl;
+               out << "    FLAGS DCP" << endl;            
+
+               /* use the session name*/
 
-       if (numtracks == 0) {
-                   /* the user has supplied no track markers.
-                      the entire export is treated as one track. 
-                   */
-
-                 numtracks++;
-                 tracknum++;
-                 indexnum = 0;
-                 out << endl << "TRACK " << tracknum << " AUDIO" << endl;
-                 out << "FLAGS " ;
-                 
-                 out << "DCP " << endl;                   
-                 
-                 /* use the session name*/
-                 
-                 if (session->name() != "") {
-                   out << "TITLE \"" << session->name() << "\"" << endl;
-                 }           
-                 
-                 /* no pregap in this case */
-
-                 out << "INDEX 00 00:00:00" << endl;
-                 indexnum++;
-                 out << "INDEX 01 00:00:00" << endl;
-                 indexnum++;
-                 last_track_end = spec.end_frame;
+               out << "    TITLE \"" << session->name() << "\"" << endl;
+
+               /* No pregap is specified in this case, adding the default pregap
+                  is left to the burning application. */
+
+               out << "    INDEX 01 00:00:00" << endl;
+               indexnum = 2;
+               last_track_end = spec.end_frame;
        }
 
        if (temp.size()) {
                LocationSortByStart cmp;
                temp.sort (cmp);
+               Location * curr_range = 0;
+               Locations::LocationList::iterator nexti;
 
                for ( i = temp.begin(); i != temp.end(); ++i) {
 
-                   if (!(*i)->is_mark() && ((*i)->start() >= last_track_end)) {
-                     /* this is a track and it doesn't start inside another one*/
-                     
-                     tracknum++;
-                     indexnum = 0;
-                     out << endl << "TRACK " << tracknum << " AUDIO" << endl;
-                     out << "FLAGS " ;
-                     
-                     if ((*i)->cd_info.find("scms") != (*i)->cd_info.end())  {
-                       out << "SCMS ";
-                     } else {
-                       out << "DCP ";
-                     }
-                     
-                     if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end())  {
-                       out << "PRE";
-                     }
-                     out << endl;
-                     
-                     if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end())  {
-                       out << "ISRC " << (*i)->cd_info["isrc"] << endl;
-                       
-                     }
-                     if ((*i)->name() != "") {
-                       out << "TITLE \"" << (*i)->name() << "\"" << endl;
-                     }       
-                     
-                     if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
-                       out << "PERFORMER \"" <<  (*i)->cd_info["performer"] << "\"" << endl;
-                     }
-                     
-                     if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
-                       out << "SONGWRITER \"" << (*i)->cd_info["string_composer"]  << "\"" << endl;
-                     }
-                       snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
-                       out << buf;
-                       frames_to_cd_frames_string (buf, last_track_end - spec.start_frame, session->frame_rate());
-                       out << buf << endl;
-                       indexnum++;
-                       last_track_end = (*i)->end();
-                   } 
-                   if ((tracknum > 0) && ((*i)->start() < last_track_end)) {
-                     /*this is an index and it lies within a track*/
-                     snprintf (buf, sizeof(buf), "INDEX %02d", indexnum);
-                     out << buf;
-                     frames_to_cd_frames_string (buf,(*i)->start() - spec.start_frame, session->frame_rate());
-                     out << buf << endl;
-                     indexnum++;
-                   }
+                       if ((*i)->start() >= last_track_end)
+                       {
+                               /* this is a track and it doesn't start inside another one*/
+                               
+                               tracknum++;
+                               indexnum = 0;
+
+                               snprintf (buf, sizeof(buf), "  TRACK %02d AUDIO", tracknum);
+                               out << buf << endl;
+
+                               out << "    FLAGS" ;
+                               if ((*i)->cd_info.find("scms") != (*i)->cd_info.end())  {
+                                       out << " SCMS";
+                               } else {
+                                       out << " DCP";
+                               }
+                               if ((*i)->cd_info.find("preemph") != (*i)->cd_info.end())  {
+                                       out << " PRE";
+                               }
+                               out << endl;
+                               
+                               if ((*i)->cd_info.find("isrc") != (*i)->cd_info.end())  {
+                                       out << "    ISRC " << (*i)->cd_info["isrc"] << endl;
+                               }
+
+                               if ((*i)->name() != "") {
+                                       out << "    TITLE \"" << (*i)->name() << "\"" << endl;
+                               }             
+                               
+                               if ((*i)->cd_info.find("performer") != (*i)->cd_info.end()) {
+                                       out << "    PERFORMER \"" <<  (*i)->cd_info["performer"] << "\"" << endl;
+                               }
+                               
+                               if ((*i)->cd_info.find("string_composer") != (*i)->cd_info.end()) {
+                                       out << "    SONGWRITER \"" << (*i)->cd_info["string_composer"]  << "\"" << endl;
+                               }
+
+                               /* only print "Index 00" if not at the same position as "Index 01" */
+                               if (last_track_end != (*i)->start()) {
+                                       frames_to_cd_frames_string (buf, last_track_end - spec.start_frame, session->frame_rate());
+                                       out << "    INDEX 00" << buf << endl;
+                               }
+
+                               indexnum++;
+
+                               if ((*i)->is_mark()) {
+                                       // need to find the next start to define the end
+                                       nexti = i;
+                                       ++nexti;
+                                       if (nexti != temp.end()) {
+                                               last_track_end = (*nexti)->start();
+                                       }
+                                       else {
+                                               last_track_end = spec.end_frame;
+                                       }
+                                       curr_range = 0;
+                               }
+                               else {
+                                       last_track_end = (*i)->end();
+                                       curr_range = (*i);
+                               }
+                       } 
+       
+                       if ((tracknum > 0) && ((*i)->start() < last_track_end)) {
+                               /*this is an index and it lies within a track*/
+                               snprintf (buf, sizeof(buf), "    INDEX %02d", indexnum);
+                               out << buf;
+                               frames_to_cd_frames_string (buf,(*i)->start() - spec.start_frame, session->frame_rate());
+                               out << buf << endl;
+                               indexnum++;
+                       }
                }
        }
        
@@ -872,26 +967,107 @@ ExportDialog::export_cue_file (Locations::LocationList& locations, const string&
 void
 ExportDialog::do_export_cd_markers (const string& path,const string& cuefile_type)
 {
-       if (cuefile_type == "TOC") {
+       if (cuefile_type == _("TOC")) {
                session->locations()->apply (*this, &ExportDialog::export_toc_file, path);      
        } else {
                session->locations()->apply (*this, &ExportDialog::export_cue_file, path);
        }
 }
 
+string
+ExportDialog::get_suffixed_filepath ()
+{
+       string filepath = file_entry.get_text();
+
+       if (wants_dir()) {
+               return filepath;
+       }
+
+       string::size_type dotpos;
+       
+       /* maybe add suffix */
+       
+       int file_format = sndfile_header_format_from_string (header_format_combo.get_active_text ());
+       
+       if ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV) {
+               if (filepath.find (".wav") != filepath.length() - 4) {
+                       if ((dotpos = filepath.rfind ('.')) != string::npos) {
+                               filepath = filepath.substr (0, dotpos);
+                       }
+                       filepath += ".wav";
+               }
+       } else if ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AIFF) {
+               if (filepath.find (".aiff") != filepath.length() - 5) {
+                       if ((dotpos = filepath.rfind ('.')) != string::npos) {
+                               filepath = filepath.substr (0, dotpos);
+                       }
+                       filepath += ".aiff";
+               }
+       } else if ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_CAF) {
+               if (filepath.find (".caf") != filepath.length() - 4) {
+                       if ((dotpos = filepath.rfind ('.')) != string::npos) {
+                               filepath = filepath.substr (0, dotpos);
+                       }
+                       filepath += ".caf";
+               }
+       } else if ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_W64) {
+               if (filepath.find (".w64") != filepath.length() - 4) {
+                       if ((dotpos = filepath.rfind ('.')) != string::npos) {
+                               filepath = filepath.substr (0, dotpos);
+                       }
+                       filepath += ".w64";
+               }
+       } else if ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_FLAC) {
+               if (filepath.find (".flac") != filepath.length() - 5) {
+                       if ((dotpos = filepath.rfind ('.')) != string::npos) {
+                               filepath = filepath.substr (0, dotpos);
+                       }
+                       filepath += ".flac";
+               }
+       } else if ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_OGG) {
+               if (filepath.find (".ogg") != filepath.length() - 4) {
+                       if ((dotpos = filepath.rfind ('.')) != string::npos) {
+                               filepath = filepath.substr (0, dotpos);
+                       }
+                       filepath += ".ogg";
+               }
+       } else if ((file_format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW) {
+               if (filepath.find (".raw") != filepath.length() - 4) {
+                       if ((dotpos = filepath.rfind ('.')) != string::npos) {
+                               filepath = filepath.substr (0, dotpos);
+                       }
+                       filepath += ".raw";
+               }
+       }
+       return filepath;
+}
 
 void
 ExportDialog::do_export ()
 {
-       string filepath = file_entry.get_text();
-       
+       if (!ARDOUR_UI::instance()->the_engine().connected()) {
+               MessageDialog msg (*this, 
+                                  _("Not connected to audioengine"),
+                                  true,
+                                  MESSAGE_ERROR,
+                                  BUTTONS_OK);
+               msg.set_secondary_text (_("Ardour cannot export audio when disconnected"));
+               msg.present ();
+               msg.run ();
+               return;
+       }
+
+       string filepath;
+
+       filepath = get_suffixed_filepath ();
+
        if(!is_filepath_valid(filepath)){
                return;
        }
 
-       if (export_cd_markers_allowed) {
+       if (!Profile->get_sae() && export_cd_markers_allowed) {
                if (cue_file_combo.get_active_text () != _("None")) {
-                       do_export_cd_markers (file_entry.get_text(), cue_file_combo.get_active_text ());
+                       do_export_cd_markers (filepath, cue_file_combo.get_active_text ());
                }
 
                if (cuefile_only_checkbox.get_active()) {
@@ -911,17 +1087,29 @@ ExportDialog::do_export ()
        progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
        cancel_label.set_text (_("Stop Export"));
 
+       session->pre_export ();
+
        export_audio_data();
        
        progress_connection.disconnect ();
        end_dialog ();
+
+       /* if not stopped early and not SAE, ask for money, maybe */
+
+       if (!spec.stop && !Profile->get_sae()) {
+
+               NagScreen* ns = NagScreen::maybe_nag (_("export"));
+               
+               if (ns) {
+                       ns->nag ();
+                       delete ns;
+               }
+       }
 }
        
-
 void
 ExportDialog::end_dialog ()
 {
-
        if (spec.running) {
                spec.stop = true;
 
@@ -934,7 +1122,7 @@ ExportDialog::end_dialog ()
                }
        }
 
-       session->engine().freewheel (false);
+       session->finalize_audio_export ();
 
        hide_all ();
 
@@ -950,21 +1138,18 @@ ExportDialog::start_export ()
        }
 
        /* If the filename hasn't been set before, use the
-          directory above the current session as a default
+          current session's export directory as a default
           location for the export.  
        */
        
        if (file_entry.get_text().length() == 0) {
-               string dir = session->path();
-               string::size_type last_slash;
-               
-               if ((last_slash = dir.find_last_of ('/')) != string::npos) {
-                       dir = dir.substr (0, last_slash+1);
-               }
+               Glib::ustring export_path = session->export_dir();
 
-               dir = dir + "export.wav";
+               if (!wants_dir()) {
+                       export_path = Glib::build_filename (export_path, "export.wav");
+               }
                
-               file_entry.set_text (dir);
+               file_entry.set_text (export_path);
        }
        
        progress_bar.set_fraction (0);
@@ -983,11 +1168,21 @@ ExportDialog::start_export ()
 void
 ExportDialog::header_chosen ()
 {
-       if (sndfile_header_format_from_string (header_format_combo.get_active_text ()) == SF_FORMAT_WAV) {
+        int fmt = sndfile_header_format_from_string (header_format_combo.get_active_text ());
+       
+       if ((fmt & SF_FORMAT_TYPEMASK) == SF_FORMAT_OGG) {
                endian_format_combo.set_sensitive (false);
-       } else {
-               endian_format_combo.set_sensitive (true);
+               bitdepth_format_combo.set_sensitive (false);     
+        } else {
+               if ((fmt & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV) {
+                      endian_format_combo.set_sensitive (false);
+               } else {
+                      endian_format_combo.set_sensitive (true);
+               }
+               bitdepth_format_combo.set_sensitive (true);     
        }
+
+       file_entry.set_text (get_suffixed_filepath());
 }
 
 void
@@ -1026,15 +1221,15 @@ ExportDialog::sample_rate_chosen ()
 
        if (sr_str == N_("22.05kHz")) {
                rate = 22050;
-       } else if (sr_str == N_("44.1kHz")) {
+       } else if (sr_str == _("44.1kHz")) {
                rate = 44100;
-       } else if (sr_str == N_("48kHz")) {
+       } else if (sr_str == _("48kHz")) {
                rate = 48000;
-       } else if (sr_str == N_("88.2kHz")) {
+       } else if (sr_str == _("88.2kHz")) {
                rate = 88200;
-       } else if (sr_str == N_("96kHz")) {
+       } else if (sr_str == _("96kHz")) {
                rate = 96000;
-       } else if (sr_str == N_("192kHz")) {
+       } else if (sr_str == _("192kHz")) {
                rate = 192000;
        } else {
                rate = session->frame_rate();
@@ -1170,7 +1365,7 @@ ExportDialog::initSpec(string &filepath)
 {
        spec.path = filepath;
        spec.progress = 0;
-       spec.running = true;
+       spec.running = false;
        spec.stop = false;
        spec.port_map.clear();
        
@@ -1183,42 +1378,56 @@ ExportDialog::initSpec(string &filepath)
        spec.format = 0;
 
        spec.format |= sndfile_header_format_from_string (header_format_combo.get_active_text ());
-       
-       if ((spec.format & SF_FORMAT_WAV) == 0) {
-               /* RIFF/WAV specifies endianess */
-               spec.format |= sndfile_endian_format_from_string (endian_format_combo.get_active_text ());
+
+       /* if they picked Ogg, give them Ogg/Vorbis */
+
+       if ((spec.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_OGG) {
+         spec.format |= SF_FORMAT_VORBIS;
        }
 
-       spec.format |= sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
+       if (!Profile->get_sae()) {
+         if (((spec.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_WAV) && ((spec.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_OGG)) {
+                       /* RIFF/WAV specifies endianess and O/V has no such concept */
+                       spec.format |= sndfile_endian_format_from_string (endian_format_combo.get_active_text ());
+               }
+       }
+
+       if ((spec.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_OGG) {
+         spec.format |= sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
+       }
 
        string sr_str = sample_rate_combo.get_active_text();
        if (sr_str == N_("22.05kHz")) {
                spec.sample_rate = 22050;
-       } else if (sr_str == N_("44.1kHz")) {
+       } else if (sr_str == _("44.1kHz")) {
                spec.sample_rate = 44100;
-       } else if (sr_str == N_("48kHz")) {
+       } else if (sr_str == _("48kHz")) {
                spec.sample_rate = 48000;
-       } else if (sr_str == N_("88.2kHz")) {
+       } else if (sr_str == _("88.2kHz")) {
                spec.sample_rate = 88200;
-       } else if (sr_str == N_("96kHz")) {
+       } else if (sr_str == _("96kHz")) {
                spec.sample_rate = 96000;
-       } else if (sr_str == N_("192kHz")) {
+       } else if (sr_str == _("192kHz")) {
                spec.sample_rate = 192000;
        } else {
                spec.sample_rate = session->frame_rate();
        }
        
-       string src_str = src_quality_combo.get_active_text();
-       if (src_str == _("fastest")) {
-               spec.src_quality = SRC_ZERO_ORDER_HOLD;
-       } else if (src_str == _("linear")) {
-               spec.src_quality = SRC_LINEAR;
-       } else if (src_str == _("better")) {
-               spec.src_quality = SRC_SINC_FASTEST;
-       } else if (src_str == _("intermediate")) {
-               spec.src_quality = SRC_SINC_MEDIUM_QUALITY;
-       } else {
+       if (Profile->get_sae()) {
                spec.src_quality = SRC_SINC_BEST_QUALITY;
+       } else {
+               string src_str = src_quality_combo.get_active_text();
+               if (src_str == _("fastest")) {
+                       spec.src_quality = SRC_ZERO_ORDER_HOLD;
+               } else if (src_str == _("linear")) {
+                       spec.src_quality = SRC_LINEAR;
+               } else if (src_str == _("better")) {
+                       spec.src_quality = SRC_SINC_FASTEST;
+               } else if (src_str == _("intermediate")) {
+                       spec.src_quality = SRC_SINC_MEDIUM_QUALITY;
+               } else {
+                       spec.src_quality = SRC_SINC_BEST_QUALITY;
+               }
        }
 
        string dither_str = dither_type_combo.get_active_text();
@@ -1307,7 +1516,7 @@ ExportDialog::window_closed (GdkEventAny *ignored)
 void
 ExportDialog::browse ()
 {
-       FileChooserDialog dialog("Export to file", FILE_CHOOSER_ACTION_SAVE);
+       FileChooserDialog dialog("Export to file", browse_action());
        dialog.set_transient_for(*this);
        dialog.set_filename (file_entry.get_text());