From 1273446ce5a5dafa0cb654ba95971d58893e91bd Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Wed, 17 Mar 2021 18:21:42 +0100 Subject: [PATCH] Add option to configure default transition delay. (#140) --- data/locale/de-DE.ini | 2 ++ data/locale/en-US.ini | 2 ++ forms/advanced-scene-switcher.ui | 3 ++ src/headers/advanced-scene-switcher.hpp | 1 + src/headers/switch-transitions.hpp | 1 + src/switch-transitions.cpp | 48 +++++++++++++++++++++---- 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/data/locale/de-DE.ini b/data/locale/de-DE.ini index 6a51a494..7d508fa3 100644 --- a/data/locale/de-DE.ini +++ b/data/locale/de-DE.ini @@ -60,6 +60,8 @@ AdvSceneSwitcher.transitionTab.defaultTransition="Ändere den Szenenübergang we AdvSceneSwitcher.transitionTab.entry="Wechsle von {{scenes}} zu {{scenes2}} mit {{transitions}}" AdvSceneSwitcher.transitionTab.defaultTransitionEntry="Wenn {{scenes}} aktiv ist ändere den Szenenübergang zu {{transitions}}" AdvSceneSwitcher.transitionTab.defaultTransitionsHelp="Klicke auf das Plus Symbol, um einen neuen Eintrag hinzuzufügen." +AdvSceneSwitcher.transitionTab.defaultTransition.delay="Wechsle Szenenübergang {{defTransitionDelay}} nach Szenenwechsel." +AdvSceneSwitcher.transitionTab.defaultTransition.delay.help="Diese Verzögerung dient dazu Szenenwechsel zu unterbrechen.\nDies kann passieren, wenn der Szenenübergangtyp gewechselt wird während ein Szenenübergang grade noch im Gang ist." ; Pause Scenes Tab AdvSceneSwitcher.pauseTab.title="Pause" diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index a15cb2e4..05f410f2 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -60,6 +60,8 @@ AdvSceneSwitcher.transitionTab.defaultTransition="Change transition if scene is AdvSceneSwitcher.transitionTab.entry="Switch from {{scenes}} to {{scenes2}} using {{transitions}}" AdvSceneSwitcher.transitionTab.defaultTransitionEntry="When scene {{scenes}} is active change default scene transition to {{transitions}}" AdvSceneSwitcher.transitionTab.defaultTransitionsHelp="Click on the plus symbol to add an entry." +AdvSceneSwitcher.transitionTab.defaultTransition.delay="Switch transition {{defTransitionDelay}} after scene change." +AdvSceneSwitcher.transitionTab.defaultTransition.delay.help="The delay is used to avoid cancelled scene switches, which can happen if the transition type is changed while a transition is still ongoing." ; Pause Scenes Tab AdvSceneSwitcher.pauseTab.title="Pause" diff --git a/forms/advanced-scene-switcher.ui b/forms/advanced-scene-switcher.ui index fb17462a..0092e0e9 100644 --- a/forms/advanced-scene-switcher.ui +++ b/forms/advanced-scene-switcher.ui @@ -737,6 +737,9 @@ AdvSceneSwitcher.transitionTab.defaultTransition + + + diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp index 07b7d4fd..deaf0e8f 100644 --- a/src/headers/advanced-scene-switcher.hpp +++ b/src/headers/advanced-scene-switcher.hpp @@ -163,6 +163,7 @@ public slots: void on_defaultTransitionsUp_clicked(); void on_defaultTransitionsDown_clicked(); void on_transitionOverridecheckBox_stateChanged(int state); + void on_defTransitionDelay_valueChanged(int value); void on_browseButton_clicked(); void on_readFileCheckBox_stateChanged(int state); diff --git a/src/headers/switch-transitions.hpp b/src/headers/switch-transitions.hpp index 0fe957f5..a91874ec 100644 --- a/src/headers/switch-transitions.hpp +++ b/src/headers/switch-transitions.hpp @@ -18,6 +18,7 @@ struct SceneTransition : SceneSwitcherEntry { struct DefaultSceneTransition : SceneSwitcherEntry { static bool pause; + static unsigned int delay; const char *getType() { return "def_transition"; } bool checkMatch(OBSWeakSource currentScene); diff --git a/src/switch-transitions.cpp b/src/switch-transitions.cpp index 91e1f791..c0eb52a4 100644 --- a/src/switch-transitions.cpp +++ b/src/switch-transitions.cpp @@ -3,7 +3,9 @@ #include "headers/advanced-scene-switcher.hpp" #include "headers/utility.hpp" +constexpr auto default_def_transition_dealy = 50; bool DefaultSceneTransition::pause = false; +unsigned int DefaultSceneTransition::delay = default_def_transition_dealy; void AdvSceneSwitcher::on_transitionsAdd_clicked() { @@ -188,6 +190,16 @@ void AdvSceneSwitcher::on_transitionOverridecheckBox_stateChanged(int state) } } +void AdvSceneSwitcher::on_defTransitionDelay_valueChanged(int value) +{ + if (loading) { + return; + } + + std::lock_guard lock(switcher->m); + DefaultSceneTransition::delay = value; +} + obs_weak_source_t *getNextTransition(obs_weak_source_t *scene1, obs_weak_source_t *scene2) { @@ -322,6 +334,10 @@ void SwitcherData::saveSceneTransitions(obs_data_t *obj) obs_data_set_bool(obj, "tansitionOverrideOverride", switcher->tansitionOverrideOverride); + obs_data_set_default_int(obj, "defTransitionDelay", + default_def_transition_dealy); + obs_data_set_int(obj, "defTransitionDelay", + DefaultSceneTransition::delay); } void SwitcherData::loadSceneTransitions(obs_data_t *obj) @@ -374,6 +390,8 @@ void SwitcherData::loadSceneTransitions(obs_data_t *obj) switcher->tansitionOverrideOverride = obs_data_get_bool(obj, "tansitionOverrideOverride"); + DefaultSceneTransition::delay = + obs_data_get_int(obj, "defTransitionDelay"); } void AdvSceneSwitcher::setupTransitionsTab() @@ -412,6 +430,24 @@ void AdvSceneSwitcher::setupTransitionsTab() ui->transitionOverridecheckBox->setChecked( switcher->tansitionOverrideOverride); + + QSpinBox *defTransitionDelay = new QSpinBox(); + defTransitionDelay->setSuffix("ms"); + defTransitionDelay->setMinimum(50); + defTransitionDelay->setMaximum(10000); + defTransitionDelay->setValue(DefaultSceneTransition::delay); + defTransitionDelay->setToolTip(obs_module_text( + "AdvSceneSwitcher.transitionTab.defaultTransition.delay.help")); + + QWidget::connect(defTransitionDelay, SIGNAL(valueChanged(int)), this, + SLOT(on_defTransitionDelay_valueChanged(int))); + + std::unordered_map widgetPlaceholders = { + {"{{defTransitionDelay}}", defTransitionDelay}}; + placeWidgets( + obs_module_text( + "AdvSceneSwitcher.transitionTab.defaultTransition.delay"), + ui->defTransitionDelayLayout, widgetPlaceholders); } bool SceneTransition::initialized() @@ -527,7 +563,7 @@ bool DefaultSceneTransition::checkMatch(OBSWeakSource currentScene) return scene == currentScene; } -void setTransitionDelayed(OBSWeakSource transition) +void setTransitionDelayed(OBSWeakSource transition, unsigned int delay) { // A hardcoded delay of 50 ms before switching transition type is // necessary due to OBS_FRONTEND_EVENT_SCENE_CHANGED seemingly firing a @@ -535,14 +571,14 @@ void setTransitionDelayed(OBSWeakSource transition) // // The same is to be the case for OBS_FRONTEND_EVENT_TRANSITION_STOPPED. // - // 50 ms was chosen as it seems to avoid the problem mentioned above and - // becuase that is the minimum value which can be chosen for the scene - // switcher's check interval. + // 50 ms was chosen as a default value as it seems to avoid the problem + // mentioned above and becuase that is the minimum value which can be + // chosen for the scene switcher's check interval. // Thus it can be made sure that the delayed setting of the transition // does not interfere with any new scene changes triggered by the scene // switcher - std::this_thread::sleep_for(std::chrono::milliseconds(50)); + std::this_thread::sleep_for(std::chrono::milliseconds(delay)); obs_source_t *transitionSource = obs_weak_source_get_source(transition); obs_frontend_set_current_transition(transitionSource); @@ -552,6 +588,6 @@ void setTransitionDelayed(OBSWeakSource transition) void DefaultSceneTransition::setTransition() { std::thread t; - t = std::thread(setTransitionDelayed, transition); + t = std::thread(setTransitionDelayed, transition, delay); t.detach(); }