1 #include "peak_display.h"
11 #include "audio_clip.h"
15 PeakDisplay::PeakDisplay(QWidget *parent)
20 void PeakDisplay::audio_clip_updated()
22 QMetaObject::invokeMethod(this, "repaint", Qt::QueuedConnection);
25 void PeakDisplay::paintEvent(QPaintEvent *event)
28 unique_ptr<pair<float, float>[]> min_max = audio_clip->get_min_max_peaks(w);
30 QPainter painter(this);
31 painter.fillRect(event->rect(), Qt::white);
32 painter.setClipRect(event->rect());
33 double mid_y = double(height()) * 0.5;
34 double scale_y = height() * 0.5;
35 for (int x = 0; x < w; ++x) {
36 if (isnan(min_max[x].first)) continue;
38 int y_min = lrint(min_max[x].first * scale_y + mid_y);
39 int y_max = lrint(min_max[x].second * scale_y + mid_y);
40 painter.drawLine(x, y_min, x, y_max);