]> git.sesse.net Git - nageru/blobdiff - vu_common.cpp
Fix another uninitialized sound data issue.
[nageru] / vu_common.cpp
index 9a6a35a85749eea5f1c0aa0c901d611d13c2c488..7b14f2f196a8683b29fb00f07e7f758c533e2dff 100644 (file)
@@ -1,7 +1,12 @@
 #include "vu_common.h"
+
 #include <math.h>
 #include <algorithm>
 
+#include <QBrush>
+#include <QColor>
+#include <QPainter>
+
 using namespace std;
 
 int lufs_to_pos(float level_lu, int height)
@@ -20,7 +25,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 +36,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);
                }
        }
 }