From e0d0735fa2c2543c6995e9128dbd16c799f4ec8f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 23 May 2012 20:32:55 +0000 Subject: add basic, not terribly glossy MIDI region export git-svn-id: svn://localhost/ardour2/branches/3.0@12402 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor_export_audio.cc | 32 ++++++++++++++++++------- gtk2_ardour/midi_export_dialog.cc | 48 ++++++++++++++++++++++++++++++++++++++ gtk2_ardour/midi_export_dialog.h | 41 ++++++++++++++++++++++++++++++++ gtk2_ardour/wscript | 1 + 4 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 gtk2_ardour/midi_export_dialog.cc create mode 100644 gtk2_ardour/midi_export_dialog.h (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index ac0c3f67c4..9521f6a0c6 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -46,6 +46,7 @@ #include "audio_time_axis.h" #include "editor.h" #include "export_dialog.h" +#include "midi_export_dialog.h" #include "midi_region_view.h" #include "public_editor.h" #include "selection.h" @@ -110,20 +111,33 @@ Editor::export_region () return; } - try { - boost::shared_ptr r = selection->regions.front()->region(); - AudioRegion & region (dynamic_cast (*r)); - + 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) { - ExportRegionDialog dialog (*this, region, track); + MidiExportDialog dialog (*this, midi_region); dialog.set_session (_session); - dialog.run(); + int ret = dialog.run (); + switch (ret) { + case Gtk::RESPONSE_ACCEPT: + break; + default: + return; + } - } catch (std::bad_cast & e) { - error << "Exporting Region failed!" << endmsg; - return; + string path = dialog.get_path (); + (void) midi_region->clone (path); } } diff --git a/gtk2_ardour/midi_export_dialog.cc b/gtk2_ardour/midi_export_dialog.cc new file mode 100644 index 0000000000..95bb7b6587 --- /dev/null +++ b/gtk2_ardour/midi_export_dialog.cc @@ -0,0 +1,48 @@ +/* + Copyright (C) 2012 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. + +*/ + +#include + +#include "ardour/midi_region.h" + +#include "midi_export_dialog.h" + +using namespace ARDOUR; + +MidiExportDialog::MidiExportDialog (PublicEditor&, boost::shared_ptr region) + : ArdourDialog (string_compose (_("Export MIDI: %1"), region->name())) + , file_chooser (Gtk::FILE_CHOOSER_ACTION_SAVE) +{ + add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); + add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + get_vbox()->pack_start (file_chooser); + file_chooser.set_filename (region->name() + ".mid"); + file_chooser.show (); +} + +MidiExportDialog::~MidiExportDialog () +{ +} + +std::string +MidiExportDialog::get_path () const +{ + return file_chooser.get_filename (); + +} diff --git a/gtk2_ardour/midi_export_dialog.h b/gtk2_ardour/midi_export_dialog.h new file mode 100644 index 0000000000..86b2328415 --- /dev/null +++ b/gtk2_ardour/midi_export_dialog.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2012 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. + +*/ + +#ifndef __gtk2_ardour_midi_export_dialog_h__ +#define __gtk2_ardour_midi_export_dialog_h__ + +#include + +#include + +#include "ardour_dialog.h" +#include "public_editor.h" + +class MidiExportDialog : public ArdourDialog { + public: + MidiExportDialog (PublicEditor& editor, boost::shared_ptr); + ~MidiExportDialog (); + + std::string get_path() const; + + private: + Gtk::FileChooserWidget file_chooser; +}; + +#endif /* __gtk2_ardour_midi_export_dialog_h__ */ diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index e1fccbd328..b9fca6cc0a 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -137,6 +137,7 @@ gtk2_ardour_sources = [ 'midi_channel_dialog.cc', 'midi_channel_selector.cc', 'midi_cut_buffer.cc', + 'midi_export_dialog.cc', 'midi_list_editor.cc', 'midi_port_dialog.cc', 'midi_region_view.cc', -- cgit v1.2.3