auto-backup: libardour part. (from mixbus)
authorBen Loftis <ben@harrisonconsoles.com>
Sat, 14 Jul 2018 17:46:49 +0000 (12:46 -0500)
committerBen Loftis <ben@harrisonconsoles.com>
Sat, 14 Jul 2018 17:46:49 +0000 (12:46 -0500)
libs/ardour/ardour/directory_names.h
libs/ardour/ardour/session_directory.h
libs/ardour/directory_names.cc
libs/ardour/session_directory.cc
libs/ardour/session_state.cc

index a671ee0b2e9ad4cac6d9e7216d5f1c3e16ff2731..69096e51eac3fb3ec954aaf646de32030db87d7e 100644 (file)
@@ -35,6 +35,7 @@ namespace ARDOUR {
        LIBARDOUR_API extern const char* const interchange_dir_name;
        LIBARDOUR_API extern const char* const peak_dir_name;
        LIBARDOUR_API extern const char* const export_dir_name;
+       LIBARDOUR_API extern const char* const backup_dir_name;
        LIBARDOUR_API extern const char* const export_formats_dir_name;
        LIBARDOUR_API extern const char* const plugin_metadata_dir_name;
        LIBARDOUR_API extern const char* const templates_dir_name;
index 6f4126e0bbab6b049bed0bf502a63eba627d30b1..75740090a4e61d26ce91ad284666d00c16497629 100644 (file)
@@ -107,6 +107,12 @@ public:
         */
        const std::string export_path () const;
 
+       /**
+        * @return The absolute path to the directory that backup
+        * session files are stored.
+        */
+       const std::string backup_path () const;
+
        /**
         * @return true if session directory and all the required
         * subdirectories exist.
index 574929f3a15387092d6a92a5e71017e387f5d54e..9ace7934f80725aed2b64c1acd261a73b5b2bf3d 100644 (file)
@@ -32,6 +32,7 @@ const char* const peak_dir_name = X_("peaks");
 const char* const dead_dir_name = X_("dead");
 const char* const interchange_dir_name = X_("interchange");
 const char* const export_dir_name = X_("export");
+const char* const backup_dir_name = X_("backup");
 const char* const export_formats_dir_name = X_("export");
 const char* const templates_dir_name = X_("templates");
 const char* const plugin_metadata_dir_name = X_("plugin_metadata");
index c52fe1aeb5c30e72389f8ac348fa643a818caae3..1f6b991f8282b8fe0945b8a3cc7af8cfa0a0dc86 100644 (file)
@@ -245,6 +245,12 @@ SessionDirectory::export_path () const
        return Glib::build_filename (m_root_path, export_dir_name);
 }
 
+const std::string
+SessionDirectory::backup_path () const
+{
+       return Glib::build_filename (m_root_path, backup_dir_name);
+}
+
 const vector<std::string>
 SessionDirectory::sub_directories () const
 {
@@ -256,6 +262,7 @@ SessionDirectory::sub_directories () const
        tmp_paths.push_back (peak_path ());
        tmp_paths.push_back (dead_path ());
        tmp_paths.push_back (export_path ());
+       tmp_paths.push_back (backup_path ());
 
        return tmp_paths;
 }
index b27a292642a21db84a42b62b7461bb1ac959f2b0..6eb06d8c356abb6ba7edc3a76f6cec65d639c54f 100644 (file)
@@ -749,6 +749,8 @@ Session::remove_state (string snapshot_name)
                error << string_compose(_("Could not remove session file at path \"%1\" (%2)"),
                                xml_path, g_strerror (errno)) << endmsg;
        }
+
+       StateSaved (snapshot_name); /* EMIT SIGNAL */
 }
 
 /** @param snapshot_name Name to save under, without .ardour / .pending prefix */
@@ -873,6 +875,32 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot
                }
        }
 
+       //Mixbus auto-backup mechanism
+       if(Profile->get_mixbus()) {
+               if (pending) {  //"pending" save means it's a backup, or some other non-user-initiated save;  a good time to make a backup
+                       // make a serialized safety backup
+                       // (will make one periodically but only one per hour is left on disk)
+                       // these backup files go into a separated folder
+                       char timebuf[128];
+                       time_t n;
+                       struct tm local_time;
+                       time (&n);
+                       localtime_r (&n, &local_time);
+                       strftime (timebuf, sizeof(timebuf), "%y-%m-%d.%H", &local_time);
+                       std::string save_path(session_directory().backup_path());
+                       save_path += G_DIR_SEPARATOR;
+                       save_path += legalize_for_path(_current_snapshot_name);
+                       save_path += "-";
+                       save_path += timebuf;
+                       save_path += statefile_suffix;
+                       if ( !tree.write (save_path) )
+                                       error << string_compose(_("Could not save backup file at path \"%1\" (%2)"),
+                                                       save_path, g_strerror (errno)) << endmsg;
+               }
+
+               StateSaved (snapshot_name); /* EMIT SIGNAL */
+       }
+
        if (!pending && !for_archive) {
 
                save_history (snapshot_name);