12 VUMeter::VUMeter(QWidget *parent)
17 void VUMeter::resizeEvent(QResizeEvent *event)
19 recalculate_pixmaps();
22 void VUMeter::paintEvent(QPaintEvent *event)
24 QPainter painter(this);
26 float level_lufs[2], peak_lufs[2];
28 lock_guard<mutex> lock(level_mutex);
29 level_lufs[0] = this->level_lufs[0];
30 level_lufs[1] = this->level_lufs[1];
31 peak_lufs[0] = this->peak_lufs[0];
32 peak_lufs[1] = this->peak_lufs[1];
35 int mid = width() / 2;
37 for (unsigned channel = 0; channel < 2; ++channel) {
38 int left = (channel == 0) ? 0 : mid;
39 int right = (channel == 0) ? mid : width();
40 float level_lu = level_lufs[channel] - ref_level_lufs;
41 int on_pos = lrint(lufs_to_pos(level_lu, height()));
43 QRect off_rect(left, 0, right - left, on_pos);
44 QRect on_rect(left, on_pos, right - left, height() - on_pos);
46 painter.drawPixmap(off_rect, off_pixmap, off_rect);
47 painter.drawPixmap(on_rect, on_pixmap, on_rect);
49 float peak_lu = peak_lufs[channel] - ref_level_lufs;
50 if (peak_lu >= min_level && peak_lu <= max_level) {
51 int peak_pos = lrint(lufs_to_pos(peak_lu, height()));
52 QRect peak_rect(left, peak_pos - 1, right, 2);
53 painter.drawPixmap(peak_rect, full_on_pixmap, peak_rect);
58 void VUMeter::recalculate_pixmaps()
60 full_on_pixmap = QPixmap(width(), height());
61 QPainter full_on_painter(&full_on_pixmap);
62 full_on_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
63 draw_vu_meter(full_on_painter, width(), height(), 0, 0.0, true, min_level, max_level, /*flip=*/false);
65 float margin = 0.5 * (width() - 20);
67 on_pixmap = QPixmap(width(), height());
68 QPainter on_painter(&on_pixmap);
69 on_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
70 draw_vu_meter(on_painter, width(), height(), margin, 2.0, true, min_level, max_level, /*flip=*/false);
72 off_pixmap = QPixmap(width(), height());
73 QPainter off_painter(&off_pixmap);
74 off_painter.fillRect(0, 0, width(), height(), parentWidget()->palette().window());
75 draw_vu_meter(off_painter, width(), height(), margin, 2.0, false, min_level, max_level, /*flip=*/false);