diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui index be110967..6cf335b7 100644 --- a/forms/advanced-scene-switcher.ui +++ b/forms/advanced-scene-switcher.ui @@ -489,16 +489,7 @@ - - - true - - - - 100 - 0 - - + diff --git a/lib/advanced-scene-switcher.hpp b/lib/advanced-scene-switcher.hpp index 9fdc958b..a6ee94ab 100644 --- a/lib/advanced-scene-switcher.hpp +++ b/lib/advanced-scene-switcher.hpp @@ -45,7 +45,6 @@ protected: /* --- Begin of general tab section --- */ public: void SetupGeneralTab(); - void UpdateNonMatchingScene(const QString &name); void SetDeprecationWarnings(); public slots: @@ -58,7 +57,6 @@ public slots: void on_startupBehavior_currentIndexChanged(int index); void on_logLevel_currentIndexChanged(int index); void on_autoStartEvent_currentIndexChanged(int index); - void on_noMatchSwitchScene_currentTextChanged(const QString &text); void on_checkInterval_valueChanged(int value); void on_tabWidget_currentChanged(int index); void on_exportSettings_clicked(); diff --git a/lib/general.cpp b/lib/general.cpp index db077adf..fca668e0 100644 --- a/lib/general.cpp +++ b/lib/general.cpp @@ -26,15 +26,6 @@ void AdvSceneSwitcher::reject() close(); } -void AdvSceneSwitcher::UpdateNonMatchingScene(const QString &name) -{ - OBSSourceAutoRelease scene = - obs_get_source_by_name(name.toUtf8().constData()); - OBSWeakSourceAutoRelease ws = obs_source_get_weak_source(scene); - - switcher->nonMatchingScene = ws; -} - void AdvSceneSwitcher::on_noMatchDontSwitch_clicked() { if (loading) { @@ -56,7 +47,6 @@ void AdvSceneSwitcher::on_noMatchSwitch_clicked() std::lock_guard lock(switcher->m); switcher->switchIfNotMatching = NoMatchBehavior::SWITCH; ui->noMatchSwitchScene->setEnabled(true); - UpdateNonMatchingScene(ui->noMatchSwitchScene->currentText()); ui->randomDisabledWarning->setVisible(true); } @@ -132,17 +122,6 @@ void AdvSceneSwitcher::on_autoStartEvent_currentIndexChanged(int index) switcher->autoStartEvent = static_cast(index); } -void AdvSceneSwitcher::on_noMatchSwitchScene_currentTextChanged( - const QString &text) -{ - if (loading) { - return; - } - - std::lock_guard lock(switcher->m); - UpdateNonMatchingScene(text); -} - void AdvSceneSwitcher::on_checkInterval_valueChanged(int value) { if (loading) { @@ -522,9 +501,9 @@ void SwitcherData::SaveGeneralSettings(obs_data_t *obj) { obs_data_set_int(obj, "interval", interval); - std::string nonMatchingSceneName = GetWeakSourceName(nonMatchingScene); - obs_data_set_string(obj, "non_matching_scene", - nonMatchingSceneName.c_str()); + OBSDataAutoRelease noMatchScene = obs_data_create(); + nonMatchingScene.Save(noMatchScene); + obs_data_set_obj(obj, "noMatchScene", noMatchScene); obs_data_set_int(obj, "switch_if_not_matching", static_cast(switchIfNotMatching)); noMatchDelay.Save(obj, "noMatchDelay"); @@ -578,9 +557,14 @@ void SwitcherData::LoadGeneralSettings(obs_data_t *obj) static_cast(NoMatchBehavior::NO_SWITCH)); switchIfNotMatching = static_cast( obs_data_get_int(obj, "switch_if_not_matching")); - std::string nonMatchingSceneName = - obs_data_get_string(obj, "non_matching_scene"); - nonMatchingScene = GetWeakSourceByName(nonMatchingSceneName.c_str()); + + if (obs_data_has_user_value(obj, "noMatchScene")) { + OBSDataAutoRelease noMatchScene = + obs_data_get_obj(obj, "noMatchScene"); + nonMatchingScene.Load(noMatchScene); + } else { + nonMatchingScene.Load(obj, "non_matching_scene"); + } noMatchDelay.Load(obj, "noMatchDelay"); cooldown.Load(obj, "cooldown"); @@ -689,10 +673,10 @@ void SwitcherData::CheckNoMatchSwitch(bool &match, OBSWeakSource &scene, return; } - if (switchIfNotMatching == NoMatchBehavior::SWITCH && - nonMatchingScene) { + auto noMatchScene = nonMatchingScene.GetScene(false); + if (switchIfNotMatching == NoMatchBehavior::SWITCH && noMatchScene) { match = true; - scene = nonMatchingScene; + scene = noMatchScene; transition = nullptr; } if (switchIfNotMatching == NoMatchBehavior::RANDOM_SWITCH) { @@ -887,8 +871,6 @@ void AdvSceneSwitcher::SetCheckIntervalTooLowVisibility() const void AdvSceneSwitcher::SetupGeneralTab() { - PopulateSceneSelection(ui->noMatchSwitchScene, false); - if (switcher->switchIfNotMatching == NoMatchBehavior::SWITCH) { ui->noMatchSwitch->setChecked(true); ui->noMatchSwitchScene->setEnabled(true); @@ -900,8 +882,17 @@ void AdvSceneSwitcher::SetupGeneralTab() ui->noMatchRandomSwitch->setChecked(true); ui->noMatchSwitchScene->setEnabled(false); } - ui->noMatchSwitchScene->setCurrentText( - GetWeakSourceName(switcher->nonMatchingScene).c_str()); + ui->noMatchSwitchScene->SetScene(switcher->nonMatchingScene); + ui->noMatchSwitchScene->LockToMainCanvas(); + + connect(ui->noMatchSwitchScene, &SceneSelectionWidget::SceneChanged, + this, [this](const SceneSelection &scene) { + if (loading) { + return; + } + std::lock_guard lock(switcher->m); + switcher->nonMatchingScene = scene; + }); DurationSelection *noMatchDelay = new DurationSelection(); noMatchDelay->SetDuration(switcher->noMatchDelay); diff --git a/lib/switcher-data.cpp b/lib/switcher-data.cpp index 95cc0d8a..f3d4f166 100644 --- a/lib/switcher-data.cpp +++ b/lib/switcher-data.cpp @@ -44,11 +44,6 @@ void SwitcherData::Prune() } } - if (nonMatchingScene && !WeakSourceValid(nonMatchingScene)) { - switchIfNotMatching = NoMatchBehavior::NO_SWITCH; - nonMatchingScene = nullptr; - } - for (size_t i = 0; i < randomSwitches.size(); i++) { RandomSwitch &s = randomSwitches[i]; if (!s.valid()) { diff --git a/lib/switcher-data.hpp b/lib/switcher-data.hpp index 98efa7ea..9dbb0334 100644 --- a/lib/switcher-data.hpp +++ b/lib/switcher-data.hpp @@ -109,7 +109,7 @@ public: /* --- Start of General tab section --- */ int interval = default_interval; - OBSWeakSource nonMatchingScene; + SceneSelection nonMatchingScene; NoMatchBehavior switchIfNotMatching = NoMatchBehavior::NO_SWITCH; Duration noMatchDelay; enum class StartupBehavior { PERSIST = 0, START = 1, STOP = 2 }; diff --git a/lib/utils/plugin-state-helpers.cpp b/lib/utils/plugin-state-helpers.cpp index 1ccec22b..157e4729 100644 --- a/lib/utils/plugin-state-helpers.cpp +++ b/lib/utils/plugin-state-helpers.cpp @@ -238,7 +238,7 @@ NoMatchBehavior GetPluginNoMatchBehavior() void SetNoMatchScene(const OBSWeakSource &scene) { - GetSwitcher()->nonMatchingScene = scene; + GetSwitcher()->nonMatchingScene.SetScene(scene); } std::string ForegroundWindowTitle()