Mercurial > hg > svgui
comparison widgets/LevelPanWidget.cpp @ 940:77110abca8a1 tonioni
LevelPanWidget alternative without including muting
author | Chris Cannam |
---|---|
date | Tue, 31 Mar 2015 14:05:39 +0100 |
parents | 2564d0865feb |
children | d6acb8e36605 |
comparison
equal
deleted
inserted
replaced
939:8744bb5d9fd0 | 940:77110abca8a1 |
---|---|
21 #include "layer/ColourMapper.h" | 21 #include "layer/ColourMapper.h" |
22 #include "base/AudioLevel.h" | 22 #include "base/AudioLevel.h" |
23 | 23 |
24 #include <iostream> | 24 #include <iostream> |
25 #include <cmath> | 25 #include <cmath> |
26 #include <cassert> | |
26 | 27 |
27 using std::cerr; | 28 using std::cerr; |
28 using std::endl; | 29 using std::endl; |
29 | 30 |
30 static const int maxLevel = 4; | 31 static const int maxLevel = 4; // min is 0, may be mute or not depending on m_includeMute |
31 static const int maxPan = 2; // range is -maxPan to maxPan | 32 static const int maxPan = 2; // range is -maxPan to maxPan |
32 | 33 |
33 LevelPanWidget::LevelPanWidget(QWidget *parent) : | 34 LevelPanWidget::LevelPanWidget(QWidget *parent) : |
34 QWidget(parent), | 35 QWidget(parent), |
35 m_level(maxLevel), | 36 m_level(maxLevel), |
36 m_pan(0), | 37 m_pan(0), |
37 m_editable(true) | 38 m_editable(true), |
39 m_includeMute(true) | |
38 { | 40 { |
39 } | 41 } |
40 | 42 |
41 LevelPanWidget::~LevelPanWidget() | 43 LevelPanWidget::~LevelPanWidget() |
42 { | 44 { |
61 int scaled = int(pixels * ratio + 0.5); | 63 int scaled = int(pixels * ratio + 0.5); |
62 if (pixels != 0 && scaled == 0) scaled = 1; | 64 if (pixels != 0 && scaled == 0) scaled = 1; |
63 return QSize(scaled, scaled); | 65 return QSize(scaled, scaled); |
64 } | 66 } |
65 | 67 |
68 static int | |
69 db_to_level(double db) | |
70 { | |
71 // Only if !m_includeMute, otherwise AudioLevel is used. | |
72 // Levels are: +6 0 -6 -12 -20 | |
73 assert(maxLevel == 4); | |
74 if (db > 3.) return 4; | |
75 else if (db > -3.) return 3; | |
76 else if (db > -9.) return 2; | |
77 else if (db > -16.) return 1; | |
78 else return 0; | |
79 } | |
80 | |
81 static double | |
82 level_to_db(int level) | |
83 { | |
84 // Only if !m_includeMute, otherwise AudioLevel is used. | |
85 // Levels are: +6 0 -6 -12 -20 | |
86 assert(maxLevel == 4); | |
87 if (level >= 4) return 6.; | |
88 else if (level == 3) return 0.; | |
89 else if (level == 2) return -6.; | |
90 else if (level == 1) return -12.; | |
91 else return -20.; | |
92 } | |
93 | |
66 void | 94 void |
67 LevelPanWidget::setLevel(float flevel) | 95 LevelPanWidget::setLevel(float flevel) |
68 { | 96 { |
69 int level = AudioLevel::multiplier_to_fader | 97 int level; |
70 (flevel, maxLevel, AudioLevel::ShortFader); | 98 if (m_includeMute) { |
99 level = AudioLevel::multiplier_to_fader | |
100 (flevel, maxLevel, AudioLevel::ShortFader); | |
101 } else { | |
102 level = db_to_level(AudioLevel::multiplier_to_dB(flevel)); | |
103 } | |
71 if (level < 0) level = 0; | 104 if (level < 0) level = 0; |
72 if (level > maxLevel) level = maxLevel; | 105 if (level > maxLevel) level = maxLevel; |
73 if (level != m_level) { | 106 if (level != m_level) { |
74 m_level = level; | 107 m_level = level; |
75 float convertsTo = getLevel(); | 108 float convertsTo = getLevel(); |
78 } | 111 } |
79 update(); | 112 update(); |
80 } | 113 } |
81 } | 114 } |
82 | 115 |
116 float | |
117 LevelPanWidget::getLevel() const | |
118 { | |
119 if (m_includeMute) { | |
120 return float(AudioLevel::fader_to_multiplier | |
121 (m_level, maxLevel, AudioLevel::ShortFader)); | |
122 } else { | |
123 return float(AudioLevel::dB_to_multiplier(level_to_db(m_level))); | |
124 } | |
125 } | |
126 | |
83 void | 127 void |
84 LevelPanWidget::setPan(float pan) | 128 LevelPanWidget::setPan(float pan) |
85 { | 129 { |
86 m_pan = int(round(pan * maxPan)); | 130 m_pan = int(round(pan * maxPan)); |
87 if (m_pan < -maxPan) m_pan = -maxPan; | 131 if (m_pan < -maxPan) m_pan = -maxPan; |
88 if (m_pan > maxPan) m_pan = maxPan; | 132 if (m_pan > maxPan) m_pan = maxPan; |
89 update(); | 133 update(); |
90 } | 134 } |
91 | 135 |
136 bool | |
137 LevelPanWidget::isEditable() const | |
138 { | |
139 return m_editable; | |
140 } | |
141 | |
142 bool | |
143 LevelPanWidget::includesMute() const | |
144 { | |
145 return m_includeMute; | |
146 } | |
147 | |
92 void | 148 void |
93 LevelPanWidget::setEditable(bool editable) | 149 LevelPanWidget::setEditable(bool editable) |
94 { | 150 { |
95 m_editable = editable; | 151 m_editable = editable; |
96 update(); | 152 update(); |
97 } | 153 } |
98 | 154 |
99 float | 155 void |
100 LevelPanWidget::getLevel() const | 156 LevelPanWidget::setIncludeMute(bool include) |
101 { | 157 { |
102 return float(AudioLevel::fader_to_multiplier | 158 m_includeMute = include; |
103 (m_level, maxLevel, AudioLevel::ShortFader)); | 159 emitLevelChanged(); |
160 update(); | |
104 } | 161 } |
105 | 162 |
106 float | 163 float |
107 LevelPanWidget::getPan() const | 164 LevelPanWidget::getPan() const |
108 { | 165 { |
280 pen.setColor(Qt::black); | 337 pen.setColor(Qt::black); |
281 } else { | 338 } else { |
282 pen.setColor(Qt::darkGray); | 339 pen.setColor(Qt::darkGray); |
283 } | 340 } |
284 | 341 |
285 if (!asIfEditable && m_level == 0) { | 342 if (!asIfEditable && m_includeMute && m_level == 0) { |
286 pen.setWidthF(thin * 2); | 343 pen.setWidthF(thin * 2); |
287 pen.setCapStyle(Qt::RoundCap); | 344 pen.setCapStyle(Qt::RoundCap); |
288 paint.setPen(pen); | 345 paint.setPen(pen); |
289 paint.drawLine(cellCentre(rect, 0, -maxPan), | 346 paint.drawLine(cellCentre(rect, 0, -maxPan), |
290 cellCentre(rect, maxLevel, maxPan)); | 347 cellCentre(rect, maxLevel, maxPan)); |
300 for (int level = 0; level <= m_level; ++level) { | 357 for (int level = 0; level <= m_level; ++level) { |
301 if (isEnabled()) { | 358 if (isEnabled()) { |
302 paint.setBrush(mapper.map(level)); | 359 paint.setBrush(mapper.map(level)); |
303 } | 360 } |
304 QRectF clr = cellLightRect(rect, level, m_pan); | 361 QRectF clr = cellLightRect(rect, level, m_pan); |
305 if (m_level == 0) { | 362 if (m_includeMute && m_level == 0) { |
306 paint.drawLine(clr.topLeft(), clr.bottomRight()); | 363 paint.drawLine(clr.topLeft(), clr.bottomRight()); |
307 paint.drawLine(clr.bottomLeft(), clr.topRight()); | 364 paint.drawLine(clr.bottomLeft(), clr.topRight()); |
308 } else { | 365 } else { |
309 paint.drawEllipse(clr); | 366 paint.drawEllipse(clr); |
310 } | 367 } |