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/audioregion.h"
27 #include "ardour/export_status.h"
28 #include "ardour/export_handler.h"
30 #include "export_dialog.h"
31 #include "gui_thread.h"
35 using namespace ARDOUR;
39 ExportDialog::ExportDialog (PublicEditor & editor, std::string title, std::string xml_node_name)
40 : ArdourDialog (title)
41 , xml_node_name (xml_node_name)
44 , warn_label ("", Gtk::ALIGN_LEFT)
45 , list_files_label (_("<span color=\"#ffa755\">Some already existing files will be overwritten.</span>"), Gtk::ALIGN_RIGHT)
46 , list_files_button (_("List files"))
49 ExportDialog::~ExportDialog ()
53 ExportDialog::set_session (ARDOUR::Session* s)
55 SessionHandlePtr::set_session (s);
61 /* Init handler and profile manager */
63 handler = _session->get_export_handler ();
64 status = _session->get_export_status ();
66 profile_manager.reset (new ExportProfileManager (*_session, xml_node_name));
68 /* Possibly init stuff in derived classes */
72 /* Rest of _session related initialization */
74 preset_selector->set_manager (profile_manager);
75 file_notebook->set_session_and_manager (_session, profile_manager);
77 /* Hand on selection range to profile manager */
79 TimeSelection const & time (editor.get_selection().time);
81 profile_manager->set_selection_range (time.front().start, time.front().end);
83 profile_manager->set_selection_range ();
88 profile_manager->load_profile ();
93 preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
94 timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
95 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
96 file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
98 status->Aborting.connect (abort_connection, invalidator (*this), boost::bind (&ExportDialog::notify_errors, this), gui_context());
100 update_warnings_and_example_filename ();
104 ExportDialog::init ()
111 warning_widget.pack_start (warn_hbox, true, true, 6);
112 warning_widget.pack_end (list_files_hbox, false, false, 0);
114 warn_hbox.pack_start (warn_label, true, true, 16);
115 warn_label.set_use_markup (true);
117 list_files_hbox.pack_end (list_files_button, false, false, 6);
118 list_files_hbox.pack_end (list_files_label, false, false, 6);
119 list_files_label.set_use_markup (true);
121 list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
123 /* Progress indicators */
125 progress_widget.pack_start (progress_bar, false, false, 6);
129 cancel_button = add_button (Gtk::Stock::CANCEL, RESPONSE_CANCEL);
130 // Realtime export is disabled for now, as it will most probably not work
131 //rt_export_button = add_button (_("Realtime Export"), RESPONSE_RT);
132 //fast_export_button = add_button (_("Fast Export"), RESPONSE_FAST);
133 fast_export_button = add_button (_("Export"), RESPONSE_FAST);
134 set_default_response (RESPONSE_FAST);
136 list_files_button.set_name ("PaddedButton");
138 cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::close_dialog));
139 //rt_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_rt));
140 fast_export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::export_fw));
144 show_all_children ();
145 progress_widget.hide_all();
149 ExportDialog::expanded_changed ()
151 set_resizable(advanced->get_expanded());
155 ExportDialog::init_gui ()
157 Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
158 preset_align->add (*preset_selector);
159 preset_align->set_padding (0, 12, 0, 0);
160 get_vbox()->pack_start (*preset_align, false, false, 0);
162 Gtk::VPaned * advanced_paned = Gtk::manage (new Gtk::VPaned());
164 Gtk::VBox* timespan_vbox = Gtk::manage (new Gtk::VBox());
165 timespan_vbox->set_spacing (12);
166 timespan_vbox->set_border_width (12);
168 Gtk::Alignment * timespan_align = Gtk::manage (new Gtk::Alignment());
169 timespan_label = Gtk::manage (new Gtk::Label (_("Time Span"), Gtk::ALIGN_LEFT));
170 timespan_align->add (*timespan_selector);
171 timespan_align->set_padding (0, 0, 18, 0);
172 timespan_vbox->pack_start (*timespan_label, false, false, 0);
173 timespan_vbox->pack_start (*timespan_align, true, true, 0);
174 advanced_paned->pack1(*timespan_vbox, true, false);
176 Gtk::VBox* channels_vbox = Gtk::manage (new Gtk::VBox());
177 channels_vbox->set_spacing (12);
178 channels_vbox->set_border_width (12);
180 Gtk::Alignment * channels_align = Gtk::manage (new Gtk::Alignment());
181 channels_label = Gtk::manage (new Gtk::Label (_("Channels"), Gtk::ALIGN_LEFT));
182 channels_align->add (*channel_selector);
183 channels_align->set_padding (0, 12, 18, 0);
184 channels_vbox->pack_start (*channels_label, false, false, 0);
185 channels_vbox->pack_start (*channels_align, true, true, 0);
186 advanced_paned->pack2(*channels_vbox, channel_selector_is_expandable(), false);
188 get_vbox()->pack_start (*file_notebook, false, false, 0);
189 get_vbox()->pack_start (warning_widget, false, false, 0);
190 get_vbox()->pack_start (progress_widget, false, false, 0);
192 advanced = Gtk::manage (new Gtk::Expander (_("Advanced options")));
193 advanced->property_expanded().signal_changed().connect(
194 sigc::mem_fun(*this, &ExportDialog::expanded_changed));
195 advanced->add (*advanced_paned);
197 if (channel_selector_is_expandable()) {
198 advanced_sizegroup = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_VERTICAL);
199 advanced_sizegroup->add_widget(*timespan_selector);
200 advanced_sizegroup->add_widget(*channel_selector);
203 get_vbox()->pack_start (*advanced, true, true);
205 Pango::AttrList bold;
206 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
209 timespan_label->set_attributes (bold);
210 channels_label->set_attributes (bold);
214 ExportDialog::init_components ()
216 preset_selector.reset (new ExportPresetSelector ());
217 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
218 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
219 file_notebook.reset (new ExportFileNotebook ());
223 ExportDialog::notify_errors ()
225 if (status->errors()) {
226 std::string txt = _("Export has been aborted due to an error!\nSee the Log for details.");
227 Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
233 ExportDialog::close_dialog ()
235 if (status->running) {
245 ExportDialog::sync_with_manager ()
247 timespan_selector->sync_with_manager();
248 channel_selector->sync_with_manager();
249 file_notebook->sync_with_manager ();
251 update_warnings_and_example_filename ();
255 ExportDialog::update_warnings_and_example_filename ()
260 warn_label.set_markup (warn_string);
262 list_files_hbox.hide ();
263 list_files_string = "";
265 fast_export_button->set_sensitive (true);
266 //rt_export_button->set_sensitive (true);
268 /* Add new warnings */
270 boost::shared_ptr<ExportProfileManager::Warnings> warnings = profile_manager->get_warnings();
272 for (std::list<string>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
276 for (std::list<string>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
280 if (!warnings->conflicting_filenames.empty()) {
281 list_files_hbox.show ();
282 for (std::list<string>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
283 string::size_type pos = it->find_last_of ("/");
284 list_files_string += it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>\n";
288 /* Update example filename */
290 file_notebook->update_example_filenames();
294 ExportDialog::show_conflicting_files ()
296 ArdourDialog dialog (_("Files that will be overwritten"), true);
298 Gtk::Label label ("", Gtk::ALIGN_LEFT);
299 label.set_use_markup (true);
300 label.set_markup (list_files_string);
302 dialog.get_vbox()->pack_start (label);
303 dialog.add_button (Gtk::Stock::OK, 0);
304 dialog.show_all_children ();
310 ExportDialog::export_rt ()
312 profile_manager->prepare_for_export ();
313 handler->do_export (true);
318 ExportDialog::export_fw ()
320 profile_manager->prepare_for_export ();
321 handler->do_export (false);
326 ExportDialog::show_progress ()
328 status->running = true;
330 cancel_button->set_label (_("Stop Export"));
331 //rt_export_button->set_sensitive (false);
332 fast_export_button->set_sensitive (false);
334 progress_bar.set_fraction (0.0);
335 warning_widget.hide_all();
336 progress_widget.show ();
337 progress_widget.show_all_children ();
338 progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
340 gtk_main_iteration ();
341 while (status->running) {
342 if (gtk_events_pending()) {
343 gtk_main_iteration ();
349 if (!status->aborted()) {
355 ExportDialog::progress_timeout ()
357 std::string status_text;
358 float progress = 0.0;
359 if (status->normalizing) {
360 status_text = string_compose (_("Normalizing '%3' (timespan %1 of %2)"),
361 status->timespan, status->total_timespans, status->timespan_name);
362 progress = ((float) status->current_normalize_cycle) / status->total_normalize_cycles;
364 status_text = string_compose (_("Exporting '%3' (timespan %1 of %2)"),
365 status->timespan, status->total_timespans, status->timespan_name);
366 progress = ((float) status->processed_frames_current_timespan) / status->total_frames_current_timespan;
368 progress_bar.set_text (status_text);
370 if (progress < previous_progress) {
371 // Work around gtk bug
375 previous_progress = progress;
377 progress_bar.set_fraction (progress);
382 ExportDialog::add_error (string const & text)
384 fast_export_button->set_sensitive (false);
385 //rt_export_button->set_sensitive (false);
387 if (warn_string.empty()) {
388 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
390 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
393 warn_label.set_markup (warn_string);
397 ExportDialog::add_warning (string const & text)
399 if (warn_string.empty()) {
400 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
402 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
405 warn_label.set_markup (warn_string);
408 /*** Dialog specializations ***/
410 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, string range_id) :
411 ExportDialog (editor, _("Export Range"), X_("RangeExportProfile")),
416 ExportRangeDialog::init_components ()
418 preset_selector.reset (new ExportPresetSelector ());
419 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, range_id));
420 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
421 file_notebook.reset (new ExportFileNotebook ());
424 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
425 ExportDialog (editor, _("Export Selection"), X_("SelectionExportProfile"))
429 ExportSelectionDialog::init_components ()
431 preset_selector.reset (new ExportPresetSelector ());
432 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, X_("selection")));
433 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
434 file_notebook.reset (new ExportFileNotebook ());
437 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
438 ExportDialog (editor, _("Export Region"), X_("RegionExportProfile")),
444 ExportRegionDialog::init_gui ()
446 ExportDialog::init_gui ();
448 channels_label->set_text (_("Source"));
452 ExportRegionDialog::init_components ()
454 string loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
456 preset_selector.reset (new ExportPresetSelector ());
457 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, loc_id));
458 channel_selector.reset (new RegionExportChannelSelector (_session, profile_manager, region, track));
459 file_notebook.reset (new ExportFileNotebook ());
462 StemExportDialog::StemExportDialog (PublicEditor & editor)
463 : ExportDialog(editor, _("Stem Export"), X_("StemExportProfile"))
469 StemExportDialog::init_components ()
471 preset_selector.reset (new ExportPresetSelector ());
472 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
473 channel_selector.reset (new TrackExportChannelSelector (_session, profile_manager));
474 file_notebook.reset (new ExportFileNotebook ());