X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fmainwindow.cpp;h=980059af5a1f9752bd0853ecbf4a8c2a6a2d4879;hb=bd01e11a41a19fef2315319909d8655cac359f0f;hp=b542c1093243dc15af5ae006c0b274b5e9c06352;hpb=392f9d1ccb835c05a3874c4bea163788b2c37024;p=nageru diff --git a/nageru/mainwindow.cpp b/nageru/mainwindow.cpp index b542c10..980059a 100644 --- a/nageru/mainwindow.cpp +++ b/nageru/mainwindow.cpp @@ -44,24 +44,24 @@ #include #include -#include "aboutdialog.h" +#include "shared/aboutdialog.h" #include "alsa_pool.h" #include "analyzer.h" #include "clickable_label.h" #include "context_menus.h" #include "correlation_meter.h" -#include "disk_space_estimator.h" +#include "shared/disk_space_estimator.h" #include "ellipsis_label.h" #include "flags.h" #include "glwidget.h" #include "input_mapping.h" #include "input_mapping_dialog.h" #include "lrameter.h" -#include "midi_mapping.pb.h" +#include "nageru_midi_mapping.pb.h" #include "midi_mapping_dialog.h" #include "mixer.h" #include "nonlinear_fader.h" -#include "post_to_main_thread.h" +#include "shared/post_to_main_thread.h" #include "ui_audio_expanded_view.h" #include "ui_audio_miniview.h" #include "ui_display.h" @@ -198,7 +198,7 @@ MainWindow::MainWindow() global_mainwindow = this; ui->setupUi(this); - global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2)); + global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2, _3)); disk_free_label = new QLabel(this); disk_free_label->setStyleSheet("QLabel {padding-right: 5px;}"); ui->menuBar->setCornerWidget(disk_free_label); @@ -216,6 +216,7 @@ MainWindow::MainWindow() connect(ui->manual_action, &QAction::triggered, this, &MainWindow::manual_triggered); connect(ui->about_action, &QAction::triggered, this, &MainWindow::about_triggered); connect(ui->open_analyzer_action, &QAction::triggered, this, &MainWindow::open_analyzer_triggered); + connect(ui->open_delay_analyzer_action, &QAction::triggered, this, &MainWindow::open_delay_analyzer_triggered); connect(ui->simple_audio_mode, &QAction::triggered, this, &MainWindow::simple_audio_mode_triggered); connect(ui->multichannel_audio_mode, &QAction::triggered, this, &MainWindow::multichannel_audio_mode_triggered); connect(ui->input_mapping_action, &QAction::triggered, this, &MainWindow::input_mapping_triggered); @@ -252,31 +253,20 @@ MainWindow::MainWindow() connect(ui->me_live, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names); qRegisterMetaType("Mixer::Output"); + connect(ui->me_live, &GLWidget::name_updated, this, &MainWindow::update_channel_name); + connect(ui->me_preview, &GLWidget::name_updated, this, &MainWindow::update_channel_name); + // Hook up the prev/next buttons on the audio views. - auto prev_page = [this]{ - if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) { - ui->audio_views->setCurrentIndex((ui->audio_views->currentIndex() + 2) % 3); - } else { - ui->audio_views->setCurrentIndex(2 - ui->audio_views->currentIndex()); // Switch between 0 and 2. - } - }; - auto next_page = [this]{ - if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) { - ui->audio_views->setCurrentIndex((ui->audio_views->currentIndex() + 1) % 3); - } else { - ui->audio_views->setCurrentIndex(2 - ui->audio_views->currentIndex()); // Switch between 0 and 2. - } - }; - connect(ui->compact_prev_page, &QAbstractButton::clicked, prev_page); - connect(ui->compact_next_page, &QAbstractButton::clicked, next_page); - connect(ui->full_prev_page, &QAbstractButton::clicked, prev_page); - connect(ui->full_next_page, &QAbstractButton::clicked, next_page); - connect(ui->video_grid_prev_page, &QAbstractButton::clicked, prev_page); - connect(ui->video_grid_next_page, &QAbstractButton::clicked, next_page); + connect(ui->compact_prev_page, &QAbstractButton::clicked, this, &MainWindow::prev_page); + connect(ui->compact_next_page, &QAbstractButton::clicked, this, &MainWindow::next_page); + connect(ui->full_prev_page, &QAbstractButton::clicked, this, &MainWindow::prev_page); + connect(ui->full_next_page, &QAbstractButton::clicked, this, &MainWindow::next_page); + connect(ui->video_grid_prev_page, &QAbstractButton::clicked, this, &MainWindow::prev_page); + connect(ui->video_grid_next_page, &QAbstractButton::clicked, this, &MainWindow::next_page); // And bind the same to PgUp/PgDown. - connect(new QShortcut(QKeySequence::MoveToNextPage, this), &QShortcut::activated, next_page); - connect(new QShortcut(QKeySequence::MoveToPreviousPage, this), &QShortcut::activated, prev_page); + connect(new QShortcut(QKeySequence::MoveToNextPage, this), &QShortcut::activated, this, &MainWindow::next_page); + connect(new QShortcut(QKeySequence::MoveToPreviousPage, this), &QShortcut::activated, this, &MainWindow::prev_page); // When the audio view changes, move the previews. connect(ui->audio_views, &QStackedWidget::currentChanged, bind(&MainWindow::audio_view_changed, this, _1)); @@ -295,7 +285,7 @@ MainWindow::MainWindow() if (!load_midi_mapping_from_file(global_flags.midi_mapping_filename, &midi_mapping)) { fprintf(stderr, "Couldn't load MIDI mapping '%s'; exiting.\n", global_flags.midi_mapping_filename.c_str()); - exit(1); + ::abort(); } midi_mapper.set_midi_mapping(midi_mapping); } @@ -306,6 +296,24 @@ MainWindow::MainWindow() } } +void MainWindow::prev_page() +{ + if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) { + ui->audio_views->setCurrentIndex((ui->audio_views->currentIndex() + 2) % 3); + } else { + ui->audio_views->setCurrentIndex(2 - ui->audio_views->currentIndex()); // Switch between 0 and 2. + } +} + +void MainWindow::next_page() +{ + if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL) { + ui->audio_views->setCurrentIndex((ui->audio_views->currentIndex() + 1) % 3); + } else { + ui->audio_views->setCurrentIndex(2 - ui->audio_views->currentIndex()); // Switch between 0 and 2. + } +} + void MainWindow::resizeEvent(QResizeEvent* event) { QMainWindow::resizeEvent(event); @@ -437,6 +445,9 @@ void MainWindow::mixer_created(Mixer *mixer) midi_mapper.start_thread(); analyzer.reset(new Analyzer); + delay_analyzer.reset(new DelayAnalyzer); + + mixer->get_audio_mixer()->set_delay_analyzer(delay_analyzer.get()); global_mixer->set_theme_menu_callback(bind(&MainWindow::setup_theme_menu, this)); setup_theme_menu(); @@ -463,6 +474,7 @@ void MainWindow::reset_audio_mapping_ui() ui->multichannel_audio_mode->setChecked(!simple); ui->input_mapping_action->setEnabled(!simple); ui->midi_mapping_action->setEnabled(!simple); + ui->open_delay_analyzer_action->setEnabled(!simple); ui->locut_enabled->setVisible(simple); ui->gainstaging_label->setVisible(simple); @@ -663,7 +675,7 @@ void MainWindow::manual_triggered() void MainWindow::about_triggered() { - AboutDialog().exec(); + AboutDialog("Nageru", "Realtime video mixer").exec(); } void MainWindow::open_analyzer_triggered() @@ -671,6 +683,11 @@ void MainWindow::open_analyzer_triggered() analyzer->show(); } +void MainWindow::open_delay_analyzer_triggered() +{ + delay_analyzer->show(); +} + void MainWindow::simple_audio_mode_triggered() { if (global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::SIMPLE) { @@ -779,7 +796,7 @@ void MainWindow::update_cutoff_labels(float cutoff_hz) } } -void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left) +void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left, double file_length_seconds) { char time_str[256]; if (estimated_seconds_left < 60.0) { @@ -804,7 +821,9 @@ void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_le char buf[256]; snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str); - std::string label = buf; + // NOTE: The default formatter does not use file_length_seconds for anything, + // but the theme might want to do so. + std::string label = global_mixer->format_status_line(buf, file_length_seconds); post_to_main_thread([this, label]{ disk_free_label->setText(QString::fromStdString(label)); @@ -877,22 +896,44 @@ void MainWindow::update_eq_label(unsigned bus_index, EQBand band, float gain_db) void MainWindow::setup_theme_menu() { - std::vector theme_menu_entries = global_mixer->get_theme_menu(); + Theme::MenuEntry *root_menu = global_mixer->get_theme_menu(); + // Remove the old menu, if any. if (theme_menu != nullptr) { ui->menuBar->removeAction(theme_menu->menuAction()); theme_menu = nullptr; } - if (!theme_menu_entries.empty()) { - theme_menu = new QMenu("&Theme"); - for (const Theme::MenuEntry &entry : theme_menu_entries) { - QAction *action = theme_menu->addAction(QString::fromStdString(entry.text)); - connect(action, &QAction::triggered, [entry] { - global_mixer->theme_menu_entry_clicked(entry.lua_ref); - }); + if (root_menu != nullptr) { + assert(root_menu->is_submenu); + if (!root_menu->submenu.empty()) { + theme_menu = new QMenu("&Theme"); + fill_menu_from_theme_menu(root_menu->submenu, theme_menu); + ui->menuBar->insertMenu(ui->menu_Help->menuAction(), theme_menu); + } + } +} + +void MainWindow::fill_menu_from_theme_menu(const vector> &entries, QMenu *menu) +{ + for (const unique_ptr &entry : entries) { + if (entry->is_submenu) { + QMenu *submenu = new QMenu(QString::fromStdString(entry->text)); + fill_menu_from_theme_menu(entry->submenu, submenu); + menu->addMenu(submenu); + continue; + } + + QAction *action = menu->addAction(QString::fromStdString(entry->text)); + if (entry->entry.flags == Theme::MenuEntry::CHECKABLE) { + action->setCheckable(true); + } else if (entry->entry.flags == Theme::MenuEntry::CHECKED) { + action->setCheckable(true); + action->setChecked(true); } - ui->menuBar->insertMenu(ui->menu_Help->menuAction(), theme_menu); + connect(action, &QAction::triggered, [lua_ref = entry->entry.lua_ref] { + global_mixer->theme_menu_entry_clicked(lua_ref); + }); } } @@ -1244,6 +1285,42 @@ void MainWindow::toggle_auto_makeup_gain() } } +void MainWindow::switch_video_channel(int channel_number) +{ + global_mixer->channel_clicked(channel_number); +} + +void MainWindow::apply_transition(int transition_number) +{ + global_mixer->transition_clicked(transition_number); +} + +void MainWindow::prev_audio_view() +{ + post_to_main_thread([this]{ + prev_page(); + }); +} + +void MainWindow::next_audio_view() +{ + post_to_main_thread([this]{ + next_page(); + }); +} + +void MainWindow::begin_new_segment() +{ + global_mixer->schedule_cut(); +} + +void MainWindow::exit() +{ + post_to_main_thread([this]{ + close(); + }); +} + void MainWindow::highlight_locut(bool highlight) { post_to_main_thread([this, highlight]{ @@ -1441,7 +1518,11 @@ void MainWindow::set_transition_names(vector transition_names) void MainWindow::update_channel_name(Mixer::Output output, const string &name) { - if (output >= Mixer::OUTPUT_INPUT0) { + if (output == Mixer::OUTPUT_LIVE) { + ui->label_live->setText(name.c_str()); + } else if (output == Mixer::OUTPUT_PREVIEW) { + ui->label_preview->setText(name.c_str()); + } else if (output >= Mixer::OUTPUT_INPUT0) { unsigned channel = output - Mixer::OUTPUT_INPUT0; previews[channel]->label->setText(name.c_str()); } @@ -1548,6 +1629,8 @@ void MainWindow::closeEvent(QCloseEvent *event) } analyzer->hide(); + global_mixer->quit(); + mixer_shutting_down(); event->accept(); }