]> git.sesse.net Git - nageru/blob - nageru/lrameter.cpp
Fix some leftovers in warning messages.
[nageru] / nageru / lrameter.cpp
1 #include "lrameter.h"
2
3 #include <QPainter>
4 #include <QPalette>
5 #include <QPen>
6 #include <QRect>
7
8 #include "vu_common.h"
9
10 class QPaintEvent;
11 class QResizeEvent;
12
13 using namespace std;
14
15 LRAMeter::LRAMeter(QWidget *parent)
16         : QWidget(parent)
17 {
18 }
19
20 void LRAMeter::resizeEvent(QResizeEvent *event)
21 {
22         recalculate_pixmaps();
23 }
24
25 void LRAMeter::paintEvent(QPaintEvent *event)
26 {
27         QPainter painter(this);
28
29         float level_lufs;
30         float range_low_lufs;
31         float range_high_lufs;
32         {
33                 lock_guard<mutex> lock(level_mutex);
34                 level_lufs = this->level_lufs;
35                 range_low_lufs = this->range_low_lufs;
36                 range_high_lufs = this->range_high_lufs;
37         }
38
39         float level_lu = level_lufs - ref_level_lufs;
40         float range_low_lu = range_low_lufs - ref_level_lufs;
41         float range_high_lu = range_high_lufs - ref_level_lufs;
42         int range_low_pos = lrint(lufs_to_pos(range_low_lu, height()));
43         int range_high_pos = lrint(lufs_to_pos(range_high_lu, height()));
44
45         QRect top_off_rect(0, 0, width(), range_high_pos);
46         QRect on_rect(0, range_high_pos, width(), range_low_pos - range_high_pos);
47         QRect bottom_off_rect(0, range_low_pos, width(), height() - range_low_pos);
48
49         painter.drawPixmap(top_off_rect, off_pixmap, top_off_rect);
50         painter.drawPixmap(on_rect, on_pixmap, on_rect);
51         painter.drawPixmap(bottom_off_rect, off_pixmap, bottom_off_rect);
52
53         // Draw the target area (+/-1 LU is allowed EBU range).
54         // It turns green when we're within.
55         int min_y = lrint(lufs_to_pos(1.0f, height()));
56         int max_y = lrint(lufs_to_pos(-1.0f, height()));
57
58         // FIXME: This outlining isn't so pretty.
59         {
60                 QPen pen(Qt::black);
61                 pen.setWidth(5);
62                 painter.setPen(pen);
63                 painter.drawRect(2, min_y, width() - 5, max_y - min_y);
64         }
65         {
66                 QPen pen;
67                 if (level_lu >= -1.0f && level_lu <= 1.0f) {
68                         pen.setColor(Qt::green);
69                 } else {
70                         pen.setColor(Qt::red);
71                 }
72                 pen.setWidth(3);
73                 painter.setPen(pen);
74                 painter.drawRect(2, min_y, width() - 5, max_y - min_y);
75         }
76
77         // Draw the integrated loudness meter, in the same color as the target area.
78         int y = lrint(lufs_to_pos(level_lu, height()));
79         {
80                 QPen pen(Qt::black);
81                 pen.setWidth(5);
82                 painter.setPen(pen);
83                 painter.drawRect(2, y, width() - 5, 1);
84         }
85         {
86                 QPen pen;
87                 if (level_lu >= -1.0f && level_lu <= 1.0f) {
88                         pen.setColor(Qt::green);
89                 } else {
90                         pen.setColor(Qt::red);
91                 }
92                 pen.setWidth(3);
93                 painter.setPen(pen);
94                 painter.drawRect(2, y, width() - 5, 1);
95         }
96 }
97
98 void LRAMeter::recalculate_pixmaps()
99 {
100         const int margin = 5;
101
102         on_pixmap = QPixmap(width(), height());
103         QPainter on_painter(&on_pixmap);
104         on_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
105         draw_vu_meter(on_painter, width(), height(), margin, 2.0, true, min_level, max_level, /*flip=*/false);
106
107         off_pixmap = QPixmap(width(), height());
108         QPainter off_painter(&off_pixmap);
109         off_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
110         draw_vu_meter(off_painter, width(), height(), margin, 2.0, false, min_level, max_level, /*flip=*/false);
111 }