From fdd77c1f8a51f1e87151b876c2c5ab536a2fb02d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 31 Oct 2015 13:01:14 +0100 Subject: [PATCH] Rework the LRA and VU meters into something much more like LRA and VU meters. --- lrameter.cpp | 29 ++++++++++++++++++++++++++++- vu_common.cpp | 17 ++++++++--------- vu_common.h | 2 +- vumeter.cpp | 18 +----------------- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/lrameter.cpp b/lrameter.cpp index 7f7aaf1..cd87a6c 100644 --- a/lrameter.cpp +++ b/lrameter.cpp @@ -17,16 +17,23 @@ void LRAMeter::paintEvent(QPaintEvent *event) painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window()); float level_lufs; + float range_low_lufs; + float range_high_lufs; { unique_lock lock(level_mutex); level_lufs = this->level_lufs; + range_low_lufs = this->range_low_lufs; + range_high_lufs = this->range_high_lufs; } float level_lu = level_lufs + 23.0f; + float range_low_lu = range_low_lufs + 23.0f; + float range_high_lu = range_high_lufs + 23.0f; const int margin = 5; - draw_vu_meter(painter, level_lu, width(), height(), margin); + draw_vu_meter(painter, range_low_lu, range_high_lu, width(), height(), margin); // Draw the target area (+/-1 LU is allowed EBU range). + // It turns green when we're within. int min_y = lufs_to_pos(1.0f, height()); int max_y = lufs_to_pos(-1.0f, height()); @@ -48,4 +55,24 @@ void LRAMeter::paintEvent(QPaintEvent *event) painter.setPen(pen); painter.drawRect(2, min_y, width() - 5, max_y - min_y); } + + // Draw the integrated loudness meter, in the same color as the target area. + int y = lufs_to_pos(level_lu, height()); + { + QPen pen(Qt::black); + pen.setWidth(5); + painter.setPen(pen); + painter.drawRect(2, y, width() - 5, 1); + } + { + QPen pen; + if (level_lu >= -1.0f && level_lu <= 1.0f) { + pen.setColor(Qt::green); + } else { + pen.setColor(Qt::red); + } + pen.setWidth(3); + painter.setPen(pen); + painter.drawRect(2, y, width() - 5, 1); + } } diff --git a/vu_common.cpp b/vu_common.cpp index 9a6a35a..9fc3553 100644 --- a/vu_common.cpp +++ b/vu_common.cpp @@ -20,7 +20,7 @@ int lufs_to_pos(float level_lu, int height) return y; } -void draw_vu_meter(QPainter &painter, float level_lu, int width, int height, int margin) +void draw_vu_meter(QPainter &painter, float range_low_lu, float range_high_lu, int width, int height, int margin) { painter.fillRect(margin, 0, width - 2 * margin, height, Qt::black); @@ -31,20 +31,19 @@ void draw_vu_meter(QPainter &painter, float level_lu, int width, int height, int on.setColorAt(1.0f, QColor(0, 255, 0)); QColor off(80, 80, 80); - int y = lufs_to_pos(level_lu, height); + int min_on_y = lufs_to_pos(range_high_lu, height); + int max_on_y = lufs_to_pos(range_low_lu, height); // Draw bars colored up until the level, then gray from there. for (int level = -18; level < 9; ++level) { int min_y = lufs_to_pos(level + 1.0f, height) + 1; int max_y = lufs_to_pos(level, height) - 1; - if (y > max_y) { - painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, off); - } else if (y < min_y) { - painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, on); - } else { - painter.fillRect(margin, min_y, width - 2 * margin, y - min_y, off); - painter.fillRect(margin, y, width - 2 * margin, max_y - y, on); + painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, off); + int min_draw_y = std::max(min_y, min_on_y); + int max_draw_y = std::min(max_y, max_on_y); + if (min_draw_y < max_draw_y) { + painter.fillRect(margin, min_draw_y, width - 2 * margin, max_draw_y - min_draw_y, on); } } } diff --git a/vu_common.h b/vu_common.h index 4a50552..06a971f 100644 --- a/vu_common.h +++ b/vu_common.h @@ -4,6 +4,6 @@ #include int lufs_to_pos(float level_lu, int height); -void draw_vu_meter(QPainter &painter, float level_lu, int width, int height, int margin); +void draw_vu_meter(QPainter &painter, float range_low_lu, float range_high_lu, int width, int height, int margin); #endif // !defined(_VU_COMMON_H) diff --git a/vumeter.cpp b/vumeter.cpp index da93c1e..ab40fce 100644 --- a/vumeter.cpp +++ b/vumeter.cpp @@ -14,21 +14,6 @@ void VUMeter::paintEvent(QPaintEvent *event) { QPainter painter(this); - painter.fillRect(0, 0, width(), height(), Qt::black); - - // Draw some reference bars. - for (int level = -18; level < 9; ++level) { - int min_y = lufs_to_pos(level, height()) - 1; - int max_y = lufs_to_pos(level + 1.0f, height()) + 1; - - // Recommended range is 0 LU +/- 1 LU. - if (level == -1 || level == 0) { - painter.fillRect(1, min_y, width() - 2, max_y - min_y, Qt::green); - } else { - painter.fillRect(1, min_y, width() - 2, max_y - min_y, QColor(80, 80, 80)); - } - } - float level_lufs; { unique_lock lock(level_mutex); @@ -36,6 +21,5 @@ void VUMeter::paintEvent(QPaintEvent *event) } float level_lu = level_lufs + 23.0f; - int y = lufs_to_pos(level_lu, height()); - painter.fillRect(0, y, width(), 2, Qt::white); + draw_vu_meter(painter, -HUGE_VAL, level_lu, width(), height(), 0); } -- 2.39.2