Add macro option to stop and rerun actions

This commit is contained in:
Przemek Pawlas 2024-03-12 00:51:54 +01:00 committed by WarmUpTill
parent b17a6cc109
commit 6df818503e
5 changed files with 34 additions and 2 deletions

View File

@ -140,6 +140,7 @@ AdvSceneSwitcher.macroTab.highlightPerformedActions="Highlight recently performe
AdvSceneSwitcher.macroTab.newMacroRegisterHotkey="Register hotkeys to control the pause state of new macros"
AdvSceneSwitcher.macroTab.currentDisableHotkeys="Register hotkeys to control the pause state of selected macro"
AdvSceneSwitcher.macroTab.currentSkipExecutionOnStartup="Skip execution of actions of current macro on startup"
AdvSceneSwitcher.macroTab.currentStopActionsIfNotDone="Stop and rerun actions of the currently selected macro, if the actions are still running, when a new execution is triggered"
AdvSceneSwitcher.macroTab.currentRegisterDock="Register dock widget to control the pause state of selected macro or run it manually"
AdvSceneSwitcher.macroTab.currentDockAddRunButton="Add button to run the macro"
AdvSceneSwitcher.macroTab.currentDockAddPauseButton="Add button to pause or unpause the macro"

View File

@ -54,6 +54,8 @@ MacroPropertiesDialog::MacroPropertiesDialog(QWidget *parent,
"AdvSceneSwitcher.macroTab.currentDisableHotkeys"))),
_currentSkipOnStartup(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.currentSkipExecutionOnStartup"))),
_currentStopActionsIfNotDone(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.currentStopActionsIfNotDone"))),
_currentMacroRegisterDock(new QCheckBox(obs_module_text(
"AdvSceneSwitcher.macroTab.currentRegisterDock"))),
_currentMacroDockAddRunButton(new QCheckBox(obs_module_text(
@ -96,6 +98,7 @@ MacroPropertiesDialog::MacroPropertiesDialog(QWidget *parent,
obs_module_text("AdvSceneSwitcher.macroTab.generalSettings"));
auto generalLayout = new QVBoxLayout;
generalLayout->addWidget(_currentSkipOnStartup);
generalLayout->addWidget(_currentStopActionsIfNotDone);
generalOptions->setLayout(generalLayout);
int row = 0;
@ -184,14 +187,17 @@ MacroPropertiesDialog::MacroPropertiesDialog(QWidget *parent,
_conditions->setChecked(prop._highlightConditions);
_actions->setChecked(prop._highlightActions);
_newMacroRegisterHotkeys->setChecked(prop._newMacroRegisterHotkeys);
if (!macro || macro->IsGroup()) {
hotkeyOptions->hide();
generalOptions->hide();
_dockOptions->hide();
return;
}
_currentMacroRegisterHotkeys->setChecked(macro->PauseHotkeysEnabled());
_currentSkipOnStartup->setChecked(macro->SkipExecOnStart());
_currentStopActionsIfNotDone->setChecked(macro->StopActionsIfNotDone());
const bool dockEnabled = macro->DockEnabled();
_currentMacroRegisterDock->setChecked(dockEnabled);
_currentMacroDockAddRunButton->setChecked(macro->DockHasRunButton());
@ -260,6 +266,7 @@ void MacroPropertiesDialog::DockEnableChanged(int enabled)
SetGridLayoutRowVisible(
_dockLayout, _conditionsFalseTextRow,
enabled && _currentMacroDockAddStatusLabel->isChecked());
Resize();
}
@ -310,6 +317,8 @@ bool MacroPropertiesDialog::AskForSettings(QWidget *parent,
macro->EnablePauseHotkeys(
dialog._currentMacroRegisterHotkeys->isChecked());
macro->SetSkipExecOnStart(dialog._currentSkipOnStartup->isChecked());
macro->SetStopActionsIfNotDone(
dialog._currentStopActionsIfNotDone->isChecked());
macro->EnableDock(dialog._currentMacroRegisterDock->isChecked());
macro->SetDockHasRunButton(
dialog._currentMacroDockAddRunButton->isChecked());
@ -328,6 +337,7 @@ bool MacroPropertiesDialog::AskForSettings(QWidget *parent,
dialog._conditionsTrueStatusText->text().toStdString());
macro->SetConditionsFalseStatusText(
dialog._conditionsFalseStatusText->text().toStdString());
return true;
}

View File

@ -49,6 +49,7 @@ private:
// Current macro specific settings
QCheckBox *_currentMacroRegisterHotkeys;
QCheckBox *_currentSkipOnStartup;
QCheckBox *_currentStopActionsIfNotDone;
QCheckBox *_currentMacroRegisterDock;
QCheckBox *_currentMacroDockAddRunButton;
QCheckBox *_currentMacroDockAddPauseButton;

View File

@ -193,9 +193,17 @@ bool Macro::CeckMatch()
bool Macro::PerformActions(bool match, bool forceParallel, bool ignorePause)
{
if (!_done) {
vblog(LOG_INFO, "macro %s already running", _name.c_str());
return !forceParallel;
vblog(LOG_INFO, "Macro %s already running", _name.c_str());
if (!_stopActionsIfNotDone) {
return !forceParallel;
}
Stop();
vblog(LOG_INFO, "Stopped macro %s actions to rerun them",
_name.c_str());
}
std::function<bool(bool)> runFunc =
match ? std::bind(&Macro::RunActions, this,
std::placeholders::_1)
@ -213,6 +221,7 @@ bool Macro::PerformActions(bool match, bool forceParallel, bool ignorePause)
} else {
ret = runFunc(ignorePause);
}
_lastExecutionTime = std::chrono::high_resolution_clock::now();
auto group = _parent.lock();
if (group) {
@ -550,6 +559,7 @@ bool Macro::Save(obs_data_t *obj) const
obs_data_set_bool(obj, "parallel", _runInParallel);
obs_data_set_bool(obj, "onChange", _performActionsOnChange);
obs_data_set_bool(obj, "skipExecOnStart", _skipExecOnStart);
obs_data_set_bool(obj, "stopActionsIfNotDone", _stopActionsIfNotDone);
obs_data_set_bool(obj, "group", _isGroup);
if (_isGroup) {
@ -644,6 +654,7 @@ bool Macro::Load(obs_data_t *obj)
_runInParallel = obs_data_get_bool(obj, "parallel");
_performActionsOnChange = obs_data_get_bool(obj, "onChange");
_skipExecOnStart = obs_data_get_bool(obj, "skipExecOnStart");
_stopActionsIfNotDone = obs_data_get_bool(obj, "stopActionsIfNotDone");
_isGroup = obs_data_get_bool(obj, "group");
if (_isGroup) {
@ -651,6 +662,7 @@ bool Macro::Load(obs_data_t *obj)
obs_data_get_obj(obj, "groupData");
_isCollapsed = obs_data_get_bool(groupData, "collapsed");
_groupSize = obs_data_get_int(groupData, "size");
return true;
}
@ -735,6 +747,7 @@ bool Macro::Load(obs_data_t *obj)
}
}
UpdateElseActionIndices();
return true;
}

View File

@ -24,6 +24,7 @@ class Macro {
public:
Macro(const std::string &name = "", const bool addHotkey = false);
virtual ~Macro();
bool CeckMatch();
bool PerformActions(bool match, bool forceParallel = false,
bool ignorePause = false);
@ -42,6 +43,11 @@ public:
bool MatchOnChange() const { return _performActionsOnChange; }
void SetSkipExecOnStart(bool skip) { _skipExecOnStart = skip; }
bool SkipExecOnStart() const { return _skipExecOnStart; }
void SetStopActionsIfNotDone(bool stopActionsIfNotDone)
{
_stopActionsIfNotDone = stopActionsIfNotDone;
}
bool StopActionsIfNotDone() const { return _stopActionsIfNotDone; }
int RunCount() const { return _runCount; };
void ResetRunCount() { _runCount = 0; };
void ResetTimers();
@ -168,6 +174,7 @@ private:
bool _conditionSateChanged = false;
bool _performActionsOnChange = true;
bool _skipExecOnStart = false;
bool _stopActionsIfNotDone = false;
bool _paused = false;
int _runCount = 0;
bool _registerHotkeys = true;