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_WITH_SIGN = 0x1;
133 constexpr unsigned DB_BARE = 0x2;
135 string format_db(double db, unsigned flags)
138 if (flags & DB_WITH_SIGN) {
141 snprintf(buf, sizeof(buf), "%+.1f", db);
143 } else if (db < 0.0) {
146 // Should never happen, really.
152 snprintf(buf, sizeof(buf), "%.1f", db);
154 } else if (db < 0.0) {
157 // Should never happen, really.
161 if (!(flags & DB_BARE)) {
167 void set_peak_label(QLabel *peak_label, float peak_db)
169 peak_label->setText(QString::fromStdString(format_db(peak_db, DB_BARE)));
171 if (peak_db > peak_limit_dbfs) {
172 peak_label->setStyleSheet("QLabel { background-color: red; color: white; }");
174 peak_label->setStyleSheet("");
178 string get_bus_desc_label(const InputMapping::Bus &bus)
181 if (bus.device.type == InputSourceType::ALSA_INPUT) {
182 ALSAPool::Device::State state = global_audio_mixer->get_alsa_card_state(bus.device.index);
183 if (state == ALSAPool::Device::State::STARTING) {
185 } else if (state == ALSAPool::Device::State::DEAD) {
190 return bus.name + suffix;
195 MainWindow::MainWindow()
196 : ui(new Ui::MainWindow), midi_mapper(this)
198 global_mainwindow = this;
201 global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2));
202 disk_free_label = new QLabel(this);
203 disk_free_label->setStyleSheet("QLabel {padding-right: 5px;}");
204 ui->menuBar->setCornerWidget(disk_free_label);
206 QActionGroup *audio_mapping_group = new QActionGroup(this);
207 ui->simple_audio_mode->setActionGroup(audio_mapping_group);
208 ui->multichannel_audio_mode->setActionGroup(audio_mapping_group);
210 ui->me_live->set_output(Mixer::OUTPUT_LIVE);
211 ui->me_preview->set_output(Mixer::OUTPUT_PREVIEW);
214 connect(ui->cut_action, &QAction::triggered, this, &MainWindow::cut_triggered);
215 connect(ui->exit_action, &QAction::triggered, this, &MainWindow::exit_triggered);
216 connect(ui->manual_action, &QAction::triggered, this, &MainWindow::manual_triggered);
217 connect(ui->about_action, &QAction::triggered, this, &MainWindow::about_triggered);
218 connect(ui->open_analyzer_action, &QAction::triggered, this, &MainWindow::open_analyzer_triggered);
219 connect(ui->simple_audio_mode, &QAction::triggered, this, &MainWindow::simple_audio_mode_triggered);
220 connect(ui->multichannel_audio_mode, &QAction::triggered, this, &MainWindow::multichannel_audio_mode_triggered);
221 connect(ui->input_mapping_action, &QAction::triggered, this, &MainWindow::input_mapping_triggered);
222 connect(ui->midi_mapping_action, &QAction::triggered, this, &MainWindow::midi_mapping_triggered);
223 connect(ui->timecode_stream_action, &QAction::triggered, this, &MainWindow::timecode_stream_triggered);
224 connect(ui->timecode_stdout_action, &QAction::triggered, this, &MainWindow::timecode_stdout_triggered);
226 ui->timecode_stream_action->setChecked(global_flags.display_timecode_in_stream);
227 ui->timecode_stdout_action->setChecked(global_flags.display_timecode_on_stdout);
229 if (global_flags.x264_video_to_http && isinf(global_flags.x264_crf)) {
230 connect(ui->x264_bitrate_action, &QAction::triggered, this, &MainWindow::x264_bitrate_triggered);
232 ui->x264_bitrate_action->setEnabled(false);
235 connect(ui->video_menu, &QMenu::aboutToShow, [this]{
236 fill_hdmi_sdi_output_device_menu(ui->hdmi_sdi_output_device_menu);
237 fill_hdmi_sdi_output_resolution_menu(ui->hdmi_sdi_output_resolution_menu);
240 // Hook up the transition buttons. (Keyboard shortcuts are set in set_transition_names().)
241 // TODO: Make them dynamic.
242 connect(ui->transition_btn1, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 0));
243 connect(ui->transition_btn2, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 1));
244 connect(ui->transition_btn3, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 2));
247 transition_btn1 = ui->transition_btn1;
248 transition_btn2 = ui->transition_btn2;
249 transition_btn3 = ui->transition_btn3;
250 qRegisterMetaType<string>("std::string");
251 qRegisterMetaType<vector<string>>("std::vector<std::string>");
252 connect(ui->me_live, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names);
253 qRegisterMetaType<Mixer::Output>("Mixer::Output");
255 // Hook up the prev/next buttons on the audio views.
256 auto prev_page = [this]{
257 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
258 ui->audio_views->setCurrentIndex((ui->audio_views->currentIndex() + 2) % 3);
260 ui->audio_views->setCurrentIndex(2 - ui->audio_views->currentIndex()); // Switch between 0 and 2.
263 auto next_page = [this]{
264 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
265 ui->audio_views->setCurrentIndex((ui->audio_views->currentIndex() + 1) % 3);
267 ui->audio_views->setCurrentIndex(2 - ui->audio_views->currentIndex()); // Switch between 0 and 2.
270 connect(ui->compact_prev_page, &QAbstractButton::clicked, prev_page);
271 connect(ui->compact_next_page, &QAbstractButton::clicked, next_page);
272 connect(ui->full_prev_page, &QAbstractButton::clicked, prev_page);
273 connect(ui->full_next_page, &QAbstractButton::clicked, next_page);
274 connect(ui->video_grid_prev_page, &QAbstractButton::clicked, prev_page);
275 connect(ui->video_grid_next_page, &QAbstractButton::clicked, next_page);
277 // And bind the same to PgUp/PgDown.
278 connect(new QShortcut(QKeySequence::MoveToNextPage, this), &QShortcut::activated, next_page);
279 connect(new QShortcut(QKeySequence::MoveToPreviousPage, this), &QShortcut::activated, prev_page);
281 // When the audio view changes, move the previews.
282 connect(ui->audio_views, &QStackedWidget::currentChanged, bind(&MainWindow::audio_view_changed, this, _1));
284 if (global_flags.enable_quick_cut_keys) {
285 ui->quick_cut_enable_action->setChecked(true);
287 connect(ui->quick_cut_enable_action, &QAction::changed, [this](){
288 global_flags.enable_quick_cut_keys = ui->quick_cut_enable_action->isChecked();
291 last_audio_level_callback = steady_clock::now() - seconds(1);
293 if (!global_flags.midi_mapping_filename.empty()) {
294 MIDIMappingProto midi_mapping;
295 if (!load_midi_mapping_from_file(global_flags.midi_mapping_filename, &midi_mapping)) {
296 fprintf(stderr, "Couldn't load MIDI mapping '%s'; exiting.\n",
297 global_flags.midi_mapping_filename.c_str());
300 midi_mapper.set_midi_mapping(midi_mapping);
302 midi_mapper.refresh_highlights();
303 midi_mapper.refresh_lights();
306 void MainWindow::resizeEvent(QResizeEvent* event)
308 QMainWindow::resizeEvent(event);
310 // Ask for a relayout, but only after the event loop is done doing relayout
311 // on everything else.
312 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
315 void MainWindow::mixer_created(Mixer *mixer)
317 // Make the previews.
318 unsigned num_previews = mixer->get_num_channels();
320 const char qwerty[] = "QWERTYUIOP";
321 for (unsigned i = 0; i < num_previews; ++i) {
322 Mixer::Output output = Mixer::Output(Mixer::OUTPUT_INPUT0 + i);
324 QWidget *preview = new QWidget(this); // Will be connected to a layout immediately after the loop.
325 Ui::Display *ui_display = new Ui::Display;
326 ui_display->setupUi(preview);
327 ui_display->label->setText(mixer->get_channel_name(output).c_str());
328 ui_display->display->set_output(output);
329 previews.push_back(ui_display);
331 // Hook up the click.
332 connect(ui_display->display, &GLWidget::clicked, bind(&MainWindow::channel_clicked, this, i));
334 // Let the theme update the text whenever the resolution or color changed.
335 connect(ui_display->display, &GLWidget::name_updated, this, &MainWindow::update_channel_name);
336 connect(ui_display->display, &GLWidget::color_updated, this, &MainWindow::update_channel_color);
338 // Hook up the keyboard key.
339 QShortcut *shortcut = nullptr;
341 shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
343 shortcut = new QShortcut(QKeySequence(Qt::Key_0), this);
345 if (shortcut != nullptr) {
346 connect(shortcut, &QShortcut::activated, bind(&MainWindow::channel_clicked, this, i));
349 // Hook up the quick-cut key.
350 if (i < strlen(qwerty)) {
351 QShortcut *shortcut = new QShortcut(QKeySequence(qwerty[i]), this);
352 connect(shortcut, &QShortcut::activated, bind(&MainWindow::quick_cut_activated, this, i));
355 // Hook up the white balance button (irrelevant if invisible).
356 ui_display->wb_button->setVisible(mixer->get_supports_set_wb(output));
357 connect(ui_display->wb_button, &QPushButton::clicked, bind(&MainWindow::wb_button_clicked, this, i));
360 // Connect the previews to the correct layout.
361 audio_view_changed(ui->audio_views->currentIndex());
363 global_audio_mixer->set_state_changed_callback(bind(&MainWindow::audio_state_changed, this));
365 slave_knob(ui->locut_cutoff_knob, ui->locut_cutoff_knob_2);
366 slave_knob(ui->limiter_threshold_knob, ui->limiter_threshold_knob_2);
367 slave_knob(ui->makeup_gain_knob, ui->makeup_gain_knob_2);
368 slave_checkbox(ui->makeup_gain_auto_checkbox, ui->makeup_gain_auto_checkbox_2);
369 slave_checkbox(ui->limiter_enabled, ui->limiter_enabled_2);
371 reset_audio_mapping_ui();
373 // TODO: Fetch all of the values these for completeness,
374 // not just the enable knobs implied by flags.
375 ui->limiter_enabled->setChecked(global_audio_mixer->get_limiter_enabled());
376 ui->makeup_gain_auto_checkbox->setChecked(global_audio_mixer->get_final_makeup_gain_auto());
378 // Controls used only for simple audio fetch their state from the first bus.
379 constexpr unsigned simple_bus_index = 0;
380 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
381 ui->locut_enabled->setChecked(global_audio_mixer->get_locut_enabled(simple_bus_index));
382 ui->gainstaging_knob->setValue(global_audio_mixer->get_gain_staging_db(simple_bus_index));
383 ui->gainstaging_auto_checkbox->setChecked(global_audio_mixer->get_gain_staging_auto(simple_bus_index));
384 ui->compressor_enabled->setChecked(global_audio_mixer->get_compressor_enabled(simple_bus_index));
385 ui->compressor_threshold_db_display->setText(
386 QString::fromStdString(format_db(mixer->get_audio_mixer()->get_compressor_threshold_dbfs(simple_bus_index), DB_WITH_SIGN)));
388 connect(ui->locut_enabled, &QCheckBox::stateChanged, [this](int state){
389 global_audio_mixer->set_locut_enabled(simple_bus_index, state == Qt::Checked);
390 midi_mapper.refresh_lights();
392 connect(ui->gainstaging_knob, &QAbstractSlider::valueChanged,
393 bind(&MainWindow::gain_staging_knob_changed, this, simple_bus_index, _1));
394 connect(ui->gainstaging_auto_checkbox, &QCheckBox::stateChanged, [this](int state){
395 global_audio_mixer->set_gain_staging_auto(simple_bus_index, state == Qt::Checked);
396 midi_mapper.refresh_lights();
398 connect(ui->compressor_threshold_knob, &QDial::valueChanged,
399 bind(&MainWindow::compressor_threshold_knob_changed, this, simple_bus_index, _1));
400 connect(ui->compressor_enabled, &QCheckBox::stateChanged, [this](int state){
401 global_audio_mixer->set_compressor_enabled(simple_bus_index, state == Qt::Checked);
402 midi_mapper.refresh_lights();
405 // Global mastering controls.
406 QString limiter_threshold_label(
407 QString::fromStdString(format_db(mixer->get_audio_mixer()->get_limiter_threshold_dbfs(), DB_WITH_SIGN)));
408 ui->limiter_threshold_db_display->setText(limiter_threshold_label);
409 ui->limiter_threshold_db_display_2->setText(limiter_threshold_label);
411 connect(ui->locut_cutoff_knob, &QDial::valueChanged, this, &MainWindow::cutoff_knob_changed);
412 cutoff_knob_changed(ui->locut_cutoff_knob->value());
414 connect(ui->makeup_gain_knob, &QAbstractSlider::valueChanged, this, &MainWindow::final_makeup_gain_knob_changed);
415 connect(ui->makeup_gain_auto_checkbox, &QCheckBox::stateChanged, [this](int state){
416 global_audio_mixer->set_final_makeup_gain_auto(state == Qt::Checked);
417 midi_mapper.refresh_lights();
420 connect(ui->limiter_threshold_knob, &QDial::valueChanged, this, &MainWindow::limiter_threshold_knob_changed);
421 connect(ui->limiter_enabled, &QCheckBox::stateChanged, [this](int state){
422 global_audio_mixer->set_limiter_enabled(state == Qt::Checked);
423 midi_mapper.refresh_lights();
425 connect(ui->reset_meters_button, &QPushButton::clicked, this, &MainWindow::reset_meters_button_clicked);
426 // Even though we have a reset button right next to it, the fact that
427 // the expanded audio view labels are clickable makes it natural to
428 // click this one as well.
429 connect(ui->peak_display, &ClickableLabel::clicked, this, &MainWindow::reset_meters_button_clicked);
430 mixer->get_audio_mixer()->set_audio_level_callback(bind(&MainWindow::audio_level_callback, this, _1, _2, _3, _4, _5, _6, _7, _8));
432 midi_mapper.refresh_highlights();
433 midi_mapper.refresh_lights();
434 midi_mapper.start_thread();
436 analyzer.reset(new Analyzer);
438 global_mixer->set_theme_menu_callback(bind(&MainWindow::setup_theme_menu, this));
441 struct sigaction act;
442 memset(&act, 0, sizeof(act));
443 act.sa_handler = schedule_cut_signal;
444 act.sa_flags = SA_RESTART;
445 sigaction(SIGHUP, &act, nullptr);
447 // Mostly for debugging. Don't override SIGINT, that's so evil if
448 // shutdown isn't instant.
449 memset(&act, 0, sizeof(act));
450 act.sa_handler = quit_signal;
451 act.sa_flags = SA_RESTART;
452 sigaction(SIGUSR1, &act, nullptr);
455 void MainWindow::reset_audio_mapping_ui()
457 bool simple = (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE);
459 ui->simple_audio_mode->setChecked(simple);
460 ui->multichannel_audio_mode->setChecked(!simple);
461 ui->input_mapping_action->setEnabled(!simple);
462 ui->midi_mapping_action->setEnabled(!simple);
464 ui->locut_enabled->setVisible(simple);
465 ui->gainstaging_label->setVisible(simple);
466 ui->gainstaging_knob->setVisible(simple);
467 ui->gainstaging_db_display->setVisible(simple);
468 ui->gainstaging_auto_checkbox->setVisible(simple);
469 ui->compressor_threshold_label->setVisible(simple);
470 ui->compressor_threshold_knob->setVisible(simple);
471 ui->compressor_threshold_db_display->setVisible(simple);
472 ui->compressor_enabled->setVisible(simple);
474 setup_audio_miniview();
475 setup_audio_expanded_view();
478 ui->compact_label->setText("Compact audio view (1/2) ");
479 ui->video_grid_label->setText("Video grid display (2/2) ");
480 if (ui->audio_views->currentIndex() == 1) {
481 // Full audio view is not available in simple mode.
482 ui->audio_views->setCurrentIndex(0);
485 ui->compact_label->setText("Compact audio view (1/3) ");
486 ui->full_label->setText("Full audio view (2/3) ");
487 ui->video_grid_label->setText("Video grid display (3/3) ");
490 midi_mapper.refresh_highlights();
491 midi_mapper.refresh_lights();
494 void MainWindow::setup_audio_miniview()
496 // Remove any existing channels.
497 for (QLayoutItem *item; (item = ui->faders->takeAt(0)) != nullptr; ) {
498 delete item->widget();
501 audio_miniviews.clear();
503 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
507 // Set up brand new ones from the input mapping.
508 InputMapping mapping = global_audio_mixer->get_input_mapping();
509 audio_miniviews.resize(mapping.buses.size());
510 for (unsigned bus_index = 0; bus_index < mapping.buses.size(); ++bus_index) {
511 QWidget *channel = new QWidget(this);
512 Ui::AudioMiniView *ui_audio_miniview = new Ui::AudioMiniView;
513 ui_audio_miniview->setupUi(channel);
514 ui_audio_miniview->bus_desc_label->setFullText(
515 QString::fromStdString(get_bus_desc_label(mapping.buses[bus_index])));
516 audio_miniviews[bus_index] = ui_audio_miniview;
518 // Set up the peak meter.
519 VUMeter *peak_meter = ui_audio_miniview->peak_meter;
520 peak_meter->set_min_level(-30.0f);
521 peak_meter->set_max_level(0.0f);
522 peak_meter->set_ref_level(0.0f);
524 ui_audio_miniview->fader->setDbValue(global_audio_mixer->get_fader_volume(bus_index));
526 ui->faders->addWidget(channel);
528 connect(ui_audio_miniview->fader, &NonLinearFader::dbValueChanged,
529 bind(&MainWindow::mini_fader_changed, this, bus_index, _1));
530 connect(ui_audio_miniview->peak_display_label, &ClickableLabel::clicked,
532 global_audio_mixer->reset_peak(bus_index);
537 void MainWindow::setup_audio_expanded_view()
539 // Remove any existing channels.
540 for (QLayoutItem *item; (item = ui->buses->takeAt(0)) != nullptr; ) {
541 delete item->widget();
544 audio_expanded_views.clear();
546 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
550 // Set up brand new ones from the input mapping.
551 InputMapping mapping = global_audio_mixer->get_input_mapping();
552 audio_expanded_views.resize(mapping.buses.size());
553 for (unsigned bus_index = 0; bus_index < mapping.buses.size(); ++bus_index) {
554 QWidget *channel = new QWidget(this);
555 Ui::AudioExpandedView *ui_audio_expanded_view = new Ui::AudioExpandedView;
556 ui_audio_expanded_view->setupUi(channel);
557 ui_audio_expanded_view->bus_desc_label->setFullText(
558 QString::fromStdString(get_bus_desc_label(mapping.buses[bus_index])));
559 audio_expanded_views[bus_index] = ui_audio_expanded_view;
560 update_stereo_knob_and_label(bus_index, lrintf(100.0f * global_audio_mixer->get_stereo_width(bus_index)));
561 update_eq_label(bus_index, EQ_BAND_TREBLE, global_audio_mixer->get_eq(bus_index, EQ_BAND_TREBLE));
562 update_eq_label(bus_index, EQ_BAND_MID, global_audio_mixer->get_eq(bus_index, EQ_BAND_MID));
563 update_eq_label(bus_index, EQ_BAND_BASS, global_audio_mixer->get_eq(bus_index, EQ_BAND_BASS));
564 ui_audio_expanded_view->fader->setDbValue(global_audio_mixer->get_fader_volume(bus_index));
565 ui_audio_expanded_view->mute_button->setChecked(global_audio_mixer->get_mute(bus_index));
566 connect(ui_audio_expanded_view->mute_button, &QPushButton::toggled,
567 bind(&MainWindow::mute_button_toggled, this, bus_index, _1));
568 ui->buses->addWidget(channel);
570 ui_audio_expanded_view->locut_enabled->setChecked(global_audio_mixer->get_locut_enabled(bus_index));
571 connect(ui_audio_expanded_view->locut_enabled, &QCheckBox::stateChanged, [this, bus_index](int state){
572 global_audio_mixer->set_locut_enabled(bus_index, state == Qt::Checked);
573 midi_mapper.refresh_lights();
576 connect(ui_audio_expanded_view->stereo_width_knob, &QDial::valueChanged,
577 bind(&MainWindow::stereo_width_knob_changed, this, bus_index, _1));
579 connect(ui_audio_expanded_view->treble_knob, &QDial::valueChanged,
580 bind(&MainWindow::eq_knob_changed, this, bus_index, EQ_BAND_TREBLE, _1));
581 connect(ui_audio_expanded_view->mid_knob, &QDial::valueChanged,
582 bind(&MainWindow::eq_knob_changed, this, bus_index, EQ_BAND_MID, _1));
583 connect(ui_audio_expanded_view->bass_knob, &QDial::valueChanged,
584 bind(&MainWindow::eq_knob_changed, this, bus_index, EQ_BAND_BASS, _1));
586 ui_audio_expanded_view->gainstaging_knob->setValue(global_audio_mixer->get_gain_staging_db(bus_index));
587 ui_audio_expanded_view->gainstaging_auto_checkbox->setChecked(global_audio_mixer->get_gain_staging_auto(bus_index));
588 ui_audio_expanded_view->compressor_enabled->setChecked(global_audio_mixer->get_compressor_enabled(bus_index));
590 connect(ui_audio_expanded_view->gainstaging_knob, &QAbstractSlider::valueChanged, bind(&MainWindow::gain_staging_knob_changed, this, bus_index, _1));
591 connect(ui_audio_expanded_view->gainstaging_auto_checkbox, &QCheckBox::stateChanged, [this, bus_index](int state){
592 global_audio_mixer->set_gain_staging_auto(bus_index, state == Qt::Checked);
593 midi_mapper.refresh_lights();
596 connect(ui_audio_expanded_view->compressor_threshold_knob, &QDial::valueChanged, bind(&MainWindow::compressor_threshold_knob_changed, this, bus_index, _1));
597 connect(ui_audio_expanded_view->compressor_enabled, &QCheckBox::stateChanged, [this, bus_index](int state){
598 global_audio_mixer->set_compressor_enabled(bus_index, state == Qt::Checked);
599 midi_mapper.refresh_lights();
602 slave_fader(audio_miniviews[bus_index]->fader, ui_audio_expanded_view->fader);
604 // Set up the peak meter.
605 VUMeter *peak_meter = ui_audio_expanded_view->peak_meter;
606 peak_meter->set_min_level(-30.0f);
607 peak_meter->set_max_level(0.0f);
608 peak_meter->set_ref_level(0.0f);
610 connect(ui_audio_expanded_view->peak_display_label, &ClickableLabel::clicked,
611 [this, bus_index]() {
612 global_audio_mixer->reset_peak(bus_index);
613 midi_mapper.refresh_lights();
617 update_cutoff_labels(global_audio_mixer->get_locut_cutoff());
620 void MainWindow::mixer_shutting_down()
622 ui->me_live->shutdown();
623 ui->me_preview->shutdown();
625 for (Ui::Display *display : previews) {
626 display->display->shutdown();
629 analyzer->mixer_shutting_down();
632 void MainWindow::cut_triggered()
634 global_mixer->schedule_cut();
637 void MainWindow::x264_bitrate_triggered()
640 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);
641 if (ok && new_bitrate >= 100 && new_bitrate <= 100000) {
642 global_flags.x264_bitrate = new_bitrate;
643 global_mixer->change_x264_bitrate(new_bitrate);
647 void MainWindow::exit_triggered()
652 void MainWindow::manual_triggered()
654 if (!QDesktopServices::openUrl(QUrl("https://nageru.sesse.net/doc/"))) {
656 msgbox.setText("Could not launch manual in web browser.\nPlease see https://nageru.sesse.net/doc/ manually.");
661 void MainWindow::about_triggered()
663 AboutDialog().exec();
666 void MainWindow::open_analyzer_triggered()
671 void MainWindow::simple_audio_mode_triggered()
673 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
676 unsigned card_index = global_audio_mixer->get_simple_input();
677 if (card_index == numeric_limits<unsigned>::max()) {
678 QMessageBox::StandardButton reply =
679 QMessageBox::question(this,
680 "Mapping too complex",
681 "The current audio mapping is too complicated to be representable in simple mode, "
682 "and will be discarded if you proceed. Really go to simple audio mode?",
683 QMessageBox::Yes | QMessageBox::No);
684 if (reply == QMessageBox::No) {
685 ui->simple_audio_mode->setChecked(false);
686 ui->multichannel_audio_mode->setChecked(true);
691 global_audio_mixer->set_simple_input(/*card_index=*/card_index);
692 reset_audio_mapping_ui();
695 void MainWindow::multichannel_audio_mode_triggered()
697 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
701 // Take the generated input mapping from the simple input,
702 // and set it as a normal multichannel mapping, which causes
703 // the mode to go to multichannel.
704 global_audio_mixer->set_input_mapping(global_audio_mixer->get_input_mapping());
705 reset_audio_mapping_ui();
708 void MainWindow::input_mapping_triggered()
710 if (InputMappingDialog().exec() == QDialog::Accepted) {
711 setup_audio_miniview();
712 setup_audio_expanded_view();
714 midi_mapper.refresh_highlights();
715 midi_mapper.refresh_lights();
718 void MainWindow::midi_mapping_triggered()
720 MIDIMappingDialog(&midi_mapper).exec();
723 void MainWindow::timecode_stream_triggered()
725 global_mixer->set_display_timecode_in_stream(ui->timecode_stream_action->isChecked());
728 void MainWindow::timecode_stdout_triggered()
730 global_mixer->set_display_timecode_on_stdout(ui->timecode_stdout_action->isChecked());
733 void MainWindow::gain_staging_knob_changed(unsigned bus_index, int value)
735 if (bus_index == 0) {
736 ui->gainstaging_auto_checkbox->setCheckState(Qt::Unchecked);
738 if (bus_index < audio_expanded_views.size()) {
739 audio_expanded_views[bus_index]->gainstaging_auto_checkbox->setCheckState(Qt::Unchecked);
742 float gain_db = value * 0.1f;
743 global_audio_mixer->set_gain_staging_db(bus_index, gain_db);
745 // The label will be updated by the audio level callback.
748 void MainWindow::final_makeup_gain_knob_changed(int value)
750 ui->makeup_gain_auto_checkbox->setCheckState(Qt::Unchecked);
752 float gain_db = value * 0.1f;
753 global_audio_mixer->set_final_makeup_gain_db(gain_db);
755 // The label will be updated by the audio level callback.
758 void MainWindow::cutoff_knob_changed(int value)
760 float octaves = value * 0.1f;
761 float cutoff_hz = 20.0 * pow(2.0, octaves);
762 global_audio_mixer->set_locut_cutoff(cutoff_hz);
763 update_cutoff_labels(cutoff_hz);
766 void MainWindow::update_cutoff_labels(float cutoff_hz)
769 snprintf(buf, sizeof(buf), "%ld Hz", lrintf(cutoff_hz));
770 ui->locut_cutoff_display->setText(buf);
771 ui->locut_cutoff_display_2->setText(buf);
773 for (unsigned bus_index = 0; bus_index < audio_expanded_views.size(); ++bus_index) {
774 audio_expanded_views[bus_index]->locut_enabled->setText(
775 QString("Lo-cut: ") + buf);
779 void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
782 if (estimated_seconds_left < 60.0) {
783 strcpy(time_str, "<font color=\"red\">Less than a minute</font>");
784 } else if (estimated_seconds_left < 1800.0) { // Less than half an hour: Xm Ys (red).
785 int s = lrintf(estimated_seconds_left);
788 snprintf(time_str, sizeof(time_str), "<font color=\"red\">%dm %ds</font>", m, s);
789 } else if (estimated_seconds_left < 3600.0) { // Less than an hour: Xm.
790 int m = lrintf(estimated_seconds_left / 60.0);
791 snprintf(time_str, sizeof(time_str), "%dm", m);
792 } else if (estimated_seconds_left < 36000.0) { // Less than ten hours: Xh Ym.
793 int m = lrintf(estimated_seconds_left / 60.0);
796 snprintf(time_str, sizeof(time_str), "%dh %dm", h, m);
797 } else { // More than ten hours: Xh.
798 int h = lrintf(estimated_seconds_left / 3600.0);
799 snprintf(time_str, sizeof(time_str), "%dh", h);
802 snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str);
804 std::string label = buf;
806 post_to_main_thread([this, label]{
807 disk_free_label->setText(QString::fromStdString(label));
808 ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right.
812 void MainWindow::stereo_width_knob_changed(unsigned bus_index, int value)
814 float stereo_width = value * 0.01f;
815 global_audio_mixer->set_stereo_width(bus_index, stereo_width);
817 update_stereo_label(bus_index, value);
820 void MainWindow::eq_knob_changed(unsigned bus_index, EQBand band, int value)
822 float gain_db = value * 0.1f;
823 global_audio_mixer->set_eq(bus_index, band, gain_db);
825 update_eq_label(bus_index, band, gain_db);
828 void MainWindow::update_stereo_knob_and_label(unsigned bus_index, int stereo_width_percent)
830 Ui::AudioExpandedView *view = audio_expanded_views[bus_index];
832 if (global_audio_mixer->is_mono(bus_index)) {
833 view->stereo_width_knob->setEnabled(false);
834 view->stereo_width_label->setEnabled(false);
836 view->stereo_width_knob->setEnabled(true);
837 view->stereo_width_label->setEnabled(true);
839 view->stereo_width_knob->setValue(stereo_width_percent);
840 update_stereo_label(bus_index, stereo_width_percent);
843 void MainWindow::update_stereo_label(unsigned bus_index, int stereo_width_percent)
845 Ui::AudioExpandedView *view = audio_expanded_views[bus_index];
847 if (global_audio_mixer->is_mono(bus_index)) {
848 view->stereo_width_label->setText("Mono");
851 snprintf(buf, sizeof(buf), "Stereo: %d%%", stereo_width_percent);
852 view->stereo_width_label->setText(buf);
856 void MainWindow::update_eq_label(unsigned bus_index, EQBand band, float gain_db)
858 Ui::AudioExpandedView *view = audio_expanded_views[bus_index];
859 string db_string = format_db(gain_db, DB_WITH_SIGN);
862 view->treble_label->setText(QString::fromStdString("Treble: " + db_string));
865 view->mid_label->setText(QString::fromStdString("Mid: " + db_string));
868 view->bass_label->setText(QString::fromStdString("Bass: " + db_string));
875 void MainWindow::setup_theme_menu()
877 std::vector<Theme::MenuEntry> theme_menu_entries = global_mixer->get_theme_menu();
879 if (theme_menu != nullptr) {
880 ui->menuBar->removeAction(theme_menu->menuAction());
881 theme_menu = nullptr;
884 if (!theme_menu_entries.empty()) {
885 theme_menu = new QMenu("&Theme");
886 for (const Theme::MenuEntry &entry : theme_menu_entries) {
887 QAction *action = theme_menu->addAction(QString::fromStdString(entry.text));
888 connect(action, &QAction::triggered, [entry] {
889 global_mixer->theme_menu_entry_clicked(entry.lua_ref);
892 ui->menuBar->insertMenu(ui->menu_Help->menuAction(), theme_menu);
896 void MainWindow::limiter_threshold_knob_changed(int value)
898 float threshold_dbfs = value * 0.1f;
899 global_audio_mixer->set_limiter_threshold_dbfs(threshold_dbfs);
900 ui->limiter_threshold_db_display->setText(
901 QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
902 ui->limiter_threshold_db_display_2->setText(
903 QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
906 void MainWindow::compressor_threshold_knob_changed(unsigned bus_index, int value)
908 float threshold_dbfs = value * 0.1f;
909 global_audio_mixer->set_compressor_threshold_dbfs(bus_index, threshold_dbfs);
911 QString label(QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
912 if (bus_index == 0) {
913 ui->compressor_threshold_db_display->setText(label);
915 if (bus_index < audio_expanded_views.size()) {
916 audio_expanded_views[bus_index]->compressor_threshold_db_display->setText(label);
920 void MainWindow::mini_fader_changed(int bus, double volume_db)
922 QString label(QString::fromStdString(format_db(volume_db, DB_WITH_SIGN)));
923 audio_miniviews[bus]->fader_label->setText(label);
924 audio_expanded_views[bus]->fader_label->setText(label);
926 global_audio_mixer->set_fader_volume(bus, volume_db);
929 void MainWindow::mute_button_toggled(int bus, bool checked)
931 global_audio_mixer->set_mute(bus, checked);
932 midi_mapper.refresh_lights();
935 void MainWindow::reset_meters_button_clicked()
937 global_audio_mixer->reset_meters();
938 ui->peak_display->setText(QString::fromStdString(format_db(-HUGE_VAL, DB_WITH_SIGN | DB_BARE)));
939 ui->peak_display->setStyleSheet("");
942 void MainWindow::audio_level_callback(float level_lufs, float peak_db, vector<AudioMixer::BusLevel> bus_levels,
943 float global_level_lufs,
944 float range_low_lufs, float range_high_lufs,
945 float final_makeup_gain_db,
948 steady_clock::time_point now = steady_clock::now();
950 // The meters are somewhat inefficient to update. Only update them
951 // every 100 ms or so (we get updates every 5–20 ms). Note that this
952 // means that the digital peak meters are ever so slightly too low
953 // (each update won't be a faithful representation of the highest peak
954 // since the previous update, since there are frames we won't draw),
955 // but the _peak_ of the peak meters will be correct (it's tracked in
956 // AudioMixer, not here), and that's much more important.
957 double last_update_age = duration<double>(now - last_audio_level_callback).count();
958 if (last_update_age < 0.100) {
961 last_audio_level_callback = now;
963 post_to_main_thread([=]() {
964 ui->vu_meter->set_level(level_lufs);
965 for (unsigned bus_index = 0; bus_index < bus_levels.size(); ++bus_index) {
966 if (bus_index < audio_miniviews.size()) {
967 const AudioMixer::BusLevel &level = bus_levels[bus_index];
968 Ui::AudioMiniView *miniview = audio_miniviews[bus_index];
969 miniview->peak_meter->set_level(
970 level.current_level_dbfs[0], level.current_level_dbfs[1]);
971 miniview->peak_meter->set_peak(
972 level.peak_level_dbfs[0], level.peak_level_dbfs[1]);
973 set_peak_label(miniview->peak_display_label, level.historic_peak_dbfs);
975 Ui::AudioExpandedView *view = audio_expanded_views[bus_index];
976 view->peak_meter->set_level(
977 level.current_level_dbfs[0], level.current_level_dbfs[1]);
978 view->peak_meter->set_peak(
979 level.peak_level_dbfs[0], level.peak_level_dbfs[1]);
980 view->reduction_meter->set_reduction_db(level.compressor_attenuation_db);
981 view->gainstaging_knob->blockSignals(true);
982 view->gainstaging_knob->setValue(lrintf(level.gain_staging_db * 10.0f));
983 view->gainstaging_knob->blockSignals(false);
984 view->gainstaging_db_display->setText(
986 QString::fromStdString(format_db(level.gain_staging_db, DB_WITH_SIGN)));
987 set_peak_label(view->peak_display_label, level.historic_peak_dbfs);
989 midi_mapper.set_has_peaked(bus_index, level.historic_peak_dbfs >= -0.1f);
992 ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
993 ui->correlation_meter->set_correlation(correlation);
995 ui->peak_display->setText(QString::fromStdString(format_db(peak_db, DB_BARE)));
996 set_peak_label(ui->peak_display, peak_db);
998 // NOTE: Will be invisible when using multitrack audio.
999 if (!bus_levels.empty()) {
1000 ui->gainstaging_knob->blockSignals(true);
1001 ui->gainstaging_knob->setValue(lrintf(bus_levels[0].gain_staging_db * 10.0f));
1002 ui->gainstaging_knob->blockSignals(false);
1003 ui->gainstaging_db_display->setText(
1004 QString::fromStdString(format_db(bus_levels[0].gain_staging_db, DB_WITH_SIGN)));
1007 ui->makeup_gain_knob->blockSignals(true);
1008 ui->makeup_gain_knob->setValue(lrintf(final_makeup_gain_db * 10.0f));
1009 ui->makeup_gain_knob->blockSignals(false);
1010 ui->makeup_gain_db_display->setText(
1011 QString::fromStdString(format_db(final_makeup_gain_db, DB_WITH_SIGN)));
1012 ui->makeup_gain_db_display_2->setText(
1013 QString::fromStdString(format_db(final_makeup_gain_db, DB_WITH_SIGN)));
1015 // Peak labels could have changed.
1016 midi_mapper.refresh_lights();
1020 void MainWindow::relayout()
1022 int height = ui->vertical_layout->geometry().height();
1024 // Seemingly this can happen and must be ignored.
1028 double remaining_height = height;
1030 // Allocate the height; the most important part is to keep the main displays
1031 // at the right aspect if at all possible.
1032 double me_width = ui->me_preview->width();
1033 double me_height = me_width * double(global_flags.height) / double(global_flags.width) + ui->label_preview->height() + ui->preview_vertical_layout->spacing();
1035 // TODO: Scale the widths when we need to do this.
1036 if (me_height / double(height) > 0.8) {
1037 me_height = height * 0.8;
1039 remaining_height -= me_height + ui->vertical_layout->spacing();
1041 // Space between the M/E displays and the audio strip.
1042 remaining_height -= ui->vertical_layout->spacing();
1044 // The label above the audio strip.
1045 double compact_label_height = ui->compact_label->minimumHeight() +
1046 ui->compact_audio_layout->spacing();
1047 remaining_height -= compact_label_height;
1049 // The previews will be constrained by the remaining height, and the width.
1050 double preview_label_height = previews[0]->label->minimumSize().height() +
1051 previews[0]->main_vertical_layout->spacing();
1052 int preview_total_width = ui->preview_displays->geometry().width() - (previews.size() - 1) * ui->preview_displays->spacing();
1053 double preview_height = min(remaining_height - preview_label_height, (preview_total_width / double(previews.size())) * double(global_flags.height) / double(global_flags.width));
1054 remaining_height -= preview_height + preview_label_height + ui->vertical_layout->spacing();
1056 ui->vertical_layout->setStretch(0, lrintf(me_height));
1057 ui->vertical_layout->setStretch(1,
1058 lrintf(compact_label_height) +
1059 lrintf(remaining_height) +
1060 lrintf(preview_height + preview_label_height)); // Audio strip and previews together.
1062 ui->compact_audio_layout->setStretch(0, lrintf(compact_label_height));
1063 ui->compact_audio_layout->setStretch(1, lrintf(remaining_height)); // Audio strip.
1064 ui->compact_audio_layout->setStretch(2, lrintf(preview_height + preview_label_height));
1066 if (current_audio_view == 0) { // Compact audio view.
1067 // Set the widths for the previews.
1068 double preview_width = preview_height * double(global_flags.width) / double(global_flags.height);
1069 for (unsigned i = 0; i < previews.size(); ++i) {
1070 ui->preview_displays->setStretch(i, lrintf(preview_width));
1073 // The preview horizontal spacer.
1074 double remaining_preview_width = preview_total_width - previews.size() * preview_width;
1075 ui->preview_displays->setStretch(previews.size(), lrintf(remaining_preview_width));
1076 } else if (current_audio_view == 2) { // Video grid view.
1077 // QGridLayout doesn't do it for us, since we need to be able to remove rows
1078 // or columns as the grid changes, and it won't do that. Thus, position everything
1080 constexpr int spacing = 6;
1081 int grid_width = ui->preview_displays_grid->geometry().width();
1082 int grid_height = ui->preview_displays_grid->geometry().height();
1083 int best_preview_width = 0;
1084 unsigned best_num_rows = 1, best_num_cols = 1;
1085 for (unsigned num_rows = 1; num_rows <= previews.size(); ++num_rows) {
1086 int num_cols = (previews.size() + num_rows - 1) / num_rows;
1088 int max_preview_height = (grid_height - spacing * (num_rows - 1)) / num_rows - preview_label_height;
1089 int max_preview_width = (grid_width - spacing * (num_cols - 1)) / num_cols;
1090 int preview_width = std::min<int>(max_preview_width, max_preview_height * double(global_flags.width) / double(global_flags.height));
1092 if (preview_width > best_preview_width) {
1093 best_preview_width = preview_width;
1094 best_num_rows = num_rows;
1095 best_num_cols = num_cols;
1099 double cell_height = lrintf(best_preview_width * double(global_flags.height) / double(global_flags.width)) + preview_label_height;
1100 remaining_height = grid_height - best_num_rows * cell_height - (best_num_rows - 1) * spacing;
1101 int cell_width = best_preview_width;
1102 int remaining_width = grid_width - best_num_cols * cell_width - (best_num_cols - 1) * spacing;
1104 for (unsigned i = 0; i < previews.size(); ++i) {
1105 int col_idx = i % best_num_cols;
1106 int row_idx = i / best_num_cols;
1108 double top = remaining_height * 0.5f + row_idx * (cell_height + spacing);
1109 double bottom = top + cell_height;
1110 double left = remaining_width * 0.5f + col_idx * (cell_width + spacing);
1111 double right = left + cell_width;
1114 rect.setTop(lrintf(top));
1115 rect.setBottom(lrintf(bottom));
1116 rect.setLeft(lrintf(left));
1117 rect.setRight(lrintf(right));
1119 QWidget *display = static_cast<QWidget *>(previews[i]->frame->parent());
1120 display->setGeometry(rect);
1126 void MainWindow::set_locut(float value)
1128 set_relative_value(ui->locut_cutoff_knob, value);
1131 void MainWindow::set_limiter_threshold(float value)
1133 set_relative_value(ui->limiter_threshold_knob, value);
1136 void MainWindow::set_makeup_gain(float value)
1138 set_relative_value(ui->makeup_gain_knob, value);
1141 void MainWindow::set_stereo_width(unsigned bus_idx, float value)
1143 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::stereo_width_knob, value);
1146 void MainWindow::set_treble(unsigned bus_idx, float value)
1148 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::treble_knob, value);
1151 void MainWindow::set_mid(unsigned bus_idx, float value)
1153 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::mid_knob, value);
1156 void MainWindow::set_bass(unsigned bus_idx, float value)
1158 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::bass_knob, value);
1161 void MainWindow::set_gain(unsigned bus_idx, float value)
1163 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::gainstaging_knob, value);
1166 void MainWindow::set_compressor_threshold(unsigned bus_idx, float value)
1168 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::compressor_threshold_knob, value);
1171 void MainWindow::set_fader(unsigned bus_idx, float value)
1173 set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::fader, value);
1176 void MainWindow::toggle_mute(unsigned bus_idx)
1178 click_button_if_exists(bus_idx, &Ui::AudioExpandedView::mute_button);
1181 void MainWindow::toggle_locut(unsigned bus_idx)
1183 click_button_if_exists(bus_idx, &Ui::AudioExpandedView::locut_enabled);
1186 void MainWindow::toggle_auto_gain_staging(unsigned bus_idx)
1188 click_button_if_exists(bus_idx, &Ui::AudioExpandedView::gainstaging_auto_checkbox);
1191 void MainWindow::toggle_compressor(unsigned bus_idx)
1193 click_button_if_exists(bus_idx, &Ui::AudioExpandedView::compressor_enabled);
1196 void MainWindow::clear_peak(unsigned bus_idx)
1198 post_to_main_thread([=]{
1199 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
1200 global_audio_mixer->reset_peak(bus_idx);
1201 midi_mapper.set_has_peaked(bus_idx, false);
1202 midi_mapper.refresh_lights();
1207 void MainWindow::clear_all_highlights()
1209 post_to_main_thread([this]{
1210 highlight_locut(false);
1211 highlight_limiter_threshold(false);
1212 highlight_makeup_gain(false);
1213 highlight_toggle_limiter(false);
1214 highlight_toggle_auto_makeup_gain(false);
1215 for (unsigned bus_idx = 0; bus_idx < audio_expanded_views.size(); ++bus_idx) {
1216 highlight_treble(bus_idx, false);
1217 highlight_mid(bus_idx, false);
1218 highlight_bass(bus_idx, false);
1219 highlight_gain(bus_idx, false);
1220 highlight_compressor_threshold(bus_idx, false);
1221 highlight_fader(bus_idx, false);
1222 highlight_mute(bus_idx, false);
1223 highlight_toggle_locut(bus_idx, false);
1224 highlight_toggle_auto_gain_staging(bus_idx, false);
1225 highlight_toggle_compressor(bus_idx, false);
1230 void MainWindow::toggle_limiter()
1232 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
1233 ui->limiter_enabled->click();
1237 void MainWindow::toggle_auto_makeup_gain()
1239 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) {
1240 ui->makeup_gain_auto_checkbox->click();
1244 void MainWindow::highlight_locut(bool highlight)
1246 post_to_main_thread([this, highlight]{
1247 highlight_control(ui->locut_cutoff_knob, highlight);
1248 highlight_control(ui->locut_cutoff_knob_2, highlight);
1252 void MainWindow::highlight_limiter_threshold(bool highlight)
1254 post_to_main_thread([this, highlight]{
1255 highlight_control(ui->limiter_threshold_knob, highlight);
1256 highlight_control(ui->limiter_threshold_knob_2, highlight);
1260 void MainWindow::highlight_makeup_gain(bool highlight)
1262 post_to_main_thread([this, highlight]{
1263 highlight_control(ui->makeup_gain_knob, highlight);
1264 highlight_control(ui->makeup_gain_knob_2, highlight);
1268 void MainWindow::highlight_stereo_width(unsigned bus_idx, bool highlight)
1270 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::stereo_width_knob, highlight);
1273 void MainWindow::highlight_treble(unsigned bus_idx, bool highlight)
1275 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::treble_knob, highlight);
1278 void MainWindow::highlight_mid(unsigned bus_idx, bool highlight)
1280 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::mid_knob, highlight);
1283 void MainWindow::highlight_bass(unsigned bus_idx, bool highlight)
1285 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::bass_knob, highlight);
1288 void MainWindow::highlight_gain(unsigned bus_idx, bool highlight)
1290 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::gainstaging_knob, highlight);
1293 void MainWindow::highlight_compressor_threshold(unsigned bus_idx, bool highlight)
1295 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::compressor_threshold_knob, highlight);
1298 void MainWindow::highlight_fader(unsigned bus_idx, bool highlight)
1300 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::fader, highlight);
1303 void MainWindow::highlight_mute(unsigned bus_idx, bool highlight)
1305 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::mute_button, highlight, /*is_mute_btton=*/true);
1308 void MainWindow::highlight_toggle_locut(unsigned bus_idx, bool highlight)
1310 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::locut_enabled, highlight);
1313 void MainWindow::highlight_toggle_auto_gain_staging(unsigned bus_idx, bool highlight)
1315 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::gainstaging_auto_checkbox, highlight);
1318 void MainWindow::highlight_toggle_compressor(unsigned bus_idx, bool highlight)
1320 highlight_control_if_exists(bus_idx, &Ui::AudioExpandedView::compressor_enabled, highlight);
1323 void MainWindow::highlight_toggle_limiter(bool highlight)
1325 post_to_main_thread([this, highlight]{
1326 highlight_control(ui->limiter_enabled, highlight);
1327 highlight_control(ui->limiter_enabled_2, highlight);
1331 void MainWindow::highlight_toggle_auto_makeup_gain(bool highlight)
1333 post_to_main_thread([this, highlight]{
1334 highlight_control(ui->makeup_gain_auto_checkbox, highlight);
1335 highlight_control(ui->makeup_gain_auto_checkbox_2, highlight);
1340 void MainWindow::set_relative_value(T *control, float value)
1342 post_to_main_thread([control, value]{
1343 control->setValue(lrintf(control->minimum() + value * (control->maximum() - control->minimum())));
1348 void MainWindow::set_relative_value_if_exists(unsigned bus_idx, T *(Ui_AudioExpandedView::*control), float value)
1350 if (global_audio_mixer != nullptr &&
1351 global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL &&
1352 bus_idx < audio_expanded_views.size()) {
1353 set_relative_value(audio_expanded_views[bus_idx]->*control, value);
1358 void MainWindow::click_button_if_exists(unsigned bus_idx, T *(Ui_AudioExpandedView::*control))
1360 post_to_main_thread([this, bus_idx, control]{
1361 if (global_audio_mixer != nullptr &&
1362 global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL &&
1363 bus_idx < audio_expanded_views.size()) {
1364 (audio_expanded_views[bus_idx]->*control)->click();
1370 void MainWindow::highlight_control(T *control, bool highlight)
1372 if (control == nullptr) {
1375 if (global_audio_mixer == nullptr ||
1376 global_audio_mixer->get_mapping_mode() != AudioMixer::MappingMode::MULTICHANNEL) {
1380 control->setStyleSheet("background: rgb(0,255,0,80)");
1382 control->setStyleSheet("");
1387 void MainWindow::highlight_mute_control(T *control, bool highlight)
1389 if (control == nullptr) {
1392 if (global_audio_mixer == nullptr ||
1393 global_audio_mixer->get_mapping_mode() != AudioMixer::MappingMode::MULTICHANNEL) {
1397 control->setStyleSheet("QPushButton { background: rgb(0,255,0,80); } QPushButton:checked { background: rgba(255,80,0,140); }");
1399 control->setStyleSheet("QPushButton:checked { background: rgba(255,0,0,80); }");
1404 void MainWindow::highlight_control_if_exists(unsigned bus_idx, T *(Ui_AudioExpandedView::*control), bool highlight, bool is_mute_button)
1406 post_to_main_thread([this, bus_idx, control, highlight, is_mute_button]{
1407 if (bus_idx < audio_expanded_views.size()) {
1408 if (is_mute_button) {
1409 highlight_mute_control(audio_expanded_views[bus_idx]->*control, highlight);
1411 highlight_control(audio_expanded_views[bus_idx]->*control, highlight);
1417 void MainWindow::set_transition_names(vector<string> transition_names)
1419 if (transition_names.size() < 1 || transition_names[0].empty()) {
1420 transition_btn1->setText(QString(""));
1422 transition_btn1->setText(QString::fromStdString(transition_names[0] + " (J)"));
1423 ui->transition_btn1->setShortcut(QKeySequence("J"));
1425 if (transition_names.size() < 2 || transition_names[1].empty()) {
1426 transition_btn2->setText(QString(""));
1428 transition_btn2->setText(QString::fromStdString(transition_names[1] + " (K)"));
1429 ui->transition_btn2->setShortcut(QKeySequence("K"));
1431 if (transition_names.size() < 3 || transition_names[2].empty()) {
1432 transition_btn3->setText(QString(""));
1434 transition_btn3->setText(QString::fromStdString(transition_names[2] + " (L)"));
1435 ui->transition_btn3->setShortcut(QKeySequence("L"));
1439 void MainWindow::update_channel_name(Mixer::Output output, const string &name)
1441 if (output >= Mixer::OUTPUT_INPUT0) {
1442 unsigned channel = output - Mixer::OUTPUT_INPUT0;
1443 previews[channel]->label->setText(name.c_str());
1446 analyzer->update_channel_name(output, name);
1449 void MainWindow::update_channel_color(Mixer::Output output, const string &color)
1451 if (output >= Mixer::OUTPUT_INPUT0) {
1452 unsigned channel = output - Mixer::OUTPUT_INPUT0;
1453 previews[channel]->frame->setStyleSheet(QString::fromStdString("background-color:" + color));
1457 void MainWindow::transition_clicked(int transition_number)
1459 global_mixer->transition_clicked(transition_number);
1462 void MainWindow::channel_clicked(int channel_number)
1464 if (current_wb_pick_display == channel_number) {
1465 // The picking was already done from eventFilter(), since we don't get
1466 // the mouse pointer here.
1468 global_mixer->channel_clicked(channel_number);
1472 void MainWindow::quick_cut_activated(int channel_number)
1474 if (!global_flags.enable_quick_cut_keys) {
1477 global_mixer->channel_clicked(channel_number);
1478 global_mixer->transition_clicked(0);
1481 void MainWindow::wb_button_clicked(int channel_number)
1483 current_wb_pick_display = channel_number;
1484 QApplication::setOverrideCursor(Qt::CrossCursor);
1487 void MainWindow::audio_view_changed(int audio_view)
1489 if (audio_view == current_audio_view) {
1493 if (audio_view == 0) {
1494 // Compact audio view. (1, full audio view, has no video previews.)
1495 for (unsigned i = 0; i < previews.size(); ++i) {
1496 QWidget *display = static_cast<QWidget *>(previews[i]->frame->parent());
1497 ui->preview_displays->insertWidget(i, display, 1);
1499 } else if (audio_view == 2) {
1500 // Video grid display.
1501 for (unsigned i = 0; i < previews.size(); ++i) {
1502 QWidget *display = static_cast<QWidget *>(previews[i]->frame->parent());
1503 display->setParent(ui->preview_displays_grid);
1508 current_audio_view = audio_view;
1510 // Ask for a relayout, but only after the event loop is done doing relayout
1511 // on everything else.
1512 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
1515 bool MainWindow::eventFilter(QObject *watched, QEvent *event)
1517 if (current_wb_pick_display != -1 &&
1518 event->type() == QEvent::MouseButtonRelease &&
1519 watched->isWidgetType()) {
1520 QApplication::restoreOverrideCursor();
1521 if (watched == previews[current_wb_pick_display]->display) {
1522 const QMouseEvent *mouse_event = (QMouseEvent *)event;
1523 previews[current_wb_pick_display]->display->grab_white_balance(
1524 current_wb_pick_display,
1525 mouse_event->x(), mouse_event->y());
1527 // The user clicked on something else, give up.
1528 // (The click goes through, which might not be ideal, but, yes.)
1529 current_wb_pick_display = -1;
1535 void MainWindow::closeEvent(QCloseEvent *event)
1537 if (global_mixer->get_num_connected_clients() > 0) {
1538 QMessageBox::StandardButton reply =
1539 QMessageBox::question(this, "Nageru", "There are clients connected. Do you really want to quit?",
1540 QMessageBox::Yes | QMessageBox::No);
1541 if (reply != QMessageBox::Yes) {
1551 void MainWindow::audio_state_changed()
1553 post_to_main_thread([this]{
1554 if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) {
1557 InputMapping mapping = global_audio_mixer->get_input_mapping();
1558 for (unsigned bus_index = 0; bus_index < mapping.buses.size(); ++bus_index) {
1559 string label = get_bus_desc_label(mapping.buses[bus_index]);
1560 audio_miniviews[bus_index]->bus_desc_label->setFullText(
1561 QString::fromStdString(label));
1562 audio_expanded_views[bus_index]->bus_desc_label->setFullText(
1563 QString::fromStdString(label));