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 "pbd/filesystem.h"
26 #include "ardour/export_status.h"
27 #include "ardour/export_handler.h"
29 #include "export_dialog.h"
30 #include "gui_thread.h"
34 using namespace ARDOUR;
37 ExportDialog::ExportDialog (PublicEditor & editor, Glib::ustring title) :
41 warn_label ("", Gtk::ALIGN_LEFT),
42 list_files_label (_("<span color=\"#ffa755\">Some already existing files will be overwritten.</span>"), Gtk::ALIGN_RIGHT),
43 list_files_button (_("List files"))
46 ExportDialog::~ExportDialog ()
50 ExportDialog::set_session (ARDOUR::Session* s)
52 SessionHandlePtr::set_session (s);
58 /* Init handler and profile manager */
60 handler = _session->get_export_handler ();
61 status = _session->get_export_status ();
62 profile_manager.reset (new ExportProfileManager (*_session));
64 /* Possibly init stuff in derived classes */
68 /* Rest of _session related initialization */
70 preset_selector->set_manager (profile_manager);
71 file_notebook->set_session_and_manager (_session, profile_manager);
73 /* Hand on selection range to profile manager */
75 TimeSelection const & time (editor.get_selection().time);
77 profile_manager->set_selection_range (time.front().start, time.front().end);
79 profile_manager->set_selection_range ();
84 profile_manager->load_profile ();
89 preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
90 timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
91 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
92 file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
94 status->Aborting.connect (abort_connection, invalidator (*this), boost::bind (&ExportDialog::notify_errors, this), gui_context());
100 ExportDialog::init ()
107 warning_widget.pack_start (warn_hbox, true, true, 6);
108 warning_widget.pack_end (list_files_hbox, false, false, 0);
110 warn_hbox.pack_start (warn_label, true, true, 16);
111 warn_label.set_use_markup (true);
113 list_files_hbox.pack_end (list_files_button, false, false, 6);
114 list_files_hbox.pack_end (list_files_label, false, false, 6);
115 list_files_label.set_use_markup (true);
117 list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
119 /* Progress indicators */
121 progress_widget.pack_start (progress_label, false, false, 6);
122 progress_widget.pack_start (progress_bar, false, false, 6);
126 cancel_button = add_button (Gtk::Stock::CANCEL, RESPONSE_CANCEL);
127 // Realtime export is disabled for now, as it will most probably not work
128 //rt_export_button = add_button (_("Realtime Export"), RESPONSE_RT);
129 //fast_export_button = add_button (_("Fast Export"), RESPONSE_FAST);
130 fast_export_button = add_button (_("Export"), RESPONSE_FAST);
132 list_files_button.set_name ("PaddedButton");
134 cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::close_dialog));
135 //rt_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_rt));
136 fast_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_fw));
140 show_all_children ();
141 progress_widget.hide_all();
145 ExportDialog::init_gui ()
147 Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
148 preset_align->add (*preset_selector);
149 preset_align->set_padding (0, 12, 0, 0);
150 get_vbox()->pack_start (*preset_align, false, false, 0);
152 Gtk::VBox* advanced_vbox = Gtk::manage (new Gtk::VBox());
153 advanced_vbox->set_spacing (12);
154 advanced_vbox->set_border_width (12);
156 Gtk::Alignment * timespan_align = Gtk::manage (new Gtk::Alignment());
157 timespan_label = Gtk::manage (new Gtk::Label (_("Time Span"), Gtk::ALIGN_LEFT));
158 timespan_align->add (*timespan_selector);
159 timespan_align->set_padding (0, 12, 18, 0);
160 advanced_vbox->pack_start (*timespan_label, false, false, 0);
161 advanced_vbox->pack_start (*timespan_align, false, false, 0);
163 Gtk::Alignment * channels_align = Gtk::manage (new Gtk::Alignment());
164 channels_label = Gtk::manage (new Gtk::Label (_("Channels"), Gtk::ALIGN_LEFT));
165 channels_align->add (*channel_selector);
166 channels_align->set_padding (0, 12, 18, 0);
167 advanced_vbox->pack_start (*channels_label, false, false, 0);
168 advanced_vbox->pack_start (*channels_align, false, false, 0);
170 get_vbox()->pack_start (*file_notebook, false, false, 0);
171 get_vbox()->pack_start (warning_widget, false, false, 0);
172 get_vbox()->pack_start (progress_widget, false, false, 0);
174 Gtk::Expander* advanced = Gtk::manage (new Gtk::Expander (_("Advanced options")));
175 advanced->add (*advanced_vbox);
177 get_vbox()->pack_start (*advanced, false, false);
179 Pango::AttrList bold;
180 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
183 timespan_label->set_attributes (bold);
184 channels_label->set_attributes (bold);
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 file_notebook.reset (new ExportFileNotebook ());
197 ExportDialog::notify_errors ()
199 if (status->errors()) {
200 Glib::ustring txt = _("Export has been aborted due to an error!\nSee the Log for details.");
201 Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
207 ExportDialog::close_dialog ()
209 if (status->running) {
219 ExportDialog::sync_with_manager ()
221 timespan_selector->sync_with_manager();
222 channel_selector->sync_with_manager();
223 file_notebook->sync_with_manager ();
229 ExportDialog::update_warnings ()
234 warn_label.set_markup (warn_string);
236 list_files_hbox.hide ();
237 list_files_string = "";
239 fast_export_button->set_sensitive (true);
240 //rt_export_button->set_sensitive (true);
242 /* Add new warnings */
244 boost::shared_ptr<ExportProfileManager::Warnings> warnings = profile_manager->get_warnings();
246 for (std::list<Glib::ustring>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
250 for (std::list<Glib::ustring>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
254 if (!warnings->conflicting_filenames.empty()) {
255 list_files_hbox.show ();
256 for (std::list<Glib::ustring>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
257 Glib::ustring::size_type pos = it->find_last_of ("/");
258 list_files_string += "\n" + it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>";
264 ExportDialog::show_conflicting_files ()
266 ArdourDialog dialog (_("Files that will be overwritten"), true);
268 Gtk::Label label ("", Gtk::ALIGN_LEFT);
269 label.set_use_markup (true);
270 label.set_markup (list_files_string);
272 dialog.get_vbox()->pack_start (label);
273 dialog.add_button (Gtk::Stock::OK, 0);
274 dialog.show_all_children ();
280 ExportDialog::export_rt ()
282 profile_manager->prepare_for_export ();
283 handler->do_export (true);
288 ExportDialog::export_fw ()
290 profile_manager->prepare_for_export ();
291 handler->do_export (false);
296 ExportDialog::show_progress ()
298 status->running = true;
300 cancel_button->set_label (_("Stop Export"));
301 //rt_export_button->set_sensitive (false);
302 fast_export_button->set_sensitive (false);
304 progress_bar.set_fraction (0.0);
305 warning_widget.hide_all();
306 progress_widget.show ();
307 progress_widget.show_all_children ();
308 progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
310 gtk_main_iteration ();
311 while (status->running) {
312 if (gtk_events_pending()) {
313 gtk_main_iteration ();
319 if (!status->aborted()) {
325 ExportDialog::progress_timeout ()
327 switch (status->stage) {
329 progress_label.set_text ("");
331 case export_ReadTimespan:
332 progress_label.set_text (string_compose (_("Reading timespan %1 of %2"), status->timespan, status->total_timespans));
334 case export_PostProcess:
335 progress_label.set_text (string_compose (_("Processing file %2 of %3 (%1) from timespan %4 of %5"),
336 file_notebook->get_nth_format_name (status->format),
337 status->format, status->total_formats,
338 status->timespan, status->total_timespans));
341 progress_label.set_text (string_compose (_("Encoding file %2 of %3 (%1) from timespan %4 of %5"),
342 file_notebook->get_nth_format_name (status->format),
343 status->format, status->total_formats,
344 status->timespan, status->total_timespans));
348 progress_bar.set_fraction (status->progress);
353 ExportDialog::add_error (Glib::ustring const & text)
355 fast_export_button->set_sensitive (false);
356 //rt_export_button->set_sensitive (false);
358 if (warn_string.empty()) {
359 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
361 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
364 warn_label.set_markup (warn_string);
368 ExportDialog::add_warning (Glib::ustring const & text)
370 if (warn_string.empty()) {
371 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
373 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
376 warn_label.set_markup (warn_string);
379 /*** Dialog specializations ***/
381 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, Glib::ustring range_id) :
382 ExportDialog (editor, _("Export Range")),
387 ExportRangeDialog::init_components ()
389 preset_selector.reset (new ExportPresetSelector ());
390 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, range_id));
391 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
392 file_notebook.reset (new ExportFileNotebook ());
395 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
396 ExportDialog (editor, _("Export Selection"))
400 ExportSelectionDialog::init_components ()
402 preset_selector.reset (new ExportPresetSelector ());
403 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, X_("selection")));
404 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
405 file_notebook.reset (new ExportFileNotebook ());
408 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
409 ExportDialog (editor, _("Export Region")),
415 ExportRegionDialog::init_gui ()
417 ExportDialog::init_gui ();
419 channels_label->set_text (_("Source"));
423 ExportRegionDialog::init_components ()
425 Glib::ustring loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
427 preset_selector.reset (new ExportPresetSelector ());
428 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, loc_id));
429 channel_selector.reset (new RegionExportChannelSelector (_session, profile_manager, region, track));
430 file_notebook.reset (new ExportFileNotebook ());