comparison widgets/Fader.cpp @ 1324:13d9b422f7fe zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:31 +0100
parents a34a2a25907c
children
comparison
equal deleted inserted replaced
1183:57d192e26331 1324:13d9b422f7fe
57 resize(116, 23); 57 resize(116, 23);
58 58
59 QString background_path = ":/icons/fader_background.png"; 59 QString background_path = ":/icons/fader_background.png";
60 bool ok = m_back.load(background_path); 60 bool ok = m_back.load(background_path);
61 if (ok == false) { 61 if (ok == false) {
62 cerr << "Fader: Error loading pixmap" << endl; 62 cerr << "Fader: Error loading pixmap" << endl;
63 } 63 }
64 64
65 QString leds_path = ":/icons/fader_leds.png"; 65 QString leds_path = ":/icons/fader_leds.png";
66 ok = m_leds.load(leds_path); 66 ok = m_leds.load(leds_path);
67 if (ok == false) { 67 if (ok == false) {
68 cerr << "Error loading pixmap" << endl; 68 cerr << "Error loading pixmap" << endl;
69 } 69 }
70 70
71 QString knob_path = ":/icons/fader_knob.png"; 71 QString knob_path = ":/icons/fader_knob.png";
72 ok = m_knob.load(knob_path); 72 ok = m_knob.load(knob_path);
73 if (ok == false) { 73 if (ok == false) {
74 cerr << "Error loading pixmap" << endl; 74 cerr << "Error loading pixmap" << endl;
75 } 75 }
76 76
77 QString clip_path = ":/icons/fader_knob_red.png"; 77 QString clip_path = ":/icons/fader_knob_red.png";
78 ok = m_clip.load(clip_path); 78 ok = m_clip.load(clip_path);
79 if (ok == false) { 79 if (ok == false) {
80 cerr << "Error loading pixmap" << endl; 80 cerr << "Error loading pixmap" << endl;
81 } 81 }
82 } 82 }
83 83
84 Fader::~Fader() 84 Fader::~Fader()
85 { 85 {
109 109
110 if (vx > getMaxX()) vx = getMaxX(); 110 if (vx > getMaxX()) vx = getMaxX();
111 if (vx < 0) vx = 0; 111 if (vx < 0) vx = 0;
112 112
113 float fval = (float)AudioLevel::fader_to_multiplier 113 float fval = (float)AudioLevel::fader_to_multiplier
114 (vx, getMaxX(), AudioLevel::LongFader); 114 (vx, getMaxX(), AudioLevel::LongFader);
115 115
116 setValue(fval); 116 setValue(fval);
117 emit valueChanged(fval); 117 emit valueChanged(fval);
118 ev->accept(); 118 ev->accept();
119 } 119 }
177 ev->accept(); 177 ev->accept();
178 178
179 //!!! needs improvement 179 //!!! needs improvement
180 180
181 if (ev->delta() > 0) { 181 if (ev->delta() > 0) {
182 setValue(m_value * 1.f); 182 setValue(m_value * 1.f);
183 } else { 183 } else {
184 setValue(m_value / 1.f); 184 setValue(m_value / 1.f);
185 } 185 }
186 186
187 update(); 187 update();
188 emit valueChanged(getValue()); 188 emit valueChanged(getValue());
189 } 189 }
204 Fader::setValue(float v) 204 Fader::setValue(float v)
205 { 205 {
206 float max = (float)AudioLevel::dB_to_multiplier(10.0); 206 float max = (float)AudioLevel::dB_to_multiplier(10.0);
207 207
208 if (v > max) { 208 if (v > max) {
209 v = max; 209 v = max;
210 } else if (v < 0.0) { 210 } else if (v < 0.0) {
211 v = 0.0; 211 v = 0.0;
212 } 212 }
213 213
214 if (m_value != v) { 214 if (m_value != v) {
215 m_value = v; 215 m_value = v;
216 float db = (float)AudioLevel::multiplier_to_dB(m_value); 216 float db = (float)AudioLevel::multiplier_to_dB(m_value);
217 QString text; 217 QString text;
218 if (db <= AudioLevel::DB_FLOOR) { 218 if (db <= AudioLevel::DB_FLOOR) {
219 text = tr("Level: Off"); 219 text = tr("Level: Off");
220 } else { 220 } else {
221 text = tr("Level: %1%2.%3%4 dB") 221 text = tr("Level: %1%2.%3%4 dB")
222 .arg(db < 0.0 ? "-" : "") 222 .arg(db < 0.0 ? "-" : "")
223 .arg(abs(int(db))) 223 .arg(abs(int(db)))
224 .arg(abs(int(db * 10.0) % 10)) 224 .arg(abs(int(db * 10.0) % 10))
225 .arg(abs(int(db * 100.0) % 10)); 225 .arg(abs(int(db * 100.0) % 10));
226 } 226 }
227 cerr << "Fader: setting tooltip to \"" << text << "\"" << endl; 227 cerr << "Fader: setting tooltip to \"" << text << "\"" << endl;
228 QWidget::setToolTip(text); 228 QWidget::setToolTip(text);
229 update(); 229 update();
230 } 230 }
231 } 231 }
232 232
233 233
234 float 234 float
241 241
242 void 242 void
243 Fader::setPeakLeft(float peak) 243 Fader::setPeakLeft(float peak)
244 { 244 {
245 if (this->m_peakLeft != peak) { 245 if (this->m_peakLeft != peak) {
246 this->m_peakLeft = peak; 246 this->m_peakLeft = peak;
247 update(); 247 update();
248 } 248 }
249 } 249 }
250 250
251 251
252 void 252 void
253 Fader::setPeakRight(float peak) 253 Fader::setPeakRight(float peak)
254 { 254 {
255 if (this->m_peakRight != peak) { 255 if (this->m_peakRight != peak) {
256 this->m_peakRight = peak; 256 this->m_peakRight = peak;
257 update(); 257 update();
258 } 258 }
259 } 259 }
260 260
261 261
262 void 262 void
266 266
267 // background 267 // background
268 painter.drawPixmap(rect(), m_back, QRect(0, 0, 116, 23)); 268 painter.drawPixmap(rect(), m_back, QRect(0, 0, 116, 23));
269 269
270 int offset_L = AudioLevel::multiplier_to_fader(m_peakLeft, 116, 270 int offset_L = AudioLevel::multiplier_to_fader(m_peakLeft, 116,
271 AudioLevel::IEC268LongMeter); 271 AudioLevel::IEC268LongMeter);
272 272
273 painter.drawPixmap(QRect(0, 0, offset_L, 11), m_leds, 273 painter.drawPixmap(QRect(0, 0, offset_L, 11), m_leds,
274 QRect(0, 0, offset_L, 11)); 274 QRect(0, 0, offset_L, 11));
275 275
276 int offset_R = AudioLevel::multiplier_to_fader(m_peakRight, 116, 276 int offset_R = AudioLevel::multiplier_to_fader(m_peakRight, 116,
277 AudioLevel::IEC268LongMeter); 277 AudioLevel::IEC268LongMeter);
278 278
279 painter.drawPixmap(QRect(0, 11, offset_R, 11), m_leds, 279 painter.drawPixmap(QRect(0, 11, offset_R, 11), m_leds,
280 QRect(0, 11, offset_R, 11)); 280 QRect(0, 11, offset_R, 11));
281 281
282 if (m_withoutKnob == false) { 282 if (m_withoutKnob == false) {
283 283
284 static const uint knob_width = 29; 284 static const uint knob_width = 29;
285 static const uint knob_height = 9; 285 static const uint knob_height = 9;
286 286
287 int x = AudioLevel::multiplier_to_fader(m_value, 116 - knob_width, 287 int x = AudioLevel::multiplier_to_fader(m_value, 116 - knob_width,
288 AudioLevel::LongFader); 288 AudioLevel::LongFader);
289 289
290 bool clipping = (m_peakLeft > 1.0 || m_peakRight > 1.0); 290 bool clipping = (m_peakLeft > 1.0 || m_peakRight > 1.0);
291 291
292 painter.drawPixmap(QRect(x, 7, knob_width, knob_height), 292 painter.drawPixmap(QRect(x, 7, knob_width, knob_height),
293 clipping ? m_clip : m_knob, 293 clipping ? m_clip : m_knob,
294 QRect(0, 0, knob_width, knob_height)); 294 QRect(0, 0, knob_width, knob_height));
295 } 295 }
296 } 296 }
297 297
298 int 298 int
299 Fader::getMaxX() const 299 Fader::getMaxX() const