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 const auto zeroLineY = GetRowFromValue(.0f);
147
148 auto inputData = cache->mPaintParamters.DBScale ?
149 DBRemappedColumns.data() :
150 result->Data.data();
151
152 auto envelope = cache->mEnvelope;
153
154 if (
155 envelope != nullptr && (envelope->GetNumberOfPoints() > 0 ||
156 envelope->GetDefaultValue() != 1.0))
157 {
158 envelope->GetValues(
159 EnvelopeValues.data(), static_cast<int>(EnvelopeValues.size()),
160 key.FirstSample / cache->GetScaledSampleRate() +
161 envelope->GetOffset(),
162 1.0 / key.PixelsPerSecond);
163
164 for (size_t column = 0; column < columnsCount; ++column)
165 {
166 const auto columnData = inputData[column];
167 const float envelopeValue = EnvelopeValues[column];
168
169 EnvRemappedColumns[column] = {
170 columnData.min * envelopeValue,
171 columnData.max * envelopeValue,
172 columnData.rms * envelopeValue
173 };
174 }
175
176 inputData = EnvRemappedColumns.data();
177 }
178
179 const bool hasTopBlankArea = cache->mPaintParamters.Max > 1.0;
180 const auto globalMaxRow = GetRowFromValue(cache->mPaintParamters.Max);
181 const auto globalMinRow = GetRowFromValue(cache->mPaintParamters.Min) + 1;
182
183 const auto blankColor = cache->mPaintParamters.BlankColor;
184 const auto zeroLineColor = cache->mPaintParamters.ZeroLineColor;
185
186 const auto backgroundColors = cache->mPaintParamters.BackgroundColors;
187 const auto sampleColors = cache->mPaintParamters.SampleColors;
188 const auto rmsColors = cache->mPaintParamters.RMSColors;
189 const auto clipColors = cache->mPaintParamters.ClippingColors;
190 const auto showRMS = cache->mPaintParamters.ShowRMS;
191
192 auto firstPixel = int64_t(key.FirstSample / cache->GetScaledSampleRate() * key.PixelsPerSecond + 0.5);
193
194 const auto selFirst = cache->mSelection.FirstPixel;
195 const auto selLast = cache->mSelection.LastPixel;
196
197 const bool showClipping = cache->mPaintParamters.ShowClipping;
198
199 for (size_t column = 0; column < columnsCount; ++column)
200 {
201 const bool selected = firstPixel >= selFirst && firstPixel < selLast;
202 ++firstPixel;
203
204 const auto columnData = inputData[column];
205 auto& function = ColorFunctions[column];
206
207 if (showClipping && (columnData.min <= -MAX_AUDIO || columnData.max >= MAX_AUDIO))
208 {
209 function.SetStop(
210 0, selected ? clipColors.Selected : clipColors.Normal, height);
211
212 continue;
213 }
214
215 size_t stopIndex = 0;
216
217 if (hasTopBlankArea)
218 function.SetStop(stopIndex++, blankColor, globalMaxRow);
219
220 const auto maxRow = GetRowFromValue(columnData.max);
221
222 if(zeroLineY > globalMaxRow && maxRow > zeroLineY)
223 {
224 //Waveform is below 0
225 function.SetStop(
226 stopIndex++,
227 selected ? backgroundColors.Selected : backgroundColors.Normal,
228 zeroLineY);
229 function.SetStop(
230 stopIndex++,
231 zeroLineColor,
232 zeroLineY + 1
233 );
234 }
235
236 if (maxRow > 0)
237 {
238 function.SetStop(
239 stopIndex++,
240 selected ? backgroundColors.Selected : backgroundColors.Normal,
241 maxRow);
242 }
243
244 if (maxRow >= height)
245 continue;
246
247 if (showRMS)
248 {
249 const auto positiveRMSRow = GetRowFromValue(columnData.rms);
250
251 if (maxRow < positiveRMSRow)
252 {
253 function.SetStop(
254 stopIndex++,
255 selected ? sampleColors.Selected : sampleColors.Normal,
256 positiveRMSRow);
257 }
258
259 if (positiveRMSRow >= height)
260 continue;
261
262 const auto negativeRMSRow =
263 GetRowFromValue(std::max(-columnData.rms, columnData.min));
264
265 if (positiveRMSRow < negativeRMSRow)
266 {
267 function.SetStop(
268 stopIndex++, selected ? rmsColors.Selected : rmsColors.Normal,
269 negativeRMSRow);
270 }
271
272 if (negativeRMSRow >= height)
273 continue;
274 }
275
276 const auto minRow = GetRowFromValue(columnData.min);
277
278 // if minRow == maxRow - we want to display it as a single pixel
279 function.SetStop(
280 stopIndex++, selected ? sampleColors.Selected : sampleColors.Normal,
281 minRow != maxRow ? minRow : minRow + 1);
282
283 if(zeroLineY < globalMinRow && minRow < zeroLineY)
284 {
285 //Waveform is above 0
286 function.SetStop(
287 stopIndex++,
288 selected ? backgroundColors.Selected : backgroundColors.Normal,
289 zeroLineY);
290 function.SetStop(
291 stopIndex++,
292 zeroLineColor,
293 zeroLineY + 1);
294 }
295
296 if (minRow < globalMinRow)
297 {
298 function.SetStop(
299 stopIndex++,
300 selected ? backgroundColors.Selected : backgroundColors.Normal,
301 globalMinRow);
302 }
303
304 if (globalMinRow < height)
305 function.SetStop(stopIndex++, blankColor, height);
306 }
307
308 AvailableColumns = columnsCount;
309 IsComplete = result->IsComplete;
310
311 return true;
312 }
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::@133 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.
graphics::Color ZeroLineColor
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, FrameStatistics::WaveBitmapCachePreprocess, and WavePaintParameters::ZeroLineColor.

Here is the call graph for this function:

Member Data Documentation

◆ AvailableColumns

size_t WaveBitmapCache::LookupHelper::AvailableColumns { 0 }

Definition at line 325 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ ColorFunctions

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

Definition at line 317 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ DataCache

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

Definition at line 314 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ DBRemappedColumns

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

Definition at line 319 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ EnvelopeValues

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

Definition at line 322 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ EnvRemappedColumns

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

Definition at line 323 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().

◆ IsComplete

bool WaveBitmapCache::LookupHelper::IsComplete { 0 }

Definition at line 326 of file WaveBitmapCache.cpp.

Referenced by PerformLookup().


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