Tidy.
[ardour.git] / gtk2_ardour / export_dialog.cc
index cbaee3d6d2bc766843c2c292378a9915b09e41fb..ef99bf43bf8059330c507686e5c70ac5c3274c9b 100644 (file)
@@ -24,7 +24,6 @@
 #include <fstream>
 
 #include <samplerate.h>
-
 #include <pbd/convert.h>
 #include <pbd/xml++.h>
 
@@ -37,9 +36,9 @@
 #include <ardour/audio_track.h>
 #include <ardour/audioregion.h>
 #include <ardour/audioengine.h>
-#include <ardour/audiofilesource.h>
 #include <ardour/gdither.h>
 #include <ardour/utils.h>
+#include <ardour/profile.h>
 
 #include "export_dialog.h"
 #include "ardour_ui.h"
@@ -57,8 +56,6 @@ using namespace sigc;
 using namespace Gtk;
 using namespace Gtkmm2ext;
 
-using PBD::internationalize;
-
 static const gchar *sample_rates[] = {
        N_("22.05kHz"),
        N_("44.1kHz"),
@@ -87,8 +84,8 @@ static const gchar *dither_types[] = {
 };
 
 static const gchar* channel_strings[] = {
-       N_("Stereo"), 
-       N_("Mono"), 
+       N_("stereo"), 
+       N_("mono"), 
        0
 };
 
@@ -113,7 +110,7 @@ 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_chooser (FILE_CHOOSER_ACTION_SAVE),
+         file_browse_button (_("Browse")),
          track_selector_button (_("Specific tracks ..."))
 {
        guint32 n;
@@ -124,7 +121,6 @@ ExportDialog::ExportDialog(PublicEditor& e)
        track_and_master_selection_allowed = true;
        channel_count_selection_allowed = true;
        export_cd_markers_allowed = true;
-       set_resizable (false);  
 
        WindowTitle title(Glib::get_application_name());
        title += _("Export");
@@ -133,9 +129,11 @@ ExportDialog::ExportDialog(PublicEditor& e)
        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");
+
        master_list = ListStore::create (exp_cols);
        master_selector.set_model (master_list);
 
@@ -145,7 +143,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);
@@ -176,11 +174,11 @@ ExportDialog::ExportDialog(PublicEditor& e)
        track_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
        master_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
 
-       get_vbox()->pack_start (file_frame, PACK_EXPAND_WIDGET);
+       get_vbox()->pack_start (file_frame, false, false);
 
        hpacker.set_spacing (5);
        hpacker.set_border_width (5);
-       hpacker.pack_start (format_frame, PACK_SHRINK );
+       hpacker.pack_start (format_frame, false, false);
 
        master_scroll.add (master_selector);
        track_scroll.add (track_selector);
@@ -195,36 +193,19 @@ ExportDialog::ExportDialog(PublicEditor& e)
 
        hpacker.pack_start (track_vpacker);
 
-       get_vbox()->pack_start (hpacker, PACK_SHRINK);
+       get_vbox()->pack_start (hpacker);
        
        track_selector_button.set_name ("EditorGTKButton");
        track_selector_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::track_selector_button_click));
 
-       Gtk::FileFilter filter_wav;
-       filter_wav.set_name("Wav files");
-       filter_wav.add_mime_type("audio/wav");
-       file_chooser.add_filter(filter_wav);
-       
-       Gtk::FileFilter filter_aiff;
-       filter_aiff.set_name("Aiff files");
-       filter_aiff.add_mime_type("audio/aiff");
-       filter_aiff.add_pattern("*.aif");
-       filter_aiff.add_pattern("*.aiff");
-       file_chooser.add_filter(filter_aiff);
-       
-       Gtk::FileFilter filter_any;
-       filter_any.set_name("All files");
-       filter_any.add_pattern("*");
-       file_chooser.add_filter(filter_any);
-       file_chooser.set_no_show_all();
+       get_vbox()->pack_start (progress_bar, false, false);
 
-       get_vbox()->pack_start (progress_bar, false, false, 5);
-       progress_bar.set_no_show_all();
-       progress_bar.hide();
+       Gtkmm2ext::set_size_request_to_display_given_text (file_entry, X_("Kg/quite/a/reasonable/size/for/files/i/think"), 5, 8);
 
        file_hbox.set_spacing (5);
        file_hbox.set_border_width (5);
-       file_hbox.pack_start (file_chooser, PACK_EXPAND_WIDGET);
+       file_hbox.pack_start (file_entry, true, true);
+       file_hbox.pack_start (file_browse_button, false, false);
 
        file_frame.add (file_hbox);
        file_frame.set_border_width (5);
@@ -234,28 +215,28 @@ ExportDialog::ExportDialog(PublicEditor& e)
           takes a reference. 
        */
 
-       vector<string> pop_strings = I18N(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 = I18N(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 = I18N(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 = I18N(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 = I18N((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 = I18N((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 = I18N((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 = I18N(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());
 
@@ -333,35 +314,59 @@ ExportDialog::ExportDialog(PublicEditor& e)
 
        cuefile_only_checkbox.set_name ("ExportCheckbox");
 
-       format_table.set_homogeneous (true);
+       format_table.set_homogeneous (false);
        format_table.set_border_width (5);
        format_table.set_col_spacings (5);
        format_table.set_row_spacings (5);
 
-       format_table.attach (channel_count_label, 0, 1, 0, 1, FILL, FILL);
-       format_table.attach (channel_count_combo, 1, 2, 0, 1, FILL, FILL);
+       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, FILL, FILL);
-       format_table.attach (header_format_combo, 1, 2, 1, 2, FILL, FILL);
+       format_table.attach (header_format_label, 0, 1, row, row+1);
+       format_table.attach (header_format_combo, 1, 2, row, row+1);
 
-       format_table.attach (bitdepth_format_label, 0, 1, 2, 3, FILL, FILL);
-       format_table.attach (bitdepth_format_combo, 1, 2, 2, 3, FILL, FILL);
+       row++;
 
-       format_table.attach (endian_format_label, 0, 1, 3, 4, FILL, FILL);
-       format_table.attach (endian_format_combo, 1, 2, 3, 4, FILL, FILL);
+       format_table.attach (bitdepth_format_label, 0, 1, row, row+1);
+       format_table.attach (bitdepth_format_combo, 1, 2, row, row+1);
 
-       format_table.attach (sample_rate_label, 0, 1, 4, 5, FILL, FILL);
-       format_table.attach (sample_rate_combo, 1, 2, 4, 5, FILL, FILL);
+       row++;
 
-       format_table.attach (src_quality_label, 0, 1, 5, 6, FILL, FILL);
-       format_table.attach (src_quality_combo, 1, 2, 5, 6, FILL, FILL);
+       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 (dither_type_label, 0, 1, 6, 7, FILL, FILL);
-       format_table.attach (dither_type_combo, 1, 2, 6, 7, FILL, FILL);
+       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 (cue_file_label, 0, 1, 7, 8, FILL, FILL);
-       format_table.attach (cue_file_combo, 1, 2, 7, 8, FILL, FILL);
-       format_table.attach (cuefile_only_checkbox, 0, 2, 8, 9, FILL, FILL);
+       row++;
+
+       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 (dither_type_label, 0, 1, row, row+1);
+       format_table.attach (dither_type_combo, 1, 2, row, row+1);
+
+       row++;
+
+       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");
 
        signal_delete_event().connect (mem_fun(*this, &ExportDialog::window_closed));
 
@@ -369,14 +374,15 @@ ExportDialog::ExportDialog(PublicEditor& e)
        cancel_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::end_dialog));
        ok_button = add_button (_("Export"), RESPONSE_ACCEPT);
        ok_button->signal_clicked().connect (mem_fun(*this, &ExportDialog::do_export));
+       
+       file_browse_button.set_name ("EditorGTKButton");
+       file_browse_button.signal_clicked().connect (mem_fun(*this, &ExportDialog::browse));
+
        channel_count_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::channels_chosen));
        bitdepth_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::bitdepth_chosen));
        header_format_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::header_chosen));
        sample_rate_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::sample_rate_chosen));
        cue_file_combo.signal_changed().connect (mem_fun(*this, &ExportDialog::cue_file_type_chosen));
-
-       file_chooser.signal_update_preview().connect (mem_fun(*this, &ExportDialog::file_chooser_selection_changed));
-
 }
 
 ExportDialog::~ExportDialog()
@@ -387,18 +393,24 @@ void
 ExportDialog::do_not_allow_track_and_master_selection()
 {
        track_and_master_selection_allowed = false;
+       track_vpacker.set_no_show_all();
 }
 
 void
 ExportDialog::do_not_allow_channel_count_selection()
 {
        channel_count_selection_allowed = false;
+       channel_count_combo.set_no_show_all();
+       channel_count_label.set_no_show_all();
 }
 
 void
 ExportDialog::do_not_allow_export_cd_markers()
 {
        export_cd_markers_allowed = false;
+       cue_file_label.set_no_show_all();
+       cue_file_combo.set_no_show_all();
+       cuefile_only_checkbox.set_no_show_all();
 }
 
 void
@@ -441,7 +453,7 @@ ExportDialog::set_state()
 {
        XMLNode* node = session->instant_xml(X_("ExportDialog"));
        XMLProperty* prop;
-       bool fc_location_requested = false;
+
        if (node) {
 
                if ((prop = node->property (X_("sample_rate"))) != 0) {
@@ -466,28 +478,13 @@ ExportDialog::set_state()
                        endian_format_combo.set_active_text(prop->value());
                }
                if ((prop = node->property (X_("filename"))) != 0) {
-                       file_chooser.set_filename(prop->value());
-                       fc_location_requested = true;
-                       file_chooser.set_current_folder(Glib::path_get_basename(prop->value()));
+                       file_entry.set_text(prop->value());
                }
-                 
                if ((prop = node->property (X_("cue_file_type"))) != 0) {
                        cue_file_combo.set_active_text(prop->value());
                }
        }
 
-       if (!fc_location_requested) {
-
-               /*
-                 If the filename hasn't been set before, use the
-                 current session's export directory as a default
-                 location for the export.  
-               */
-
-               file_chooser.set_current_folder (session->session_directory().export_path().to_string());
-               file_chooser.set_current_name (_("export.wav"));
-       }
-
        header_chosen ();
        bitdepth_chosen();
        channels_chosen();
@@ -511,14 +508,14 @@ ExportDialog::set_state()
                if (!master) {
                        
                        /* default is to use all */
-                       if (channel_count_combo.get_active_text() == _("Mono")) {
+                       if (channel_count_combo.get_active_text() == _("mono")) {
                                nchns = 1;
                        } else {
                                nchns = 2;
                        }
 
                        TreeModel::Children rows = master_selector.get_model()->children();
-                       for (uint32_t r = 0; r < session->master_out()->n_outputs().n_audio(); ++r) {
+                       for (uint32_t r = 0; r < session->master_out()->n_outputs().n_total(); ++r) {
                                if (nchns == 2) {
                                        if (r % 2) {
                                                rows[r][exp_cols.right] = true;
@@ -587,7 +584,7 @@ ExportDialog::save_state()
        node->add_property(X_("header_format"), header_format_combo.get_active_text());
        node->add_property(X_("bitdepth_format"), bitdepth_format_combo.get_active_text());
        node->add_property(X_("endian_format"), endian_format_combo.get_active_text());
-       node->add_property(X_("filename"), file_chooser.get_filename());
+       node->add_property(X_("filename"), file_entry.get_text());
        node->add_property(X_("cue_file_type"), cue_file_combo.get_active_text());
 
        XMLNode* tracks = new XMLNode(X_("Tracks"));
@@ -651,10 +648,9 @@ ExportDialog::export_toc_file (Locations::LocationList& locations, const string&
                return;
        }
        
-    string filepath = path + ".toc";
+       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];
 
        if (!out) {
@@ -669,102 +665,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 \"" << 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;
+                                       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("string_composer") != (*i)->cd_info.end()) {
-                         out  << "     COMPOSER \"" << (*i)->cd_info["string_composer"] << "\"" << 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;
                        }
-
-                       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 \"" << 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;
-                     }
                }
        }
        
@@ -809,7 +813,7 @@ ExportDialog::export_cue_file (Locations::LocationList& locations, const string&
                  out << "FILE " << path  << ' ' << (header_format_combo.get_active_text()) << endl;
        }
 
-       if (numtracks == 0) {
+       if (false && numtracks == 0) {
                    /* the user has supplied no track markers.
                       the entire export is treated as one track. 
                    */
@@ -840,58 +844,78 @@ ExportDialog::export_cue_file (Locations::LocationList& locations, const string&
        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;
+                               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++;
+
+                               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++;
+                       }
                }
        }
        
@@ -911,15 +935,27 @@ ExportDialog::do_export_cd_markers (const string& path,const string& cuefile_typ
 void
 ExportDialog::do_export ()
 {
-       string filepath = file_chooser.get_filename();
-       
+       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;
+       }
+               
        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_chooser.get_filename(), cue_file_combo.get_active_text ());
+                       do_export_cd_markers (file_entry.get_text(), cue_file_combo.get_active_text ());
                }
 
                if (cuefile_only_checkbox.get_active()) {
@@ -936,15 +972,13 @@ ExportDialog::do_export ()
        // read user input into spec
        initSpec(filepath);
        
-       progress_bar.show();
        progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
        cancel_label.set_text (_("Stop Export"));
 
-       export_audio_data();
-       
+       session->pre_export ();
+       export_data();
+
        progress_connection.disconnect ();
-       session->engine().freewheel (false);
-       progress_bar.hide();
        end_dialog ();
 }
        
@@ -963,9 +997,9 @@ ExportDialog::end_dialog ()
                }
        }
 
-       hide ();
+       session->finalize_export ();
 
-       session->finalize_audio_export ();
+       hide_all ();
 
        set_modal (false);
        ok_button->set_sensitive(true);
@@ -993,39 +1027,11 @@ ExportDialog::start_export ()
                
                file_entry.set_text (export_file_path.to_string());
        }
-
+       
        progress_bar.set_fraction (0);
-       progress_bar.hide();
-       progress_bar.set_no_show_all();
        cancel_label.set_text (_("Cancel"));
 
-       show_all();
-
-       if (track_and_master_selection_allowed) {
-               track_vpacker.show();
-       } else {
-               track_vpacker.hide();
-       }
-
-       file_chooser.show();
-
-       if (channel_count_selection_allowed) {
-               channel_count_combo.show();
-               channel_count_label.show();
-       } else {
-               channel_count_combo.hide();
-               channel_count_label.hide();
-       }
-
-       if (export_cd_markers_allowed) {
-               cue_file_label.show();
-               cue_file_combo.show();
-               cuefile_only_checkbox.show();
-       } else {
-               cue_file_label.hide();
-               cue_file_combo.hide();
-               cuefile_only_checkbox.hide();
-       }
+       show_all ();
 
        if (session->master_out()) {
                track_scroll.hide ();
@@ -1033,21 +1039,15 @@ ExportDialog::start_export ()
                master_scroll.hide ();
                track_selector_button.hide ();
        }
-
-       track_and_master_selection_allowed = true;
-       channel_count_selection_allowed =  true;
-       export_cd_markers_allowed = true;
 }
 
 void
 ExportDialog::header_chosen ()
 {
        if (sndfile_header_format_from_string (header_format_combo.get_active_text ()) == SF_FORMAT_WAV) {
-               endian_format_combo.set_active_text (N_("Little-endian (Intel)"));
                endian_format_combo.set_sensitive (false);
        } else {
                endian_format_combo.set_sensitive (true);
-               endian_format_combo.set_active_text (N_("Big-endian (Mac)"));
        }
 }
 
@@ -1079,65 +1079,6 @@ ExportDialog::cue_file_type_chosen ()
        }
 }
 
-void
-ExportDialog::file_chooser_selection_changed ()
-{
-
-  /*
-    if the user selects an existing file from the 'browse for other folders' tab,
-    change the format settings to match the file.
-  */
-       if (file_chooser.get_filename().length() == 0) {
-               return;
-       }
-       if (Glib::file_test(file_chooser.get_preview_filename(),Glib::FILE_TEST_IS_DIR)){
-               file_chooser.set_current_name (_(""));
-               return;
-       }
-       if (!Glib::file_test(file_chooser.get_preview_filename(),Glib::FILE_TEST_EXISTS)) {
-               return;
-       }
-
-       SoundFileInfo finfo;
-       string error_msg, format_str;
-       
-       if (!AudioFileSource::get_soundfile_info (file_chooser.get_preview_filename(), finfo, error_msg)) {
-               error << string_compose(_("Export: cannot open file \"%1\"."), error_msg ) << endmsg;
-               return;
-       }
-
-       if (finfo.samplerate == 22050) {
-               sample_rate_combo.set_active_text (N_("22.05kHz"));
-       } else if (finfo.samplerate == 44100) {
-               sample_rate_combo.set_active_text (N_("44.1kHz"));
-       } else if (finfo.samplerate == 48000) {
-               sample_rate_combo.set_active_text (N_("48kHz"));
-       } else if (finfo.samplerate == 88200) {
-               sample_rate_combo.set_active_text (N_("88.2kHz"));
-       } else if (finfo.samplerate == 96000) {
-               sample_rate_combo.set_active_text (N_("96kHz"));
-       } else if (finfo.samplerate == 192000) {
-               sample_rate_combo.set_active_text (N_("192kHz"));
-       } 
-
-       if (finfo.channels == 1) {
-               channel_count_combo.set_active_text(N_("Mono"));
-       } else {
-               channel_count_combo.set_active_text(N_("Stereo"));
-       }
-
-       string::size_type pos;
-
-       pos = finfo.format_name.find_first_of (" ");
-       format_str = finfo.format_name.substr(pos + 1, 255);
-       pos = format_str.find_first_of (" ");
-       header_format_combo.set_active_text(format_str.substr(0, pos));
-
-       format_str = finfo.format_name;
-       pos = format_str.find_first_of (",");
-       bitdepth_format_combo.set_active_text(format_str.substr(pos + 2, 255));
-}
-
 void
 ExportDialog::sample_rate_chosen ()
 {
@@ -1172,7 +1113,7 @@ ExportDialog::channels_chosen ()
 {
        bool mono;
 
-       mono = (channel_count_combo.get_active_text() == _("Mono"));
+       mono = (channel_count_combo.get_active_text() == _("mono"));
 
        if (mono) {
                track_selector.get_column(2)->set_visible(false);
@@ -1212,9 +1153,9 @@ ExportDialog::fill_lists ()
                        continue;
                }
 
-               for (uint32_t i=0; i < route->n_outputs().n_audio(); ++i) {
+               for (uint32_t i=0; i < route->n_outputs().n_total(); ++i) {
                        string name;
-                       if (route->n_outputs().n_audio() == 1) {
+                       if (route->n_outputs().n_total() == 1) {
                                name = route->name();
                        } else {
                                name = string_compose("%1: out-%2", route->name(), i+1);
@@ -1264,7 +1205,7 @@ ExportDialog::is_filepath_valid(string &filepath)
                        return false;
                }
                else {
-                       string txt = _("File ") + filepath + _(" already exists, do you want to overwrite it?");
+                       string txt = _("File already exists, do you want to overwrite it?");
                        MessageDialog msg (*this, txt, false, MESSAGE_QUESTION, BUTTONS_YES_NO, true);
                        if ((ResponseType) msg.run() == Gtk::RESPONSE_NO) {
                                return false;
@@ -1290,11 +1231,11 @@ ExportDialog::initSpec(string &filepath)
 {
        spec.path = filepath;
        spec.progress = 0;
-       spec.running = true;
+       spec.running = false;
        spec.stop = false;
        spec.port_map.clear();
        
-       if (channel_count_combo.get_active_text() == _("Mono")) {
+       if (channel_count_combo.get_active_text() == _("mono")) {
                spec.channels = 1;
        } else {
                spec.channels = 2;
@@ -1303,10 +1244,12 @@ 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 (!Profile->get_sae()) {
+               if ((spec.format & SF_FORMAT_WAV) == 0) {
+                       /* RIFF/WAV specifies endianess */
+                       spec.format |= sndfile_endian_format_from_string (endian_format_combo.get_active_text ());
+               }
        }
 
        spec.format |= sndfile_bitdepth_format_from_string (bitdepth_format_combo.get_active_text ());
@@ -1328,17 +1271,21 @@ ExportDialog::initSpec(string &filepath)
                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();
@@ -1424,6 +1371,27 @@ ExportDialog::window_closed (GdkEventAny *ignored)
        return TRUE;
 }
 
+void
+ExportDialog::browse ()
+{
+       FileChooserDialog dialog("Export to file", browse_action());
+       dialog.set_transient_for(*this);
+       dialog.set_filename (file_entry.get_text());
+
+       dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+       dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
+  
+       int result = dialog.run();
+
+       if (result == Gtk::RESPONSE_OK) {
+               string filename = dialog.get_filename();
+       
+               if (filename.length()) {
+                       file_entry.set_text (filename);
+               }
+       }
+}
+
 void
 ExportDialog::track_selector_button_click ()
 {