diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index df10c3f1..0f154604 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -70,6 +70,7 @@ AdvSceneSwitcher.macroTab.name="Name:" AdvSceneSwitcher.macroTab.run="Run macro" AdvSceneSwitcher.macroTab.runFail="Running \"%1\" failed!\nEither one of the actions failed or the macro is running already." AdvSceneSwitcher.macroTab.runInParallel="Run macro in parallel to other macros" +AdvSceneSwitcher.macroTab.onChange="Perform actions only on condition change" AdvSceneSwitcher.macroTab.defaultname="Macro %1" AdvSceneSwitcher.macroTab.exists="Macro name exists already" AdvSceneSwitcher.macroTab.copy="Create copy" @@ -104,7 +105,7 @@ AdvSceneSwitcher.condition.scene.type.current="Current scene is" AdvSceneSwitcher.condition.scene.type.previous="Previous scene is" AdvSceneSwitcher.condition.scene.type.changed="Scene changed" AdvSceneSwitcher.condition.scene.type.notChanged="Scene has not changed" -AdvSceneSwitcher.condition.scene.currentSceneTransitionBehaviour="During transition check for transition traget scene" +AdvSceneSwitcher.condition.scene.currentSceneTransitionBehaviour="During transition check for transition target scene" AdvSceneSwitcher.condition.scene.entry.line1="{{sceneType}} {{scenes}}" AdvSceneSwitcher.condition.scene.entry.line2="{{useTransitionTargetScene}}" AdvSceneSwitcher.condition.window="Window" diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui index 7a96810b..8e94da28 100644 --- a/forms/advanced-scene-switcher.ui +++ b/forms/advanced-scene-switcher.ui @@ -729,7 +729,7 @@ - + @@ -754,6 +754,13 @@ + + + + AdvSceneSwitcher.macroTab.onChange + + + @@ -783,7 +790,7 @@ 0 0 - 767 + 792 218 @@ -882,7 +889,7 @@ 0 0 - 767 + 792 218 diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp index 28e5c44a..f66b3544 100644 --- a/src/headers/advanced-scene-switcher.hpp +++ b/src/headers/advanced-scene-switcher.hpp @@ -120,6 +120,7 @@ public slots: void on_macroName_editingFinished(); void on_runMacro_clicked(); void on_runMacroInParallel_stateChanged(int value); + void on_runMacroOnChange_stateChanged(int value); void on_macros_currentRowChanged(int idx); void on_macros_itemChanged(QListWidgetItem *); void on_conditionAdd_clicked(); diff --git a/src/headers/macro.hpp b/src/headers/macro.hpp index d8d9c479..b86bcde9 100644 --- a/src/headers/macro.hpp +++ b/src/headers/macro.hpp @@ -82,6 +82,8 @@ public: bool RunInParallel() { return _runInParallel; } void SetPaused(bool pause = true); bool Paused() { return _paused; } + void SetMatchOnChange(bool onChange) { _matchOnChange = onChange; } + bool MatchOnChange() { return _matchOnChange; } int GetCount() { return _count; }; void ResetCount() { _count = 0; }; std::deque> &Conditions() @@ -114,6 +116,8 @@ private: std::deque> _actions; bool _runInParallel = false; bool _matched = false; + bool _lastMatched = false; + bool _matchOnChange = false; bool _paused = false; int _count = 0; obs_hotkey_id _pauseHotkey = OBS_INVALID_HOTKEY_ID; diff --git a/src/macro-tab.cpp b/src/macro-tab.cpp index c8eb01ba..943ddaf3 100644 --- a/src/macro-tab.cpp +++ b/src/macro-tab.cpp @@ -198,6 +198,16 @@ void AdvSceneSwitcher::on_runMacroInParallel_stateChanged(int value) macro->SetRunInParallel(value); } +void AdvSceneSwitcher::on_runMacroOnChange_stateChanged(int value) +{ + Macro *macro = getSelectedMacro(); + if (!macro) { + return; + } + std::lock_guard lock(switcher->m); + macro->SetMatchOnChange(value); +} + void AdvSceneSwitcher::PopulateMacroActions(Macro &m, uint32_t afterIdx) { auto &actions = m.Actions(); @@ -232,8 +242,10 @@ void AdvSceneSwitcher::SetEditMacro(Macro &m) { const QSignalBlocker b1(ui->macroName); const QSignalBlocker b2(ui->runMacroInParallel); + const QSignalBlocker b3(ui->runMacroOnChange); ui->macroName->setText(m.Name().c_str()); ui->runMacroInParallel->setChecked(m.RunInParallel()); + ui->runMacroOnChange->setChecked(m.MatchOnChange()); } clearLayout(ui->macroEditConditionLayout); clearLayout(ui->macroEditActionLayout); diff --git a/src/macro.cpp b/src/macro.cpp index 45626e60..0128562d 100644 --- a/src/macro.cpp +++ b/src/macro.cpp @@ -95,9 +95,16 @@ bool Macro::CeckMatch() vblog(LOG_INFO, "condition %s returned %d", c->GetId().c_str(), cond); } - vblog(LOG_INFO, "Macro %s returned %d", _name.c_str(), _matched); + bool newLastMatched = _matched; + if (_matched && _matchOnChange && _lastMatched == _matched) { + vblog(LOG_INFO, "ignore match for Macro %s (on change)", + _name.c_str()); + _matched = false; + } + _lastMatched = newLastMatched; + // TODO: Move back to PerformAction() once new scene collection frontend // events are available - see: // https://github.com/obsproject/obs-studio/commit/feda1aaa283e8a99f6ba1159cfe6b9c1f2934a61 @@ -194,6 +201,7 @@ bool Macro::Save(obs_data_t *obj) obs_data_set_string(obj, "name", _name.c_str()); obs_data_set_bool(obj, "pause", _paused); obs_data_set_bool(obj, "parallel", _runInParallel); + obs_data_set_bool(obj, "onChange", _matchOnChange); obs_data_array_t *pauseHotkey = obs_hotkey_save(_pauseHotkey); obs_data_set_array(obj, "pauseHotkey", pauseHotkey); @@ -272,6 +280,7 @@ bool Macro::Load(obs_data_t *obj) _name = obs_data_get_string(obj, "name"); _paused = obs_data_get_bool(obj, "pause"); _runInParallel = obs_data_get_bool(obj, "parallel"); + _matchOnChange = obs_data_get_bool(obj, "onChange"); obs_data_array_t *pauseHotkey = obs_data_get_array(obj, "pauseHotkey"); obs_hotkey_load(_pauseHotkey, pauseHotkey);