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::VBox* advanced_vbox = Gtk::manage (new Gtk::VBox());
142 advanced_vbox->set_spacing (12);
143 advanced_vbox->set_border_width (12);
145 Gtk::Alignment * timespan_align = Gtk::manage (new Gtk::Alignment());
146 timespan_label = Gtk::manage (new Gtk::Label (_("Time Span"), Gtk::ALIGN_LEFT));
147 timespan_align->add (*timespan_selector);
148 timespan_align->set_padding (0, 12, 18, 0);
149 advanced_vbox->pack_start (*timespan_label, false, false, 0);
150 advanced_vbox->pack_start (*timespan_align, false, false, 0);
152 Gtk::Alignment * channels_align = Gtk::manage (new Gtk::Alignment());
153 channels_label = Gtk::manage (new Gtk::Label (_("Channels"), Gtk::ALIGN_LEFT));
154 channels_align->add (*channel_selector);
155 channels_align->set_padding (0, 12, 18, 0);
156 advanced_vbox->pack_start (*channels_label, false, false, 0);
157 advanced_vbox->pack_start (*channels_align, false, false, 0);
159 get_vbox()->pack_start (*file_notebook, false, false, 0);
160 get_vbox()->pack_start (warning_widget, false, false, 0);
161 get_vbox()->pack_start (progress_widget, false, false, 0);
163 Gtk::Expander* advanced = Gtk::manage (new Gtk::Expander (_("Advanced options")));
164 advanced->add (*advanced_vbox);
166 get_vbox()->pack_start (*advanced, false, false);
168 Pango::AttrList bold;
169 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
172 timespan_label->set_attributes (bold);
173 channels_label->set_attributes (bold);
177 ExportDialog::init_components ()
179 preset_selector.reset (new ExportPresetSelector ());
180 timespan_selector.reset (new ExportTimespanSelectorMultiple (session, profile_manager));
181 channel_selector.reset (new PortExportChannelSelector (session, profile_manager));
182 file_notebook.reset (new ExportFileNotebook ());
186 ExportDialog::notify_errors ()
188 if (status->errors()) {
189 Glib::ustring txt = _("Export has been aborted due to an error!\nSee the Log for details.");
190 Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
196 ExportDialog::close_dialog ()
198 if (status->running) {
208 ExportDialog::sync_with_manager ()
210 timespan_selector->sync_with_manager();
211 channel_selector->sync_with_manager();
212 file_notebook->sync_with_manager ();
218 ExportDialog::update_warnings ()
223 warn_label.set_markup (warn_string);
225 list_files_hbox.hide ();
226 list_files_string = "";
228 fast_export_button->set_sensitive (true);
229 rt_export_button->set_sensitive (true);
231 /* Add new warnings */
233 boost::shared_ptr<ExportProfileManager::Warnings> warnings = profile_manager->get_warnings();
235 for (std::list<Glib::ustring>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
239 for (std::list<Glib::ustring>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
243 if (!warnings->conflicting_filenames.empty()) {
244 list_files_hbox.show ();
245 for (std::list<Glib::ustring>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
246 Glib::ustring::size_type pos = it->find_last_of ("/");
247 list_files_string += "\n" + it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>";
253 ExportDialog::show_conflicting_files ()
255 ArdourDialog dialog (_("Files that will be overwritten"), true);
257 Gtk::Label label ("", Gtk::ALIGN_LEFT);
258 label.set_use_markup (true);
259 label.set_markup (list_files_string);
261 dialog.get_vbox()->pack_start (label);
262 dialog.add_button (Gtk::Stock::OK, 0);
263 dialog.show_all_children ();
269 ExportDialog::export_rt ()
271 profile_manager->prepare_for_export ();
272 handler->do_export (true);
277 ExportDialog::export_fw ()
279 profile_manager->prepare_for_export ();
280 handler->do_export (false);
285 ExportDialog::show_progress ()
287 status->running = true;
289 cancel_button->set_label (_("Stop Export"));
290 rt_export_button->set_sensitive (false);
291 fast_export_button->set_sensitive (false);
293 progress_bar.set_fraction (0.0);
294 warning_widget.hide_all();
295 progress_widget.show ();
296 progress_widget.show_all_children ();
297 progress_connection = Glib::signal_timeout().connect (mem_fun(*this, &ExportDialog::progress_timeout), 100);
299 gtk_main_iteration ();
300 while (status->running) {
301 if (gtk_events_pending()) {
302 gtk_main_iteration ();
310 ExportDialog::progress_timeout ()
312 switch (status->stage) {
314 progress_label.set_text ("");
316 case export_ReadTimespan:
317 progress_label.set_text (string_compose (_("Reading timespan %1 of %2"), status->timespan, status->total_timespans));
319 case export_PostProcess:
320 progress_label.set_text (string_compose (_("Processing file %2 of %3 (%1) from timespan %4 of %5"),
321 file_notebook->get_nth_format_name (status->format),
322 status->format, status->total_formats,
323 status->timespan, status->total_timespans));
326 progress_label.set_text (string_compose (_("Encoding file %2 of %3 (%1) from timespan %4 of %5"),
327 file_notebook->get_nth_format_name (status->format),
328 status->format, status->total_formats,
329 status->timespan, status->total_timespans));
333 progress_bar.set_fraction (status->progress);
338 ExportDialog::add_error (Glib::ustring const & text)
340 fast_export_button->set_sensitive (false);
341 rt_export_button->set_sensitive (false);
343 if (warn_string.empty()) {
344 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
346 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
349 warn_label.set_markup (warn_string);
353 ExportDialog::add_warning (Glib::ustring const & text)
355 if (warn_string.empty()) {
356 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
358 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
361 warn_label.set_markup (warn_string);
364 /*** Dialog specializations ***/
366 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, Glib::ustring range_id) :
367 ExportDialog (editor, _("Export Range")),
372 ExportRangeDialog::init_components ()
374 preset_selector.reset (new ExportPresetSelector ());
375 timespan_selector.reset (new ExportTimespanSelectorSingle (session, profile_manager, range_id));
376 channel_selector.reset (new PortExportChannelSelector (session, profile_manager));
377 file_notebook.reset (new ExportFileNotebook ());
380 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
381 ExportDialog (editor, _("Export Selection"))
385 ExportSelectionDialog::init_components ()
387 preset_selector.reset (new ExportPresetSelector ());
388 timespan_selector.reset (new ExportTimespanSelectorSingle (session, profile_manager, X_("selection")));
389 channel_selector.reset (new PortExportChannelSelector (session, profile_manager));
390 file_notebook.reset (new ExportFileNotebook ());
393 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
394 ExportDialog (editor, _("Export Region")),
400 ExportRegionDialog::init_gui ()
402 ExportDialog::init_gui ();
404 channels_label->set_text (_("Source"));
408 ExportRegionDialog::init_components ()
410 Glib::ustring loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
412 preset_selector.reset (new ExportPresetSelector ());
413 timespan_selector.reset (new ExportTimespanSelectorSingle (session, profile_manager, loc_id));
414 channel_selector.reset (new RegionExportChannelSelector (session, profile_manager, region, track));
415 file_notebook.reset (new ExportFileNotebook ());