Skip to content

Commit

Permalink
Change Mapping table to mapping List
Browse files Browse the repository at this point in the history
  • Loading branch information
cpyarger committed Mar 20, 2021
1 parent 75d5490 commit 8d6acff
Show file tree
Hide file tree
Showing 12 changed files with 593 additions and 606 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ 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})
qt5_wrap_ui(obs_midi_UI_HEADERS src/forms/settings-dialog.ui)

add_library(obs-midi MODULE
${obs-midi_SOURCES}
Expand Down
201 changes: 133 additions & 68 deletions src/Midi_hook.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include"obs-controller.h"
#include "obs-controller.h"
#include "Midi_hook.h"

MidiHook::MidiHook(){};
MidiHook::MidiHook(const QString &json_string)
{
const auto data = obs_data_create_from_json(json_string.toStdString().c_str());
const auto data = obs_data_create_from_json(json_string.qtocs());
channel = obs_data_get_int(data, "channel");
message_type = obs_data_get_string(data, "message_type");
norc = obs_data_get_int(data, "norc");
Expand All @@ -27,7 +27,7 @@ MidiHook::MidiHook(const QString &json_string)
int_override.emplace(obs_data_get_int(data, "range_max"));
value_as_filter = obs_data_get_bool(data, "value_as_filter");
value.emplace(obs_data_get_int(data, "value"));
setAction();
set_obs_action();
obs_data_release(data);
}
MidiMessage *MidiHook::get_message_from_hook()
Expand All @@ -39,94 +39,159 @@ MidiMessage *MidiHook::get_message_from_hook()
message->value = *this->value;
return std::move(message);
}

QString MidiHook::GetData()
void MidiHook::get_scene(obs_data_t *data)
{
if (scene.isEmpty() || scene.isNull())
return;
obs_data_set_string(data, "scene", scene.qtocs());
}
void MidiHook::get_source(obs_data_t *data)
{
if (source.isEmpty())
return;
obs_data_set_string(data, "source", source.qtocs());
}
void MidiHook::get_filter(obs_data_t *data)
{
if (filter.isEmpty())
return;
obs_data_set_string(data, "filter", filter.qtocs());
}
void MidiHook::get_transition(obs_data_t *data)
{
if (transition.isEmpty())
return;
obs_data_set_string(data, "transition", transition.qtocs());
}
void MidiHook::get_item(obs_data_t *data)
{
if (item.isEmpty())
return;
obs_data_set_string(data, "item", item.qtocs());
}
void MidiHook::get_hotkey(obs_data_t *data)
{
if (hotkey.isEmpty())
return;
obs_data_set_string(data, "hotkey", hotkey.qtocs());
}
void MidiHook::get_audio_source(obs_data_t *data)
{
if (audio_source.isEmpty())
return;
obs_data_set_string(data, "audio_source", audio_source.qtocs());
}
void MidiHook::get_media_source(obs_data_t *data)
{
if (media_source.isEmpty())
return;
obs_data_set_string(data, "media_source", media_source.qtocs());
}
void MidiHook::get_duration(obs_data_t *data)
{
blog(LOG_DEBUG, "MH::GetData");
obs_data_t *data = obs_data_create();
obs_data_set_int(data, "channel", channel);
obs_data_set_string(data, "message_type", message_type.toStdString().c_str());
obs_data_set_int(data, "norc", norc);
obs_data_set_string(data, "action", action.toStdString().c_str());
if (!scene.isEmpty())
obs_data_set_string(data, "scene", scene.toStdString().c_str());
if (!source.isEmpty())
obs_data_set_string(data, "source", source.toStdString().c_str());
if (!filter.isEmpty())
obs_data_set_string(data, "filter", filter.toStdString().c_str());
if (!transition.isEmpty())
obs_data_set_string(data, "transition", transition.toStdString().c_str());
if (!item.isEmpty())
obs_data_set_string(data, "item", item.toStdString().c_str());
if (!hotkey.isEmpty())
obs_data_set_string(data, "hotkey", hotkey.toStdString().c_str());
if (!audio_source.isEmpty())
obs_data_set_string(data, "audio_source", audio_source.toStdString().c_str());
if (!media_source.isEmpty())
obs_data_set_string(data, "media_source", media_source.toStdString().c_str());
if (duration)
obs_data_set_int(data, "duration", *duration);
if (!scene_collection.isEmpty())
obs_data_set_string(data, "scene_collection", scene_collection.toStdString().c_str());
if (!profile.isEmpty())
obs_data_set_string(data, "profile", profile.toStdString().c_str());
if (!string_override.isEmpty())
obs_data_set_string(data, "string_override", string_override.toStdString().c_str());
}
void MidiHook::get_scene_collection(obs_data_t *data)
{
if (scene_collection.isEmpty())
return;
obs_data_set_string(data, "scene_collection", scene_collection.qtocs());
}
void MidiHook::get_profile(obs_data_t *data)
{
if (profile.isEmpty())
return;
obs_data_set_string(data, "profile", profile.qtocs());
}
void MidiHook::get_string_override(obs_data_t *data)
{
if (string_override.isEmpty())
return;
obs_data_set_string(data, "string_override", string_override.qtocs());
}
void MidiHook::get_bool_override(obs_data_t *data)
{
if (bool_override)
obs_data_set_bool(data, "bool_override", *bool_override);
}
void MidiHook::get_int_override(obs_data_t *data)
{
if (int_override)
obs_data_set_int(data, "int_override", *int_override);
}
void MidiHook::get_range_min(obs_data_t *data)
{
if (range_min)
obs_data_set_int(data, "range_min", *range_min);
}
void MidiHook::get_range_max(obs_data_t *data)
{
if (range_max)
obs_data_set_int(data, "range_max", *range_max);
}
void MidiHook::get_value(obs_data_t *data)
{
obs_data_set_bool(data, "value_as_filter", value_as_filter);
if (value_as_filter)
obs_data_set_int(data, "value", *value);
obs_data_set_bool(data, "value_as_filter", value_as_filter);
QString hook_data(obs_data_get_json(data));
blog(LOG_DEBUG, "Midi Hook JSON = %s", hook_data.toStdString().c_str());
obs_data_release(data);
blog(LOG_DEBUG, "Midi Hook JSON post release = %s", hook_data.toStdString().c_str());
return hook_data;
}
void MidiHook::setAction()
void MidiHook::get_channel(obs_data_t *data)
{
if (action.isEmpty() || action.isNull())
return;
Actions AC(this);
actions = AC.get_action(action, this);
obs_data_set_int(data, "channel", channel);
}
void MidiHook::EXE()

void MidiHook::get_message(obs_data_t *data)
{
actions->execute();
obs_data_set_string(data, "message_type", message_type.qtocs());
}
void MidiHook::setHotkey(obs_hotkey_t *hotkey)

void MidiHook::get_norc(obs_data_t *data)
{
if (!hotkey) {
hotkeyInstance = NULL;
return;
}
hotkeyInstance = hotkey;
this->hotkey = QString(obs_hotkey_get_name(hotkey));
obs_data_set_int(data, "norc", norc);
}

void MidiHook::initHotkey()
void MidiHook::get_action(obs_data_t *data)
{
if (hotkey.isEmpty()) {
this->hotkey = nullptr;
return;
}
obs_hotkey_t *obsHotkey = Utils::FindHotkeyByName(hotkey);
if (obsHotkey) {
this->hotkeyInstance = obsHotkey;
}
obs_data_set_string(data, "action", action.qtocs());
}

obs_hotkey_t *MidiHook::getHotkey() const
QString MidiHook::GetData()
{
if (!hotkeyInstance) {
blog(LOG_ERROR, "ERROR: Stored hotkey %s not found", hotkey.toStdString().c_str());
return nullptr;
}
return hotkeyInstance;
obs_data_t *data = obs_data_create();
get_channel(data);
get_message(data);
get_norc(data);
get_action(data);
get_scene(data);
get_source(data);
get_filter(data);
get_transition(data);
get_item(data);
get_hotkey(data);
get_audio_source(data);
get_media_source(data);
get_duration(data);
get_scene_collection(data);
get_profile(data);
get_string_override(data);
get_bool_override(data);
get_int_override(data);
get_range_min(data);
get_range_max(data);
get_value(data);
QString hook_data(obs_data_get_json(data));
obs_data_release(data);
return hook_data;
}
void MidiHook::set_obs_action()
{
if (action.isEmpty() || action.isNull())
return;
Actions AC(this);
actions = AC.make_action(action, this);
}
void MidiHook::EXE()
{
actions->execute();
}
36 changes: 31 additions & 5 deletions src/Midi_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class MidiHook : public QObject {
MidiHook(const QString &json_string);
MidiMessage *get_message_from_hook();
QString GetData();

void set_obs_action();
void EXE();
int channel = -1; // midi channel
QString message_type; // Message Type
int norc = -1; // Note or Control
Expand All @@ -37,10 +38,35 @@ class MidiHook : public QObject {
std::optional<int> range_max;
bool value_as_filter = false;
std::optional<int> value;
Actions *actions;

private:
/// <summary>
/// Function pointer to execute action
/// class pointer to execute action
/// </summary>
Actions *actions;
void EXE();
void setAction();


//get Midi data from hook data
void get_channel(obs_data_t *data);
void get_message(obs_data_t *data);
void get_norc(obs_data_t *data);
void get_value(obs_data_t *data);
// get sction data from hook data
void get_action(obs_data_t *data);
void get_scene(obs_data_t *data);
void get_source(obs_data_t *data);
void get_filter(obs_data_t *data);
void get_transition(obs_data_t *data);
void get_item(obs_data_t *data);
void get_hotkey(obs_data_t *data);
void get_audio_source(obs_data_t *data);
void get_media_source(obs_data_t *data);
void get_duration(obs_data_t *data);
void get_scene_collection(obs_data_t *data);
void get_profile(obs_data_t *data);
void get_string_override(obs_data_t *data);
void get_bool_override(obs_data_t *data);
void get_int_override(obs_data_t *data);
void get_range_min(obs_data_t *data);
void get_range_max(obs_data_t *data);
};
6 changes: 3 additions & 3 deletions src/device-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DeviceManager::~DeviceManager()
*/
void DeviceManager::Load(QString datastring)
{
obs_data_t *incoming_data = obs_data_create_from_json(datastring.toStdString().c_str());
obs_data_t *incoming_data = obs_data_create_from_json(datastring.qtocs());
obs_data_array_t *data = obs_data_get_array(incoming_data, "MidiDevices");
const size_t deviceCount = obs_data_array_count(data);
for (size_t i = 0; i < deviceCount; i++) {
Expand All @@ -40,7 +40,7 @@ void DeviceManager::Unload()
{
blog(LOG_INFO, "UNLOADING DEVICE MANAGER");
for (auto &midiAgent : midiAgents) {
blog(LOG_DEBUG, "Unloading Midi Device %s", midiAgent->get_midi_input_name().toStdString().c_str());
blog(LOG_DEBUG, "Unloading Midi Device %s", midiAgent->get_midi_input_name().qtocs());
midiAgent->clear_MidiHooks();
delete midiAgent;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ QString DeviceManager::GetData()
obs_data_t *return_data = obs_data_create();
obs_data_array_t *data = obs_data_array_create();
for (auto midiAgent : midiAgents) {
obs_data_t *adata = obs_data_create_from_json(midiAgent->GetData().toStdString().c_str());
obs_data_t *adata = obs_data_create_from_json(midiAgent->GetData().qtocs());
obs_data_array_push_back(data, adata);
obs_data_release(adata);
}
Expand Down
13 changes: 3 additions & 10 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ QString Events::getRecordingTimecode()
void Events::OnSceneChange()
{
const OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene();
obs_data_t *idata = obs_data_create_from_json(Utils::GetSceneItems(currentScene).toStdString().c_str());
obs_data_t *idata = obs_data_create_from_json(Utils::GetSceneItems(currentScene).qtocs());
const OBSDataArrayAutoRelease sceneItems = obs_data_get_array(idata, "array");
obs_data_release(idata);
obs_data_t *data = obs_data_create();
Expand Down Expand Up @@ -1538,7 +1538,7 @@ void Events::OnPreviewSceneChanged()
const OBSSourceAutoRelease scene = obs_frontend_get_current_preview_scene();
if (!scene)
return;
obs_data_t *idata = obs_data_create_from_json(Utils::GetSceneItems(scene).toStdString().c_str());
obs_data_t *idata = obs_data_create_from_json(Utils::GetSceneItems(scene).qtocs());
const OBSDataArrayAutoRelease sceneItems = obs_data_get_array(idata, "array");
obs_data_release(idata);
obs_data_t *data = obs_data_create();
Expand Down Expand Up @@ -1619,11 +1619,4 @@ obs_data_t *Events::GetStats()
obs_data_set_double(stats, "free-disk-space", freeDiskSpace);
return stats;
}
void Events::initialiseHotkeysHooks()
{
for (auto midiAgent : GetDeviceManager()->get_active_midi_devices()) {
for (auto midiHook : midiAgent->GetMidiHooks()) {
midiHook->initHotkey();
}
}
}

Loading

0 comments on commit 8d6acff

Please sign in to comment.