diff --git a/src/macro-core/macro-action-scene-switch.cpp b/src/macro-core/macro-action-scene-switch.cpp index c116d6ce..c172e873 100644 --- a/src/macro-core/macro-action-scene-switch.cpp +++ b/src/macro-core/macro-action-scene-switch.cpp @@ -123,15 +123,15 @@ void MacroActionSwitchScene::LogAction() auto t = _scene.GetType(); auto sceneName = GetWeakSourceName(_scene.GetScene(false)); switch (t) { - case SceneSelectionType::SCENE: + case SceneSelection::Type::SCENE: vblog(LOG_INFO, "switch to scene '%s'", _scene.ToString().c_str()); break; - case SceneSelectionType::GROUP: + case SceneSelection::Type::GROUP: vblog(LOG_INFO, "switch to scene '%s' (scene group '%s')", sceneName.c_str(), _scene.ToString().c_str()); break; - case SceneSelectionType::PREVIOUS: + case SceneSelection::Type::PREVIOUS: vblog(LOG_INFO, "switch to previous scene '%s'", sceneName.c_str()); break; @@ -153,30 +153,6 @@ bool MacroActionSwitchScene::Save(obs_data_t *obj) bool MacroActionSwitchScene::Load(obs_data_t *obj) { - // Convert old data format - // TODO: Remove in future version - if (obs_data_has_user_value(obj, "targetType")) { - auto sceneName = obs_data_get_string(obj, "target"); - obs_data_set_string(obj, "scene", sceneName); - auto transitionName = obs_data_get_string(obj, "transition"); - bool usePreviousScene = - strcmp(sceneName, previous_scene_name) == 0; - bool useCurrentTransition = - strcmp(transitionName, current_transition_name) == 0; - obs_data_set_int( - obj, "sceneType", - (usePreviousScene) - ? static_cast(SceneSelectionType::PREVIOUS) - : obs_data_get_int(obj, "targetType")); - obs_data_set_int( - obj, "transitionType", - (useCurrentTransition) - ? static_cast( - TransitionSelectionType::CURRENT) - : static_cast( - TransitionSelectionType::TRANSITION)); - } - MacroAction::Load(obj); _scene.Load(obj); _transition.Load(obj); diff --git a/src/utils/scene-item-selection.cpp b/src/utils/scene-item-selection.cpp index da2e85ce..9f03f95a 100644 --- a/src/utils/scene-item-selection.cpp +++ b/src/utils/scene-item-selection.cpp @@ -48,8 +48,7 @@ int getCountOfSceneItemOccurance(SceneSelection &s, std::string &name, bool enumAllScenes = true) { ItemCountData data{name}; - if (enumAllScenes && (s.GetType() == SceneSelectionType::CURRENT || - s.GetType() == SceneSelectionType::PREVIOUS)) { + if (enumAllScenes && (s.GetType() != SceneSelection::Type::SCENE)) { auto enumScenes = [](void *param, obs_source_t *source) { if (!source) { return true; diff --git a/src/utils/scene-selection.cpp b/src/utils/scene-selection.cpp index ec016cde..4238d54a 100644 --- a/src/utils/scene-selection.cpp +++ b/src/utils/scene-selection.cpp @@ -1,52 +1,80 @@ #include "scene-selection.hpp" #include "advanced-scene-switcher.hpp" -void SceneSelection::Save(obs_data_t *obj, const char *name, - const char *typeName) -{ - obs_data_set_int(obj, typeName, static_cast(_type)); +constexpr std::string_view typeSaveName = "type"; +constexpr std::string_view nameSaveName = "name"; +constexpr std::string_view selectionSaveName = "sceneSelection"; +void SceneSelection::Save(obs_data_t *obj) +{ + auto data = obs_data_create(); + obs_data_set_int(data, typeSaveName.data(), static_cast(_type)); switch (_type) { - case SceneSelectionType::SCENE: - obs_data_set_string(obj, name, + case Type::SCENE: + obs_data_set_string(data, nameSaveName.data(), GetWeakSourceName(_scene).c_str()); break; - case SceneSelectionType::GROUP: - obs_data_set_string(obj, name, _group->name.c_str()); + case Type::GROUP: + obs_data_set_string(data, nameSaveName.data(), + _group->name.c_str()); break; default: break; } + obs_data_set_obj(obj, selectionSaveName.data(), data); + obs_data_release(data); } void SceneSelection::Load(obs_data_t *obj, const char *name, const char *typeName) { - _type = static_cast( - obs_data_get_int(obj, typeName)); - auto target = obs_data_get_string(obj, name); + // TODO: Remove in future version + if (!obs_data_has_user_value(obj, selectionSaveName.data())) { + _type = static_cast(obs_data_get_int(obj, typeName)); + auto targetName = obs_data_get_string(obj, name); + switch (_type) { + case Type::SCENE: + _scene = GetWeakSourceByName(targetName); + break; + case Type::GROUP: + _group = GetSceneGroupByName(targetName); + break; + case Type::PREVIOUS: + break; + case Type::CURRENT: + break; + default: + break; + } + return; + } + + auto data = obs_data_get_obj(obj, selectionSaveName.data()); + _type = static_cast(obs_data_get_int(data, typeSaveName.data())); + auto targetName = obs_data_get_string(data, nameSaveName.data()); switch (_type) { - case SceneSelectionType::SCENE: - _scene = GetWeakSourceByName(target); + case Type::SCENE: + _scene = GetWeakSourceByName(targetName); break; - case SceneSelectionType::GROUP: - _group = GetSceneGroupByName(target); + case Type::GROUP: + _group = GetSceneGroupByName(targetName); break; - case SceneSelectionType::PREVIOUS: + case Type::PREVIOUS: break; - case SceneSelectionType::CURRENT: + case Type::CURRENT: break; default: break; } + obs_data_release(data); } OBSWeakSource SceneSelection::GetScene(bool advance) { switch (_type) { - case SceneSelectionType::SCENE: + case Type::SCENE: return _scene; - case SceneSelectionType::GROUP: + case Type::GROUP: if (!_group) { return nullptr; } @@ -54,9 +82,9 @@ OBSWeakSource SceneSelection::GetScene(bool advance) return _group->getNextScene(); } return _group->getCurrentScene(); - case SceneSelectionType::PREVIOUS: + case Type::PREVIOUS: return switcher->previousScene; - case SceneSelectionType::CURRENT: + case Type::CURRENT: return switcher->currentScene; default: break; @@ -67,16 +95,16 @@ OBSWeakSource SceneSelection::GetScene(bool advance) std::string SceneSelection::ToString() { switch (_type) { - case SceneSelectionType::SCENE: + case Type::SCENE: return GetWeakSourceName(_scene); - case SceneSelectionType::GROUP: + case Type::GROUP: if (_group) { return _group->name; } break; - case SceneSelectionType::PREVIOUS: + case Type::PREVIOUS: return obs_module_text("AdvSceneSwitcher.selectPreviousScene"); - case SceneSelectionType::CURRENT: + case Type::CURRENT: return obs_module_text("AdvSceneSwitcher.selectCurrentScene"); default: break; @@ -116,18 +144,18 @@ void SceneSelectionWidget::SetScene(SceneSelection &s) int idx; switch (s.GetType()) { - case SceneSelectionType::SCENE: - case SceneSelectionType::GROUP: + case SceneSelection::Type::SCENE: + case SceneSelection::Type::GROUP: setCurrentText(QString::fromStdString(s.ToString())); break; - case SceneSelectionType::PREVIOUS: + case SceneSelection::Type::PREVIOUS: idx = findText(QString::fromStdString(obs_module_text( "AdvSceneSwitcher.selectPreviousScene"))); if (idx != -1) { setCurrentIndex(idx); } break; - case SceneSelectionType::CURRENT: + case SceneSelection::Type::CURRENT: idx = findText(QString::fromStdString(obs_module_text( "AdvSceneSwitcher.selectCurrentScene"))); if (idx != -1) { @@ -175,23 +203,23 @@ void SceneSelectionWidget::SelectionChanged(const QString &name) SceneSelection s; auto scene = GetWeakSourceByQString(name); if (scene) { - s._type = SceneSelectionType::SCENE; + s._type = SceneSelection::Type::SCENE; s._scene = scene; } auto group = GetSceneGroupByQString(name); if (group) { - s._type = SceneSelectionType::GROUP; + s._type = SceneSelection::Type::GROUP; s._scene = nullptr; s._group = group; } if (!scene && !group) { if (IsCurrentSceneSelected(name)) { - s._type = SceneSelectionType::CURRENT; + s._type = SceneSelection::Type::CURRENT; } if (IsPreviousSceneSelected(name)) { - s._type = SceneSelectionType::PREVIOUS; + s._type = SceneSelection::Type::PREVIOUS; } } diff --git a/src/utils/scene-selection.hpp b/src/utils/scene-selection.hpp index 3d711988..bf14fcb9 100644 --- a/src/utils/scene-selection.hpp +++ b/src/utils/scene-selection.hpp @@ -4,13 +4,6 @@ #include -enum class SceneSelectionType { - SCENE, - GROUP, - PREVIOUS, - CURRENT, -}; - class SceneSelection { public: void Save(obs_data_t *obj, const char *name = "scene", @@ -18,14 +11,21 @@ public: void Load(obs_data_t *obj, const char *name = "scene", const char *typeName = "sceneType"); - SceneSelectionType GetType() { return _type; } + enum class Type { + SCENE, + GROUP, + PREVIOUS, + CURRENT, + }; + + Type GetType() { return _type; } OBSWeakSource GetScene(bool advance = true); std::string ToString(); private: OBSWeakSource _scene; SceneGroup *_group = nullptr; - SceneSelectionType _type = SceneSelectionType::SCENE; + Type _type = Type::SCENE; friend class SceneSelectionWidget; }; diff --git a/src/utils/utility.cpp b/src/utils/utility.cpp index 2126dd5d..3d1948c2 100644 --- a/src/utils/utility.cpp +++ b/src/utils/utility.cpp @@ -826,8 +826,7 @@ void populateSceneItemSelection(QComboBox *list, SceneSelection &s) { std::set names; - if (s.GetType() == SceneSelectionType::CURRENT || - s.GetType() == SceneSelectionType::PREVIOUS) { + if (s.GetType() != SceneSelection::Type::SCENE) { auto enumScenes = [](void *param, obs_source_t *source) { if (!source) { return true;