]> git.sesse.net Git - nageru/blobdiff - nageru/mainwindow.cpp
Give the theme access to basic audio information.
[nageru] / nageru / mainwindow.cpp
index 91234ceb23ff301b6194d9bda9b1f81fd0f7e34b..c369f28993452aea9d610834b32b0c8c4eb19a73 100644 (file)
@@ -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);
@@ -252,6 +252,9 @@ MainWindow::MainWindow()
        connect(ui->me_live, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names);
        qRegisterMetaType<Mixer::Output>("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.
        connect(ui->compact_prev_page, &QAbstractButton::clicked, this, &MainWindow::prev_page);
        connect(ui->compact_next_page, &QAbstractButton::clicked, this, &MainWindow::next_page);
@@ -783,7 +786,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) {
@@ -808,7 +811,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));
@@ -881,22 +886,44 @@ void MainWindow::update_eq_label(unsigned bus_index, EQBand band, float gain_db)
 
 void MainWindow::setup_theme_menu()
 {
-       std::vector<Theme::MenuEntry> 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<unique_ptr<Theme::MenuEntry>> &entries, QMenu *menu)
+{
+       for (const unique_ptr<Theme::MenuEntry> &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);
+               });
        }
 }
 
@@ -1180,6 +1207,15 @@ void MainWindow::set_fader(unsigned bus_idx, float value)
        set_relative_value_if_exists(bus_idx, &Ui::AudioExpandedView::fader, value);
 }
 
+void MainWindow::set_fader_absolute(unsigned bus_idx, float value_db)
+{
+       if (global_audio_mixer != nullptr &&
+           global_audio_mixer->get_mapping_mode() == AudioMixer::MappingMode::MULTICHANNEL &&
+           bus_idx < audio_expanded_views.size()) {
+               audio_expanded_views[bus_idx]->fader->setDbValue(value_db);
+       }
+}
+
 void MainWindow::toggle_mute(unsigned bus_idx)
 {
        click_button_if_exists(bus_idx, &Ui::AudioExpandedView::mute_button);
@@ -1481,7 +1517,11 @@ void MainWindow::set_transition_names(vector<string> 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());
        }