2 * Copyright (C) 2005-2006 Doug McLain <doug@nostar.net>
3 * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
4 * Copyright (C) 2005-2008 Nick Mainsbridge <mainsbridge@gmail.com>
5 * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
6 * Copyright (C) 2006-2011 David Robillard <d@drobilla.net>
7 * Copyright (C) 2007-2012 Tim Mayberry <mojofunk@gmail.com>
8 * Copyright (C) 2008-2013 Sakari Bergen <sakari.bergen@beatwaves.net>
9 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
10 * Copyright (C) 2013-2014 Colin Fletcher <colin.m.fletcher@googlemail.com>
11 * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <sigc++/signal.h>
31 #include <gtkmm/messagedialog.h>
32 #include <gtkmm/stock.h>
34 #include "pbd/gstdio_compat.h"
35 #include "pbd/file_utils.h"
37 #include "ardour/audioregion.h"
38 #include "ardour/export_channel_configuration.h"
39 #include "ardour/export_format_specification.h"
40 #include "ardour/export_status.h"
41 #include "ardour/export_handler.h"
42 #include "ardour/profile.h"
44 #include "export_dialog.h"
45 #include "export_report.h"
46 #include "gui_thread.h"
49 #include "ui_config.h"
53 using namespace ARDOUR;
57 ExportDialog::ExportDialog (PublicEditor & editor, std::string title, ARDOUR::ExportProfileManager::ExportType type)
58 : ArdourDialog (title)
61 , warn_label ("", Gtk::ALIGN_LEFT)
62 , list_files_label (_("<span color=\"#ffa755\">Some already existing files will be overwritten.</span>"), Gtk::ALIGN_RIGHT)
63 , list_files_button (_("List files"))
64 , previous_progress (0)
67 ExportDialog::~ExportDialog ()
71 ExportDialog::set_session (ARDOUR::Session* s)
73 SessionHandlePtr::set_session (s);
79 /* Init handler and profile manager */
81 handler = _session->get_export_handler ();
82 status = _session->get_export_status ();
84 profile_manager.reset (new ExportProfileManager (*_session, type));
86 /* Possibly init stuff in derived classes */
90 /* Rest of _session related initialization */
92 preset_selector->set_manager (profile_manager);
93 file_notebook->set_session_and_manager (_session, profile_manager);
95 /* Hand on selection range to profile manager */
97 TimeSelection const & time (editor.get_selection().time);
99 profile_manager->set_selection_range (time.front().start, time.front().end);
101 profile_manager->set_selection_range ();
106 profile_manager->load_profile ();
107 sync_with_manager ();
111 preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
112 timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
113 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
114 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_realtime_selection));
115 file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
117 update_warnings_and_example_filename ();
118 update_realtime_selection ();
120 _session->config.ParameterChanged.connect (*this, invalidator (*this), boost::bind (&ExportDialog::parameter_changed, this, _1), gui_context());
124 ExportDialog::init ()
131 warning_widget.pack_start (warn_hbox, true, true, 6);
132 warning_widget.pack_end (list_files_hbox, false, false, 0);
134 warn_hbox.pack_start (warn_label, true, true, 16);
135 warn_label.set_use_markup (true);
137 list_files_hbox.pack_end (list_files_button, false, false, 6);
138 list_files_hbox.pack_end (list_files_label, false, false, 6);
139 list_files_label.set_use_markup (true);
141 list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
143 /* Progress indicators */
145 progress_widget.pack_start (progress_bar, false, false, 6);
149 cancel_button = add_button (Gtk::Stock::CANCEL, RESPONSE_CANCEL);
150 export_button = add_button (_("Export"), RESPONSE_FAST);
151 set_default_response (RESPONSE_FAST);
153 cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::close_dialog));
154 export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::do_export));
156 file_notebook->soundcloud_export_selector = soundcloud_selector;
160 show_all_children ();
161 progress_widget.hide_all();
165 ExportDialog::init_gui ()
167 Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
168 preset_align->add (*preset_selector);
169 preset_align->set_padding (0, 12, 0, 0);
171 Gtk::VBox * file_format_selector = Gtk::manage (new Gtk::VBox());
172 file_format_selector->set_homogeneous (false);
173 file_format_selector->pack_start (*preset_align, false, false, 0);
174 file_format_selector->pack_start (*file_notebook, false, false, 0);
175 file_format_selector->pack_start (*soundcloud_selector, false, false, 0);
177 export_notebook.append_page (*file_format_selector, _("File format"));
178 export_notebook.append_page (*timespan_selector, _("Time Span"));
179 export_notebook.append_page (*channel_selector, _("Channels"));
181 get_vbox()->pack_start (export_notebook, true, true, 0);
182 get_vbox()->pack_end (warning_widget, false, false, 0);
183 get_vbox()->pack_end (progress_widget, false, false, 0);
188 ExportDialog::init_components ()
190 preset_selector.reset (new ExportPresetSelector ());
191 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
192 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
193 soundcloud_selector.reset (new SoundcloudExportSelector ());
194 file_notebook.reset (new ExportFileNotebook ());
198 ExportDialog::notify_errors (bool force)
200 if (force || status->errors()) {
201 std::string txt = _("Export has been aborted due to an error!\nSee the Log for details.");
202 Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
208 ExportDialog::close_dialog ()
210 if (status->running ()) {
220 ExportDialog::sync_with_manager ()
222 timespan_selector->sync_with_manager();
223 channel_selector->sync_with_manager();
224 file_notebook->sync_with_manager ();
226 update_warnings_and_example_filename ();
227 update_realtime_selection ();
231 ExportDialog::update_warnings_and_example_filename ()
236 warn_label.set_markup (warn_string);
238 list_files_hbox.hide ();
239 list_files_string = "";
241 export_button->set_sensitive (true);
243 /* Add new warnings */
245 boost::shared_ptr<ExportProfileManager::Warnings> warnings = profile_manager->get_warnings();
247 for (std::list<string>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
251 for (std::list<string>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
255 if (!warnings->conflicting_filenames.empty()) {
256 list_files_hbox.show ();
257 for (std::list<string>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
258 string::size_type pos = it->find_last_of ("/");
259 list_files_string += it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>\n";
263 /* Update example filename */
265 file_notebook->update_example_filenames();
269 ExportDialog::update_realtime_selection ()
272 switch (profile_manager->type ()) {
273 case ExportProfileManager::RegularExport:
275 case ExportProfileManager::RangeExport:
277 case ExportProfileManager::SelectionExport:
279 case ExportProfileManager::RegionExport:
280 if (!profile_manager->get_channel_configs().empty ()) {
281 switch (profile_manager->get_channel_configs().front()->config->region_processing_type ()) {
282 case RegionExportChannelFactory::Raw:
283 case RegionExportChannelFactory::Fades:
291 case ExportProfileManager::StemExport:
292 if (! static_cast<TrackExportChannelSelector*>(channel_selector.get())->track_output ()) {
298 timespan_selector->allow_realtime_export (rt_ok);
302 ExportDialog::parameter_changed (std::string const& p)
304 if (p == "realtime-export") {
305 update_realtime_selection ();
310 ExportDialog::show_conflicting_files ()
312 ArdourDialog dialog (_("Files that will be overwritten"), true);
314 Gtk::Label label ("", Gtk::ALIGN_LEFT);
315 label.set_use_markup (true);
316 label.set_markup (list_files_string);
318 dialog.get_vbox()->pack_start (label);
319 dialog.add_button (Gtk::Stock::OK, 0);
320 dialog.show_all_children ();
326 ExportDialog::soundcloud_upload_progress(double total, double now, std::string title)
328 soundcloud_selector->do_progress_callback(total, now, title);
333 ExportDialog::do_export ()
336 profile_manager->prepare_for_export ();
337 handler->soundcloud_username = soundcloud_selector->username ();
338 handler->soundcloud_password = soundcloud_selector->password ();
339 handler->soundcloud_make_public = soundcloud_selector->make_public ();
340 handler->soundcloud_open_page = soundcloud_selector->open_page ();
341 handler->soundcloud_downloadable = soundcloud_selector->downloadable ();
343 handler->SoundcloudProgress.connect_same_thread(
345 boost::bind(&ExportDialog::soundcloud_upload_progress, this, _1, _2, _3)
348 handler->SoundcloudProgress.connect(
349 *this, invalidator (*this),
350 boost::bind(&ExportDialog::soundcloud_upload_progress, this, _1, _2, _3),
354 handler->do_export ();
356 } catch(std::exception & e) {
357 error << string_compose (_("Export initialization failed: %1"), e.what()) << endmsg;
363 ExportDialog::show_progress ()
365 export_notebook.set_sensitive (false);
367 cancel_button->set_label (_("Stop Export"));
368 export_button->set_sensitive (false);
370 progress_bar.set_fraction (0.0);
371 warning_widget.hide_all();
372 progress_widget.show ();
373 progress_widget.show_all_children ();
374 progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
376 gtk_main_iteration ();
378 while (status->running ()) {
379 if (gtk_events_pending()) {
380 gtk_main_iteration ();
382 Glib::usleep (10000);
388 if (!status->aborted() && UIConfiguration::instance().get_save_export_mixer_screenshot ()) {
389 ExportProfileManager::TimespanStateList const& timespans = profile_manager->get_timespans();
390 ExportProfileManager::FilenameStateList const& filenames = profile_manager->get_filenames ();
392 std::list<std::string> paths;
393 for (ExportProfileManager::FilenameStateList::const_iterator fi = filenames.begin(); fi != filenames.end(); ++fi) {
394 for (ExportProfileManager::TimespanStateList::const_iterator ti = timespans.begin(); ti != timespans.end(); ++ti) {
395 ExportProfileManager::TimespanListPtr tlp = (*ti)->timespans;
396 for (ExportProfileManager::TimespanList::const_iterator eti = tlp->begin(); eti != tlp->end(); ++eti) {
397 (*fi)->filename->set_timespan (*eti);
398 paths.push_back ((*fi)->filename->get_path (ExportFormatSpecPtr ()) + "-mixer.png");
403 if (paths.size() > 0) {
404 PBD::info << string_compose(_("Writing Mixer Screenshot: %1."), paths.front()) << endmsg;
405 Mixer_UI::instance()->screenshot (paths.front());
407 std::list<std::string>::const_iterator it = paths.begin ();
409 for (; it != paths.end(); ++it) {
410 PBD::info << string_compose(_("Copying Mixer Screenshot: %1."), *it) << endmsg;
411 ::g_unlink (it->c_str());
412 if (!hard_link (paths.front(), *it)) {
413 copy_file (paths.front(), *it);
419 if (!status->aborted() && status->result_map.size() > 0) {
421 ExportReport er (_session, status);
425 if (!status->aborted()) {
427 if (!ARDOUR::Profile->get_mixbus()) {
428 NagScreen* ns = NagScreen::maybe_nag (_("export"));
437 export_notebook.set_sensitive (true);
441 ExportDialog::progress_timeout ()
443 std::string status_text;
445 switch (status->active_job) {
446 case ExportStatus::Exporting:
447 status_text = string_compose (_("Exporting '%3' (timespan %1 of %2)"),
448 status->timespan, status->total_timespans, status->timespan_name);
449 progress = ((float) status->processed_samples_current_timespan) / status->total_samples_current_timespan;
451 case ExportStatus::Normalizing:
452 status_text = string_compose (_("Normalizing '%3' (timespan %1 of %2)"),
453 status->timespan, status->total_timespans, status->timespan_name);
454 progress = ((float) status->current_postprocessing_cycle) / status->total_postprocessing_cycles;
456 case ExportStatus::Encoding:
457 status_text = string_compose (_("Encoding '%3' (timespan %1 of %2)"),
458 status->timespan, status->total_timespans, status->timespan_name);
459 progress = ((float) status->current_postprocessing_cycle) / status->total_postprocessing_cycles;
461 case ExportStatus::Tagging:
462 status_text = string_compose (_("Tagging '%3' (timespan %1 of %2)"),
463 status->timespan, status->total_timespans, status->timespan_name);
465 case ExportStatus::Uploading:
466 status_text = string_compose (_("Uploading '%3' (timespan %1 of %2)"),
467 status->timespan, status->total_timespans, status->timespan_name);
469 case ExportStatus::Command:
470 status_text = string_compose (_("Running Post Export Command for '%1'"), status->timespan_name);
474 progress_bar.set_text (status_text);
476 if (progress < previous_progress) {
477 // Work around gtk bug
481 previous_progress = progress;
484 progress_bar.set_fraction (progress);
486 progress_bar.set_pulse_step(.1);
487 progress_bar.pulse();
493 ExportDialog::add_error (string const & text)
495 export_button->set_sensitive (false);
497 if (warn_string.empty()) {
498 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
500 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
503 warn_label.set_markup (warn_string);
507 ExportDialog::add_warning (string const & text)
509 if (warn_string.empty()) {
510 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
512 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
515 warn_label.set_markup (warn_string);
518 /*** Dialog specializations ***/
520 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, string range_id) :
521 ExportDialog (editor, _("Export Range"), ExportProfileManager::RangeExport),
526 ExportRangeDialog::init_components ()
528 preset_selector.reset (new ExportPresetSelector ());
529 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, range_id));
530 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
531 soundcloud_selector.reset (new SoundcloudExportSelector ());
532 file_notebook.reset (new ExportFileNotebook ());
535 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
536 ExportDialog (editor, _("Export Selection"), ExportProfileManager::SelectionExport)
540 ExportSelectionDialog::init_components ()
542 preset_selector.reset (new ExportPresetSelector ());
543 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, X_("selection")));
544 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
545 soundcloud_selector.reset (new SoundcloudExportSelector ());
546 file_notebook.reset (new ExportFileNotebook ());
549 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
550 ExportDialog (editor, _("Export Region"), ExportProfileManager::RegionExport),
556 ExportRegionDialog::init_gui ()
558 ExportDialog::init_gui ();
559 export_notebook.set_tab_label_text(*export_notebook.get_nth_page(2), _("Source"));
563 ExportRegionDialog::init_components ()
565 string loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
567 preset_selector.reset (new ExportPresetSelector ());
568 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, loc_id));
569 channel_selector.reset (new RegionExportChannelSelector (_session, profile_manager, region, track));
570 soundcloud_selector.reset (new SoundcloudExportSelector ());
571 file_notebook.reset (new ExportFileNotebook ());
574 StemExportDialog::StemExportDialog (PublicEditor & editor)
575 : ExportDialog(editor, _("Stem Export"), ExportProfileManager::StemExport)
581 StemExportDialog::init_components ()
583 preset_selector.reset (new ExportPresetSelector ());
584 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
585 channel_selector.reset (new TrackExportChannelSelector (_session, profile_manager));
586 soundcloud_selector.reset (new SoundcloudExportSelector ());
587 file_notebook.reset (new ExportFileNotebook ());