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`.
This commit is contained in:
tt2468 2021-12-14 17:37:06 -08:00
parent 889062e44b
commit 20426924cd

View File

@ -277,19 +277,27 @@ std::vector<std::string> Utils::Obs::ListHelper::GetHotkeyNameList()
std::vector<json> Utils::Obs::ListHelper::GetSceneList()
{
obs_frontend_source_list sceneList = {};
obs_frontend_get_scenes(&sceneList);
std::vector<json> ret;
auto sceneEnumProc = [](void *param, obs_source_t *scene) {
auto ret = reinterpret_cast<std::vector<json>*>(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;
}