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, SIGNAL(clicked()), mapper, SLOT(map()));
51 connect(ui->transition_btn2, SIGNAL(clicked()), mapper, SLOT(map()));
52 connect(ui->transition_btn3, SIGNAL(clicked()), mapper, SLOT(map()));
53 connect(mapper, SIGNAL(mapped(int)), this, SLOT(transition_clicked(int)));
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, SIGNAL(transition_names_updated(std::vector<std::string>)),
62 this, SLOT(set_transition_names(std::vector<std::string>)));
65 void MainWindow::resizeEvent(QResizeEvent* event)
67 QMainWindow::resizeEvent(event);
69 // Ask for a relayout, but only after the event loop is done doing relayout
70 // on everything else.
71 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
74 void MainWindow::mixer_created(Mixer *mixer)
77 unsigned num_previews = mixer->get_num_channels();
78 QSignalMapper *mapper = new QSignalMapper(this);
80 for (unsigned i = 0; i < num_previews; ++i) {
81 Mixer::Output output = Mixer::Output(Mixer::OUTPUT_INPUT0 + i);
83 QWidget *preview = new QWidget(this);
84 Ui::Display *ui_display = new Ui::Display;
85 ui_display->setupUi(preview);
86 ui_display->label->setText(mixer->get_channel_name(output).c_str());
87 ui_display->wb_button->setVisible(mixer->get_supports_set_wb(output));
88 ui_display->display->set_output(output);
89 ui->preview_displays->insertWidget(previews.size(), preview, 1);
90 previews.push_back(ui_display);
93 mapper->setMapping(ui_display->display, i);
94 connect(ui_display->display, SIGNAL(clicked()), mapper, SLOT(map()));
96 // Hook up the keyboard key.
97 QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
98 mapper->setMapping(shortcut, i);
99 connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
102 connect(mapper, SIGNAL(mapped(int)), this, SLOT(channel_clicked(int)));
104 mixer->set_audio_level_callback([this](float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs){
105 ui->vu_meter->set_level(level_lufs);
106 ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
109 snprintf(buf, sizeof(buf), "%.1f", peak_db);
110 ui->peak_display->setText(buf);
111 if (peak_db > -0.1f) { // -0.1 dBFS is EBU peak limit.
112 ui->peak_display->setStyleSheet("QLabel { background-color: red; color: white; }");
114 ui->peak_display->setStyleSheet("");
119 void MainWindow::relayout()
121 int width = size().width();
122 int height = size().height();
124 // Allocate the height; the most important part is to keep the main displays
125 // at 16:9 if at all possible.
126 double me_width = ui->me_preview->width();
127 double me_height = me_width * 9.0 / 16.0 + ui->label_preview->height();
129 // TODO: Scale the widths when we need to do this.
130 if (me_height / double(height) > 0.8) {
131 me_height = height * 0.8;
134 // The previews will be constrained by the remaining height, and the width.
136 double preview_label_height = previews[0]->label->height();
137 double preview_height = std::min(height - me_height - preview_label_height, (width / double(previews.size())) * 9.0 / 16.0);
139 ui->vertical_layout->setStretch(0, lrintf(me_height));
140 ui->vertical_layout->setStretch(1, std::max<int>(1, lrintf(height - me_height - preview_height)));
141 ui->vertical_layout->setStretch(2, lrintf(preview_height + preview_label_height));
143 // Set the widths for the previews.
144 double preview_width = preview_height * 16.0 / 9.0; // FIXME: spacing?
146 for (unsigned i = 0; i < previews.size(); ++i) {
147 ui->preview_displays->setStretch(i, lrintf(preview_width));
151 ui->preview_displays->setStretch(previews.size(), lrintf(width - previews.size() * preview_width));
154 void MainWindow::set_transition_names(vector<string> transition_names)
156 if (transition_names.size() < 1) {
157 transition_btn1->setText(QString(""));
159 transition_btn1->setText(QString::fromStdString(transition_names[0]));
161 if (transition_names.size() < 2) {
162 transition_btn2->setText(QString(""));
164 transition_btn2->setText(QString::fromStdString(transition_names[1]));
166 if (transition_names.size() < 3) {
167 transition_btn3->setText(QString(""));
169 transition_btn3->setText(QString::fromStdString(transition_names[2]));
173 void MainWindow::transition_clicked(int transition_number)
175 global_mixer->transition_clicked(transition_number);
178 void MainWindow::channel_clicked(int channel_number)
180 global_mixer->channel_clicked(channel_number);