1 #include "mainwindow.h"
8 #include <QAbstractButton>
9 #include <QAbstractSlider>
11 #include <QActionGroup>
12 #include <QApplication>
15 #include <QDesktopServices>
22 #include <QInputDialog>
23 #include <QKeySequence>
25 #include <QLayoutItem>
27 #include <QMessageBox>
28 #include <QMouseEvent>
30 #include <QPushButton>
34 #include <QStackedWidget>
35 #include <QToolButton>
47 #include "aboutdialog.h"
48 #include "alsa_pool.h"
50 #include "clickable_label.h"
51 #include "context_menus.h"
52 #include "correlation_meter.h"
53 #include "disk_space_estimator.h"
54 #include "ellipsis_label.h"
57 #include "input_mapping.h"
58 #include "input_mapping_dialog.h"
60 #include "midi_mapping.pb.h"
61 #include "midi_mapping_dialog.h"
63 #include "nonlinear_fader.h"
64 #include "post_to_main_thread.h"
65 #include "ui_audio_expanded_view.h"
66 #include "ui_audio_miniview.h"
67 #include "ui_display.h"
68 #include "ui_mainwindow.h"
72 using namespace std::chrono;
73 using namespace std::placeholders;
75 Q_DECLARE_METATYPE(std::string);
76 Q_DECLARE_METATYPE(std::vector<std::string>);
78 MainWindow *global_mainwindow = nullptr;
80 // -0.1 dBFS is EBU peak limit. We use it consistently, even for the bus meters
81 // (which don't calculate interpolate peak, and in general don't follow EBU recommendations).
82 constexpr float peak_limit_dbfs = -0.1f;
86 void schedule_cut_signal(int ignored)
88 global_mixer->schedule_cut();
91 void quit_signal(int ignored)
93 global_mainwindow->close();
96 void slave_knob(QDial *master, QDial *slave)
98 QWidget::connect(master, &QDial::valueChanged, [slave](int value){
99 slave->blockSignals(true);
100 slave->setValue(value);
101 slave->blockSignals(false);
103 QWidget::connect(slave, &QDial::valueChanged, [master](int value){
104 master->setValue(value);
108 void slave_checkbox(QCheckBox *master, QCheckBox *slave)
110 QWidget::connect(master, &QCheckBox::stateChanged, [slave](int state){
111 slave->blockSignals(true);
112 slave->setCheckState(Qt::CheckState(state));
113 slave->blockSignals(false);
115 QWidget::connect(slave, &QCheckBox::stateChanged, [master](int state){
116 master->setCheckState(Qt::CheckState(state));
120 void slave_fader(NonLinearFader *master, NonLinearFader *slave)
122 QWidget::connect(master, &NonLinearFader::dbValueChanged, [slave](double value) {
123 slave->blockSignals(true);
124 slave->setDbValue(value);
125 slave->blockSignals(false);
127 QWidget::connect(slave, &NonLinearFader::dbValueChanged, [master](double value){
128 master->setDbValue(value);
132 constexpr unsigned DB_NO_FLAGS = 0x0;
133 constexpr unsigned DB_WITH_SIGN = 0x1;
134 constexpr unsigned DB_BARE = 0x2;
136 string format_db(double db, unsigned flags)
139 if (flags & DB_WITH_SIGN) {
142 snprintf(buf, sizeof(buf), "%+.1f", db);
144 } else if (db < 0.0) {
147 // Should never happen, really.
153 snprintf(buf, sizeof(buf), "%.1f", db);
155 } else if (db < 0.0) {
158 // Should never happen, really.
162 if (!(flags & DB_BARE)) {
168 void set_peak_label(QLabel *peak_label, float peak_db)
170 peak_label->setText(QString::fromStdString(format_db(peak_db, DB_BARE)));
172 if (peak_db > peak_limit_dbfs) {
173 peak_label->setStyleSheet("QLabel { background-color: red; color: white; }");
175 peak_label->setStyleSheet("");
181 MainWindow::MainWindow()
182 : ui(new Ui::MainWindow), midi_mapper(this)
184 global_mainwindow = this;
187 global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2));
188 disk_free_label = new QLabel(this);
189 disk_free_label->setStyleSheet("QLabel {padding-right: 5px;}");
190 ui->menuBar->setCornerWidget(disk_free_label);
192 QActionGroup *audio_mapping_group = new QActionGroup(this);
193 ui->simple_audio_mode->setActionGroup(audio_mapping_group);
194 ui->multichannel_audio_mode->setActionGroup(audio_mapping_group);
196 ui->me_live->set_output(Mixer::OUTPUT_LIVE);
197 ui->me_preview->set_output(Mixer::OUTPUT_PREVIEW);
200 connect(ui->cut_action, &QAction::triggered, this, &MainWindow::cut_triggered);
201 connect(ui->exit_action, &QAction::triggered, this, &MainWindow::exit_triggered);
202 connect(ui->manual_action, &QAction::triggered, this, &MainWindow::manual_triggered);
203 connect(ui->about_action, &QAction::triggered, this, &MainWindow::about_triggered);
204 connect(ui->open_analyzer_action, &QAction::triggered, this, &MainWindow::open_analyzer_triggered);
205 connect(ui->simple_audio_mode, &QAction::triggered, this, &MainWindow::simple_audio_mode_triggered);
206 connect(ui->multichannel_audio_mode, &QAction::triggered, this, &MainWindow::multichannel_audio_mode_triggered);
207 connect(ui->input_mapping_action, &QAction::triggered, this, &MainWindow::input_mapping_triggered);
208 connect(ui->midi_mapping_action, &QAction::triggered, this, &MainWindow::midi_mapping_triggered);
209 connect(ui->timecode_stream_action, &QAction::triggered, this, &MainWindow::timecode_stream_triggered);
210 connect(ui->timecode_stdout_action, &QAction::triggered, this, &MainWindow::timecode_stdout_triggered);
212 ui->timecode_stream_action->setChecked(global_flags.display_timecode_in_stream);
213 ui->timecode_stdout_action->setChecked(global_flags.display_timecode_on_stdout);
215 if (global_flags.x264_video_to_http && isinf(global_flags.x264_crf)) {
216 connect(ui->x264_bitrate_action, &QAction::triggered, this, &MainWindow::x264_bitrate_triggered);
218 ui->x264_bitrate_action->setEnabled(false);
221 connect(ui->video_menu, &QMenu::aboutToShow, [this]{
222 fill_hdmi_sdi_output_device_menu(ui->hdmi_sdi_output_device_menu);
223 fill_hdmi_sdi_output_resolution_menu(ui->hdmi_sdi_output_resolution_menu);
226 // Hook up the transition buttons. (Keyboard shortcuts are set in set_transition_names().)
227 // TODO: Make them dynamic.
228 connect(ui->transition_btn1, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 0));
229 connect(ui->transition_btn2, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 1));
230 connect(ui->transition_btn3, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 2));
233 transition_btn1 = ui->transition_btn1;
234 transition_btn2 = ui->transition_btn2;
235 transition_btn3 = ui->transition_btn3;
236 qRegisterMetaType<string>("std::string");
237 qRegisterMetaType<vector<string>>("std::vector<std::string>");
238 connect(ui->me_live, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names);
239 qRegisterMetaType<Mixer::Output>("Mixer::Output");
241 // Hook up the prev/next buttons on the audio views.
242 auto prev_page = [this]{
243 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
244 ui->audio_views->setCurrentIndex((ui->audio_views->currentIndex() + 2) % 3);
246 ui->audio_views->setCurrentIndex(2 - ui->audio_views->currentIndex()); // Switch between 0 and 2.
249 auto next_page = [this]{
250 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
251 ui->audio_views->setCurrentIndex((ui->audio_views->currentIndex() + 1) % 3);
253 ui->audio_views->setCurrentIndex(2 - ui->audio_views->currentIndex()); // Switch between 0 and 2.
256 connect(ui->compact_prev_page, &QAbstractButton::clicked, prev_page);
257 connect(ui->compact_next_page, &QAbstractButton::clicked, next_page);
258 connect(ui->full_prev_page, &QAbstractButton::clicked, prev_page);
259 connect(ui->full_next_page, &QAbstractButton::clicked, next_page);
260 connect(ui->video_grid_prev_page, &QAbstractButton::clicked, prev_page);
261 connect(ui->video_grid_next_page, &QAbstractButton::clicked, next_page);
263 // And bind the same to PgUp/PgDown.
264 connect(new QShortcut(QKeySequence::MoveToNextPage, this), &QShortcut::activated, next_page);
265 connect(new QShortcut(QKeySequence::MoveToPreviousPage, this), &QShortcut::activated, prev_page);
267 // When the audio view changes, move the previews.
268 connect(ui->audio_views, &QStackedWidget::currentChanged, bind(&MainWindow::audio_view_changed, this, _1));
270 if (global_flags.enable_quick_cut_keys) {
271 ui->quick_cut_enable_action->setChecked(true);
273 connect(ui->quick_cut_enable_action, &QAction::changed, [this](){
274 global_flags.enable_quick_cut_keys = ui->quick_cut_enable_action->isChecked();
277 last_audio_level_callback = steady_clock::now() - seconds(1);
279 if (!global_flags.midi_mapping_filename.empty()) {
280 MIDIMappingProto midi_mapping;
281 if (!load_midi_mapping_from_file(global_flags.midi_mapping_filename, &midi_mapping)) {
282 fprintf(stderr, "Couldn't load MIDI mapping '%s'; exiting.\n",
283 global_flags.midi_mapping_filename.c_str());
286 midi_mapper.set_midi_mapping(midi_mapping);
288 midi_mapper.refresh_highlights();
289 midi_mapper.refresh_lights();
292 void MainWindow::resizeEvent(QResizeEvent* event)
294 QMainWindow::resizeEvent(event);
296 // Ask for a relayout, but only after the event loop is done doing relayout
297 // on everything else.
298 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
301 void MainWindow::mixer_created(Mixer *mixer)
303 // Make the previews.
304 unsigned num_previews = mixer->get_num_channels();
306 const char qwerty[] = "QWERTYUIOP";
307 for (unsigned i = 0; i < num_previews; ++i) {
308 Mixer::Output output = Mixer::Output(Mixer::OUTPUT_INPUT0 + i);
310 QWidget *preview = new QWidget(this); // Will be connected to a layout immediately after the loop.
311 Ui::Display *ui_display = new Ui::Display;
312 ui_display->setupUi(preview);
313 ui_display->label->setText(mixer->get_channel_name(output).c_str());
314 ui_display->display->set_output(output);
315 previews.push_back(ui_display);
317 // Hook up the click.
318 connect(ui_display->display, &GLWidget::clicked, bind(&MainWindow::channel_clicked, this, i));
320 // Let the theme update the text whenever the resolution or color changed.
321 connect(ui_display->display, &GLWidget::name_updated, this, &MainWindow::update_channel_name);
322 connect(ui_display->display, &GLWidget::color_updated, this, &MainWindow::update_channel_color);
324 // Hook up the keyboard key.
325 QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
326 connect(shortcut, &QShortcut::activated, bind(&MainWindow::channel_clicked, this, i));
328 // Hook up the quick-cut key.
329 if (i < strlen(qwerty)) {
330 QShortcut *shortcut = new QShortcut(QKeySequence(qwerty[i]), this);
331 connect(shortcut, &QShortcut::activated, bind(&MainWindow::quick_cut_activated, this, i));
334 // Hook up the white balance button (irrelevant if invisible).
335 ui_display->wb_button->setVisible(mixer->get_supports_set_wb(output));
336 connect(ui_display->wb_button, &QPushButton::clicked, bind(&MainWindow::wb_button_clicked, this, i));
339 // Connect the previews to the correct layout.
340 audio_view_changed(ui->audio_views->currentIndex());
342 global_audio_mixer->set_state_changed_callback(bind(&MainWindow::audio_state_changed, this));
344 slave_knob(ui->locut_cutoff_knob, ui->locut_cutoff_knob_2);
345 slave_knob(ui->limiter_threshold_knob, ui->limiter_threshold_knob_2);
346 slave_knob(ui->makeup_gain_knob, ui->makeup_gain_knob_2);
347 slave_checkbox(ui->makeup_gain_auto_checkbox, ui->makeup_gain_auto_checkbox_2);
348 slave_checkbox(ui->limiter_enabled, ui->limiter_enabled_2);
350 reset_audio_mapping_ui();
352 // TODO: Fetch all of the values these for completeness,
353 // not just the enable knobs implied by flags.
354 ui->limiter_enabled->setChecked(global_audio_mixer->get_limiter_enabled());
355 ui->makeup_gain_auto_checkbox->setChecked(global_audio_mixer->get_final_makeup_gain_auto());
357 // Controls used only for simple audio fetch their state from the first bus.
358 constexpr unsigned simple_bus_index = 0;
359 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
360 ui->locut_enabled->setChecked(global_audio_mixer->get_locut_enabled(simple_bus_index));
361 ui->gainstaging_knob->setValue(global_audio_mixer->get_gain_staging_db(simple_bus_index));
362 ui->gainstaging_auto_checkbox->setChecked(global_audio_mixer->get_gain_staging_auto(simple_bus_index));
363 ui->compressor_enabled->setChecked(global_audio_mixer->get_compressor_enabled(simple_bus_index));
364 ui->compressor_threshold_db_display->setText(
365 QString::fromStdString(format_db(mixer->get_audio_mixer()->get_compressor_threshold_dbfs(simple_bus_index), DB_WITH_SIGN)));
367 connect(ui->locut_enabled, &QCheckBox::stateChanged, [this](int state){
368 global_audio_mixer->set_locut_enabled(simple_bus_index, state == Qt::Checked);
369 midi_mapper.refresh_lights();
371 connect(ui->gainstaging_knob, &QAbstractSlider::valueChanged,
372 bind(&MainWindow::gain_staging_knob_changed, this, simple_bus_index, _1));
373 connect(ui->gainstaging_auto_checkbox, &QCheckBox::stateChanged, [this, simple_bus_index](int state){
374 global_audio_mixer->set_gain_staging_auto(simple_bus_index, state == Qt::Checked);
375 midi_mapper.refresh_lights();
377 connect(ui->compressor_threshold_knob, &QDial::valueChanged,
378 bind(&MainWindow::compressor_threshold_knob_changed, this, simple_bus_index, _1));
379 connect(ui->compressor_enabled, &QCheckBox::stateChanged, [this, simple_bus_index](int state){
380 global_audio_mixer->set_compressor_enabled(simple_bus_index, state == Qt::Checked);
381 midi_mapper.refresh_lights();
384 // Global mastering controls.
385 QString limiter_threshold_label(
386 QString::fromStdString(format_db(mixer->get_audio_mixer()->get_limiter_threshold_dbfs(), DB_WITH_SIGN)));
387 ui->limiter_threshold_db_display->setText(limiter_threshold_label);
388 ui->limiter_threshold_db_display_2->setText(limiter_threshold_label);
390 connect(ui->locut_cutoff_knob, &QDial::valueChanged, this, &MainWindow::cutoff_knob_changed);
391 cutoff_knob_changed(ui->locut_cutoff_knob->value());
393 connect(ui->makeup_gain_knob, &QAbstractSlider::valueChanged, this, &MainWindow::final_makeup_gain_knob_changed);
394 connect(ui->makeup_gain_auto_checkbox, &QCheckBox::stateChanged, [this](int state){
395 global_audio_mixer->set_final_makeup_gain_auto(state == Qt::Checked);
396 midi_mapper.refresh_lights();
399 connect(ui->limiter_threshold_knob, &QDial::valueChanged, this, &MainWindow::limiter_threshold_knob_changed);
400 connect(ui->limiter_enabled, &QCheckBox::stateChanged, [this](int state){
401 global_audio_mixer->set_limiter_enabled(state == Qt::Checked);
402 midi_mapper.refresh_lights();
404 connect(ui->reset_meters_button, &QPushButton::clicked, this, &MainWindow::reset_meters_button_clicked);
405 // Even though we have a reset button right next to it, the fact that
406 // the expanded audio view labels are clickable makes it natural to
407 // click this one as well.
408 connect(ui->peak_display, &ClickableLabel::clicked, this, &MainWindow::reset_meters_button_clicked);
409 mixer->get_audio_mixer()->set_audio_level_callback(bind(&MainWindow::audio_level_callback, this, _1, _2, _3, _4, _5, _6, _7, _8));
411 midi_mapper.refresh_highlights();
412 midi_mapper.refresh_lights();
413 midi_mapper.start_thread();
415 analyzer.reset(new Analyzer);
417 struct sigaction act;
418 memset(&act, 0, sizeof(act));
419 act.sa_handler = schedule_cut_signal;
420 act.sa_flags = SA_RESTART;
421 sigaction(SIGHUP, &act, nullptr);
423 // Mostly for debugging. Don't override SIGINT, that's so evil if
424 // shutdown isn't instant.
425 memset(&act, 0, sizeof(act));
426 act.sa_handler = quit_signal;
427 act.sa_flags = SA_RESTART;
428 sigaction(SIGUSR1, &act, nullptr);
431 void MainWindow::reset_audio_mapping_ui()
433 bool simple = (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE);
435 ui->simple_audio_mode->setChecked(simple);
436 ui->multichannel_audio_mode->setChecked(!simple);
437 ui->input_mapping_action->setEnabled(!simple);
438 ui->midi_mapping_action->setEnabled(!simple);
440 ui->locut_enabled->setVisible(simple);
441 ui->gainstaging_label->setVisible(simple);
442 ui->gainstaging_knob->setVisible(simple);
443 ui->gainstaging_db_display->setVisible(simple);
444 ui->gainstaging_auto_checkbox->setVisible(simple);
445 ui->compressor_threshold_label->setVisible(simple);
446 ui->compressor_threshold_knob->setVisible(simple);
447 ui->compressor_threshold_db_display->setVisible(simple);
448 ui->compressor_enabled->setVisible(simple);
450 setup_audio_miniview();
451 setup_audio_expanded_view();
454 ui->compact_label->setText("Compact audio view (1/2) ");
455 ui->video_grid_label->setText("Video grid display (2/2) ");
456 if (ui->audio_views->currentIndex() == 1) {
457 // Full audio view is not available in simple mode.
458 ui->audio_views->setCurrentIndex(0);
461 ui->compact_label->setText("Compact audio view (1/3) ");
462 ui->full_label->setText("Full audio view (2/3) ");
463 ui->video_grid_label->setText("Video grid display (3/3) ");
466 midi_mapper.refresh_highlights();
467 midi_mapper.refresh_lights();
470 void MainWindow::setup_audio_miniview()
472 // Remove any existing channels.
473 for (QLayoutItem *item; (item = ui->faders->takeAt(0)) != nullptr; ) {
474 delete item->widget();
477 audio_miniviews.clear();
479 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
483 // Set up brand new ones from the input mapping.
484 InputMapping mapping = global_audio_mixer->get_input_mapping();
485 audio_miniviews.resize(mapping.buses.size());
486 for (unsigned bus_index = 0; bus_index < mapping.buses.size(); ++bus_index) {
487 QWidget *channel = new QWidget(this);
488 Ui::AudioMiniView *ui_audio_miniview = new Ui::AudioMiniView;
489 ui_audio_miniview->setupUi(channel);
490 ui_audio_miniview->bus_desc_label->setFullText(
491 QString::fromStdString(mapping.buses[bus_index].name));
492 audio_miniviews[bus_index] = ui_audio_miniview;
494 // Set up the peak meter.
495 VUMeter *peak_meter = ui_audio_miniview->peak_meter;
496 peak_meter->set_min_level(-30.0f);
497 peak_meter->set_max_level(0.0f);
498 peak_meter->set_ref_level(0.0f);
500 ui_audio_miniview->fader->setDbValue(global_audio_mixer->get_fader_volume(bus_index));
502 ui->faders->addWidget(channel);
504 connect(ui_audio_miniview->fader, &NonLinearFader::dbValueChanged,
505 bind(&MainWindow::mini_fader_changed, this, bus_index, _1));
506 connect(ui_audio_miniview->peak_display_label, &ClickableLabel::clicked,
508 global_audio_mixer->reset_peak(bus_index);
513 void MainWindow::setup_audio_expanded_view()
515 // Remove any existing channels.
516 for (QLayoutItem *item; (item = ui->buses->takeAt(0)) != nullptr; ) {
517 delete item->widget();
520 audio_expanded_views.clear();
522 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
526 // Set up brand new ones from the input mapping.
527 InputMapping mapping = global_audio_mixer->get_input_mapping();
528 audio_expanded_views.resize(mapping.buses.size());
529 for (unsigned bus_index = 0; bus_index < mapping.buses.size(); ++bus_index) {
530 QWidget *channel = new QWidget(this);
531 Ui::AudioExpandedView *ui_audio_expanded_view = new Ui::AudioExpandedView;
532 ui_audio_expanded_view->setupUi(channel);
533 ui_audio_expanded_view->bus_desc_label->setFullText(
534 QString::fromStdString(mapping.buses[bus_index].name));
535 audio_expanded_views[bus_index] = ui_audio_expanded_view;
536 update_eq_label(bus_index, EQ_BAND_TREBLE, global_audio_mixer->get_eq(bus_index, EQ_BAND_TREBLE));
537 update_eq_label(bus_index, EQ_BAND_MID, global_audio_mixer->get_eq(bus_index, EQ_BAND_MID));
538 update_eq_label(bus_index, EQ_BAND_BASS, global_audio_mixer->get_eq(bus_index, EQ_BAND_BASS));
539 ui_audio_expanded_view->fader->setDbValue(global_audio_mixer->get_fader_volume(bus_index));
540 ui_audio_expanded_view->mute_button->setChecked(global_audio_mixer->get_mute(bus_index));
541 connect(ui_audio_expanded_view->mute_button, &QPushButton::toggled,
542 bind(&MainWindow::mute_button_toggled, this, bus_index, _1));
543 ui->buses->addWidget(channel);
545 ui_audio_expanded_view->locut_enabled->setChecked(global_audio_mixer->get_locut_enabled(bus_index));
546 connect(ui_audio_expanded_view->locut_enabled, &QCheckBox::stateChanged, [this, bus_index](int state){
547 global_audio_mixer->set_locut_enabled(bus_index, state == Qt::Checked);
548 midi_mapper.refresh_lights();
551 connect(ui_audio_expanded_view->treble_knob, &QDial::valueChanged,
552 bind(&MainWindow::eq_knob_changed, this, bus_index, EQ_BAND_TREBLE, _1));
553 connect(ui_audio_expanded_view->mid_knob, &QDial::valueChanged,
554 bind(&MainWindow::eq_knob_changed, this, bus_index, EQ_BAND_MID, _1));
555 connect(ui_audio_expanded_view->bass_knob, &QDial::valueChanged,
556 bind(&MainWindow::eq_knob_changed, this, bus_index, EQ_BAND_BASS, _1));
558 ui_audio_expanded_view->gainstaging_knob->setValue(global_audio_mixer->get_gain_staging_db(bus_index));
559 ui_audio_expanded_view->gainstaging_auto_checkbox->setChecked(global_audio_mixer->get_gain_staging_auto(bus_index));
560 ui_audio_expanded_view->compressor_enabled->setChecked(global_audio_mixer->get_compressor_enabled(bus_index));
562 connect(ui_audio_expanded_view->gainstaging_knob, &QAbstractSlider::valueChanged, bind(&MainWindow::gain_staging_knob_changed, this, bus_index, _1));
563 connect(ui_audio_expanded_view->gainstaging_auto_checkbox, &QCheckBox::stateChanged, [this, bus_index](int state){
564 global_audio_mixer->set_gain_staging_auto(bus_index, state == Qt::Checked);
565 midi_mapper.refresh_lights();
568 connect(ui_audio_expanded_view->compressor_threshold_knob, &QDial::valueChanged, bind(&MainWindow::compressor_threshold_knob_changed, this, bus_index, _1));
569 connect(ui_audio_expanded_view->compressor_enabled, &QCheckBox::stateChanged, [this, bus_index](int state){
570 global_audio_mixer->set_compressor_enabled(bus_index, state == Qt::Checked);
571 midi_mapper.refresh_lights();
574 slave_fader(audio_miniviews[bus_index]->fader, ui_audio_expanded_view->fader);
576 // Set up the peak meter.
577 VUMeter *peak_meter = ui_audio_expanded_view->peak_meter;
578 peak_meter->set_min_level(-30.0f);
579 peak_meter->set_max_level(0.0f);
580 peak_meter->set_ref_level(0.0f);
582 connect(ui_audio_expanded_view->peak_display_label, &ClickableLabel::clicked,
583 [this, bus_index]() {
584 global_audio_mixer->reset_peak(bus_index);
585 midi_mapper.refresh_lights();
589 update_cutoff_labels(global_audio_mixer->get_locut_cutoff());
592 void MainWindow::mixer_shutting_down()
594 ui->me_live->shutdown();
595 ui->me_preview->shutdown();
597 for (Ui::Display *display : previews) {
598 display->display->shutdown();
601 analyzer->mixer_shutting_down();
604 void MainWindow::cut_triggered()
606 global_mixer->schedule_cut();
609 void MainWindow::x264_bitrate_triggered()
612 int new_bitrate = QInputDialog::getInt(this, "Change x264 bitrate", "Choose new bitrate for x264 HTTP output (from 100–100,000 kbit/sec):", global_flags.x264_bitrate, /*min=*/100, /*max=*/100000, /*step=*/100, &ok);
613 if (ok && new_bitrate >= 100 && new_bitrate <= 100000) {
614 global_flags.x264_bitrate = new_bitrate;
615 global_mixer->change_x264_bitrate(new_bitrate);
619 void MainWindow::exit_triggered()
624 void MainWindow::manual_triggered()
626 if (!QDesktopServices::openUrl(QUrl("https://nageru.sesse.net/doc/"))) {
628 msgbox.setText("Could not launch manual in web browser.\nPlease see https://nageru.sesse.net/doc/ manually.");
633 void MainWindow::about_triggered()
635 AboutDialog().exec();
638 void MainWindow::open_analyzer_triggered()
643 void MainWindow::simple_audio_mode_triggered()
645 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
648 unsigned card_index = global_audio_mixer->get_simple_input();
649 if (card_index == numeric_limits<unsigned>::max()) {
650 QMessageBox::StandardButton reply =
651 QMessageBox::question(this,
652 "Mapping too complex",
653 "The current audio mapping is too complicated to be representable in simple mode, "
654 "and will be discarded if you proceed. Really go to simple audio mode?",
655 QMessageBox::Yes | QMessageBox::No);
656 if (reply == QMessageBox::No) {
657 ui->simple_audio_mode->setChecked(false);
658 ui->multichannel_audio_mode->setChecked(true);
663 global_audio_mixer->set_simple_input(/*card_index=*/card_index);
664 reset_audio_mapping_ui();
667 void MainWindow::multichannel_audio_mode_triggered()
669 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
673 // Take the generated input mapping from the simple input,
674 // and set it as a normal multichannel mapping, which causes
675 // the mode to go to multichannel.
676 global_audio_mixer->set_input_mapping(global_audio_mixer->get_input_mapping());
677 reset_audio_mapping_ui();
680 void MainWindow::input_mapping_triggered()
682 if (InputMappingDialog().exec() == QDialog::Accepted) {
683 setup_audio_miniview();
684 setup_audio_expanded_view();
686 midi_mapper.refresh_highlights();
687 midi_mapper.refresh_lights();
690 void MainWindow::midi_mapping_triggered()
692 MIDIMappingDialog(&midi_mapper).exec();
695 void MainWindow::timecode_stream_triggered()
697 global_mixer->set_display_timecode_in_stream(ui->timecode_stream_action->isChecked());
700 void MainWindow::timecode_stdout_triggered()
702 global_mixer->set_display_timecode_on_stdout(ui->timecode_stdout_action->isChecked());
705 void MainWindow::gain_staging_knob_changed(unsigned bus_index, int value)
707 if (bus_index == 0) {
708 ui->gainstaging_auto_checkbox->setCheckState(Qt::Unchecked);
710 if (bus_index < audio_expanded_views.size()) {
711 audio_expanded_views[bus_index]->gainstaging_auto_checkbox->setCheckState(Qt::Unchecked);
714 float gain_db = value * 0.1f;
715 global_audio_mixer->set_gain_staging_db(bus_index, gain_db);
717 // The label will be updated by the audio level callback.
720 void MainWindow::final_makeup_gain_knob_changed(int value)
722 ui->makeup_gain_auto_checkbox->setCheckState(Qt::Unchecked);
724 float gain_db = value * 0.1f;
725 global_audio_mixer->set_final_makeup_gain_db(gain_db);
727 // The label will be updated by the audio level callback.
730 void MainWindow::cutoff_knob_changed(int value)
732 float octaves = value * 0.1f;
733 float cutoff_hz = 20.0 * pow(2.0, octaves);
734 global_audio_mixer->set_locut_cutoff(cutoff_hz);
735 update_cutoff_labels(cutoff_hz);
738 void MainWindow::update_cutoff_labels(float cutoff_hz)
741 snprintf(buf, sizeof(buf), "%ld Hz", lrintf(cutoff_hz));
742 ui->locut_cutoff_display->setText(buf);
743 ui->locut_cutoff_display_2->setText(buf);
745 for (unsigned bus_index = 0; bus_index < audio_expanded_views.size(); ++bus_index) {
746 audio_expanded_views[bus_index]->locut_enabled->setText(
747 QString("Lo-cut: ") + buf);
751 void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
754 if (estimated_seconds_left < 60.0) {
755 strcpy(time_str, "<font color=\"red\">Less than a minute</font>");
756 } else if (estimated_seconds_left < 1800.0) { // Less than half an hour: Xm Ys (red).
757 int s = lrintf(estimated_seconds_left);
760 snprintf(time_str, sizeof(time_str), "<font color=\"red\">%dm %ds</font>", m, s);
761 } else if (estimated_seconds_left < 3600.0) { // Less than an hour: Xm.
762 int m = lrintf(estimated_seconds_left / 60.0);
763 snprintf(time_str, sizeof(time_str), "%dm", m);
764 } else if (estimated_seconds_left < 36000.0) { // Less than ten hours: Xh Ym.
765 int m = lrintf(estimated_seconds_left / 60.0);
768 snprintf(time_str, sizeof(time_str), "%dh %dm", h, m);
769 } else { // More than ten hours: Xh.
770 int h = lrintf(estimated_seconds_left / 3600.0);
771 snprintf(time_str, sizeof(time_str), "%dh", h);
774 snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str);
776 std::string label = buf;
778 post_to_main_thread([this, label]{
779 disk_free_label->setText(QString::fromStdString(label));
780 ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right.
784 void MainWindow::eq_knob_changed(unsigned bus_index, EQBand band, int value)
786 float gain_db = value * 0.1f;
787 global_audio_mixer->set_eq(bus_index, band, gain_db);
789 update_eq_label(bus_index, band, gain_db);
792 void MainWindow::update_eq_label(unsigned bus_index, EQBand band, float gain_db)
794 Ui::AudioExpandedView *view = audio_expanded_views[bus_index];
795 string db_string = format_db(gain_db, DB_WITH_SIGN);
798 view->treble_label->setText(QString::fromStdString("Treble: " + db_string));
801 view->mid_label->setText(QString::fromStdString("Mid: " + db_string));
804 view->bass_label->setText(QString::fromStdString("Bass: " + db_string));
811 void MainWindow::limiter_threshold_knob_changed(int value)
813 float threshold_dbfs = value * 0.1f;
814 global_audio_mixer->set_limiter_threshold_dbfs(threshold_dbfs);
815 ui->limiter_threshold_db_display->setText(
816 QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
817 ui->limiter_threshold_db_display_2->setText(
818 QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
821 void MainWindow::compressor_threshold_knob_changed(unsigned bus_index, int value)
823 float threshold_dbfs = value * 0.1f;
824 global_audio_mixer->set_compressor_threshold_dbfs(bus_index, threshold_dbfs);
826 QString label(QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
827 if (bus_index == 0) {
828 ui->compressor_threshold_db_display->setText(label);
830 if (bus_index < audio_expanded_views.size()) {
831 audio_expanded_views[bus_index]->compressor_threshold_db_display->setText(label);
835 void MainWindow::mini_fader_changed(int bus, double volume_db)
837 QString label(QString::fromStdString(format_db(volume_db, DB_WITH_SIGN)));
838 audio_miniviews[bus]->fader_label->setText(label);
839 audio_expanded_views[bus]->fader_label->setText(label);
841 global_audio_mixer->set_fader_volume(bus, volume_db);
844 void MainWindow::mute_button_toggled(int bus, bool checked)
846 global_audio_mixer->set_mute(bus, checked);
847 midi_mapper.refresh_lights();
850 void MainWindow::reset_meters_button_clicked()
852 global_audio_mixer->reset_meters();
853 ui->peak_display->setText(QString::fromStdString(format_db(-HUGE_VAL, DB_WITH_SIGN | DB_BARE)));
854 ui->peak_display->setStyleSheet("");
857 void MainWindow::audio_level_callback(float level_lufs, float peak_db, vector<AudioMixer::BusLevel> bus_levels,
858 float global_level_lufs,
859 float range_low_lufs, float range_high_lufs,
860 float final_makeup_gain_db,
863 steady_clock::time_point now = steady_clock::now();
865 // The meters are somewhat inefficient to update. Only update them
866 // every 100 ms or so (we get updates every 5–20 ms). Note that this
867 // means that the digital peak meters are ever so slightly too low
868 // (each update won't be a faithful representation of the highest peak
869 // since the previous update, since there are frames we won't draw),
870 // but the _peak_ of the peak meters will be correct (it's tracked in
871 // AudioMixer, not here), and that's much more important.
872 double last_update_age = duration<double>(now - last_audio_level_callback).count();
873 if (last_update_age < 0.100) {
876 last_audio_level_callback = now;
878 post_to_main_thread([=]() {
879 ui->vu_meter->set_level(level_lufs);
880 for (unsigned bus_index = 0; bus_index < bus_levels.size(); ++bus_index) {
881 if (bus_index < audio_miniviews.size()) {
882 const AudioMixer::BusLevel &level = bus_levels[bus_index];
883 Ui::AudioMiniView *miniview = audio_miniviews[bus_index];
884 miniview->peak_meter->set_level(
885 level.current_level_dbfs[0], level.current_level_dbfs[1]);
886 miniview->peak_meter->set_peak(
887 level.peak_level_dbfs[0], level.peak_level_dbfs[1]);
888 set_peak_label(miniview->peak_display_label, level.historic_peak_dbfs);
890 Ui::AudioExpandedView *view = audio_expanded_views[bus_index];
891 view->peak_meter->set_level(
892 level.current_level_dbfs[0], level.current_level_dbfs[1]);
893 view->peak_meter->set_peak(
894 level.peak_level_dbfs[0], level.peak_level_dbfs[1]);
895 view->reduction_meter->set_reduction_db(level.compressor_attenuation_db);
896 view->gainstaging_knob->blockSignals(true);
897 view->gainstaging_knob->setValue(lrintf(level.gain_staging_db * 10.0f));
898 view->gainstaging_knob->blockSignals(false);
899 view->gainstaging_db_display->setText(
901 QString::fromStdString(format_db(level.gain_staging_db, DB_WITH_SIGN)));
902 set_peak_label(view->peak_display_label, level.historic_peak_dbfs);
904 midi_mapper.set_has_peaked(bus_index, level.historic_peak_dbfs >= -0.1f);
907 ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
908 ui->correlation_meter->set_correlation(correlation);
910 ui->peak_display->setText(QString::fromStdString(format_db(peak_db, DB_BARE)));
911 set_peak_label(ui->peak_display, peak_db);
913 // NOTE: Will be invisible when using multitrack audio.
914 ui->gainstaging_knob->blockSignals(true);
915 ui->gainstaging_knob->setValue(lrintf(bus_levels[0].gain_staging_db * 10.0f));
916 ui->gainstaging_knob->blockSignals(false);
917 ui->gainstaging_db_display->setText(
918 QString::fromStdString(format_db(bus_levels[0].gain_staging_db, DB_WITH_SIGN)));
920 ui->makeup_gain_knob->blockSignals(true);
921 ui->makeup_gain_knob->setValue(lrintf(final_makeup_gain_db * 10.0f));
922 ui->makeup_gain_knob->blockSignals(false);
923 ui->makeup_gain_db_display->setText(
924 QString::fromStdString(format_db(final_makeup_gain_db, DB_WITH_SIGN)));
925 ui->makeup_gain_db_display_2->setText(
926 QString::fromStdString(format_db(final_makeup_gain_db, DB_WITH_SIGN)));
928 // Peak labels could have changed.
929 midi_mapper.refresh_lights();
933 void MainWindow::relayout()
935 int height = ui->vertical_layout->geometry().height();
937 // Seemingly this can happen and must be ignored.
941 double remaining_height = height;
943 // Allocate the height; the most important part is to keep the main displays
944 // at the right aspect if at all possible.
945 double me_width = ui->me_preview->width();
946 double me_height = me_width * double(global_flags.height) / double(global_flags.width) + ui->label_preview->height() + ui->preview_vertical_layout->spacing();
948 // TODO: Scale the widths when we need to do this.
949 if (me_height / double(height) > 0.8) {
950 me_height = height * 0.8;
952 remaining_height -= me_height + ui->vertical_layout->spacing();
954 // Space between the M/E displays and the audio strip.
955 remaining_height -= ui->vertical_layout->spacing();
957 // The label above the audio strip.
958 double compact_label_height = ui->compact_label->minimumHeight() +
959 ui->compact_audio_layout->spacing();
960 remaining_height -= compact_label_height;
962 // The previews will be constrained by the remaining height, and the width.
963 double preview_label_height = previews[0]->label->minimumSize().height() +
964 previews[0]->main_vertical_layout->spacing();
965 int preview_total_width = ui->preview_displays->geometry().width() - (previews.size() - 1) * ui->preview_displays->spacing();
966 double preview_height = min(remaining_height - preview_label_height, (preview_total_width / double(previews.size())) * double(global_flags.height) / double(global_flags.width));
967 remaining_height -= preview_height + preview_label_height + ui->vertical_layout->spacing();
969 ui->vertical_layout->setStretch(0, lrintf(me_height));
970 ui->vertical_layout->setStretch(1,
971 lrintf(compact_label_height) +
972 lrintf(remaining_height) +
973 lrintf(preview_height + preview_label_height)); // Audio strip and previews together.
975 ui->compact_audio_layout->setStretch(0, lrintf(compact_label_height));
976 ui->compact_audio_layout->setStretch(1, lrintf(remaining_height)); // Audio strip.
977 ui->compact_audio_layout->setStretch(2, lrintf(preview_height + preview_label_height));
979 if (current_audio_view == 0) { // Compact audio view.
980 // Set the widths for the previews.
981 double preview_width = preview_height * double(global_flags.width) / double(global_flags.height);
982 for (unsigned i = 0; i < previews.size(); ++i) {
983 ui->preview_displays->setStretch(i, lrintf(preview_width));
986 // The preview horizontal spacer.
987 double remaining_preview_width = preview_total_width - previews.size() * preview_width;
988 ui->preview_displays->setStretch(previews.size(), lrintf(remaining_preview_width));
989 } else if (current_audio_view == 2) { // Video grid view.
990 // QGridLayout doesn't do it for us, since we need to be able to remove rows
991 // or columns as the grid changes, and it won't do that. Thus, position everything
993 constexpr int spacing = 6;
994 int grid_width = ui->preview_displays_grid->geometry().width();
995 int grid_height = ui->preview_displays_grid->geometry().height();
996 int best_preview_width = 0;
997 unsigned best_num_rows = 1, best_num_cols = 1;
998 for (unsigned num_rows = 1; num_rows <= previews.size(); ++num_rows) {
999 int num_cols = (previews.size() + num_rows - 1) / num_rows;
1001 int max_preview_height = (grid_height - spacing * (num_rows - 1)) / num_rows - preview_label_height;
1002 int max_preview_width = (grid_width - spacing * (num_cols - 1)) / num_cols;
1003 int preview_width = std::min<int>(max_preview_width, max_preview_height * double(global_flags.width) / double(global_flags.height));
1005 if (preview_width > best_preview_width) {
1006 best_preview_width = preview_width;
1007 best_num_rows = num_rows;
1008 best_num_cols = num_cols;
1012 double cell_height = lrintf(best_preview_width * double(global_flags.height) / double(global_flags.width)) + preview_label_height;
1013 remaining_height = grid_height - best_num_rows * cell_height - (best_num_rows - 1) * spacing;
1014 int cell_width = best_preview_width;
1015 int remaining_width = grid_width - best_num_cols * cell_width - (best_num_cols - 1) * spacing;
1017 for (unsigned i = 0; i < previews.size(); ++i) {
1018 int col_idx = i % best_num_cols;
1019 int row_idx = i / best_num_cols;
1021 double top = remaining_height * 0.5f + row_idx * (cell_height + spacing);
1022 double bottom = top + cell_height;
1023 double left = remaining_width * 0.5f + col_idx * (cell_width + spacing);
1024 double right = left + cell_width;
1027 rect.setTop(lrintf(top));
1028 rect.setBottom(lrintf(bottom));
1029 rect.setLeft(lrintf(left));
1030 rect.setRight(lrintf(right));
1032 QWidget *display = static_cast<QWidget *>(previews[i]->frame->parent());
1033 display->setGeometry(rect);
1039 void MainWindow::set_locut(float value)
1041 set_relative_value(ui->locut_cutoff_knob, value);
1044 void MainWindow::set_limiter_threshold(float value)
1046 set_relative_value(ui->limiter_threshold_knob, value);
1049 void MainWindow::set_makeup_gain(float value)
1051 set_relative_value(ui->makeup_gain_knob, value);
1054 void MainWindow::set_treble(unsigned bus_idx, float value)
1056 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::treble_knob, value);
1059 void MainWindow::set_mid(unsigned bus_idx, float value)
1061 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::mid_knob, value);
1064 void MainWindow::set_bass(unsigned bus_idx, float value)
1066 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::bass_knob, value);
1069 void MainWindow::set_gain(unsigned bus_idx, float value)
1071 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::gainstaging_knob, value);
1074 void MainWindow::set_compressor_threshold(unsigned bus_idx, float value)
1076 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::compressor_threshold_knob, value);
1079 void MainWindow::set_fader(unsigned bus_idx, float value)
1081 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::fader, value);
1084 void MainWindow::toggle_mute(unsigned bus_idx)
1086 click_button_if_exists(bus_idx, &Ui::AudioExpandedView::mute_button);
1089 void MainWindow::toggle_locut(unsigned bus_idx)
1091 click_button_if_exists(bus_idx, &Ui::AudioExpandedView::locut_enabled);
1094 void MainWindow::toggle_auto_gain_staging(unsigned bus_idx)
1096 click_button_if_exists(bus_idx, &Ui::AudioExpandedView::gainstaging_auto_checkbox);
1099 void MainWindow::toggle_compressor(unsigned bus_idx)
1101 click_button_if_exists(bus_idx, &Ui::AudioExpandedView::compressor_enabled);
1104 void MainWindow::clear_peak(unsigned bus_idx)
1106 post_to_main_thread([=]{
1107 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
1108 global_audio_mixer->reset_peak(bus_idx);
1109 midi_mapper.set_has_peaked(bus_idx, false);
1110 midi_mapper.refresh_lights();
1115 void MainWindow::clear_all_highlights()
1117 post_to_main_thread([this]{
1118 highlight_locut(false);
1119 highlight_limiter_threshold(false);
1120 highlight_makeup_gain(false);
1121 highlight_toggle_limiter(false);
1122 highlight_toggle_auto_makeup_gain(false);
1123 for (unsigned bus_idx = 0; bus_idx < audio_expanded_views.size(); ++bus_idx) {
1124 highlight_treble(bus_idx, false);
1125 highlight_mid(bus_idx, false);
1126 highlight_bass(bus_idx, false);
1127 highlight_gain(bus_idx, false);
1128 highlight_compressor_threshold(bus_idx, false);
1129 highlight_fader(bus_idx, false);
1130 highlight_mute(bus_idx, false);
1131 highlight_toggle_locut(bus_idx, false);
1132 highlight_toggle_auto_gain_staging(bus_idx, false);
1133 highlight_toggle_compressor(bus_idx, false);
1138 void MainWindow::toggle_limiter()
1140 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
1141 ui->limiter_enabled->click();
1145 void MainWindow::toggle_auto_makeup_gain()
1147 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
1148 ui->makeup_gain_auto_checkbox->click();
1152 void MainWindow::highlight_locut(bool highlight)
1154 post_to_main_thread([this, highlight]{
1155 highlight_control(ui->locut_cutoff_knob, highlight);
1156 highlight_control(ui->locut_cutoff_knob_2, highlight);
1160 void MainWindow::highlight_limiter_threshold(bool highlight)
1162 post_to_main_thread([this, highlight]{
1163 highlight_control(ui->limiter_threshold_knob, highlight);
1164 highlight_control(ui->limiter_threshold_knob_2, highlight);
1168 void MainWindow::highlight_makeup_gain(bool highlight)
1170 post_to_main_thread([this, highlight]{
1171 highlight_control(ui->makeup_gain_knob, highlight);
1172 highlight_control(ui->makeup_gain_knob_2, highlight);
1176 void MainWindow::highlight_treble(unsigned bus_idx, bool highlight)
1178 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::treble_knob, highlight);
1181 void MainWindow::highlight_mid(unsigned bus_idx, bool highlight)
1183 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::mid_knob, highlight);
1186 void MainWindow::highlight_bass(unsigned bus_idx, bool highlight)
1188 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::bass_knob, highlight);
1191 void MainWindow::highlight_gain(unsigned bus_idx, bool highlight)
1193 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::gainstaging_knob, highlight);
1196 void MainWindow::highlight_compressor_threshold(unsigned bus_idx, bool highlight)
1198 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::compressor_threshold_knob, highlight);
1201 void MainWindow::highlight_fader(unsigned bus_idx, bool highlight)
1203 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::fader, highlight);
1206 void MainWindow::highlight_mute(unsigned bus_idx, bool highlight)
1208 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::mute_button, highlight, /*is_mute_btton=*/true);
1211 void MainWindow::highlight_toggle_locut(unsigned bus_idx, bool highlight)
1213 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::locut_enabled, highlight);
1216 void MainWindow::highlight_toggle_auto_gain_staging(unsigned bus_idx, bool highlight)
1218 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::gainstaging_auto_checkbox, highlight);
1221 void MainWindow::highlight_toggle_compressor(unsigned bus_idx, bool highlight)
1223 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::compressor_enabled, highlight);
1226 void MainWindow::highlight_toggle_limiter(bool highlight)
1228 post_to_main_thread([this, highlight]{
1229 highlight_control(ui->limiter_enabled, highlight);
1230 highlight_control(ui->limiter_enabled_2, highlight);
1234 void MainWindow::highlight_toggle_auto_makeup_gain(bool highlight)
1236 post_to_main_thread([this, highlight]{
1237 highlight_control(ui->makeup_gain_auto_checkbox, highlight);
1238 highlight_control(ui->makeup_gain_auto_checkbox_2, highlight);
1243 void MainWindow::set_relative_value(T *control, float value)
1245 post_to_main_thread([control, value]{
1246 control->setValue(lrintf(control->minimum() + value * (control->maximum() - control->minimum())));
1251 void MainWindow::set_relative_value_if_exists(unsigned bus_idx, T *(Ui_AudioExpandedView::*control), float value)
1253 if (global_audio_mixer != nullptr &&
1254 global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL &&
1255 bus_idx < audio_expanded_views.size()) {
1256 set_relative_value(audio_expanded_views[bus_idx]->*control, value);
1261 void MainWindow::click_button_if_exists(unsigned bus_idx, T *(Ui_AudioExpandedView::*control))
1263 post_to_main_thread([this, bus_idx, control]{
1264 if (global_audio_mixer != nullptr &&
1265 global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL &&
1266 bus_idx < audio_expanded_views.size()) {
1267 (audio_expanded_views[bus_idx]->*control)->click();
1273 void MainWindow::highlight_control(T *control, bool highlight)
1275 if (control == nullptr) {
1278 if (global_audio_mixer == nullptr ||
1279 global_audio_mixer->get_mapping_mode() != AudioMixer::MappingMode::MULTICHANNEL) {
1283 control->setStyleSheet("background: rgb(0,255,0,80)");
1285 control->setStyleSheet("");
1290 void MainWindow::highlight_mute_control(T *control, bool highlight)
1292 if (control == nullptr) {
1295 if (global_audio_mixer == nullptr ||
1296 global_audio_mixer->get_mapping_mode() != AudioMixer::MappingMode::MULTICHANNEL) {
1300 control->setStyleSheet("QPushButton { background: rgb(0,255,0,80); } QPushButton:checked { background: rgba(255,80,0,140); }");
1302 control->setStyleSheet("QPushButton:checked { background: rgba(255,0,0,80); }");
1307 void MainWindow::highlight_control_if_exists(unsigned bus_idx, T *(Ui_AudioExpandedView::*control), bool highlight, bool is_mute_button)
1309 post_to_main_thread([this, bus_idx, control, highlight, is_mute_button]{
1310 if (bus_idx < audio_expanded_views.size()) {
1311 if (is_mute_button) {
1312 highlight_mute_control(audio_expanded_views[bus_idx]->*control, highlight);
1314 highlight_control(audio_expanded_views[bus_idx]->*control, highlight);
1320 void MainWindow::set_transition_names(vector<string> transition_names)
1322 if (transition_names.size() < 1 || transition_names[0].empty()) {
1323 transition_btn1->setText(QString(""));
1325 transition_btn1->setText(QString::fromStdString(transition_names[0] + " (J)"));
1326 ui->transition_btn1->setShortcut(QKeySequence("J"));
1328 if (transition_names.size() < 2 || transition_names[1].empty()) {
1329 transition_btn2->setText(QString(""));
1331 transition_btn2->setText(QString::fromStdString(transition_names[1] + " (K)"));
1332 ui->transition_btn2->setShortcut(QKeySequence("K"));
1334 if (transition_names.size() < 3 || transition_names[2].empty()) {
1335 transition_btn3->setText(QString(""));
1337 transition_btn3->setText(QString::fromStdString(transition_names[2] + " (L)"));
1338 ui->transition_btn3->setShortcut(QKeySequence("L"));
1342 void MainWindow::update_channel_name(Mixer::Output output, const string &name)
1344 if (output >= Mixer::OUTPUT_INPUT0) {
1345 unsigned channel = output - Mixer::OUTPUT_INPUT0;
1346 previews[channel]->label->setText(name.c_str());
1349 analyzer->update_channel_name(output, name);
1352 void MainWindow::update_channel_color(Mixer::Output output, const string &color)
1354 if (output >= Mixer::OUTPUT_INPUT0) {
1355 unsigned channel = output - Mixer::OUTPUT_INPUT0;
1356 previews[channel]->frame->setStyleSheet(QString::fromStdString("background-color:" + color));
1360 void MainWindow::transition_clicked(int transition_number)
1362 global_mixer->transition_clicked(transition_number);
1365 void MainWindow::channel_clicked(int channel_number)
1367 if (current_wb_pick_display == channel_number) {
1368 // The picking was already done from eventFilter(), since we don't get
1369 // the mouse pointer here.
1371 global_mixer->channel_clicked(channel_number);
1375 void MainWindow::quick_cut_activated(int channel_number)
1377 if (!global_flags.enable_quick_cut_keys) {
1380 global_mixer->channel_clicked(channel_number);
1381 global_mixer->transition_clicked(0);
1384 void MainWindow::wb_button_clicked(int channel_number)
1386 current_wb_pick_display = channel_number;
1387 QApplication::setOverrideCursor(Qt::CrossCursor);
1390 void MainWindow::audio_view_changed(int audio_view)
1392 if (audio_view == current_audio_view) {
1396 if (audio_view == 0) {
1397 // Compact audio view. (1, full audio view, has no video previews.)
1398 for (unsigned i = 0; i < previews.size(); ++i) {
1399 QWidget *display = static_cast<QWidget *>(previews[i]->frame->parent());
1400 ui->preview_displays->insertWidget(i, display, 1);
1402 } else if (audio_view == 2) {
1403 // Video grid display.
1404 for (unsigned i = 0; i < previews.size(); ++i) {
1405 QWidget *display = static_cast<QWidget *>(previews[i]->frame->parent());
1406 display->setParent(ui->preview_displays_grid);
1411 current_audio_view = audio_view;
1413 // Ask for a relayout, but only after the event loop is done doing relayout
1414 // on everything else.
1415 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
1418 bool MainWindow::eventFilter(QObject *watched, QEvent *event)
1420 if (current_wb_pick_display != -1 &&
1421 event->type() == QEvent::MouseButtonRelease &&
1422 watched->isWidgetType()) {
1423 QApplication::restoreOverrideCursor();
1424 if (watched == previews[current_wb_pick_display]->display) {
1425 const QMouseEvent *mouse_event = (QMouseEvent *)event;
1426 set_white_balance(current_wb_pick_display, mouse_event->x(), mouse_event->y());
1428 // The user clicked on something else, give up.
1429 // (The click goes through, which might not be ideal, but, yes.)
1430 current_wb_pick_display = -1;
1436 void MainWindow::closeEvent(QCloseEvent *event)
1438 if (global_mixer->get_num_connected_clients() > 0) {
1439 QMessageBox::StandardButton reply =
1440 QMessageBox::question(this, "Nageru", "There are clients connected. Do you really want to quit?",
1441 QMessageBox::Yes | QMessageBox::No);
1442 if (reply != QMessageBox::Yes) {
1454 double srgb_to_linear(double x)
1459 return pow((x + 0.055) / 1.055, 2.4);
1465 void MainWindow::set_white_balance(int channel_number, int x, int y)
1467 // Set the white balance to neutral for the grab. It's probably going to
1468 // flicker a bit, but hopefully this display is not live anyway.
1469 global_mixer->set_wb(Mixer::OUTPUT_INPUT0 + channel_number, 0.5, 0.5, 0.5);
1470 previews[channel_number]->display->updateGL();
1471 QRgb reference_color = previews[channel_number]->display->grabFrameBuffer().pixel(x, y);
1473 double r = srgb_to_linear(qRed(reference_color) / 255.0);
1474 double g = srgb_to_linear(qGreen(reference_color) / 255.0);
1475 double b = srgb_to_linear(qBlue(reference_color) / 255.0);
1476 global_mixer->set_wb(Mixer::OUTPUT_INPUT0 + channel_number, r, g, b);
1477 previews[channel_number]->display->updateGL();
1480 void MainWindow::audio_state_changed()
1482 post_to_main_thread([this]{
1483 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
1486 InputMapping mapping = global_audio_mixer->get_input_mapping();
1487 for (unsigned bus_index = 0; bus_index < mapping.buses.size(); ++bus_index) {
1488 const InputMapping::Bus &bus = mapping.buses[bus_index];
1490 if (bus.device.type == InputSourceType::ALSA_INPUT) {
1491 ALSAPool::Device::State state = global_audio_mixer->get_alsa_card_state(bus.device.index);
1492 if (state == ALSAPool::Device::State::STARTING) {
1494 } else if (state == ALSAPool::Device::State::DEAD) {
1499 audio_miniviews[bus_index]->bus_desc_label->setFullText(
1500 QString::fromStdString(bus.name + suffix));
1501 audio_expanded_views[bus_index]->bus_desc_label->setFullText(
1502 QString::fromStdString(bus.name + suffix));