Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
pool.h
1// SPDX-FileCopyrightText: © 2019-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "engine/session/clip.h"
7#include "utils/types.h"
8
14
23struct AudioPool final
24{
25public:
26 using ProjectPoolPathGetter = std::function<fs::path (bool backup)>;
27
28 AudioPool (ProjectPoolPathGetter path_getter, SampleRateGetter sr_getter);
29
30public:
36 void init_loaded ();
37
45 void register_clip (std::shared_ptr<AudioClip> clip);
46
55 auto duplicate_clip (const AudioClip::Uuid &clip_id, bool write_file)
56 -> AudioClip::Uuid;
57
61 AudioClip * get_clip (const AudioClip::Uuid &clip_id);
62
70 const utils::Utf8String &name,
71 bool use_flac,
72 bool is_backup) const;
73
79 fs::path get_clip_path (const AudioClip &clip, bool is_backup) const;
80
89 void write_clip (AudioClip &clip, bool parts, bool backup);
90
99 const AudioClip::Uuid &clip_id,
100 bool free_and_remove_file,
101 bool backup);
102
110 void remove_unused (bool backup);
111
120
131
141 void write_to_disk (bool is_backup);
142
143 void print () const;
144
145 friend void init_from (
146 AudioPool &obj,
147 const AudioPool &other,
148 utils::ObjectCloneType clone_type);
149
150private:
151 static constexpr auto kClipsKey = "clips"sv;
152 friend void to_json (nlohmann::json &j, const AudioPool &pool);
153 friend void from_json (const nlohmann::json &j, AudioPool &pool);
154
155 bool name_exists (const utils::Utf8String &name) const;
156
157private:
158 SampleRateGetter sample_rate_getter_;
159 ProjectPoolPathGetter project_pool_path_getter_;
160
164 QHash<AudioClip::Uuid, std::shared_ptr<AudioClip>> clips_;
165};
166
Audio clips for the pool.
Definition clip.h:25
Lightweight UTF-8 string wrapper with safe conversions.
Definition string.h:39
AudioClip * get_clip(const AudioClip::Uuid &clip_id)
Returns the clip for the given ID.
fs::path get_clip_path(const AudioClip &clip, bool is_backup) const
Gets the path of the given clip from the pool.
void write_clip(AudioClip &clip, bool parts, bool backup)
Writes the clip to the pool as a wav file.
auto duplicate_clip(const AudioClip::Uuid &clip_id, bool write_file) -> AudioClip::Uuid
Duplicates the clip with the given ID and returns the duplicate.
void reload_clip_frame_bufs()
Loads the frame buffers of clips currently in use in the project from their files and frees the buffe...
void write_to_disk(bool is_backup)
Writes all the clips to disk.
void register_clip(std::shared_ptr< AudioClip > clip)
Takes ownership of the given clip.
fs::path get_clip_path_from_name(const utils::Utf8String &name, bool use_flac, bool is_backup) const
Gets the path of a clip matching name from the pool.
void init_loaded()
Initializes the audio pool after deserialization.
void ensure_unique_clip_name(AudioClip &clip)
Ensures that the name of the clip is unique.
void remove_unused(bool backup)
Removes and frees (and removes the files for) all clips not used by the project or undo stacks.
void remove_clip(const AudioClip::Uuid &clip_id, bool free_and_remove_file, bool backup)
Removes the clip with the given ID from the pool and optionally frees it (and removes the file).