From 84d6a0a75da730de95bace5bec5a3133d5d148ab Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 27 Jul 2022 01:03:03 +0200 Subject: [PATCH] Copy demo sessions (if any) for new-users * Fix demo-session glob (missing "*" + session_archive_suffix) * Copy demo-session also when copying settings from older version * Also add demo-session to recent-list if it was previously unpacked for new major versions. --- gtk2_ardour/ardour_ui.cc | 6 ++++ gtk2_ardour/ardour_ui.h | 1 + gtk2_ardour/ardour_ui_startup.cc | 48 ++++++++++++++++++++++++++++++++ gtk2_ardour/new_user_wizard.cc | 37 ++---------------------- 4 files changed, 57 insertions(+), 35 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 908b2dfa61..9dac19ca19 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -384,6 +384,12 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir) /* "touch" the been-here-before path now that config has been migrated */ PBD::ScopedFileDescriptor fout (g_open (been_here_before_path ().c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666)); } + + { + Config->load_state (); // need session-parent folder + copy_demo_sessions (); + } + ArdourMessageDialog msg (string_compose (_("Your configuration files were copied. You can now restart %1."), PROGRAM_NAME), true); msg.run (); /* configuration was modified, exit immediately */ diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 707dbf3155..ab1b629848 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -221,6 +221,7 @@ public: void load_from_application_api (const std::string& path); void finish(); + int copy_demo_sessions (); int load_session (const std::string& path, const std::string& snapshot, std::string mix_template = std::string()); bool session_load_in_progress; int build_session (std::string const& path, std::string const& snapshot, std::string const& session_template, ARDOUR::BusProfile const&, bool from_startup_fsm, bool unnamed); diff --git a/gtk2_ardour/ardour_ui_startup.cc b/gtk2_ardour/ardour_ui_startup.cc index 74685ea7c3..a5cf4d0d40 100644 --- a/gtk2_ardour/ardour_ui_startup.cc +++ b/gtk2_ardour/ardour_ui_startup.cc @@ -57,6 +57,7 @@ #include "ardour/filename_extensions.h" #include "ardour/filesystem_paths.h" #include "ardour/profile.h" +#include "ardour/recent_sessions.h" #include "gtkmm2ext/application.h" @@ -581,6 +582,53 @@ ARDOUR_UI::starting () return 0; } +int +ARDOUR_UI::copy_demo_sessions () +{ + int copied = 0; + if (ARDOUR::Profile->get_mixbus () && Config->get_copy_demo_sessions ()) { + std::string dspd (Config->get_default_session_parent_dir()); + Searchpath ds (ARDOUR::ardour_data_search_path()); + ds.add_subdirectory_to_paths ("sessions"); + vector demos; + find_files_matching_pattern (demos, ds, string_compose ("*%1", ARDOUR::session_archive_suffix)); + + ARDOUR::RecentSessions rs; + ARDOUR::read_recent_sessions (rs); + + for (vector::iterator i = demos.begin(); i != demos.end (); ++i) { + /* "demo-session" must be inside "demo-session." */ + std::string name = basename_nosuffix (basename_nosuffix (*i)); + std::string path = Glib::build_filename (dspd, name); + /* skip if session-dir already exists */ + if (Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR)) { + /* ..but add it to recent-list */ + store_recent_sessions (name, path); + continue; + } + /* skip sessions that are already in 'recent'. + * eg. a new user changed shortly after installation + */ + for (ARDOUR::RecentSessions::iterator r = rs.begin(); r != rs.end(); ++r) { + if ((*r).first == name) { + continue; + } + } + try { + PBD::FileArchive ar (*i); + if (0 == ar.inflate (dspd)) { + store_recent_sessions (name, path); + info << string_compose (_("Copied demo session `%1'."), name) << endmsg; + ++copied; + } + } catch (...) { + info << string_compose (_("Failed to extract demo session `%1'."), name) << endmsg; + } + } + } + return copied; +} + int ARDOUR_UI::load_session_from_startup_fsm () { diff --git a/gtk2_ardour/new_user_wizard.cc b/gtk2_ardour/new_user_wizard.cc index 49c084a67f..7a82e20d0e 100644 --- a/gtk2_ardour/new_user_wizard.cc +++ b/gtk2_ardour/new_user_wizard.cc @@ -47,7 +47,6 @@ #include "ardour/filesystem_paths.h" #include "ardour/filename_extensions.h" #include "ardour/plugin_manager.h" -#include "ardour/recent_sessions.h" #include "ardour/session.h" #include "ardour/session_state_utils.h" #include "ardour/template_utils.h" @@ -55,6 +54,7 @@ #include "gtkmm2ext/utils.h" +#include "ardour_ui.h" #include "new_user_wizard.h" #include "opts.h" #include "splash.h" @@ -343,41 +343,8 @@ NewUserWizard::on_apply () } - if (ARDOUR::Profile->get_mixbus () && Config->get_copy_demo_sessions ()) { - std::string dspd (Config->get_default_session_parent_dir()); - Searchpath ds (ARDOUR::ardour_data_search_path()); - ds.add_subdirectory_to_paths ("sessions"); - vector demos; - find_files_matching_pattern (demos, ds, ARDOUR::session_archive_suffix); + ARDOUR_UI::instance()->copy_demo_sessions (); - ARDOUR::RecentSessions rs; - ARDOUR::read_recent_sessions (rs); - - for (vector::iterator i = demos.begin(); i != demos.end (); ++i) { - /* "demo-session" must be inside "demo-session." */ - std::string name = basename_nosuffix (basename_nosuffix (*i)); - std::string path = Glib::build_filename (dspd, name); - /* skip if session-dir already exists */ - if (Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR)) { - continue; - } - /* skip sessions that are already in 'recent'. - * eg. a new user changed shortly after installation - */ - for (ARDOUR::RecentSessions::iterator r = rs.begin(); r != rs.end(); ++r) { - if ((*r).first == name) { - continue; - } - } - try { - PBD::FileArchive ar (*i); - if (0 == ar.inflate (dspd)) { - store_recent_sessions (name, path); - info << string_compose (_("Copied Demo Session %1."), name) << endmsg; - } - } catch (...) {} - } - } _signal_response (int (RESPONSE_OK)); }