Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
cpyarger committed Mar 14, 2021
2 parents e3faf69 + 1f7adf5 commit a17a646
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 72 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ list(APPEND obs-midi_HEADERS
src/macro-helpers.h
src/Midi_hook.h
src/Midi_message.h)
set(obs_midi_UI
src/forms/settings-dialog.ui)

qt5_wrap_ui(obs_midi_UI_HEADERS ${obs_midi_UI})

add_library(obs-midi MODULE
${obs-midi_SOURCES}
${obs_midi_UI_HEADERS}
${obs-midi_HEADERS})
include_directories(
"${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api"

${obs_midi_UI_HEADERS}
${Qt5Core_INCLUDES}
${Qt5Widgets_INCLUDES}
"${CMAKE_SOURCE_DIR}/deps/asio/asio/include")
Expand Down
141 changes: 89 additions & 52 deletions src/forms/settings-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PluginWindow::PluginWindow(QWidget *parent) : QDialog(parent, Qt::Dialog), ui(ne
configure_table();
hide_all_pairs();
connect_ui_signals();

reset_to_defaults();
starting = false;
}
void PluginWindow::configure_table() const
Expand Down Expand Up @@ -68,6 +68,7 @@ void PluginWindow::connect_ui_signals() const
connect(ui->table_mapping, SIGNAL(cellClicked(int, int)), this, SLOT(edit_mapping()));
/**************Connections to mappper****************/
connect(ui->btn_add, SIGNAL(clicked()), this, SLOT(add_new_mapping()));
connect(ui->btn_reset, SIGNAL(clicked()), this, SLOT(reset_to_defaults()));
connect(ui->btn_delete, SIGNAL(clicked()), this, SLOT(delete_mapping()));
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int)));
connect(ui->outbox, SIGNAL(currentTextChanged(QString)), this, SLOT(select_output_device(QString)));
Expand Down Expand Up @@ -450,16 +451,23 @@ void PluginWindow::reset_to_defaults() const
ui->cb_obs_output_audio_source->setCurrentIndex(0);
ui->cb_obs_output_media_source->setCurrentIndex(0);
ui->sb_channel->setValue(0);
ui->sb_norc->setValue(0);
ui->sb_norc->clear();
ui->cb_mtype->setCurrentIndex(0);
ui->slider_value->setValue(0);
ui->btn_add->setText("Add Mapping");
ui->btn_delete->setEnabled(false);
ui->btn_reset->setEnabled(false);
ui->table_mapping->clearSelection();
ui->sb_max->clear();
ui->sb_min->clear();
ui->sb_int_override->clear();
clear_table();
load_table();
this->ui->table_mapping->resizeColumnsToContents();
}
void PluginWindow::obs_actions_select(const QString &action) const
{
ui->btn_reset->setEnabled(true);
if (!switching) {
hide_all_pairs();
switch (ActionsClass::string_to_action(Utils::untranslate(action))) {
Expand Down Expand Up @@ -605,9 +613,9 @@ void PluginWindow::obs_actions_select(const QString &action) const
ui->label_Int_override->setText("Duration * ");
ui->sb_int_override->setSuffix(" ms");
break;
case ActionsClass::Actions::Trigger_Hotkey_By_Name:
show_pair(Pairs::Hotkey);
break;
case ActionsClass::Actions::Trigger_Hotkey_By_Name:
show_pair(Pairs::Hotkey);
break;
default:
hide_all_pairs();
break;
Expand Down Expand Up @@ -673,8 +681,6 @@ void PluginWindow::add_new_mapping()
const auto row = (editmode) ? editrow : ui->table_mapping->rowCount();
if (!editmode)
ui->table_mapping->insertRow(row);

editmode = false;
// don't delete it, because the table takes ownership of the items
const auto channel_item = new QTableWidgetItem(QString::number(ui->sb_channel->value()));
const auto message_type_item = new QTableWidgetItem(ui->cb_mtype->currentText());
Expand All @@ -690,47 +696,71 @@ void PluginWindow::add_new_mapping()
const auto int_override = new QTableWidgetItem(QString::number(ui->sb_int_override->value()));
const auto min = new QTableWidgetItem(QString::number(ui->sb_min->value()));
const auto max = new QTableWidgetItem(QString::number(ui->sb_max->value()));
const auto hotkey_item = new QTableWidgetItem(ui->cb_obs_output_hotkey->currentText());
const auto hotkey_item = new QTableWidgetItem(ui->cb_obs_output_hotkey->currentText());
ui->table_mapping->setItem(row, 0, channel_item);
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);
ui->table_mapping->setItem(row, 4, scene_item);
ui->table_mapping->setItem(row, 5, source_item);
ui->table_mapping->setItem(row, 6, filter_item);
ui->table_mapping->setItem(row, 7, transition_item);
ui->table_mapping->setItem(row, 8, item_item);
ui->table_mapping->setItem(row, 9, audio_item);
ui->table_mapping->setItem(row, 10, media_item);
ui->table_mapping->setItem(row, 11, int_override);
ui->table_mapping->setItem(row, 12, min);
ui->table_mapping->setItem(row, 13, max);
ui->table_mapping->setItem(row, 14, hotkey_item);

set_all_cell_colors(row);
auto *new_midi_hook = (editmode) ? find_existing_hook() : new MidiHook();

auto *new_midi_hook = new MidiHook();
new_midi_hook->channel = ui->sb_channel->value();
new_midi_hook->message_type = ui->cb_mtype->currentText();
new_midi_hook->norc = ui->sb_norc->value();
new_midi_hook->value_as_filter = ui->check_use_value->isChecked();
new_midi_hook->value.emplace((ui->check_use_value->isChecked()) ? ui->slider_value->value() : NULL);
new_midi_hook->value.emplace(ui->slider_value->value());
new_midi_hook->action = ui->cb_obs_output_action->currentText();
new_midi_hook->scene = ui->cb_obs_output_scene->currentText();
new_midi_hook->source = ui->cb_obs_output_source->currentText();
new_midi_hook->filter = ui->cb_obs_output_filter->currentText();
new_midi_hook->transition = ui->cb_obs_output_transition->currentText();
new_midi_hook->item = ui->cb_obs_output_item->currentText();
new_midi_hook->hotkey = ui->cb_obs_output_hotkey->currentText();
new_midi_hook->audio_source = ui->cb_obs_output_audio_source->currentText();
new_midi_hook->media_source = ui->cb_obs_output_media_source->currentText();
new_midi_hook->int_override.emplace(ui->sb_int_override->value());
new_midi_hook->range_min.emplace(ui->sb_min->value());
new_midi_hook->range_max.emplace(ui->sb_max->value());
if (ui->cb_obs_output_scene->isVisible()) {
ui->table_mapping->setItem(row, 4, scene_item);
new_midi_hook->scene = ui->cb_obs_output_scene->currentText();
}
if (ui->cb_obs_output_source->isVisible()) {
ui->table_mapping->setItem(row, 5, source_item);
new_midi_hook->source = ui->cb_obs_output_source->currentText();
}
if (ui->cb_obs_output_filter->isVisible()) {
ui->table_mapping->setItem(row, 6, filter_item);
new_midi_hook->filter = ui->cb_obs_output_filter->currentText();
}
if (ui->cb_obs_output_transition->isVisible()) {
ui->table_mapping->setItem(row, 7, transition_item);
new_midi_hook->transition = ui->cb_obs_output_transition->currentText();
}
if (ui->cb_obs_output_item->isVisible()) {
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();
}
if (ui->cb_obs_output_media_source->isVisible()) {
ui->table_mapping->setItem(row, 10, media_item);
new_midi_hook->media_source = ui->cb_obs_output_media_source->currentText();
}
if (ui->sb_int_override->isVisible()) {
ui->table_mapping->setItem(row, 11, int_override);
new_midi_hook->int_override.emplace(ui->sb_int_override->value());
}
if (ui->sb_min->isVisible()) {
ui->table_mapping->setItem(row, 12, min);
new_midi_hook->range_min.emplace(ui->sb_min->value());
}
if (ui->sb_max->isVisible()) {
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);
new_midi_hook->setAction();
GetDeviceManager().get()->get_midi_device(ui->mapping_lbl_device_name->text())->add_MidiHook(new_midi_hook);

set_all_cell_colors(row);
if (editmode) {
GetDeviceManager().get()->get_midi_device(ui->mapping_lbl_device_name->text())->edit_midi_hook(edithook, new_midi_hook);
} else {
GetDeviceManager().get()->get_midi_device(ui->mapping_lbl_device_name->text())->add_MidiHook(new_midi_hook);
}
GetConfig().get()->Save();
ui->table_mapping->selectRow(row);
reset_to_defaults();
this->ui->table_mapping->resizeColumnsToContents();
} else {
if (ui->sb_channel->value()) {
Expand All @@ -753,6 +783,8 @@ void PluginWindow::add_new_mapping()
Utils::alert_popup(mess);
}
}
if (editmode)
editmode = false;
}
void PluginWindow::add_row_from_hook(const MidiHook *hook) const
{
Expand Down Expand Up @@ -796,7 +828,7 @@ void PluginWindow::set_all_cell_colors(const int row) const
{
const QColor midi_color(0, 170, 255);
const QColor action_color(170, 0, 255);

for (auto col = 0; col <= ui->table_mapping->columnCount(); col++) {
auto *const rc = ui->table_mapping->item(row, col);
(col < 3) ? set_cell_colors(midi_color, rc) : set_cell_colors(action_color, rc);
Expand Down Expand Up @@ -847,32 +879,36 @@ void PluginWindow::remove_hook(MidiHook *hook) const
}
void PluginWindow::delete_mapping() const
{
if (ui->table_mapping->rowCount() > 0) {
auto row = ui->table_mapping->selectedItems().at(0)->row();
blog(LOG_DEBUG, "selected row to delete %i", row);
const auto hooks = GetDeviceManager()->get_midi_device(ui->mapping_lbl_device_name->text())->GetMidiHooks();
for (auto *hook : hooks) {
if ((hook->channel == ui->sb_channel->value()) && (hook->norc == ui->sb_norc->value()) &&
(hook->message_type == ui->cb_mtype->currentText())) {
if (hook->value_as_filter) {
if (hook->value == ui->slider_value->value()) {
remove_hook(hook);
ui->table_mapping->removeRow(row);
ui->table_mapping->clearSelection();
}
} else {
if (ui->table_mapping->rowCount() <= 0)
return;

auto row = ui->table_mapping->selectedItems().at(0)->row();
blog(LOG_DEBUG, "selected row to delete %i", row);
const auto hooks = GetDeviceManager()->get_midi_device(ui->mapping_lbl_device_name->text())->GetMidiHooks();
for (auto *hook : hooks) {
if ((hook->channel == ui->sb_channel->value()) && (hook->norc == ui->sb_norc->value()) && (hook->message_type == ui->cb_mtype->currentText())) {
if (hook->value_as_filter) {
if (hook->value == ui->slider_value->value()) {
remove_hook(hook);
ui->table_mapping->removeRow(row);
ui->table_mapping->clearSelection();
}
} else {
remove_hook(hook);
ui->table_mapping->removeRow(row);
ui->table_mapping->clearSelection();
}
}
}
reset_to_defaults();
}
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());
blog(LOG_DEBUG, "hook numners: name %s = %i", ui->mapping_lbl_device_name->text().toStdString().c_str(), dv.count());
const auto selected_items = ui->table_mapping->selectedItems();
Expand All @@ -899,6 +935,7 @@ void PluginWindow::edit_mapping()
ui->check_int_override->setChecked(check);
ui->sb_int_override->setValue(selected_items.at(11)->text().toInt());
ui->btn_delete->setEnabled(true);
edithook = find_existing_hook();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/forms/settings-dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>

#include <vector>

#include "ui_settings-dialog.h"

#include "ui_settings-dialog.h"
#include "../midi-agent.h"
#include "../version.h"

Expand Down Expand Up @@ -82,4 +82,5 @@ private slots:
int editrow = -1;
bool editmode = false;
bool switching = false;
MidiHook *edithook;
};
47 changes: 30 additions & 17 deletions src/forms/settings-dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1428,8 +1428,11 @@
</size>
</property>
<layout class="QGridLayout" name="gridLayout_28">
<item row="2" column="0">
<widget class="QPushButton" name="btn_add">
<item row="4" column="0">
<widget class="QPushButton" name="btn_delete">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -1443,12 +1446,19 @@
</size>
</property>
<property name="text">
<string>Add Mapping</string>
<string>Delete Mapping</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="btn_delete">
<item row="1" column="0">
<widget class="QLabel" name="label_optional">
<property name="text">
<string>* optional</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="btn_add">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -1462,19 +1472,12 @@
</size>
</property>
<property name="text">
<string>Delete Mapping</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_optional">
<property name="text">
<string>* optional</string>
<string>Add Mapping</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer_3">
<item row="0" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
Expand All @@ -1486,8 +1489,8 @@
</property>
</spacer>
</item>
<item row="0" column="0">
<spacer name="verticalSpacer_4">
<item row="6" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
Expand All @@ -1499,6 +1502,16 @@
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="btn_reset">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
7 changes: 6 additions & 1 deletion src/midi-agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ void MidiAgent::remove_MidiHook(MidiHook *hook)
delete (hook);
}
}
/// <summary>
void MidiAgent::edit_midi_hook(MidiHook *old_hook, MidiHook *new_hook)
{
remove_MidiHook(old_hook);
add_MidiHook(new_hook);
}
/// <summary>
/// Clears all the MidiHooks for this device.
/// *This does not delete hooks from config unless saved afterwards*
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/midi-agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class MidiAgent : public QObject {
void exe_midi_hook_if_exists(MidiMessage *message);
void add_MidiHook(MidiHook *hook);
void remove_MidiHook(MidiHook *hook);
void edit_midi_hook(MidiHook *old_hook, MidiHook *new_hook);
void clear_MidiHooks();
QString GetData();
void remove_source(const RpcEvent &event);
Expand Down

0 comments on commit a17a646

Please sign in to comment.