X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_export_audio.cc;h=795091fb4142e846753dd1013bd83e7b272925a4;hb=cf52d6e4b40111eb04b244ec054055a4ec15dbe0;hp=851a045f0d376bb68f21079bdb68415ba9b5e40f;hpb=046f8026628a52adeb6983948e39b2665f4c0b49;p=ardour.git diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index 851a045f0d..795091fb41 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -19,33 +19,41 @@ /* Note: public Editor methods are documented in public_editor.h */ +#include #include #include #include -#include "export_dialog.h" -#include "editor.h" -#include "public_editor.h" -#include "selection.h" -#include "time_axis_view.h" -#include "audio_time_axis.h" -#include "audio_region_view.h" -#include "midi_region_view.h" +#include "pbd/gstdio_compat.h" + +#include "gtkmm2ext/choice.h" #include "pbd/pthread_utils.h" -#include "ardour/types.h" + #include "ardour/audio_track.h" #include "ardour/audiofilesource.h" -#include "ardour/audio_diskstream.h" -#include "ardour/audioregion.h" #include "ardour/audioplaylist.h" +#include "ardour/audioregion.h" #include "ardour/chan_count.h" +#include "ardour/midi_region.h" +#include "ardour/session.h" #include "ardour/session_directory.h" #include "ardour/source_factory.h" -#include "ardour/audiofilesource.h" +#include "ardour/types.h" -#include "i18n.h" +#include "audio_region_view.h" +#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" +#include "time_axis_view.h" +#include "utils.h" + +#include "pbd/i18n.h" using namespace std; using namespace ARDOUR; @@ -55,8 +63,16 @@ using namespace Gtk; void Editor::export_audio () { - ExportDialog dialog (*this); - dialog.set_session (session); + ExportDialog dialog (*this, _("Export"), ExportProfileManager::RegularExport); + dialog.set_session (_session); + dialog.run(); +} + +void +Editor::stem_export () +{ + StemExportDialog dialog (*this); + dialog.set_session (_session); dialog.run(); } @@ -64,18 +80,18 @@ void Editor::export_selection () { ExportSelectionDialog dialog (*this); - dialog.set_session (session); + dialog.set_session (_session); dialog.run(); } 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; @@ -83,11 +99,37 @@ Editor::export_range () if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) { ExportRangeDialog dialog (*this, l->id().to_s()); - dialog.set_session (session); + dialog.set_session (_session); dialog.run(); } } +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()); + } + + (void) midi_region->clone (path); + + return true; +} + /** Export the first selected region */ void Editor::export_region () @@ -96,20 +138,35 @@ 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, region, track); - dialog.set_session (session); - dialog.run(); + ExportRegionDialog dialog (*this, *(audio_region.get()), track); + dialog.set_session (_session); + dialog.run (); - } catch (std::bad_cast & e) { - error << "Exporting Region failed!" << endmsg; - return; + } else if (midi_region) { + + MidiExportDialog dialog (*this, midi_region); + dialog.set_session (_session); + + bool finished = false; + while (!finished) { + switch (dialog.run ()) { + case Gtk::RESPONSE_ACCEPT: + finished = process_midi_export_dialog (dialog, midi_region); + break; + default: + finished = true; + return; + } + } } } @@ -133,26 +190,27 @@ Editor::write_region_selection (RegionSelection& regions) } void -Editor::bounce_region_selection () +Editor::bounce_region_selection (bool with_processing) { + /* no need to check for bounceable() because this operation never puts + * its results back in the playlist (only in the region list). + */ + for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { boost::shared_ptr region ((*i)->region()); RouteTimeAxisView* rtv = dynamic_cast(&(*i)->get_time_axis_view()); - Track* track = dynamic_cast(rtv->route().get()); + boost::shared_ptr track = boost::dynamic_pointer_cast (rtv->route()); InterThreadInfo itt; - itt.done = false; - itt.cancel = false; - itt.progress = 0.0f; + boost::shared_ptr r; - boost::shared_ptr r = track->bounce_range (region->position(), region->position() + region->length(), itt); - cerr << "Result of bounce of " - << region->name() << " len = " << region->length() - << " was " - << r->name() << " len = " << r->length() - << endl; + if (with_processing) { + r = track->bounce_range (region->position(), region->position() + region->length(), itt, track->main_outs(), false); + } else { + r = track->bounce_range (region->position(), region->position() + region->length(), itt, boost::shared_ptr(), false); + } } } @@ -160,17 +218,17 @@ bool Editor::write_region (string path, boost::shared_ptr region) { boost::shared_ptr fs; - const nframes64_t chunk_size = 4096; - nframes64_t to_read; + const framepos_t chunk_size = 4096; + framepos_t to_read; Sample buf[chunk_size]; gain_t gain_buffer[chunk_size]; - nframes64_t pos; + framepos_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(); @@ -197,7 +255,7 @@ Editor::write_region (string path, boost::shared_ptr region) path = s; - if (::access (path.c_str(), F_OK) != 0) { + if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) { break; } } @@ -211,9 +269,9 @@ Editor::write_region (string path, boost::shared_ptr region) try { fs = boost::dynamic_pointer_cast ( - SourceFactory::createWritable (DataType::AUDIO, *session, - path, true, - false, session->frame_rate())); + SourceFactory::createWritable (DataType::AUDIO, *_session, + path, true, + false, _session->frame_rate())); } catch (failed_constructor& err) { @@ -232,7 +290,7 @@ Editor::write_region (string path, boost::shared_ptr region) pos = region->position(); while (to_read) { - nframes64_t this_time; + framepos_t this_time; this_time = min (to_read, chunk_size); @@ -294,9 +352,9 @@ Editor::write_audio_selection (TimeSelection& ts) if (atv->is_audio_track()) { - boost::shared_ptr playlist = boost::dynamic_pointer_cast(atv->get_diskstream()->playlist()); + boost::shared_ptr playlist = boost::dynamic_pointer_cast(atv->track()->playlist()); - if (playlist && write_audio_range (*playlist, atv->get_diskstream()->n_channels(), ts) == 0) { + if (playlist && write_audio_range (*playlist, atv->track()->n_channels(), ts) == 0) { ret = -1; break; } @@ -310,17 +368,17 @@ bool Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list& range) { boost::shared_ptr fs; - const nframes64_t chunk_size = 4096; - nframes64_t nframes; + const framepos_t chunk_size = 4096; + framepos_t nframes; Sample buf[chunk_size]; gain_t gain_buffer[chunk_size]; - nframes64_t pos; + framepos_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(); @@ -336,7 +394,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list legalize_for_path(playlist.name()).c_str(), cnt, n); } - if (::access (s, F_OK) != 0) { + if (!Glib::file_test (s, Glib::FILE_TEST_EXISTS)) { break; } } @@ -350,9 +408,9 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list try { fs = boost::dynamic_pointer_cast ( - SourceFactory::createWritable (DataType::AUDIO, *session, - path, true, - false, session->frame_rate())); + SourceFactory::createWritable (DataType::AUDIO, *_session, + path, true, + false, _session->frame_rate())); } catch (failed_constructor& err) { @@ -370,7 +428,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list pos = (*i).start; while (nframes) { - nframes64_t this_time; + framepos_t this_time; this_time = min (nframes, chunk_size); @@ -402,7 +460,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list while (nframes) { - nframes64_t this_time = min (nframes, chunk_size); + framepos_t this_time = min (nframes, chunk_size); memset (buf, 0, sizeof (Sample) * this_time); for (uint32_t n=0; n < channels; ++n) {