diff --git a/gtk2_ardour/session_dialog.cc b/gtk2_ardour/session_dialog.cc index 299fa1620e..028a0dde37 100644 --- a/gtk2_ardour/session_dialog.cc +++ b/gtk2_ardour/session_dialog.cc @@ -75,12 +75,26 @@ SessionDialog::SessionDialog (WM::Proxy& system_configuratio _recent_session_button[8] = &get_waves_button ("recent_session_button_8"); _recent_session_button[9] = &get_waves_button ("recent_session_button_9"); + _recent_template_button[0] = &get_waves_button ("recent_template_button_0"); + _recent_template_button[1] = &get_waves_button ("recent_template_button_1"); + _recent_template_button[2] = &get_waves_button ("recent_template_button_2"); + _recent_template_button[3] = &get_waves_button ("recent_template_button_3"); + _recent_template_button[4] = &get_waves_button ("recent_template_button_4"); + _recent_template_button[5] = &get_waves_button ("recent_template_button_5"); + _recent_template_button[6] = &get_waves_button ("recent_template_button_6"); + _recent_template_button[7] = &get_waves_button ("recent_template_button_7"); + _recent_template_button[8] = &get_waves_button ("recent_template_button_8"); + _recent_template_button[9] = &get_waves_button ("recent_template_button_9"); + for (size_t i = 0; i < MAX_RECENT_SESSION_COUNT; i++) { - _recent_session_button[i]->signal_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_recent_session )); + _recent_session_button[i]->signal_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_recent_object )); _recent_session_button[i]->signal_double_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_recent_session_double_click )); } - _open_selected_button.set_sensitive (false); + for (size_t i = 0; i < MAX_RECENT_TEMPLATE_COUNT; i++) { + _recent_template_button[i]->signal_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_recent_object )); + _recent_template_button[i]->signal_double_clicked.connect (sigc::mem_fun (*this, &SessionDialog::on_recent_template_double_click )); + } } SessionDialog::~SessionDialog() diff --git a/gtk2_ardour/session_dialog.h b/gtk2_ardour/session_dialog.h index e67a382a10..bcf4da7333 100644 --- a/gtk2_ardour/session_dialog.h +++ b/gtk2_ardour/session_dialog.h @@ -53,6 +53,7 @@ class TracksControlPanel; class EngineControl; #define MAX_RECENT_SESSION_COUNT 10 +#define MAX_RECENT_TEMPLATE_COUNT 10 class SessionDialog : public WavesDialog { public: SessionDialog (WM::Proxy& system_configuration_dialog, @@ -72,6 +73,7 @@ class SessionDialog : public WavesDialog { WavesButton& _open_saved_session_button; WavesButton& _system_configuration_button; WavesButton* _recent_session_button[MAX_RECENT_SESSION_COUNT]; + WavesButton* _recent_template_button[MAX_RECENT_TEMPLATE_COUNT]; Gtk::Label& _session_details_label_1; Gtk::Label& _session_details_label_2; Gtk::Label& _session_details_label_3; diff --git a/gtk2_ardour/session_dialog.logic.cc b/gtk2_ardour/session_dialog.logic.cc index d58b3c0840..e0a547698e 100644 --- a/gtk2_ardour/session_dialog.logic.cc +++ b/gtk2_ardour/session_dialog.logic.cc @@ -62,12 +62,14 @@ using namespace Glib; using namespace PBD; using namespace ARDOUR; +#if (0) // let's keep it for a time per possible need in future. static string poor_mans_glob (string path) { string copy = path; replace_all (copy, "~", Glib::get_home_dir()); return copy; } +#endif void SessionDialog::set_engine_state_controller (EngineStateController* _engine_state_controller) { @@ -85,7 +87,8 @@ void SessionDialog::redisplay () } redisplay_system_configuration (); - redisplay_recent_sessions(); + redisplay_recent_sessions (); + redisplay_recent_templates (); } void @@ -127,11 +130,6 @@ SessionDialog::session_folder () return ""; } -void -SessionDialog::session_selected () -{ -} - void SessionDialog::on_new_session (WavesButton*) { @@ -141,6 +139,14 @@ SessionDialog::on_new_session (WavesButton*) void SessionDialog::on_new_session_with_template (WavesButton*) { + std::vector template_types = boost::assign::list_of (ARDOUR::template_suffix + 1); //WOW!!!! + std::vector selected_files = ARDOUR::open_file_dialog(template_types, false, Config->get_default_session_parent_dir(), _("Select Template")); + if (selected_files.empty ()) { + set_keep_above(true); + return; + } else { + _session_template_full_name = selected_files [0]; + } new_session (true); } @@ -184,18 +190,14 @@ SessionDialog::redisplay_recent_sessions () } std::vector session_directories; - RecentSessionsSorter cmp; ARDOUR::RecentSessions rs; ARDOUR::read_recent_sessions (rs); - if (rs.empty()) { + if (rs.empty ()) { return 0; } - // sort them alphabetically - // sort (rs.begin(), rs.end(), cmp); - for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) { session_directories.push_back ((*i).second); } @@ -231,10 +233,10 @@ SessionDialog::redisplay_recent_sessions () states = Session::possible_states (dirname); - if (states.empty()) { - /* no state file? */ - continue; - } + if (states.empty()) { + /* no state file? */ + continue; + } std::vector state_file_names(get_file_names_no_extension (state_file_paths)); @@ -252,6 +254,53 @@ SessionDialog::redisplay_recent_sessions () return session_snapshot_count; } +int +SessionDialog::redisplay_recent_templates () +{ + for (size_t i = 0; i < MAX_RECENT_SESSION_COUNT; i++) { + _recent_template_button[i]->set_active_state (Gtkmm2ext::Off); + _recent_template_button[i]->set_sensitive (false); + } + + std::deque rt; + ARDOUR::read_recent_templates (rt); + + if (rt.empty ()) { + return 0; + } + + int session_template_count = 0; + for (std::deque::const_iterator i = rt.begin(); i != rt.end(); ++i) { + + /* check whether template still exists and it's a regular file*/ + if (!Glib::file_test((*i).c_str(), Glib::FILE_TEST_IS_REGULAR)) { + /* such regular file doesn't exist */ + continue; + } + + /* now get available states for this session */ + _recent_template_full_name[session_template_count ] = *i; + std::string basename = Glib::path_get_basename (*i); + std::string::size_type pos = basename.find_last_of ("."); + if (pos != std::string::npos) { + std::string filetype = basename.substr (pos); + std::string template_suffix = ARDOUR::template_suffix; + boost::to_lower (template_suffix); + boost::to_lower (filetype); + if (filetype == template_suffix) { + basename = basename.substr (0, pos); + } + } + _recent_template_button[session_template_count ]->set_text (basename); + _recent_template_button[session_template_count ]->set_sensitive (true); + + ARDOUR_UI::instance()->set_tip (*_recent_template_button[session_template_count ], *i); + ++session_template_count; + } + + return ++session_template_count; +} + bool SessionDialog::on_delete_event (GdkEventAny* ev) { @@ -270,50 +319,69 @@ SessionDialog::on_quit (WavesButton*) void SessionDialog::on_open_selected (WavesButton*) { - hide(); - response (Gtk::RESPONSE_ACCEPT); + switch (_selection_type) { + case RecentSession: + hide(); + response (Gtk::RESPONSE_ACCEPT); + break; + case RecentTemplate: + new_session (true); + break; + default: + break; + } } void SessionDialog::on_open_saved_session (WavesButton*) { set_keep_above(false); - string temp_session_full_file_name = ARDOUR::open_file_dialog(Config->get_default_session_parent_dir(), _("Select Saved Session")); - set_keep_above(true); + string temp_session_full_file_name = ARDOUR::open_file_dialog(Config->get_default_session_parent_dir(), _("Select Saved Session")); + set_keep_above(true); - if(!temp_session_full_file_name.empty()) { - _selected_session_full_name = temp_session_full_file_name; - for (size_t i = 0; i < MAX_RECENT_SESSION_COUNT; i++) { - _recent_session_button[i]->set_active_state (Gtkmm2ext::Off); - } - _selection_type = SavedSession; - hide (); - response (Gtk::RESPONSE_ACCEPT); - } + if(!temp_session_full_file_name.empty()) { + _selected_session_full_name = temp_session_full_file_name; + for (size_t i = 0; i < MAX_RECENT_SESSION_COUNT; i++) { + _recent_session_button[i]->set_active_state (Gtkmm2ext::Off); + } + _selection_type = SavedSession; + hide (); + response (Gtk::RESPONSE_ACCEPT); + } return; } void -SessionDialog::on_recent_session (WavesButton* clicked_button) +SessionDialog::on_recent_object (WavesButton* clicked_button) { if (clicked_button->get_active()) { return; } else { _selected_session_full_name = ""; + _session_template_full_name = ""; _selection_type = Nothing; for (size_t i = 0; i < MAX_RECENT_SESSION_COUNT; i++) { if (_recent_session_button[i] == clicked_button) { _selected_session_full_name = _recent_session_full_name[i]; _recent_session_button[i]->set_active_state(Gtkmm2ext::ExplicitActive); + _selection_type = RecentSession; } else { _recent_session_button[i]->set_active_state(Gtkmm2ext::Off); - _selection_type = RecentSession; + } + } + for (size_t i = 0; i < MAX_RECENT_SESSION_COUNT; i++) { + if (_recent_template_button[i] == clicked_button) { + _session_template_full_name = _recent_template_full_name[i]; + _recent_template_button[i]->set_active_state(Gtkmm2ext::ExplicitActive); + _selection_type = RecentTemplate; + } else { + _recent_template_button[i]->set_active_state(Gtkmm2ext::Off); } } } - _open_selected_button.set_sensitive (_selection_type == RecentSession); + _open_selected_button.set_sensitive ((_selection_type == RecentSession) || (_selection_type == RecentTemplate)); } void @@ -326,6 +394,11 @@ SessionDialog::on_recent_session_double_click (WavesButton* button) response (Gtk::RESPONSE_ACCEPT); } +void +SessionDialog::on_recent_template_double_click (WavesButton* button) +{ +} + void SessionDialog::on_system_configuration (WavesButton* clicked_button) { @@ -372,17 +445,8 @@ void SessionDialog::new_session (bool with_template) { set_keep_above(false); - if (with_template) { - std::vector template_types = boost::assign::list_of (ARDOUR::template_suffix + 1); //WOW!!!! - std::vector selected_files = ARDOUR::open_file_dialog(template_types, false, Config->get_default_session_parent_dir(), _("Select Template")); - if (selected_files.empty ()) { - set_keep_above(true); - return; - } else { - _session_template = selected_files [0]; - } - } else { - _session_template.clear (); + if (!with_template) { + _session_template_full_name.clear (); } std::string temp_session_full_file_name = ARDOUR::save_file_dialog(Config->get_default_session_parent_dir(),_("Create New Session")); diff --git a/gtk2_ardour/session_dialog.logic.h b/gtk2_ardour/session_dialog.logic.h index b1e2c7f6b9..637e005f34 100644 --- a/gtk2_ardour/session_dialog.logic.h +++ b/gtk2_ardour/session_dialog.logic.h @@ -25,24 +25,24 @@ std::string session_name (bool& should_be_new); std::string session_folder (); - bool use_session_template() { return _session_template.empty () == false; } - std::string session_template_name() { return _session_template; } + bool use_session_template() { return _session_template_full_name.empty () == false; } + std::string session_template_name () { return _session_template_full_name; } // advanced session options - bool create_master_bus() const { return true; } - int master_channel_count() const { return 2; } + bool create_master_bus () const { return true; } + int master_channel_count () const { return 2; } - bool connect_inputs() const { return true; } - bool limit_inputs_used_for_connection() const { return false; } - int input_limit_count() const { return 0; } + bool connect_inputs () const { return true; } + bool limit_inputs_used_for_connection () const { return false; } + int input_limit_count () const { return 0; } - bool connect_outputs() const { return true; } - bool limit_outputs_used_for_connection() const { return false; } - int output_limit_count() const { return 0; } + bool connect_outputs () const { return true; } + bool limit_outputs_used_for_connection () const { return false; } + int output_limit_count () const { return 0; } - bool connect_outs_to_master() const { return true; } - bool connect_outs_to_physical() const { return false; } + bool connect_outs_to_master () const { return true; } + bool connect_outs_to_physical () const { return false; } void set_selected_session_full_path (std::string path) { _selected_session_full_name = path; } void set_session_info (bool require_new, @@ -56,13 +56,14 @@ enum SessionSelectionType { Nothing, RecentSession, + RecentTemplate, SavedSession, NewSession } _selection_type; struct RecentSessionsSorter { bool operator() (std::pair a, std::pair b) const { - return ARDOUR::cmp_nocase(a.first, b.first) == -1; + return ARDOUR::cmp_nocase (a.first, b.first) == -1; } }; @@ -71,12 +72,13 @@ std::string _provided_session_name; std::string _provided_session_path; std::string _recent_session_full_name[MAX_RECENT_SESSION_COUNT]; + std::string _recent_template_full_name[MAX_RECENT_TEMPLATE_COUNT]; std::string _selected_session_full_name; bool _existing_session_chooser_used; ///< set to true when the existing session chooser has been used Gtk::Label _info_scroller_label; std::string::size_type _info_scroller_count; sigc::connection _info_scroller_connection; - std::string _session_template; + std::string _session_template_full_name; // methods void on_quit (WavesButton*); @@ -84,17 +86,18 @@ void on_open_saved_session (WavesButton*); void on_new_session (WavesButton*); void on_new_session_with_template (WavesButton*); - void on_recent_session (WavesButton*); + void on_recent_object (WavesButton*); void on_recent_session_double_click (WavesButton*); + void on_recent_template_double_click (WavesButton*); void on_system_configuration (WavesButton*); bool on_delete_event (GdkEventAny*); bool on_key_press_event (GdkEventKey*); - void on_system_configuration_change(); + void on_system_configuration_change (); void redisplay_system_configuration(); int redisplay_recent_sessions (); - void session_selected (); - bool info_scroller_update(); + int redisplay_recent_templates (); + bool info_scroller_update (); void update_recent_session_buttons (); void new_session (bool with_template); diff --git a/gtk2_ardour/ui/session_dialog.xml b/gtk2_ardour/ui/session_dialog.xml index 5c03195950..a2b13c379c 100644 --- a/gtk2_ardour/ui/session_dialog.xml +++ b/gtk2_ardour/ui/session_dialog.xml @@ -14,7 +14,7 @@ fgdisabled ="#959595" bordercolor="#7E7E7E"/>