Mercurial > hg > svgui
comparison widgets/LevelPanWidget.cpp @ 1177:916b62baf7ac levelpanwidget
Add monitoring to level-pan widget (though not well, yet)
author | Chris Cannam |
---|---|
date | Mon, 05 Dec 2016 15:47:32 +0000 |
parents | 125748a569fa |
children | 6a6a63506e3f |
comparison
equal
deleted
inserted
replaced
1176:125748a569fa | 1177:916b62baf7ac |
---|---|
35 | 35 |
36 LevelPanWidget::LevelPanWidget(QWidget *parent) : | 36 LevelPanWidget::LevelPanWidget(QWidget *parent) : |
37 QWidget(parent), | 37 QWidget(parent), |
38 m_level(maxLevel), | 38 m_level(maxLevel), |
39 m_pan(0), | 39 m_pan(0), |
40 m_monitorLeft(-1), | |
41 m_monitorRight(-1), | |
40 m_editable(true), | 42 m_editable(true), |
41 m_includeMute(true) | 43 m_includeMute(true) |
42 { | 44 { |
43 } | 45 } |
44 | 46 |
76 else if (level == 2) return -6.; | 78 else if (level == 2) return -6.; |
77 else if (level == 1) return -12.; | 79 else if (level == 1) return -12.; |
78 else return -20.; | 80 else return -20.; |
79 } | 81 } |
80 | 82 |
81 void | 83 int |
82 LevelPanWidget::setLevel(float flevel) | 84 LevelPanWidget::audioLevelToLevel(float audioLevel, bool withMute) |
83 { | 85 { |
84 int level; | 86 int level; |
85 if (m_includeMute) { | 87 if (withMute) { |
86 level = AudioLevel::multiplier_to_fader | 88 level = AudioLevel::multiplier_to_fader |
87 (flevel, maxLevel, AudioLevel::ShortFader); | 89 (audioLevel, maxLevel, AudioLevel::ShortFader); |
88 } else { | 90 } else { |
89 level = db_to_level(AudioLevel::multiplier_to_dB(flevel)); | 91 level = db_to_level(AudioLevel::multiplier_to_dB(audioLevel)); |
90 } | 92 } |
91 if (level < 0) level = 0; | 93 if (level < 0) level = 0; |
92 if (level > maxLevel) level = maxLevel; | 94 if (level > maxLevel) level = maxLevel; |
95 return level; | |
96 } | |
97 | |
98 float | |
99 LevelPanWidget::levelToAudioLevel(int level, bool withMute) | |
100 { | |
101 if (withMute) { | |
102 return float(AudioLevel::fader_to_multiplier | |
103 (level, maxLevel, AudioLevel::ShortFader)); | |
104 } else { | |
105 return float(AudioLevel::dB_to_multiplier(level_to_db(level))); | |
106 } | |
107 } | |
108 | |
109 void | |
110 LevelPanWidget::setLevel(float flevel) | |
111 { | |
112 int level = audioLevelToLevel(flevel, m_includeMute); | |
93 if (level != m_level) { | 113 if (level != m_level) { |
94 m_level = level; | 114 m_level = level; |
95 float convertsTo = getLevel(); | 115 float convertsTo = getLevel(); |
96 if (fabsf(convertsTo - flevel) > 1e-5) { | 116 if (fabsf(convertsTo - flevel) > 1e-5) { |
97 emitLevelChanged(); | 117 emitLevelChanged(); |
101 } | 121 } |
102 | 122 |
103 float | 123 float |
104 LevelPanWidget::getLevel() const | 124 LevelPanWidget::getLevel() const |
105 { | 125 { |
106 if (m_includeMute) { | 126 return levelToAudioLevel(m_level, m_includeMute); |
107 return float(AudioLevel::fader_to_multiplier | 127 } |
108 (m_level, maxLevel, AudioLevel::ShortFader)); | 128 |
109 } else { | 129 int |
110 return float(AudioLevel::dB_to_multiplier(level_to_db(m_level))); | 130 LevelPanWidget::audioPanToPan(float audioPan) |
111 } | 131 { |
112 } | 132 int pan = int(round(audioPan * maxPan)); |
113 | 133 if (pan < -maxPan) pan = -maxPan; |
114 void | 134 if (pan > maxPan) pan = maxPan; |
115 LevelPanWidget::setPan(float pan) | 135 return pan; |
116 { | 136 } |
117 m_pan = int(round(pan * maxPan)); | 137 |
118 if (m_pan < -maxPan) m_pan = -maxPan; | 138 float |
119 if (m_pan > maxPan) m_pan = maxPan; | 139 LevelPanWidget::panToAudioPan(int pan) |
140 { | |
141 return float(pan) / float(maxPan); | |
142 } | |
143 | |
144 void | |
145 LevelPanWidget::setPan(float fpan) | |
146 { | |
147 int pan = audioPanToPan(fpan); | |
148 if (pan != m_pan) { | |
149 m_pan = pan; | |
150 update(); | |
151 } | |
152 } | |
153 | |
154 float | |
155 LevelPanWidget::getPan() const | |
156 { | |
157 return panToAudioPan(m_pan); | |
158 } | |
159 | |
160 void | |
161 LevelPanWidget::setMonitoringLevels(float left, float right) | |
162 { | |
163 m_monitorLeft = left; | |
164 m_monitorRight = right; | |
120 update(); | 165 update(); |
121 } | 166 } |
122 | 167 |
123 bool | 168 bool |
124 LevelPanWidget::isEditable() const | 169 LevelPanWidget::isEditable() const |
143 LevelPanWidget::setIncludeMute(bool include) | 188 LevelPanWidget::setIncludeMute(bool include) |
144 { | 189 { |
145 m_includeMute = include; | 190 m_includeMute = include; |
146 emitLevelChanged(); | 191 emitLevelChanged(); |
147 update(); | 192 update(); |
148 } | |
149 | |
150 float | |
151 LevelPanWidget::getPan() const | |
152 { | |
153 return float(m_pan) / float(maxPan); | |
154 } | 193 } |
155 | 194 |
156 void | 195 void |
157 LevelPanWidget::emitLevelChanged() | 196 LevelPanWidget::emitLevelChanged() |
158 { | 197 { |
323 | 362 |
324 pen.setColor(QColor(127, 127, 127, 127)); | 363 pen.setColor(QColor(127, 127, 127, 127)); |
325 pen.setWidthF(cellLightSize(rect).width() + thin); | 364 pen.setWidthF(cellLightSize(rect).width() + thin); |
326 pen.setCapStyle(Qt::RoundCap); | 365 pen.setCapStyle(Qt::RoundCap); |
327 paint.setPen(pen); | 366 paint.setPen(pen); |
367 paint.setBrush(Qt::NoBrush); | |
328 | 368 |
329 for (int pan = -maxPan; pan <= maxPan; ++pan) { | 369 for (int pan = -maxPan; pan <= maxPan; ++pan) { |
330 paint.drawLine(cellCentre(rect, 0, pan), cellCentre(rect, maxLevel, pan)); | 370 paint.drawLine(cellCentre(rect, 0, pan), cellCentre(rect, maxLevel, pan)); |
331 } | 371 } |
332 | 372 |
373 if (m_monitorLeft > 0.f || m_monitorRight > 0.f) { | |
374 paint.setPen(Qt::NoPen); | |
375 for (int pan = -maxPan; pan <= maxPan; ++pan) { | |
376 float audioPan = panToAudioPan(pan); | |
377 float audioLevel; | |
378 if (audioPan < 0.f) { | |
379 audioLevel = m_monitorLeft + m_monitorRight * (1.f + audioPan); | |
380 } else { | |
381 audioLevel = m_monitorRight + m_monitorLeft * (1.f - audioPan); | |
382 } | |
383 int levelHere = audioLevelToLevel(audioLevel, false); | |
384 for (int level = 0; level <= levelHere; ++level) { | |
385 paint.setBrush(level_to_colour(level)); | |
386 QRectF clr = cellLightRect(rect, level, pan); | |
387 paint.drawEllipse(clr); | |
388 } | |
389 } | |
390 paint.setPen(pen); | |
391 paint.setBrush(Qt::NoBrush); | |
392 } | |
393 | |
333 if (isEnabled()) { | 394 if (isEnabled()) { |
334 pen.setColor(Qt::black); | 395 pen.setColor(Qt::black); |
335 } else { | 396 } else { |
336 pen.setColor(Qt::darkGray); | 397 pen.setColor(Qt::darkGray); |
337 } | 398 } |