mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Rename and refactor macro class functions
LastConditionCheckTime() will be required to support custom condition check intervals per macro
This commit is contained in:
parent
94263cc7a0
commit
9eb4e90291
|
|
@ -196,13 +196,13 @@ void MacroActionMacro::RunActions(Macro *actionMacro) const
|
|||
}
|
||||
|
||||
if (_runOptions.reevaluateConditionState) {
|
||||
conditionMacro->CeckMatch(true);
|
||||
conditionMacro->CheckConditions(true);
|
||||
}
|
||||
|
||||
if ((_runOptions.logic == RunOptions::Logic::CONDITIONS &&
|
||||
conditionMacro->Matched()) ||
|
||||
conditionMacro->ConditionsMatched()) ||
|
||||
(_runOptions.logic == RunOptions::Logic::INVERT_CONDITIONS &&
|
||||
!conditionMacro->Matched())) {
|
||||
!conditionMacro->ConditionsMatched())) {
|
||||
runActionsHelper(actionMacro, _runOptions.runElseActions,
|
||||
_runOptions.setInputs, _runOptions.inputs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ bool MacroConditionMacro::CheckStateCondition()
|
|||
return false;
|
||||
}
|
||||
|
||||
return macro->Matched();
|
||||
return macro->ConditionsMatched();
|
||||
}
|
||||
|
||||
bool MacroConditionMacro::CheckMultiStateCondition()
|
||||
|
|
@ -72,7 +72,7 @@ bool MacroConditionMacro::CheckMultiStateCondition()
|
|||
if (!macro) {
|
||||
continue;
|
||||
}
|
||||
if (macro->Matched()) {
|
||||
if (macro->ConditionsMatched()) {
|
||||
matchedCount++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,8 +138,9 @@ void MacroDock::UpdateText()
|
|||
|
||||
_pauseToggle->setText(macro->Paused() ? _unpauseButtonText.c_str()
|
||||
: _pauseButtonText.c_str());
|
||||
_statusText->setText(macro->Matched() ? _conditionsTrueText.c_str()
|
||||
: _conditionsFalseText.c_str());
|
||||
_statusText->setText(macro->ConditionsMatched()
|
||||
? _conditionsTrueText.c_str()
|
||||
: _conditionsFalseText.c_str());
|
||||
}
|
||||
|
||||
void MacroDock::Highlight()
|
||||
|
|
|
|||
|
|
@ -85,9 +85,11 @@ std::string GetMacroName(Macro *macro)
|
|||
return macro ? macro->Name() : "";
|
||||
}
|
||||
|
||||
int64_t MillisecondsSinceMacroConditionCheck(Macro *macro)
|
||||
std::chrono::high_resolution_clock::time_point
|
||||
LastMacroConditionCheckTime(Macro *macro)
|
||||
{
|
||||
return macro ? macro->MsSinceLastCheck() : 0;
|
||||
return macro ? macro->LastConditionCheckTime()
|
||||
: std::chrono::high_resolution_clock::time_point{};
|
||||
}
|
||||
|
||||
bool MacroIsStopped(Macro *macro)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ EXPORT bool MacroSwitchedScene();
|
|||
|
||||
EXPORT std::string GetMacroName(Macro *);
|
||||
|
||||
EXPORT int64_t MillisecondsSinceMacroConditionCheck(Macro *);
|
||||
EXPORT std::chrono::high_resolution_clock::time_point
|
||||
LastMacroConditionCheckTime(Macro *);
|
||||
|
||||
EXPORT bool MacroIsStopped(Macro *);
|
||||
EXPORT bool MacroIsPaused(Macro *);
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ bool Macro::CheckConditionHelper(
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Macro::CeckMatch(bool ignorePause)
|
||||
bool Macro::CheckConditions(bool ignorePause)
|
||||
{
|
||||
if (_isGroup) {
|
||||
return false;
|
||||
|
|
@ -309,8 +309,7 @@ bool Macro::PerformActions(bool match, bool forceParallel, bool ignorePause)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool Macro::WasExecutedSince(
|
||||
const std::chrono::high_resolution_clock::time_point &time) const
|
||||
bool Macro::WasExecutedSince(const TimePoint &time) const
|
||||
{
|
||||
return _lastExecutionTime > time;
|
||||
}
|
||||
|
|
@ -337,18 +336,6 @@ bool Macro::ShouldRunActions() const
|
|||
return hasActionsToExecute;
|
||||
}
|
||||
|
||||
int64_t Macro::MsSinceLastCheck() const
|
||||
{
|
||||
if (_lastCheckTime.time_since_epoch().count() == 0) {
|
||||
return 0;
|
||||
}
|
||||
const auto timePassed =
|
||||
std::chrono::high_resolution_clock::now() - _lastCheckTime;
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(timePassed)
|
||||
.count() +
|
||||
1;
|
||||
}
|
||||
|
||||
void Macro::SetName(const std::string &name)
|
||||
{
|
||||
const bool nameChanged = _name == name;
|
||||
|
|
@ -414,8 +401,7 @@ bool Macro::RunElseActions(bool ignorePause)
|
|||
return RunActionsHelper(_elseActions, ignorePause);
|
||||
}
|
||||
|
||||
bool Macro::WasPausedSince(
|
||||
const std::chrono::high_resolution_clock::time_point &time) const
|
||||
bool Macro::WasPausedSince(const TimePoint &time) const
|
||||
{
|
||||
return _lastUnpauseTime > time;
|
||||
}
|
||||
|
|
@ -1303,7 +1289,7 @@ bool CheckMacros()
|
|||
{
|
||||
bool matchFound = false;
|
||||
for (const auto &m : macros) {
|
||||
if (m->CeckMatch() || m->ElseActions().size() > 0) {
|
||||
if (m->CheckConditions() || m->ElseActions().size() > 0) {
|
||||
matchFound = true;
|
||||
// This has to be performed here for now as actions are
|
||||
// not performed immediately after checking conditions.
|
||||
|
|
@ -1349,7 +1335,7 @@ bool RunMacros()
|
|||
continue;
|
||||
}
|
||||
vblog(LOG_INFO, "running macro: %s", m->Name().c_str());
|
||||
if (!m->PerformActions(m->Matched())) {
|
||||
if (!m->PerformActions(m->ConditionsMatched())) {
|
||||
blog(LOG_WARNING, "abort macro: %s", m->Name().c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ namespace advss {
|
|||
class MacroDock;
|
||||
|
||||
class Macro {
|
||||
using TimePoint = std::chrono::high_resolution_clock::time_point;
|
||||
|
||||
public:
|
||||
Macro(const std::string &name = "", const bool addHotkey = false,
|
||||
const bool shortCircuitEvaluation = false);
|
||||
|
|
@ -30,17 +32,17 @@ public:
|
|||
std::string Name() const { return _name; }
|
||||
void SetName(const std::string &name);
|
||||
|
||||
bool CeckMatch(bool ignorePause = false);
|
||||
bool Matched() const { return _matched; }
|
||||
int64_t MsSinceLastCheck() const;
|
||||
bool CheckConditions(bool ignorePause = false);
|
||||
bool ConditionsMatched() const { return _matched; }
|
||||
TimePoint LastConditionCheckTime() const { return _lastCheckTime; }
|
||||
|
||||
bool ShouldRunActions() const;
|
||||
bool PerformActions(bool match, bool forceParallel = false,
|
||||
bool ignorePause = false);
|
||||
|
||||
void SetPaused(bool pause = true);
|
||||
bool Paused() const { return _paused; }
|
||||
bool WasPausedSince(
|
||||
const std::chrono::high_resolution_clock::time_point &) const;
|
||||
bool WasPausedSince(const TimePoint &) const;
|
||||
|
||||
void Stop();
|
||||
bool GetStop() const { return _stop; }
|
||||
|
|
@ -117,8 +119,7 @@ public:
|
|||
void SetElseActionSplitterPosition(const QList<int>);
|
||||
const QList<int> &GetElseActionSplitterPosition() const;
|
||||
bool HasValidSplitterPositions() const;
|
||||
bool WasExecutedSince(
|
||||
const std::chrono::high_resolution_clock::time_point &) const;
|
||||
bool WasExecutedSince(const TimePoint &) const;
|
||||
bool OnChangePreventedActionsRecently();
|
||||
void ResetUIHelpers();
|
||||
|
||||
|
|
@ -171,9 +172,9 @@ private:
|
|||
bool _die = false;
|
||||
bool _stop = false;
|
||||
bool _done = true;
|
||||
std::chrono::high_resolution_clock::time_point _lastCheckTime{};
|
||||
std::chrono::high_resolution_clock::time_point _lastUnpauseTime{};
|
||||
std::chrono::high_resolution_clock::time_point _lastExecutionTime{};
|
||||
TimePoint _lastCheckTime{};
|
||||
TimePoint _lastUnpauseTime{};
|
||||
TimePoint _lastExecutionTime{};
|
||||
std::thread _backgroundThread;
|
||||
std::vector<std::thread> _helperThreads;
|
||||
|
||||
|
|
|
|||
|
|
@ -180,11 +180,16 @@ bool MacroConditionDate::CheckCondition()
|
|||
if (!m) {
|
||||
return false;
|
||||
}
|
||||
auto msSinceLastCheck = MillisecondsSinceMacroConditionCheck(m);
|
||||
const auto timePassed = std::chrono::high_resolution_clock::now() -
|
||||
LastMacroConditionCheckTime(m);
|
||||
const auto msSinceLastCheck =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
timePassed);
|
||||
|
||||
if (_dayOfWeekCheck) {
|
||||
return CheckDayOfWeek(msSinceLastCheck);
|
||||
return CheckDayOfWeek(msSinceLastCheck.count());
|
||||
}
|
||||
return CheckRegularDate(msSinceLastCheck);
|
||||
return CheckRegularDate(msSinceLastCheck.count());
|
||||
}
|
||||
|
||||
bool MacroConditionDate::Save(obs_data_t *obj) const
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user