Skip to content

Commit

Permalink
Update CI, Build actions classes
Browse files Browse the repository at this point in the history
  • Loading branch information
cpyarger committed Mar 19, 2021
1 parent 7a712f0 commit 156260d
Show file tree
Hide file tree
Showing 9 changed files with 460 additions and 286 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/CI Build and release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,3 @@ jobs:
asset_path: ${{ github.workspace }}/${{ steps.version.outputs.version }}-linux/obs-midi-Linux-${{ steps.version.outputs.version }}-x64.tar.gz
asset_name: obs-midi-Linux-${{ steps.version.outputs.version }}-x64.tar.gz
asset_content_type: application/octet-stream
- name: 'Clean old releases'
uses: dev-drprasad/[email protected]
with:
keep_latest: 5
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Those two guys are
[![Crowdin](https://badges.crowdin.net/obs-midi/localized.svg)](https://crowdin.com/project/obs-midi)
[![CodeFactor](https://www.codefactor.io/repository/github/cpyarger/obs-midi/badge/master)](https://www.codefactor.io/repository/github/cpyarger/obs-midi/overview/master)

A not fully accurate download count (based off the last few releases I have kept) [![img](https://img.shields.io/github/downloads/cpyarger/obs-midi/total)](#)
Currently runs on Windows and Linux, and MAC

# Installing
Expand Down
199 changes: 39 additions & 160 deletions src/Midi_hook.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#include"obs-controller.h"
#include "Midi_hook.h"

#include "obs-controller.h"
MidiHook::MidiHook(){};
MidiHook::MidiHook(const QString &json_string)
{
Expand Down Expand Up @@ -40,10 +39,7 @@ MidiMessage *MidiHook::get_message_from_hook()
message->value = *this->value;
return std::move(message);
}
void MidiHook::EXE()
{
(*obsControlFunction)(this);
}

QString MidiHook::GetData()
{
blog(LOG_DEBUG, "MH::GetData");
Expand Down Expand Up @@ -95,159 +91,42 @@ QString MidiHook::GetData()
}
void MidiHook::setAction()
{
switch (ActionsClass::string_to_action(Utils::untranslate(action))) {
case ActionsClass::Set_Current_Scene:
break;
case ActionsClass::Reset_Scene_Item:
obsControlFunction = ResetSceneItem;
break;
case ActionsClass::Toggle_Mute:
obsControlFunction = ToggleMute;
break;
case ActionsClass::Do_Transition:
obsControlFunction = TransitionToProgram;
break;
case ActionsClass::Set_Current_Transition:
obsControlFunction = SetCurrentTransition;
break;
case ActionsClass::Set_Mute:
obsControlFunction = SetMute;
break;
case ActionsClass::Toggle_Start_Stop_Streaming:
obsControlFunction = StartStopStreaming;
break;
case ActionsClass::Set_Preview_Scene:
obsControlFunction = SetPreviewScene;
break;
case ActionsClass::Set_Current_Scene_Collection:
obsControlFunction = SetCurrentSceneCollection;
break;
case ActionsClass::Set_Transition_Duration:
obsControlFunction = SetTransitionDuration;
break;
case ActionsClass::Start_Streaming:
obsControlFunction = StartStreaming;
break;
case ActionsClass::Stop_Streaming:
obsControlFunction = StopStreaming;
break;
case ActionsClass::Start_Recording:
obsControlFunction = StartRecording;
break;
case ActionsClass::Stop_Recording:
obsControlFunction = StopRecording;
break;
case ActionsClass::Start_Replay_Buffer:
obsControlFunction = StartReplayBuffer;
break;
case ActionsClass::Stop_Replay_Buffer:
obsControlFunction = StopReplayBuffer;
break;
case ActionsClass::Set_Volume:
obsControlFunction = SetVolume;
break;
case ActionsClass::Take_Source_Screenshot:
obsControlFunction = TakeSourceScreenshot;
break;
case ActionsClass::Pause_Recording:
obsControlFunction = PauseRecording;
break;
case ActionsClass::Enable_Source_Filter:
obsControlFunction = EnableSourceFilter;
break;
case ActionsClass::Disable_Source_Filter:
obsControlFunction = DisableSourceFilter;
break;
case ActionsClass::Toggle_Start_Stop_Recording:
obsControlFunction = StartStopRecording;
break;
case ActionsClass::Toggle_Start_Stop_Replay_Buffer:
obsControlFunction = StartStopReplayBuffer;
break;
case ActionsClass::Resume_Recording:
obsControlFunction = ResumeRecording;
break;
case ActionsClass::Save_Replay_Buffer:
obsControlFunction = SaveReplayBuffer;
break;
case ActionsClass::Set_Current_Profile:
obsControlFunction = SetCurrentProfile;
break;
case ActionsClass::Toggle_Source_Filter:
obsControlFunction = ToggleSourceFilter;
break;
case ActionsClass::Set_Text_GDIPlus_Text:
obsControlFunction = SetTextGDIPlusText;
break;
case ActionsClass::Set_Browser_Source_URL:
obsControlFunction = SetBrowserSourceURL;
break;
case ActionsClass::Reload_Browser_Source:
obsControlFunction = ReloadBrowserSource;
break;
case ActionsClass::Set_Sync_Offset:
obsControlFunction = SetSyncOffset;
break;
case ActionsClass::Set_Source_Rotation:
obsControlFunction = SetSourceRotation;
break;
case ActionsClass::Set_Source_Position:
obsControlFunction = SetSourcePosition;
break;
case ActionsClass::Set_Gain_Filter:
obsControlFunction = SetGainFilter;
break;
case ActionsClass::Set_Opacity:
obsControlFunction = SetOpacity;
break;
case ActionsClass::Set_Source_Scale:
obsControlFunction = SetSourceScale;
break;
case ActionsClass::Move_T_Bar:
obsControlFunction = move_t_bar;
break;
case ActionsClass::Play_Pause_Media:
obsControlFunction = play_pause_media_source;
break;
case ActionsClass::Studio_Mode:
obsControlFunction = toggle_studio_mode;
break;
case ActionsClass::Reset_Stats:
obsControlFunction = reset_stats;
break;
case ActionsClass::Restart_Media:
obsControlFunction = restart_media;
break;
case ActionsClass::Stop_Media:
obsControlFunction = stop_media;
break;
case ActionsClass::Previous_Media:
obsControlFunction = prev_media;
break;
case ActionsClass::Next_Media:
obsControlFunction = next_media;
break;
case ActionsClass::Toggle_Source_Visibility:
obsControlFunction = ToggleSourceVisibility;
break;
case ActionsClass::Take_Screenshot:
obsControlFunction = TakeScreenshot;
break;
case ActionsClass::Disable_Preview:
obsControlFunction = DisablePreview;
break;
case ActionsClass::Enable_Preview:
obsControlFunction = EnablePreview;
break;
case ActionsClass::Toggle_Fade_Source:
obsControlFunction = make_opacity_filter;
break;
case ActionsClass::Trigger_Hotkey_By_Name:
obsControlFunction = TriggerHotkeyByName;
break;
if (action.isEmpty() || action.isNull())
return;
Actions AC(this);
actions = AC.get_action(action, this);
}
void MidiHook::EXE()
{
actions->execute();
}
void MidiHook::setHotkey(obs_hotkey_t *hotkey)
{
if (!hotkey) {
hotkeyInstance = NULL;
return;
}
hotkeyInstance = hotkey;
this->hotkey = QString(obs_hotkey_get_name(hotkey));
}

default:
blog(LOG_DEBUG, "Action Does not exist");
break;
};
void MidiHook::initHotkey()
{
if (hotkey.isEmpty()) {
this->hotkey = nullptr;
return;
}
obs_hotkey_t *obsHotkey = Utils::FindHotkeyByName(hotkey);
if (obsHotkey) {
this->hotkeyInstance = obsHotkey;
}
}

obs_hotkey_t *MidiHook::getHotkey() const
{
if (!hotkeyInstance) {
blog(LOG_ERROR, "ERROR: Stored hotkey %s not found", hotkey.toStdString().c_str());
return nullptr;
}
return hotkeyInstance;
}
4 changes: 2 additions & 2 deletions src/Midi_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <optional>
#include "utils.h"
#include "Midi_message.h"
class Actions;
/*
* Midi Hook Class
*/
Expand Down Expand Up @@ -39,8 +40,7 @@ class MidiHook : public QObject {
/// <summary>
/// Function pointer to execute action
/// </summary>
typedef void (*obsc)(MidiHook*);
obsc obsControlFunction;
Actions *actions;
void EXE();
void setAction();
};
8 changes: 8 additions & 0 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,3 +1620,11 @@ 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();
}
}
}
20 changes: 11 additions & 9 deletions src/midi-agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ void MidiAgent::edit_midi_hook(MidiHook *old_hook, MidiHook *new_hook)
/// </summary>
void MidiAgent::clear_MidiHooks()
{
for (int i = 0; i < midiHooks.count(); i++) {
delete midiHooks.at(i);
for (auto hook:midiHooks) {
delete hook;
}
midiHooks.clear();
}
Expand Down Expand Up @@ -444,21 +444,21 @@ QString MidiAgent::GetData()
/// <returns>MidiHook *</returns>
MidiHook *MidiAgent::get_midi_hook_if_exists(const RpcEvent &event) const
{
for (int i = 0; i < this->midiHooks.size(); i++) {
for (auto hook: this->midiHooks) {
bool found = false;
switch (ActionsClass::string_to_action(Utils::untranslate(midiHooks.at(i)->action))) {
switch (ActionsClass::string_to_action(Utils::untranslate(hook->action))) {
case ActionsClass::Actions::Set_Volume:
found = (midiHooks.at(i)->audio_source == QString(obs_data_get_string(event.additionalFields(), "sourceName")) &&
found = (hook->audio_source == QString(obs_data_get_string(event.additionalFields(), "sourceName")) &&
event.updateType() == "SourceVolumeChanged");
break;
case ActionsClass::Actions::Toggle_Mute:
found = (midiHooks.at(i)->audio_source == QString(obs_data_get_string(event.additionalFields(), "sourceName")) &&
found = (hook->audio_source == QString(obs_data_get_string(event.additionalFields(), "sourceName")) &&
event.updateType() == "SourceMuteStateChanged");
break;
case ActionsClass::Actions::Do_Transition:
case ActionsClass::Actions::Set_Preview_Scene:
case ActionsClass::Actions::Set_Current_Scene:
found = (midiHooks.at(i)->scene == QString(obs_data_get_string(event.additionalFields(), "scene-name")));
found = (hook->scene == QString(obs_data_get_string(event.additionalFields(), "scene-name")));
break;
case ActionsClass::Actions::Toggle_Start_Stop_Recording:
case ActionsClass::Actions::Start_Recording:
Expand Down Expand Up @@ -623,20 +623,22 @@ MidiHook *MidiAgent::get_midi_hook_if_exists(const RpcEvent &event) const
break;
}
if (found)
return midiHooks.at(i);
return hook;
}
return NULL;
}
/*Handle OBS events*/
void MidiAgent::handle_obs_event(const RpcEvent &event)
{
blog(LOG_DEBUG, "OBS Event : %s \n AD: %s", event.updateType().toStdString().c_str(), obs_data_get_json(event.additionalFields()));
MidiHook *hook = get_midi_hook_if_exists(event);
if (event.updateType() == "FinishedLoading") {
loading = false;
return;
}
if (loading)
return;
MidiHook *hook = get_midi_hook_if_exists(event);

/// <summary>
/// ON EVENT TYPE Find matching hook, pull data from that hook, and do thing.
/// </summary>
Expand Down
Loading

0 comments on commit 156260d

Please sign in to comment.