Mercurial > hg > svgui
comparison layer/ColourScale.cpp @ 1105:ea5ae9dd10ba spectrogram-minor-refactor
Convert ColourScaleType into an enum class
author | Chris Cannam |
---|---|
date | Thu, 14 Jul 2016 16:52:16 +0100 |
parents | 7ebfb61b1701 |
children | 9fb8dfd7ce4c |
comparison
equal
deleted
inserted
replaced
1104:46cc4644206d | 1105:ea5ae9dd10ba |
---|---|
31 } | 31 } |
32 | 32 |
33 m_mappedMin = m_params.minValue; | 33 m_mappedMin = m_params.minValue; |
34 m_mappedMax = m_params.maxValue; | 34 m_mappedMax = m_params.maxValue; |
35 | 35 |
36 if (m_params.scale == LogColourScale) { | 36 if (m_params.scale == ColourScaleType::Log) { |
37 | 37 |
38 LogRange::mapRange(m_mappedMin, m_mappedMax); | 38 LogRange::mapRange(m_mappedMin, m_mappedMax); |
39 | 39 |
40 } else if (m_params.scale == PlusMinusOneScale) { | 40 } else if (m_params.scale == ColourScaleType::PlusMinusOne) { |
41 | 41 |
42 m_mappedMin = -1.0; | 42 m_mappedMin = -1.0; |
43 m_mappedMax = 1.0; | 43 m_mappedMax = 1.0; |
44 | 44 |
45 } else if (m_params.scale == AbsoluteScale) { | 45 } else if (m_params.scale == ColourScaleType::Absolute) { |
46 | 46 |
47 m_mappedMin = fabs(m_mappedMin); | 47 m_mappedMin = fabs(m_mappedMin); |
48 m_mappedMax = fabs(m_mappedMax); | 48 m_mappedMax = fabs(m_mappedMax); |
49 if (m_mappedMin >= m_mappedMax) { | 49 if (m_mappedMin >= m_mappedMax) { |
50 std::swap(m_mappedMin, m_mappedMax); | 50 std::swap(m_mappedMin, m_mappedMax); |
58 | 58 |
59 ColourScale::~ColourScale() | 59 ColourScale::~ColourScale() |
60 { | 60 { |
61 } | 61 } |
62 | 62 |
63 ColourScale::Scale | 63 ColourScaleType |
64 ColourScale::getScale() const | 64 ColourScale::getScale() const |
65 { | 65 { |
66 return m_params.scale; | 66 return m_params.scale; |
67 } | 67 } |
68 | 68 |
69 int | 69 int |
70 ColourScale::getPixel(double value) const | 70 ColourScale::getPixel(double value) const |
71 { | 71 { |
72 double maxPixF = m_maxPixel; | 72 double maxPixF = m_maxPixel; |
73 | 73 |
74 if (m_params.scale == PhaseColourScale) { | 74 if (m_params.scale == ColourScaleType::Phase) { |
75 double half = (maxPixF - 1.f) / 2.f; | 75 double half = (maxPixF - 1.f) / 2.f; |
76 return 1 + int((value * half) / M_PI + half); | 76 return 1 + int((value * half) / M_PI + half); |
77 } | 77 } |
78 | 78 |
79 value *= m_params.gain; | 79 value *= m_params.gain; |
80 | 80 |
81 if (value < m_params.threshold) return 0; | 81 if (value < m_params.threshold) return 0; |
82 | 82 |
83 double mapped = value; | 83 double mapped = value; |
84 | 84 |
85 if (m_params.scale == LogColourScale) { | 85 if (m_params.scale == ColourScaleType::Log) { |
86 mapped = LogRange::map(value); | 86 mapped = LogRange::map(value); |
87 } else if (m_params.scale == PlusMinusOneScale) { | 87 } else if (m_params.scale == ColourScaleType::PlusMinusOne) { |
88 if (mapped < -1.f) mapped = -1.f; | 88 if (mapped < -1.f) mapped = -1.f; |
89 if (mapped > 1.f) mapped = 1.f; | 89 if (mapped > 1.f) mapped = 1.f; |
90 } else if (m_params.scale == AbsoluteScale) { | 90 } else if (m_params.scale == ColourScaleType::Absolute) { |
91 if (mapped < 0.f) mapped = -mapped; | 91 if (mapped < 0.f) mapped = -mapped; |
92 } | 92 } |
93 | 93 |
94 if (mapped < m_mappedMin) { | 94 if (mapped < m_mappedMin) { |
95 mapped = m_mappedMin; | 95 mapped = m_mappedMin; |
100 | 100 |
101 double proportion = (mapped - m_mappedMin) / (m_mappedMax - m_mappedMin); | 101 double proportion = (mapped - m_mappedMin) / (m_mappedMax - m_mappedMin); |
102 | 102 |
103 int pixel = 0; | 103 int pixel = 0; |
104 | 104 |
105 if (m_params.scale == MeterColourScale) { | 105 if (m_params.scale == ColourScaleType::Meter) { |
106 pixel = AudioLevel::multiplier_to_preview(proportion, m_maxPixel-1) + 1; | 106 pixel = AudioLevel::multiplier_to_preview(proportion, m_maxPixel-1) + 1; |
107 } else { | 107 } else { |
108 pixel = int(proportion * maxPixF) + 1; | 108 pixel = int(proportion * maxPixF) + 1; |
109 } | 109 } |
110 | 110 |