Audacity 3.2.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
WaveBitmapCache Class Referencefinal

Cache containing rasterized bitmaps representing the waveform. More...

#include <WaveBitmapCache.h>

Inheritance diagram for WaveBitmapCache:
[legend]
Collaboration diagram for WaveBitmapCache:
[legend]

Classes

struct  LookupHelper
 

Public Member Functions

 WaveBitmapCache (const WaveClip &waveClip, std::shared_ptr< WaveDataCache > dataCache, ElementFactory elementFactory)
 
 ~WaveBitmapCache () override
 
WaveBitmapCacheSetPaintParameters (const WavePaintParameters &params)
 
WaveBitmapCacheSetSelection (const ZoomInfo &zoomInfo, double t0, double t1, bool selected)
 
- Public Member Functions inherited from GraphicsDataCache< WaveBitmapCacheElement >
 GraphicsDataCache (const GraphicsDataCache &)=delete
 
 GraphicsDataCache (double scaledSampleRate, ElementFactory elementFactory)
 
GraphicsDataCacheoperator= (const GraphicsDataCache &)=delete
 
 ~GraphicsDataCache () override
 
IteratorRange< GraphicsDataCacheIterator< WaveBitmapCacheElement > > PerformLookup (const ZoomInfo &zoomInfo, double t0, double t1)
 
const WaveBitmapCacheElementPerformLookup (GraphicsDataCacheKey key)
 
void setInitializer (Initializer initializer)
 
- Public Member Functions inherited from GraphicsDataCacheBase
virtual ~GraphicsDataCacheBase ()=default
 
void Invalidate ()
 Invalidate the cache content. More...
 
double GetScaledSampleRate () const noexcept
 Returns the sample rate associated with cache. More...
 
void UpdateViewportWidth (int64_t width) noexcept
 
int64_t GetMaxViewportWidth () const noexcept
 

Private Member Functions

bool InitializeElement (const GraphicsDataCacheKey &key, WaveBitmapCacheElement &element) override
 
void CheckCache (const ZoomInfo &, double, double) override
 

Private Attributes

WavePaintParameters mPaintParamters
 
struct {
   int64_t   FirstPixel { -1 }
 
   int64_t   LastPixel { -1 }
 
mSelection
 
std::unique_ptr< LookupHelpermLookupHelper
 
const EnvelopemEnvelope { nullptr }
 
size_t mEnvelopeVersion { 0 }
 
const WaveClipmWaveClip
 
Observer::Subscription mStretchChangedSubscription
 

Additional Inherited Members

- Public Types inherited from GraphicsDataCache< WaveBitmapCacheElement >
using ElementFactory = std::function< std::unique_ptr< WaveBitmapCacheElement >()>
 
using Initializer = std::function< bool(const GraphicsDataCacheKey &Key, WaveBitmapCacheElement &element)>
 
- Static Public Attributes inherited from GraphicsDataCacheBase
static constexpr uint32_t CacheElementWidth = 256
 
- Protected Types inherited from GraphicsDataCacheBase
using Lookup = std::vector< LookupElement >
 Cache lookup is a vector, with items sorted using Key. More...
 
virtual void CheckCache (const ZoomInfo &, double, double)
 
virtual bool InitializeElement (const GraphicsDataCacheKey &key, WaveBitmapCacheElement &element)
 
- Protected Member Functions inherited from GraphicsDataCacheBase
 GraphicsDataCacheBase (double scaledSampleRate)
 
void SetScaledSampleRate (double scaledSampleRate)
 
virtual GraphicsDataCacheElementBaseCreateElement (const GraphicsDataCacheKey &key)=0
 Create a new Cache element. Implementation is responsible of the lifetime control. More...
 
virtual void DisposeElement (GraphicsDataCacheElementBase *element)=0
 This method is called, when the cache element should be evicted. Implementation may not deallocate the object. More...
 
virtual bool UpdateElement (const GraphicsDataCacheKey &key, GraphicsDataCacheElementBase &element)=0
 This method is called on all elements matching the request that are not complete (i. e. IsComplete if false). More...
 
BaseLookupResult PerformBaseLookup (const ZoomInfo &zoomInfo, double t0, double t1)
 Perform a lookup inside the cache. This method modifies mLookup and invalidates any previous result. More...
 
const GraphicsDataCacheElementBasePerformBaseLookup (GraphicsDataCacheKey key)
 Perform a lookup for the given key. This method modifies mLookup and invalidates any previous result. More...
 

Detailed Description

Cache containing rasterized bitmaps representing the waveform.

Definition at line 41 of file WaveBitmapCache.h.

Constructor & Destructor Documentation

◆ WaveBitmapCache()

WaveBitmapCache::WaveBitmapCache ( const WaveClip waveClip,
std::shared_ptr< WaveDataCache dataCache,
ElementFactory  elementFactory 
)

Definition at line 298 of file WaveBitmapCache.cpp.

301 : GraphicsDataCache { waveClip.GetRate() / waveClip.GetStretchRatio(),
302 std::move(elementFactory) }
303 , mLookupHelper { std::make_unique<LookupHelper>(std::move(dataCache)) }
304 , mWaveClip { waveClip }
306 const_cast<WaveClip&>(waveClip)
308 [this](const StretchRatioChange&) {
311 })
312 }
313{
314}
void SetScaledSampleRate(double scaledSampleRate)
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
Observer::Subscription mStretchChangedSubscription
std::unique_ptr< LookupHelper > mLookupHelper
const WaveClip & mWaveClip
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:238
double GetStretchRatio() const override
Definition: WaveClip.cpp:625
int GetRate() const override
Definition: WaveClip.h:337

References WaveClip::GetRate(), WaveClip::GetStretchRatio(), mWaveClip, and GraphicsDataCacheBase::SetScaledSampleRate().

Here is the call graph for this function:

◆ ~WaveBitmapCache()

WaveBitmapCache::~WaveBitmapCache ( )
overridedefault

Member Function Documentation

◆ CheckCache()

void WaveBitmapCache::CheckCache ( const ZoomInfo ,
double  ,
double   
)
overrideprivatevirtual

Reimplemented from GraphicsDataCache< WaveBitmapCacheElement >.

Definition at line 357 of file WaveBitmapCache.cpp.

358{
359 if (mEnvelope != nullptr && mEnvelopeVersion != mEnvelope->GetVersion())
360 {
362 Invalidate();
363 }
364}
size_t GetVersion() const
Definition: Envelope.cpp:733
void Invalidate()
Invalidate the cache content.
const Envelope * mEnvelope

References Envelope::GetVersion(), GraphicsDataCacheBase::Invalidate(), mEnvelope, and mEnvelopeVersion.

Here is the call graph for this function:

◆ InitializeElement()

bool WaveBitmapCache::InitializeElement ( const GraphicsDataCacheKey key,
WaveBitmapCacheElement element 
)
overrideprivatevirtual

Reimplemented from GraphicsDataCache< WaveBitmapCacheElement >.

Definition at line 366 of file WaveBitmapCache.cpp.

368{
369 if (mPaintParamters.Height == 0)
370 return false;
371
372 if (!mLookupHelper->PerformLookup(this, key))
373 {
374 const auto width = 1;
375 const auto height = mPaintParamters.Height;
376 const auto bytes = element.Allocate(width, height);
377 std::memset(bytes, 0, width * height * 3);
378 return true;
379 }
380
383
384 const auto columnsCount = mLookupHelper->AvailableColumns;
385
386 const auto defaultColor = Triplet(mPaintParamters.BlankColor);
387
388 const auto height = static_cast<uint32_t>(mPaintParamters.Height);
389
390 auto rowData = element.Allocate(columnsCount, height);
391
392 for (uint32_t row = 0; row < height; ++row)
393 {
394 auto colorFunction = mLookupHelper->ColorFunctions.data();
395
396 for (size_t pixel = 0; pixel < columnsCount; ++pixel)
397 {
398 const auto color = colorFunction->GetColor(row, defaultColor);
399
400 *rowData++ = color.r;
401 *rowData++ = color.g;
402 *rowData++ = color.b;
403
404 ++colorFunction;
405 }
406 }
407
408 element.AvailableColumns = columnsCount;
409 element.IsComplete = mLookupHelper->IsComplete;
410
411 return true;
412}
static const AudacityProject::AttachedObjects::RegisteredFactory key
@ WaveBitmapCache
Time required to access the wave bitmaps cache.
static Stopwatch CreateStopwatch(SectionID section) noexcept
Create a Stopwatch for the section specified.
virtual uint8_t * Allocate(size_t width, size_t height)=0
WavePaintParameters mPaintParamters
bool IsComplete
Cache implementation is responsible to set this flag when all the data of the item is filled.
graphics::Color BlankColor
Color outside the waveform area.
int Height
Height of the of clip on screen.

References WaveBitmapCacheElement::Allocate(), WaveBitmapCacheElement::AvailableColumns, WavePaintParameters::BlankColor, FrameStatistics::CreateStopwatch(), WavePaintParameters::Height, GraphicsDataCacheElementBase::IsComplete, key, mLookupHelper, mPaintParamters, and FrameStatistics::WaveBitmapCache.

Here is the call graph for this function:

◆ SetPaintParameters()

WaveBitmapCache & WaveBitmapCache::SetPaintParameters ( const WavePaintParameters params)

Definition at line 322 of file WaveBitmapCache.cpp.

323{
324 if (mPaintParamters != params)
325 {
327 mEnvelope = params.AttachedEnvelope;
328 mEnvelopeVersion = mEnvelope != nullptr ? mEnvelope->GetVersion() : 0;
329
330 Invalidate();
331 }
332
333 return *this;
334}
EffectDistortionSettings params
Definition: Distortion.cpp:77

References Envelope::GetVersion(), GraphicsDataCacheBase::Invalidate(), mEnvelope, mEnvelopeVersion, mPaintParamters, and params.

Here is the call graph for this function:

◆ SetSelection()

WaveBitmapCache & WaveBitmapCache::SetSelection ( const ZoomInfo zoomInfo,
double  t0,
double  t1,
bool  selected 
)

Definition at line 336 of file WaveBitmapCache.cpp.

338{
339 const auto empty = !selected || t0 > t1 ||
340 ((t1 - t0) < std::numeric_limits<double>::epsilon());
341
342 const auto first = empty ? int64_t(-1) : zoomInfo.TimeToPosition(t0);
343 const auto last =
344 empty ? int64_t(-1) : std::max(zoomInfo.TimeToPosition(t1), first + 1);
345
346 if (mSelection.FirstPixel != first || mSelection.LastPixel != last)
347 {
348 mSelection.FirstPixel = first;
349 mSelection.LastPixel = last;
350
351 Invalidate();
352 }
353
354 return *this;
355}
struct WaveBitmapCache::@136 mSelection
STL namespace.

References GraphicsDataCacheBase::Invalidate(), mSelection, and ZoomInfo::TimeToPosition().

Here is the call graph for this function:

Member Data Documentation

◆ FirstPixel

int64_t WaveBitmapCache::FirstPixel { -1 }

Definition at line 64 of file WaveBitmapCache.h.

Referenced by WaveBitmapCache::LookupHelper::PerformLookup().

◆ LastPixel

int64_t WaveBitmapCache::LastPixel { -1 }

Definition at line 65 of file WaveBitmapCache.h.

Referenced by WaveBitmapCache::LookupHelper::PerformLookup().

◆ mEnvelope

const Envelope* WaveBitmapCache::mEnvelope { nullptr }
private

◆ mEnvelopeVersion

size_t WaveBitmapCache::mEnvelopeVersion { 0 }
private

Definition at line 76 of file WaveBitmapCache.h.

Referenced by CheckCache(), and SetPaintParameters().

◆ mLookupHelper

std::unique_ptr<LookupHelper> WaveBitmapCache::mLookupHelper
private

Definition at line 73 of file WaveBitmapCache.h.

Referenced by InitializeElement().

◆ mPaintParamters

WavePaintParameters WaveBitmapCache::mPaintParamters
private

◆ 

struct { ... } WaveBitmapCache::mSelection

◆ mStretchChangedSubscription

Observer::Subscription WaveBitmapCache::mStretchChangedSubscription
private

Definition at line 79 of file WaveBitmapCache.h.

◆ mWaveClip

const WaveClip& WaveBitmapCache::mWaveClip
private

Definition at line 78 of file WaveBitmapCache.h.

Referenced by WaveBitmapCache().


The documentation for this class was generated from the following files: