use new method in MidiPatchManager to use MIDNAM data when setting a MidiTimeAxisView
[ardour.git] / gtk2_ardour / editor_export_audio.cc
index e40030d671d5a7fe6a0b7b65df792a7dba6b0511..ef55394253fd7b8c24c6cd5a991f71529b807054 100644 (file)
@@ -1,21 +1,27 @@
 /*
-    Copyright (C) 2001 Paul Davis
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
+ * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
+ * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
+ * Copyright (C) 2007-2010 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2007-2017 Tim Mayberry <mojofunk@gmail.com>
+ * Copyright (C) 2008-2012 Sakari Bergen <sakari.bergen@beatwaves.net>
+ * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2015 AndrĂ© Nusser <andre.nusser@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 /* Note: public Editor methods are documented in public_editor.h */
 
@@ -25,9 +31,7 @@
 
 #include <gtkmm/messagedialog.h>
 
-#include <glib/gstdio.h>
-
-#include "gtkmm2ext/choice.h"
+#include "pbd/gstdio_compat.h"
 
 #include "pbd/pthread_utils.h"
 
@@ -51,8 +55,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;
@@ -86,11 +91,11 @@ Editor::export_selection ()
 void
 Editor::export_range ()
 {
-       Marker* marker;
+       ArdourMarker* marker;
 
-       if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
+       if ((marker = reinterpret_cast<ArdourMarker *> (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 +108,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 ()
@@ -114,65 +143,31 @@ Editor::export_region ()
        boost::shared_ptr<Region> r = selection->regions.front()->region();
        boost::shared_ptr<AudioRegion> audio_region = boost::dynamic_pointer_cast<AudioRegion>(r);
        boost::shared_ptr<MidiRegion> midi_region = boost::dynamic_pointer_cast<MidiRegion>(r);
-       
+
        if (audio_region) {
-               
+
                RouteTimeAxisView & rtv (dynamic_cast<RouteTimeAxisView &> (selection->regions.front()->get_time_axis_view()));
                AudioTrack & track (dynamic_cast<AudioTrack &> (*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;
-               }
-
-               dialog.hide ();
 
-               string path = dialog.get_path ();
-
-               if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
-
-                       MessageDialog checker (_("File Exists!"),
-                                              true,
-                                              Gtk::MESSAGE_WARNING,
-                                              Gtk::BUTTONS_NONE);
-                       
-                       checker.set_title (_("File Exists!"));
-
-                       checker.add_button (Stock::CANCEL, RESPONSE_CANCEL);
-                       checker.add_button (_("Overwrite Existing File"), RESPONSE_ACCEPT);
-                       checker.set_default_response (RESPONSE_CANCEL);
-                       
-                       checker.set_wmclass (X_("midi_export_file_exists"), PROGRAM_NAME);
-                       checker.set_position (Gtk::WIN_POS_MOUSE);
-
-                       ret = checker.run ();
-
-                       switch (ret) {
+               bool finished = false;
+               while (!finished) {
+                       switch (dialog.run ()) {
                        case Gtk::RESPONSE_ACCEPT:
-                               /* 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());
+                               finished = process_midi_export_dialog (dialog, midi_region);
                                break;
                        default:
                                return;
                        }
-                       
                }
-
-               (void) midi_region->clone (path);
        }
 }
 
@@ -224,11 +219,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;
@@ -277,7 +272,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) {
@@ -296,7 +291,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);
 
@@ -374,11 +369,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;
@@ -416,7 +411,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) {
@@ -434,7 +429,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);
 
@@ -466,7 +461,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) {