From 4eb1b47db834e02c109b0c05c192efebc84e2173 Mon Sep 17 00:00:00 2001 From: Christopher P Yarger Date: Mon, 15 Mar 2021 14:02:24 -0400 Subject: [PATCH] Hotkey triggers now save as "hotkey name" and display as "hotkey description" --- src/events.cpp | 1 + src/forms/settings-dialog.cpp | 16 +++++++++----- src/utils.cpp | 41 +++++++++++++++++++++++++---------- src/utils.h | 7 ++++++ 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/events.cpp b/src/events.cpp index 36b5f0ae..7b889184 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -392,6 +392,7 @@ void Events::FinishedLoading() hookTransitionPlaybackEvents(); startup(); started=true; + Utils::build_hotkey_map(); broadcastUpdate("LoadingFinished"); } /** diff --git a/src/forms/settings-dialog.cpp b/src/forms/settings-dialog.cpp index 062e13d9..c0281bad 100644 --- a/src/forms/settings-dialog.cpp +++ b/src/forms/settings-dialog.cpp @@ -39,6 +39,7 @@ PluginWindow::PluginWindow(QWidget *parent) : QDialog(parent, Qt::Dialog), ui(ne hide_all_pairs(); connect_ui_signals(); reset_to_defaults(); + starting = false; } void PluginWindow::configure_table() const @@ -701,7 +702,7 @@ void PluginWindow::add_new_mapping() ui->table_mapping->setItem(row, 1, message_type_item); ui->table_mapping->setItem(row, 2, norc_item); ui->table_mapping->setItem(row, 3, action_item); - + auto *new_midi_hook = new MidiHook(); new_midi_hook->channel = ui->sb_channel->value(); new_midi_hook->message_type = ui->cb_mtype->currentText(); @@ -729,8 +730,6 @@ void PluginWindow::add_new_mapping() ui->table_mapping->setItem(row, 8, item_item); new_midi_hook->item = ui->cb_obs_output_item->currentText(); } - if (ui->cb_obs_output_hotkey->isVisible()) - new_midi_hook->hotkey = ui->cb_obs_output_hotkey->currentText(); if (ui->cb_obs_output_audio_source->isVisible()) { ui->table_mapping->setItem(row, 9, audio_item); new_midi_hook->audio_source = ui->cb_obs_output_audio_source->currentText(); @@ -751,7 +750,12 @@ void PluginWindow::add_new_mapping() ui->table_mapping->setItem(row, 13, max); new_midi_hook->range_max.emplace(ui->sb_max->value()); } - ui->table_mapping->setItem(row, 14, hotkey_item); + if (ui->cb_obs_output_hotkey->isVisible()) { + ui->table_mapping->setItem(row, 14, hotkey_item); + auto key = Utils::get_hotkey_key(ui->cb_obs_output_hotkey->currentText()); + blog(LOG_DEBUG, "hotkey_key %s", key.toStdString().c_str()); + new_midi_hook->hotkey = key; + } new_midi_hook->setAction(); set_all_cell_colors(row); if (editmode) { @@ -803,7 +807,7 @@ void PluginWindow::add_row_from_hook(const MidiHook *hook) const auto *item_item = new QTableWidgetItem(hook->item); auto *audio_item = new QTableWidgetItem(hook->audio_source); auto *media_item = new QTableWidgetItem(hook->media_source); - auto *hotkey_item = new QTableWidgetItem(hook->hotkey); + auto *hotkey_item = new QTableWidgetItem(Utils::get_hotkey_value(hook->hotkey)); QTableWidgetItem *ioveritem = (hook->int_override) ? new QTableWidgetItem(QString::number(*hook->int_override)) : new QTableWidgetItem(); QTableWidgetItem *min = (hook->range_min) ? new QTableWidgetItem(QString::number(*hook->range_min)) : new QTableWidgetItem(); QTableWidgetItem *max = (hook->range_max) ? new QTableWidgetItem(QString::number(*hook->range_max)) : new QTableWidgetItem(); @@ -906,7 +910,7 @@ void PluginWindow::edit_mapping() { if (ui->table_mapping->rowCount() != 0) { editmode = true; - + ui->btn_add->setText("Save Edits"); ui->btn_reset->setEnabled(true); const auto dv = GetDeviceManager().get()->get_midi_hooks(ui->mapping_lbl_device_name->text()); diff --git a/src/utils.cpp b/src/utils.cpp index b4ef978b..5ce8d354 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -633,18 +633,7 @@ obs_hotkey_t *Utils::FindHotkeyByName(const QString &name) } QStringList Utils::GetHotkeysList() { - QStringList *HotkeysList=new QStringList(); - obs_enum_hotkeys( - [](void *data, obs_hotkey_id id, obs_hotkey_t *hotkey) { - auto list = static_cast(data); - QString item(obs_hotkey_get_name(hotkey)); - if (item.contains("libobs") || item.contains("MediaSource") || item.contains("OBSBasic")) - return true; - list->append(item); - return true; - }, - HotkeysList); - return (QStringList)*HotkeysList; + return QStringList(hotkey_map.values()); } bool Utils::ReplayBufferEnabled() { @@ -952,6 +941,34 @@ QString Utils::translate_action(ActionsClass::Actions action) { return QString(obs_module_text(ActionsClass::action_to_string(action).toStdString().c_str())); } +void Utils::build_hotkey_map() { + hotkey_map.clear(); + + obs_enum_hotkeys( + [](void *data, obs_hotkey_id id, obs_hotkey_t *hotkey) { + QString item(obs_hotkey_get_name(hotkey)); + if (item.contains("libobs") || item.contains("MediaSource") || item.contains("OBSBasic")) + return true; + blog(LOG_DEBUG, "hotkey_map insert: <%s>,<%s>",obs_hotkey_get_name(hotkey) ,obs_hotkey_get_description(hotkey)); + hotkey_map.insert(item, obs_hotkey_get_description(hotkey)); + return true; + + }, + NULL); + blog(LOG_DEBUG, "test_map_get_key %s ",hotkey_map.key("Deactivate capture").toStdString().c_str()); + +} +QString Utils::get_hotkey_key(QString value) +{ + + return hotkey_map.key(value); +} +QString Utils::get_hotkey_value(QString key) +{ + + return hotkey_map.value(key); +} + QString Utils::untranslate(const QString &tstring) { return ActionsClass::action_to_string(AllActions_raw.at(TranslateActions().indexOf(tstring))); diff --git a/src/utils.h b/src/utils.h index 5ff4cff0..1863c555 100644 --- a/src/utils.h +++ b/src/utils.h @@ -236,4 +236,11 @@ const QList not_ready_actions{ }; void alert_popup(const QString &message); QString translate_action(ActionsClass::Actions action); + +static QMap hotkey_map; +void build_hotkey_map(); +QString get_hotkey_key(QString value); +QString get_hotkey_value(QString key); + + };