From d8c042fe4a638f192a4b891ca35bafafb5d49419 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Wed, 13 Apr 2022 02:13:30 -0700 Subject: [PATCH] requesthandler: Add private scene item settings get/set Some may need it, similarly to Get/SetSourcePrivateSettings. --- src/requesthandler/RequestHandler.cpp | 2 ++ src/requesthandler/RequestHandler.h | 2 ++ .../RequestHandler_SceneItems.cpp | 36 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index 9df48aa4..251fc75a 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -138,6 +138,8 @@ const std::unordered_map RequestHandler::_han {"SetSceneItemIndex", &RequestHandler::SetSceneItemIndex}, {"GetSceneItemBlendMode", &RequestHandler::GetSceneItemBlendMode}, {"SetSceneItemBlendMode", &RequestHandler::SetSceneItemBlendMode}, + {"GetSceneItemPrivateSettings", &RequestHandler::GetSceneItemPrivateSettings}, + {"SetSceneItemPrivateSettings", &RequestHandler::SetSceneItemPrivateSettings}, // Outputs {"GetVirtualCamStatus", &RequestHandler::GetVirtualCamStatus}, diff --git a/src/requesthandler/RequestHandler.h b/src/requesthandler/RequestHandler.h index e198a304..e0c77160 100644 --- a/src/requesthandler/RequestHandler.h +++ b/src/requesthandler/RequestHandler.h @@ -156,6 +156,8 @@ class RequestHandler { RequestResult SetSceneItemIndex(const Request&); RequestResult GetSceneItemBlendMode(const Request&); RequestResult SetSceneItemBlendMode(const Request&); + RequestResult GetSceneItemPrivateSettings(const Request&); + RequestResult SetSceneItemPrivateSettings(const Request&); // Outputs RequestResult GetVirtualCamStatus(const Request&); diff --git a/src/requesthandler/RequestHandler_SceneItems.cpp b/src/requesthandler/RequestHandler_SceneItems.cpp index e4a9be84..2b1d5fd9 100644 --- a/src/requesthandler/RequestHandler_SceneItems.cpp +++ b/src/requesthandler/RequestHandler_SceneItems.cpp @@ -718,3 +718,39 @@ RequestResult RequestHandler::SetSceneItemBlendMode(const Request& request) return RequestResult::Success(); } + +// Intentionally undocumented +RequestResult RequestHandler::GetSceneItemPrivateSettings(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem("sceneName", "sceneItemId", statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); + if (!sceneItem) + return RequestResult::Error(statusCode, comment); + + OBSDataAutoRelease privateSettings = obs_sceneitem_get_private_settings(sceneItem); + + json responseData; + responseData["sceneItemSettings"] = Utils::Json::ObsDataToJson(privateSettings); + + return RequestResult::Success(responseData); +} + +// Intentionally undocumented +RequestResult RequestHandler::SetSceneItemPrivateSettings(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem("sceneName", "sceneItemId", statusCode, comment, OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); + if (!sceneItem || !request.ValidateObject("sceneItemSettings", statusCode, comment)) + return RequestResult::Error(statusCode, comment); + + OBSDataAutoRelease privateSettings = obs_sceneitem_get_private_settings(sceneItem); + + OBSDataAutoRelease newSettings = Utils::Json::JsonToObsData(request.RequestData["sceneItemSettings"]); + + // Always overlays to prevent destroying internal source unintentionally + obs_data_apply(privateSettings, newSettings); + + return RequestResult::Success(); +}