]> git.sesse.net Git - nageru/blobdiff - vumeter.cpp
Release Nageru 1.7.2.
[nageru] / vumeter.cpp
index 50f0f143f7e575d03f8e0810130cad28da010424..b697a834da3876533c06db888c16a42e8f209067 100644 (file)
@@ -1,8 +1,12 @@
-#include <QPainter>
-
 #include "vumeter.h"
+
+#include <QPainter>
+#include <QRect>
 #include "vu_common.h"
 
+class QPaintEvent;
+class QResizeEvent;
+
 using namespace std;
 
 VUMeter::VUMeter(QWidget *parent)
@@ -19,11 +23,13 @@ void VUMeter::paintEvent(QPaintEvent *event)
 {
        QPainter painter(this);
 
-       float level_lufs[2];
+       float level_lufs[2], peak_lufs[2];
        {
                unique_lock<mutex> lock(level_mutex);
                level_lufs[0] = this->level_lufs[0];
                level_lufs[1] = this->level_lufs[1];
+               peak_lufs[0] = this->peak_lufs[0];
+               peak_lufs[1] = this->peak_lufs[1];
        }
 
        int mid = width() / 2;
@@ -34,29 +40,37 @@ void VUMeter::paintEvent(QPaintEvent *event)
                float level_lu = level_lufs[channel] - ref_level_lufs;
                int on_pos = lrint(lufs_to_pos(level_lu, height()));
 
-               if (flip) {
-                       QRect on_rect(left, 0, right, height() - on_pos);
-                       QRect off_rect(left, height() - on_pos, right, height());
+               QRect off_rect(left, 0, right - left, on_pos);
+               QRect on_rect(left, on_pos, right - left, height() - on_pos);
 
-                       painter.drawPixmap(on_rect, on_pixmap, on_rect);
-                       painter.drawPixmap(off_rect, off_pixmap, off_rect);
-               } else {
-                       QRect off_rect(left, 0, right, on_pos);
-                       QRect on_rect(left, on_pos, right, height() - on_pos);
+               painter.drawPixmap(off_rect, off_pixmap, off_rect);
+               painter.drawPixmap(on_rect, on_pixmap, on_rect);
 
-                       painter.drawPixmap(off_rect, off_pixmap, off_rect);
-                       painter.drawPixmap(on_rect, on_pixmap, on_rect);
+               float peak_lu = peak_lufs[channel] - ref_level_lufs;
+               if (peak_lu >= min_level && peak_lu <= max_level) {
+                       int peak_pos = lrint(lufs_to_pos(peak_lu, height()));
+                       QRect peak_rect(left, peak_pos - 1, right, 2);
+                       painter.drawPixmap(peak_rect, full_on_pixmap, peak_rect);
                }
        }
 }
 
 void VUMeter::recalculate_pixmaps()
 {
+       full_on_pixmap = QPixmap(width(), height());
+       QPainter full_on_painter(&full_on_pixmap);
+       full_on_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
+       draw_vu_meter(full_on_painter, width(), height(), 0, 0.0, true, min_level, max_level, /*flip=*/false);
+
+       float margin = 0.5 * (width() - 20);
+
        on_pixmap = QPixmap(width(), height());
        QPainter on_painter(&on_pixmap);
-       draw_vu_meter(on_painter, width(), height(), 0, true, min_level, max_level, flip);
+       on_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
+       draw_vu_meter(on_painter, width(), height(), margin, 2.0, true, min_level, max_level, /*flip=*/false);
 
        off_pixmap = QPixmap(width(), height());
        QPainter off_painter(&off_pixmap);
-       draw_vu_meter(off_painter, width(), height(), 0, false, min_level, max_level, flip);
+       off_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
+       draw_vu_meter(off_painter, width(), height(), margin, 2.0, false, min_level, max_level, /*flip=*/false);
 }