]> git.sesse.net Git - nageru/commitdiff
Move the audio level logic into MainWindow, where it has a much better home than...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 29 Oct 2015 20:44:39 +0000 (21:44 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 29 Oct 2015 20:44:39 +0000 (21:44 +0100)
glwidget.cpp
mainwindow.cpp
mainwindow.h
vumeter.h

index 075106aa695b2d582aab561a1faba58ff5b36247..3cd63585633d8bb314376d6600f1de435f82d6b3 100644 (file)
@@ -48,13 +48,7 @@ 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_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_mainwindow->mixer_created(global_mixer);
                global_mixer->start();
        });
        global_mixer->set_frame_ready_callback(output, [this]{
index afc2194469fdf3cb21ba133403304817b2462df3..4dc06084a0e93bd51ef8e065607affd347bb6ffd 100644 (file)
@@ -16,9 +16,12 @@ using namespace std;
 
 Q_DECLARE_METATYPE(std::vector<std::string>);
 
+MainWindow *global_mainwindow = nullptr;
+
 MainWindow::MainWindow()
        : ui(new Ui::MainWindow)
 {
+       global_mainwindow = this;
        ui->setupUi(this);
 
        ui->me_live->set_output(Mixer::OUTPUT_LIVE);
@@ -78,10 +81,6 @@ MainWindow::MainWindow()
        qRegisterMetaType<std::vector<std::string>>("std::vector<std::string>");
        connect(ui->preview1, SIGNAL(transition_names_updated(std::vector<std::string>)),
                this, SLOT(set_transition_names(std::vector<std::string>)));
-
-       // 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)
@@ -93,6 +92,17 @@ void MainWindow::resizeEvent(QResizeEvent* event)
        QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
 }
 
+void MainWindow::mixer_created(Mixer *mixer)
+{
+       mixer->set_audio_level_callback([this](float level_lufs, float peak_db){
+               ui->vu_meter->set_level(level_lufs);
+
+               char buf[256];
+               snprintf(buf, sizeof(buf), "%.1f", peak_db);
+               ui->peak_display->setText(buf);
+       });
+}
+
 void MainWindow::relayout()
 {
        int width = size().width();
index b0e26897b2dbbf937828d785a21d57370a84f982..6f2666869443a433a9ce658b1d95e607e312c1a7 100644 (file)
@@ -9,6 +9,7 @@ namespace Ui {
 class MainWindow;
 }  // namespace Ui
 
+class Mixer;
 class QPushButton;
 
 class MainWindow : public QMainWindow
@@ -17,7 +18,8 @@ class MainWindow : public QMainWindow
 
 public:
        MainWindow();
-       void resizeEvent(QResizeEvent* event) override;
+       void resizeEvent(QResizeEvent *event) override;
+       void mixer_created(Mixer *mixer);
 
 public slots:
        void transition_clicked(int transition_number);
@@ -30,4 +32,6 @@ private:
        QPushButton *transition_btn1, *transition_btn2, *transition_btn3;
 };
 
+extern MainWindow *global_mainwindow;
+
 #endif
index 61fbf23a5995ddf505a3320ade5b8282e04aabbc..3492f770c69e9e61390a85e1b96cb58cebf073b1 100644 (file)
--- a/vumeter.h
+++ b/vumeter.h
@@ -27,7 +27,4 @@ private:
        float level_lufs = -HUGE_VAL;
 };
 
-extern VUMeter *global_vu_meter;
-extern QLabel *global_peak_display;
-
 #endif