| 379 | } |
| 380 | |
| 381 | void Fader::paintDBFSLevels(QPaintEvent * ev, QPainter & painter) |
| 382 | { |
| 383 | int height = m_back->height(); |
| 384 | int width = m_back->width() / 2; |
| 385 | int center = m_back->width() - width; |
| 386 | |
| 387 | float const maxDB(ampToDbfs(m_fMaxPeak)); |
| 388 | float const minDB(ampToDbfs(m_fMinPeak)); |
| 389 | |
| 390 | // We will need to divide by the span between min and max several times. It's more |
| 391 | // efficient to calculate the reciprocal once and then to multiply. |
| 392 | float const fullSpanReciprocal = 1 / (maxDB - minDB); |
| 393 | |
| 394 | |
| 395 | // Draw left levels |
| 396 | float const leftSpan = ampToDbfs(qMax<float>(0.0001, m_fPeakValue_L)) - minDB; |
| 397 | int peak_L = height * leftSpan * fullSpanReciprocal; |
| 398 | QRect drawRectL( 0, height - peak_L, width, peak_L ); // Source and target are identical |
| 399 | painter.drawPixmap( drawRectL, *m_leds, drawRectL ); |
| 400 | |
| 401 | float const persistentLeftPeakDBFS = ampToDbfs(qMax<float>(0.0001, m_persistentPeak_L)); |
| 402 | int persistentPeak_L = height * (1 - (persistentLeftPeakDBFS - minDB) * fullSpanReciprocal); |
| 403 | // the LED's have a 4px padding and we don't want the peaks |
| 404 | // to draw on the fader background |
| 405 | if( persistentPeak_L <= 4 ) |
| 406 | { |
| 407 | persistentPeak_L = 4; |
| 408 | } |
| 409 | if( persistentLeftPeakDBFS > minDB ) |
| 410 | { |
| 411 | QColor const & peakColor = clips(m_persistentPeak_L) ? peakRed() : |
| 412 | persistentLeftPeakDBFS >= -6 ? peakYellow() : peakGreen(); |
| 413 | painter.fillRect( QRect( 2, persistentPeak_L, 7, 1 ), peakColor ); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | // Draw right levels |
| 418 | float const rightSpan = ampToDbfs(qMax<float>(0.0001, m_fPeakValue_R)) - minDB; |
| 419 | int peak_R = height * rightSpan * fullSpanReciprocal; |
| 420 | QRect const drawRectR( center, height - peak_R, width, peak_R ); // Source and target are identical |
| 421 | painter.drawPixmap( drawRectR, *m_leds, drawRectR ); |
| 422 | |
| 423 | float const persistentRightPeakDBFS = ampToDbfs(qMax<float>(0.0001, m_persistentPeak_R)); |
| 424 | int persistentPeak_R = height * (1 - (persistentRightPeakDBFS - minDB) * fullSpanReciprocal); |
| 425 | // the LED's have a 4px padding and we don't want the peaks |
| 426 | // to draw on the fader background |
| 427 | if( persistentPeak_R <= 4 ) |
| 428 | { |
| 429 | persistentPeak_R = 4; |
| 430 | } |
| 431 | if( persistentRightPeakDBFS > minDB ) |
| 432 | { |
| 433 | QColor const & peakColor = clips(m_persistentPeak_R) ? peakRed() : |
| 434 | persistentRightPeakDBFS >= -6 ? peakYellow() : peakGreen(); |
| 435 | painter.fillRect( QRect( 14, persistentPeak_R, 7, 1 ), peakColor ); |
| 436 | } |
| 437 | } |
| 438 | |