Reduce dependencies to switcher-data.hpp implementation details

This is necessary for the switch to libremidi version 4 due to
incompatabilities  with websocketpp, but also might save some headaches
later on.
This commit is contained in:
WarmUpTill
2023-12-01 23:51:11 +01:00
committed by WarmUpTill
parent 258a6d076e
commit fb664b6f08
14 changed files with 137 additions and 46 deletions

View File

@@ -291,6 +291,8 @@ target_sources(
src/utils/obs-module-helper.hpp
src/utils/osc-helpers.cpp
src/utils/osc-helpers.hpp
src/utils/plugin-state-helper.cpp
src/utils/plugin-state-helper.hpp
src/utils/priority-helper.cpp
src/utils/priority-helper.hpp
src/utils/process-config.cpp

View File

@@ -33,7 +33,7 @@ void AdvSceneSwitcher::on_noMatchDontSwitch_clicked()
}
std::lock_guard<std::mutex> lock(switcher->m);
switcher->switchIfNotMatching = SwitcherData::NoMatch::NO_SWITCH;
switcher->switchIfNotMatching = NoMatchBehavior::NO_SWITCH;
ui->noMatchSwitchScene->setEnabled(false);
ui->randomDisabledWarning->setVisible(true);
}
@@ -45,7 +45,7 @@ void AdvSceneSwitcher::on_noMatchSwitch_clicked()
}
std::lock_guard<std::mutex> lock(switcher->m);
switcher->switchIfNotMatching = SwitcherData::NoMatch::SWITCH;
switcher->switchIfNotMatching = NoMatchBehavior::SWITCH;
ui->noMatchSwitchScene->setEnabled(true);
UpdateNonMatchingScene(ui->noMatchSwitchScene->currentText());
ui->randomDisabledWarning->setVisible(true);
@@ -58,7 +58,7 @@ void AdvSceneSwitcher::on_noMatchRandomSwitch_clicked()
}
std::lock_guard<std::mutex> lock(switcher->m);
switcher->switchIfNotMatching = SwitcherData::NoMatch::RANDOM_SWITCH;
switcher->switchIfNotMatching = NoMatchBehavior::RANDOM_SWITCH;
ui->noMatchSwitchScene->setEnabled(false);
ui->randomDisabledWarning->setVisible(false);
}
@@ -624,9 +624,9 @@ void SwitcherData::LoadGeneralSettings(obs_data_t *obj)
interval = obs_data_get_int(obj, "interval");
obs_data_set_default_int(obj, "switch_if_not_matching",
static_cast<int>(NoMatch::NO_SWITCH));
switchIfNotMatching =
(NoMatch)obs_data_get_int(obj, "switch_if_not_matching");
static_cast<int>(NoMatchBehavior::NO_SWITCH));
switchIfNotMatching = static_cast<NoMatchBehavior>(
obs_data_get_int(obj, "switch_if_not_matching"));
std::string nonMatchingSceneName =
obs_data_get_string(obj, "non_matching_scene");
nonMatchingScene = GetWeakSourceByName(nonMatchingSceneName.c_str());
@@ -800,12 +800,13 @@ void SwitcherData::CheckNoMatchSwitch(bool &match, OBSWeakSource &scene,
return;
}
if (switchIfNotMatching == NoMatch::SWITCH && nonMatchingScene) {
if (switchIfNotMatching == NoMatchBehavior::SWITCH &&
nonMatchingScene) {
match = true;
scene = nonMatchingScene;
transition = nullptr;
}
if (switchIfNotMatching == NoMatch::RANDOM_SWITCH) {
if (switchIfNotMatching == NoMatchBehavior::RANDOM_SWITCH) {
match = checkRandom(scene, transition, sleep);
}
}
@@ -956,11 +957,11 @@ void AdvSceneSwitcher::SetupGeneralTab()
{
PopulateSceneSelection(ui->noMatchSwitchScene, false);
if (switcher->switchIfNotMatching == SwitcherData::NoMatch::SWITCH) {
if (switcher->switchIfNotMatching == NoMatchBehavior::SWITCH) {
ui->noMatchSwitch->setChecked(true);
ui->noMatchSwitchScene->setEnabled(true);
} else if (switcher->switchIfNotMatching ==
SwitcherData::NoMatch::NO_SWITCH) {
NoMatchBehavior::NO_SWITCH) {
ui->noMatchDontSwitch->setChecked(true);
ui->noMatchSwitchScene->setEnabled(false);
} else {

View File

@@ -143,8 +143,7 @@ void AdvSceneSwitcher::SetupRandomTab()
border-radius: 7px; \
border-color: rgb(0,0,0,0) \
}");
if (switcher->switchIfNotMatching !=
SwitcherData::NoMatch::RANDOM_SWITCH) {
if (switcher->switchIfNotMatching != NoMatchBehavior::RANDOM_SWITCH) {
if (!switcher->disableHints) {
PulseWidget(ui->randomDisabledWarning, QColor(Qt::red),
QColor(0, 0, 0, 0));

View File

@@ -1,8 +1,9 @@
#include "macro-action-plugin-state.hpp"
#include "switcher-data.hpp"
#include "plugin-state-helper.hpp"
#include "utility.hpp"
#include <thread>
#include <condition_variable>
#include <QMainWindow>
using namespace std::chrono_literals;
@@ -27,40 +28,38 @@ const static std::map<PluginStateAction, std::string> actionTypes = {
"AdvSceneSwitcher.action.pluginState.type.terminate"},
};
const static std::map<SwitcherData::NoMatch, std::string> noMatchValues = {
{SwitcherData::NoMatch::NO_SWITCH,
const static std::map<NoMatchBehavior, std::string> noMatchValues = {
{NoMatchBehavior::NO_SWITCH,
"AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.dontSwitch"},
{SwitcherData::NoMatch::SWITCH,
{NoMatchBehavior::SWITCH,
"AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchTo"},
{SwitcherData::NoMatch::RANDOM_SWITCH,
{NoMatchBehavior::RANDOM_SWITCH,
"AdvSceneSwitcher.generalTab.generalBehavior.onNoMet.switchToRandom"},
};
static void stopPlugin()
{
std::thread t([]() { switcher->Stop(); });
std::thread t([]() { StopPlugin(); });
t.detach();
}
static void importSettings(const std::string &path)
{
if (switcher->settingsWindowOpened) {
if (SettingsWindowIsOpened()) {
return;
}
obs_data_t *obj = obs_data_create_from_json_file(path.c_str());
OBSDataAutoRelease obj = obs_data_create_from_json_file(path.c_str());
if (!obj) {
return;
}
switcher->LoadSettings(obj);
obs_data_release(obj);
LoadPluginSettings(obj);
}
static void setNoMatchBehaviour(int value, OBSWeakSource &scene)
{
switcher->switchIfNotMatching =
static_cast<SwitcherData::NoMatch>(value);
if (switcher->switchIfNotMatching == SwitcherData::NoMatch::SWITCH) {
switcher->nonMatchingScene = scene;
SetPluginNoMatchBehavior(static_cast<NoMatchBehavior>(value));
if (GetPluginNoMatchBehavior() == NoMatchBehavior::SWITCH) {
SetNoMatchScene(scene);
}
}
@@ -342,8 +341,8 @@ void MacroActionPluginStateEdit::SetWidgetVisibility()
break;
case PluginStateAction::NO_MATCH_BEHAVIOUR:
_values->show();
if (static_cast<SwitcherData::NoMatch>(_entryData->_value) ==
SwitcherData::NoMatch::SWITCH) {
if (static_cast<NoMatchBehavior>(_entryData->_value) ==
NoMatchBehavior::SWITCH) {
_scenes->show();
}
break;

View File

@@ -1,5 +1,5 @@
#include "macro-action-scene-collection.hpp"
#include "switcher-data.hpp"
#include "plugin-state-helper.hpp"
#include "utility.hpp"
namespace advss {
@@ -17,7 +17,7 @@ bool MacroActionSceneCollection::PerformAction()
// Changing the scene collection will also reload the settings of the
// scene switcher, so to avoid issues of not being able to change
// settings ignore this action if the settings dialog is opened.
if (switcher->settingsWindowOpened) {
if (SettingsWindowIsOpened()) {
return false;
}
obs_frontend_set_current_scene_collection(_sceneCollection.c_str());

View File

@@ -1,15 +1,17 @@
#include "midi-helpers.hpp"
#include <utility.hpp>
#include <log-helper.hpp>
#include <obs-module-helper.hpp>
#include <switcher-data.hpp>
#include <plugin-state-helper.hpp>
#include <sync-helper.hpp>
namespace advss {
static std::map<std::pair<MidiDeviceType, int>, MidiDeviceInstance *>
SetupMidiMessageVector()
{
GetSwitcher()->AddIntervalResetStep(
AddIntervalResetStep(
MidiDeviceInstance::ClearMessageBuffersOfAllDevices);
return {};
}

View File

@@ -3,7 +3,7 @@
#include "twitch-helpers.hpp"
#include <log-helper.hpp>
#include <switcher-data.hpp>
#include <plugin-state-helper.hpp>
namespace advss {
@@ -364,8 +364,7 @@ TwitchChatConnection::~TwitchChatConnection()
static bool setupChatMessageClear()
{
GetSwitcher()->AddIntervalResetStep(
&TwitchChatConnection::ClearAllMessages);
AddIntervalResetStep(&TwitchChatConnection::ClearAllMessages);
return true;
}

View File

@@ -3,7 +3,7 @@
#include "twitch-helpers.hpp"
#include <log-helper.hpp>
#include <switcher-data.hpp>
#include <plugin-state-helper.hpp>
namespace advss {
@@ -58,7 +58,7 @@ EventSub::~EventSub()
static bool setupEventSubMessageClear()
{
GetSwitcher()->AddIntervalResetStep(&EventSub::ClearAllEvents);
AddIntervalResetStep(&EventSub::ClearAllEvents);
return true;
}

View File

@@ -1,10 +1,14 @@
#include "token.hpp"
#include "twitch-helpers.hpp"
#include <switcher-data.hpp>
#include <plugin-state-helper.hpp>
#include <log-helper.hpp>
#include <obs-module-helper.hpp>
#include <utility.hpp>
#include <QScrollArea>
#include <QDesktopServices>
#include <QGroupBox>
#include <QUrl>
namespace advss {
@@ -78,8 +82,8 @@ static void loadConnections(obs_data_t *obj);
bool setupTwitchTokenSupport()
{
GetSwitcher()->AddSaveStep(saveConnections);
GetSwitcher()->AddLoadStep(loadConnections);
AddSaveStep(saveConnections);
AddLoadStep(loadConnections);
return true;
}

View File

@@ -45,7 +45,7 @@ void SwitcherData::Prune()
}
if (nonMatchingScene && !WeakSourceValid(nonMatchingScene)) {
switchIfNotMatching = NoMatch::NO_SWITCH;
switchIfNotMatching = NoMatchBehavior::NO_SWITCH;
nonMatchingScene = nullptr;
}

View File

@@ -21,6 +21,7 @@
#include "curl-helper.hpp"
#include "priority-helper.hpp"
#include "log-helper.hpp"
#include "plugin-state-helper.hpp"
#include <condition_variable>
#include <vector>
@@ -143,8 +144,7 @@ public:
int interval = default_interval;
OBSWeakSource nonMatchingScene;
enum class NoMatch { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 };
NoMatch switchIfNotMatching = NoMatch::NO_SWITCH;
NoMatchBehavior switchIfNotMatching = NoMatchBehavior::NO_SWITCH;
Duration noMatchDelay;
enum class StartupBehavior { PERSIST = 0, START = 1, STOP = 2 };
StartupBehavior startupBehavior = StartupBehavior::PERSIST;

View File

@@ -0,0 +1,61 @@
#include "plugin-state-helper.hpp"
#include "switcher-data.hpp"
namespace advss {
void LoadPluginSettings(obs_data_t *obj)
{
GetSwitcher()->LoadSettings(obj);
}
void AddSaveStep(std::function<void(obs_data_t *)> step)
{
GetSwitcher()->AddSaveStep(step);
}
void AddLoadStep(std::function<void(obs_data_t *)> step)
{
GetSwitcher()->AddLoadStep(step);
}
void AddPostLoadStep(std::function<void()> step)
{
GetSwitcher()->AddPostLoadStep(step);
}
void AddIntervalResetStep(std::function<void()> step)
{
GetSwitcher()->AddIntervalResetStep(step);
}
void StopPlugin()
{
GetSwitcher()->Stop();
}
void StartPlugin()
{
GetSwitcher()->Start();
}
void SetPluginNoMatchBehavior(NoMatchBehavior behavior)
{
GetSwitcher()->switchIfNotMatching = behavior;
}
void SetNoMatchScene(const OBSWeakSource &scene)
{
GetSwitcher()->nonMatchingScene = scene;
}
NoMatchBehavior GetPluginNoMatchBehavior()
{
return GetSwitcher()->switchIfNotMatching;
}
bool SettingsWindowIsOpened()
{
return GetSwitcher()->settingsWindowOpened;
}
} // namespace advss

View File

@@ -0,0 +1,24 @@
#pragma once
#include <functional>
#include <obs.hpp>
namespace advss {
void LoadPluginSettings(obs_data_t *);
void AddSaveStep(std::function<void(obs_data_t *)>);
void AddLoadStep(std::function<void(obs_data_t *)>);
void AddPostLoadStep(std::function<void()>);
void AddIntervalResetStep(std::function<void()>);
void StopPlugin();
void StartPlugin();
enum class NoMatchBehavior { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 };
void SetPluginNoMatchBehavior(NoMatchBehavior);
NoMatchBehavior GetPluginNoMatchBehavior();
void SetNoMatchScene(const OBSWeakSource &);
bool SettingsWindowIsOpened();
} // namespace advss

View File

@@ -2,7 +2,7 @@
#include "advanced-scene-switcher.hpp"
#include "macro.hpp"
#include "macro-segment.hpp"
#include "switcher-data.hpp"
#include "plugin-state-helper.hpp"
#include "utility.hpp"
#include <QVariant>
@@ -170,7 +170,7 @@ void TempVariableRef::Load(obs_data_t *obj, Macro *macro, const char *name)
_id = obs_data_get_string(data, "id");
const auto type =
static_cast<SegmentType>(obs_data_get_int(data, "type"));
switcher->AddPostLoadStep([this, idx, type, macro]() {
AddPostLoadStep([this, idx, type, macro]() {
this->PostLoad(idx, type, macro);
});
}
@@ -427,7 +427,7 @@ void NotifyUIAboutTempVarChange()
obs_queue_task(
OBS_TASK_UI,
[](void *) {
if (!GetSwitcher()->settingsWindowOpened) {
if (!SettingsWindowIsOpened()) {
return;
}
AdvSceneSwitcher::window->SegmentTempVarsChanged();