1 #include "mainwindow.h"
9 #include <QKeySequence>
12 #include <QPushButton>
13 #include <QResizeEvent>
15 #include <QSignalMapper>
22 #include "ui_display.h"
23 #include "ui_mainwindow.h"
30 Q_DECLARE_METATYPE(std::vector<std::string>);
32 MainWindow *global_mainwindow = nullptr;
34 MainWindow::MainWindow()
35 : ui(new Ui::MainWindow)
37 global_mainwindow = this;
40 ui->me_live->set_output(Mixer::OUTPUT_LIVE);
41 ui->me_preview->set_output(Mixer::OUTPUT_PREVIEW);
43 // Hook up the transition buttons.
44 // TODO: Make them dynamic.
46 QSignalMapper *mapper = new QSignalMapper(this);
47 mapper->setMapping(ui->transition_btn1, 0),
48 mapper->setMapping(ui->transition_btn2, 1);
49 mapper->setMapping(ui->transition_btn3, 2);
50 connect(ui->transition_btn1, &QPushButton::clicked, mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
51 connect(ui->transition_btn2, &QPushButton::clicked, mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
52 connect(ui->transition_btn3, &QPushButton::clicked, mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
53 connect(mapper, static_cast<void (QSignalMapper::*)(int)>(&QSignalMapper::mapped), this, &MainWindow::transition_clicked);
57 transition_btn1 = ui->transition_btn1;
58 transition_btn2 = ui->transition_btn2;
59 transition_btn3 = ui->transition_btn3;
60 qRegisterMetaType<std::vector<std::string>>("std::vector<std::string>");
61 connect(ui->me_preview, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names);
64 void MainWindow::resizeEvent(QResizeEvent* event)
66 QMainWindow::resizeEvent(event);
68 // Ask for a relayout, but only after the event loop is done doing relayout
69 // on everything else.
70 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
73 void MainWindow::mixer_created(Mixer *mixer)
76 unsigned num_previews = mixer->get_num_channels();
77 QSignalMapper *mapper = new QSignalMapper(this);
79 for (unsigned i = 0; i < num_previews; ++i) {
80 Mixer::Output output = Mixer::Output(Mixer::OUTPUT_INPUT0 + i);
82 QWidget *preview = new QWidget(this);
83 Ui::Display *ui_display = new Ui::Display;
84 ui_display->setupUi(preview);
85 ui_display->label->setText(mixer->get_channel_name(output).c_str());
86 ui_display->wb_button->setVisible(mixer->get_supports_set_wb(output));
87 ui_display->display->set_output(output);
88 ui->preview_displays->insertWidget(previews.size(), preview, 1);
89 previews.push_back(ui_display);
92 mapper->setMapping(ui_display->display, i);
93 connect(ui_display->display, &GLWidget::clicked, mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
95 // Hook up the keyboard key.
96 QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
97 mapper->setMapping(shortcut, i);
98 connect(shortcut, &QShortcut::activated, mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
101 connect(mapper, static_cast<void (QSignalMapper::*)(int)>(&QSignalMapper::mapped), this, &MainWindow::channel_clicked);
103 mixer->set_audio_level_callback([this](float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs){
104 ui->vu_meter->set_level(level_lufs);
105 ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
108 snprintf(buf, sizeof(buf), "%.1f", peak_db);
109 ui->peak_display->setText(buf);
110 if (peak_db > -0.1f) { // -0.1 dBFS is EBU peak limit.
111 ui->peak_display->setStyleSheet("QLabel { background-color: red; color: white; }");
113 ui->peak_display->setStyleSheet("");
118 void MainWindow::relayout()
120 int width = size().width();
121 int height = size().height();
123 // Allocate the height; the most important part is to keep the main displays
124 // at 16:9 if at all possible.
125 double me_width = ui->me_preview->width();
126 double me_height = me_width * 9.0 / 16.0 + ui->label_preview->height();
128 // TODO: Scale the widths when we need to do this.
129 if (me_height / double(height) > 0.8) {
130 me_height = height * 0.8;
133 // The previews will be constrained by the remaining height, and the width.
135 double preview_label_height = previews[0]->label->height();
136 double preview_height = std::min(height - me_height - preview_label_height, (width / double(previews.size())) * 9.0 / 16.0);
138 ui->vertical_layout->setStretch(0, lrintf(me_height));
139 ui->vertical_layout->setStretch(1, std::max<int>(1, lrintf(height - me_height - preview_height)));
140 ui->vertical_layout->setStretch(2, lrintf(preview_height + preview_label_height));
142 // Set the widths for the previews.
143 double preview_width = preview_height * 16.0 / 9.0; // FIXME: spacing?
145 for (unsigned i = 0; i < previews.size(); ++i) {
146 ui->preview_displays->setStretch(i, lrintf(preview_width));
150 ui->preview_displays->setStretch(previews.size(), lrintf(width - previews.size() * preview_width));
153 void MainWindow::set_transition_names(vector<string> transition_names)
155 if (transition_names.size() < 1) {
156 transition_btn1->setText(QString(""));
158 transition_btn1->setText(QString::fromStdString(transition_names[0]));
160 if (transition_names.size() < 2) {
161 transition_btn2->setText(QString(""));
163 transition_btn2->setText(QString::fromStdString(transition_names[1]));
165 if (transition_names.size() < 3) {
166 transition_btn3->setText(QString(""));
168 transition_btn3->setText(QString::fromStdString(transition_names[2]));
172 void MainWindow::transition_clicked(int transition_number)
174 global_mixer->transition_clicked(transition_number);
177 void MainWindow::channel_clicked(int channel_number)
179 global_mixer->channel_clicked(channel_number);