diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui index 19ab4fd6..6f22df7f 100644 --- a/forms/advanced-scene-switcher.ui +++ b/forms/advanced-scene-switcher.ui @@ -289,13 +289,23 @@ - If no switch condition is met + If no switch condition is met for Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + s + + + 999999.989999999990687 + + + diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index 602a043e..284d4cfb 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -415,15 +415,7 @@ void SwitcherData::Thread() } } - if (!match && switchIfNotMatching == SWITCH && - nonMatchingScene) { - match = true; - scene = nonMatchingScene; - transition = nullptr; - } - if (!match && switchIfNotMatching == RANDOM_SWITCH) { - checkRandom(match, scene, transition, sleep); - } + checkNoMatchSwitch(match, scene, transition, sleep); // After this point we will call frontend functions // obs_frontend_set_current_scene() and diff --git a/src/general.cpp b/src/general.cpp index f58c46a4..696dc277 100644 --- a/src/general.cpp +++ b/src/general.cpp @@ -56,6 +56,14 @@ void AdvSceneSwitcher::on_noMatchRandomSwitch_clicked() ui->randomDisabledWarning->setVisible(false); } +void AdvSceneSwitcher::on_noMatchDelay_valueChanged(double i) +{ + if (loading) + return; + std::lock_guard lock(switcher->m); + switcher->noMatchDelay = i; +} + void AdvSceneSwitcher::on_startupBehavior_currentIndexChanged(int index) { if (loading) @@ -450,6 +458,7 @@ void SwitcherData::saveGeneralSettings(obs_data_t *obj) nonMatchingSceneName.c_str()); obs_data_set_int(obj, "switch_if_not_matching", switcher->switchIfNotMatching); + obs_data_set_double(obj, "noMatchDelay", switcher->noMatchDelay); obs_data_set_bool(obj, "active", !switcher->stop); obs_data_set_int(obj, "startup_behavior", switcher->startupBehavior); @@ -526,6 +535,7 @@ void SwitcherData::loadGeneralSettings(obs_data_t *obj) obs_data_get_string(obj, "non_matching_scene"); switcher->nonMatchingScene = GetWeakSourceByName(nonMatchingScene.c_str()); + switcher->noMatchDelay = obs_data_get_double(obj, "noMatchDelay"); switcher->stop = !obs_data_get_bool(obj, "active"); switcher->startupBehavior = @@ -636,6 +646,29 @@ void SwitcherData::loadGeneralSettings(obs_data_t *obj) (int)(obs_data_get_int(obj, "audioTabPos"))); } +void SwitcherData::checkNoMatchSwitch(bool &match, OBSWeakSource &scene, + OBSWeakSource &transition, int &sleep) +{ + if (match) { + noMatchCount = 0; + return; + } + + if ((noMatchCount * interval) / 1000.0 < noMatchDelay) { + noMatchCount++; + return; + } + + if (switchIfNotMatching == SWITCH && nonMatchingScene) { + match = true; + scene = nonMatchingScene; + transition = nullptr; + } + if (switchIfNotMatching == RANDOM_SWITCH) { + checkRandom(match, scene, transition, sleep); + } +} + void AdvSceneSwitcher::setupGeneralTab() { populateSceneSelection(ui->noMatchSwitchScene, false); @@ -654,6 +687,9 @@ void AdvSceneSwitcher::setupGeneralTab() } ui->noMatchSwitchScene->setCurrentText( GetWeakSourceName(switcher->nonMatchingScene).c_str()); + ui->noMatchDelay->setValue(switcher->noMatchDelay); + ui->noMatchDelay->setToolTip( + "Will only ever be as accurate as the configured check interval."); ui->checkInterval->setValue(switcher->interval); ui->autoStopSceneCheckBox->setChecked(switcher->autoStopEnable); diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp index 9924042f..7110d011 100644 --- a/src/headers/advanced-scene-switcher.hpp +++ b/src/headers/advanced-scene-switcher.hpp @@ -86,6 +86,7 @@ public slots: void on_noMatchDontSwitch_clicked(); void on_noMatchSwitch_clicked(); void on_noMatchRandomSwitch_clicked(); + void on_noMatchDelay_valueChanged(double i); void on_startupBehavior_currentIndexChanged(int index); void on_noMatchSwitchScene_currentTextChanged(const QString &text); void on_checkInterval_valueChanged(int value); diff --git a/src/headers/switcher-data-structs.hpp b/src/headers/switcher-data-structs.hpp index 51dacb0a..9fbb634a 100644 --- a/src/headers/switcher-data-structs.hpp +++ b/src/headers/switcher-data-structs.hpp @@ -63,6 +63,8 @@ struct SwitcherData { OBSWeakSource lastRandomScene; OBSWeakSource nonMatchingScene; NoMatch switchIfNotMatching = NO_SWITCH; + double noMatchDelay; + double noMatchCount = 0; StartupBehavior startupBehavior = PERSIST; std::deque windowSwitches; @@ -183,6 +185,8 @@ struct SwitcherData { OBSWeakSource &transition); void checkAudioSwitch(bool &match, OBSWeakSource &scene, OBSWeakSource &transition); + void checkNoMatchSwitch(bool &match, OBSWeakSource &scene, + OBSWeakSource &transition, int &sleep); void saveWindowTitleSwitches(obs_data_t *obj); void saveScreenRegionSwitches(obs_data_t *obj);