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 329 of file WaveBitmapCache.cpp.

332 : GraphicsDataCache { waveClip.GetRate() / waveClip.GetStretchRatio(),
333 std::move(elementFactory) }
334 , mLookupHelper { std::make_unique<LookupHelper>(std::move(dataCache)) }
335 , mWaveClip { waveClip }
337 const_cast<WaveClip&>(waveClip)
339 [this](const StretchRatioChange&) {
342 })
343 }
344{
345}
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 388 of file WaveBitmapCache.cpp.

389{
390 if (mEnvelope != nullptr && mEnvelopeVersion != mEnvelope->GetVersion())
391 {
393 Invalidate();
394 }
395}
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 397 of file WaveBitmapCache.cpp.

399{
400 if (mPaintParamters.Height == 0)
401 return false;
402
403 if (!mLookupHelper->PerformLookup(this, key))
404 {
405 const auto width = 1;
406 const auto height = mPaintParamters.Height;
407 const auto bytes = element.Allocate(width, height);
408 std::memset(bytes, 0, width * height * 3);
409 return true;
410 }
411
414
415 const auto columnsCount = mLookupHelper->AvailableColumns;
416
417 const auto defaultColor = Triplet(mPaintParamters.BlankColor);
418
419 const auto height = static_cast<uint32_t>(mPaintParamters.Height);
420
421 auto rowData = element.Allocate(columnsCount, height);
422
423 for (uint32_t row = 0; row < height; ++row)
424 {
425 auto colorFunction = mLookupHelper->ColorFunctions.data();
426
427 for (size_t pixel = 0; pixel < columnsCount; ++pixel)
428 {
429 const auto color = colorFunction->GetColor(row, defaultColor);
430
431 *rowData++ = color.r;
432 *rowData++ = color.g;
433 *rowData++ = color.b;
434
435 ++colorFunction;
436 }
437 }
438
439 element.AvailableColumns = columnsCount;
440 element.IsComplete = mLookupHelper->IsComplete;
441
442 return true;
443}
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 353 of file WaveBitmapCache.cpp.

354{
355 if (mPaintParamters != params)
356 {
358 mEnvelope = params.AttachedEnvelope;
359 mEnvelopeVersion = mEnvelope != nullptr ? mEnvelope->GetVersion() : 0;
360
361 Invalidate();
362 }
363
364 return *this;
365}
EffectDistortionSettings params

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 367 of file WaveBitmapCache.cpp.

369{
370 const auto empty = !selected || t0 > t1 ||
371 ((t1 - t0) < std::numeric_limits<double>::epsilon());
372
373 const auto first = empty ? int64_t(-1) : zoomInfo.TimeToPosition(t0);
374 const auto last =
375 empty ? int64_t(-1) : std::max(zoomInfo.TimeToPosition(t1), first + 1);
376
377 if (mSelection.FirstPixel != first || mSelection.LastPixel != last)
378 {
379 mSelection.FirstPixel = first;
380 mSelection.LastPixel = last;
381
382 Invalidate();
383 }
384
385 return *this;
386}
struct WaveBitmapCache::@133 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: