From 54bf3bae3d72dfce0f0517e1c82926ef22aad028 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 29 Oct 2015 20:50:22 +0100 Subject: [PATCH] Show the +/-1 dB target range. --- ui_mainwindow.ui | 2 +- vumeter.cpp | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ui_mainwindow.ui b/ui_mainwindow.ui index 12e3864..c4a1d7c 100644 --- a/ui_mainwindow.ui +++ b/ui_mainwindow.ui @@ -141,7 +141,7 @@ - 30 + 20 0 diff --git a/vumeter.cpp b/vumeter.cpp index ab649bc..27ffc5a 100644 --- a/vumeter.cpp +++ b/vumeter.cpp @@ -4,6 +4,20 @@ using namespace std; +namespace { + +int lufs_to_pos(float level_lu, int height) +{ + const float min_level = 18.0f; // y=0 is top of screen, so “min” is the loudest level. + const float max_level = -36.0f; + int y = lrintf(height * (level_lu - min_level) / (max_level - min_level)); + y = std::max(y, 0); + y = std::min(y, height - 1); + return y; +} + +} // namespace + VUMeter *global_vu_meter = nullptr; VUMeter::VUMeter(QWidget *parent) @@ -17,6 +31,10 @@ void VUMeter::paintEvent(QPaintEvent *event) painter.fillRect(0, 0, width(), height(), Qt::black); + int min_y = lufs_to_pos(1.0f, height()); + int max_y = lufs_to_pos(-1.0f, height()); + painter.fillRect(0, min_y, width(), max_y - min_y, Qt::green); + float level_lufs; { unique_lock lock(level_mutex); @@ -24,11 +42,7 @@ void VUMeter::paintEvent(QPaintEvent *event) } float level_lu = level_lufs + 23.0f; - const float min_level = 18.0f; // y=0 is top of screen, so “min” is the loudest level. - const float max_level = -36.0f; - int y = lrintf(height() * (level_lu - min_level) / (max_level - min_level)); - if (y >= 0 && y < height()) { - painter.setPen(Qt::white); - painter.drawLine(0, y, width(), y); - } + int y = lufs_to_pos(level_lu, height()); + painter.setPen(Qt::white); + painter.drawLine(0, y, width(), y); } -- 2.39.2