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;
38 ExportDialog::ExportDialog (PublicEditor & editor, std::string title) :
42 warn_label ("", Gtk::ALIGN_LEFT),
43 list_files_label (_("<span color=\"#ffa755\">Some already existing files will be overwritten.</span>"), Gtk::ALIGN_RIGHT),
44 list_files_button (_("List files"))
47 ExportDialog::~ExportDialog ()
51 ExportDialog::set_session (ARDOUR::Session* s)
53 SessionHandlePtr::set_session (s);
59 /* Init handler and profile manager */
61 handler = _session->get_export_handler ();
62 status = _session->get_export_status ();
63 profile_manager.reset (new ExportProfileManager (*_session));
65 /* Possibly init stuff in derived classes */
69 /* Rest of _session related initialization */
71 preset_selector->set_manager (profile_manager);
72 file_notebook->set_session_and_manager (_session, profile_manager);
74 /* Hand on selection range to profile manager */
76 TimeSelection const & time (editor.get_selection().time);
78 profile_manager->set_selection_range (time.front().start, time.front().end);
80 profile_manager->set_selection_range ();
85 profile_manager->load_profile ();
90 preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
91 timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
92 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
93 file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
95 status->Aborting.connect (abort_connection, invalidator (*this), boost::bind (&ExportDialog::notify_errors, this), gui_context());
101 ExportDialog::init ()
108 warning_widget.pack_start (warn_hbox, true, true, 6);
109 warning_widget.pack_end (list_files_hbox, false, false, 0);
111 warn_hbox.pack_start (warn_label, true, true, 16);
112 warn_label.set_use_markup (true);
114 list_files_hbox.pack_end (list_files_button, false, false, 6);
115 list_files_hbox.pack_end (list_files_label, false, false, 6);
116 list_files_label.set_use_markup (true);
118 list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
120 /* Progress indicators */
122 progress_widget.pack_start (progress_label, false, false, 6);
123 progress_widget.pack_start (progress_bar, false, false, 6);
127 cancel_button = add_button (Gtk::Stock::CANCEL, RESPONSE_CANCEL);
128 // Realtime export is disabled for now, as it will most probably not work
129 //rt_export_button = add_button (_("Realtime Export"), RESPONSE_RT);
130 //fast_export_button = add_button (_("Fast Export"), RESPONSE_FAST);
131 fast_export_button = add_button (_("Export"), RESPONSE_FAST);
133 list_files_button.set_name ("PaddedButton");
135 cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::close_dialog));
136 //rt_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_rt));
137 fast_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_fw));
141 show_all_children ();
142 progress_widget.hide_all();
146 ExportDialog::init_gui ()
148 Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
149 preset_align->add (*preset_selector);
150 preset_align->set_padding (0, 12, 0, 0);
151 get_vbox()->pack_start (*preset_align, false, false, 0);
153 Gtk::VBox* advanced_vbox = Gtk::manage (new Gtk::VBox());
154 advanced_vbox->set_spacing (12);
155 advanced_vbox->set_border_width (12);
157 Gtk::Alignment * timespan_align = Gtk::manage (new Gtk::Alignment());
158 timespan_label = Gtk::manage (new Gtk::Label (_("Time Span"), Gtk::ALIGN_LEFT));
159 timespan_align->add (*timespan_selector);
160 timespan_align->set_padding (0, 12, 18, 0);
161 advanced_vbox->pack_start (*timespan_label, false, false, 0);
162 advanced_vbox->pack_start (*timespan_align, false, false, 0);
164 Gtk::Alignment * channels_align = Gtk::manage (new Gtk::Alignment());
165 channels_label = Gtk::manage (new Gtk::Label (_("Channels"), Gtk::ALIGN_LEFT));
166 channels_align->add (*channel_selector);
167 channels_align->set_padding (0, 12, 18, 0);
168 advanced_vbox->pack_start (*channels_label, false, false, 0);
169 advanced_vbox->pack_start (*channels_align, false, false, 0);
171 get_vbox()->pack_start (*file_notebook, false, false, 0);
172 get_vbox()->pack_start (warning_widget, false, false, 0);
173 get_vbox()->pack_start (progress_widget, false, false, 0);
175 Gtk::Expander* advanced = Gtk::manage (new Gtk::Expander (_("Advanced options")));
176 advanced->add (*advanced_vbox);
178 get_vbox()->pack_start (*advanced, false, false);
180 Pango::AttrList bold;
181 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
184 timespan_label->set_attributes (bold);
185 channels_label->set_attributes (bold);
189 ExportDialog::init_components ()
191 preset_selector.reset (new ExportPresetSelector ());
192 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
193 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
194 file_notebook.reset (new ExportFileNotebook ());
198 ExportDialog::notify_errors ()
200 if (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 ();
230 ExportDialog::update_warnings ()
235 warn_label.set_markup (warn_string);
237 list_files_hbox.hide ();
238 list_files_string = "";
240 fast_export_button->set_sensitive (true);
241 //rt_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 += "\n" + it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>";
265 ExportDialog::show_conflicting_files ()
267 ArdourDialog dialog (_("Files that will be overwritten"), true);
269 Gtk::Label label ("", Gtk::ALIGN_LEFT);
270 label.set_use_markup (true);
271 label.set_markup (list_files_string);
273 dialog.get_vbox()->pack_start (label);
274 dialog.add_button (Gtk::Stock::OK, 0);
275 dialog.show_all_children ();
281 ExportDialog::export_rt ()
283 profile_manager->prepare_for_export ();
284 handler->do_export (true);
289 ExportDialog::export_fw ()
291 profile_manager->prepare_for_export ();
292 handler->do_export (false);
297 ExportDialog::show_progress ()
299 status->running = true;
301 cancel_button->set_label (_("Stop Export"));
302 //rt_export_button->set_sensitive (false);
303 fast_export_button->set_sensitive (false);
305 progress_bar.set_fraction (0.0);
306 warning_widget.hide_all();
307 progress_widget.show ();
308 progress_widget.show_all_children ();
309 progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
311 gtk_main_iteration ();
312 while (status->running) {
313 if (gtk_events_pending()) {
314 gtk_main_iteration ();
320 if (!status->aborted()) {
326 ExportDialog::progress_timeout ()
328 switch (status->stage) {
330 progress_label.set_text ("");
332 case export_ReadTimespan:
333 progress_label.set_text (string_compose (_("Reading timespan %1 of %2"), status->timespan, status->total_timespans));
335 case export_PostProcess:
336 progress_label.set_text (string_compose (_("Processing file %2 of %3 (%1) from timespan %4 of %5"),
337 file_notebook->get_nth_format_name (status->format),
338 status->format, status->total_formats,
339 status->timespan, status->total_timespans));
342 progress_label.set_text (string_compose (_("Encoding file %2 of %3 (%1) from timespan %4 of %5"),
343 file_notebook->get_nth_format_name (status->format),
344 status->format, status->total_formats,
345 status->timespan, status->total_timespans));
349 progress_bar.set_fraction (status->progress);
354 ExportDialog::add_error (string const & text)
356 fast_export_button->set_sensitive (false);
357 //rt_export_button->set_sensitive (false);
359 if (warn_string.empty()) {
360 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
362 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
365 warn_label.set_markup (warn_string);
369 ExportDialog::add_warning (string const & text)
371 if (warn_string.empty()) {
372 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
374 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
377 warn_label.set_markup (warn_string);
380 /*** Dialog specializations ***/
382 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, string range_id) :
383 ExportDialog (editor, _("Export Range")),
388 ExportRangeDialog::init_components ()
390 preset_selector.reset (new ExportPresetSelector ());
391 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, range_id));
392 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
393 file_notebook.reset (new ExportFileNotebook ());
396 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
397 ExportDialog (editor, _("Export Selection"))
401 ExportSelectionDialog::init_components ()
403 preset_selector.reset (new ExportPresetSelector ());
404 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, X_("selection")));
405 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
406 file_notebook.reset (new ExportFileNotebook ());
409 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
410 ExportDialog (editor, _("Export Region")),
416 ExportRegionDialog::init_gui ()
418 ExportDialog::init_gui ();
420 channels_label->set_text (_("Source"));
424 ExportRegionDialog::init_components ()
426 string loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
428 preset_selector.reset (new ExportPresetSelector ());
429 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, loc_id));
430 channel_selector.reset (new RegionExportChannelSelector (_session, profile_manager, region, track));
431 file_notebook.reset (new ExportFileNotebook ());