Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
project_saver.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
7
8#include <QFuture>
9
10namespace zrythm::structure::project
11{
12class Project;
13
14class ProjectSaver
15{
16public:
17 ProjectSaver (const Project &project);
18
19 QFuture<void> save_async (bool for_backup);
20
32 void save (bool is_backup, bool show_notification, bool async);
33
41 static int autosave_cb (void * data);
42
49 static void make_project_dirs (const Project &project, bool is_backup);
50
54 enum class CompressionFlag
55 {
56 PROJECT_COMPRESS_FILE = 0,
57 PROJECT_DECOMPRESS_FILE = 0,
58 PROJECT_COMPRESS_DATA = 1,
59 PROJECT_DECOMPRESS_DATA = 1,
60 };
61
74 bool compress,
75 char ** _dest,
76 size_t * _dest_size,
77 CompressionFlag dest_type,
78 const QByteArray &src);
79
80 static void compress (
81 char ** _dest,
82 size_t * _dest_size,
83 CompressionFlag dest_type,
84 const QByteArray &src)
85 {
86 compress_or_decompress (true, _dest, _dest_size, dest_type, src);
87 }
88
89 static void decompress (
90 char ** _dest,
91 size_t * _dest_size,
92 CompressionFlag dest_type,
93 const QByteArray &src)
94 {
95 compress_or_decompress (false, _dest, _dest_size, dest_type, src);
96 }
97
106 std::string get_existing_uncompressed_text (bool backup);
107
108 bool has_unsaved_changes () const;
109
110private:
114 struct SaveContext
115 {
117 // std::unique_ptr<Project> project_;
118
122 const Project * main_project_;
123
125 fs::path project_file_path_;
126
127 bool is_backup_ = false;
128
130 std::atomic_bool finished_ = false;
131
132 bool show_notification_ = false;
133
135 bool has_error_ = false;
136
137 ProgressInfo progress_info_;
138 };
139
143 class SerializeProjectThread final : public juce::Thread
144 {
145 public:
146 SerializeProjectThread (SaveContext &ctx);
147 ~SerializeProjectThread () override;
148 void run () override;
149
150 private:
151 SaveContext &ctx_;
152 };
153
160 void set_and_create_next_available_backup_dir ();
161
170 void cleanup_plugin_state_dirs (const Project &main_project, bool is_backup);
171
178 static bool idle_saved_callback (SaveContext * ctx);
179
180private:
181 const Project &project_;
182 // std::optional<gui::actions::UndoableActionPtrVariant>
183 // last_action_in_last_successful_autosave_;
184
186 SteadyTimePoint last_successful_autosave_time_;
187
189 // std::optional<gui::actions::UndoableActionPtrVariant> last_saved_action_;
190
192 std::binary_semaphore save_sem_{ 1 };
193};
194}
Generic progress info.
CompressionFlag
Flag to pass to project_compress() and project_decompress().
static void compress_or_decompress(bool compress, char **_dest, size_t *_dest_size, CompressionFlag dest_type, const QByteArray &src)
Compresses/decompress a project from a file/data to a file/data.
static int autosave_cb(void *data)
Autosave callback.
static void make_project_dirs(const Project &project, bool is_backup)
Creates the project directories.
void save(bool is_backup, bool show_notification, bool async)
Saves the project to the directory set previously in Project.
std::string get_existing_uncompressed_text(bool backup)
Returns the uncompressed text representation of the saved project file.
Core functionality of a Zrythm project.
Definition project.h:45
Progress info.