]> git.sesse.net Git - nageru/blobdiff - mainwindow.cpp
Add the GPU memory metrics to the Grafana dashboard.
[nageru] / mainwindow.cpp
index 6c1c790b41f30098b428b8e6be9af3aaa72b94a1..839f1b359e1a9060fdb64a8cfdd942b0f42c26ea 100644 (file)
@@ -129,7 +129,6 @@ void slave_fader(NonLinearFader *master, NonLinearFader *slave)
        });
 }
 
-constexpr unsigned DB_NO_FLAGS = 0x0;
 constexpr unsigned DB_WITH_SIGN = 0x1;
 constexpr unsigned DB_BARE = 0x2;
 
@@ -176,6 +175,21 @@ void set_peak_label(QLabel *peak_label, float peak_db)
        }
 }
 
+string get_bus_desc_label(const InputMapping::Bus &bus)
+{
+       string suffix;
+       if (bus.device.type == InputSourceType::ALSA_INPUT) {
+               ALSAPool::Device::State state = global_audio_mixer->get_alsa_card_state(bus.device.index);
+               if (state == ALSAPool::Device::State::STARTING) {
+                       suffix = " (busy)";
+               } else if (state == ALSAPool::Device::State::DEAD) {
+                       suffix = " (dead)";
+               }
+       }
+
+       return bus.name + suffix;
+}
+
 }  // namespace
 
 MainWindow::MainWindow()
@@ -322,8 +336,15 @@ void MainWindow::mixer_created(Mixer *mixer)
                connect(ui_display->display, &GLWidget::color_updated, this, &MainWindow::update_channel_color);
 
                // Hook up the keyboard key.
-               QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
-               connect(shortcut, &QShortcut::activated, bind(&MainWindow::channel_clicked, this, i));
+               QShortcut *shortcut = nullptr;
+               if (i < 9) {
+                       shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
+               } else if (i == 9) {
+                       shortcut = new QShortcut(QKeySequence(Qt::Key_0), this);
+               }
+               if (shortcut != nullptr) {
+                       connect(shortcut, &QShortcut::activated, bind(&MainWindow::channel_clicked, this, i));
+               }
 
                // Hook up the quick-cut key.
                if (i < strlen(qwerty)) {
@@ -370,13 +391,13 @@ void MainWindow::mixer_created(Mixer *mixer)
        });
        connect(ui->gainstaging_knob, &QAbstractSlider::valueChanged,
                bind(&MainWindow::gain_staging_knob_changed, this, simple_bus_index, _1));
-       connect(ui->gainstaging_auto_checkbox, &QCheckBox::stateChanged, [this, simple_bus_index](int state){
+       connect(ui->gainstaging_auto_checkbox, &QCheckBox::stateChanged, [this](int state){
                global_audio_mixer->set_gain_staging_auto(simple_bus_index, state == Qt::Checked);
                midi_mapper.refresh_lights();
        });
        connect(ui->compressor_threshold_knob, &QDial::valueChanged,
                bind(&MainWindow::compressor_threshold_knob_changed, this, simple_bus_index, _1));
-       connect(ui->compressor_enabled, &QCheckBox::stateChanged, [this, simple_bus_index](int state){
+       connect(ui->compressor_enabled, &QCheckBox::stateChanged, [this](int state){
                global_audio_mixer->set_compressor_enabled(simple_bus_index, state == Qt::Checked);
                midi_mapper.refresh_lights();
        });
@@ -414,6 +435,9 @@ void MainWindow::mixer_created(Mixer *mixer)
 
        analyzer.reset(new Analyzer);
 
+       global_mixer->set_theme_menu_callback(bind(&MainWindow::setup_theme_menu, this));
+       setup_theme_menu();
+
        struct sigaction act;
        memset(&act, 0, sizeof(act));
        act.sa_handler = schedule_cut_signal;
@@ -488,7 +512,7 @@ void MainWindow::setup_audio_miniview()
                Ui::AudioMiniView *ui_audio_miniview = new Ui::AudioMiniView;
                ui_audio_miniview->setupUi(channel);
                ui_audio_miniview->bus_desc_label->setFullText(
-                       QString::fromStdString(mapping.buses[bus_index].name));
+                       QString::fromStdString(get_bus_desc_label(mapping.buses[bus_index])));
                audio_miniviews[bus_index] = ui_audio_miniview;
 
                // Set up the peak meter.
@@ -531,7 +555,7 @@ void MainWindow::setup_audio_expanded_view()
                Ui::AudioExpandedView *ui_audio_expanded_view = new Ui::AudioExpandedView;
                ui_audio_expanded_view->setupUi(channel);
                ui_audio_expanded_view->bus_desc_label->setFullText(
-                       QString::fromStdString(mapping.buses[bus_index].name));
+                       QString::fromStdString(get_bus_desc_label(mapping.buses[bus_index])));
                audio_expanded_views[bus_index] = ui_audio_expanded_view;
                update_eq_label(bus_index, EQ_BAND_TREBLE, global_audio_mixer->get_eq(bus_index, EQ_BAND_TREBLE));
                update_eq_label(bus_index, EQ_BAND_MID, global_audio_mixer->get_eq(bus_index, EQ_BAND_MID));
@@ -808,6 +832,27 @@ void MainWindow::update_eq_label(unsigned bus_index, EQBand band, float gain_db)
        }
 }
 
+void MainWindow::setup_theme_menu()
+{
+       std::vector<Theme::MenuEntry> theme_menu_entries = global_mixer->get_theme_menu();
+
+       if (theme_menu != nullptr) {
+               ui->menuBar->removeAction(theme_menu->menuAction());
+               theme_menu = nullptr;
+       }
+
+       if (!theme_menu_entries.empty()) {
+               theme_menu = new QMenu("&Theme");
+               for (const Theme::MenuEntry &entry : theme_menu_entries) {
+                       QAction *action = theme_menu->addAction(QString::fromStdString(entry.text));
+                       connect(action, &QAction::triggered, [entry] {
+                               global_mixer->theme_menu_entry_clicked(entry.lua_ref);
+                       });
+               }
+               ui->menuBar->insertMenu(ui->menu_Help->menuAction(), theme_menu);
+       }
+}
+
 void MainWindow::limiter_threshold_knob_changed(int value)
 {
        float threshold_dbfs = value * 0.1f;
@@ -911,11 +956,13 @@ void MainWindow::audio_level_callback(float level_lufs, float peak_db, vector<Au
                set_peak_label(ui->peak_display, peak_db);
 
                // NOTE: Will be invisible when using multitrack audio.
-               ui->gainstaging_knob->blockSignals(true);
-               ui->gainstaging_knob->setValue(lrintf(bus_levels[0].gain_staging_db * 10.0f));
-               ui->gainstaging_knob->blockSignals(false);
-               ui->gainstaging_db_display->setText(
-                       QString::fromStdString(format_db(bus_levels[0].gain_staging_db, DB_WITH_SIGN)));
+               if (!bus_levels.empty()) {
+                       ui->gainstaging_knob->blockSignals(true);
+                       ui->gainstaging_knob->setValue(lrintf(bus_levels[0].gain_staging_db * 10.0f));
+                       ui->gainstaging_knob->blockSignals(false);
+                       ui->gainstaging_db_display->setText(
+                               QString::fromStdString(format_db(bus_levels[0].gain_staging_db, DB_WITH_SIGN)));
+               }
 
                ui->makeup_gain_knob->blockSignals(true);
                ui->makeup_gain_knob->setValue(lrintf(final_makeup_gain_db * 10.0f));
@@ -1423,7 +1470,9 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
                QApplication::restoreOverrideCursor();
                if (watched == previews[current_wb_pick_display]->display) {
                        const QMouseEvent *mouse_event = (QMouseEvent *)event;
-                       set_white_balance(current_wb_pick_display, mouse_event->x(), mouse_event->y());
+                       previews[current_wb_pick_display]->display->grab_white_balance(
+                               current_wb_pick_display,
+                               mouse_event->x(), mouse_event->y());
                } else {
                        // The user clicked on something else, give up.
                        // (The click goes through, which might not be ideal, but, yes.)
@@ -1449,34 +1498,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
        event->accept();
 }
 
-namespace {
-
-double srgb_to_linear(double x)
-{
-       if (x < 0.04045) {
-               return x / 12.92;
-       } else {
-               return pow((x + 0.055) / 1.055, 2.4);
-       }
-}
-
-}  // namespace
-
-void MainWindow::set_white_balance(int channel_number, int x, int y)
-{
-       // Set the white balance to neutral for the grab. It's probably going to
-       // flicker a bit, but hopefully this display is not live anyway.
-       global_mixer->set_wb(Mixer::OUTPUT_INPUT0 + channel_number, 0.5, 0.5, 0.5);
-       previews[channel_number]->display->updateGL();
-       QRgb reference_color = previews[channel_number]->display->grabFrameBuffer().pixel(x, y);
-
-       double r = srgb_to_linear(qRed(reference_color) / 255.0);
-       double g = srgb_to_linear(qGreen(reference_color) / 255.0);
-       double b = srgb_to_linear(qBlue(reference_color) / 255.0);
-       global_mixer->set_wb(Mixer::OUTPUT_INPUT0 + channel_number, r, g, b);
-       previews[channel_number]->display->updateGL();
-}
-
 void MainWindow::audio_state_changed()
 {
        post_to_main_thread([this]{
@@ -1485,21 +1506,11 @@ void MainWindow::audio_state_changed()
                }
                InputMapping mapping = global_audio_mixer->get_input_mapping();
                for (unsigned bus_index = 0; bus_index < mapping.buses.size(); ++bus_index) {
-                       const InputMapping::Bus &bus = mapping.buses[bus_index];
-                       string suffix;
-                       if (bus.device.type == InputSourceType::ALSA_INPUT) {
-                               ALSAPool::Device::State state = global_audio_mixer->get_alsa_card_state(bus.device.index);
-                               if (state == ALSAPool::Device::State::STARTING) {
-                                       suffix = " (busy)";
-                               } else if (state == ALSAPool::Device::State::DEAD) {
-                                       suffix = " (dead)";
-                               }
-                       }
-
+                       string label = get_bus_desc_label(mapping.buses[bus_index]);
                        audio_miniviews[bus_index]->bus_desc_label->setFullText(
-                               QString::fromStdString(bus.name + suffix));
+                               QString::fromStdString(label));
                        audio_expanded_views[bus_index]->bus_desc_label->setFullText(
-                               QString::fromStdString(bus.name + suffix));
+                               QString::fromStdString(label));
                }
        });
 }