Vorbis Quality Config GUI
[ardour.git] / gtk2_ardour / editor_export_audio.cc
index c886885dd23849fd6fa5652620bd0e6316748c69..8159b784bc5e3f79dd1ba640b0d2df4eeaae449f 100644 (file)
@@ -27,8 +27,6 @@
 
 #include "pbd/gstdio_compat.h"
 
-#include "gtkmm2ext/choice.h"
-
 #include "pbd/pthread_utils.h"
 
 #include "ardour/audio_track.h"
@@ -53,7 +51,7 @@
 #include "time_axis_view.h"
 #include "utils.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -104,6 +102,30 @@ Editor::export_range ()
        }
 }
 
+bool
+Editor::process_midi_export_dialog (MidiExportDialog& dialog, boost::shared_ptr<MidiRegion> midi_region)
+{
+       string path = dialog.get_path ();
+
+       if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
+               bool overwrite = ARDOUR_UI_UTILS::overwrite_file_dialog (dialog,
+                                                                        _("Confirm MIDI File Overwrite"),
+                                                                        _("A file with the same name already exists. Do you want to overwrite it?"));
+
+               if (!overwrite) {
+                       return false;
+               }
+
+               /* force ::g_unlink because the backend code will
+                  go wrong if it tries to open an existing
+                  file for writing.
+               */
+               ::g_unlink (path.c_str());
+       }
+
+       return midi_region->do_export (path);
+}
+
 /** Export the first selected region */
 void
 Editor::export_region ()
@@ -129,34 +151,17 @@ Editor::export_region ()
 
                MidiExportDialog dialog (*this, midi_region);
                dialog.set_session (_session);
-               int ret = dialog.run ();
-               switch (ret) {
-               case Gtk::RESPONSE_ACCEPT:
-                       break;
-               default:
-                       return;
-               }
-
-               dialog.hide ();
-
-               string path = dialog.get_path ();
 
-               if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
-                       bool overwrite = ARDOUR_UI_UTILS::overwrite_file_dialog (_("Confirm MIDI File Overwrite"),
-                                                                                _("A file with the same name already exists. Do you want to overwrite it?"));
-
-                       if (!overwrite) {
+               bool finished = false;
+               while (!finished) {
+                       switch (dialog.run ()) {
+                       case Gtk::RESPONSE_ACCEPT:
+                               finished = process_midi_export_dialog (dialog, midi_region);
+                               break;
+                       default:
                                return;
                        }
-
-                       /* force ::g_unlink because the backend code will
-                          go wrong if it tries to open an existing
-                          file for writing.
-                       */
-                       ::g_unlink (path.c_str());
                }
-
-               (void) midi_region->clone (path);
        }
 }
 
@@ -208,11 +213,11 @@ bool
 Editor::write_region (string path, boost::shared_ptr<AudioRegion> region)
 {
        boost::shared_ptr<AudioFileSource> fs;
-       const framepos_t chunk_size = 4096;
-       framepos_t to_read;
+       const samplepos_t chunk_size = 4096;
+       samplepos_t to_read;
        Sample buf[chunk_size];
        gain_t gain_buffer[chunk_size];
-       framepos_t pos;
+       samplepos_t pos;
        char s[PATH_MAX+1];
        uint32_t cnt;
        vector<boost::shared_ptr<AudioFileSource> > sources;
@@ -261,7 +266,7 @@ Editor::write_region (string path, boost::shared_ptr<AudioRegion> region)
                                fs = boost::dynamic_pointer_cast<AudioFileSource> (
                                        SourceFactory::createWritable (DataType::AUDIO, *_session,
                                                                       path, true,
-                                                                      false, _session->frame_rate()));
+                                                                      false, _session->sample_rate()));
                        }
 
                        catch (failed_constructor& err) {
@@ -280,7 +285,7 @@ Editor::write_region (string path, boost::shared_ptr<AudioRegion> region)
        pos = region->position();
 
        while (to_read) {
-               framepos_t this_time;
+               samplepos_t this_time;
 
                this_time = min (to_read, chunk_size);
 
@@ -358,11 +363,11 @@ bool
 Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list<AudioRange>& range)
 {
        boost::shared_ptr<AudioFileSource> fs;
-       const framepos_t chunk_size = 4096;
-       framepos_t nframes;
+       const samplepos_t chunk_size = 4096;
+       samplepos_t nframes;
        Sample buf[chunk_size];
        gain_t gain_buffer[chunk_size];
-       framepos_t pos;
+       samplepos_t pos;
        char s[PATH_MAX+1];
        uint32_t cnt;
        string path;
@@ -400,7 +405,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list
                        fs = boost::dynamic_pointer_cast<AudioFileSource> (
                                SourceFactory::createWritable (DataType::AUDIO, *_session,
                                                               path, true,
-                                                              false, _session->frame_rate()));
+                                                              false, _session->sample_rate()));
                }
 
                catch (failed_constructor& err) {
@@ -418,7 +423,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list
                pos = (*i).start;
 
                while (nframes) {
-                       framepos_t this_time;
+                       samplepos_t this_time;
 
                        this_time = min (nframes, chunk_size);
 
@@ -450,7 +455,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list
 
                        while (nframes) {
 
-                               framepos_t this_time = min (nframes, chunk_size);
+                               samplepos_t this_time = min (nframes, chunk_size);
                                memset (buf, 0, sizeof (Sample) * this_time);
 
                                for (uint32_t n=0; n < channels; ++n) {