From 2155a942f3f9e7dc663df7d33c655aec3c04227e Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Tue, 9 Nov 2021 19:45:36 +0100 Subject: [PATCH] Do not check conditions of paused macros --- src/headers/macro.hpp | 3 ++- src/macro.cpp | 32 ++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/headers/macro.hpp b/src/headers/macro.hpp index 04ff5c1e..7b8d7634 100644 --- a/src/headers/macro.hpp +++ b/src/headers/macro.hpp @@ -77,7 +77,7 @@ public: bool Matched() { return _matched; } std::string Name() { return _name; } void SetName(const std::string &name); - void SetPaused(bool pause = true) { _paused = pause; } + void SetPaused(bool pause = true); bool Paused() { return _paused; } int GetCount() { return _count; }; void ResetCount() { _count = 0; }; @@ -102,6 +102,7 @@ private: void SetupHotkeys(); void ClearHotkeys(); void SetHotkeysDesc(); + void ResetTimers(); std::string _name = ""; std::deque> _conditions; diff --git a/src/macro.cpp b/src/macro.cpp index 83684a29..48a2d5ff 100644 --- a/src/macro.cpp +++ b/src/macro.cpp @@ -36,6 +36,11 @@ bool Macro::CeckMatch() { _matched = false; for (auto &c : _conditions) { + if (_paused) { + vblog(LOG_INFO, "Macro %s is paused", _name.c_str()); + return false; + } + auto startTime = std::chrono::high_resolution_clock::now(); bool cond = c->CheckCondition(); auto endTime = std::chrono::high_resolution_clock::now(); @@ -88,18 +93,6 @@ bool Macro::CeckMatch() } vblog(LOG_INFO, "Macro %s returned %d", _name.c_str(), _matched); - - // Condition checks shall still be run even if macro is paused. - // Otherwise conditions might behave in unexpected ways when resuming. - // - // For example, audio could immediately match after unpause, when it - // matched before it was paused due to timers not being updated. - if (_paused) { - vblog(LOG_INFO, "Macro %s is paused", _name.c_str()); - _matched = false; - return false; - } - return _matched; } @@ -125,6 +118,21 @@ void Macro::SetName(const std::string &name) SetHotkeysDesc(); } +void Macro::ResetTimers() +{ + for (auto &c : _conditions) { + c->ResetDuration(); + } +} + +void Macro::SetPaused(bool pause) +{ + if (_paused && !pause) { + ResetTimers(); + } + _paused = pause; +} + void Macro::UpdateActionIndices() { int idx = 0;