1 #include "mainwindow.h"
9 #include <QKeySequence>
12 #include <QPushButton>
13 #include <QResizeEvent>
21 #include "ui_display.h"
22 #include "ui_mainwindow.h"
29 Q_DECLARE_METATYPE(std::vector<std::string>);
31 MainWindow *global_mainwindow = nullptr;
33 MainWindow::MainWindow()
34 : ui(new Ui::MainWindow)
36 global_mainwindow = this;
39 ui->me_live->set_output(Mixer::OUTPUT_LIVE);
40 ui->me_preview->set_output(Mixer::OUTPUT_PREVIEW);
42 // Hook up the transition buttons.
43 // TODO: Make them dynamic.
44 connect(ui->transition_btn1, &QPushButton::clicked, std::bind(&MainWindow::transition_clicked, this, 0));
45 connect(ui->transition_btn2, &QPushButton::clicked, std::bind(&MainWindow::transition_clicked, this, 1));
46 connect(ui->transition_btn3, &QPushButton::clicked, std::bind(&MainWindow::transition_clicked, this, 2));
49 transition_btn1 = ui->transition_btn1;
50 transition_btn2 = ui->transition_btn2;
51 transition_btn3 = ui->transition_btn3;
52 qRegisterMetaType<std::vector<std::string>>("std::vector<std::string>");
53 connect(ui->me_preview, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names);
56 void MainWindow::resizeEvent(QResizeEvent* event)
58 QMainWindow::resizeEvent(event);
60 // Ask for a relayout, but only after the event loop is done doing relayout
61 // on everything else.
62 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
65 void MainWindow::mixer_created(Mixer *mixer)
68 unsigned num_previews = mixer->get_num_channels();
70 for (unsigned i = 0; i < num_previews; ++i) {
71 Mixer::Output output = Mixer::Output(Mixer::OUTPUT_INPUT0 + i);
73 QWidget *preview = new QWidget(this);
74 Ui::Display *ui_display = new Ui::Display;
75 ui_display->setupUi(preview);
76 ui_display->label->setText(mixer->get_channel_name(output).c_str());
77 ui_display->wb_button->setVisible(mixer->get_supports_set_wb(output));
78 ui_display->display->set_output(output);
79 ui->preview_displays->insertWidget(previews.size(), preview, 1);
80 previews.push_back(ui_display);
83 connect(ui_display->display, &GLWidget::clicked, std::bind(&MainWindow::channel_clicked, this, i));
85 // Hook up the keyboard key.
86 QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
87 connect(shortcut, &QShortcut::activated, std::bind(&MainWindow::channel_clicked, this, i));
90 mixer->set_audio_level_callback([this](float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs){
91 ui->vu_meter->set_level(level_lufs);
92 ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
95 snprintf(buf, sizeof(buf), "%.1f", peak_db);
96 ui->peak_display->setText(buf);
97 if (peak_db > -0.1f) { // -0.1 dBFS is EBU peak limit.
98 ui->peak_display->setStyleSheet("QLabel { background-color: red; color: white; }");
100 ui->peak_display->setStyleSheet("");
105 void MainWindow::relayout()
107 int width = size().width();
108 int height = size().height();
110 // Allocate the height; the most important part is to keep the main displays
111 // at 16:9 if at all possible.
112 double me_width = ui->me_preview->width();
113 double me_height = me_width * 9.0 / 16.0 + ui->label_preview->height();
115 // TODO: Scale the widths when we need to do this.
116 if (me_height / double(height) > 0.8) {
117 me_height = height * 0.8;
120 // The previews will be constrained by the remaining height, and the width.
122 double preview_label_height = previews[0]->label->height();
123 double preview_height = std::min(height - me_height - preview_label_height, (width / double(previews.size())) * 9.0 / 16.0);
125 ui->vertical_layout->setStretch(0, lrintf(me_height));
126 ui->vertical_layout->setStretch(1, std::max<int>(1, lrintf(height - me_height - preview_height)));
127 ui->vertical_layout->setStretch(2, lrintf(preview_height + preview_label_height));
129 // Set the widths for the previews.
130 double preview_width = preview_height * 16.0 / 9.0; // FIXME: spacing?
132 for (unsigned i = 0; i < previews.size(); ++i) {
133 ui->preview_displays->setStretch(i, lrintf(preview_width));
137 ui->preview_displays->setStretch(previews.size(), lrintf(width - previews.size() * preview_width));
140 void MainWindow::set_transition_names(vector<string> transition_names)
142 if (transition_names.size() < 1) {
143 transition_btn1->setText(QString(""));
145 transition_btn1->setText(QString::fromStdString(transition_names[0]));
147 if (transition_names.size() < 2) {
148 transition_btn2->setText(QString(""));
150 transition_btn2->setText(QString::fromStdString(transition_names[1]));
152 if (transition_names.size() < 3) {
153 transition_btn3->setText(QString(""));
155 transition_btn3->setText(QString::fromStdString(transition_names[2]));
159 void MainWindow::transition_clicked(int transition_number)
161 global_mixer->transition_clicked(transition_number);
164 void MainWindow::channel_clicked(int channel_number)
166 global_mixer->channel_clicked(channel_number);