6#include "dsp/file_audio_source.h"
8#include "utils/units.h"
10#include <boost/unordered/concurrent_flat_map.hpp>
35 using SampleRateGetter = std::function<units::sample_rate_t ()>;
38 dsp::FileAudioSourceRegistry &file_audio_source_registry,
40 SampleRateGetter sr_getter);
59 -> FileAudioSourceUuidReference;
66 [[nodiscard]] fs::path
67 get_clip_path (
const dsp::FileAudioSource::Uuid &
id,
bool is_backup)
const;
111 auto get_clip_ptrs ()
const
113 return std::views::transform (
114 clip_registry_.get_hash_map () | std::views::values,
115 [] (
const auto &clip) { return std::get<dsp::FileAudioSource *> (clip); });
119 friend void init_from (
124 static constexpr auto kLastKnownFileHashesKey =
"fileHashes"sv;
125 friend void to_json (nlohmann::json &j,
const AudioPool &pool);
126 friend void from_json (
const nlohmann::json &j,
AudioPool &pool);
129 SampleRateGetter sample_rate_getter_;
135 FileAudioSourceRegistry &clip_registry_;
139 boost::unordered::concurrent_flat_map<FileAudioSource::Uuid, utils::hash::HashT>
140 last_known_file_hashes_;
148 template <
typename FormatContext>
151 std::stringstream ss;
152 ss <<
"\nAudio Pool:\n";
153 for (
const auto &clip : pool.get_clip_ptrs ())
155 auto pool_path = pool.
get_clip_path (clip->get_uuid (),
false);
157 "[Clip {}] {}: {}\n", clip->get_uuid (), clip->get_name (), pool_path);
160 return fmt::formatter<std::string_view>::format (
161 fmt::format (
"{}", ss.str ()), ctx);
Audio clips for the pool.
A manager for a registry of FileAudioSource inside a project.
void remove_unused(bool backup)
Removes and frees (and removes the files for) all clips not used by the project or undo stacks.
fs::path get_clip_path(const dsp::FileAudioSource::Uuid &id, bool is_backup) const
Gets the path of a clip matching name from the pool.
void init_loaded()
Initializes the audio pool after deserialization.
std::function< fs::path(bool backup)> ProjectPoolPathGetter
Returns a path that will be used to manage audio files in.
void write_to_disk(bool is_backup)
Writes all the clips to disk.
auto duplicate_clip(const FileAudioSource::Uuid &clip_id, bool write_file) -> FileAudioSourceUuidReference
Duplicates the clip with the given ID and returns the duplicate.
void write_clip(const FileAudioSource *clip, bool parts, bool backup)
Writes the clip to the pool as a wav file.
void reload_clip_frame_bufs()
Loads the frame buffers of clips currently in use in the project from their files and frees the buffe...