Audacity 3.2.0
PixelSampleMapper.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 PixelSampleMapper.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include <cstdint>
14#include <functional>
15#include <variant>
16
17// Clang will fail to instantiate a variant if sampleCount is forward declared
18// It tries to instantiate std::invoke_result for some reason
19#include "SampleCount.h"
20
22class WAVE_TRACK_PAINT_API PixelSampleMapper final
23{
24public:
25 PixelSampleMapper() = default;
30
31 PixelSampleMapper(double t0, double rate, double samplesPerPixel) noexcept;
32
33 void applyBias(double bias) noexcept;
34
35 double applyCorrection(
36 const PixelSampleMapper& oldMapper, size_t oldLen, size_t newLen);
37
38 sampleCount GetFirstSample(uint32_t column) const;
39 sampleCount GetLastSample(uint32_t column) const;
40 std::pair<sampleCount, sampleCount> GetSampleRange(uint32_t column) const;
41
42 using CustomMapper = std::function<sampleCount(uint32_t)>;
43 void setCustomMapper(CustomMapper mapper);
44
45 bool IsValid() const;
46 bool IsLinear() const noexcept;
47
48private:
49 struct LinearMapper final
50 {
51 // Fixes GCC7 build issues (constructor required before non-static data member)
52 LinearMapper() noexcept {}
53
54 LinearMapper(double initialValue, double samplesPerPixel) noexcept
55 : mInitialValue(initialValue)
56 , mSamplesPerPixel(samplesPerPixel)
57 {}
58
59 LinearMapper(const LinearMapper&) = default;
60
61 double mInitialValue {};
62 double mSamplesPerPixel {};
63
64 sampleCount operator()(uint32_t column) const noexcept;
65
66 explicit operator bool() const noexcept;
67 };
68 // GCC 9.3.0 fails horribly if you do not initialize variant explicitly here
69 std::variant<LinearMapper, CustomMapper> mMapper { LinearMapper {} };
70};
Utility class to calculate sample range for a given column.
PixelSampleMapper()=default
PixelSampleMapper(PixelSampleMapper &&)=default
PixelSampleMapper(const PixelSampleMapper &)=default
PixelSampleMapper & operator=(PixelSampleMapper &&)=default
PixelSampleMapper & operator=(const PixelSampleMapper &)=default
std::function< sampleCount(uint32_t)> CustomMapper
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
STL namespace.
LinearMapper(const LinearMapper &)=default
LinearMapper(double initialValue, double samplesPerPixel) noexcept