Audacity 3.2.0
WaveformCache.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 WaveformCache.h
6
7 Paul Licameli split from WaveClip.h
8
9*******************************************************************/
10
11#ifndef __AUDACITY_WAVEFORM_CACHE__
12#define __AUDACITY_WAVEFORM_CACHE__
13
14#include "WaveClip.h"
16
17class WaveCache;
18
19// A bundle of arrays needed for drawing waveforms. The object may or may not
20// own the storage for those arrays. If it does, it destroys them.
22{
23public:
24 int width;
26 float *min, *max, *rms;
27
28 std::vector<sampleCount> ownWhere;
29 std::vector<float> ownMin, ownMax, ownRms;
30
31public:
33 : width(w), where(0), min(0), max(0), rms(0)
34 {
35 }
36
37 // Create "own" arrays.
38 void Allocate()
39 {
40 ownWhere.resize(width + 1);
41 ownMin.resize(width);
42 ownMax.resize(width);
43 ownRms.resize(width);
44
45 where = &ownWhere[0];
46 if (width > 0) {
47 min = &ownMin[0];
48 max = &ownMax[0];
49 rms = &ownRms[0];
50 }
51 else {
52 min = max = rms = 0;
53 }
54 }
55
57 {
58 }
59};
60
62{
63 explicit WaveClipWaveformCache(size_t nChannels);
64 ~WaveClipWaveformCache() override;
65
66 std::unique_ptr<WaveClipListener> Clone() const override;
67
68 // Cache of values for drawing the waveform
69 std::vector<std::unique_ptr<WaveCache>> mWaveCaches;
70 int mDirty { 0 };
71
73
74 void MarkChanged() noexcept override; // NOFAIL-GUARANTEE
75 void Invalidate() override; // NOFAIL-GUARANTEE
76
78 void Clear();
79
81 bool GetWaveDisplay(const WaveChannelInterval &clip,
82 WaveDisplay &display, double t0, double pixelsPerSecond);
83
84 void MakeStereo(WaveClipListener &&other, bool aligned) override;
85 void SwapChannels() override;
86 void Erase(size_t index) override;
87};
88
89#endif
std::vector< float > ownMin
Definition: WaveformCache.h:29
WaveDisplay(int w)
Definition: WaveformCache.h:32
float * rms
Definition: WaveformCache.h:26
sampleCount * where
Definition: WaveformCache.h:25
std::vector< sampleCount > ownWhere
Definition: WaveformCache.h:28
float * min
Definition: WaveformCache.h:26
std::vector< float > ownMax
Definition: WaveformCache.h:29
float * max
Definition: WaveformCache.h:26
void Allocate()
Definition: WaveformCache.h:38
std::vector< float > ownRms
Definition: WaveformCache.h:29
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
bool GetWaveDisplay(const WaveChannelInterval &clip, WaveDisplay &display, double t0, double pixelsPerSecond)
void Erase(size_t index) override
void MarkChanged() noexcept override
~WaveClipWaveformCache() override
void MakeStereo(WaveClipListener &&other, bool aligned) override
void Clear()
Delete the wave cache - force redraw. Thread-safe.
void SwapChannels() override
Default implementation does nothing.
static WaveClipWaveformCache & Get(const WaveChannelInterval &clip)
std::unique_ptr< WaveClipListener > Clone() const override
void Invalidate() override
std::vector< std::unique_ptr< WaveCache > > mWaveCaches
Definition: WaveformCache.h:69
WaveClipWaveformCache(size_t nChannels)