From 0729ff3f8eccb46a3887fda2bf975985176d150d Mon Sep 17 00:00:00 2001 From: VKamyshniy Date: Fri, 16 Jan 2015 07:52:24 +0200 Subject: [PATCH] [Summary] Progressing Tracks specific export dialog. --- gtk2_ardour/editor_export_audio.cc | 5 + gtk2_ardour/waves_export_dialog.cc | 9 +- gtk2_ardour/waves_export_dialog.h | 10 +- gtk2_ardour/waves_export_dialog.logic.cc | 120 ++++++++++++++++++++++- gtk2_ardour/waves_export_dialog.logic.h | 29 +++++- 5 files changed, 156 insertions(+), 17 deletions(-) diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index 2c2c8bcebd..89fbb3d4d7 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -45,6 +45,7 @@ #include "audio_region_view.h" #include "audio_time_axis.h" #include "editor.h" +#include "waves_export_dialog.h" #include "export_dialog.h" #include "midi_export_dialog.h" #include "midi_region_view.h" @@ -63,6 +64,10 @@ using namespace Gtk; void Editor::export_audio () { + { + WavesExportDialog export_dialog (_("Export"), _session, ExportProfileManager::RegularExport); + export_dialog.run(); + } ExportDialog dialog (*this, _("Export"), ExportProfileManager::RegularExport); dialog.set_session (_session); dialog.run(); diff --git a/gtk2_ardour/waves_export_dialog.cc b/gtk2_ardour/waves_export_dialog.cc index f1e78c71d5..b2d4d45a70 100644 --- a/gtk2_ardour/waves_export_dialog.cc +++ b/gtk2_ardour/waves_export_dialog.cc @@ -18,11 +18,16 @@ */ #include "waves_export_dialog.h" -WavesExportDialog::WavesExportDialog (const std::string &title, ARDOUR::ExportProfileManager::ExportType type) + +WavesExportDialog::WavesExportDialog (const std::string &title, ARDOUR::Session* session, ARDOUR::ExportProfileManager::ExportType type) : WavesDialog ("waves_export_dialog.xml", true, false ) , _export_button (get_waves_button ("export_button")) , _cancel_button (get_waves_button ("cancel_button")) + , _stop_export_button (get_waves_button ("stop_export_button")) + , _export_progress_bar (get_progressbar ("export_progress_bar")) + , _export_type (type) + , _previous_progress (0) { set_title (title); - init (); + init (session); } diff --git a/gtk2_ardour/waves_export_dialog.h b/gtk2_ardour/waves_export_dialog.h index 736c8a3db2..31f8ad8d01 100644 --- a/gtk2_ardour/waves_export_dialog.h +++ b/gtk2_ardour/waves_export_dialog.h @@ -21,23 +21,19 @@ #define __waves_export_dialog_h__ #include "ardour/export_profile_manager.h" -#include "public_editor.h" -#include "export_timespan_selector.h" -#include "export_channel_selector.h" -#include "export_file_notebook.h" -#include "export_preset_selector.h" -#include "soundcloud_export_selector.h" #include "waves_dialog.h" class WavesExportDialog : public WavesDialog { public: - WavesExportDialog(const std::string &title, ARDOUR::ExportProfileManager::ExportType type); + WavesExportDialog(const std::string &title, ARDOUR::Session* session, ARDOUR::ExportProfileManager::ExportType type); protected: WavesButton& _export_button; WavesButton& _cancel_button; + WavesButton& _stop_export_button; + Gtk::ProgressBar &_export_progress_bar; private: #include "waves_export_dialog.logic.h" diff --git a/gtk2_ardour/waves_export_dialog.logic.cc b/gtk2_ardour/waves_export_dialog.logic.cc index 86e27359f4..1f0548791e 100644 --- a/gtk2_ardour/waves_export_dialog.logic.cc +++ b/gtk2_ardour/waves_export_dialog.logic.cc @@ -17,23 +17,135 @@ */ +#include "ardour/audioregion.h" +#include "ardour/export_status.h" +#include "ardour/export_handler.h" #include "waves_export_dialog.h" +#include "public_editor.h" +#include "ardour_ui.h" +#include "time_selection.h" +#include "i18n.h" void -WavesExportDialog::init () +WavesExportDialog::init (ARDOUR::Session* session) { _export_button.signal_clicked.connect (sigc::mem_fun (*this, &WavesExportDialog::_on_export_button_clicked)); - _cancel_button.signal_clicked.connect (sigc::mem_fun (*this, &WavesExportDialog::_on_export_button_clicked)); + _cancel_button.signal_clicked.connect (sigc::mem_fun (*this, &WavesExportDialog::_on_cancel_button_clicked)); + + SessionHandlePtr::set_session (session); + if (!_session) { + return; + } + /* Init handler and profile manager */ + _export_handler = _session->get_export_handler (); + _export_status = _session->get_export_status (); + + _profile_manager.reset (new ARDOUR::ExportProfileManager (*_session, _export_type)); + + TimeSelection const & time (ARDOUR_UI::instance()->the_editor ().get_selection().time); + if (!time.empty()) { + _profile_manager->set_selection_range (time.front().start, time.front().end); + } else { + _profile_manager->set_selection_range (); + } +} + +void +WavesExportDialog::_show_progress () +{ + _export_status->running = true; + + _cancel_button.hide (); + _stop_export_button.show (); + + _export_progress_bar.set_fraction (0.0); + _export_progress_bar.show (); + _progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &WavesExportDialog::_on_progress_timeout), 100); + + gtk_main_iteration (); + + while (_export_status->running) { + if (gtk_events_pending()) { + gtk_main_iteration (); + } else { + Glib::usleep (10000); + } + } + + if (_export_status->aborted()) { + _notify_errors (); + } + + _export_status->finish (); +} + +void +WavesExportDialog::_notify_errors (bool force) +{ + if (force || _export_status->errors()) { + std::string txt = _("Export has been aborted due to an error!\nSee the Log for details."); + WavesMessageDialog msg ("", txt); + msg.run(); + } } void WavesExportDialog::_on_export_button_clicked (WavesButton*) { - response (Gtk::RESPONSE_OK); + _export_error.clear (); + _previous_progress = 0; + try { + _profile_manager->prepare_for_export (); + _export_handler->soundcloud_make_public = false; + _export_handler->soundcloud_open_page = false; + _export_handler->soundcloud_downloadable = false; + + _export_handler->do_export (); + _show_progress (); + } catch(std::exception & e) { + _export_error << string_compose (_("Export initialization failed: %1"), e.what()) << endmsg; + _notify_errors(true); + } } void WavesExportDialog::_on_cancel_button_clicked (WavesButton*) { + if (_export_status->running) { + _export_status->abort(); + } + + hide (); + set_modal (false); response (Gtk::RESPONSE_CANCEL); -} \ No newline at end of file +} + +gint +WavesExportDialog::_on_progress_timeout () +{ + std::string status_text; + float progress = 0.0; + + if (_export_status->normalizing) { + status_text = string_compose (_("Normalizing '%3' (timespan %1 of %2)"), + _export_status->timespan, _export_status->total_timespans, _export_status->timespan_name); + progress = ((float) _export_status->current_normalize_cycle) / _export_status->total_normalize_cycles; + } else { + status_text = string_compose (_("Exporting '%3' (timespan %1 of %2)"), + _export_status->timespan, _export_status->total_timespans, _export_status->timespan_name); + progress = ((float) _export_status->processed_frames_current_timespan) / _export_status->total_frames_current_timespan; + } + + _export_progress_bar.set_text (status_text); + + if (progress < _previous_progress) { + // Work around gtk bug + _export_progress_bar.hide(); + _export_progress_bar.show(); + } + + _previous_progress = progress; + + _export_progress_bar.set_fraction (progress); + return TRUE; +} diff --git a/gtk2_ardour/waves_export_dialog.logic.h b/gtk2_ardour/waves_export_dialog.logic.h index 409c050e2f..83f7ef5431 100644 --- a/gtk2_ardour/waves_export_dialog.logic.h +++ b/gtk2_ardour/waves_export_dialog.logic.h @@ -19,8 +19,29 @@ //class WavesExportDialog : public WavesDialog //{ -private: - void init (); -void _on_export_button_clicked (WavesButton*); -void _on_cancel_button_clicked (WavesButton*); +protected: + + typedef boost::shared_ptr HandlerPtr; + HandlerPtr _export_handler; + + typedef boost::shared_ptr ManagerPtr; + ManagerPtr _profile_manager; + + typedef boost::shared_ptr StatusPtr; + StatusPtr _export_status; + + ARDOUR::ExportProfileManager::ExportType _export_type; + sigc::connection _progress_connection; + std::stringstream _export_error; + float _previous_progress; // Needed for gtk bug workaround. + + + void init (ARDOUR::Session* session); + void _show_progress (); + void _notify_errors (bool force = false); + void _on_export_button_clicked (WavesButton*); + void _on_cancel_button_clicked (WavesButton*); + gint _on_progress_timeout (); + + //};