From dba601eeab9054ca4fac811c6c5e414d59fdc460 Mon Sep 17 00:00:00 2001 From: Sakari Bergen Date: Sun, 29 Jan 2012 20:55:44 +0000 Subject: Show an example filename in the main export dialog git-svn-id: svn://localhost/ardour2/branches/3.0@11383 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/export_dialog.cc | 16 ++++--- gtk2_ardour/export_dialog.h | 2 +- gtk2_ardour/export_file_notebook.cc | 42 +++++++++++++++++- gtk2_ardour/export_file_notebook.h | 5 +++ gtk2_ardour/export_filename_selector.cc | 16 ++++++- gtk2_ardour/export_filename_selector.h | 2 + libs/ardour/ardour/export_profile_manager.h | 6 +++ libs/ardour/export_profile_manager.cc | 66 +++++++++++++++++++---------- 8 files changed, 121 insertions(+), 34 deletions(-) diff --git a/gtk2_ardour/export_dialog.cc b/gtk2_ardour/export_dialog.cc index 3dea7ee1a6..9155595b8c 100644 --- a/gtk2_ardour/export_dialog.cc +++ b/gtk2_ardour/export_dialog.cc @@ -91,13 +91,13 @@ ExportDialog::set_session (ARDOUR::Session* s) /* Warnings */ preset_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::sync_with_manager)); - timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings)); - channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings)); - file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings)); + timespan_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename)); + channel_selector->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename)); + file_notebook->CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportDialog::update_warnings_and_example_filename)); status->Aborting.connect (abort_connection, invalidator (*this), boost::bind (&ExportDialog::notify_errors, this), gui_context()); - update_warnings (); + update_warnings_and_example_filename (); } void @@ -226,11 +226,11 @@ ExportDialog::sync_with_manager () channel_selector->sync_with_manager(); file_notebook->sync_with_manager (); - update_warnings (); + update_warnings_and_example_filename (); } void -ExportDialog::update_warnings () +ExportDialog::update_warnings_and_example_filename () { /* Reset state */ @@ -263,7 +263,9 @@ ExportDialog::update_warnings () } } - + /* Update example filename */ + + file_notebook->update_example_filenames(); } void diff --git a/gtk2_ardour/export_dialog.h b/gtk2_ardour/export_dialog.h index a720ec0b9c..ee0f7ce269 100644 --- a/gtk2_ardour/export_dialog.h +++ b/gtk2_ardour/export_dialog.h @@ -94,7 +94,7 @@ class ExportDialog : public ArdourDialog { void close_dialog (); void sync_with_manager (); - void update_warnings (); + void update_warnings_and_example_filename (); void show_conflicting_files (); void export_rt (); diff --git a/gtk2_ardour/export_file_notebook.cc b/gtk2_ardour/export_file_notebook.cc index ef0c56f55c..959bc42a2f 100644 --- a/gtk2_ardour/export_file_notebook.cc +++ b/gtk2_ardour/export_file_notebook.cc @@ -22,11 +22,14 @@ #include "ardour/export_format_specification.h" +#include "pbd/filesystem.h" + #include "gui_thread.h" #include "utils.h" #include "i18n.h" using namespace ARDOUR; +using namespace PBD; ExportFileNotebook::ExportFileNotebook () : page_counter (1) @@ -88,6 +91,16 @@ ExportFileNotebook::sync_with_manager () CriticalSelectionChanged (); } +void +ExportFileNotebook::update_example_filenames() +{ + int i = 0; + FilePage * page; + while ((page = dynamic_cast (get_nth_page (i++)))) { + page->update_example_filename(); + } +} + std::string ExportFileNotebook::get_nth_format_name (uint32_t n) { @@ -203,8 +216,10 @@ ExportFileNotebook::FilePage::FilePage (Session * s, ManagerPtr profile_manager, format_selector.FormatRemoved.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::remove_format_profile)); format_selector.NewFormat.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::get_new_format)); - format_selector.CriticalSelectionChanged.connect (sigc::mem_fun (*this, &ExportFileNotebook::FilePage::update_tab_label)); - filename_selector.CriticalSelectionChanged.connect (CriticalSelectionChanged.make_slot()); + format_selector.CriticalSelectionChanged.connect ( + sigc::mem_fun (*this, &ExportFileNotebook::FilePage::critical_selection_changed)); + filename_selector.CriticalSelectionChanged.connect ( + sigc::mem_fun (*this, &ExportFileNotebook::FilePage::critical_selection_changed)); /* Tab widget */ @@ -216,6 +231,7 @@ ExportFileNotebook::FilePage::FilePage (Session * s, ManagerPtr profile_manager, tab_widget.pack_end (tab_close_alignment, false, false, 0); tab_widget.show_all_children (); update_tab_label (); + update_example_filename(); /* Done */ @@ -251,5 +267,27 @@ void ExportFileNotebook::FilePage::update_tab_label () { tab_label.set_text (string_compose ("Format %1: %2", tab_number, get_format_name())); +} + +void +ExportFileNotebook::FilePage::update_example_filename() +{ + if (profile_manager) { + std::string example = profile_manager->get_sample_filename_for_format ( + filename_state->filename, format_state->format); + if (example != "") { + sys::path path(example); + filename_selector.set_example_filename(path.leaf()); + } else { + filename_selector.set_example_filename(""); + } + } +} + +void +ExportFileNotebook::FilePage::critical_selection_changed () +{ + update_tab_label(); + update_example_filename(); CriticalSelectionChanged(); } diff --git a/gtk2_ardour/export_file_notebook.h b/gtk2_ardour/export_file_notebook.h index 9f357ab1d5..5555828e98 100644 --- a/gtk2_ardour/export_file_notebook.h +++ b/gtk2_ardour/export_file_notebook.h @@ -39,6 +39,8 @@ class ExportFileNotebook : public Gtk::Notebook, public ARDOUR::SessionHandlePtr void set_session_and_manager (ARDOUR::Session * s, boost::shared_ptr manager); void sync_with_manager (); + void update_example_filenames(); + std::string get_nth_format_name (uint32_t n); sigc::signal CriticalSelectionChanged; @@ -79,6 +81,8 @@ class ExportFileNotebook : public Gtk::Notebook, public ARDOUR::SessionHandlePtr void set_remove_sensitive (bool value); std::string get_format_name () const; + void update_example_filename(); + ARDOUR::ExportProfileManager::FormatStatePtr get_format_state () const { return format_state; } ARDOUR::ExportProfileManager::FilenameStatePtr get_filename_state () const { return filename_state; } @@ -87,6 +91,7 @@ class ExportFileNotebook : public Gtk::Notebook, public ARDOUR::SessionHandlePtr private: void save_format_to_manager (FormatPtr format); void update_tab_label (); + void critical_selection_changed (); ARDOUR::ExportProfileManager::FormatStatePtr format_state; ARDOUR::ExportProfileManager::FilenameStatePtr filename_state; diff --git a/gtk2_ardour/export_filename_selector.cc b/gtk2_ardour/export_filename_selector.cc index 789b7eb435..e2d360984c 100644 --- a/gtk2_ardour/export_filename_selector.cc +++ b/gtk2_ardour/export_filename_selector.cc @@ -38,11 +38,14 @@ ExportFilenameSelector::ExportFilenameSelector () : revision_checkbox (_("Revision:")), path_label (_("Folder:"), Gtk::ALIGN_LEFT), - browse_button (_("Browse")) + browse_button (_("Browse")), + + example_filename_label ("", Gtk::ALIGN_LEFT) { pack_start (include_label, false, false, 6); pack_start (include_hbox, false, false, 0); pack_start (path_hbox, false, false, 12); + pack_start (example_filename_label, false, false, 0); include_hbox.pack_start (label_label, false, false, 3); include_hbox.pack_start (label_entry, false, false, 3); @@ -204,6 +207,17 @@ ExportFilenameSelector::set_state (ARDOUR::ExportProfileManager::FilenameStatePt } +void +ExportFilenameSelector::set_example_filename (std::string filename) +{ + if (filename == "") { + example_filename_label.set_text (_("Sorry, no example filename can be shown at the moment")); + } else { + example_filename_label.set_text (string_compose(_("Example filename: \"%1\""), + filename)); + } +} + void ExportFilenameSelector::update_label () { diff --git a/gtk2_ardour/export_filename_selector.h b/gtk2_ardour/export_filename_selector.h index 8522f79b20..f6f7551438 100644 --- a/gtk2_ardour/export_filename_selector.h +++ b/gtk2_ardour/export_filename_selector.h @@ -37,6 +37,7 @@ class ExportFilenameSelector : public Gtk::VBox, public ARDOUR::SessionHandlePtr ~ExportFilenameSelector (); void set_state (ARDOUR::ExportProfileManager::FilenameStatePtr state_, ARDOUR::Session * session_); + void set_example_filename (std::string filename); /* Compatibility with other elements */ @@ -80,6 +81,7 @@ class ExportFilenameSelector : public Gtk::VBox, public ARDOUR::SessionHandlePtr Gtk::Label path_label; Gtk::Entry path_entry; Gtk::Button browse_button; + Gtk::Label example_filename_label; /* Date combo */ diff --git a/libs/ardour/ardour/export_profile_manager.h b/libs/ardour/ardour/export_profile_manager.h index c0d2bb1dd8..f73085e5ba 100644 --- a/libs/ardour/ardour/export_profile_manager.h +++ b/libs/ardour/ardour/export_profile_manager.h @@ -232,6 +232,8 @@ class ExportProfileManager FilenameStatePtr duplicate_filename_state (FilenameStatePtr state); void remove_filename_state (FilenameStatePtr state); + std::string get_sample_filename_for_format (ExportFilenamePtr filename, ExportFormatSpecPtr format); + private: FilenameStateList filenames; @@ -261,6 +263,10 @@ class ExportProfileManager /* Utilities */ + void build_filenames(std::list & result, ExportFilenamePtr filename, + TimespanListPtr timespans, ExportChannelConfigPtr channel_config, + ExportFormatSpecPtr format); + /* Element state lists should never be empty, this is used to check them */ template std::list const & diff --git a/libs/ardour/export_profile_manager.cc b/libs/ardour/export_profile_manager.cc index af1209fde3..c644687f59 100644 --- a/libs/ardour/export_profile_manager.cc +++ b/libs/ardour/export_profile_manager.cc @@ -711,6 +711,19 @@ ExportProfileManager::remove_filename_state (FilenameStatePtr state) } } +std::string +ExportProfileManager::get_sample_filename_for_format (ExportFilenamePtr filename, ExportFormatSpecPtr format) +{ + if (channel_configs.empty()) { return ""; } + + std::list filenames; + build_filenames (filenames, filename, timespans.front()->timespans, + channel_configs.front()->config, format); + + if (filenames.empty()) { return ""; } + return filenames.front(); +} + bool ExportProfileManager::init_filenames (XMLNodeList nodes) { @@ -815,34 +828,17 @@ ExportProfileManager::check_config (boost::shared_ptr warnings, // filename->include_timespan = (timespans->size() > 1); Disabled for now... - for (std::list::iterator timespan_it = timespans->begin(); timespan_it != timespans->end(); ++timespan_it) { - filename->set_timespan (*timespan_it); - - if (channel_config->get_split()) { - filename->include_channel = true; - - for (uint32_t chan = 1; chan <= channel_config->get_n_chans(); ++chan) { - filename->set_channel (chan); + std::list paths; + build_filenames(paths, filename, timespans, channel_config, format); - string path = filename->get_path (format); + for (std::list::const_iterator path_it = paths.begin(); path_it != paths.end(); ++path_it) { - if (sys::exists (sys::path (path))) { - warnings->conflicting_filenames.push_back (path); - } - } + string path = *path_it; - } else { - filename->include_channel = false; - string path = filename->get_path (format); - - if (sys::exists (sys::path (path))) { - warnings->conflicting_filenames.push_back (path); - } + if (sys::exists (sys::path (path))) { + warnings->conflicting_filenames.push_back (path); } - // TODO check what happens with split channel configs... - string path = filename->get_path (format); - if (format->with_toc()) { string marker_file = handler->get_cd_marker_filename(path, CDMarkerTOC); if (sys::exists (sys::path (marker_file))) { @@ -882,4 +878,28 @@ ExportProfileManager::check_sndfile_format (ExportFormatSpecPtr format, unsigned return (sf_format_check (&sf_info) == SF_TRUE ? true : false); } +void +ExportProfileManager::build_filenames(std::list & result, ExportFilenamePtr filename, + TimespanListPtr timespans, ExportChannelConfigPtr channel_config, + ExportFormatSpecPtr format) +{ + for (std::list::iterator timespan_it = timespans->begin(); + timespan_it != timespans->end(); ++timespan_it) { + filename->set_timespan (*timespan_it); + + if (channel_config->get_split()) { + filename->include_channel = true; + + for (uint32_t chan = 1; chan <= channel_config->get_n_chans(); ++chan) { + filename->set_channel (chan); + result.push_back(filename->get_path (format)); + } + + } else { + filename->include_channel = false; + result.push_back(filename->get_path (format)); + } + } +} + }; // namespace ARDOUR -- cgit v1.2.3