2 Copyright (C) 2013 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "gtk2ardour-config.h"
27 #include "pbd/gstdio_compat.h"
30 #include <glibmm/datetime.h>
32 #include <gtkmm/filechooser.h>
33 #include <gtkmm/stock.h>
35 #include "pbd/basename.h"
36 #include "pbd/failed_constructor.h"
37 #include "pbd/file_utils.h"
38 #include "pbd/replace_all.h"
39 #include "pbd/whitespace.h"
40 #include "pbd/stacktrace.h"
41 #include "pbd/stl_delete.h"
42 #include "pbd/openuri.h"
44 #include "gtkmm2ext/utils.h"
45 #include "gtkmm2ext/keyboard.h"
47 #include "widgets/tooltips.h"
49 #include "ardour/audioengine.h"
50 #include "ardour/filesystem_paths.h"
51 #include "ardour/luascripting.h"
52 #include "ardour/recent_sessions.h"
53 #include "ardour/session.h"
54 #include "ardour/session_state_utils.h"
55 #include "ardour/template_utils.h"
56 #include "ardour/filename_extensions.h"
58 #include "LuaBridge/LuaBridge.h"
60 #include "ardour_ui.h"
61 #include "session_dialog.h"
63 #include "engine_dialog.h"
65 #include "ui_config.h"
73 using namespace ARDOUR;
74 using namespace ArdourWidgets;
75 using namespace ARDOUR_UI_UTILS;
77 SessionDialog::SessionDialog (bool require_new, const std::string& session_name, const std::string& session_path, const std::string& template_name, bool cancel_not_quit)
78 : ArdourDialog (_("Session Setup"), true, true)
79 , new_only (require_new)
80 , _provided_session_name (session_name)
81 , _provided_session_path (session_path)
82 , new_folder_chooser (FILE_CHOOSER_ACTION_SELECT_FOLDER)
83 , _existing_session_chooser_used (false)
85 set_position (WIN_POS_CENTER);
86 get_vbox()->set_spacing (6);
88 cancel_button = add_button ((cancel_not_quit ? Stock::CANCEL : Stock::QUIT), RESPONSE_CANCEL);
89 back_button = add_button (Stock::GO_BACK, RESPONSE_NO);
90 open_button = add_button (Stock::OPEN, RESPONSE_ACCEPT);
92 back_button->signal_button_press_event().connect (sigc::mem_fun (*this, &SessionDialog::back_button_pressed), false);
93 open_button->signal_button_press_event().connect (sigc::mem_fun (*this, &SessionDialog::open_button_pressed), false);
95 open_button->set_sensitive (false);
96 back_button->set_sensitive (false);
98 /* this is where announcements will be displayed, but it may be empty
99 * and invisible most of the time.
102 info_frame.set_shadow_type(SHADOW_ETCHED_OUT);
103 info_frame.set_no_show_all (true);
104 info_frame.set_border_width (12);
105 get_vbox()->pack_start (info_frame, false, false);
107 if (!template_name.empty()) {
108 load_template_override = template_name;
111 setup_new_session_page ();
114 setup_initial_choice_box ();
115 get_vbox()->pack_start (ic_vbox, true, true);
117 get_vbox()->pack_start (session_new_vbox, true, true);
120 get_vbox()->show_all ();
122 /* fill data models and show/hide accordingly */
124 populate_session_templates ();
126 if (recent_session_model) {
127 int cnt = redisplay_recent_sessions ();
129 recent_scroller.show();
130 recent_label.show ();
133 recent_scroller.set_size_request (-1, 300);
135 recent_scroller.set_size_request (-1, 80);
138 recent_scroller.hide();
139 recent_label.hide ();
144 SessionDialog::SessionDialog ()
145 : ArdourDialog (_("Recent Sessions"), true, true)
147 , _provided_session_name ("")
148 , _provided_session_path ("")
149 , _existing_session_chooser_used (false) // caller must check should_be_new
151 get_vbox()->set_spacing (6);
153 cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
154 open_button = add_button (Stock::OPEN, RESPONSE_ACCEPT);
155 open_button->set_sensitive (false);
157 setup_recent_sessions ();
159 get_vbox()->pack_start (recent_scroller, true, true);
160 get_vbox()->show_all ();
162 recent_scroller.show();
164 int cnt = redisplay_recent_sessions ();
166 recent_scroller.set_size_request (-1, 300);
168 recent_scroller.set_size_request (-1, 80);
173 SessionDialog::~SessionDialog()
178 SessionDialog::clear_given ()
180 _provided_session_path = "";
181 _provided_session_name = "";
185 SessionDialog::meta_master_bus_profile (std::string script_path) const
187 if (!Glib::file_test (script_path, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
193 lua_State* L = lua.getState();
197 "function ardour (entry)"
198 " ardourluainfo['type'] = assert(entry['type'])"
199 " ardourluainfo['master_bus'] = entry['master_bus'] or 2"
206 err = lua.do_file (script_path);
207 } catch (luabridge::LuaException const& e) {
218 luabridge::LuaRef nfo = luabridge::getGlobal (L, "ardourluainfo");
219 if (nfo.type() != LUA_TTABLE) {
223 if (nfo["master_bus"].type() != LUA_TNUMBER || nfo["type"].type() != LUA_TSTRING) {
227 LuaScriptInfo::ScriptType type = LuaScriptInfo::str2type (nfo["type"].cast<std::string>());
228 if (type != LuaScriptInfo::SessionInit) {
232 return nfo["master_bus"].cast<uint32_t>();
236 SessionDialog::master_channel_count ()
238 if (use_session_template ()) {
239 std::string tn = session_template_name();
240 if (tn.substr (0, 11) == "urn:ardour:") {
241 uint32_t mc = meta_master_bus_profile (tn.substr (11));
242 if (mc != UINT32_MAX) {
251 SessionDialog::use_session_template () const
253 if (!back_button->sensitive () && !new_only) {
254 /* open session -- not create a new one */
258 if (!load_template_override.empty()) {
262 if (template_chooser.get_selection()->count_selected_rows() > 0) {
270 SessionDialog::session_template_name ()
272 if (!load_template_override.empty()) {
273 /* compare to SessionDialog::populate_session_templates */
275 /* compare by name (path may or may not be UTF-8) */
276 vector<TemplateInfo> templates;
277 find_session_templates (templates, false);
278 for (vector<TemplateInfo>::iterator x = templates.begin(); x != templates.end(); ++x) {
279 if ((*x).name == load_template_override) {
284 /* look up script by name */
285 LuaScriptList scripts (LuaScripting::instance ().scripts (LuaScriptInfo::SessionInit));
286 LuaScriptList& as (LuaScripting::instance ().scripts (LuaScriptInfo::EditorAction));
287 for (LuaScriptList::const_iterator s = as.begin(); s != as.end(); ++s) {
288 if ((*s)->subtype & LuaScriptInfo::SessionSetup) {
289 scripts.push_back (*s);
292 std::sort (scripts.begin(), scripts.end(), LuaScripting::Sorter());
293 for (LuaScriptList::const_iterator s = scripts.begin(); s != scripts.end(); ++s) {
294 if ((*s)->name == load_template_override) {
295 return "urn:ardour:" + (*s)->path;
299 /* this will produce a more or less meaninful error later:
300 * "ERROR: Could not open session template [abs-path to user-config dir]"
302 return Glib::build_filename (ARDOUR::user_template_directory (), load_template_override);
305 if (template_chooser.get_selection()->count_selected_rows() > 0) {
307 TreeIter const iter = template_chooser.get_selection()->get_selected();
310 string s = (*iter)[session_template_columns.path];
319 SessionDialog::session_name (bool& should_be_new)
321 if (!_provided_session_name.empty()) {
322 /* user gave name on cmdline/invocation. Did they also specify
323 that it must be a new session?
325 should_be_new = new_only;
326 return _provided_session_name;
329 /* Try recent session selection */
331 TreeIter iter = recent_session_display.get_selection()->get_selected();
334 should_be_new = false;
335 string s = (*iter)[recent_session_columns.fullpath];
336 if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
337 return PBD::basename_nosuffix (s);
339 return (*iter)[recent_session_columns.visible_name];
342 if (_existing_session_chooser_used) {
343 /* existing session chosen from file chooser */
344 should_be_new = false;
345 return existing_session_chooser.get_filename ();
347 should_be_new = true;
348 string val = new_name_entry.get_text ();
349 strip_whitespace_edges (val);
355 SessionDialog::session_folder ()
357 if (!_provided_session_path.empty()) {
358 return _provided_session_path;
361 /* Try recent session selection */
363 TreeIter iter = recent_session_display.get_selection()->get_selected();
366 string s = (*iter)[recent_session_columns.fullpath];
367 if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
368 return Glib::path_get_dirname (s);
373 if (_existing_session_chooser_used) {
374 /* existing session chosen from file chooser */
375 return Glib::path_get_dirname (existing_session_chooser.get_current_folder ());
377 std::string val = new_name_entry.get_text();
378 strip_whitespace_edges (val);
379 std::string legal_session_folder_name = legalize_for_path (val);
380 return Glib::build_filename (new_folder_chooser.get_filename (), legal_session_folder_name);
385 SessionDialog::setup_recent_sessions ()
387 recent_session_model = TreeStore::create (recent_session_columns);
388 recent_session_model->signal_sort_column_changed().connect (sigc::mem_fun (*this, &SessionDialog::recent_session_sort_changed));
390 recent_session_display.set_model (recent_session_model);
391 recent_session_display.append_column (_("Session Name"), recent_session_columns.visible_name);
392 recent_session_display.append_column (_("Sample Rate"), recent_session_columns.sample_rate);
394 recent_session_display.append_column (_("Modified With"), recent_session_columns.modified_with);
396 recent_session_display.append_column (_("File Resolution"), recent_session_columns.disk_format);
398 recent_session_display.append_column (_("Last Modified"), recent_session_columns.time_formatted);
399 recent_session_display.set_headers_visible (true);
400 recent_session_display.get_selection()->set_mode (SELECTION_SINGLE);
402 recent_session_display.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::recent_session_row_selected));
404 recent_scroller.add (recent_session_display);
405 recent_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
406 recent_scroller.set_shadow_type (Gtk::SHADOW_IN);
408 recent_session_display.show();
409 recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &SessionDialog::recent_row_activated));
410 recent_session_display.signal_button_press_event().connect (sigc::mem_fun (*this, &SessionDialog::recent_button_press), false);
414 SessionDialog::setup_initial_choice_box ()
416 ic_vbox.set_spacing (6);
418 HBox* centering_hbox = manage (new HBox);
419 VBox* centering_vbox = manage (new VBox);
421 centering_vbox->set_spacing (6);
423 Label* new_label = manage (new Label);
424 new_label->set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("New Session")));
425 new_label->set_justify (JUSTIFY_CENTER);
427 ic_new_session_button.add (*new_label);
428 ic_new_session_button.signal_clicked().connect (sigc::mem_fun (*this, &SessionDialog::new_session_button_clicked));
430 Gtk::HBox* hbox = manage (new HBox);
431 Gtk::VBox* vbox = manage (new VBox);
432 hbox->set_spacing (12);
433 vbox->set_spacing (12);
437 Searchpath rc (ARDOUR::ardour_data_search_path());
438 rc.add_subdirectory_to_paths ("resources");
440 if (find_file (rc, PROGRAM_NAME "-small-splash.png", image_path)) {
442 if ((image = manage (new Gtk::Image (image_path))) != 0) {
443 hbox->pack_start (*image, false, false);
447 vbox->pack_start (ic_new_session_button, true, true, 20);
448 hbox->pack_start (*vbox, true, true, 20);
450 centering_vbox->pack_start (*hbox, false, false);
452 /* Possible update message */
454 if (ARDOUR_UI::instance()->announce_string() != "" ) {
456 Box *info_box = manage (new VBox);
457 info_box->set_border_width (12);
458 info_box->set_spacing (6);
460 info_box->pack_start (info_scroller_label, false, false);
462 info_scroller_count = 0;
463 info_scroller_connection = Glib::signal_timeout().connect (mem_fun(*this, &SessionDialog::info_scroller_update), 50);
465 Gtk::Button *updates_button = manage (new Gtk::Button (_("Check the website for more...")));
467 updates_button->signal_clicked().connect (mem_fun(*this, &SessionDialog::updates_button_clicked) );
468 set_tooltip (*updates_button, _("Click to open the program website in your web browser"));
470 info_box->pack_start (*updates_button, false, false);
472 info_frame.add (*info_box);
473 info_box->show_all ();
477 /* recent session scroller */
478 setup_recent_sessions ();
480 recent_label.set_no_show_all (true);
481 recent_scroller.set_no_show_all (true);
483 recent_label.set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("Recent Sessions")));
485 centering_vbox->pack_start (recent_label, false, false, 12);
486 centering_vbox->pack_start (recent_scroller, true, true);
490 existing_session_chooser.set_title (_("Select session file"));
491 existing_session_chooser.signal_file_set().connect (sigc::mem_fun (*this, &SessionDialog::existing_session_selected));
492 existing_session_chooser.set_current_folder(poor_mans_glob (Config->get_default_session_parent_dir()));
494 FileFilter session_filter;
495 session_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::statefile_suffix));
496 session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME));
497 existing_session_chooser.add_filter (session_filter);
499 FileFilter archive_filter;
500 archive_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::session_archive_suffix));
501 archive_filter.set_name (_("Session Archives"));
502 existing_session_chooser.add_filter (archive_filter);
504 existing_session_chooser.set_filter (session_filter);
506 Gtkmm2ext::add_volume_shortcuts (existing_session_chooser);
508 Label* browse_label = manage (new Label);
509 browse_label->set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("Other Sessions")));
511 centering_vbox->pack_start (*browse_label, false, false, 12);
512 centering_vbox->pack_start (existing_session_chooser, false, false);
514 /* --disable plugins UI */
516 _disable_plugins.set_label (_("Safe Mode: Disable all Plugins"));
517 _disable_plugins.set_flags (Gtk::CAN_FOCUS);
518 _disable_plugins.set_relief (Gtk::RELIEF_NORMAL);
519 _disable_plugins.set_mode (true);
520 _disable_plugins.set_active (ARDOUR::Session::get_disable_all_loaded_plugins());
521 _disable_plugins.set_border_width(0);
522 _disable_plugins.signal_clicked().connect (sigc::mem_fun (*this, &SessionDialog::disable_plugins_clicked));
523 centering_vbox->pack_start (_disable_plugins, false, false);
527 centering_hbox->pack_start (*centering_vbox, true, true);
528 ic_vbox.pack_start (*centering_hbox, true, true);
533 SessionDialog::session_selected ()
535 /* HACK HACK HACK ... change the "Apply" button label
539 Gtk::Widget* tl = ic_vbox.get_toplevel();
541 if ((win = dynamic_cast<Gtk::Window*>(tl)) != 0) {
542 /* ::get_default_widget() is not wrapped in gtkmm */
543 Gtk::Widget* def = wrap (gtk_window_get_default_widget (win->gobj()));
545 if ((button = dynamic_cast<Gtk::Button*>(def)) != 0) {
546 button->set_label (_("Open"));
552 SessionDialog::new_session_button_clicked ()
554 _existing_session_chooser_used = false;
555 recent_session_display.get_selection()->unselect_all ();
557 get_vbox()->remove (ic_vbox);
558 get_vbox()->pack_start (session_new_vbox, true, true);
559 back_button->set_sensitive (true);
560 new_name_entry.grab_focus ();
564 SessionDialog::back_button_pressed (GdkEventButton*)
566 get_vbox()->remove (session_new_vbox);
567 back_button->set_sensitive (false);
568 get_vbox()->pack_start (ic_vbox);
574 SessionDialog::open_button_pressed (GdkEventButton* ev)
576 if (Gtkmm2ext::Keyboard::modifier_state_equals (ev->state, Gtkmm2ext::Keyboard::PrimaryModifier)) {
577 _disable_plugins.set_active();
579 response (RESPONSE_ACCEPT);
584 SessionDialog::populate_session_templates ()
586 vector<TemplateInfo> templates;
588 find_session_templates (templates, true);
590 template_model->clear ();
592 /* Get Lua Scripts dedicated to session-setup */
593 LuaScriptList scripts (LuaScripting::instance ().scripts (LuaScriptInfo::SessionInit));
595 /* Add Lua Action Scripts which can also be used for session-setup */
596 LuaScriptList& as (LuaScripting::instance ().scripts (LuaScriptInfo::EditorAction));
597 for (LuaScriptList::const_iterator s = as.begin(); s != as.end(); ++s) {
598 if ((*s)->subtype & LuaScriptInfo::SessionSetup) {
599 scripts.push_back (*s);
603 std::sort (scripts.begin(), scripts.end(), LuaScripting::Sorter());
605 for (LuaScriptList::const_iterator s = scripts.begin(); s != scripts.end(); ++s) {
606 TreeModel::Row row = *(template_model->append ());
607 row[session_template_columns.name] = (*s)->name;
608 row[session_template_columns.path] = "urn:ardour:" + (*s)->path;
609 row[session_template_columns.description] = (*s)->description;
610 row[session_template_columns.modified_with_short] = _("{Factory Template}");
611 row[session_template_columns.modified_with_long] = _("{Factory Template}");
614 //Add any "template sessions" found in the user's preferences folder
615 for (vector<TemplateInfo>::iterator x = templates.begin(); x != templates.end(); ++x) {
618 row = *(template_model->append ());
620 row[session_template_columns.name] = (*x).name;
621 row[session_template_columns.path] = (*x).path;
622 row[session_template_columns.description] = (*x).description;
623 row[session_template_columns.modified_with_long] = (*x).modified_with;
624 row[session_template_columns.modified_with_short] = (*x).modified_with.substr(0, (*x).modified_with.find(" "));
627 //Add an explicit 'Empty Template' item
628 TreeModel::Row row = *template_model->prepend ();
629 row[session_template_columns.name] = (_("Empty Template"));
630 row[session_template_columns.path] = string();
631 row[session_template_columns.description] = _("An empty session with factory default settings.\n\nSelect this option if you are importing files to mix.");
632 row[session_template_columns.modified_with_short] = _("");
633 row[session_template_columns.modified_with_long] = _("");
635 //auto-select the first item in the list
636 Gtk::TreeModel::Row first = template_model->children()[0];
638 template_chooser.get_selection()->select(first);
643 SessionDialog::setup_new_session_page ()
645 session_new_vbox.set_border_width (8);
646 session_new_vbox.set_spacing (8);
648 Label* name_label = manage (new Label);
649 name_label->set_text (_("Session name:"));
651 HBox* name_hbox = manage (new HBox);
652 name_hbox->set_spacing (8);
653 name_hbox->pack_start (*name_label, false, true);
654 name_hbox->pack_start (new_name_entry, true, true);
656 //check to see if a session name was provided on command line
657 if (!ARDOUR_COMMAND_LINE::session_name.empty()) {
658 new_name_entry.set_text (Glib::path_get_basename (ARDOUR_COMMAND_LINE::session_name));
659 open_button->set_sensitive (true);
662 new_name_entry.signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::new_name_changed));
663 new_name_entry.signal_activate().connect (sigc::mem_fun (*this, &SessionDialog::new_name_activated));
665 //Folder location for the new session
666 Label* new_folder_label = manage (new Label);
667 new_folder_label->set_text (_("Create session folder in:"));
668 HBox* folder_box = manage (new HBox);
669 folder_box->set_spacing (8);
670 folder_box->pack_start (*new_folder_label, false, false);
671 folder_box->pack_start (new_folder_chooser, true, true);
673 //determine the text in the new folder selector
674 if (!ARDOUR_COMMAND_LINE::session_name.empty()) {
675 new_folder_chooser.set_current_folder (poor_mans_glob (Glib::path_get_dirname (ARDOUR_COMMAND_LINE::session_name)));
676 } else if (ARDOUR_UI::instance()->the_session ()) {
677 // point the new session file chooser at the parent directory of the current session
678 string session_parent_dir = Glib::path_get_dirname(ARDOUR_UI::instance()->the_session()->path());
679 new_folder_chooser.set_current_folder (session_parent_dir);
680 string default_session_folder = poor_mans_glob (Config->get_default_session_parent_dir());
683 /* add_shortcut_folder throws an exception if the folder being added already has a shortcut */
684 new_folder_chooser.add_shortcut_folder (default_session_folder);
686 catch (Glib::Error & e) {
687 std::cerr << "new_folder_chooser.add_shortcut_folder (" << default_session_folder << ") threw Glib::Error " << e.what() << std::endl;
690 new_folder_chooser.set_current_folder (poor_mans_glob (Config->get_default_session_parent_dir()));
692 new_folder_chooser.show ();
693 new_folder_chooser.set_title (_("Select folder for session"));
694 Gtkmm2ext::add_volume_shortcuts (new_folder_chooser);
696 //Template & Template Description area
697 HBox* template_hbox = manage (new HBox);
699 //if the "template override" is provided, don't give the user any template selections (?)
700 if (load_template_override.empty()) {
701 template_hbox->set_spacing (8);
703 Gtk::ScrolledWindow *template_scroller = manage (new Gtk::ScrolledWindow());
704 template_scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
705 template_scroller->add (template_chooser);
707 Gtk::ScrolledWindow *desc_scroller = manage (new Gtk::ScrolledWindow());
708 desc_scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
709 desc_scroller->add (template_desc);
711 template_hbox->pack_start (*template_scroller, true, true);
713 template_desc_frame.set_name (X_("TextHighlightFrame"));
714 template_desc_frame.add (*desc_scroller);
715 template_hbox->pack_start (template_desc_frame, true, true);
718 //template_desc is the textview that displays the currently selected template's description
719 template_desc.set_editable (false);
720 template_desc.set_wrap_mode (Gtk::WRAP_WORD);
721 template_desc.set_size_request (300,400);
722 template_desc.set_name (X_("TextOnBackground"));
723 template_desc.set_border_width (6);
725 //template_chooser is the treeview showing available templates
726 template_model = TreeStore::create (session_template_columns);
727 template_chooser.set_model (template_model);
728 template_chooser.append_column (_("Template"), session_template_columns.name);
730 template_chooser.append_column (_("Modified With"), session_template_columns.modified_with_short);
732 template_chooser.set_headers_visible (true);
733 template_chooser.get_selection()->set_mode (SELECTION_SINGLE);
734 template_chooser.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::template_row_selected));
735 template_chooser.set_sensitive (true);
736 if (UIConfiguration::instance().get_use_tooltips()) {
737 template_chooser.set_tooltip_column(4); // modified_with_long
740 session_new_vbox.pack_start (*template_hbox, true, true);
741 session_new_vbox.pack_start (*folder_box, false, true);
742 session_new_vbox.pack_start (*name_hbox, false, true);
743 session_new_vbox.show_all ();
747 SessionDialog::new_name_changed ()
749 if (!new_name_entry.get_text().empty()) {
751 open_button->set_sensitive (true);
753 open_button->set_sensitive (false);
758 SessionDialog::new_name_activated ()
760 response (RESPONSE_ACCEPT);
764 SessionDialog::redisplay_recent_sessions ()
766 std::vector<std::string> session_directories;
767 RecentSessionsSorter cmp;
769 recent_session_display.set_model (Glib::RefPtr<TreeModel>(0));
770 recent_session_model->clear ();
772 ARDOUR::RecentSessions rs;
773 ARDOUR::read_recent_sessions (rs);
776 recent_session_display.set_model (recent_session_model);
780 // sort them alphabetically
781 sort (rs.begin(), rs.end(), cmp);
783 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
784 session_directories.push_back ((*i).second);
787 int session_snapshot_count = 0;
789 for (vector<std::string>::const_iterator i = session_directories.begin(); i != session_directories.end(); ++i)
791 std::vector<std::string> state_file_paths;
793 // now get available states for this session
795 get_state_files_in_directory (*i, state_file_paths);
797 vector<string> states;
798 vector<const gchar*> item;
801 /* remove any trailing / */
803 if (dirname[dirname.length()-1] == '/') {
804 dirname = dirname.substr (0, dirname.length()-1);
807 /* check whether session still exists */
808 if (!Glib::file_test(dirname.c_str(), Glib::FILE_TEST_EXISTS)) {
809 /* session doesn't exist */
813 /* now get available states for this session */
815 states = Session::possible_states (dirname);
817 if (states.empty()) {
822 std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
824 if (state_file_names.empty()) {
830 std::string program_version;
832 std::string state_file_basename;
834 if (state_file_names.size() > 1) {
835 state_file_basename = Session::get_snapshot_from_instant (dirname);
836 std::string s = Glib::build_filename (dirname, state_file_basename + statefile_suffix);
837 if (!Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
838 state_file_basename = "";
842 if (state_file_basename.empty()) {
843 state_file_basename = state_file_names.front();
846 std::string s = Glib::build_filename (dirname, state_file_basename + statefile_suffix);
848 int err = Session::get_info_from_path (s, sr, sf, program_version);
850 // XML cannot be parsed, or unsuppored version
855 g_stat (s.c_str(), &gsb);
857 Gtk::TreeModel::Row row = *(recent_session_model->append());
858 row[recent_session_columns.fullpath] = s;
859 row[recent_session_columns.time_modified] = gsb.st_mtime;
863 row[recent_session_columns.sample_rate] = rate_as_string (sr);
866 row[recent_session_columns.disk_format] = _("32-bit float");
869 row[recent_session_columns.disk_format] = _("24-bit");
872 row[recent_session_columns.disk_format] = _("16-bit");
876 row[recent_session_columns.sample_rate] = "??";
877 row[recent_session_columns.disk_format] = "--";
880 if (program_version.empty()) {
881 row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (dirname);
883 row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (dirname + "\n" + string_compose (_("Last modified with: %1"), program_version));
884 row[recent_session_columns.modified_with] = program_version;
887 ++session_snapshot_count;
889 if (state_file_names.size() > 1) {
890 // multiple session files in the session directory - show the directory name.
891 // if there's not a session file with the same name as the session directory,
892 // opening the parent item will fail, but expanding it will show the session
893 // files that actually exist, and the right one can then be opened.
894 row[recent_session_columns.visible_name] = Glib::path_get_basename (dirname);
895 int64_t most_recent = 0;
899 for (std::vector<std::string>::iterator i2 = state_file_names.begin(); i2 != state_file_names.end(); ++i2) {
901 s = Glib::build_filename (dirname, *i2 + statefile_suffix);
902 Gtk::TreeModel::Row child_row = *(recent_session_model->append (row.children()));
904 child_row[recent_session_columns.visible_name] = *i2;
905 child_row[recent_session_columns.fullpath] = s;
906 child_row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (dirname);
907 g_stat (s.c_str(), &gsb);
908 child_row[recent_session_columns.time_modified] = gsb.st_mtime;
910 Glib::DateTime gdt(Glib::DateTime::create_now_local (gsb.st_mtime));
911 child_row[recent_session_columns.time_formatted] = gdt.format ("%F %H:%M");
913 if (gsb.st_mtime > most_recent) {
914 most_recent = gsb.st_mtime;
917 if (++kidcount < 5) {
918 // parse "modified with" for the first 5 snapshots
919 if (Session::get_info_from_path (s, sr, sf, program_version) == 0) {
921 child_row[recent_session_columns.sample_rate] = rate_as_string (sr);
924 child_row[recent_session_columns.disk_format] = _("32-bit float");
927 child_row[recent_session_columns.disk_format] = _("24-bit");
930 child_row[recent_session_columns.disk_format] = _("16-bit");
934 child_row[recent_session_columns.sample_rate] = "";
935 child_row[recent_session_columns.disk_format] = "";
938 child_row[recent_session_columns.sample_rate] = "??";
939 child_row[recent_session_columns.disk_format] = "--";
941 if (!program_version.empty()) {
942 child_row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (string_compose (_("Last modified with: %1"), program_version));
945 child_row[recent_session_columns.sample_rate] = "";
946 child_row[recent_session_columns.disk_format] = "";
949 ++session_snapshot_count;
952 assert (most_recent >= row[recent_session_columns.time_modified]);
953 row[recent_session_columns.time_modified] = most_recent;
956 // only a single session file in the directory - show its actual name.
957 row[recent_session_columns.visible_name] = state_file_basename;
960 Glib::DateTime gdt(Glib::DateTime::create_now_local (row[recent_session_columns.time_modified]));
961 row[recent_session_columns.time_formatted] = gdt.format ("%F %H:%M");
964 if (UIConfiguration::instance().get_use_tooltips()) {
965 recent_session_display.set_tooltip_column(1); // recent_session_columns.tip
967 recent_session_display.set_model (recent_session_model);
970 Gtk::TreeView::Column* pColumn;
971 if ((pColumn = recent_session_display.get_column (0))) { // name
972 pColumn->set_sort_column (recent_session_columns.visible_name);
974 if ((pColumn = recent_session_display.get_column (3))) { // date
975 pColumn->set_sort_column (recent_session_columns.time_modified); // unixtime
978 int32_t sort = UIConfiguration::instance().get_recent_session_sort();
979 if (abs(sort) != 1 + recent_session_columns.visible_name.index () &&
980 abs(sort) != 1 + recent_session_columns.time_modified.index ()) {
981 sort = 1 + recent_session_columns.visible_name.index();
983 recent_session_model->set_sort_column (abs (sort) -1, sort < 0 ? Gtk::SORT_DESCENDING : Gtk::SORT_ASCENDING);
985 return session_snapshot_count;
989 SessionDialog::recent_session_sort_changed ()
993 if (recent_session_model->get_sort_column_id (column, order)) {
994 int32_t sort = (column + 1) * (order == Gtk::SORT_DESCENDING ? -1 : 1);
995 if (sort != UIConfiguration::instance().get_recent_session_sort()) {
996 UIConfiguration::instance().set_recent_session_sort(sort);
1002 SessionDialog::recent_session_row_selected ()
1004 if (recent_session_display.get_selection()->count_selected_rows() > 0) {
1005 open_button->set_sensitive (true);
1006 session_selected ();
1008 open_button->set_sensitive (false);
1013 SessionDialog::template_row_selected ()
1015 if (template_chooser.get_selection()->count_selected_rows() > 0) {
1016 TreeIter iter = template_chooser.get_selection()->get_selected();
1019 string s = (*iter)[session_template_columns.description];
1020 template_desc.get_buffer()->set_text (s);
1026 SessionDialog::recent_row_activated (const Gtk::TreePath&, Gtk::TreeViewColumn*)
1028 response (RESPONSE_ACCEPT);
1032 SessionDialog::recent_button_press (GdkEventButton* ev)
1034 if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 3) ) {
1036 TreeModel::Path path;
1037 TreeViewColumn* column;
1039 if (recent_session_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
1040 Glib::RefPtr<Gtk::TreeView::Selection> selection = recent_session_display.get_selection();
1042 selection->unselect_all();
1043 selection->select(path);
1047 if (recent_session_display.get_selection()->count_selected_rows() > 0) {
1048 recent_context_mennu (ev);
1055 SessionDialog::recent_context_mennu (GdkEventButton *ev)
1057 using namespace Gtk::Menu_Helpers;
1059 TreeIter iter = recent_session_display.get_selection()->get_selected();
1061 string s = (*iter)[recent_session_columns.fullpath];
1062 if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
1063 s = Glib::path_get_dirname (s);
1065 if (!Glib::file_test (s, Glib::FILE_TEST_IS_DIR)) {
1069 Gtk::TreeModel::Path tpath = recent_session_model->get_path(iter);
1070 const bool is_child = tpath.up () && tpath.up ();
1072 Gtk::Menu* m = ARDOUR_UI::instance()->shared_popup_menu ();
1073 MenuList& items = m->items ();
1074 items.push_back (MenuElem (s, sigc::bind (sigc::hide_return (sigc::ptr_fun (&PBD::open_folder)), s)));
1076 items.push_back (SeparatorElem());
1077 items.push_back (MenuElem (_("Remove session from recent list"), sigc::mem_fun (*this, &SessionDialog::recent_remove_selected)));
1079 m->popup (ev->button, ev->time);
1083 SessionDialog::recent_remove_selected ()
1085 TreeIter iter = recent_session_display.get_selection()->get_selected();
1087 string s = (*iter)[recent_session_columns.fullpath];
1088 if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
1089 s = Glib::path_get_dirname (s);
1091 ARDOUR::remove_recent_sessions (s);
1092 redisplay_recent_sessions ();
1096 SessionDialog::disable_plugins_clicked ()
1098 ARDOUR::Session::set_disable_all_loaded_plugins (_disable_plugins.get_active());
1102 SessionDialog::existing_session_selected ()
1104 _existing_session_chooser_used = true;
1105 recent_session_display.get_selection()->unselect_all();
1106 /* mark this sensitive in case we come back here after a failed open
1107 * attempt and the user has hacked up the fix. sigh.
1109 open_button->set_sensitive (true);
1110 response (RESPONSE_ACCEPT);
1114 SessionDialog::updates_button_clicked ()
1116 //now open a browser window so user can see more
1117 PBD::open_uri (Config->get_updates_url());
1121 SessionDialog::info_scroller_update()
1123 info_scroller_count++;
1126 snprintf (buf, std::min(info_scroller_count,sizeof(buf)-1), "%s", ARDOUR_UI::instance()->announce_string().c_str() );
1127 buf[info_scroller_count] = 0;
1128 info_scroller_label.set_text (buf);
1129 info_scroller_label.show();
1131 if (info_scroller_count > ARDOUR_UI::instance()->announce_string().length()) {
1132 info_scroller_connection.disconnect();
1139 SessionDialog::on_delete_event (GdkEventAny* ev)
1141 response (RESPONSE_CANCEL);
1142 return ArdourDialog::on_delete_event (ev);