2 Copyright (C) 2008 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <sigc++/signal.h>
24 #include <gtkmm/messagedialog.h>
26 #include "ardour/audioregion.h"
27 #include "ardour/export_channel_configuration.h"
28 #include "ardour/export_status.h"
29 #include "ardour/export_handler.h"
30 #include "ardour/profile.h"
32 #include "export_dialog.h"
33 #include "export_report.h"
34 #include "gui_thread.h"
39 using namespace ARDOUR;
43 ExportDialog::ExportDialog (PublicEditor & editor, std::string title, ARDOUR::ExportProfileManager::ExportType type)
44 : ArdourDialog (title)
48 , warn_label ("", Gtk::ALIGN_LEFT)
49 , list_files_label (_("<span color=\"#ffa755\">Some already existing files will be overwritten.</span>"), Gtk::ALIGN_RIGHT)
50 , list_files_button (_("List files"))
53 ExportDialog::~ExportDialog ()
57 ExportDialog::set_session (ARDOUR::Session* s)
59 SessionHandlePtr::set_session (s);
65 /* Init handler and profile manager */
67 handler = _session->get_export_handler ();
68 status = _session->get_export_status ();
70 profile_manager.reset (new ExportProfileManager (*_session, type));
72 /* Possibly init stuff in derived classes */
76 /* Rest of _session related initialization */
78 preset_selector->set_manager (profile_manager);
79 file_notebook->set_session_and_manager (_session, profile_manager);
81 /* Hand on selection range to profile manager */
83 TimeSelection const & time (editor.get_selection().time);
85 profile_manager->set_selection_range (time.front().start, time.front().end);
87 profile_manager->set_selection_range ();
92 profile_manager->load_profile ();
97 preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
98 timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
99 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
100 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_realtime_selection));
101 file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
103 update_warnings_and_example_filename ();
104 update_realtime_selection ();
106 _session->config.ParameterChanged.connect (*this, invalidator (*this), boost::bind (&ExportDialog::parameter_changed, this, _1), gui_context());
110 ExportDialog::init ()
117 warning_widget.pack_start (warn_hbox, true, true, 6);
118 warning_widget.pack_end (list_files_hbox, false, false, 0);
120 warn_hbox.pack_start (warn_label, true, true, 16);
121 warn_label.set_use_markup (true);
123 list_files_hbox.pack_end (list_files_button, false, false, 6);
124 list_files_hbox.pack_end (list_files_label, false, false, 6);
125 list_files_label.set_use_markup (true);
127 list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
129 /* Progress indicators */
131 progress_widget.pack_start (progress_bar, false, false, 6);
135 cancel_button = add_button (Gtk::Stock::CANCEL, RESPONSE_CANCEL);
136 export_button = add_button (_("Export"), RESPONSE_FAST);
137 set_default_response (RESPONSE_FAST);
139 cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::close_dialog));
140 export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::do_export));
142 file_notebook->soundcloud_export_selector = soundcloud_selector;
146 show_all_children ();
147 progress_widget.hide_all();
151 ExportDialog::init_gui ()
153 Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
154 preset_align->add (*preset_selector);
155 preset_align->set_padding (0, 12, 0, 0);
157 Gtk::VBox * file_format_selector = Gtk::manage (new Gtk::VBox());
158 file_format_selector->set_homogeneous (false);
159 file_format_selector->pack_start (*preset_align, false, false, 0);
160 file_format_selector->pack_start (*file_notebook, false, false, 0);
161 file_format_selector->pack_start (*soundcloud_selector, false, false, 0);
163 export_notebook.append_page (*file_format_selector, _("File format"));
164 export_notebook.append_page (*timespan_selector, _("Time Span"));
165 export_notebook.append_page (*channel_selector, _("Channels"));
167 get_vbox()->pack_start (export_notebook, true, true, 0);
168 get_vbox()->pack_end (warning_widget, false, false, 0);
169 get_vbox()->pack_end (progress_widget, false, false, 0);
174 ExportDialog::init_components ()
176 preset_selector.reset (new ExportPresetSelector ());
177 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
178 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
179 soundcloud_selector.reset (new SoundcloudExportSelector ());
180 file_notebook.reset (new ExportFileNotebook ());
184 ExportDialog::notify_errors (bool force)
186 if (force || status->errors()) {
187 std::string txt = _("Export has been aborted due to an error!\nSee the Log for details.");
188 Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
194 ExportDialog::close_dialog ()
196 if (status->running ()) {
206 ExportDialog::sync_with_manager ()
208 timespan_selector->sync_with_manager();
209 channel_selector->sync_with_manager();
210 file_notebook->sync_with_manager ();
212 update_warnings_and_example_filename ();
213 update_realtime_selection ();
217 ExportDialog::update_warnings_and_example_filename ()
222 warn_label.set_markup (warn_string);
224 list_files_hbox.hide ();
225 list_files_string = "";
227 export_button->set_sensitive (true);
229 /* Add new warnings */
231 boost::shared_ptr<ExportProfileManager::Warnings> warnings = profile_manager->get_warnings();
233 for (std::list<string>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
237 for (std::list<string>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
241 if (!warnings->conflicting_filenames.empty()) {
242 list_files_hbox.show ();
243 for (std::list<string>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
244 string::size_type pos = it->find_last_of ("/");
245 list_files_string += it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>\n";
249 /* Update example filename */
251 file_notebook->update_example_filenames();
255 ExportDialog::update_realtime_selection ()
258 switch (profile_manager->type ()) {
259 case ExportProfileManager::RegularExport:
261 case ExportProfileManager::RangeExport:
263 case ExportProfileManager::SelectionExport:
265 case ExportProfileManager::RegionExport:
266 if (!profile_manager->get_channel_configs().empty ()) {
267 switch (profile_manager->get_channel_configs().front()->config->region_processing_type ()) {
268 case RegionExportChannelFactory::Raw:
269 case RegionExportChannelFactory::Fades:
277 case ExportProfileManager::StemExport:
278 if (! static_cast<TrackExportChannelSelector*>(channel_selector.get())->track_output ()) {
284 timespan_selector->allow_realtime_export (rt_ok);
288 ExportDialog::parameter_changed (std::string const& p)
290 if (p == "realtime-export") {
291 update_realtime_selection ();
296 ExportDialog::show_conflicting_files ()
298 ArdourDialog dialog (_("Files that will be overwritten"), true);
300 Gtk::Label label ("", Gtk::ALIGN_LEFT);
301 label.set_use_markup (true);
302 label.set_markup (list_files_string);
304 dialog.get_vbox()->pack_start (label);
305 dialog.add_button (Gtk::Stock::OK, 0);
306 dialog.show_all_children ();
312 ExportDialog::soundcloud_upload_progress(double total, double now, std::string title)
314 soundcloud_selector->do_progress_callback(total, now, title);
319 ExportDialog::do_export ()
322 profile_manager->prepare_for_export ();
323 handler->soundcloud_username = soundcloud_selector->username ();
324 handler->soundcloud_password = soundcloud_selector->password ();
325 handler->soundcloud_make_public = soundcloud_selector->make_public ();
326 handler->soundcloud_open_page = soundcloud_selector->open_page ();
327 handler->soundcloud_downloadable = soundcloud_selector->downloadable ();
329 handler->SoundcloudProgress.connect_same_thread(
331 boost::bind(&ExportDialog::soundcloud_upload_progress, this, _1, _2, _3)
334 handler->SoundcloudProgress.connect(
335 *this, invalidator (*this),
336 boost::bind(&ExportDialog::soundcloud_upload_progress, this, _1, _2, _3),
340 handler->do_export ();
342 } catch(std::exception & e) {
343 error << string_compose (_("Export initialization failed: %1"), e.what()) << endmsg;
349 ExportDialog::show_progress ()
351 export_notebook.set_sensitive (false);
353 cancel_button->set_label (_("Stop Export"));
354 export_button->set_sensitive (false);
356 progress_bar.set_fraction (0.0);
357 warning_widget.hide_all();
358 progress_widget.show ();
359 progress_widget.show_all_children ();
360 progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
362 gtk_main_iteration ();
364 while (status->running ()) {
365 if (gtk_events_pending()) {
366 gtk_main_iteration ();
368 Glib::usleep (10000);
374 if (!status->aborted() && status->result_map.size() > 0) {
376 ExportReport er (_session, status);
380 if (!status->aborted()) {
382 if (!ARDOUR::Profile->get_mixbus()) {
383 NagScreen* ns = NagScreen::maybe_nag (_("export"));
392 export_notebook.set_sensitive (true);
396 ExportDialog::progress_timeout ()
398 std::string status_text;
400 switch (status->active_job) {
401 case ExportStatus::Exporting:
402 status_text = string_compose (_("Exporting '%3' (timespan %1 of %2)"),
403 status->timespan, status->total_timespans, status->timespan_name);
404 progress = ((float) status->processed_frames_current_timespan) / status->total_frames_current_timespan;
406 case ExportStatus::Normalizing:
407 status_text = string_compose (_("Normalizing '%3' (timespan %1 of %2)"),
408 status->timespan, status->total_timespans, status->timespan_name);
409 progress = ((float) status->current_postprocessing_cycle) / status->total_postprocessing_cycles;
411 case ExportStatus::Encoding:
412 status_text = string_compose (_("Encoding '%3' (timespan %1 of %2)"),
413 status->timespan, status->total_timespans, status->timespan_name);
414 progress = ((float) status->current_postprocessing_cycle) / status->total_postprocessing_cycles;
416 case ExportStatus::Tagging:
417 status_text = string_compose (_("Tagging '%3' (timespan %1 of %2)"),
418 status->timespan, status->total_timespans, status->timespan_name);
420 case ExportStatus::Uploading:
421 status_text = string_compose (_("Uploading '%3' (timespan %1 of %2)"),
422 status->timespan, status->total_timespans, status->timespan_name);
424 case ExportStatus::Command:
425 status_text = string_compose (_("Running Post Export Command for '%1'"), status->timespan_name);
429 progress_bar.set_text (status_text);
431 if (progress < previous_progress) {
432 // Work around gtk bug
436 previous_progress = progress;
439 progress_bar.set_fraction (progress);
441 progress_bar.set_pulse_step(.1);
442 progress_bar.pulse();
448 ExportDialog::add_error (string const & text)
450 export_button->set_sensitive (false);
452 if (warn_string.empty()) {
453 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
455 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
458 warn_label.set_markup (warn_string);
462 ExportDialog::add_warning (string const & text)
464 if (warn_string.empty()) {
465 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
467 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
470 warn_label.set_markup (warn_string);
473 /*** Dialog specializations ***/
475 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, string range_id) :
476 ExportDialog (editor, _("Export Range"), ExportProfileManager::RangeExport),
481 ExportRangeDialog::init_components ()
483 preset_selector.reset (new ExportPresetSelector ());
484 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, range_id));
485 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
486 soundcloud_selector.reset (new SoundcloudExportSelector ());
487 file_notebook.reset (new ExportFileNotebook ());
490 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
491 ExportDialog (editor, _("Export Selection"), ExportProfileManager::SelectionExport)
495 ExportSelectionDialog::init_components ()
497 preset_selector.reset (new ExportPresetSelector ());
498 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, X_("selection")));
499 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
500 soundcloud_selector.reset (new SoundcloudExportSelector ());
501 file_notebook.reset (new ExportFileNotebook ());
504 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
505 ExportDialog (editor, _("Export Region"), ExportProfileManager::RegionExport),
511 ExportRegionDialog::init_gui ()
513 ExportDialog::init_gui ();
514 export_notebook.set_tab_label_text(*export_notebook.get_nth_page(2), _("Source"));
518 ExportRegionDialog::init_components ()
520 string loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
522 preset_selector.reset (new ExportPresetSelector ());
523 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, loc_id));
524 channel_selector.reset (new RegionExportChannelSelector (_session, profile_manager, region, track));
525 soundcloud_selector.reset (new SoundcloudExportSelector ());
526 file_notebook.reset (new ExportFileNotebook ());
529 StemExportDialog::StemExportDialog (PublicEditor & editor)
530 : ExportDialog(editor, _("Stem Export"), ExportProfileManager::StemExport)
536 StemExportDialog::init_components ()
538 preset_selector.reset (new ExportPresetSelector ());
539 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
540 channel_selector.reset (new TrackExportChannelSelector (_session, profile_manager));
541 soundcloud_selector.reset (new SoundcloudExportSelector ());
542 file_notebook.reset (new ExportFileNotebook ());