]> git.sesse.net Git - nageru/commitdiff
Show the +/-1 dB target range.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 29 Oct 2015 19:50:22 +0000 (20:50 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 29 Oct 2015 19:50:22 +0000 (20:50 +0100)
ui_mainwindow.ui
vumeter.cpp

index 12e386485147b6ef985a3dbafbfca6c4d23d1e3f..c4a1d7c9c0dfc868997f941ef8c8e6c2ace9d6fb 100644 (file)
          <widget class="VUMeter" name="vu_meter" native="true">
           <property name="minimumSize">
            <size>
-            <width>30</width>
+            <width>20</width>
             <height>0</height>
            </size>
           </property>
index ab649bc792af8c74e3657f9986006125471d6f0c..27ffc5ae5a6b0c86eb14f0f218b7baa59552c1b0 100644 (file)
@@ -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<mutex> 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);
 }