Audacity 3.2.0
WaveDataCache.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 WaveDataCache.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include <array>
14#include <cstdint>
15#include <numeric>
16#include <vector>
17#include <functional>
18
19#include "GraphicsDataCache.h"
20#include "WaveData.h"
21#include "Observer.h"
22
23class WaveClip;
24
26struct WAVE_TRACK_PAINT_API WaveCacheSampleBlock final
27{
29 enum class Type
30 {
32 Samples,
37 MinMaxRMS256,
42 MinMaxRMS64k,
43 };
44
46 struct Summary final
47 {
48 size_t SamplesCount { 0 };
49
50 float Min { std::numeric_limits<float>::infinity() };
51 float Max { -std::numeric_limits<float>::infinity() };
52
53 double SquaresSum { 0.0f };
54
55 size_t SumItemsCount { 0 };
56 };
57
58 Type DataType { Type::Samples };
59 int64_t FirstSample { 0 };
60 size_t NumSamples { 0 };
61
63 bool ContainsSample(int64_t sampleIndex) const noexcept;
64
66 float* GetWritePointer(size_t floatsCount);
67
68 void Reset() noexcept;
69private:
70 Summary GetSummary(
71 int64_t from, size_t samplesCount,
72 const Summary& initializer) const noexcept;
73
74 std::vector<float> mData;
75
76 friend class WaveDataCache;
77};
78
80struct WAVE_TRACK_PAINT_API WaveCacheElement final : GraphicsDataCacheElementBase
81{
82 using Columns =
83 std::array<WaveDisplayColumn, GraphicsDataCacheBase::CacheElementWidth>;
84
86 size_t AvailableColumns { 0 };
87
88 void Smooth(GraphicsDataCacheElementBase* prevElement) override;
89};
90
92class WAVE_TRACK_PAINT_API WaveDataCache final :
93 public GraphicsDataCache<WaveCacheElement>
94{
95public:
96 using DataProvider = std::function<bool (int64_t requiredSample, WaveCacheSampleBlock::Type dataType, WaveCacheSampleBlock& block)>;
97
98 WaveDataCache(const WaveClip& waveClip, int channelIndex);
99
100private:
101 bool InitializeElement(
102 const GraphicsDataCacheKey& key, WaveCacheElement& element) override;
103
105
107
110};
static const AudacityProject::AttachedObjects::RegisteredFactory key
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:238
Cache that contains the waveform data.
Definition: WaveDataCache.h:94
Observer::Subscription mStretchChangedSubscription
std::function< bool(int64_t requiredSample, WaveCacheSampleBlock::Type dataType, WaveCacheSampleBlock &block)> DataProvider
Definition: WaveDataCache.h:96
DataProvider mProvider
WaveCacheSampleBlock mCachedBlock
const WaveClip & mWaveClip
STL namespace.
A base class for the for cache elements.
A key into the graphics data cache.
An element of a cache that contains the waveform data.
Definition: WaveDataCache.h:81
std::array< WaveDisplayColumn, GraphicsDataCacheBase::CacheElementWidth > Columns
Definition: WaveDataCache.h:83
Summary calculated over the requested range.
Definition: WaveDataCache.h:47
Helper structure used to transfer the data between the data and graphics layers.
Definition: WaveDataCache.h:27
Type
Type of the data of the request.
Definition: WaveDataCache.h:30