lmms
Cross-platform music production software
Loading...
Searching...
No Matches
SampleCache.h
Go to the documentation of this file.
1/*
2 * SampleCache.h
3 *
4 * Copyright (c) 2026 saker <sakertooth@gmail.com>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_SAMPLE_CACHE_H
26#define LMMS_SAMPLE_CACHE_H
27
28#include <filesystem>
29
30#include "FileResourceCache.h"
31#include "PathUtil.h"
32#include "SampleBuffer.h"
34
35namespace lmms {
36
38{
39public:
40 auto fetchBuffer(const std::filesystem::path& path) -> std::shared_ptr<const SampleBuffer>
41 {
42 return m_buffers.fetch(path, [&path] {
44 return buffer ? std::make_shared<SampleBuffer>(std::move(*buffer)) : nullptr;
45 });
46 }
47
48 auto fetchThumbnailCache(const std::filesystem::path& path) -> std::shared_ptr<const SampleThumbnailCache>
49 {
50 return m_thumbnailCaches.fetch(path, [&path, this] {
51 auto buffer = fetchBuffer(path);
52 return buffer ? std::make_shared<SampleThumbnailCache>(*buffer) : nullptr;
53 });
54 }
55
56 static auto instance() -> SampleCache&
57 {
58 static auto s_inst = SampleCache{};
59 return s_inst;
60 }
61
62private:
65};
66} // namespace lmms
67
68#endif // LMMS_SAMPLE_CACHE_H
A non-owning cache for resources loaded from file paths.
Definition FileResourceCache.h:44
static std::shared_ptr< const SampleBuffer > fromFile(const QString &path)
Definition SampleBuffer.cpp:73
Definition SampleCache.h:38
static auto instance() -> SampleCache &
Definition SampleCache.h:56
auto fetchThumbnailCache(const std::filesystem::path &path) -> std::shared_ptr< const SampleThumbnailCache >
Definition SampleCache.h:48
auto fetchBuffer(const std::filesystem::path &path) -> std::shared_ptr< const SampleBuffer >
Definition SampleCache.h:40
FileResourceCache< SampleBuffer > m_buffers
Definition SampleCache.h:63
FileResourceCache< SampleThumbnailCache > m_thumbnailCaches
Definition SampleCache.h:64
auto pathToQString(const std::filesystem::path &path) -> QString
Converts std::filesystem::path to QString.
Definition PathUtil.cpp:287
Definition RemotePluginBase.cpp:34