From e5ea0b2dca8a04baeccd52b8a3c327b3a234c8ef Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 25 Feb 2017 10:36:50 +0100 Subject: [PATCH] Add a copy of the right-click HDMI/SDI output video menu on the main menu bar. --- Makefile | 2 +- context_menus.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++ context_menus.h | 19 ++++++++++++++ glwidget.cpp | 67 +++++------------------------------------------ mainwindow.cpp | 6 +++++ ui_mainwindow.ui | 18 +++++++++++-- 6 files changed, 114 insertions(+), 64 deletions(-) create mode 100644 context_menus.cpp create mode 100644 context_menus.h diff --git a/Makefile b/Makefile index 9991424..6d46bc3 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ LDLIBS=$(shell pkg-config --libs $(PKG_MODULES)) -pthread -lva -lva-drm -lva-x11 OBJS_WITH_MOC = glwidget.o mainwindow.o vumeter.o lrameter.o compression_reduction_meter.o correlation_meter.o aboutdialog.o input_mapping_dialog.o midi_mapping_dialog.o nonlinear_fader.o OBJS += $(OBJS_WITH_MOC) OBJS += $(OBJS_WITH_MOC:.o=.moc.o) ellipsis_label.moc.o clickable_label.moc.o -OBJS += vu_common.o piecewise_interpolator.o main.o +OBJS += context_menus.o vu_common.o piecewise_interpolator.o main.o OBJS += midi_mapper.o midi_mapping.pb.o # Mixer objects diff --git a/context_menus.cpp b/context_menus.cpp new file mode 100644 index 0000000..790de94 --- /dev/null +++ b/context_menus.cpp @@ -0,0 +1,66 @@ +#include +#include +#include + +#include + +#include "mixer.h" + +using namespace std; + +void fill_hdmi_sdi_output_device_menu(QMenu *menu) +{ + menu->clear(); + QActionGroup *card_group = new QActionGroup(menu); + int current_card = global_mixer->get_output_card_index(); + + QAction *none_action = new QAction("None", card_group); + none_action->setCheckable(true); + if (current_card == -1) { + none_action->setChecked(true); + } + QObject::connect(none_action, &QAction::triggered, []{ global_mixer->set_output_card(-1); }); + menu->addAction(none_action); + + unsigned num_cards = global_mixer->get_num_cards(); + for (unsigned card_index = 0; card_index < num_cards; ++card_index) { + if (!global_mixer->card_can_be_used_as_output(card_index)) { + continue; + } + + QString description(QString::fromStdString(global_mixer->get_output_card_description(card_index))); + QAction *action = new QAction(description, card_group); + action->setCheckable(true); + if (current_card == int(card_index)) { + action->setChecked(true); + } + QObject::connect(action, &QAction::triggered, [card_index]{ global_mixer->set_output_card(card_index); }); + menu->addAction(action); + } +} + +void fill_hdmi_sdi_output_resolution_menu(QMenu *menu) +{ + menu->clear(); + int current_card = global_mixer->get_output_card_index(); + if (current_card == -1) { + menu->setEnabled(false); + return; + } + + menu->setEnabled(true); + QActionGroup *resolution_group = new QActionGroup(menu); + uint32_t current_mode = global_mixer->get_output_video_mode(); + map video_modes = global_mixer->get_available_output_video_modes(); + for (const auto &mode : video_modes) { + QString description(QString::fromStdString(mode.second.name)); + QAction *action = new QAction(description, resolution_group); + action->setCheckable(true); + if (current_mode == mode.first) { + action->setChecked(true); + } + const uint32_t mode_id = mode.first; + QObject::connect(action, &QAction::triggered, [mode_id]{ global_mixer->set_output_video_mode(mode_id); }); + menu->addAction(action); + } +} diff --git a/context_menus.h b/context_menus.h new file mode 100644 index 0000000..2f9005d --- /dev/null +++ b/context_menus.h @@ -0,0 +1,19 @@ +#ifndef _CONTEXT_MENUS_H +#define _CONTEXT_MENUS_H 1 + +// Some context menus for controlling various I/O selections, +// based on data from Mixer. + +class QMenu; + +// Populate a submenu for selecting output card, with an action for each card. +// Will call into the mixer on trigger. +void fill_hdmi_sdi_output_device_menu(QMenu *menu); + +// Populate a submenu for choosing the output resolution. Since this is +// card-dependent, the entire menu is disabled if we haven't chosen a card +// (but it's still there so that the user will know it exists). +// Will call into the mixer on trigger. +void fill_hdmi_sdi_output_resolution_menu(QMenu *menu); + +#endif // !defined(_CONTEXT_MENUS_H) diff --git a/glwidget.cpp b/glwidget.cpp index ae4b62f..0dd4a56 100644 --- a/glwidget.cpp +++ b/glwidget.cpp @@ -20,6 +20,7 @@ #include "audio_mixer.h" #include "context.h" +#include "context_menus.h" #include "flags.h" #include "mainwindow.h" #include "mixer.h" @@ -132,76 +133,20 @@ void GLWidget::show_live_context_menu(const QPoint &pos) // Add a submenu for selecting output card, with an action for each card. QMenu card_submenu; - QActionGroup card_group(&card_submenu); - - int current_card = global_mixer->get_output_card_index(); - - QAction *none_action = new QAction("None", &card_group); - none_action->setCheckable(true); - if (current_card == -1) { - none_action->setChecked(true); - } - none_action->setData(QList{"output_card", -1}); - card_submenu.addAction(none_action); - - unsigned num_cards = global_mixer->get_num_cards(); - for (unsigned card_index = 0; card_index < num_cards; ++card_index) { - if (!global_mixer->card_can_be_used_as_output(card_index)) { - continue; - } - - QString description(QString::fromStdString(global_mixer->get_output_card_description(card_index))); - QAction *action = new QAction(description, &card_group); - action->setCheckable(true); - if (current_card == int(card_index)) { - action->setChecked(true); - } - action->setData(QList{"output_card", card_index}); - card_submenu.addAction(action); - } - - card_submenu.setTitle("HDMI/SDI output"); + fill_hdmi_sdi_output_device_menu(&card_submenu); + card_submenu.setTitle("HDMI/SDI output device"); menu.addMenu(&card_submenu); // Add a submenu for choosing the output resolution. Since this is // card-dependent, it is disabled if we haven't chosen a card // (but it's still there so that the user will know it exists). QMenu resolution_submenu; - QActionGroup resolution_group(&resolution_submenu); - if (current_card == -1) { - resolution_submenu.setEnabled(false); - } else { - uint32_t current_mode = global_mixer->get_output_video_mode(); - map video_modes = global_mixer->get_available_output_video_modes(); - for (const auto &mode : video_modes) { - QString description(QString::fromStdString(mode.second.name)); - QAction *action = new QAction(description, &resolution_group); - action->setCheckable(true); - if (current_mode == mode.first) { - action->setChecked(true); - } - action->setData(QList{"video_mode", mode.first}); - resolution_submenu.addAction(action); - } - } - + fill_hdmi_sdi_output_resolution_menu(&resolution_submenu); resolution_submenu.setTitle("HDMI/SDI output resolution"); menu.addMenu(&resolution_submenu); - // Show the menu and look at the result. - QAction *selected_item = menu.exec(global_pos); - if (selected_item != nullptr) { - QList selected = selected_item->data().toList(); - if (selected[0].toString() == "output_card") { - unsigned output_card = selected[1].toUInt(nullptr); - global_mixer->set_output_card(output_card); - } else if (selected[0].toString() == "video_mode") { - uint32_t mode = selected[1].toUInt(nullptr); - global_mixer->set_output_video_mode(mode); - } else { - assert(false); - } - } + // Show the menu; if there's an action selected, it will deal with it itself. + menu.exec(global_pos); } void GLWidget::show_preview_context_menu(unsigned signal_num, const QPoint &pos) diff --git a/mainwindow.cpp b/mainwindow.cpp index 04a16a8..a1c2915 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -47,6 +47,7 @@ #include "aboutdialog.h" #include "alsa_pool.h" #include "clickable_label.h" +#include "context_menus.h" #include "correlation_meter.h" #include "disk_space_estimator.h" #include "ellipsis_label.h" @@ -215,6 +216,11 @@ MainWindow::MainWindow() ui->x264_bitrate_action->setEnabled(false); } + connect(ui->video_menu, &QMenu::aboutToShow, [this]{ + fill_hdmi_sdi_output_device_menu(ui->hdmi_sdi_output_device_menu); + fill_hdmi_sdi_output_resolution_menu(ui->hdmi_sdi_output_resolution_menu); + }); + // Hook up the transition buttons. (Keyboard shortcuts are set in set_transition_names().) // TODO: Make them dynamic. connect(ui->transition_btn1, &QPushButton::clicked, bind(&MainWindow::transition_clicked, this, 0)); diff --git a/ui_mainwindow.ui b/ui_mainwindow.ui index b11141e..0118eae 100644 --- a/ui_mainwindow.ui +++ b/ui_mainwindow.ui @@ -1393,7 +1393,7 @@ 23 - + &Video @@ -1404,8 +1404,22 @@ + + + HDMI/SDI output device + + + + + + HDMI/SDI output resolution + + + + + @@ -1426,7 +1440,7 @@ - + -- 2.39.2