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.
21 #include "export_dialog.h"
23 #include <sigc++/signal.h>
25 #include "pbd/filesystem.h"
27 #include "ardour/export_status.h"
28 #include "ardour/export_handler.h"
30 using namespace ARDOUR;
33 ExportDialog::ExportDialog (PublicEditor & editor, Glib::ustring title) :
37 warn_label ("", Gtk::ALIGN_LEFT),
38 list_files_label (_("<span color=\"#ffa755\">Some already existing files will be overwritten.</span>"), Gtk::ALIGN_RIGHT),
39 list_files_button (_("List files"))
42 ExportDialog::~ExportDialog ()
46 ExportDialog::set_session (ARDOUR::Session* s)
50 /* Init handler and profile manager */
52 handler = session->get_export_handler ();
53 status = session->get_export_status ();
54 profile_manager.reset (new ExportProfileManager (*session));
56 /* Possibly init stuff in derived classes */
60 /* Rest of session related initialization */
62 preset_selector->set_manager (profile_manager);
63 file_notebook->set_session_and_manager (session, profile_manager);
65 /* Hand on selection range to profile manager */
67 TimeSelection const & time (editor.get_selection().time);
69 profile_manager->set_selection_range (time.front().start, time.front().end);
71 profile_manager->set_selection_range ();
76 profile_manager->load_profile ();
81 preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
82 timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
83 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
84 file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
85 status->Aborting.connect (sigc::mem_fun (*this, &ExportDialog::notify_errors));
98 warning_widget.pack_start (warn_hbox, true, true, 6);
99 warning_widget.pack_end (list_files_hbox, false, false, 0);
101 warn_hbox.pack_start (warn_label, true, true, 16);
102 warn_label.set_use_markup (true);
104 list_files_hbox.pack_end (list_files_button, false, false, 6);
105 list_files_hbox.pack_end (list_files_label, false, false, 6);
106 list_files_label.set_use_markup (true);
108 list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
110 /* Progress indicators */
112 progress_widget.pack_start (progress_label, false, false, 6);
113 progress_widget.pack_start (progress_bar, false, false, 6);
117 cancel_button = add_button (Gtk::Stock::CANCEL, RESPONSE_CANCEL);
118 rt_export_button = add_button (_("Realtime Export"), RESPONSE_RT);
119 fast_export_button = add_button (_("Fast Export"), RESPONSE_FAST);
121 list_files_button.set_name ("PaddedButton");
123 cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::close_dialog));
124 rt_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_rt));
125 fast_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_fw));
129 show_all_children ();
130 progress_widget.hide_all();
134 ExportDialog::init_gui ()
136 Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
137 preset_align->add (*preset_selector);
138 preset_align->set_padding (0, 12, 0, 0);
139 get_vbox()->pack_start (*preset_align, false, false, 0);
141 Gtk::Alignment * timespan_align = Gtk::manage (new Gtk::Alignment());
142 timespan_label = Gtk::manage (new Gtk::Label (_("Time Span"), Gtk::ALIGN_LEFT));
143 timespan_align->add (*timespan_selector);
144 timespan_align->set_padding (0, 12, 18, 0);
145 get_vbox()->pack_start (*timespan_label, false, false, 0);
146 get_vbox()->pack_start (*timespan_align, false, false, 0);
148 Gtk::Alignment * channels_align = Gtk::manage (new Gtk::Alignment());
149 channels_label = Gtk::manage (new Gtk::Label (_("Channels"), Gtk::ALIGN_LEFT));
150 channels_align->add (*channel_selector);
151 channels_align->set_padding (0, 12, 18, 0);
152 get_vbox()->pack_start (*channels_label, false, false, 0);
153 get_vbox()->pack_start (*channels_align, false, false, 0);
155 get_vbox()->pack_start (*file_notebook, false, false, 0);
156 get_vbox()->pack_start (warning_widget, true, true, 0);
157 get_vbox()->pack_start (progress_widget, true, true, 0);
159 Pango::AttrList bold;
160 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
163 timespan_label->set_attributes (bold);
164 channels_label->set_attributes (bold);
168 ExportDialog::init_components ()
170 preset_selector.reset (new ExportPresetSelector ());
171 timespan_selector.reset (new ExportTimespanSelectorMultiple (session, profile_manager));
172 channel_selector.reset (new PortExportChannelSelector (session, profile_manager));
173 file_notebook.reset (new ExportFileNotebook ());
177 ExportDialog::notify_errors ()
179 if (status->errors()) {
180 Glib::ustring txt = _("Export has been aborted due to an error!\nSee the Log for details.");
181 Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
187 ExportDialog::close_dialog ()
189 if (status->running) {
199 ExportDialog::sync_with_manager ()
201 timespan_selector->sync_with_manager();
202 channel_selector->sync_with_manager();
203 file_notebook->sync_with_manager ();
209 ExportDialog::update_warnings ()
214 warn_label.set_markup (warn_string);
216 list_files_hbox.hide ();
217 list_files_string = "";
219 fast_export_button->set_sensitive (true);
220 rt_export_button->set_sensitive (true);
222 /* Add new warnings */
224 boost::shared_ptr<ExportProfileManager::Warnings> warnings = profile_manager->get_warnings();
226 for (std::list<Glib::ustring>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
230 for (std::list<Glib::ustring>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
234 if (!warnings->conflicting_filenames.empty()) {
235 list_files_hbox.show ();
236 for (std::list<Glib::ustring>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
237 Glib::ustring::size_type pos = it->find_last_of ("/");
238 list_files_string += "\n" + it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>";
244 ExportDialog::show_conflicting_files ()
246 ArdourDialog dialog (_("Files that will be overwritten"), true);
248 Gtk::Label label ("", Gtk::ALIGN_LEFT);
249 label.set_use_markup (true);
250 label.set_markup (list_files_string);
252 dialog.get_vbox()->pack_start (label);
253 dialog.add_button (Gtk::Stock::OK, 0);
254 dialog.show_all_children ();
260 ExportDialog::export_rt ()
262 profile_manager->prepare_for_export ();
263 handler->do_export (true);
268 ExportDialog::export_fw ()
270 profile_manager->prepare_for_export ();
271 handler->do_export (false);
276 ExportDialog::show_progress ()
278 status->running = true;
280 cancel_button->set_label (_("Stop Export"));
281 rt_export_button->set_sensitive (false);
282 fast_export_button->set_sensitive (false);
284 progress_bar.set_fraction (0.0);
285 warning_widget.hide_all();
286 progress_widget.show ();
287 progress_widget.show_all_children ();
288 progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
290 gtk_main_iteration ();
291 while (status->running) {
292 if (gtk_events_pending()) {
293 gtk_main_iteration ();
301 ExportDialog::progress_timeout ()
303 switch (status->stage) {
305 progress_label.set_text ("");
307 case export_ReadTimespan:
308 progress_label.set_text (string_compose (_("Reading timespan %1 of %2"), status->timespan, status->total_timespans));
310 case export_PostProcess:
311 progress_label.set_text (string_compose (_("Processing file %2 of %3 (%1) from timespan %4 of %5"),
312 file_notebook->get_nth_format_name (status->format),
313 status->format, status->total_formats,
314 status->timespan, status->total_timespans));
317 progress_label.set_text (string_compose (_("Encoding file %2 of %3 (%1) from timespan %4 of %5"),
318 file_notebook->get_nth_format_name (status->format),
319 status->format, status->total_formats,
320 status->timespan, status->total_timespans));
324 progress_bar.set_fraction (status->progress);
329 ExportDialog::add_error (Glib::ustring const & text)
331 fast_export_button->set_sensitive (false);
332 rt_export_button->set_sensitive (false);
334 if (warn_string.empty()) {
335 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
337 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
340 warn_label.set_markup (warn_string);
344 ExportDialog::add_warning (Glib::ustring const & text)
346 if (warn_string.empty()) {
347 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
349 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
352 warn_label.set_markup (warn_string);
355 /*** Dialog specializations ***/
357 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, Glib::ustring range_id) :
358 ExportDialog (editor, _("Export Range")),
363 ExportRangeDialog::init_components ()
365 preset_selector.reset (new ExportPresetSelector ());
366 timespan_selector.reset (new ExportTimespanSelectorSingle (session, profile_manager, range_id));
367 channel_selector.reset (new PortExportChannelSelector (session, profile_manager));
368 file_notebook.reset (new ExportFileNotebook ());
371 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
372 ExportDialog (editor, _("Export Selection"))
376 ExportSelectionDialog::init_components ()
378 preset_selector.reset (new ExportPresetSelector ());
379 timespan_selector.reset (new ExportTimespanSelectorSingle (session, profile_manager, X_("selection")));
380 channel_selector.reset (new PortExportChannelSelector (session, profile_manager));
381 file_notebook.reset (new ExportFileNotebook ());
384 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
385 ExportDialog (editor, _("Export Region")),
391 ExportRegionDialog::init_gui ()
393 ExportDialog::init_gui ();
395 channels_label->set_text (_("Source"));
399 ExportRegionDialog::init_components ()
401 Glib::ustring loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
403 preset_selector.reset (new ExportPresetSelector ());
404 timespan_selector.reset (new ExportTimespanSelectorSingle (session, profile_manager, loc_id));
405 channel_selector.reset (new RegionExportChannelSelector (session, profile_manager, region, track));
406 file_notebook.reset (new ExportFileNotebook ());