From 8d0d68b7cca3a4c58268fa0822ca38bb1863dd19 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 29 Oct 2015 21:02:39 +0100 Subject: [PATCH] Add a peak display. --- glwidget.cpp | 8 ++++++-- mainwindow.cpp | 4 +++- mixer.h | 2 +- ui_mainwindow.ui | 36 +++++++++++++++++++++++++++++------- vumeter.cpp | 1 + vumeter.h | 2 ++ 6 files changed, 42 insertions(+), 11 deletions(-) diff --git a/glwidget.cpp b/glwidget.cpp index 2118ffe..075106a 100644 --- a/glwidget.cpp +++ b/glwidget.cpp @@ -48,8 +48,12 @@ void GLWidget::initializeGL() static std::once_flag flag; std::call_once(flag, [this]{ global_mixer = new Mixer(QGLFormat::toSurfaceFormat(format())); - global_mixer->set_audio_level_callback([this](float level){ - global_vu_meter->set_level(level); + global_mixer->set_audio_level_callback([this](float level_lufs, float peak_db){ + global_vu_meter->set_level(level_lufs); + + char buf[256]; + snprintf(buf, sizeof(buf), "%.1f", peak_db); + global_peak_display->setText(buf); }); global_mixer->start(); }); diff --git a/mainwindow.cpp b/mainwindow.cpp index 29a863b..0fc17b5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -80,7 +80,9 @@ MainWindow::MainWindow() connect(ui->preview1, SIGNAL(transition_names_updated(std::vector)), this, SLOT(set_transition_names(std::vector))); - global_vu_meter = ui->vu_meter; // global_mixer does not exist yet, so need to delay the hookup. + // global_mixer does not exist yet, so need to delay the actual hookups. + global_vu_meter = ui->vu_meter; + global_peak_display = ui->peak_display; } void MainWindow::resizeEvent(QResizeEvent* event) diff --git a/mixer.h b/mixer.h index 5b82b4e..7a0bfa3 100644 --- a/mixer.h +++ b/mixer.h @@ -81,7 +81,7 @@ public: output_channel[output].set_frame_ready_callback(callback); } - typedef std::function audio_level_callback_t; + typedef std::function audio_level_callback_t; void set_audio_level_callback(audio_level_callback_t callback) { audio_level_callback = callback; diff --git a/ui_mainwindow.ui b/ui_mainwindow.ui index c4a1d7c..3f0a211 100644 --- a/ui_mainwindow.ui +++ b/ui_mainwindow.ui @@ -138,14 +138,36 @@ - - - - 20 - 0 - + + + 0 - + + + + + 0 + 1 + + + + + 20 + 0 + + + peak_display + peak_display + + + + + + -0.0 + + + + diff --git a/vumeter.cpp b/vumeter.cpp index 27ffc5a..e56268a 100644 --- a/vumeter.cpp +++ b/vumeter.cpp @@ -19,6 +19,7 @@ int lufs_to_pos(float level_lu, int height) } // namespace VUMeter *global_vu_meter = nullptr; +QLabel *global_peak_display = nullptr; VUMeter::VUMeter(QWidget *parent) : QWidget(parent) diff --git a/vumeter.h b/vumeter.h index f9be292..61fbf23 100644 --- a/vumeter.h +++ b/vumeter.h @@ -2,6 +2,7 @@ #define VUMETER_H #include +#include #include #include @@ -27,5 +28,6 @@ private: }; extern VUMeter *global_vu_meter; +extern QLabel *global_peak_display; #endif -- 2.39.2