Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
WaveBitmapCache::LookupHelper Struct Referencefinal
Collaboration diagram for WaveBitmapCache::LookupHelper:
[legend]

Public Member Functions

 LookupHelper (std::shared_ptr< WaveDataCache > dataCache)
 
bool PerformLookup (WaveBitmapCache *cache, GraphicsDataCacheKey key)
 

Public Attributes

std::shared_ptr< WaveDataCacheDataCache
 
std::array< ColorFunction, GraphicsDataCacheBase::CacheElementWidthColorFunctions {}
 
WaveCacheElement::Columns DBRemappedColumns {}
 
std::array< double, GraphicsDataCacheBase::CacheElementWidthEnvelopeValues {}
 
WaveCacheElement::Columns EnvRemappedColumns {}
 
size_t AvailableColumns { 0 }
 
bool IsComplete { 0 }
 

Detailed Description

Definition at line 84 of file WaveBitmapCache.cpp.

Constructor & Destructor Documentation

◆ LookupHelper()

WaveBitmapCache::LookupHelper::LookupHelper ( std::shared_ptr< WaveDataCache dataCache)
inlineexplicit

Definition at line 86 of file WaveBitmapCache.cpp.

87 : DataCache(std::move(dataCache))
88 {
89 }
std::shared_ptr< WaveDataCache > DataCache

Member Function Documentation

◆ PerformLookup()

bool WaveBitmapCache::LookupHelper::PerformLookup ( WaveBitmapCache cache,
GraphicsDataCacheKey  key 
)
inline

Definition at line 91 of file WaveBitmapCache.cpp.

92 {
93 DataCache->UpdateViewportWidth(cache->GetMaxViewportWidth());
94
95 auto result = DataCache->PerformLookup(key);
96
97 if (result == nullptr)
98 return false;
99
102
103 const auto columnsCount = result->AvailableColumns;
104
105 if (cache->mPaintParamters.DBScale)
106 {
107 auto GetDBValue =
108 [dbRange = cache->mPaintParamters.DBRange](float value)
109 {
110 float sign = (value >= 0 ? 1 : -1);
111
112 if (value != 0.)
113 {
114 float db = LINEAR_TO_DB(fabs(value));
115 value = (db + dbRange) / dbRange;
116
117 if (value < 0.0)
118 value = 0.0;
119
120 value *= sign;
121 }
122
123 return value;
124 };
125
126 for (size_t column = 0; column < columnsCount; ++column)
127 {
128 auto oldColumn = result->Data[column];
129
130 DBRemappedColumns[column] = { GetDBValue(oldColumn.min),
131 GetDBValue(oldColumn.max),
132 GetDBValue(oldColumn.rms) };
133 }
134 }
135
136 auto GetRowFromValue =
137 [min = cache->mPaintParamters.Min, max = cache->mPaintParamters.Max,
138 height = cache->mPaintParamters.Height](float value)
139 {
140 value = (max - value) / (max - min);
141 return static_cast<int>(value * (height - 1) + 0.5);
142 };
143
144 const auto height = cache->mPaintParamters.Height;
145
146 auto inputData = cache->mPaintParamters.DBScale ?
147 DBRemappedColumns.data() :
148 result->Data.data();
149
150 auto envelope = cache->mEnvelope;
151
152 if (
153 envelope != nullptr && (envelope->GetNumberOfPoints() > 0 ||
154 envelope->GetDefaultValue() != 1.0))
155 {
156 envelope->GetValues(
157 EnvelopeValues.data(), static_cast<int>(EnvelopeValues.size()),
158 key.FirstSample / cache->GetScaledSampleRate(),
159 1.0 / key.PixelsPerSecond);
160
161 for (size_t column = 0; column < columnsCount; ++column)
162 {
163 const auto columnData = inputData[column];
164 const float envelopeValue = EnvelopeValues[column];
165
166 EnvRemappedColumns[column] = {
167 columnData.min * envelopeValue,
168 columnData.max * envelopeValue,
169 columnData.rms * envelopeValue
170 };
171 }
172
173 inputData = EnvRemappedColumns.data();
174 }
175
176 const bool hasTopBlankArea = cache->mPaintParamters.Max > 1.0;
177 const auto globalMaxRow = GetRowFromValue(cache->mPaintParamters.Max);
178 const auto globalMinRow = GetRowFromValue(cache->mPaintParamters.Min) + 1;
179
180 const auto blankColor = cache->mPaintParamters.BlankColor;
181
182 const auto backgroundColors = cache->mPaintParamters.BackgroundColors;
183 const auto sampleColors = cache->mPaintParamters.SampleColors;
184 const auto rmsColors = cache->mPaintParamters.RMSColors;
185 const auto clipColors = cache->mPaintParamters.ClippingColors;
186 const auto showRMS = cache->mPaintParamters.ShowRMS;
187
188 auto firstPixel = int64_t(key.FirstSample / cache->GetScaledSampleRate() * key.PixelsPerSecond + 0.5);
189
190 const auto selFirst = cache->mSelection.FirstPixel;
191 const auto selLast = cache->mSelection.LastPixel;
192
193 const bool showClipping = cache->mPaintParamters.ShowClipping;
194
195 for (size_t column = 0; column < columnsCount; ++column)
196 {
197 const bool selected = firstPixel >= selFirst && firstPixel < selLast;
198 ++firstPixel;
199
200 const auto columnData = inputData[column];
201 auto& function = ColorFunctions[column];
202
203 if (showClipping && (columnData.min <= -MAX_AUDIO || columnData.max >= MAX_AUDIO))
204 {
205 function.SetStop(
206 0, selected ? clipColors.Selected : clipColors.Normal, height);
207
208 continue;
209 }
210
211 size_t stopIndex = 0;
212
213 if (hasTopBlankArea)
214 function.SetStop(stopIndex++, blankColor, globalMaxRow);
215
216 const auto maxRow = GetRowFromValue(columnData.max);
217
218 if (maxRow > 0)
219 {
220 function.SetStop(
221 stopIndex++,
222 selected ? backgroundColors.Selected : backgroundColors.Normal,
223 maxRow);
224 }
225
226 if (maxRow >= height)
227 continue;
228
229 if (showRMS)
230 {
231 const auto positiveRMSRow = GetRowFromValue(columnData.rms);
232
233 if (maxRow < positiveRMSRow)
234 {
235 function.SetStop(
236 stopIndex++,
237 selected ? sampleColors.Selected : sampleColors.Normal,
238 positiveRMSRow);
239 }
240
241 if (positiveRMSRow >= height)
242 continue;
243
244 const auto negativeRMSRow =
245 GetRowFromValue(std::max(-columnData.rms, columnData.min));
246
247 if (positiveRMSRow < negativeRMSRow)
248 {
249 function.SetStop(
250 stopIndex++, selected ? rmsColors.Selected : rmsColors.Normal,
251 negativeRMSRow);
252 }
253
254 if (negativeRMSRow >= height)
255 continue;
256 }
257
258 const auto minRow = GetRowFromValue(columnData.min);
259
260 // if minRow == maxRow - we want to display it as a single pixel
261 function.SetStop(
262 stopIndex++, selected ? sampleColors.Selected : sampleColors.Normal,
263 minRow != maxRow ? minRow : minRow + 1);
264
265 if (minRow < globalMinRow)
266 {
267 function.SetStop(
268 stopIndex++,
269 selected ? backgroundColors.Selected : backgroundColors.Normal,
270 globalMinRow);
271 }
272
273 if (globalMinRow < height)
274 function.SetStop(stopIndex++, blankColor, height);
275 }
276
277 AvailableColumns = columnsCount;
278 IsComplete = result->IsComplete;
279
280 return true;
281 }
int min(int a, int b)
#define MAX_AUDIO
Definition: MemoryX.h:341
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:339
static const AudacityProject::AttachedObjects::RegisteredFactory key
void GetValues(double *buffer, int len, double t0, double tstep) const
Get many envelope points at once.
Definition: Envelope.cpp:981
@ WaveBitmapCachePreprocess
Time required to build the structures required for the bitmap cache population.
static Stopwatch CreateStopwatch(SectionID section) noexcept
Create a Stopwatch for the section specified.
int64_t GetMaxViewportWidth() const noexcept
double GetScaledSampleRate() const noexcept
Returns the sample rate associated with cache.
WavePaintParameters mPaintParamters
const Envelope * mEnvelope
struct WaveBitmapCache::@136 mSelection
std::array< double, GraphicsDataCacheBase::CacheElementWidth > EnvelopeValues
WaveCacheElement::Columns DBRemappedColumns
WaveCacheElement::Columns EnvRemappedColumns
std::array< ColorFunction, GraphicsDataCacheBase::CacheElementWidth > ColorFunctions
bool ShowRMS
True, if we paint RMS values on top of min and max.
graphics::Color BlankColor
Color outside the waveform area.
ColorPair RMSColors
Color of the (-rms, +rms) line.
bool DBScale
True, if we paint in dB scale.
bool ShowClipping
True, if we mark clipped values.
double DBRange
Decibel range.
double Max
Max value used to clip the output.
ColorPair SampleColors
Color of the (min, max) line.
ColorPair ClippingColors
Color for the columns where clipping has occurred.
ColorPair BackgroundColors
Waveform background color.
int Height
Height of the of clip on screen.
double Min
Min value used to clip the output.

References AvailableColumns, WavePaintParameters::BackgroundColors, WavePaintParameters::BlankColor, WavePaintParameters::ClippingColors, ColorFunctions, FrameStatistics::CreateStopwatch(), DataCache, WavePaintParameters::DBRange, DBRemappedColumns, WavePaintParameters::DBScale, EnvelopeValues, EnvRemappedColumns, WaveBitmapCache::FirstPixel, GraphicsDataCacheBase::GetMaxViewportWidth(), GraphicsDataCacheBase::GetScaledSampleRate(), Envelope::GetValues(), WavePaintParameters::Height, IsComplete, key, WaveBitmapCache::LastPixel, LINEAR_TO_DB, WavePaintParameters::Max, MAX_AUDIO, WaveBitmapCache::mEnvelope, WavePaintParameters::Min, min(), WaveBitmapCache::mPaintParamters, WaveBitmapCache::mSelection, WavePaintParameters::RMSColors, WavePaintParameters::SampleColors, WavePaintParameters::ShowClipping, WavePaintParameters::ShowRMS, and FrameStatistics::WaveBitmapCachePreprocess.

Here is the call graph for this function:

Member Data Documentation

◆ AvailableColumns

size_t WaveBitmapCache::LookupHelper::AvailableColumns { 0 }

Definition at line 294 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ ColorFunctions

std::array<ColorFunction, GraphicsDataCacheBase::CacheElementWidth> WaveBitmapCache::LookupHelper::ColorFunctions {}

Definition at line 286 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ DataCache

std::shared_ptr<WaveDataCache> WaveBitmapCache::LookupHelper::DataCache

Definition at line 283 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ DBRemappedColumns

WaveCacheElement::Columns WaveBitmapCache::LookupHelper::DBRemappedColumns {}

Definition at line 288 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ EnvelopeValues

std::array<double, GraphicsDataCacheBase::CacheElementWidth> WaveBitmapCache::LookupHelper::EnvelopeValues {}

Definition at line 291 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ EnvRemappedColumns

WaveCacheElement::Columns WaveBitmapCache::LookupHelper::EnvRemappedColumns {}

Definition at line 292 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ IsComplete

bool WaveBitmapCache::LookupHelper::IsComplete { 0 }

Definition at line 295 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().


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