lmms
Cross-platform music production software
Loading...
Searching...
No Matches
SampleThumbnailCache.h
Go to the documentation of this file.
1/*
2 * SampleThumbnailCache.h
3 *
4 * Copyright (c) 2026 Khoi Dau <casboi86@gmail.com>
5 * Copyright (c) 2026 saker <sakertooth@gmail.com>
6 *
7 * This file is part of LMMS - https://lmms.io
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program (see COPYING); if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA.
23 *
24 */
25
26#ifndef LMMS_SAMPLE_THUMBNAIL_CACHE_H
27#define LMMS_SAMPLE_THUMBNAIL_CACHE_H
28
29#include "SampleBuffer.h"
30#include "lmms_export.h"
31
32namespace lmms {
33
42class LMMS_EXPORT SampleThumbnailCache
43{
44public:
53 {
54 public:
61 struct Peak
62 {
67 friend auto operator+(const Peak& left, const Peak& right) -> Peak
68 { return Peak{std::min(left.min, right.min), std::max(left.max, right.max)}; }
69
74 auto operator+=(const Peak& other) -> Peak&
75 {
76 min = std::min(min, other.min);
77 max = std::max(max, other.max);
78 return *this;
79 }
80
85 float min = std::numeric_limits<float>::infinity();
86
91 float max = -std::numeric_limits<float>::infinity();
92 };
93
99 : m_peaks(width)
100 {
101 }
102
104 auto compress(f_cnt_t outputWidth) const -> Thumbnail;
105
107 auto operator[](f_cnt_t index) -> Peak& { return m_peaks[index]; }
108
110 auto operator[](f_cnt_t index) const -> const Peak& { return m_peaks[index]; }
111
113 auto begin() { return m_peaks.begin(); }
114
116 auto begin() const { return m_peaks.begin(); }
117
119 auto end() { return m_peaks.end(); }
120
122 auto end() const { return m_peaks.end(); }
123
125 auto rbegin() { return m_peaks.rbegin(); }
126
128 auto rbegin() const { return m_peaks.rbegin(); }
129
131 auto rend() { return m_peaks.rend(); }
132
134 auto rend() const { return m_peaks.rend(); }
135
137 auto width() const -> f_cnt_t { return m_peaks.size(); }
138
139 private:
140 std::vector<Peak> m_peaks;
141 };
142
147
152 SampleThumbnailCache(const SampleBuffer& buffer);
153
161 auto nearestThumbnailForWidth(f_cnt_t width) const -> const Thumbnail&;
162
164 auto sampleCount() const -> f_cnt_t { return m_sampleCount; }
165
166private:
167 // Thumbnails are to be in descending order (highest to lowest resolution, or longest to shortest width)
168 // These thumbnails are representative of the entire sample
169 std::vector<Thumbnail> m_thumbnails;
171};
172
173} // namespace lmms
174
175#endif // LMMS_SAMPLE_THUMBNAIL_CACHE_H
Definition SampleBuffer.h:39
Encapsulates a fixed-width vector of audio peak min/max values.
Definition SampleThumbnailCache.h:53
auto begin()
Definition SampleThumbnailCache.h:113
auto operator[](f_cnt_t index) const -> const Peak &
Definition SampleThumbnailCache.h:110
auto rbegin() const
Definition SampleThumbnailCache.h:128
auto end()
Definition SampleThumbnailCache.h:119
auto begin() const
Definition SampleThumbnailCache.h:116
auto rend()
Definition SampleThumbnailCache.h:131
std::vector< Peak > m_peaks
Definition SampleThumbnailCache.h:140
auto rbegin()
Definition SampleThumbnailCache.h:125
auto end() const
Definition SampleThumbnailCache.h:122
Thumbnail(f_cnt_t width)
Constructs an empty thumbnail of a certain width.
Definition SampleThumbnailCache.h:98
auto width() const -> f_cnt_t
Definition SampleThumbnailCache.h:137
auto rend() const
Definition SampleThumbnailCache.h:134
auto operator[](f_cnt_t index) -> Peak &
Definition SampleThumbnailCache.h:107
auto nearestThumbnailForWidth(f_cnt_t width) const -> const Thumbnail &
Get a thumbnail of the requested width. If no thumbnail of the requested width exists,...
Definition SampleThumbnailCache.cpp:57
std::vector< Thumbnail > m_thumbnails
Definition SampleThumbnailCache.h:169
f_cnt_t m_sampleCount
Definition SampleThumbnailCache.h:170
SampleThumbnailCache()=default
Constructs an uninitialized, empty thumbnail cache.
auto sampleCount() const -> f_cnt_t
Definition SampleThumbnailCache.h:164
Definition RemotePluginBase.cpp:34
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
Stores a audio peak value pairing (i.e., minimum and maximum sample over some amount of time).
Definition SampleThumbnailCache.h:62
float max
The highest audio sample found in this frame window. Initialized to negative infinity so that any rea...
Definition SampleThumbnailCache.h:91
auto operator+=(const Peak &other) -> Peak &
In-place accumulates another peak into this peak, expanding this one as necessary.
Definition SampleThumbnailCache.h:74
float min
The lowest audio sample found in this frame window. Initialized to positive infinity so that any real...
Definition SampleThumbnailCache.h:85
friend auto operator+(const Peak &left, const Peak &right) -> Peak
Combines two peaks together by getting the smallest minimum and largest maximum of the two.
Definition SampleThumbnailCache.h:67