lmms
Cross-platform music production software
Toggle main menu visibility
Loading...
Searching...
No Matches
include
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
"
33
#include "
SampleThumbnailCache.h
"
34
35
namespace
lmms
{
36
37
class
SampleCache
38
{
39
public
:
40
auto
fetchBuffer
(
const
std::filesystem::path& path) -> std::shared_ptr<const SampleBuffer>
41
{
42
return
m_buffers
.fetch(path, [&path] {
43
auto
buffer =
SampleBuffer::fromFile
(
PathUtil::pathToQString
(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
62
private
:
63
FileResourceCache<SampleBuffer>
m_buffers
;
64
FileResourceCache<SampleThumbnailCache>
m_thumbnailCaches
;
65
};
66
}
// namespace lmms
67
68
#endif
// LMMS_SAMPLE_CACHE_H
FileResourceCache.h
PathUtil.h
SampleBuffer.h
SampleThumbnailCache.h
lmms::FileResourceCache
A non-owning cache for resources loaded from file paths.
Definition
FileResourceCache.h:44
lmms::SampleBuffer::fromFile
static std::shared_ptr< const SampleBuffer > fromFile(const QString &path)
Definition
SampleBuffer.cpp:73
lmms::SampleCache
Definition
SampleCache.h:38
lmms::SampleCache::instance
static auto instance() -> SampleCache &
Definition
SampleCache.h:56
lmms::SampleCache::fetchThumbnailCache
auto fetchThumbnailCache(const std::filesystem::path &path) -> std::shared_ptr< const SampleThumbnailCache >
Definition
SampleCache.h:48
lmms::SampleCache::fetchBuffer
auto fetchBuffer(const std::filesystem::path &path) -> std::shared_ptr< const SampleBuffer >
Definition
SampleCache.h:40
lmms::SampleCache::m_buffers
FileResourceCache< SampleBuffer > m_buffers
Definition
SampleCache.h:63
lmms::SampleCache::m_thumbnailCaches
FileResourceCache< SampleThumbnailCache > m_thumbnailCaches
Definition
SampleCache.h:64
lmms::PathUtil::pathToQString
auto pathToQString(const std::filesystem::path &path) -> QString
Converts std::filesystem::path to QString.
Definition
PathUtil.cpp:287
lmms
Definition
RemotePluginBase.cpp:34
Generated on
for lmms by
1.18.0