2 * Copyright (C) 2013-2019 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2014-2015 Tim Mayberry <mojofunk@gmail.com>
4 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
5 * Copyright (C) 2014 Colin Fletcher <colin.m.fletcher@googlemail.com>
6 * Copyright (C) 2015 Nick Mainsbridge <mainsbridge@gmail.com>
7 * Copyright (C) 2017 Ben Loftis <ben@harrisonconsoles.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.
25 #include "gtk2ardour-config.h"
31 #include "pbd/gstdio_compat.h"
34 #include <glibmm/datetime.h>
36 #include <gtkmm/filechooser.h>
37 #include <gtkmm/stock.h>
39 #include "pbd/basename.h"
40 #include "pbd/failed_constructor.h"
41 #include "pbd/file_utils.h"
42 #include "pbd/replace_all.h"
43 #include "pbd/whitespace.h"
44 #include "pbd/stacktrace.h"
45 #include "pbd/stl_delete.h"
46 #include "pbd/openuri.h"
48 #include "gtkmm2ext/utils.h"
49 #include "gtkmm2ext/keyboard.h"
51 #include "widgets/tooltips.h"
53 #include "ardour/audioengine.h"
54 #include "ardour/filesystem_paths.h"
55 #include "ardour/luascripting.h"
56 #include "ardour/recent_sessions.h"
57 #include "ardour/session.h"
58 #include "ardour/session_state_utils.h"
59 #include "ardour/template_utils.h"
60 #include "ardour/filename_extensions.h"
62 #include "LuaBridge/LuaBridge.h"
64 #include "ardour_ui.h"
65 #include "session_dialog.h"
67 #include "engine_dialog.h"
69 #include "ui_config.h"
77 using namespace ARDOUR;
78 using namespace ArdourWidgets;
79 using namespace ARDOUR_UI_UTILS;
81 SessionDialog::SessionDialog (bool require_new, const std::string& session_name, const std::string& session_path, const std::string& template_name, bool cancel_not_quit)
82 : ArdourDialog (_("Session Setup"), true, true)
83 , new_only (require_new)
84 , new_folder_chooser (FILE_CHOOSER_ACTION_SELECT_FOLDER)
85 , _existing_session_chooser_used (false)
87 set_position (WIN_POS_CENTER);
88 get_vbox()->set_spacing (6);
90 cancel_button = add_button ((cancel_not_quit ? Stock::CANCEL : Stock::QUIT), RESPONSE_CANCEL);
91 back_button = add_button (Stock::GO_BACK, RESPONSE_NO);
92 open_button = add_button (Stock::OPEN, RESPONSE_ACCEPT);
94 back_button->signal_button_press_event().connect (sigc::mem_fun (*this, &SessionDialog::back_button_pressed), false);
95 open_button->signal_button_press_event().connect (sigc::mem_fun (*this, &SessionDialog::open_button_pressed), false);
97 open_button->set_sensitive (false);
98 back_button->set_sensitive (false);
100 /* this is where announcements will be displayed, but it may be empty
101 * and invisible most of the time.
104 info_frame.set_shadow_type(SHADOW_ETCHED_OUT);
105 info_frame.set_no_show_all (true);
106 info_frame.set_border_width (12);
107 get_vbox()->pack_start (info_frame, false, false);
109 if (!template_name.empty()) {
110 load_template_override = template_name;
113 setup_new_session_page ();
116 setup_initial_choice_box ();
117 get_vbox()->pack_start (ic_vbox, true, true);
119 get_vbox()->pack_start (session_new_vbox, true, true);
122 get_vbox()->show_all ();
124 /* fill data models and show/hide accordingly */
126 populate_session_templates ();
128 if (recent_session_model) {
129 int cnt = redisplay_recent_sessions ();
131 recent_scroller.show();
132 recent_label.show ();
135 recent_scroller.set_size_request (-1, 300);
137 recent_scroller.set_size_request (-1, 80);
140 recent_scroller.hide();
141 recent_label.hide ();
146 SessionDialog::SessionDialog ()
147 : ArdourDialog (_("Recent Sessions"), true, true)
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::meta_master_bus_profile (std::string script_path)
180 if (!Glib::file_test (script_path, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
186 lua_State* L = lua.getState();
190 "function ardour (entry)"
191 " ardourluainfo['type'] = assert(entry['type'])"
192 " ardourluainfo['master_bus'] = entry['master_bus'] or 2"
199 err = lua.do_file (script_path);
200 } catch (luabridge::LuaException const& e) {
211 luabridge::LuaRef nfo = luabridge::getGlobal (L, "ardourluainfo");
212 if (nfo.type() != LUA_TTABLE) {
216 if (nfo["master_bus"].type() != LUA_TNUMBER || nfo["type"].type() != LUA_TSTRING) {
220 LuaScriptInfo::ScriptType type = LuaScriptInfo::str2type (nfo["type"].cast<std::string>());
221 if (type != LuaScriptInfo::SessionInit) {
225 return nfo["master_bus"].cast<uint32_t>();
229 SessionDialog::master_channel_count ()
231 if (use_session_template ()) {
232 std::string tn = session_template_name();
233 if (tn.substr (0, 11) == "urn:ardour:") {
234 uint32_t mc = meta_master_bus_profile (tn.substr (11));
235 if (mc != UINT32_MAX) {
244 SessionDialog::use_session_template () const
246 if (!back_button->sensitive () && !new_only) {
247 /* open session -- not create a new one */
251 if (template_chooser.get_selection()->count_selected_rows() > 0) {
259 SessionDialog::session_template_name ()
261 if (template_chooser.get_selection()->count_selected_rows() > 0) {
263 TreeIter const iter = template_chooser.get_selection()->get_selected();
266 string s = (*iter)[session_template_columns.path];
275 SessionDialog::clear_name ()
277 recent_session_display.get_selection()->unselect_all();
278 new_name_entry.set_text (string());
282 SessionDialog::session_name (bool& should_be_new)
284 /* Try recent session selection */
286 TreeIter iter = recent_session_display.get_selection()->get_selected();
289 should_be_new = false;
290 string s = (*iter)[recent_session_columns.fullpath];
291 if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
292 return PBD::basename_nosuffix (s);
294 return (*iter)[recent_session_columns.visible_name];
297 if (_existing_session_chooser_used) {
298 /* existing session chosen from file chooser */
299 should_be_new = false;
300 return existing_session_chooser.get_filename ();
302 should_be_new = true;
303 string val = new_name_entry.get_text ();
304 strip_whitespace_edges (val);
310 SessionDialog::session_folder ()
312 /* Try recent session selection */
314 TreeIter iter = recent_session_display.get_selection()->get_selected();
317 string s = (*iter)[recent_session_columns.fullpath];
318 if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
319 return Glib::path_get_dirname (s);
324 if (_existing_session_chooser_used) {
325 /* existing session chosen from file chooser */
326 return Glib::path_get_dirname (existing_session_chooser.get_current_folder ());
328 std::string val = new_name_entry.get_text();
329 strip_whitespace_edges (val);
330 std::string legal_session_folder_name = legalize_for_path (val);
331 return Glib::build_filename (new_folder_chooser.get_filename (), legal_session_folder_name);
336 SessionDialog::setup_recent_sessions ()
338 recent_session_model = TreeStore::create (recent_session_columns);
339 recent_session_model->signal_sort_column_changed().connect (sigc::mem_fun (*this, &SessionDialog::recent_session_sort_changed));
341 recent_session_display.set_model (recent_session_model);
342 recent_session_display.append_column (_("Session Name"), recent_session_columns.visible_name);
343 recent_session_display.append_column (_("Sample Rate"), recent_session_columns.sample_rate);
345 recent_session_display.append_column (_("Modified With"), recent_session_columns.modified_with);
347 recent_session_display.append_column (_("File Resolution"), recent_session_columns.disk_format);
349 recent_session_display.append_column (_("Last Modified"), recent_session_columns.time_formatted);
350 recent_session_display.set_headers_visible (true);
351 recent_session_display.get_selection()->set_mode (SELECTION_SINGLE);
353 recent_session_display.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::recent_session_row_selected));
355 recent_scroller.add (recent_session_display);
356 recent_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
357 recent_scroller.set_shadow_type (Gtk::SHADOW_IN);
359 recent_session_display.show();
360 recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &SessionDialog::recent_row_activated));
361 recent_session_display.signal_button_press_event().connect (sigc::mem_fun (*this, &SessionDialog::recent_button_press), false);
365 SessionDialog::setup_initial_choice_box ()
367 ic_vbox.set_spacing (6);
369 HBox* centering_hbox = manage (new HBox);
370 VBox* centering_vbox = manage (new VBox);
372 centering_vbox->set_spacing (6);
374 Label* new_label = manage (new Label);
375 new_label->set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("New Session")));
376 new_label->set_justify (JUSTIFY_CENTER);
378 ic_new_session_button.add (*new_label);
379 ic_new_session_button.signal_clicked().connect (sigc::mem_fun (*this, &SessionDialog::new_session_button_clicked));
381 Gtk::HBox* hbox = manage (new HBox);
382 Gtk::VBox* vbox = manage (new VBox);
383 hbox->set_spacing (12);
384 vbox->set_spacing (12);
388 Searchpath rc (ARDOUR::ardour_data_search_path());
389 rc.add_subdirectory_to_paths ("resources");
391 if (find_file (rc, PROGRAM_NAME "-small-splash.png", image_path)) {
393 if ((image = manage (new Gtk::Image (image_path))) != 0) {
394 hbox->pack_start (*image, false, false);
398 vbox->pack_start (ic_new_session_button, true, true, 20);
399 hbox->pack_start (*vbox, true, true, 20);
401 centering_vbox->pack_start (*hbox, false, false);
403 /* Possible update message */
405 if (ARDOUR_UI::instance()->announce_string() != "" ) {
407 Box *info_box = manage (new VBox);
408 info_box->set_border_width (12);
409 info_box->set_spacing (6);
411 info_box->pack_start (info_scroller_label, false, false);
413 info_scroller_count = 0;
414 info_scroller_connection = Glib::signal_timeout().connect (mem_fun(*this, &SessionDialog::info_scroller_update), 50);
416 Gtk::Button *updates_button = manage (new Gtk::Button (_("Check the website for more...")));
418 updates_button->signal_clicked().connect (mem_fun(*this, &SessionDialog::updates_button_clicked) );
419 set_tooltip (*updates_button, _("Click to open the program website in your web browser"));
421 info_box->pack_start (*updates_button, false, false);
423 info_frame.add (*info_box);
424 info_box->show_all ();
428 /* recent session scroller */
429 setup_recent_sessions ();
431 recent_label.set_no_show_all (true);
432 recent_scroller.set_no_show_all (true);
434 recent_label.set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("Recent Sessions")));
436 centering_vbox->pack_start (recent_label, false, false, 12);
437 centering_vbox->pack_start (recent_scroller, true, true);
441 existing_session_chooser.set_title (_("Select session file"));
442 existing_session_chooser.signal_file_set().connect (sigc::mem_fun (*this, &SessionDialog::existing_session_selected));
443 existing_session_chooser.set_current_folder(poor_mans_glob (Config->get_default_session_parent_dir()));
445 FileFilter session_filter;
446 session_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::statefile_suffix));
447 session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME));
448 existing_session_chooser.add_filter (session_filter);
450 FileFilter archive_filter;
451 archive_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::session_archive_suffix));
452 archive_filter.set_name (_("Session Archives"));
453 existing_session_chooser.add_filter (archive_filter);
455 existing_session_chooser.set_filter (session_filter);
457 Gtkmm2ext::add_volume_shortcuts (existing_session_chooser);
459 Label* browse_label = manage (new Label);
460 browse_label->set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("Other Sessions")));
462 centering_vbox->pack_start (*browse_label, false, false, 12);
463 centering_vbox->pack_start (existing_session_chooser, false, false);
465 /* --disable plugins UI */
467 _disable_plugins.set_label (_("Safe Mode: Disable all Plugins"));
468 _disable_plugins.set_flags (Gtk::CAN_FOCUS);
469 _disable_plugins.set_relief (Gtk::RELIEF_NORMAL);
470 _disable_plugins.set_mode (true);
471 _disable_plugins.set_active (ARDOUR::Session::get_disable_all_loaded_plugins());
472 _disable_plugins.set_border_width(0);
473 _disable_plugins.signal_clicked().connect (sigc::mem_fun (*this, &SessionDialog::disable_plugins_clicked));
474 centering_vbox->pack_start (_disable_plugins, false, false);
478 centering_hbox->pack_start (*centering_vbox, true, true);
479 ic_vbox.pack_start (*centering_hbox, true, true);
484 SessionDialog::session_selected ()
486 /* HACK HACK HACK ... change the "Apply" button label
490 Gtk::Widget* tl = ic_vbox.get_toplevel();
492 if ((win = dynamic_cast<Gtk::Window*>(tl)) != 0) {
493 /* ::get_default_widget() is not wrapped in gtkmm */
494 Gtk::Widget* def = wrap (gtk_window_get_default_widget (win->gobj()));
496 if ((button = dynamic_cast<Gtk::Button*>(def)) != 0) {
497 button->set_label (_("Open"));
503 SessionDialog::new_session_button_clicked ()
505 _existing_session_chooser_used = false;
506 recent_session_display.get_selection()->unselect_all ();
508 get_vbox()->remove (ic_vbox);
509 get_vbox()->pack_start (session_new_vbox, true, true);
510 back_button->set_sensitive (true);
511 new_name_entry.grab_focus ();
515 SessionDialog::back_button_pressed (GdkEventButton*)
517 get_vbox()->remove (session_new_vbox);
518 back_button->set_sensitive (false);
519 get_vbox()->pack_start (ic_vbox);
525 SessionDialog::open_button_pressed (GdkEventButton* ev)
527 if (Gtkmm2ext::Keyboard::modifier_state_equals (ev->state, Gtkmm2ext::Keyboard::PrimaryModifier)) {
528 _disable_plugins.set_active();
530 response (RESPONSE_ACCEPT);
535 SessionDialog::populate_session_templates ()
537 vector<TemplateInfo> templates;
539 find_session_templates (templates, true);
541 template_model->clear ();
543 /* Get Lua Scripts dedicated to session-setup */
544 LuaScriptList scripts (LuaScripting::instance ().scripts (LuaScriptInfo::SessionInit));
546 /* Add Lua Action Scripts which can also be used for session-setup */
547 LuaScriptList& as (LuaScripting::instance ().scripts (LuaScriptInfo::EditorAction));
548 for (LuaScriptList::const_iterator s = as.begin(); s != as.end(); ++s) {
549 if ((*s)->subtype & LuaScriptInfo::SessionSetup) {
550 scripts.push_back (*s);
554 std::sort (scripts.begin(), scripts.end(), LuaScripting::Sorter());
556 for (LuaScriptList::const_iterator s = scripts.begin(); s != scripts.end(); ++s) {
557 TreeModel::Row row = *(template_model->append ());
558 row[session_template_columns.name] = (*s)->name;
559 row[session_template_columns.path] = "urn:ardour:" + (*s)->path;
560 row[session_template_columns.description] = (*s)->description;
561 row[session_template_columns.modified_with_short] = _("{Factory Template}");
562 row[session_template_columns.modified_with_long] = _("{Factory Template}");
565 //Add any "template sessions" found in the user's preferences folder
566 for (vector<TemplateInfo>::iterator x = templates.begin(); x != templates.end(); ++x) {
569 row = *(template_model->append ());
571 row[session_template_columns.name] = (*x).name;
572 row[session_template_columns.path] = (*x).path;
573 row[session_template_columns.description] = (*x).description;
574 row[session_template_columns.modified_with_long] = (*x).modified_with;
575 row[session_template_columns.modified_with_short] = (*x).modified_with.substr(0, (*x).modified_with.find(" "));
578 //Add an explicit 'Empty Template' item
579 TreeModel::Row row = *template_model->prepend ();
580 row[session_template_columns.name] = (_("Empty Template"));
581 row[session_template_columns.path] = string();
582 row[session_template_columns.description] = _("An empty session with factory default settings.\n\nSelect this option if you are importing files to mix.");
583 row[session_template_columns.modified_with_short] = _("");
584 row[session_template_columns.modified_with_long] = _("");
586 //auto-select the first item in the list
587 Gtk::TreeModel::Row first = template_model->children()[0];
589 template_chooser.get_selection()->select(first);
594 SessionDialog::setup_new_session_page ()
596 session_new_vbox.set_border_width (8);
597 session_new_vbox.set_spacing (8);
599 Label* name_label = manage (new Label);
600 name_label->set_text (_("Session name:"));
602 HBox* name_hbox = manage (new HBox);
603 name_hbox->set_spacing (8);
604 name_hbox->pack_start (*name_label, false, true);
605 name_hbox->pack_start (new_name_entry, true, true);
607 new_name_entry.signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::new_name_changed));
608 new_name_entry.signal_activate().connect (sigc::mem_fun (*this, &SessionDialog::new_name_activated));
610 //Folder location for the new session
611 Label* new_folder_label = manage (new Label);
612 new_folder_label->set_text (_("Create session folder in:"));
613 HBox* folder_box = manage (new HBox);
614 folder_box->set_spacing (8);
615 folder_box->pack_start (*new_folder_label, false, false);
616 folder_box->pack_start (new_folder_chooser, true, true);
618 if (ARDOUR_UI::instance()->the_session ()) {
619 // point the new session file chooser at the parent directory of the current session
620 string session_parent_dir = Glib::path_get_dirname(ARDOUR_UI::instance()->the_session()->path());
621 new_folder_chooser.set_current_folder (session_parent_dir);
622 string default_session_folder = poor_mans_glob (Config->get_default_session_parent_dir());
625 /* add_shortcut_folder throws an exception if the folder being added already has a shortcut */
626 new_folder_chooser.add_shortcut_folder (default_session_folder);
628 catch (Glib::Error & e) {
629 std::cerr << "new_folder_chooser.add_shortcut_folder (" << default_session_folder << ") threw Glib::Error " << e.what() << std::endl;
632 new_folder_chooser.set_current_folder (poor_mans_glob (Config->get_default_session_parent_dir()));
634 new_folder_chooser.show ();
635 new_folder_chooser.set_title (_("Select folder for session"));
636 Gtkmm2ext::add_volume_shortcuts (new_folder_chooser);
638 //Template & Template Description area
639 HBox* template_hbox = manage (new HBox);
641 //if the "template override" is provided, don't give the user any template selections (?)
642 if (load_template_override.empty()) {
643 template_hbox->set_spacing (8);
645 Gtk::ScrolledWindow *template_scroller = manage (new Gtk::ScrolledWindow());
646 template_scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
647 template_scroller->add (template_chooser);
649 Gtk::ScrolledWindow *desc_scroller = manage (new Gtk::ScrolledWindow());
650 desc_scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
651 desc_scroller->add (template_desc);
653 template_hbox->pack_start (*template_scroller, true, true);
655 template_desc_frame.set_name (X_("TextHighlightFrame"));
656 template_desc_frame.add (*desc_scroller);
657 template_hbox->pack_start (template_desc_frame, true, true);
660 //template_desc is the textview that displays the currently selected template's description
661 template_desc.set_editable (false);
662 template_desc.set_wrap_mode (Gtk::WRAP_WORD);
663 template_desc.set_size_request (300,400);
664 template_desc.set_name (X_("TextOnBackground"));
665 template_desc.set_border_width (6);
667 //template_chooser is the treeview showing available templates
668 template_model = TreeStore::create (session_template_columns);
669 template_chooser.set_model (template_model);
670 template_chooser.append_column (_("Template"), session_template_columns.name);
672 template_chooser.append_column (_("Modified With"), session_template_columns.modified_with_short);
674 template_chooser.set_headers_visible (true);
675 template_chooser.get_selection()->set_mode (SELECTION_SINGLE);
676 template_chooser.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::template_row_selected));
677 template_chooser.set_sensitive (true);
678 if (UIConfiguration::instance().get_use_tooltips()) {
679 template_chooser.set_tooltip_column(4); // modified_with_long
682 session_new_vbox.pack_start (*template_hbox, true, true);
683 session_new_vbox.pack_start (*folder_box, false, true);
684 session_new_vbox.pack_start (*name_hbox, false, true);
685 session_new_vbox.show_all ();
689 SessionDialog::new_name_changed ()
691 if (!new_name_entry.get_text().empty()) {
693 open_button->set_sensitive (true);
695 open_button->set_sensitive (false);
700 SessionDialog::new_name_activated ()
702 response (RESPONSE_ACCEPT);
706 SessionDialog::redisplay_recent_sessions ()
708 std::vector<std::string> session_directories;
709 RecentSessionsSorter cmp;
711 recent_session_display.set_model (Glib::RefPtr<TreeModel>(0));
712 recent_session_model->clear ();
714 ARDOUR::RecentSessions rs;
715 ARDOUR::read_recent_sessions (rs);
718 recent_session_display.set_model (recent_session_model);
722 // sort them alphabetically
723 sort (rs.begin(), rs.end(), cmp);
725 for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
726 session_directories.push_back ((*i).second);
729 int session_snapshot_count = 0;
731 for (vector<std::string>::const_iterator i = session_directories.begin(); i != session_directories.end(); ++i) {
732 std::vector<std::string> state_file_paths;
734 // now get available states for this session
736 get_state_files_in_directory (*i, state_file_paths);
738 vector<string> states;
739 vector<const gchar*> item;
742 /* remove any trailing / */
744 if (dirname[dirname.length()-1] == '/') {
745 dirname = dirname.substr (0, dirname.length()-1);
748 /* check whether session still exists */
749 if (!Glib::file_test(dirname.c_str(), Glib::FILE_TEST_EXISTS)) {
750 /* session doesn't exist */
754 /* now get available states for this session */
756 states = Session::possible_states (dirname);
758 if (states.empty()) {
763 std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
765 if (state_file_names.empty()) {
771 std::string program_version;
773 std::string state_file_basename;
775 if (state_file_names.size() > 1) {
776 state_file_basename = Session::get_snapshot_from_instant (dirname);
777 std::string s = Glib::build_filename (dirname, state_file_basename + statefile_suffix);
778 if (!Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
779 state_file_basename = "";
783 if (state_file_basename.empty()) {
784 state_file_basename = state_file_names.front();
787 std::string s = Glib::build_filename (dirname, state_file_basename + statefile_suffix);
789 int err = Session::get_info_from_path (s, sr, sf, program_version);
791 // XML cannot be parsed, or unsuppored version
796 g_stat (s.c_str(), &gsb);
798 Gtk::TreeModel::Row row = *(recent_session_model->append());
799 row[recent_session_columns.fullpath] = s;
800 row[recent_session_columns.time_modified] = gsb.st_mtime;
804 row[recent_session_columns.sample_rate] = rate_as_string (sr);
807 row[recent_session_columns.disk_format] = _("32-bit float");
810 row[recent_session_columns.disk_format] = _("24-bit");
813 row[recent_session_columns.disk_format] = _("16-bit");
817 row[recent_session_columns.sample_rate] = "??";
818 row[recent_session_columns.disk_format] = "--";
821 if (program_version.empty()) {
822 row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (dirname);
824 row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (dirname + "\n" + string_compose (_("Last modified with: %1"), program_version));
825 row[recent_session_columns.modified_with] = program_version;
828 ++session_snapshot_count;
830 if (state_file_names.size() > 1) {
831 // multiple session files in the session directory - show the directory name.
832 // if there's not a session file with the same name as the session directory,
833 // opening the parent item will fail, but expanding it will show the session
834 // files that actually exist, and the right one can then be opened.
835 row[recent_session_columns.visible_name] = Glib::path_get_basename (dirname);
836 int64_t most_recent = 0;
840 for (std::vector<std::string>::iterator i2 = state_file_names.begin(); i2 != state_file_names.end(); ++i2) {
842 s = Glib::build_filename (dirname, *i2 + statefile_suffix);
843 Gtk::TreeModel::Row child_row = *(recent_session_model->append (row.children()));
845 child_row[recent_session_columns.visible_name] = *i2;
846 child_row[recent_session_columns.fullpath] = s;
847 child_row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (dirname);
848 g_stat (s.c_str(), &gsb);
849 child_row[recent_session_columns.time_modified] = gsb.st_mtime;
851 Glib::DateTime gdt(Glib::DateTime::create_now_local (gsb.st_mtime));
852 child_row[recent_session_columns.time_formatted] = gdt.format ("%F %H:%M");
854 if (gsb.st_mtime > most_recent) {
855 most_recent = gsb.st_mtime;
858 if (++kidcount < 5) {
859 // parse "modified with" for the first 5 snapshots
860 if (Session::get_info_from_path (s, sr, sf, program_version) == 0) {
862 child_row[recent_session_columns.sample_rate] = rate_as_string (sr);
865 child_row[recent_session_columns.disk_format] = _("32-bit float");
868 child_row[recent_session_columns.disk_format] = _("24-bit");
871 child_row[recent_session_columns.disk_format] = _("16-bit");
875 child_row[recent_session_columns.sample_rate] = "";
876 child_row[recent_session_columns.disk_format] = "";
879 child_row[recent_session_columns.sample_rate] = "??";
880 child_row[recent_session_columns.disk_format] = "--";
882 if (!program_version.empty()) {
883 child_row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (string_compose (_("Last modified with: %1"), program_version));
886 child_row[recent_session_columns.sample_rate] = "";
887 child_row[recent_session_columns.disk_format] = "";
890 ++session_snapshot_count;
893 assert (most_recent >= row[recent_session_columns.time_modified]);
894 row[recent_session_columns.time_modified] = most_recent;
897 // only a single session file in the directory - show its actual name.
898 row[recent_session_columns.visible_name] = state_file_basename;
901 Glib::DateTime gdt(Glib::DateTime::create_now_local (row[recent_session_columns.time_modified]));
902 row[recent_session_columns.time_formatted] = gdt.format ("%F %H:%M");
905 if (UIConfiguration::instance().get_use_tooltips()) {
906 recent_session_display.set_tooltip_column(1); // recent_session_columns.tip
908 recent_session_display.set_model (recent_session_model);
911 Gtk::TreeView::Column* pColumn;
912 if ((pColumn = recent_session_display.get_column (0))) { // name
913 pColumn->set_sort_column (recent_session_columns.visible_name);
915 if ((pColumn = recent_session_display.get_column (3))) { // date
916 pColumn->set_sort_column (recent_session_columns.time_modified); // unixtime
919 int32_t sort = UIConfiguration::instance().get_recent_session_sort();
920 if (abs(sort) != 1 + recent_session_columns.visible_name.index () &&
921 abs(sort) != 1 + recent_session_columns.time_modified.index ()) {
922 sort = 1 + recent_session_columns.visible_name.index();
924 recent_session_model->set_sort_column (abs (sort) -1, sort < 0 ? Gtk::SORT_DESCENDING : Gtk::SORT_ASCENDING);
926 return session_snapshot_count;
930 SessionDialog::recent_session_sort_changed ()
934 if (recent_session_model->get_sort_column_id (column, order)) {
935 int32_t sort = (column + 1) * (order == Gtk::SORT_DESCENDING ? -1 : 1);
936 if (sort != UIConfiguration::instance().get_recent_session_sort()) {
937 UIConfiguration::instance().set_recent_session_sort(sort);
943 SessionDialog::recent_session_row_selected ()
945 if (recent_session_display.get_selection()->count_selected_rows() > 0) {
946 open_button->set_sensitive (true);
949 open_button->set_sensitive (false);
954 SessionDialog::template_row_selected ()
956 if (template_chooser.get_selection()->count_selected_rows() > 0) {
957 TreeIter iter = template_chooser.get_selection()->get_selected();
960 string s = (*iter)[session_template_columns.description];
961 template_desc.get_buffer()->set_text (s);
967 SessionDialog::recent_row_activated (const Gtk::TreePath&, Gtk::TreeViewColumn*)
969 response (RESPONSE_ACCEPT);
973 SessionDialog::recent_button_press (GdkEventButton* ev)
975 if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 3) ) {
977 TreeModel::Path path;
978 TreeViewColumn* column;
980 if (recent_session_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
981 Glib::RefPtr<Gtk::TreeView::Selection> selection = recent_session_display.get_selection();
983 selection->unselect_all();
984 selection->select(path);
988 if (recent_session_display.get_selection()->count_selected_rows() > 0) {
989 recent_context_mennu (ev);
996 SessionDialog::recent_context_mennu (GdkEventButton *ev)
998 using namespace Gtk::Menu_Helpers;
1000 TreeIter iter = recent_session_display.get_selection()->get_selected();
1002 string s = (*iter)[recent_session_columns.fullpath];
1003 if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
1004 s = Glib::path_get_dirname (s);
1006 if (!Glib::file_test (s, Glib::FILE_TEST_IS_DIR)) {
1010 Gtk::TreeModel::Path tpath = recent_session_model->get_path(iter);
1011 const bool is_child = tpath.up () && tpath.up ();
1013 Gtk::Menu* m = ARDOUR_UI::instance()->shared_popup_menu ();
1014 MenuList& items = m->items ();
1015 items.push_back (MenuElem (s, sigc::bind (sigc::hide_return (sigc::ptr_fun (&PBD::open_folder)), s)));
1017 items.push_back (SeparatorElem());
1018 items.push_back (MenuElem (_("Remove session from recent list"), sigc::mem_fun (*this, &SessionDialog::recent_remove_selected)));
1020 m->popup (ev->button, ev->time);
1024 SessionDialog::recent_remove_selected ()
1026 TreeIter iter = recent_session_display.get_selection()->get_selected();
1028 string s = (*iter)[recent_session_columns.fullpath];
1029 if (Glib::file_test (s, Glib::FILE_TEST_IS_REGULAR)) {
1030 s = Glib::path_get_dirname (s);
1032 ARDOUR::remove_recent_sessions (s);
1033 redisplay_recent_sessions ();
1037 SessionDialog::disable_plugins_clicked ()
1039 ARDOUR::Session::set_disable_all_loaded_plugins (_disable_plugins.get_active());
1043 SessionDialog::existing_session_selected ()
1045 _existing_session_chooser_used = true;
1046 recent_session_display.get_selection()->unselect_all();
1047 /* mark this sensitive in case we come back here after a failed open
1048 * attempt and the user has hacked up the fix. sigh.
1050 open_button->set_sensitive (true);
1051 response (RESPONSE_ACCEPT);
1055 SessionDialog::updates_button_clicked ()
1057 //now open a browser window so user can see more
1058 PBD::open_uri (Config->get_updates_url());
1062 SessionDialog::info_scroller_update()
1064 info_scroller_count++;
1067 snprintf (buf, std::min(info_scroller_count,sizeof(buf)-1), "%s", ARDOUR_UI::instance()->announce_string().c_str() );
1068 buf[info_scroller_count] = 0;
1069 info_scroller_label.set_text (buf);
1070 info_scroller_label.show();
1072 if (info_scroller_count > ARDOUR_UI::instance()->announce_string().length()) {
1073 info_scroller_connection.disconnect();
1080 SessionDialog::on_delete_event (GdkEventAny* ev)
1082 response (RESPONSE_CANCEL);
1083 return ArdourDialog::on_delete_event (ev);
1087 SessionDialog::set_provided_session (string const & name, string const & path)
1089 /* Note: path is required to be the full path to the session file, not
1090 just the folder name
1092 new_name_entry.set_text (name);
1093 existing_session_chooser.set_current_folder (Glib::path_get_dirname (path));