Add macro action to stop other macros

This commit is contained in:
WarmUpTill
2022-01-14 18:49:43 +01:00
committed by WarmUpTill
parent 7349841758
commit 38b7e08711
5 changed files with 15 additions and 4 deletions

View File

@@ -334,6 +334,7 @@ AdvSceneSwitcher.action.macro.type.pause="Pause"
AdvSceneSwitcher.action.macro.type.unpause="Unpause"
AdvSceneSwitcher.action.macro.type.resetCounter="Reset counter"
AdvSceneSwitcher.action.macro.type.run="Run"
AdvSceneSwitcher.action.macro.type.stop="Stop"
AdvSceneSwitcher.action.macro.entry="{{actions}} {{macros}}"
AdvSceneSwitcher.action.pluginState="Plugin state"
AdvSceneSwitcher.action.pluginState.type.stop="Stop the Advanced Scene Switcher plugin"

View File

@@ -9,6 +9,7 @@ enum class PerformMacroAction {
UNPAUSE,
RESET_COUNTER,
RUN,
STOP,
};
class MacroActionMacro : public MacroRefAction {

View File

@@ -88,6 +88,7 @@ public:
bool MatchOnChange() { return _matchOnChange; }
int GetCount() { return _count; };
void ResetCount() { _count = 0; };
void Stop() { _stop = true; }
std::deque<std::shared_ptr<MacroCondition>> &Conditions()
{
return _conditions;
@@ -126,6 +127,7 @@ private:
obs_hotkey_id _unpauseHotkey = OBS_INVALID_HOTKEY_ID;
obs_hotkey_id _togglePauseHotkey = OBS_INVALID_HOTKEY_ID;
bool _die = false;
bool _stop = false;
bool _done = true;
std::thread _thread;

View File

@@ -16,6 +16,7 @@ const static std::map<PerformMacroAction, std::string> actionTypes = {
{PerformMacroAction::RESET_COUNTER,
"AdvSceneSwitcher.action.macro.type.resetCounter"},
{PerformMacroAction::RUN, "AdvSceneSwitcher.action.macro.type.run"},
{PerformMacroAction::STOP, "AdvSceneSwitcher.action.macro.type.stop"},
};
bool MacroActionMacro::PerformAction()
@@ -37,6 +38,9 @@ bool MacroActionMacro::PerformAction()
case PerformMacroAction::RUN:
_macro->PerformAction();
break;
case PerformMacroAction::STOP:
_macro->Stop();
break;
default:
break;
}
@@ -63,6 +67,9 @@ void MacroActionMacro::LogAction()
vblog(LOG_INFO, "run nested macro \"%s\"",
_macro->Name().c_str());
break;
case PerformMacroAction::STOP:
vblog(LOG_INFO, "stopped macro \"%s\"", _macro->Name().c_str());
break;
default:
break;
}

View File

@@ -29,7 +29,7 @@ Macro::Macro(const std::string &name)
Macro::~Macro()
{
_stop = true;
_die = true;
if (_thread.joinable()) {
_thread.join();
}
@@ -121,9 +121,9 @@ bool Macro::PerformAction(bool forceParallel, bool ignorePause)
vblog(LOG_INFO, "macro %s already running", _name.c_str());
return !forceParallel;
}
bool ret = true;
_stop = false;
_done = false;
bool ret = true;
if (_runInParallel || forceParallel) {
if (_thread.joinable()) {
_thread.join();
@@ -155,7 +155,7 @@ void Macro::RunActions(bool &retVal, bool ignorePause)
for (auto &a : _actions) {
a->LogAction();
ret = ret && a->PerformAction();
if (!ret || _stop || (_paused && !ignorePause)) {
if (!ret || (_paused && !ignorePause) || _stop || _die) {
retVal = ret;
_done = true;
return;