15 LRAMeter::LRAMeter(QWidget *parent)
20 void LRAMeter::resizeEvent(QResizeEvent *event)
22 recalculate_pixmaps();
25 void LRAMeter::paintEvent(QPaintEvent *event)
27 QPainter painter(this);
31 float range_high_lufs;
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;
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()));
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);
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);
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()));
58 // FIXME: This outlining isn't so pretty.
63 painter.drawRect(2, min_y, width() - 5, max_y - min_y);
67 if (level_lu >= -1.0f && level_lu <= 1.0f) {
68 pen.setColor(Qt::green);
70 pen.setColor(Qt::red);
74 painter.drawRect(2, min_y, width() - 5, max_y - min_y);
77 // Draw the integrated loudness meter, in the same color as the target area.
78 int y = lrint(lufs_to_pos(level_lu, height()));
83 painter.drawRect(2, y, width() - 5, 1);
87 if (level_lu >= -1.0f && level_lu <= 1.0f) {
88 pen.setColor(Qt::green);
90 pen.setColor(Qt::red);
94 painter.drawRect(2, y, width() - 5, 1);
98 void LRAMeter::recalculate_pixmaps()
100 const int margin = 5;
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);
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);