]> git.sesse.net Git - nageru/commitdiff
Rework the LRA and VU meters into something much more like LRA and VU meters.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 31 Oct 2015 12:01:14 +0000 (13:01 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 31 Oct 2015 12:01:14 +0000 (13:01 +0100)
lrameter.cpp
vu_common.cpp
vu_common.h
vumeter.cpp

index 7f7aaf1cd672de81a60920b427c68fe7726b9c1f..cd87a6c0f14e2dd52d3b155d4d994b630db79473 100644 (file)
@@ -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<mutex> 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);
+       }
 }
index 9a6a35a85749eea5f1c0aa0c901d611d13c2c488..9fc3553eeb2fc907f21a1f7feea158b3c4236b20 100644 (file)
@@ -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);
                }
        }
 }
index 4a50552b9edb553fcd86189b3dd7ee58d06f52a5..06a971f409fb9f4e3ac3c1cbe4c66bf049ac0e04 100644 (file)
@@ -4,6 +4,6 @@
 #include <QPainter>
 
 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)
index da93c1e380732535c18ee38d038e2c9996184fe0..ab40fceff699ec13df3f3db1c86eefdbd73ed3bf 100644 (file)
@@ -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<mutex> 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);
 }