2 * Copyright (C) 2008-2012 Sakari Bergen <sakari.bergen@beatwaves.net>
3 * Copyright (C) 2009-2016 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2009 David Robillard <d@drobilla.net>
5 * Copyright (C) 2012-2016 Tim Mayberry <mojofunk@gmail.com>
6 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
7 * Copyright (C) 2014 Colin Fletcher <colin.m.fletcher@googlemail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "export_file_notebook.h"
26 #include "ardour/export_format_specification.h"
28 #include "gui_thread.h"
32 using namespace ARDOUR;
33 using namespace ARDOUR_UI_UTILS;
36 ExportFileNotebook::ExportFileNotebook () :
41 new_file_button.set_image (*Gtk::manage (new Gtk::Image (::get_icon("add"))));
42 new_file_button.set_label (_("Add another format"));
43 new_file_button.set_alignment (0, 0.5);
44 new_file_button.set_relief (Gtk::RELIEF_NONE);
46 new_file_hbox.pack_start (new_file_button, true, true);
47 append_page (new_file_dummy, new_file_hbox);
48 set_tab_label_packing (new_file_dummy, true, true, Gtk::PACK_START);
49 new_file_hbox.show_all_children ();
51 page_change_connection = signal_switch_page().connect (sigc::mem_fun (*this, &ExportFileNotebook::handle_page_change));
52 new_file_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFileNotebook::add_new_file_page));
56 ExportFileNotebook::set_session_and_manager (ARDOUR::Session * s, boost::shared_ptr<ARDOUR::ExportProfileManager> manager)
58 SessionHandlePtr::set_session (s);
59 profile_manager = manager;
65 ExportFileNotebook::sync_with_manager ()
67 /* Clear pages from notebook
68 The page switch handling has to be disabled during removing all pages due to a gtk bug
71 page_change_connection.block();
72 while (get_n_pages() > 1) {
75 page_change_connection.block(false);
78 last_visible_page = 0;
82 ExportProfileManager::FormatStateList const & formats = profile_manager->get_formats ();
83 ExportProfileManager::FormatStateList::const_iterator format_it;
84 ExportProfileManager::FilenameStateList const & filenames = profile_manager->get_filenames ();
85 ExportProfileManager::FilenameStateList::const_iterator filename_it;
86 for (format_it = formats.begin(), filename_it = filenames.begin();
87 format_it != formats.end() && filename_it != filenames.end();
88 ++format_it, ++filename_it) {
89 add_file_page (*format_it, *filename_it);
93 update_soundcloud_upload ();
94 CriticalSelectionChanged ();
98 ExportFileNotebook::update_soundcloud_upload ()
101 bool show_credentials_entry = false;
102 ExportProfileManager::FormatStateList const & formats = profile_manager->get_formats ();
103 ExportProfileManager::FormatStateList::const_iterator format_it;
105 for (i = 0, format_it = formats.begin(); format_it != formats.end(); ++i, ++format_it) {
107 if ((page = dynamic_cast<FilePage *> (get_nth_page (i)))) {
108 bool this_soundcloud_upload = page->get_soundcloud_upload ();
109 (*format_it)->format->set_soundcloud_upload (this_soundcloud_upload);
110 if (this_soundcloud_upload) {
111 show_credentials_entry = true;
115 soundcloud_export_selector->set_visible (show_credentials_entry);
119 ExportFileNotebook::FilePage::analysis_changed ()
121 format_state->format->set_analyse (analysis_button.get_active ());
122 profile_manager->save_format_to_disk (format_state->format);
126 ExportFileNotebook::FilePage::update_analysis_button ()
128 analysis_button.set_active (format_state->format->analyse());
132 ExportFileNotebook::update_example_filenames ()
136 while ((page = dynamic_cast<FilePage *> (get_nth_page (i++)))) {
137 page->update_example_filename();
142 ExportFileNotebook::add_new_file_page ()
145 if ((page = dynamic_cast<FilePage *> (get_nth_page (get_current_page())))) {
146 add_file_page (profile_manager->duplicate_format_state (page->get_format_state()),
147 profile_manager->duplicate_filename_state (page->get_filename_state()));
152 ExportFileNotebook::add_file_page (ARDOUR::ExportProfileManager::FormatStatePtr format_state, ARDOUR::ExportProfileManager::FilenameStatePtr filename_state)
154 FilePage * page = Gtk::manage (new FilePage (_session, profile_manager, this, page_counter, format_state, filename_state));
155 page->CriticalSelectionChanged.connect (CriticalSelectionChanged.make_slot());
156 insert_page (*page, page->get_tab_widget(), get_n_pages() - 1);
158 update_remove_file_page_sensitivity ();
162 CriticalSelectionChanged ();
166 ExportFileNotebook::remove_file_page (FilePage * page)
168 profile_manager->remove_format_state (page->get_format_state());
169 profile_manager->remove_filename_state (page->get_filename_state());
172 update_remove_file_page_sensitivity ();
174 CriticalSelectionChanged ();
178 ExportFileNotebook::update_remove_file_page_sensitivity ()
181 if ((page = dynamic_cast<FilePage *> (get_nth_page (0)))) {
182 if (get_n_pages() > 2) {
183 page->set_remove_sensitive (true);
185 page->set_remove_sensitive (false);
191 ExportFileNotebook::handle_page_change (GtkNotebookPage*, uint32_t page)
193 if (page + 1 == (uint32_t) get_n_pages()) {
194 set_current_page (last_visible_page);
196 last_visible_page = page;
198 update_soundcloud_upload ();
201 ExportFileNotebook::FilePage::FilePage (Session * s, ManagerPtr profile_manager, ExportFileNotebook * parent, uint32_t number,
202 ExportProfileManager::FormatStatePtr format_state,
203 ExportProfileManager::FilenameStatePtr filename_state) :
204 format_state (format_state),
205 filename_state (filename_state),
206 profile_manager (profile_manager),
208 format_label (_("Format"), Gtk::ALIGN_LEFT),
209 filename_label (_("Location"), Gtk::ALIGN_LEFT),
210 soundcloud_upload_button (_("Upload to Soundcloud")),
211 analysis_button (_("Analyze Exported Audio")),
214 set_border_width (12);
216 pack_start (format_label, false, false, 0);
217 pack_start (format_align, false, false, 0);
218 pack_start (filename_label, false, false, 0);
219 pack_start (filename_align, false, false, 0);
221 Gtk::HBox *hbox = Gtk::manage (new Gtk::HBox());
222 hbox->set_spacing (6);
223 #ifndef NDEBUG // SoundCloud upload is currently b0rked, needs debugging
224 hbox->pack_start (soundcloud_upload_button, false, false, 0);
226 hbox->pack_start (analysis_button, false, false, 0);
227 pack_start (*hbox, false, false, 0);
229 format_align.add (format_selector);
230 format_align.set_padding (6, 12, 18, 0);
232 filename_align.add (filename_selector);
233 filename_align.set_padding (0, 12, 18, 0);
235 Pango::AttrList bold;
236 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
239 format_label.set_attributes (bold);
240 filename_label.set_attributes (bold);
241 tab_label.set_attributes (bold);
244 format_selector.set_state (format_state, s);
245 filename_selector.set_state (filename_state, s);
246 analysis_button.set_active (format_state->format->analyse());
247 soundcloud_upload_button.set_active (format_state->format->soundcloud_upload());
251 tab_close_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*parent, &ExportFileNotebook::remove_file_page), this));
253 profile_manager->FormatListChanged.connect (format_connection, invalidator (*this), boost::bind (&ExportFormatSelector::update_format_list, &format_selector), gui_context());
255 format_selector.FormatEdited.connect (sigc::mem_fun (*this, &ExportFileNotebook::FilePage::save_format_to_manager));
256 format_selector.FormatRemoved.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::remove_format_profile));
257 format_selector.NewFormat.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::get_new_format));
258 format_selector.FormatReverted.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::revert_format_profile));
260 format_selector.CriticalSelectionChanged.connect (
261 sigc::mem_fun (*this, &ExportFileNotebook::FilePage::critical_selection_changed));
262 filename_selector.CriticalSelectionChanged.connect (
263 sigc::mem_fun (*this, &ExportFileNotebook::FilePage::critical_selection_changed));
265 soundcloud_upload_button.signal_toggled().connect (sigc::mem_fun (*parent, &ExportFileNotebook::update_soundcloud_upload));
266 soundcloud_button_connection = soundcloud_upload_button.signal_toggled().connect (sigc::mem_fun (*this, &ExportFileNotebook::FilePage::soundcloud_upload_changed));
267 analysis_button_connection = analysis_button.signal_toggled().connect (sigc::mem_fun (*this, &ExportFileNotebook::FilePage::analysis_changed));
270 tab_close_button.add (*Gtk::manage (new Gtk::Image (::get_icon("close"))));
271 tab_close_alignment.add (tab_close_button);
272 tab_close_alignment.set (0.5, 0.5, 0, 0);
274 tab_widget.pack_start (tab_label, false, false, 3);
275 tab_widget.pack_end (tab_close_alignment, false, false, 0);
276 tab_widget.show_all_children ();
278 update_example_filename();
282 show_all_children ();
285 ExportFileNotebook::FilePage::~FilePage ()
290 ExportFileNotebook::FilePage::set_remove_sensitive (bool value)
292 tab_close_button.set_sensitive (value);
296 ExportFileNotebook::FilePage::get_format_name () const
298 if (format_state && format_state->format) {
299 return format_state->format->name();
301 return _("No format!");
305 ExportFileNotebook::FilePage::get_soundcloud_upload () const
307 #ifdef NDEBUG // SoundCloud upload is currently b0rked, needs debugging
310 return soundcloud_upload_button.get_active ();
314 ExportFileNotebook::FilePage::soundcloud_upload_changed ()
316 profile_manager->save_format_to_disk (format_state->format);
320 ExportFileNotebook::FilePage::update_soundcloud_upload_button ()
322 soundcloud_upload_button.set_active (format_state->format->soundcloud_upload());
326 ExportFileNotebook::FilePage::save_format_to_manager (FormatPtr format)
328 profile_manager->save_format_to_disk (format);
332 ExportFileNotebook::FilePage::update_tab_label ()
334 tab_label.set_text (string_compose (_("Format %1: %2"), tab_number, get_format_name()));
338 ExportFileNotebook::FilePage::update_example_filename()
340 if (profile_manager) {
341 if (profile_manager->get_timespans().size() > 1
342 || profile_manager->get_timespans().front()->timespans->size() > 1) {
343 filename_selector.require_timespan (true);
345 filename_selector.require_timespan (false);
349 if (format_state->format) {
350 example = profile_manager->get_sample_filename_for_format (
351 filename_state->filename, format_state->format);
355 filename_selector.set_example_filename(Glib::path_get_basename (example));
357 filename_selector.set_example_filename("");
363 ExportFileNotebook::FilePage::critical_selection_changed ()
366 update_example_filename();
368 soundcloud_button_connection.block ();
369 analysis_button_connection.block ();
371 update_analysis_button();
372 update_soundcloud_upload_button();
374 analysis_button_connection.unblock ();
375 soundcloud_button_connection.unblock ();
377 CriticalSelectionChanged();