1 #include "mainwindow.h"
11 #include <QInputDialog>
12 #include <QKeySequence>
15 #include <QPushButton>
16 #include <QResizeEvent>
21 #include "aboutdialog.h"
22 #include "disk_space_estimator.h"
25 #include "input_mapping_dialog.h"
28 #include "post_to_main_thread.h"
29 #include "ui_audio_miniview.h"
30 #include "ui_audio_expanded_view.h"
31 #include "ui_display.h"
32 #include "ui_mainwindow.h"
38 using namespace std::chrono;
39 using namespace std::placeholders;
41 Q_DECLARE_METATYPE(std::string);
42 Q_DECLARE_METATYPE(std::vector<std::string>);
44 MainWindow *global_mainwindow = nullptr;
48 void schedule_cut_signal(int ignored)
50 global_mixer->schedule_cut();
53 void quit_signal(int ignored)
55 global_mainwindow->close();
58 void slave_knob(QDial *master, QDial *slave)
60 QWidget::connect(master, &QDial::valueChanged, [slave](int value){
61 slave->blockSignals(true);
62 slave->setValue(value);
63 slave->blockSignals(false);
65 QWidget::connect(slave, &QDial::valueChanged, [master](int value){
66 master->setValue(value);
70 void slave_checkbox(QCheckBox *master, QCheckBox *slave)
72 QWidget::connect(master, &QCheckBox::stateChanged, [slave](int state){
73 slave->blockSignals(true);
74 slave->setCheckState(Qt::CheckState(state));
75 slave->blockSignals(false);
77 QWidget::connect(slave, &QCheckBox::stateChanged, [master](int state){
78 master->setCheckState(Qt::CheckState(state));
82 void slave_fader(NonLinearFader *master, NonLinearFader *slave)
84 QWidget::connect(master, &NonLinearFader::dbValueChanged, [slave](double value) {
85 slave->blockSignals(true);
86 slave->setDbValue(value);
87 slave->blockSignals(false);
89 QWidget::connect(slave, &NonLinearFader::dbValueChanged, [master](double value){
90 master->setDbValue(value);
94 constexpr unsigned DB_NO_FLAGS = 0x0;
95 constexpr unsigned DB_WITH_SIGN = 0x1;
96 constexpr unsigned DB_BARE = 0x2;
98 string format_db(double db, unsigned flags)
101 if (flags & DB_WITH_SIGN) {
104 snprintf(buf, sizeof(buf), "%+.1f", db);
106 } else if (db < 0.0) {
109 // Should never happen, really.
115 snprintf(buf, sizeof(buf), "%.1f", db);
117 } else if (db < 0.0) {
120 // Should never happen, really.
124 if (!(flags & DB_BARE)) {
132 MainWindow::MainWindow()
133 : ui(new Ui::MainWindow)
135 global_mainwindow = this;
138 global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2));
139 disk_free_label = new QLabel(this);
140 disk_free_label->setStyleSheet("QLabel {padding-right: 5px;}");
141 ui->menuBar->setCornerWidget(disk_free_label);
143 ui->me_live->set_output(Mixer::OUTPUT_LIVE);
144 ui->me_preview->set_output(Mixer::OUTPUT_PREVIEW);
147 connect(ui->cut_action, &QAction::triggered, this, &MainWindow::cut_triggered);
148 connect(ui->exit_action, &QAction::triggered, this, &MainWindow::exit_triggered);
149 connect(ui->about_action, &QAction::triggered, this, &MainWindow::about_triggered);
150 connect(ui->input_mapping_action, &QAction::triggered, this, &MainWindow::input_mapping_triggered);
152 if (global_flags.x264_video_to_http) {
153 connect(ui->x264_bitrate_action, &QAction::triggered, this, &MainWindow::x264_bitrate_triggered);
155 ui->x264_bitrate_action->setEnabled(false);
158 // Hook up the transition buttons. (Keyboard shortcuts are set in set_transition_names().)
159 // TODO: Make them dynamic.
160 connect(ui->transition_btn1, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 0));
161 connect(ui->transition_btn2, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 1));
162 connect(ui->transition_btn3, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 2));
165 transition_btn1 = ui->transition_btn1;
166 transition_btn2 = ui->transition_btn2;
167 transition_btn3 = ui->transition_btn3;
168 qRegisterMetaType<string>("std::string");
169 qRegisterMetaType<vector<string>>("std::vector<std::string>");
170 connect(ui->me_live, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names);
171 qRegisterMetaType<Mixer::Output>("Mixer::Output");
173 // Hook up the prev/next buttons on the audio views.
174 connect(ui->compact_prev_page, &QAbstractButton::clicked, bind(&QStackedWidget::setCurrentIndex, ui->audio_views, 1));
175 connect(ui->compact_next_page, &QAbstractButton::clicked, bind(&QStackedWidget::setCurrentIndex, ui->audio_views, 1));
176 connect(ui->full_prev_page, &QAbstractButton::clicked, bind(&QStackedWidget::setCurrentIndex, ui->audio_views, 0));
177 connect(ui->full_next_page, &QAbstractButton::clicked, bind(&QStackedWidget::setCurrentIndex, ui->audio_views, 0));
179 last_audio_level_callback = steady_clock::now() - seconds(1);
182 void MainWindow::resizeEvent(QResizeEvent* event)
184 QMainWindow::resizeEvent(event);
186 // Ask for a relayout, but only after the event loop is done doing relayout
187 // on everything else.
188 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
191 void MainWindow::mixer_created(Mixer *mixer)
193 // Make the previews.
194 unsigned num_previews = mixer->get_num_channels();
196 for (unsigned i = 0; i < num_previews; ++i) {
197 Mixer::Output output = Mixer::Output(Mixer::OUTPUT_INPUT0 + i);
199 QWidget *preview = new QWidget(this);
200 Ui::Display *ui_display = new Ui::Display;
201 ui_display->setupUi(preview);
202 ui_display->label->setText(mixer->get_channel_name(output).c_str());
203 ui_display->display->set_output(output);
204 ui->preview_displays->insertWidget(previews.size(), preview, 1);
205 previews.push_back(ui_display);
207 // Hook up the click.
208 connect(ui_display->display, &GLWidget::clicked, bind(&MainWindow::channel_clicked, this, i));
210 // Let the theme update the text whenever the resolution or color changed.
211 connect(ui_display->display, &GLWidget::name_updated, this, &MainWindow::update_channel_name);
212 connect(ui_display->display, &GLWidget::color_updated, this, &MainWindow::update_channel_color);
214 // Hook up the keyboard key.
215 QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
216 connect(shortcut, &QShortcut::activated, bind(&MainWindow::channel_clicked, this, i));
218 // Hook up the white balance button (irrelevant if invisible).
219 ui_display->wb_button->setVisible(mixer->get_supports_set_wb(output));
220 connect(ui_display->wb_button, &QPushButton::clicked, bind(&MainWindow::wb_button_clicked, this, i));
223 setup_audio_miniview();
224 setup_audio_expanded_view();
226 slave_knob(ui->locut_cutoff_knob, ui->locut_cutoff_knob_2);
227 slave_knob(ui->limiter_threshold_knob, ui->limiter_threshold_knob_2);
228 slave_knob(ui->makeup_gain_knob, ui->makeup_gain_knob_2);
229 slave_checkbox(ui->makeup_gain_auto_checkbox, ui->makeup_gain_auto_checkbox_2);
230 slave_checkbox(ui->limiter_enabled, ui->limiter_enabled_2);
232 // TODO: Fetch all of the values these for completeness,
233 // not just the enable knobs implied by flags.
234 ui->locut_enabled->setChecked(global_mixer->get_audio_mixer()->get_locut_enabled());
235 ui->gainstaging_knob->setValue(global_mixer->get_audio_mixer()->get_gain_staging_db());
236 ui->gainstaging_auto_checkbox->setChecked(global_mixer->get_audio_mixer()->get_gain_staging_auto());
237 ui->compressor_enabled->setChecked(global_mixer->get_audio_mixer()->get_compressor_enabled());
238 ui->limiter_enabled->setChecked(global_mixer->get_audio_mixer()->get_limiter_enabled());
239 ui->makeup_gain_auto_checkbox->setChecked(global_mixer->get_audio_mixer()->get_final_makeup_gain_auto());
241 QString limiter_threshold_label(
242 QString::fromStdString(format_db(mixer->get_audio_mixer()->get_limiter_threshold_dbfs(), DB_WITH_SIGN)));
243 ui->limiter_threshold_db_display->setText(limiter_threshold_label);
244 ui->limiter_threshold_db_display_2->setText(limiter_threshold_label);
245 ui->compressor_threshold_db_display->setText(
246 QString::fromStdString(format_db(mixer->get_audio_mixer()->get_compressor_threshold_dbfs(), DB_WITH_SIGN)));
248 connect(ui->locut_cutoff_knob, &QDial::valueChanged, this, &MainWindow::cutoff_knob_changed);
249 cutoff_knob_changed(ui->locut_cutoff_knob->value());
250 connect(ui->locut_enabled, &QCheckBox::stateChanged, [this](int state){
251 global_mixer->get_audio_mixer()->set_locut_enabled(state == Qt::Checked);
254 connect(ui->gainstaging_knob, &QAbstractSlider::valueChanged, this, &MainWindow::gain_staging_knob_changed);
255 connect(ui->gainstaging_auto_checkbox, &QCheckBox::stateChanged, [this](int state){
256 global_mixer->get_audio_mixer()->set_gain_staging_auto(state == Qt::Checked);
258 connect(ui->makeup_gain_knob, &QAbstractSlider::valueChanged, this, &MainWindow::final_makeup_gain_knob_changed);
259 connect(ui->makeup_gain_auto_checkbox, &QCheckBox::stateChanged, [this](int state){
260 global_mixer->get_audio_mixer()->set_final_makeup_gain_auto(state == Qt::Checked);
263 connect(ui->limiter_threshold_knob, &QDial::valueChanged, this, &MainWindow::limiter_threshold_knob_changed);
264 connect(ui->compressor_threshold_knob, &QDial::valueChanged, this, &MainWindow::compressor_threshold_knob_changed);
265 connect(ui->limiter_enabled, &QCheckBox::stateChanged, [this](int state){
266 global_mixer->get_audio_mixer()->set_limiter_enabled(state == Qt::Checked);
268 connect(ui->compressor_enabled, &QCheckBox::stateChanged, [this](int state){
269 global_mixer->get_audio_mixer()->set_compressor_enabled(state == Qt::Checked);
271 connect(ui->reset_meters_button, &QPushButton::clicked, this, &MainWindow::reset_meters_button_clicked);
272 mixer->get_audio_mixer()->set_audio_level_callback(bind(&MainWindow::audio_level_callback, this, _1, _2, _3, _4, _5, _6, _7, _8, _9));
274 struct sigaction act;
275 memset(&act, 0, sizeof(act));
276 act.sa_handler = schedule_cut_signal;
277 act.sa_flags = SA_RESTART;
278 sigaction(SIGHUP, &act, nullptr);
280 // Mostly for debugging. Don't override SIGINT, that's so evil if
281 // shutdown isn't instant.
282 memset(&act, 0, sizeof(act));
283 act.sa_handler = quit_signal;
284 act.sa_flags = SA_RESTART;
285 sigaction(SIGUSR1, &act, nullptr);
288 void MainWindow::setup_audio_miniview()
290 // Remove any existing channels.
291 for (QLayoutItem *item; (item = ui->faders->takeAt(0)) != nullptr; ) {
292 delete item->widget();
295 audio_miniviews.clear();
297 // Set up brand new ones from the input mapping.
298 InputMapping mapping = global_mixer->get_audio_mixer()->get_input_mapping();
299 audio_miniviews.resize(mapping.buses.size());
300 for (unsigned bus_index = 0; bus_index < mapping.buses.size(); ++bus_index) {
301 QWidget *channel = new QWidget(this);
302 Ui::AudioMiniView *ui_audio_miniview = new Ui::AudioMiniView;
303 ui_audio_miniview->setupUi(channel);
304 ui_audio_miniview->bus_desc_label->setFullText(
305 QString::fromStdString(mapping.buses[bus_index].name));
306 audio_miniviews[bus_index] = ui_audio_miniview;
307 // TODO: Set the fader position.
308 ui->faders->addWidget(channel);
310 connect(ui_audio_miniview->fader, &NonLinearFader::dbValueChanged,
311 bind(&MainWindow::mini_fader_changed, this, bus_index, _1));
315 void MainWindow::setup_audio_expanded_view()
317 // Remove any existing channels.
318 for (QLayoutItem *item; (item = ui->buses->takeAt(0)) != nullptr; ) {
319 delete item->widget();
322 audio_expanded_views.clear();
324 // Set up brand new ones from the input mapping.
325 InputMapping mapping = global_mixer->get_audio_mixer()->get_input_mapping();
326 audio_expanded_views.resize(mapping.buses.size());
327 for (unsigned bus_index = 0; bus_index < mapping.buses.size(); ++bus_index) {
328 QWidget *channel = new QWidget(this);
329 Ui::AudioExpandedView *ui_audio_expanded_view = new Ui::AudioExpandedView;
330 ui_audio_expanded_view->setupUi(channel);
331 ui_audio_expanded_view->bus_desc_label->setFullText(
332 QString::fromStdString(mapping.buses[bus_index].name));
333 audio_expanded_views[bus_index] = ui_audio_expanded_view;
334 // TODO: Set the fader position.
335 ui->buses->addWidget(channel);
337 slave_fader(audio_miniviews[bus_index]->fader, ui_audio_expanded_view->fader);
341 void MainWindow::mixer_shutting_down()
343 ui->me_live->clean_context();
344 ui->me_preview->clean_context();
345 for (Ui::Display *display : previews) {
346 display->display->clean_context();
350 void MainWindow::cut_triggered()
352 global_mixer->schedule_cut();
355 void MainWindow::x264_bitrate_triggered()
358 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);
359 if (ok && new_bitrate >= 100 && new_bitrate <= 100000) {
360 global_flags.x264_bitrate = new_bitrate;
361 global_mixer->change_x264_bitrate(new_bitrate);
365 void MainWindow::exit_triggered()
370 void MainWindow::about_triggered()
372 AboutDialog().exec();
375 void MainWindow::input_mapping_triggered()
377 if (InputMappingDialog().exec() == QDialog::Accepted) {
378 setup_audio_miniview();
379 setup_audio_expanded_view();
383 void MainWindow::gain_staging_knob_changed(int value)
385 ui->gainstaging_auto_checkbox->setCheckState(Qt::Unchecked);
387 float gain_db = value * 0.1f;
388 global_mixer->get_audio_mixer()->set_gain_staging_db(gain_db);
390 // The label will be updated by the audio level callback.
393 void MainWindow::final_makeup_gain_knob_changed(int value)
395 ui->makeup_gain_auto_checkbox->setCheckState(Qt::Unchecked);
397 float gain_db = value * 0.1f;
398 global_mixer->get_audio_mixer()->set_final_makeup_gain_db(gain_db);
400 // The label will be updated by the audio level callback.
403 void MainWindow::cutoff_knob_changed(int value)
405 float octaves = value * 0.1f;
406 float cutoff_hz = 20.0 * pow(2.0, octaves);
407 global_mixer->get_audio_mixer()->set_locut_cutoff(cutoff_hz);
410 snprintf(buf, sizeof(buf), "%ld Hz", lrintf(cutoff_hz));
411 ui->locut_cutoff_display->setText(buf);
412 ui->locut_cutoff_display_2->setText(buf);
415 void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
418 if (estimated_seconds_left < 60.0) {
419 strcpy(time_str, "<font color=\"red\">Less than a minute</font>");
420 } else if (estimated_seconds_left < 1800.0) { // Less than half an hour: Xm Ys (red).
421 int s = lrintf(estimated_seconds_left);
424 snprintf(time_str, sizeof(time_str), "<font color=\"red\">%dm %ds</font>", m, s);
425 } else if (estimated_seconds_left < 3600.0) { // Less than an hour: Xm.
426 int m = lrintf(estimated_seconds_left / 60.0);
427 snprintf(time_str, sizeof(time_str), "%dm", m);
428 } else if (estimated_seconds_left < 36000.0) { // Less than ten hours: Xh Ym.
429 int m = lrintf(estimated_seconds_left / 60.0);
432 snprintf(time_str, sizeof(time_str), "%dh %dm", h, m);
433 } else { // More than ten hours: Xh.
434 int h = lrintf(estimated_seconds_left / 3600.0);
435 snprintf(time_str, sizeof(time_str), "%dh", h);
438 snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str);
440 std::string label = buf;
442 post_to_main_thread([this, label]{
443 disk_free_label->setText(QString::fromStdString(label));
444 ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right.
448 void MainWindow::limiter_threshold_knob_changed(int value)
450 float threshold_dbfs = value * 0.1f;
451 global_mixer->get_audio_mixer()->set_limiter_threshold_dbfs(threshold_dbfs);
452 ui->limiter_threshold_db_display->setText(
453 QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
454 ui->limiter_threshold_db_display_2->setText(
455 QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
458 void MainWindow::compressor_threshold_knob_changed(int value)
460 float threshold_dbfs = value * 0.1f;
461 global_mixer->get_audio_mixer()->set_compressor_threshold_dbfs(threshold_dbfs);
462 ui->compressor_threshold_db_display->setText(
463 QString::fromStdString(format_db(threshold_dbfs, DB_WITH_SIGN)));
466 void MainWindow::mini_fader_changed(int bus, double volume_db)
468 QString label(QString::fromStdString(format_db(volume_db, DB_WITH_SIGN)));
469 audio_miniviews[bus]->fader_label->setText(label);
470 audio_expanded_views[bus]->fader_label->setText(label);
472 global_mixer->get_audio_mixer()->set_fader_volume(bus, volume_db);
475 void MainWindow::reset_meters_button_clicked()
477 global_mixer->get_audio_mixer()->reset_meters();
478 ui->peak_display->setText(QString::fromStdString(format_db(-HUGE_VAL, DB_WITH_SIGN | DB_BARE)));
479 ui->peak_display->setStyleSheet("");
482 void MainWindow::audio_level_callback(float level_lufs, float peak_db, vector<float> bus_level_lufs,
483 float global_level_lufs,
484 float range_low_lufs, float range_high_lufs,
485 float gain_staging_db, float final_makeup_gain_db,
488 steady_clock::time_point now = steady_clock::now();
490 // The meters are somewhat inefficient to update. Only update them
491 // every 100 ms or so (we get updates every 5–20 ms).
492 double last_update_age = duration<double>(now - last_audio_level_callback).count();
493 if (last_update_age < 0.100) {
496 last_audio_level_callback = now;
498 post_to_main_thread([=]() {
499 ui->vu_meter->set_level(level_lufs);
500 for (unsigned bus_index = 0; bus_index < bus_level_lufs.size(); ++bus_index) {
501 if (bus_index < audio_miniviews.size()) {
502 audio_miniviews[bus_index]->vu_meter_meter->set_level(
503 bus_level_lufs[bus_index]);
506 ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
507 ui->correlation_meter->set_correlation(correlation);
509 ui->peak_display->setText(QString::fromStdString(format_db(peak_db, DB_BARE)));
510 if (peak_db > -0.1f) { // -0.1 dBFS is EBU peak limit.
511 ui->peak_display->setStyleSheet("QLabel { background-color: red; color: white; }");
513 ui->peak_display->setStyleSheet("");
516 ui->gainstaging_knob->blockSignals(true);
517 ui->gainstaging_knob->setValue(lrintf(gain_staging_db * 10.0f));
518 ui->gainstaging_knob->blockSignals(false);
519 ui->gainstaging_db_display->setText(
520 QString::fromStdString(format_db(gain_staging_db, DB_WITH_SIGN)));
522 ui->makeup_gain_knob->blockSignals(true);
523 ui->makeup_gain_knob->setValue(lrintf(final_makeup_gain_db * 10.0f));
524 ui->makeup_gain_knob->blockSignals(false);
525 ui->makeup_gain_db_display->setText(
526 QString::fromStdString(format_db(final_makeup_gain_db, DB_WITH_SIGN)));
527 ui->makeup_gain_db_display_2->setText(
528 QString::fromStdString(format_db(final_makeup_gain_db, DB_WITH_SIGN)));
532 void MainWindow::relayout()
534 int height = ui->vertical_layout->geometry().height();
536 double remaining_height = height;
538 // Allocate the height; the most important part is to keep the main displays
539 // at 16:9 if at all possible.
540 double me_width = ui->me_preview->width();
541 double me_height = me_width * 9.0 / 16.0 + ui->label_preview->height() + ui->preview_vertical_layout->spacing();
543 // TODO: Scale the widths when we need to do this.
544 if (me_height / double(height) > 0.8) {
545 me_height = height * 0.8;
547 remaining_height -= me_height + ui->vertical_layout->spacing();
549 // Space between the M/E displays and the audio strip.
550 remaining_height -= ui->vertical_layout->spacing();
552 // The label above the audio strip.
553 double compact_label_height = ui->compact_label->geometry().height() +
554 ui->compact_audio_layout->spacing();
555 remaining_height -= compact_label_height;
557 // The previews will be constrained by the remaining height, and the width.
558 double preview_label_height = previews[0]->title_bar->geometry().height() +
559 previews[0]->main_vertical_layout->spacing();
560 int preview_total_width = ui->preview_displays->geometry().width() - (previews.size() - 1) * ui->preview_displays->spacing();
561 double preview_height = min(remaining_height - preview_label_height, (preview_total_width / double(previews.size())) * 9.0 / 16.0);
562 remaining_height -= preview_height + preview_label_height + ui->vertical_layout->spacing();
564 ui->vertical_layout->setStretch(0, lrintf(me_height));
565 ui->vertical_layout->setStretch(1,
566 lrintf(compact_label_height) +
567 lrintf(remaining_height) +
568 lrintf(preview_height + preview_label_height)); // Audio strip and previews together.
570 ui->compact_audio_layout->setStretch(0, lrintf(compact_label_height));
571 ui->compact_audio_layout->setStretch(1, lrintf(remaining_height)); // Audio strip.
572 ui->compact_audio_layout->setStretch(2, lrintf(preview_height + preview_label_height));
574 // Set the widths for the previews.
575 double preview_width = preview_height * 16.0 / 9.0;
576 for (unsigned i = 0; i < previews.size(); ++i) {
577 ui->preview_displays->setStretch(i, lrintf(preview_width));
580 // The preview horizontal spacer.
581 double remaining_preview_width = preview_total_width - previews.size() * preview_width;
582 ui->preview_displays->setStretch(previews.size(), lrintf(remaining_preview_width));
585 void MainWindow::set_transition_names(vector<string> transition_names)
587 if (transition_names.size() < 1 || transition_names[0].empty()) {
588 transition_btn1->setText(QString(""));
590 transition_btn1->setText(QString::fromStdString(transition_names[0] + " (J)"));
591 ui->transition_btn1->setShortcut(QKeySequence("J"));
593 if (transition_names.size() < 2 || transition_names[1].empty()) {
594 transition_btn2->setText(QString(""));
596 transition_btn2->setText(QString::fromStdString(transition_names[1] + " (K)"));
597 ui->transition_btn2->setShortcut(QKeySequence("K"));
599 if (transition_names.size() < 3 || transition_names[2].empty()) {
600 transition_btn3->setText(QString(""));
602 transition_btn3->setText(QString::fromStdString(transition_names[2] + " (L)"));
603 ui->transition_btn3->setShortcut(QKeySequence("L"));
607 void MainWindow::update_channel_name(Mixer::Output output, const string &name)
609 if (output >= Mixer::OUTPUT_INPUT0) {
610 unsigned channel = output - Mixer::OUTPUT_INPUT0;
611 previews[channel]->label->setText(name.c_str());
615 void MainWindow::update_channel_color(Mixer::Output output, const string &color)
617 if (output >= Mixer::OUTPUT_INPUT0) {
618 unsigned channel = output - Mixer::OUTPUT_INPUT0;
619 previews[channel]->frame->setStyleSheet(QString::fromStdString("background-color:" + color));
623 void MainWindow::transition_clicked(int transition_number)
625 global_mixer->transition_clicked(transition_number);
628 void MainWindow::channel_clicked(int channel_number)
630 if (current_wb_pick_display == channel_number) {
631 // The picking was already done from eventFilter(), since we don't get
632 // the mouse pointer here.
634 global_mixer->channel_clicked(channel_number);
638 void MainWindow::wb_button_clicked(int channel_number)
640 current_wb_pick_display = channel_number;
641 QApplication::setOverrideCursor(Qt::CrossCursor);
644 bool MainWindow::eventFilter(QObject *watched, QEvent *event)
646 if (current_wb_pick_display != -1 &&
647 event->type() == QEvent::MouseButtonRelease &&
648 watched->isWidgetType()) {
649 QApplication::restoreOverrideCursor();
650 if (watched == previews[current_wb_pick_display]->display) {
651 const QMouseEvent *mouse_event = (QMouseEvent *)event;
652 set_white_balance(current_wb_pick_display, mouse_event->x(), mouse_event->y());
654 // The user clicked on something else, give up.
655 // (The click goes through, which might not be ideal, but, yes.)
656 current_wb_pick_display = -1;
664 double srgb_to_linear(double x)
669 return pow((x + 0.055) / 1.055, 2.4);
675 void MainWindow::set_white_balance(int channel_number, int x, int y)
677 // Set the white balance to neutral for the grab. It's probably going to
678 // flicker a bit, but hopefully this display is not live anyway.
679 global_mixer->set_wb(Mixer::OUTPUT_INPUT0 + channel_number, 0.5, 0.5, 0.5);
680 previews[channel_number]->display->updateGL();
681 QRgb reference_color = previews[channel_number]->display->grabFrameBuffer().pixel(x, y);
683 double r = srgb_to_linear(qRed(reference_color) / 255.0);
684 double g = srgb_to_linear(qGreen(reference_color) / 255.0);
685 double b = srgb_to_linear(qBlue(reference_color) / 255.0);
686 global_mixer->set_wb(Mixer::OUTPUT_INPUT0 + channel_number, r, g, b);
687 previews[channel_number]->display->updateGL();