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"
32 using namespace ARDOUR;
35 ExportDialog::ExportDialog (PublicEditor & editor, Glib::ustring title) :
39 warn_label ("", Gtk::ALIGN_LEFT),
40 list_files_label (_("<span color=\"#ffa755\">Some already existing files will be overwritten.</span>"), Gtk::ALIGN_RIGHT),
41 list_files_button (_("List files"))
44 ExportDialog::~ExportDialog ()
48 ExportDialog::set_session (ARDOUR::Session* s)
50 SessionHandlePtr::set_session (s);
56 /* Init handler and profile manager */
58 handler = _session->get_export_handler ();
59 status = _session->get_export_status ();
60 profile_manager.reset (new ExportProfileManager (*_session));
62 /* Possibly init stuff in derived classes */
66 /* Rest of _session related initialization */
68 preset_selector->set_manager (profile_manager);
69 file_notebook->set_session_and_manager (_session, profile_manager);
71 /* Hand on selection range to profile manager */
73 TimeSelection const & time (editor.get_selection().time);
75 profile_manager->set_selection_range (time.front().start, time.front().end);
77 profile_manager->set_selection_range ();
82 profile_manager->load_profile ();
87 preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
88 timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
89 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
90 file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
92 status->Aborting.connect (abort_connection, boost::bind (&ExportDialog::notify_errors, this), gui_context());
105 warning_widget.pack_start (warn_hbox, true, true, 6);
106 warning_widget.pack_end (list_files_hbox, false, false, 0);
108 warn_hbox.pack_start (warn_label, true, true, 16);
109 warn_label.set_use_markup (true);
111 list_files_hbox.pack_end (list_files_button, false, false, 6);
112 list_files_hbox.pack_end (list_files_label, false, false, 6);
113 list_files_label.set_use_markup (true);
115 list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
117 /* Progress indicators */
119 progress_widget.pack_start (progress_label, false, false, 6);
120 progress_widget.pack_start (progress_bar, false, false, 6);
124 cancel_button = add_button (Gtk::Stock::CANCEL, RESPONSE_CANCEL);
125 rt_export_button = add_button (_("Realtime Export"), RESPONSE_RT);
126 fast_export_button = add_button (_("Fast Export"), RESPONSE_FAST);
128 list_files_button.set_name ("PaddedButton");
130 cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::close_dialog));
131 rt_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_rt));
132 fast_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_fw));
136 show_all_children ();
137 progress_widget.hide_all();
141 ExportDialog::init_gui ()
143 Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
144 preset_align->add (*preset_selector);
145 preset_align->set_padding (0, 12, 0, 0);
146 get_vbox()->pack_start (*preset_align, false, false, 0);
148 Gtk::VBox* advanced_vbox = Gtk::manage (new Gtk::VBox());
149 advanced_vbox->set_spacing (12);
150 advanced_vbox->set_border_width (12);
152 Gtk::Alignment * timespan_align = Gtk::manage (new Gtk::Alignment());
153 timespan_label = Gtk::manage (new Gtk::Label (_("Time Span"), Gtk::ALIGN_LEFT));
154 timespan_align->add (*timespan_selector);
155 timespan_align->set_padding (0, 12, 18, 0);
156 advanced_vbox->pack_start (*timespan_label, false, false, 0);
157 advanced_vbox->pack_start (*timespan_align, false, false, 0);
159 Gtk::Alignment * channels_align = Gtk::manage (new Gtk::Alignment());
160 channels_label = Gtk::manage (new Gtk::Label (_("Channels"), Gtk::ALIGN_LEFT));
161 channels_align->add (*channel_selector);
162 channels_align->set_padding (0, 12, 18, 0);
163 advanced_vbox->pack_start (*channels_label, false, false, 0);
164 advanced_vbox->pack_start (*channels_align, false, false, 0);
166 get_vbox()->pack_start (*file_notebook, false, false, 0);
167 get_vbox()->pack_start (warning_widget, false, false, 0);
168 get_vbox()->pack_start (progress_widget, false, false, 0);
170 Gtk::Expander* advanced = Gtk::manage (new Gtk::Expander (_("Advanced options")));
171 advanced->add (*advanced_vbox);
173 get_vbox()->pack_start (*advanced, false, false);
175 Pango::AttrList bold;
176 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
179 timespan_label->set_attributes (bold);
180 channels_label->set_attributes (bold);
184 ExportDialog::init_components ()
186 preset_selector.reset (new ExportPresetSelector ());
187 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
188 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
189 file_notebook.reset (new ExportFileNotebook ());
193 ExportDialog::notify_errors ()
195 if (status->errors()) {
196 Glib::ustring txt = _("Export has been aborted due to an error!\nSee the Log for details.");
197 Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
203 ExportDialog::close_dialog ()
205 if (status->running) {
215 ExportDialog::sync_with_manager ()
217 timespan_selector->sync_with_manager();
218 channel_selector->sync_with_manager();
219 file_notebook->sync_with_manager ();
225 ExportDialog::update_warnings ()
230 warn_label.set_markup (warn_string);
232 list_files_hbox.hide ();
233 list_files_string = "";
235 fast_export_button->set_sensitive (true);
236 rt_export_button->set_sensitive (true);
238 /* Add new warnings */
240 boost::shared_ptr<ExportProfileManager::Warnings> warnings = profile_manager->get_warnings();
242 for (std::list<Glib::ustring>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
246 for (std::list<Glib::ustring>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
250 if (!warnings->conflicting_filenames.empty()) {
251 list_files_hbox.show ();
252 for (std::list<Glib::ustring>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
253 Glib::ustring::size_type pos = it->find_last_of ("/");
254 list_files_string += "\n" + it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>";
260 ExportDialog::show_conflicting_files ()
262 ArdourDialog dialog (_("Files that will be overwritten"), true);
264 Gtk::Label label ("", Gtk::ALIGN_LEFT);
265 label.set_use_markup (true);
266 label.set_markup (list_files_string);
268 dialog.get_vbox()->pack_start (label);
269 dialog.add_button (Gtk::Stock::OK, 0);
270 dialog.show_all_children ();
276 ExportDialog::export_rt ()
278 profile_manager->prepare_for_export ();
279 handler->do_export (true);
284 ExportDialog::export_fw ()
286 profile_manager->prepare_for_export ();
287 handler->do_export (false);
292 ExportDialog::show_progress ()
294 status->running = true;
296 cancel_button->set_label (_("Stop Export"));
297 rt_export_button->set_sensitive (false);
298 fast_export_button->set_sensitive (false);
300 progress_bar.set_fraction (0.0);
301 warning_widget.hide_all();
302 progress_widget.show ();
303 progress_widget.show_all_children ();
304 progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
306 gtk_main_iteration ();
307 while (status->running) {
308 if (gtk_events_pending()) {
309 gtk_main_iteration ();
317 ExportDialog::progress_timeout ()
319 switch (status->stage) {
321 progress_label.set_text ("");
323 case export_ReadTimespan:
324 progress_label.set_text (string_compose (_("Reading timespan %1 of %2"), status->timespan, status->total_timespans));
326 case export_PostProcess:
327 progress_label.set_text (string_compose (_("Processing file %2 of %3 (%1) from timespan %4 of %5"),
328 file_notebook->get_nth_format_name (status->format),
329 status->format, status->total_formats,
330 status->timespan, status->total_timespans));
333 progress_label.set_text (string_compose (_("Encoding file %2 of %3 (%1) from timespan %4 of %5"),
334 file_notebook->get_nth_format_name (status->format),
335 status->format, status->total_formats,
336 status->timespan, status->total_timespans));
340 progress_bar.set_fraction (status->progress);
345 ExportDialog::add_error (Glib::ustring const & text)
347 fast_export_button->set_sensitive (false);
348 rt_export_button->set_sensitive (false);
350 if (warn_string.empty()) {
351 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
353 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
356 warn_label.set_markup (warn_string);
360 ExportDialog::add_warning (Glib::ustring const & text)
362 if (warn_string.empty()) {
363 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
365 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
368 warn_label.set_markup (warn_string);
371 /*** Dialog specializations ***/
373 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, Glib::ustring range_id) :
374 ExportDialog (editor, _("Export Range")),
379 ExportRangeDialog::init_components ()
381 preset_selector.reset (new ExportPresetSelector ());
382 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, range_id));
383 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
384 file_notebook.reset (new ExportFileNotebook ());
387 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
388 ExportDialog (editor, _("Export Selection"))
392 ExportSelectionDialog::init_components ()
394 preset_selector.reset (new ExportPresetSelector ());
395 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, X_("selection")));
396 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
397 file_notebook.reset (new ExportFileNotebook ());
400 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
401 ExportDialog (editor, _("Export Region")),
407 ExportRegionDialog::init_gui ()
409 ExportDialog::init_gui ();
411 channels_label->set_text (_("Source"));
415 ExportRegionDialog::init_components ()
417 Glib::ustring loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
419 preset_selector.reset (new ExportPresetSelector ());
420 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, loc_id));
421 channel_selector.reset (new RegionExportChannelSelector (_session, profile_manager, region, track));
422 file_notebook.reset (new ExportFileNotebook ());