X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_export_audio.cc;h=8159b784bc5e3f79dd1ba640b0d2df4eeaae449f;hb=0883f02de92478800ad232f10d388219e2817ed7;hp=9521f6a0c676be686a814236e35b1d2fec3c5163;hpb=e0d0735fa2c2543c6995e9128dbd16c799f4ec8f;p=ardour.git diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index 9521f6a0c6..8159b784bc 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -25,14 +25,12 @@ #include -#include "gtkmm2ext/choice.h" +#include "pbd/gstdio_compat.h" #include "pbd/pthread_utils.h" -#include "ardour/audio_diskstream.h" #include "ardour/audio_track.h" #include "ardour/audiofilesource.h" -#include "ardour/audiofilesource.h" #include "ardour/audioplaylist.h" #include "ardour/audioregion.h" #include "ardour/chan_count.h" @@ -51,8 +49,9 @@ #include "public_editor.h" #include "selection.h" #include "time_axis_view.h" +#include "utils.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace ARDOUR; @@ -62,7 +61,7 @@ using namespace Gtk; void Editor::export_audio () { - ExportDialog dialog (*this, _("Export"), X_("ExportProfile")); + ExportDialog dialog (*this, _("Export"), ExportProfileManager::RegularExport); dialog.set_session (_session); dialog.run(); } @@ -86,11 +85,11 @@ Editor::export_selection () void Editor::export_range () { - Marker* marker; + ArdourMarker* marker; - if ((marker = reinterpret_cast (marker_menu_item->get_data ("marker"))) == 0) { + if ((marker = reinterpret_cast (marker_menu_item->get_data ("marker"))) == 0) { fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg; - /*NOTREACHED*/ + abort(); /*NOTREACHED*/ } Location* l; @@ -103,6 +102,30 @@ Editor::export_range () } } +bool +Editor::process_midi_export_dialog (MidiExportDialog& dialog, boost::shared_ptr 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 () @@ -114,30 +137,31 @@ Editor::export_region () boost::shared_ptr r = selection->regions.front()->region(); boost::shared_ptr audio_region = boost::dynamic_pointer_cast(r); boost::shared_ptr midi_region = boost::dynamic_pointer_cast(r); - + if (audio_region) { - + RouteTimeAxisView & rtv (dynamic_cast (selection->regions.front()->get_time_axis_view())); AudioTrack & track (dynamic_cast (*rtv.route())); - + ExportRegionDialog dialog (*this, *(audio_region.get()), track); dialog.set_session (_session); dialog.run (); - + } else if (midi_region) { MidiExportDialog dialog (*this, midi_region); dialog.set_session (_session); - int ret = dialog.run (); - switch (ret) { - case Gtk::RESPONSE_ACCEPT: - break; - default: - return; - } - string path = dialog.get_path (); - (void) midi_region->clone (path); + bool finished = false; + while (!finished) { + switch (dialog.run ()) { + case Gtk::RESPONSE_ACCEPT: + finished = process_midi_export_dialog (dialog, midi_region); + break; + default: + return; + } + } } } @@ -189,17 +213,17 @@ bool Editor::write_region (string path, boost::shared_ptr region) { boost::shared_ptr 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 > sources; uint32_t nchans; - const string sound_directory = _session->session_directory().sound_path().to_string(); + const string sound_directory = _session->session_directory().sound_path(); nchans = region->n_channels(); @@ -241,8 +265,8 @@ Editor::write_region (string path, boost::shared_ptr region) try { fs = boost::dynamic_pointer_cast ( SourceFactory::createWritable (DataType::AUDIO, *_session, - path, string(), true, - false, _session->frame_rate())); + path, true, + false, _session->sample_rate())); } catch (failed_constructor& err) { @@ -261,7 +285,7 @@ Editor::write_region (string path, boost::shared_ptr region) pos = region->position(); while (to_read) { - framepos_t this_time; + samplepos_t this_time; this_time = min (to_read, chunk_size); @@ -339,17 +363,17 @@ bool Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list& range) { boost::shared_ptr 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; vector > sources; - const string sound_directory = _session->session_directory().sound_path().to_string(); + const string sound_directory = _session->session_directory().sound_path(); uint32_t channels = count.n_audio(); @@ -380,8 +404,8 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list try { fs = boost::dynamic_pointer_cast ( SourceFactory::createWritable (DataType::AUDIO, *_session, - path, string(), true, - false, _session->frame_rate())); + path, true, + false, _session->sample_rate())); } catch (failed_constructor& err) { @@ -399,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); @@ -431,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) {