From 57669893198bd4c7bbf66b3a154fe14726ee62db Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 24 Mar 2020 10:38:03 -0600 Subject: introduce the idea of an "unnamed" session --- libs/ardour/ardour/session.h | 6 ++++-- libs/ardour/session.cc | 5 +++-- libs/ardour/session_state.cc | 19 ++++++++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 7f18857bff..0f27ac5029 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -207,7 +207,8 @@ public: const std::string& fullpath, const std::string& snapshot_name, BusProfile const * bus_profile = 0, - std::string mix_template = ""); + std::string mix_template = "", + bool unnamed = false); virtual ~Session (); @@ -242,6 +243,7 @@ public: bool cannot_save () const { return _state_of_the_state & CannotSave; } bool in_cleanup () const { return _state_of_the_state & InCleanup; } bool inital_connect_or_deletion_in_progress () { return _state_of_the_state & (InitialConnecting | Deletion); } + bool not_named() const; PBD::Signal0 DirtyChanged; @@ -1270,7 +1272,7 @@ protected: void set_transport_speed (double speed, bool abort, bool clear_state, bool as_default); private: - int create (const std::string& mix_template, BusProfile const *); + int create (const std::string& mix_template, BusProfile const *, bool unnamed); void destroy (); static guint _name_id_counter; diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 9e4829666f..bb13cee49e 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -172,7 +172,8 @@ Session::Session (AudioEngine &eng, const string& fullpath, const string& snapshot_name, BusProfile const * bus_profile, - string mix_template) + string mix_template, + bool unnamed) : _playlists (new SessionPlaylists) , _engine (eng) , process_function (&Session::process_with_events) @@ -344,7 +345,7 @@ Session::Session (AudioEngine &eng, Stateful::loading_state_version = CURRENT_SESSION_FILE_VERSION; - if (create (mix_template, bus_profile)) { + if (create (mix_template, bus_profile, unnamed)) { destroy (); throw SessionException (_("Session initialization failed")); } diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 5098f5d62b..b44b42294c 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -44,6 +44,10 @@ #include #include #include +/* for open(2) */ +#include +#include +#include #ifdef HAVE_SYS_VFS_H #include @@ -80,6 +84,7 @@ #include "pbd/file_utils.h" #include "pbd/pathexpand.h" #include "pbd/pthread_utils.h" +#include "pbd/scoped_file_descriptor.h" #include "pbd/stacktrace.h" #include "pbd/types_convert.h" #include "pbd/localtime_r.h" @@ -154,6 +159,8 @@ using namespace PBD; #define DEBUG_UNDO_HISTORY(msg) DEBUG_TRACE (PBD::DEBUG::UndoHistory, string_compose ("%1: %2\n", __LINE__, msg)); +static const char* unnamed_file_name = X_(".unnamed"); + void Session::pre_engine_init (string fullpath) { @@ -569,13 +576,17 @@ Session::ensure_subdirs () * Caller must not hold process lock. */ int -Session::create (const string& session_template, BusProfile const * bus_profile) +Session::create (const string& session_template, BusProfile const * bus_profile, bool unnamed) { if (g_mkdir_with_parents (_path.c_str(), 0755) < 0) { error << string_compose(_("Session: cannot create session folder \"%1\" (%2)"), _path, strerror (errno)) << endmsg; return -1; } + if (unnamed) { + PBD::ScopedFileDescriptor fd = g_open (Glib::build_filename (_path, unnamed_file_name).c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666); + } + if (ensure_subdirs ()) { return -1; } @@ -5637,3 +5648,9 @@ Session::redo (uint32_t n) StateProtector stp (this); _history.redo (n); } + +bool +Session::not_named() const +{ + return Glib::file_test (Glib::build_filename (_path, unnamed_file_name), Glib::FILE_TEST_EXISTS); +} -- cgit v1.2.3