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)
48 SessionHandlePtr::set_session (s);
54 /* Init handler and profile manager */
56 handler = _session->get_export_handler ();
57 status = _session->get_export_status ();
58 profile_manager.reset (new ExportProfileManager (*_session));
60 /* Possibly init stuff in derived classes */
64 /* Rest of _session related initialization */
66 preset_selector->set_manager (profile_manager);
67 file_notebook->set_session_and_manager (_session, profile_manager);
69 /* Hand on selection range to profile manager */
71 TimeSelection const & time (editor.get_selection().time);
73 profile_manager->set_selection_range (time.front().start, time.front().end);
75 profile_manager->set_selection_range ();
80 profile_manager->load_profile ();
85 preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
86 timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
87 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
88 file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
89 status->Aborting.connect (sigc::mem_fun (*this, &ExportDialog::notify_errors));
102 warning_widget.pack_start (warn_hbox, true, true, 6);
103 warning_widget.pack_end (list_files_hbox, false, false, 0);
105 warn_hbox.pack_start (warn_label, true, true, 16);
106 warn_label.set_use_markup (true);
108 list_files_hbox.pack_end (list_files_button, false, false, 6);
109 list_files_hbox.pack_end (list_files_label, false, false, 6);
110 list_files_label.set_use_markup (true);
112 list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
114 /* Progress indicators */
116 progress_widget.pack_start (progress_label, false, false, 6);
117 progress_widget.pack_start (progress_bar, false, false, 6);
121 cancel_button = add_button (Gtk::Stock::CANCEL, RESPONSE_CANCEL);
122 rt_export_button = add_button (_("Realtime Export"), RESPONSE_RT);
123 fast_export_button = add_button (_("Fast Export"), RESPONSE_FAST);
125 list_files_button.set_name ("PaddedButton");
127 cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::close_dialog));
128 rt_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_rt));
129 fast_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_fw));
133 show_all_children ();
134 progress_widget.hide_all();
138 ExportDialog::init_gui ()
140 Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
141 preset_align->add (*preset_selector);
142 preset_align->set_padding (0, 12, 0, 0);
143 get_vbox()->pack_start (*preset_align, false, false, 0);
145 Gtk::VBox* advanced_vbox = Gtk::manage (new Gtk::VBox());
146 advanced_vbox->set_spacing (12);
147 advanced_vbox->set_border_width (12);
149 Gtk::Alignment * timespan_align = Gtk::manage (new Gtk::Alignment());
150 timespan_label = Gtk::manage (new Gtk::Label (_("Time Span"), Gtk::ALIGN_LEFT));
151 timespan_align->add (*timespan_selector);
152 timespan_align->set_padding (0, 12, 18, 0);
153 advanced_vbox->pack_start (*timespan_label, false, false, 0);
154 advanced_vbox->pack_start (*timespan_align, false, false, 0);
156 Gtk::Alignment * channels_align = Gtk::manage (new Gtk::Alignment());
157 channels_label = Gtk::manage (new Gtk::Label (_("Channels"), Gtk::ALIGN_LEFT));
158 channels_align->add (*channel_selector);
159 channels_align->set_padding (0, 12, 18, 0);
160 advanced_vbox->pack_start (*channels_label, false, false, 0);
161 advanced_vbox->pack_start (*channels_align, false, false, 0);
163 get_vbox()->pack_start (*file_notebook, false, false, 0);
164 get_vbox()->pack_start (warning_widget, false, false, 0);
165 get_vbox()->pack_start (progress_widget, false, false, 0);
167 Gtk::Expander* advanced = Gtk::manage (new Gtk::Expander (_("Advanced options")));
168 advanced->add (*advanced_vbox);
170 get_vbox()->pack_start (*advanced, false, false);
172 Pango::AttrList bold;
173 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
176 timespan_label->set_attributes (bold);
177 channels_label->set_attributes (bold);
181 ExportDialog::init_components ()
183 preset_selector.reset (new ExportPresetSelector ());
184 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
185 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
186 file_notebook.reset (new ExportFileNotebook ());
190 ExportDialog::notify_errors ()
192 if (status->errors()) {
193 Glib::ustring txt = _("Export has been aborted due to an error!\nSee the Log for details.");
194 Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
200 ExportDialog::close_dialog ()
202 if (status->running) {
212 ExportDialog::sync_with_manager ()
214 timespan_selector->sync_with_manager();
215 channel_selector->sync_with_manager();
216 file_notebook->sync_with_manager ();
222 ExportDialog::update_warnings ()
227 warn_label.set_markup (warn_string);
229 list_files_hbox.hide ();
230 list_files_string = "";
232 fast_export_button->set_sensitive (true);
233 rt_export_button->set_sensitive (true);
235 /* Add new warnings */
237 boost::shared_ptr<ExportProfileManager::Warnings> warnings = profile_manager->get_warnings();
239 for (std::list<Glib::ustring>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
243 for (std::list<Glib::ustring>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
247 if (!warnings->conflicting_filenames.empty()) {
248 list_files_hbox.show ();
249 for (std::list<Glib::ustring>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
250 Glib::ustring::size_type pos = it->find_last_of ("/");
251 list_files_string += "\n" + it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>";
257 ExportDialog::show_conflicting_files ()
259 ArdourDialog dialog (_("Files that will be overwritten"), true);
261 Gtk::Label label ("", Gtk::ALIGN_LEFT);
262 label.set_use_markup (true);
263 label.set_markup (list_files_string);
265 dialog.get_vbox()->pack_start (label);
266 dialog.add_button (Gtk::Stock::OK, 0);
267 dialog.show_all_children ();
273 ExportDialog::export_rt ()
275 profile_manager->prepare_for_export ();
276 handler->do_export (true);
281 ExportDialog::export_fw ()
283 profile_manager->prepare_for_export ();
284 handler->do_export (false);
289 ExportDialog::show_progress ()
291 status->running = true;
293 cancel_button->set_label (_("Stop Export"));
294 rt_export_button->set_sensitive (false);
295 fast_export_button->set_sensitive (false);
297 progress_bar.set_fraction (0.0);
298 warning_widget.hide_all();
299 progress_widget.show ();
300 progress_widget.show_all_children ();
301 progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
303 gtk_main_iteration ();
304 while (status->running) {
305 if (gtk_events_pending()) {
306 gtk_main_iteration ();
314 ExportDialog::progress_timeout ()
316 switch (status->stage) {
318 progress_label.set_text ("");
320 case export_ReadTimespan:
321 progress_label.set_text (string_compose (_("Reading timespan %1 of %2"), status->timespan, status->total_timespans));
323 case export_PostProcess:
324 progress_label.set_text (string_compose (_("Processing file %2 of %3 (%1) from timespan %4 of %5"),
325 file_notebook->get_nth_format_name (status->format),
326 status->format, status->total_formats,
327 status->timespan, status->total_timespans));
330 progress_label.set_text (string_compose (_("Encoding file %2 of %3 (%1) from timespan %4 of %5"),
331 file_notebook->get_nth_format_name (status->format),
332 status->format, status->total_formats,
333 status->timespan, status->total_timespans));
337 progress_bar.set_fraction (status->progress);
342 ExportDialog::add_error (Glib::ustring const & text)
344 fast_export_button->set_sensitive (false);
345 rt_export_button->set_sensitive (false);
347 if (warn_string.empty()) {
348 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
350 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
353 warn_label.set_markup (warn_string);
357 ExportDialog::add_warning (Glib::ustring const & text)
359 if (warn_string.empty()) {
360 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
362 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
365 warn_label.set_markup (warn_string);
368 /*** Dialog specializations ***/
370 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, Glib::ustring range_id) :
371 ExportDialog (editor, _("Export Range")),
376 ExportRangeDialog::init_components ()
378 preset_selector.reset (new ExportPresetSelector ());
379 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, range_id));
380 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
381 file_notebook.reset (new ExportFileNotebook ());
384 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
385 ExportDialog (editor, _("Export Selection"))
389 ExportSelectionDialog::init_components ()
391 preset_selector.reset (new ExportPresetSelector ());
392 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, X_("selection")));
393 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
394 file_notebook.reset (new ExportFileNotebook ());
397 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
398 ExportDialog (editor, _("Export Region")),
404 ExportRegionDialog::init_gui ()
406 ExportDialog::init_gui ();
408 channels_label->set_text (_("Source"));
412 ExportRegionDialog::init_components ()
414 Glib::ustring loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
416 preset_selector.reset (new ExportPresetSelector ());
417 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, loc_id));
418 channel_selector.reset (new RegionExportChannelSelector (_session, profile_manager, region, track));
419 file_notebook.reset (new ExportFileNotebook ());