1 #include "mainwindow.h"
9 #include <QKeySequence>
12 #include <QPushButton>
13 #include <QResizeEvent>
15 #include <QSignalMapper>
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.
45 QSignalMapper *mapper = new QSignalMapper(this);
46 mapper->setMapping(ui->transition_btn1, 0),
47 mapper->setMapping(ui->transition_btn2, 1);
48 mapper->setMapping(ui->transition_btn3, 2);
49 connect(ui->transition_btn1, SIGNAL(clicked()), mapper, SLOT(map()));
50 connect(ui->transition_btn2, SIGNAL(clicked()), mapper, SLOT(map()));
51 connect(ui->transition_btn3, SIGNAL(clicked()), mapper, SLOT(map()));
52 connect(mapper, SIGNAL(mapped(int)), this, SLOT(transition_clicked(int)));
56 transition_btn1 = ui->transition_btn1;
57 transition_btn2 = ui->transition_btn2;
58 transition_btn3 = ui->transition_btn3;
59 qRegisterMetaType<std::vector<std::string>>("std::vector<std::string>");
60 connect(ui->me_preview, SIGNAL(transition_names_updated(std::vector<std::string>)),
61 this, SLOT(set_transition_names(std::vector<std::string>)));
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 GLWidget *preview = new GLWidget(this);
81 preview->set_output(Mixer::Output(Mixer::OUTPUT_INPUT0 + i));
82 ui->preview_displays->insertWidget(previews.size(), preview, 1);
83 previews.push_back(preview);
86 mapper->setMapping(preview, i);
87 connect(preview, SIGNAL(clicked()), mapper, SLOT(map()));
89 // Hook up the keyboard key.
90 QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
91 mapper->setMapping(shortcut, i);
92 connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
95 connect(mapper, SIGNAL(mapped(int)), this, SLOT(channel_clicked(int)));
97 mixer->set_audio_level_callback([this](float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs){
98 ui->vu_meter->set_level(level_lufs);
99 ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
102 snprintf(buf, sizeof(buf), "%.1f", peak_db);
103 ui->peak_display->setText(buf);
104 if (peak_db > -0.1f) { // -0.1 dBFS is EBU peak limit.
105 ui->peak_display->setStyleSheet("QLabel { background-color: red; color: white; }");
107 ui->peak_display->setStyleSheet("");
112 void MainWindow::relayout()
114 int width = size().width();
115 int height = size().height();
117 // Allocate the height; the most important part is to keep the main displays
118 // at 16:9 if at all possible.
119 double me_width = ui->me_preview->width();
120 double me_height = me_width * 9.0 / 16.0 + ui->label_preview->height();
122 // TODO: Scale the widths when we need to do this.
123 if (me_height / double(height) > 0.8) {
124 me_height = height * 0.8;
127 // The previews will be constrained by the remaining height, and the width.
129 double preview_height = std::min(height - me_height, (width / double(previews.size())) * 9.0 / 16.0);
131 ui->vertical_layout->setStretch(0, lrintf(me_height));
132 ui->vertical_layout->setStretch(1, std::max<int>(1, lrintf(height - me_height - preview_height)));
133 ui->vertical_layout->setStretch(2, lrintf(preview_height));
135 // Set the widths for the previews.
136 double preview_width = preview_height * 16.0 / 9.0; // FIXME: spacing?
138 for (unsigned i = 0; i < previews.size(); ++i) {
139 ui->preview_displays->setStretch(i, lrintf(preview_width));
143 ui->preview_displays->setStretch(previews.size(), lrintf(width - previews.size() * preview_width));
146 void MainWindow::set_transition_names(vector<string> transition_names)
148 if (transition_names.size() < 1) {
149 transition_btn1->setText(QString(""));
151 transition_btn1->setText(QString::fromStdString(transition_names[0]));
153 if (transition_names.size() < 2) {
154 transition_btn2->setText(QString(""));
156 transition_btn2->setText(QString::fromStdString(transition_names[1]));
158 if (transition_names.size() < 3) {
159 transition_btn3->setText(QString(""));
161 transition_btn3->setText(QString::fromStdString(transition_names[2]));
165 void MainWindow::transition_clicked(int transition_number)
167 global_mixer->transition_clicked(transition_number);
170 void MainWindow::channel_clicked(int channel_number)
172 global_mixer->channel_clicked(channel_number);