Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
anonymous_namespace{WaveformView.cpp}::WaveformPainter Class Referencefinal
Inheritance diagram for anonymous_namespace{WaveformView.cpp}::WaveformPainter:
[legend]
Collaboration diagram for anonymous_namespace{WaveformView.cpp}::WaveformPainter:
[legend]

Classes

struct  ChannelCaches
 

Public Member Functions

 WaveformPainter ()
 
WaveformPainterEnsureClip (const WaveClip &clip)
 
void SetSelection (const ZoomInfo &zoomInfo, float t0, float t1, bool selected)
 
void Draw (int channelIndex, wxDC &dc, const WavePaintParameters &params, const ZoomInfo &zoomInfo, const wxRect &targetRect, int leftOffset, double from, double to)
 
void SwapChannels () override
 Default implementation does nothing. More...
 
void MarkChanged () noexcept override
 
void Invalidate () override
 
std::unique_ptr< WaveClipListenerClone () const override
 
- Public Member Functions inherited from WaveClipListener
virtual ~WaveClipListener ()=0
 
virtual void MarkChanged () noexcept=0
 
virtual void Invalidate ()=0
 
virtual void WriteXMLAttributes (XMLWriter &writer) const
 
virtual bool HandleXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView)
 
virtual void MakeStereo (WaveClipListener &&other, bool aligned)
 
virtual void SwapChannels ()
 Default implementation does nothing. More...
 
virtual void Erase (size_t index)
 

Static Public Member Functions

static WaveformPainterGet (const WaveClip &clip)
 

Private Attributes

const WaveClipmWaveClip {}
 
std::vector< ChannelCachesmChannelCaches
 
std::atomic< bool > mChanged = false
 

Detailed Description

Definition at line 212 of file WaveformView.cpp.

Constructor & Destructor Documentation

◆ WaveformPainter()

anonymous_namespace{WaveformView.cpp}::WaveformPainter::WaveformPainter ( )
inline

Definition at line 219 of file WaveformView.cpp.

220 {
221 }

Member Function Documentation

◆ Clone()

std::unique_ptr< WaveClipListener > anonymous_namespace{WaveformView.cpp}::WaveformPainter::Clone ( ) const
inlineoverride

Definition at line 317 of file WaveformView.cpp.

318 {
319 return std::make_unique<WaveformPainter>();
320 }

◆ Draw()

void anonymous_namespace{WaveformView.cpp}::WaveformPainter::Draw ( int  channelIndex,
wxDC &  dc,
const WavePaintParameters params,
const ZoomInfo zoomInfo,
const wxRect &  targetRect,
int  leftOffset,
double  from,
double  to 
)
inline

Definition at line 259 of file WaveformView.cpp.

263 {
264 auto& channelCache = mChannelCaches[channelIndex];
265
266 channelCache.BitmapCache->SetPaintParameters(params);
267
268 auto range = channelCache.BitmapCache->PerformLookup(zoomInfo, from, to);
269
270 auto left = targetRect.x + leftOffset;
271 auto height = targetRect.height;
272
273 const auto top = targetRect.y;
274
275 wxMemoryDC memdc;
276 for (auto it = range.begin(); it != range.end(); ++it)
277 {
278 const auto elementLeftOffset = it.GetLeftOffset();
279 const auto elementRightOffset = it.GetRightOffset();
280
281 const auto width = WaveBitmapCache::CacheElementWidth -
282 elementLeftOffset - elementRightOffset;
283
284 auto& bitmap = static_cast<WaveBitmapCacheElementWX&>(*it).GetBitmap();
285 memdc.SelectObject(bitmap);
286 dc.Blit(
287 wxPoint(left, targetRect.y), wxSize(width, it->Height()), &memdc,
288 wxPoint(elementLeftOffset, 0));
289
290 left += width;
291 }
292 }
EffectDistortionSettings params
static constexpr uint32_t CacheElementWidth

References GraphicsDataCacheBase::CacheElementWidth, anonymous_namespace{WaveformView.cpp}::WaveBitmapCacheElementWX::GetBitmap(), and params.

Here is the call graph for this function:

◆ EnsureClip()

WaveformPainter & anonymous_namespace{WaveformView.cpp}::WaveformPainter::EnsureClip ( const WaveClip clip)
inline

Definition at line 223 of file WaveformView.cpp.

224 {
225 const auto changed = mChanged.exchange(false);
226 if (&clip != mWaveClip || changed)
227 mChannelCaches.clear();
228
229 const auto nChannels = clip.NChannels();
230
231 if (mChannelCaches.size() == nChannels)
232 return *this;
233
234 mWaveClip = &clip;
235
236 mChannelCaches.reserve(nChannels);
237
238 for (auto channelIndex = 0; channelIndex < nChannels; ++channelIndex)
239 {
240 auto dataCache = std::make_shared<WaveDataCache>(clip, channelIndex);
241
242 auto bitmapCache = std::make_unique<WaveBitmapCache>(
243 clip, dataCache,
244 [] { return std::make_unique<WaveBitmapCacheElementWX>(); });
245
246 mChannelCaches.push_back(
247 { std::move(dataCache), std::move(bitmapCache) });
248 }
249
250 return *this;
251 }
size_t NChannels() const override
How many Sequences the clip contains.
Definition: WaveClip.cpp:373

References WaveClip::NChannels().

Here is the call graph for this function:

◆ Get()

WaveformPainter & WaveformPainter::Get ( const WaveClip clip)
static

Definition at line 1197 of file WaveformView.cpp.

1198{
1199 return const_cast< WaveClip& >( clip ) // Consider it mutable data
1200 .Attachments::Get<WaveformPainter>(sKeyW).EnsureClip(clip);
1201}
static WaveClip::Attachments::RegisteredFactory sKeyW
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:238

References sKeyW.

◆ Invalidate()

void anonymous_namespace{WaveformView.cpp}::WaveformPainter::Invalidate ( )
inlineoverridevirtual

Implements WaveClipListener.

Definition at line 308 of file WaveformView.cpp.

309 {
310 for (auto& channelCache : mChannelCaches)
311 {
312 channelCache.DataCache->Invalidate();
313 channelCache.BitmapCache->Invalidate();
314 }
315 }

◆ MarkChanged()

void anonymous_namespace{WaveformView.cpp}::WaveformPainter::MarkChanged ( )
inlineoverridevirtualnoexcept

Implements WaveClipListener.

Definition at line 301 of file WaveformView.cpp.

302 {
303 //Triggered when any part of the waveform has changed
304 //TODO: invalidate parts of the cache that intersect changes
305 mChanged.store(true);
306 }

◆ SetSelection()

void anonymous_namespace{WaveformView.cpp}::WaveformPainter::SetSelection ( const ZoomInfo zoomInfo,
float  t0,
float  t1,
bool  selected 
)
inline

Definition at line 253 of file WaveformView.cpp.

254 {
255 for (auto& channelCache : mChannelCaches)
256 channelCache.BitmapCache->SetSelection(zoomInfo, t0, t1, selected);
257 }

◆ SwapChannels()

void anonymous_namespace{WaveformView.cpp}::WaveformPainter::SwapChannels ( )
inlineoverridevirtual

Default implementation does nothing.

Reimplemented from WaveClipListener.

Definition at line 294 of file WaveformView.cpp.

295 {
296 //Wave data cache captures channel index which becomes
297 //part of it's state, request cache rebuild...
298 mChanged.store(true);
299 }

Member Data Documentation

◆ mChanged

std::atomic<bool> anonymous_namespace{WaveformView.cpp}::WaveformPainter::mChanged = false
private

Definition at line 332 of file WaveformView.cpp.

◆ mChannelCaches

std::vector<ChannelCaches> anonymous_namespace{WaveformView.cpp}::WaveformPainter::mChannelCaches
private

Definition at line 331 of file WaveformView.cpp.

◆ mWaveClip

const WaveClip* anonymous_namespace{WaveformView.cpp}::WaveformPainter::mWaveClip {}
private

Definition at line 323 of file WaveformView.cpp.


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