From 20426924cdca6ca0bc8e9ebc8d5cded5fa2acc98 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Tue, 14 Dec 2021 17:37:06 -0800 Subject: [PATCH] Utils: [BREAKING CHANGE] Remove groups from GetSceneList + re-add order - Removes the `isGroup` boolean field from the scene object, and does not include any groups in the returned array. - Reintroduces ordered results. Previous versions used a method which did not return the scene list in the same order as the UI. This change also means that this request is more susceptible to crashing OBS if called during a scene collection change. - Adds the `sceneIndex` number to the scene object. 0 being the bottom of the scene list, just like in other requests like `GetSceneItemList`. --- src/utils/Obs.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/utils/Obs.cpp b/src/utils/Obs.cpp index a0d87601..f32e106a 100644 --- a/src/utils/Obs.cpp +++ b/src/utils/Obs.cpp @@ -277,19 +277,27 @@ std::vector Utils::Obs::ListHelper::GetHotkeyNameList() std::vector Utils::Obs::ListHelper::GetSceneList() { + obs_frontend_source_list sceneList = {}; + obs_frontend_get_scenes(&sceneList); + std::vector ret; - auto sceneEnumProc = [](void *param, obs_source_t *scene) { - auto ret = reinterpret_cast*>(param); + for (size_t i = 0; i < sceneList.sources.num; i++) { + obs_source_t *scene = sceneList.sources.array[i]; + + if (obs_source_is_group(scene)) + continue; json sceneJson; sceneJson["sceneName"] = obs_source_get_name(scene); - sceneJson["isGroup"] = obs_source_is_group(scene); + sceneJson["sceneIndex"] = sceneList.sources.num - i - 1; - ret->push_back(sceneJson); - return true; - }; + ret.push_back(sceneJson); + } - obs_enum_scenes(sceneEnumProc, &ret); + obs_frontend_source_list_free(&sceneList); + + // Reverse the vector order to match other array returns + std::reverse(ret.begin(), ret.end()); return ret; }