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_file_notebook.h"
23 #include "ardour/export_format_specification.h"
25 #include "gui_thread.h"
29 using namespace ARDOUR;
30 using namespace ARDOUR_UI_UTILS;
33 ExportFileNotebook::ExportFileNotebook () :
38 new_file_button.set_image (*Gtk::manage (new Gtk::Image (::get_icon("add"))));
39 new_file_button.set_label (_("Add another format"));
40 new_file_button.set_alignment (0, 0.5);
41 new_file_button.set_relief (Gtk::RELIEF_NONE);
43 new_file_hbox.pack_start (new_file_button, true, true);
44 append_page (new_file_dummy, new_file_hbox);
45 set_tab_label_packing (new_file_dummy, true, true, Gtk::PACK_START);
46 new_file_hbox.show_all_children ();
48 page_change_connection = signal_switch_page().connect (sigc::mem_fun (*this, &ExportFileNotebook::handle_page_change));
49 new_file_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFileNotebook::add_new_file_page));
53 ExportFileNotebook::set_session_and_manager (ARDOUR::Session * s, boost::shared_ptr<ARDOUR::ExportProfileManager> manager)
55 SessionHandlePtr::set_session (s);
56 profile_manager = manager;
62 ExportFileNotebook::sync_with_manager ()
64 /* Clear pages from notebook
65 The page switch handling has to be disabled during removing all pages due to a gtk bug
68 page_change_connection.block();
69 while (get_n_pages() > 1) {
72 page_change_connection.block(false);
75 last_visible_page = 0;
79 ExportProfileManager::FormatStateList const & formats = profile_manager->get_formats ();
80 ExportProfileManager::FormatStateList::const_iterator format_it;
81 ExportProfileManager::FilenameStateList const & filenames = profile_manager->get_filenames ();
82 ExportProfileManager::FilenameStateList::const_iterator filename_it;
83 for (format_it = formats.begin(), filename_it = filenames.begin();
84 format_it != formats.end() && filename_it != filenames.end();
85 ++format_it, ++filename_it) {
86 add_file_page (*format_it, *filename_it);
90 update_soundcloud_upload ();
91 CriticalSelectionChanged ();
95 ExportFileNotebook::update_soundcloud_upload ()
98 bool show_credentials_entry = false;
99 ExportProfileManager::FormatStateList const & formats = profile_manager->get_formats ();
100 ExportProfileManager::FormatStateList::const_iterator format_it;
102 for (i = 0, format_it = formats.begin(); format_it != formats.end(); ++i, ++format_it) {
104 if ((page = dynamic_cast<FilePage *> (get_nth_page (i)))) {
105 bool this_soundcloud_upload = page->get_soundcloud_upload ();
106 (*format_it)->format->set_soundcloud_upload (this_soundcloud_upload);
107 if (this_soundcloud_upload) {
108 show_credentials_entry = true;
112 soundcloud_export_selector->set_visible (show_credentials_entry);
116 ExportFileNotebook::FilePage::analysis_changed ()
118 format_state->format->set_analyse (analysis_button.get_active ());
119 profile_manager->save_format_to_disk (format_state->format);
123 ExportFileNotebook::FilePage::update_analysis_button ()
125 analysis_button.set_active (format_state->format->analyse());
129 ExportFileNotebook::update_example_filenames ()
133 while ((page = dynamic_cast<FilePage *> (get_nth_page (i++)))) {
134 page->update_example_filename();
139 ExportFileNotebook::add_new_file_page ()
142 if ((page = dynamic_cast<FilePage *> (get_nth_page (get_current_page())))) {
143 add_file_page (profile_manager->duplicate_format_state (page->get_format_state()),
144 profile_manager->duplicate_filename_state (page->get_filename_state()));
149 ExportFileNotebook::add_file_page (ARDOUR::ExportProfileManager::FormatStatePtr format_state, ARDOUR::ExportProfileManager::FilenameStatePtr filename_state)
151 FilePage * page = Gtk::manage (new FilePage (_session, profile_manager, this, page_counter, format_state, filename_state));
152 page->CriticalSelectionChanged.connect (CriticalSelectionChanged.make_slot());
153 insert_page (*page, page->get_tab_widget(), get_n_pages() - 1);
155 update_remove_file_page_sensitivity ();
159 CriticalSelectionChanged ();
163 ExportFileNotebook::remove_file_page (FilePage * page)
165 profile_manager->remove_format_state (page->get_format_state());
166 profile_manager->remove_filename_state (page->get_filename_state());
169 update_remove_file_page_sensitivity ();
171 CriticalSelectionChanged ();
175 ExportFileNotebook::update_remove_file_page_sensitivity ()
178 if ((page = dynamic_cast<FilePage *> (get_nth_page (0)))) {
179 if (get_n_pages() > 2) {
180 page->set_remove_sensitive (true);
182 page->set_remove_sensitive (false);
188 ExportFileNotebook::handle_page_change (GtkNotebookPage*, uint32_t page)
190 if (page + 1 == (uint32_t) get_n_pages()) {
191 set_current_page (last_visible_page);
193 last_visible_page = page;
195 update_soundcloud_upload ();
198 ExportFileNotebook::FilePage::FilePage (Session * s, ManagerPtr profile_manager, ExportFileNotebook * parent, uint32_t number,
199 ExportProfileManager::FormatStatePtr format_state,
200 ExportProfileManager::FilenameStatePtr filename_state) :
201 format_state (format_state),
202 filename_state (filename_state),
203 profile_manager (profile_manager),
205 format_label (_("Format"), Gtk::ALIGN_LEFT),
206 filename_label (_("Location"), Gtk::ALIGN_LEFT),
207 soundcloud_upload_button (_("Upload to Soundcloud")),
208 analysis_button (_("Analyze Exported Audio")),
211 set_border_width (12);
213 pack_start (format_label, false, false, 0);
214 pack_start (format_align, false, false, 0);
215 pack_start (filename_label, false, false, 0);
216 pack_start (filename_align, false, false, 0);
218 Gtk::HBox *hbox = Gtk::manage (new Gtk::HBox());
219 hbox->set_spacing (6);
220 #ifndef NDEBUG // SoundCloud upload is currently b0rked, needs debugging
221 hbox->pack_start (soundcloud_upload_button, false, false, 0);
223 hbox->pack_start (analysis_button, false, false, 0);
224 pack_start (*hbox, false, false, 0);
226 format_align.add (format_selector);
227 format_align.set_padding (6, 12, 18, 0);
229 filename_align.add (filename_selector);
230 filename_align.set_padding (0, 12, 18, 0);
232 Pango::AttrList bold;
233 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
236 format_label.set_attributes (bold);
237 filename_label.set_attributes (bold);
238 tab_label.set_attributes (bold);
241 format_selector.set_state (format_state, s);
242 filename_selector.set_state (filename_state, s);
243 analysis_button.set_active (format_state->format->analyse());
244 soundcloud_upload_button.set_active (format_state->format->soundcloud_upload());
248 tab_close_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*parent, &ExportFileNotebook::remove_file_page), this));
250 profile_manager->FormatListChanged.connect (format_connection, invalidator (*this), boost::bind (&ExportFormatSelector::update_format_list, &format_selector), gui_context());
252 format_selector.FormatEdited.connect (sigc::mem_fun (*this, &ExportFileNotebook::FilePage::save_format_to_manager));
253 format_selector.FormatRemoved.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::remove_format_profile));
254 format_selector.NewFormat.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::get_new_format));
255 format_selector.FormatReverted.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::revert_format_profile));
257 format_selector.CriticalSelectionChanged.connect (
258 sigc::mem_fun (*this, &ExportFileNotebook::FilePage::critical_selection_changed));
259 filename_selector.CriticalSelectionChanged.connect (
260 sigc::mem_fun (*this, &ExportFileNotebook::FilePage::critical_selection_changed));
262 soundcloud_upload_button.signal_toggled().connect (sigc::mem_fun (*parent, &ExportFileNotebook::update_soundcloud_upload));
263 soundcloud_upload_button.signal_toggled().connect (sigc::mem_fun (*this, &ExportFileNotebook::FilePage::soundcloud_upload_changed));
264 analysis_button.signal_toggled().connect (sigc::mem_fun (*this, &ExportFileNotebook::FilePage::analysis_changed));
267 tab_close_button.add (*Gtk::manage (new Gtk::Image (::get_icon("close"))));
268 tab_close_alignment.add (tab_close_button);
269 tab_close_alignment.set (0.5, 0.5, 0, 0);
271 tab_widget.pack_start (tab_label, false, false, 3);
272 tab_widget.pack_end (tab_close_alignment, false, false, 0);
273 tab_widget.show_all_children ();
275 update_example_filename();
279 show_all_children ();
282 ExportFileNotebook::FilePage::~FilePage ()
287 ExportFileNotebook::FilePage::set_remove_sensitive (bool value)
289 tab_close_button.set_sensitive (value);
293 ExportFileNotebook::FilePage::get_format_name () const
295 if (format_state && format_state->format) {
296 return format_state->format->name();
298 return _("No format!");
302 ExportFileNotebook::FilePage::get_soundcloud_upload () const
304 #ifdef NDEBUG // SoundCloud upload is currently b0rked, needs debugging
307 return soundcloud_upload_button.get_active ();
311 ExportFileNotebook::FilePage::soundcloud_upload_changed ()
313 profile_manager->save_format_to_disk (format_state->format);
317 ExportFileNotebook::FilePage::update_soundcloud_upload_button ()
319 soundcloud_upload_button.set_active (format_state->format->soundcloud_upload());
323 ExportFileNotebook::FilePage::save_format_to_manager (FormatPtr format)
325 profile_manager->save_format_to_disk (format);
329 ExportFileNotebook::FilePage::update_tab_label ()
331 tab_label.set_text (string_compose (_("Format %1: %2"), tab_number, get_format_name()));
335 ExportFileNotebook::FilePage::update_example_filename()
337 if (profile_manager) {
338 if (profile_manager->get_timespans().size() > 1
339 || profile_manager->get_timespans().front()->timespans->size() > 1) {
340 filename_selector.require_timespan (true);
342 filename_selector.require_timespan (false);
346 if (format_state->format) {
347 example = profile_manager->get_sample_filename_for_format (
348 filename_state->filename, format_state->format);
352 filename_selector.set_example_filename(Glib::path_get_basename (example));
354 filename_selector.set_example_filename("");
360 ExportFileNotebook::FilePage::critical_selection_changed ()
363 update_example_filename();
364 update_analysis_button();
365 update_soundcloud_upload_button();
366 CriticalSelectionChanged();