ardour
export_dialog.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 Paul Davis
3  Author: Sakari Bergen
4 
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.
9 
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.
14 
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.
18 
19 */
20 
21 
22 #include <sigc++/signal.h>
23 
24 #include <gtkmm/messagedialog.h>
25 
26 #include "ardour/audioregion.h"
27 #include "ardour/export_status.h"
28 #include "ardour/export_handler.h"
29 
30 #include "export_dialog.h"
31 #include "gui_thread.h"
32 #include "nag.h"
33 
34 #include "i18n.h"
35 
36 using namespace ARDOUR;
37 using namespace PBD;
38 using std::string;
39 
41  : ArdourDialog (title)
42  , type (type)
43  , editor (editor)
44 
45  , warn_label ("", Gtk::ALIGN_LEFT)
46  , list_files_label (_("<span color=\"#ffa755\">Some already existing files will be overwritten.</span>"), Gtk::ALIGN_RIGHT)
47  , list_files_button (_("List files"))
48 { }
49 
51 { }
52 
53 void
55 {
56  SessionHandlePtr::set_session (s);
57 
58  if (!_session) {
59  return;
60  }
61 
62  /* Init handler and profile manager */
63 
66 
68 
69  /* Possibly init stuff in derived classes */
70 
71  init ();
72 
73  /* Rest of _session related initialization */
74 
75  preset_selector->set_manager (profile_manager);
76  file_notebook->set_session_and_manager (_session, profile_manager);
77 
78  /* Hand on selection range to profile manager */
79 
80  TimeSelection const & time (editor.get_selection().time);
81  if (!time.empty()) {
82  profile_manager->set_selection_range (time.front().start, time.front().end);
83  } else {
85  }
86 
87  /* Load states */
88 
91 
92  /* Warnings */
93 
94  preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager));
95  timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
96  channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
97  file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename));
98 
100 }
101 
102 void
104 {
105  init_components ();
106  init_gui ();
107 
108  /* warnings */
109 
110  warning_widget.pack_start (warn_hbox, true, true, 6);
111  warning_widget.pack_end (list_files_hbox, false, false, 0);
112 
113  warn_hbox.pack_start (warn_label, true, true, 16);
114  warn_label.set_use_markup (true);
115 
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);
119 
120  list_files_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::show_conflicting_files));
121 
122  /* Progress indicators */
123 
124  progress_widget.pack_start (progress_bar, false, false, 6);
125 
126  /* Buttons */
127 
128  cancel_button = add_button (Gtk::Stock::CANCEL, RESPONSE_CANCEL);
129  export_button = add_button (_("Export"), RESPONSE_FAST);
130  set_default_response (RESPONSE_FAST);
131 
132  list_files_button.set_name ("PaddedButton");
133 
134  cancel_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::close_dialog));
135  export_button->signal_clicked().connect (sigc::mem_fun (*this, &ExportDialog::do_export));
136 
137  file_notebook->soundcloud_export_selector = soundcloud_selector;
138 
139  /* Done! */
140 
141  show_all_children ();
142  progress_widget.hide_all();
143 }
144 
145 void
147 {
148  Gtk::Alignment * preset_align = Gtk::manage (new Gtk::Alignment());
149  preset_align->add (*preset_selector);
150  preset_align->set_padding (0, 12, 0, 0);
151 
152  Gtk::VBox * file_format_selector = Gtk::manage (new Gtk::VBox());
153  file_format_selector->set_homogeneous (false);
154  file_format_selector->pack_start (*preset_align, false, false, 0);
155  file_format_selector->pack_start (*file_notebook, false, false, 0);
156  file_format_selector->pack_start (*soundcloud_selector, false, false, 0);
157 
158  export_notebook.append_page (*file_format_selector, _("File format"));
159  export_notebook.append_page (*timespan_selector, _("Time Span"));
160  export_notebook.append_page (*channel_selector, _("Channels"));
161 
162  get_vbox()->pack_start (export_notebook, true, true, 0);
163  get_vbox()->pack_end (warning_widget, false, false, 0);
164  get_vbox()->pack_end (progress_widget, false, false, 0);
165 
166 }
167 
168 void
170 {
171  preset_selector.reset (new ExportPresetSelector ());
175  file_notebook.reset (new ExportFileNotebook ());
176 }
177 
178 void
180 {
181  if (force || status->errors()) {
182  std::string txt = _("Export has been aborted due to an error!\nSee the Log for details.");
183  Gtk::MessageDialog msg (txt, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
184  msg.run();
185  }
186 }
187 
188 void
190 {
191  if (status->running) {
192  status->abort();
193  }
194 
195  hide_all ();
196  set_modal (false);
197 
198 }
199 
200 void
202 {
203  timespan_selector->sync_with_manager();
204  channel_selector->sync_with_manager();
205  file_notebook->sync_with_manager ();
206 
208 }
209 
210 void
212 {
213  /* Reset state */
214 
215  warn_string = "";
216  warn_label.set_markup (warn_string);
217 
218  list_files_hbox.hide ();
219  list_files_string = "";
220 
221  export_button->set_sensitive (true);
222 
223  /* Add new warnings */
224 
226 
227  for (std::list<string>::iterator it = warnings->errors.begin(); it != warnings->errors.end(); ++it) {
228  add_error (*it);
229  }
230 
231  for (std::list<string>::iterator it = warnings->warnings.begin(); it != warnings->warnings.end(); ++it) {
232  add_warning (*it);
233  }
234 
235  if (!warnings->conflicting_filenames.empty()) {
236  list_files_hbox.show ();
237  for (std::list<string>::iterator it = warnings->conflicting_filenames.begin(); it != warnings->conflicting_filenames.end(); ++it) {
238  string::size_type pos = it->find_last_of ("/");
239  list_files_string += it->substr (0, pos + 1) + "<b>" + it->substr (pos + 1) + "</b>\n";
240  }
241  }
242 
243  /* Update example filename */
244 
245  file_notebook->update_example_filenames();
246 }
247 
248 void
250 {
251  ArdourDialog dialog (_("Files that will be overwritten"), true);
252 
253  Gtk::Label label ("", Gtk::ALIGN_LEFT);
254  label.set_use_markup (true);
255  label.set_markup (list_files_string);
256 
257  dialog.get_vbox()->pack_start (label);
258  dialog.add_button (Gtk::Stock::OK, 0);
259  dialog.show_all_children ();
260 
261  dialog.run();
262 }
263 
264 void
265 ExportDialog::soundcloud_upload_progress(double total, double now, std::string title)
266 {
267  soundcloud_selector->do_progress_callback(total, now, title);
268 
269 }
270 
271 void
273 {
274  try {
281 
282  handler->SoundcloudProgress.connect_same_thread(
283  *this,
284  boost::bind(&ExportDialog::soundcloud_upload_progress, this, _1, _2, _3)
285  );
286 #if 0
287  handler->SoundcloudProgress.connect(
288  *this, invalidator (*this),
289  boost::bind(&ExportDialog::soundcloud_upload_progress, this, _1, _2, _3),
290  gui_context()
291  );
292 #endif
293  handler->do_export ();
294  show_progress ();
295  } catch(std::exception & e) {
296  error << string_compose (_("Export initialization failed: %1"), e.what()) << endmsg;
297  notify_errors(true);
298  }
299 }
300 
301 void
303 {
304  status->running = true;
305 
306  cancel_button->set_label (_("Stop Export"));
307  export_button->set_sensitive (false);
308 
309  progress_bar.set_fraction (0.0);
310  warning_widget.hide_all();
311  progress_widget.show ();
312  progress_widget.show_all_children ();
313  progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportDialog::progress_timeout), 100);
314 
315  gtk_main_iteration ();
316 
317  while (status->running) {
318  if (gtk_events_pending()) {
319  gtk_main_iteration ();
320  } else {
321  Glib::usleep (10000);
322  }
323  }
324 
325  if (!status->aborted()) {
326 
327  NagScreen* ns = NagScreen::maybe_nag (_("export"));
328 
329  if (ns) {
330  ns->nag ();
331  delete ns;
332  }
333  } else {
334  notify_errors ();
335  }
336 
337  status->finish ();
338 }
339 
340 gint
342 {
343  std::string status_text;
344  float progress = 0.0;
345  if (status->normalizing) {
346  status_text = string_compose (_("Normalizing '%3' (timespan %1 of %2)"),
349  } else {
350  status_text = string_compose (_("Exporting '%3' (timespan %1 of %2)"),
353  }
354  progress_bar.set_text (status_text);
355 
356  if (progress < previous_progress) {
357  // Work around gtk bug
358  progress_bar.hide();
359  progress_bar.show();
360  }
361  previous_progress = progress;
362 
363  progress_bar.set_fraction (progress);
364  return TRUE;
365 }
366 
367 void
368 ExportDialog::add_error (string const & text)
369 {
370  export_button->set_sensitive (false);
371 
372  if (warn_string.empty()) {
373  warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>";
374  } else {
375  warn_string = _("<span color=\"#ffa755\">Error: ") + text + "</span>\n" + warn_string;
376  }
377 
378  warn_label.set_markup (warn_string);
379 }
380 
381 void
382 ExportDialog::add_warning (string const & text)
383 {
384  if (warn_string.empty()) {
385  warn_string = _("<span color=\"#ffa755\">Warning: ") + text + "</span>";
386  } else {
387  warn_string = warn_string + _("\n<span color=\"#ffa755\">Warning: ") + text + "</span>";
388  }
389 
390  warn_label.set_markup (warn_string);
391 }
392 
393 /*** Dialog specializations ***/
394 
396  ExportDialog (editor, _("Export Range"), ExportProfileManager::RangeExport),
397  range_id (range_id)
398 {}
399 
400 void
402 {
403  preset_selector.reset (new ExportPresetSelector ());
407  file_notebook.reset (new ExportFileNotebook ());
408 }
409 
411  ExportDialog (editor, _("Export Selection"), ExportProfileManager::SelectionExport)
412 {}
413 
414 void
416 {
417  preset_selector.reset (new ExportPresetSelector ());
421  file_notebook.reset (new ExportFileNotebook ());
422 }
423 
425  ExportDialog (editor, _("Export Region"), ExportProfileManager::RegionExport),
426  region (region),
427  track (track)
428 {}
429 
430 void
432 {
434  export_notebook.set_tab_label_text(*export_notebook.get_nth_page(2), _("Source"));
435 }
436 
437 void
439 {
441 
442  preset_selector.reset (new ExportPresetSelector ());
446  file_notebook.reset (new ExportFileNotebook ());
447 }
448 
450  : ExportDialog(editor, _("Stem Export"), ExportProfileManager::StemExport)
451 {
452 
453 }
454 
455 void
457 {
458  preset_selector.reset (new ExportPresetSelector ());
462  file_notebook.reset (new ExportFileNotebook ());
463 }
gint progress_timeout()
void add_warning(std::string const &text)
virtual void init_gui()
Gtk::Button * export_button
ARDOUR::AudioRegion const & region
void close_dialog()
void abort(bool error_occurred=false)
sigc::connection progress_connection
std::string timespan_name
Definition: export_status.h:60
volatile uint32_t timespan
Definition: export_status.h:59
boost::scoped_ptr< ExportTimespanSelector > timespan_selector
Definition: export_dialog.h:81
ARDOUR::AudioTrack & track
Gtk::VBox warning_widget
Definition: export_dialog.h:87
volatile framecnt_t processed_frames_current_timespan
Definition: export_status.h:66
void sync_with_manager()
Definition: ardour_ui.h:130
HandlerPtr handler
Definition: export_dialog.h:71
std::string soundcloud_username
Gtk::HBox list_files_hbox
volatile framecnt_t total_frames_current_timespan
Definition: export_status.h:65
static NagScreen * maybe_nag(std::string context)
Definition: nag.cc:111
Representation of the interface of the Editor class.
void set_session(ARDOUR::Session *s)
LIBPBD_API Transmitter error
StatusPtr status
StemExportDialog(PublicEditor &editor)
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
std::string set_single_range(framepos_t start, framepos_t end, std::string name)
boost::shared_ptr< ExportStatus > get_export_status()
#define invalidator(x)
Definition: gui_thread.h:40
boost::shared_ptr< ExportHandler > get_export_handler()
ExportDialog(PublicEditor &editor, std::string title, ARDOUR::ExportProfileManager::ExportType type)
#define _(Text)
Definition: i18n.h:11
bool errors() const
Definition: export_status.h:46
volatile bool running
Definition: export_status.h:42
void add_error(std::string const &text)
#define X_(Text)
Definition: i18n.h:13
void notify_errors(bool force=false)
bool aborted() const
Definition: export_status.h:45
Definition: nag.h:29
Gtk::VBox progress_widget
Definition: export_dialog.h:88
void soundcloud_upload_progress(double total, double now, std::string title)
Definition: amp.h:29
void set_selection_range(framepos_t start=0, framepos_t end=0)
std::string list_files_string
#define gui_context()
Definition: gui_thread.h:36
Manages (de)serialization of export profiles and related classes.
virtual Selection & get_selection() const =0
float previous_progress
Gtk::Button * cancel_button
volatile uint32_t total_normalize_cycles
Definition: export_status.h:68
ExportRangeDialog(PublicEditor &editor, std::string range_id)
Allows selecting multiple timespans.
framepos_t position() const
Definition: region.h:112
Gtk::Label list_files_label
virtual void init_components()
std::string soundcloud_password
ExportSelectionDialog(PublicEditor &editor)
boost::shared_ptr< Warnings > get_warnings()
boost::scoped_ptr< ExportFileNotebook > file_notebook
Definition: export_dialog.h:83
std::string warn_string
std::string name() const
TimeSelection time
Definition: selection.h:83
Gtk::Button list_files_button
void show_conflicting_files()
Definition: debug.h:30
Gtk::Notebook export_notebook
Definition: export_dialog.h:91
Gtk::HBox warn_hbox
framecnt_t length() const
Definition: region.h:114
boost::shared_ptr< SoundcloudExportSelector > soundcloud_selector
Definition: export_dialog.h:85
volatile uint32_t total_timespans
Definition: export_status.h:58
Gtk::ProgressBar progress_bar
volatile uint32_t current_normalize_cycle
Definition: export_status.h:69
void show_progress()
PublicEditor & editor
volatile bool normalizing
Definition: export_status.h:56
ARDOUR::Session * _session
boost::scoped_ptr< ExportPresetSelector > preset_selector
Definition: export_dialog.h:80
int do_progress_callback(double ultotal, double ulnow, const std::string &filename)
ManagerPtr profile_manager
Definition: export_dialog.h:72
boost::scoped_ptr< ExportChannelSelector > channel_selector
Definition: export_dialog.h:82
ExportRegionDialog(PublicEditor &editor, ARDOUR::AudioRegion const &region, ARDOUR::AudioTrack &track)
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
PBD::Signal3< void, double, double, std::string > SoundcloudProgress
void nag()
Definition: nag.cc:84
ARDOUR::ExportProfileManager::ExportType type
Definition: export_dialog.h:70
void update_warnings_and_example_filename()
Gtk::Label warn_label
std::string range_id