Remove erroneous assert which I added earlier.
[ardour2.git] / gtk2_ardour / export_dialog.cc
blob50796f2fccd4bc092ebbcd00a806e7d8f8b7f88d
1 /*
2 Copyright (C) 2008 Paul Davis
3 Author: Sakari Bergen
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"
33 #include "i18n.h"
35 using namespace ARDOUR;
36 using namespace PBD;
37 using std::string;
39 ExportDialog::ExportDialog (PublicEditor & editor, std::string title, std::string xml_node_name)
40 : ArdourDialog (title)
41 , xml_node_name (xml_node_name)
42 , editor (editor)
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"))
47 { }
49 ExportDialog::~ExportDialog ()
50 { }
52 void
53 ExportDialog::set_session (ARDOUR::Session* s)
55 SessionHandlePtr::set_session (s);
57 if (!_session) {
58 return;
61 /* Init handler and profile manager */
63 handler = _session->get_export_handler ();
64 status = _session->get_export_status ();
65 profile_manager.reset (new ExportProfileManager (*_session, xml_node_name));
67 /* Possibly init stuff in derived classes */
69 init ();
71 /* Rest of _session related initialization */
73 preset_selector->set_manager (profile_manager);
74 file_notebook->set_session_and_manager (_session, profile_manager);
76 /* Hand on selection range to profile manager */
78 TimeSelection const & time (editor.get_selection().time);
79 if (!time.empty()) {
80 profile_manager->set_selection_range (time.front().start, time.front().end);
81 } else {
82 profile_manager->set_selection_range ();
85 /* Load states */
87 profile_manager->load_profile ();
88 sync_with_manager ();
90 /* Warnings */
92 preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
93 timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
94 channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
95 file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings));
97 status->Aborting.connect (abort_connection, invalidator (*this), boost::bind (&ExportDialog::notify_errors, this), gui_context());
99 update_warnings ();
102 void
103 ExportDialog::init ()
105 init_components ();
106 init_gui ();
108 /* warnings */
110 warning_widget.pack_start (warn_hbox, true, true, 6);
111 warning_widget.pack_end (list_files_hbox, false, false, 0);
113 warn_hbox.pack_start (warn_label, true, true, 16);
114 warn_label.set_use_markup (true);
116 list_files_hbox.pack_end (list_files_button, false, false, 6);
117 list_files_hbox.pack_end (list_files_label, false, false, 6);
118 list_files_label.set_use_markup (true);
120 list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
122 /* Progress indicators */
124 progress_widget.pack_start (progress_label, false, false, 6);
125 progress_widget.pack_start (progress_bar, false, false, 6);
127 /* Buttons */
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));
142 /* Done! */
144 show_all_children ();
145 progress_widget.hide_all();
148 void
149 ExportDialog::init_gui ()
151 Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
152 preset_align->add (*preset_selector);
153 preset_align->set_padding (0, 12, 0, 0);
154 get_vbox()->pack_start (*preset_align, false, false, 0);
156 Gtk::VBox* advanced_vbox = Gtk::manage (new Gtk::VBox());
157 advanced_vbox->set_spacing (12);
158 advanced_vbox->set_border_width (12);
160 Gtk::Alignment * timespan_align = Gtk::manage (new Gtk::Alignment());
161 timespan_label = Gtk::manage (new Gtk::Label (_("Time Span"), Gtk::ALIGN_LEFT));
162 timespan_align->add (*timespan_selector);
163 timespan_align->set_padding (0, 12, 18, 0);
164 advanced_vbox->pack_start (*timespan_label, false, false, 0);
165 advanced_vbox->pack_start (*timespan_align, false, false, 0);
167 Gtk::Alignment * channels_align = Gtk::manage (new Gtk::Alignment());
168 channels_label = Gtk::manage (new Gtk::Label (_("Channels"), Gtk::ALIGN_LEFT));
169 channels_align->add (*channel_selector);
170 channels_align->set_padding (0, 12, 18, 0);
171 advanced_vbox->pack_start (*channels_label, false, false, 0);
172 advanced_vbox->pack_start (*channels_align, false, false, 0);
174 get_vbox()->pack_start (*file_notebook, false, false, 0);
175 get_vbox()->pack_start (warning_widget, false, false, 0);
176 get_vbox()->pack_start (progress_widget, false, false, 0);
178 Gtk::Expander* advanced = Gtk::manage (new Gtk::Expander (_("Advanced options")));
179 advanced->add (*advanced_vbox);
181 get_vbox()->pack_start (*advanced, false, false);
183 Pango::AttrList bold;
184 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
185 bold.insert (b);
187 timespan_label->set_attributes (bold);
188 channels_label->set_attributes (bold);
191 void
192 ExportDialog::init_components ()
194 preset_selector.reset (new ExportPresetSelector ());
195 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
196 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
197 file_notebook.reset (new ExportFileNotebook ());
200 void
201 ExportDialog::notify_errors ()
203 if (status->errors()) {
204 std::string txt = _("Export has been aborted due to an error!\nSee the Log for details.");
205 Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
206 msg.run();
210 void
211 ExportDialog::close_dialog ()
213 if (status->running) {
214 status->abort();
217 hide_all ();
218 set_modal (false);
222 void
223 ExportDialog::sync_with_manager ()
225 timespan_selector->sync_with_manager();
226 channel_selector->sync_with_manager();
227 file_notebook->sync_with_manager ();
229 update_warnings ();
232 void
233 ExportDialog::update_warnings ()
235 /* Reset state */
237 warn_string = "";
238 warn_label.set_markup (warn_string);
240 list_files_hbox.hide ();
241 list_files_string = "";
243 fast_export_button->set_sensitive (true);
244 //rt_export_button->set_sensitive (true);
246 /* Add new warnings */
248 boost::shared_ptr<ExportProfileManager::Warnings> warnings = profile_manager->get_warnings();
250 for (std::list<string>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
251 add_error (*it);
254 for (std::list<string>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
255 add_warning (*it);
258 if (!warnings->conflicting_filenames.empty()) {
259 list_files_hbox.show ();
260 for (std::list<string>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
261 string::size_type pos = it->find_last_of ("/");
262 list_files_string += "\n" + it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>";
267 void
268 ExportDialog::show_conflicting_files ()
270 ArdourDialog dialog (_("Files that will be overwritten"), true);
272 Gtk::Label label ("", Gtk::ALIGN_LEFT);
273 label.set_use_markup (true);
274 label.set_markup (list_files_string);
276 dialog.get_vbox()->pack_start (label);
277 dialog.add_button (Gtk::Stock::OK, 0);
278 dialog.show_all_children ();
280 dialog.run();
283 void
284 ExportDialog::export_rt ()
286 profile_manager->prepare_for_export ();
287 handler->do_export (true);
288 show_progress ();
291 void
292 ExportDialog::export_fw ()
294 profile_manager->prepare_for_export ();
295 handler->do_export (false);
296 show_progress ();
299 void
300 ExportDialog::show_progress ()
302 status->running = true;
304 cancel_button->set_label (_("Stop Export"));
305 //rt_export_button->set_sensitive (false);
306 fast_export_button->set_sensitive (false);
308 progress_bar.set_fraction (0.0);
309 warning_widget.hide_all();
310 progress_widget.show ();
311 progress_widget.show_all_children ();
312 progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
314 gtk_main_iteration ();
315 while (status->running) {
316 if (gtk_events_pending()) {
317 gtk_main_iteration ();
318 } else {
319 usleep (10000);
323 if (!status->aborted()) {
324 status->finish ();
328 gint
329 ExportDialog::progress_timeout ()
331 std::string status_text;
332 if (status->normalizing) {
333 status_text = string_compose (_("Normalizing timespan %1 of %2"),
334 status->timespan, status->total_timespans);
335 } else {
336 status_text = string_compose (_("Exporting timespan %1 of %2"),
337 status->timespan, status->total_timespans);
339 progress_label.set_text (status_text);
341 progress_bar.set_fraction (status->progress);
342 return TRUE;
345 void
346 ExportDialog::add_error (string const & text)
348 fast_export_button->set_sensitive (false);
349 //rt_export_button->set_sensitive (false);
351 if (warn_string.empty()) {
352 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
353 } else {
354 warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
357 warn_label.set_markup (warn_string);
360 void
361 ExportDialog::add_warning (string const & text)
363 if (warn_string.empty()) {
364 warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
365 } else {
366 warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
369 warn_label.set_markup (warn_string);
372 /*** Dialog specializations ***/
374 ExportRangeDialog::ExportRangeDialog (PublicEditor & editor, string range_id) :
375 ExportDialog (editor, _("Export Range"), X_("RangeExportProfile")),
376 range_id (range_id)
379 void
380 ExportRangeDialog::init_components ()
382 preset_selector.reset (new ExportPresetSelector ());
383 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, range_id));
384 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
385 file_notebook.reset (new ExportFileNotebook ());
388 ExportSelectionDialog::ExportSelectionDialog (PublicEditor & editor) :
389 ExportDialog (editor, _("Export Selection"), X_("SelectionExportProfile"))
392 void
393 ExportSelectionDialog::init_components ()
395 preset_selector.reset (new ExportPresetSelector ());
396 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, X_("selection")));
397 channel_selector.reset (new PortExportChannelSelector (_session, profile_manager));
398 file_notebook.reset (new ExportFileNotebook ());
401 ExportRegionDialog::ExportRegionDialog (PublicEditor & editor, ARDOUR::AudioRegion const & region, ARDOUR::AudioTrack & track) :
402 ExportDialog (editor, _("Export Region"), X_("RegionExportProfile")),
403 region (region),
404 track (track)
407 void
408 ExportRegionDialog::init_gui ()
410 ExportDialog::init_gui ();
412 channels_label->set_text (_("Source"));
415 void
416 ExportRegionDialog::init_components ()
418 string loc_id = profile_manager->set_single_range (region.position(), region.position() + region.length(), region.name());
420 preset_selector.reset (new ExportPresetSelector ());
421 timespan_selector.reset (new ExportTimespanSelectorSingle (_session, profile_manager, loc_id));
422 channel_selector.reset (new RegionExportChannelSelector (_session, profile_manager, region, track));
423 file_notebook.reset (new ExportFileNotebook ());
426 StemExportDialog::StemExportDialog (PublicEditor & editor)
427 : ExportDialog(editor, _("Stem Export"), X_("StemExportProfile"))
432 void
433 StemExportDialog::init_components ()
435 preset_selector.reset (new ExportPresetSelector ());
436 timespan_selector.reset (new ExportTimespanSelectorMultiple (_session, profile_manager));
437 channel_selector.reset (new TrackExportChannelSelector (_session, profile_manager));
438 file_notebook.reset (new ExportFileNotebook ());