From 3709ea1a9534e0e695e4517563cb2d67c422a70b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 19:11:03 +0200 Subject: [PATCH 01/11] docs(clarity): move scene items events into a proper "Scene Items" category Namely: - SourceOrderChanged - SceneItemAdded - SceneItemRemoved - SceneItemVisibilityChanged - SceneItemLockChanged - SceneItemTransformChanged - SceneItemSelected - SceneItemDeselected --- src/WSEvents.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/WSEvents.cpp b/src/WSEvents.cpp index e2c0684f..37ada8ee 100644 --- a/src/WSEvents.cpp +++ b/src/WSEvents.cpp @@ -1345,7 +1345,7 @@ void WSEvents::OnSourceFilterOrderChanged(void* param, calldata_t* data) { * * @api events * @name SourceOrderChanged - * @category sources + * @category scene items * @since 4.0.0 */ void WSEvents::OnSceneReordered(void* param, calldata_t* data) { @@ -1387,7 +1387,7 @@ void WSEvents::OnSceneReordered(void* param, calldata_t* data) { * * @api events * @name SceneItemAdded - * @category sources + * @category scene items * @since 4.0.0 */ void WSEvents::OnSceneItemAdd(void* param, calldata_t* data) { @@ -1420,7 +1420,7 @@ void WSEvents::OnSceneItemAdd(void* param, calldata_t* data) { * * @api events * @name SceneItemRemoved - * @category sources + * @category scene items * @since 4.0.0 */ void WSEvents::OnSceneItemDelete(void* param, calldata_t* data) { @@ -1454,7 +1454,7 @@ void WSEvents::OnSceneItemDelete(void* param, calldata_t* data) { * * @api events * @name SceneItemVisibilityChanged - * @category sources + * @category scene items * @since 4.0.0 */ void WSEvents::OnSceneItemVisibilityChanged(void* param, calldata_t* data) { @@ -1492,7 +1492,7 @@ void WSEvents::OnSceneItemVisibilityChanged(void* param, calldata_t* data) { * * @api events * @name SceneItemLockChanged - * @category sources + * @category scene items * @since 4.8.0 */ void WSEvents::OnSceneItemLockChanged(void* param, calldata_t* data) { @@ -1530,7 +1530,7 @@ void WSEvents::OnSceneItemLockChanged(void* param, calldata_t* data) { * * @api events * @name SceneItemTransformChanged - * @category sources + * @category scene items * @since 4.6.0 */ void WSEvents::OnSceneItemTransform(void* param, calldata_t* data) { @@ -1566,7 +1566,7 @@ void WSEvents::OnSceneItemTransform(void* param, calldata_t* data) { * * @api events * @name SceneItemSelected - * @category sources + * @category scene items * @since 4.6.0 */ void WSEvents::OnSceneItemSelected(void* param, calldata_t* data) { @@ -1601,7 +1601,7 @@ void WSEvents::OnSceneItemSelected(void* param, calldata_t* data) { * * @api events * @name SceneItemDeselected - * @category sources + * @category scene items * @since 4.6.0 */ void WSEvents::OnSceneItemDeselected(void* param, calldata_t* data) { From c486bc64c460ecdf211527d9847b457850f0816c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 19:35:57 +0200 Subject: [PATCH 02/11] requests(scene items): refactor docs --- src/WSRequestHandler_SceneItems.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index 5e736802..87fac51d 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -6,10 +6,10 @@ * Gets the scene specific properties of the specified source item. * Coordinates are relative to the item's parent (the scene or group it belongs to). * -* @param {String (optional)} `scene-name` the name of the scene that the source item belongs to. Defaults to the current scene. -* @param {String} `item` The name of the source. +* @param {String (optional)} `scene-name` Name of the scene the scene item belongs to. Defaults to the current scene. +* @param {String} `item` Scene Item name. * -* @return {String} `name` The name of the source. +* @return {String} `name` Scene Item name. * @return {int} `position.x` The x position of the source from the left. * @return {int} `position.y` The y position of the source from the top. * @return {int} `position.alignment` The point on the source that the item is manipulated from. @@ -71,8 +71,8 @@ RpcResponse WSRequestHandler::GetSceneItemProperties(const RpcRequest& request) * Sets the scene specific properties of a source. Unspecified properties will remain unchanged. * Coordinates are relative to the item's parent (the scene or group it belongs to). * -* @param {String (optional)} `scene-name` the name of the scene that the source item belongs to. Defaults to the current scene. -* @param {String} `item` The name of the source. +* @param {String (optional)} `scene-name` Name of the scene the source item belongs to. Defaults to the current scene. +* @param {String} `item` Scene Item name. * @param {int (optional)} `position.x` The new x position of the source. * @param {int (optional)} `position.y` The new y position of the source. * @param {int (optional)} `position.alignment` The new alignment of the source. @@ -263,8 +263,8 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) /** * Reset a scene item. * -* @param {String (optional)} `scene-name` Name of the scene the source belongs to. Defaults to the current scene. -* @param {String} `item` Name of the source item. +* @param {String (optional)} `scene-name` Name of the scene the scene item belongs to. Defaults to the current scene. +* @param {String} `item` Scene item name. * * @api requests * @name ResetSceneItem @@ -496,10 +496,10 @@ RpcResponse WSRequestHandler::SetSceneItemCrop(const RpcRequest& request) { /** * Deletes a scene item. * - * @param {String (optional)} `scene` Name of the scene the source belongs to. Defaults to the current scene. - * @param {Object} `item` item to delete (required) - * @param {String} `item.name` name of the scene item (prefer `id`, including both is acceptable). - * @param {int} `item.id` id of the scene item. + * @param {String (optional)} `scene` Name of the scene the scene item belongs to. Defaults to the current scene. + * @param {Object} `item` Scene item to delete (required) + * @param {String} `item.name` Scene Item name (prefer `id`, including both is acceptable). + * @param {int} `item.id` Scene Item ID. * * @api requests * @name DeleteSceneItem @@ -533,9 +533,9 @@ RpcResponse WSRequestHandler::DeleteSceneItem(const RpcRequest& request) { * * @param {String (optional)} `fromScene` Name of the scene to copy the item from. Defaults to the current scene. * @param {String (optional)} `toScene` Name of the scene to create the item in. Defaults to the current scene. - * @param {Object} `item` item to duplicate (required) - * @param {String} `item.name` name of the scene item (prefer `id`, including both is acceptable). - * @param {int} `item.id` id of the scene item. + * @param {Object} `item` Scene Item to duplicate from the source scene (required) + * @param {String} `item.name` Scene Item name (prefer `id`, including both is acceptable). + * @param {int} `item.id` Scene Item ID. * * @return {String} `scene` Name of the scene where the new item was created * @return {Object} `item` New item info From a6c6a42669c7730bd2e6d19cec82fe5ca7d90f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 19:37:51 +0200 Subject: [PATCH 03/11] requests(scene items): doc fixes again --- src/WSRequestHandler_SceneItems.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index 87fac51d..55058fed 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -305,9 +305,9 @@ RpcResponse WSRequestHandler::ResetSceneItem(const RpcRequest& request) { /** * Show or hide a specified source item in a specified scene. * -* @param {String} `source` Scene item name in the specified scene. +* @param {String (optional)} `scene-name` Name of the scene the scene item belongs to. Defaults to the currently active scene. +* @param {String} `source` Scene Item name. * @param {boolean} `render` true = shown ; false = hidden -* @param {String (optional)} `scene-name` Name of the scene where the source resides. Defaults to the currently active scene. * * @api requests * @name SetSceneItemRender @@ -348,8 +348,8 @@ RpcResponse WSRequestHandler::SetSceneItemRender(const RpcRequest& request) { /** * Sets the coordinates of a specified source item. * -* @param {String (optional)} `scene-name` The name of the scene that the source item belongs to. Defaults to the current scene. -* @param {String} `item` The name of the source item. +* @param {String (optional)} `scene-name` Name of the scene the scene item belongs to. Defaults to the current scene. +* @param {String} `item` Scene Item name. * @param {double} `x` X coordinate. * @param {double} `y` Y coordinate. @@ -393,8 +393,8 @@ RpcResponse WSRequestHandler::SetSceneItemPosition(const RpcRequest& request) { /** * Set the transform of the specified source item. * -* @param {String (optional)} `scene-name` The name of the scene that the source item belongs to. Defaults to the current scene. -* @param {String} `item` The name of the source item. +* @param {String (optional)} `scene-name` Name of the scene the scene item belongs to. Defaults to the current scene. +* @param {String} `item` Scene Item name. * @param {double} `x-scale` Width scale factor. * @param {double} `y-scale` Height scale factor. * @param {double} `rotation` Source item rotation (in degrees). @@ -448,8 +448,8 @@ RpcResponse WSRequestHandler::SetSceneItemTransform(const RpcRequest& request) { /** * Sets the crop coordinates of the specified source item. * -* @param {String (optional)} `scene-name` the name of the scene that the source item belongs to. Defaults to the current scene. -* @param {String} `item` The name of the source. +* @param {String (optional)} `scene-name` Name of the scene the scene item belongs to. Defaults to the current scene. +* @param {String} `item` Scene Item name. * @param {int} `top` Pixel position of the top of the source item. * @param {int} `bottom` Pixel position of the bottom of the source item. * @param {int} `left` Pixel position of the left of the source item. From 4e2302936f2a8cb4f92cd9a240fcfd648624d57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 21:41:38 +0200 Subject: [PATCH 04/11] refactor bits --- src/Utils.cpp | 56 +++++++++++++++++++++++++-------------------------- src/Utils.h | 4 ++-- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index 978162be..a104e05c 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -180,34 +180,6 @@ obs_data_t* Utils::GetSceneItemData(obs_sceneitem_t* item) { return data; } -obs_sceneitem_t* Utils::GetSceneItemFromItem(obs_scene_t* scene, obs_data_t* itemInfo) { - if (!scene) { - return nullptr; - } - - OBSDataItemAutoRelease idInfoItem = obs_data_item_byname(itemInfo, "id"); - int id = obs_data_item_get_int(idInfoItem); - - OBSDataItemAutoRelease nameInfoItem = obs_data_item_byname(itemInfo, "name"); - const char* name = obs_data_item_get_string(nameInfoItem); - - if (idInfoItem) { - obs_sceneitem_t* sceneItem = GetSceneItemFromId(scene, id); - obs_source_t* sceneItemSource = obs_sceneitem_get_source(sceneItem); - - QString sceneItemName = obs_source_get_name(sceneItemSource); - if (nameInfoItem && (QString(name) != sceneItemName)) { - return nullptr; - } - - return sceneItem; - } else if (nameInfoItem) { - return GetSceneItemFromName(scene, name); - } - - return nullptr; -} - obs_sceneitem_t* Utils::GetSceneItemFromName(obs_scene_t* scene, QString name) { if (!scene) { return nullptr; @@ -297,6 +269,34 @@ obs_sceneitem_t* Utils::GetSceneItemFromId(obs_scene_t* scene, int64_t id) { return search.result; } +obs_sceneitem_t* Utils::GetSceneItemFromItem(obs_scene_t* scene, obs_data_t* itemInfo) { + if (!scene) { + return nullptr; + } + + OBSDataItemAutoRelease idInfoItem = obs_data_item_byname(itemInfo, "id"); + int id = obs_data_item_get_int(idInfoItem); + + OBSDataItemAutoRelease nameInfoItem = obs_data_item_byname(itemInfo, "name"); + const char* name = obs_data_item_get_string(nameInfoItem); + + if (idInfoItem) { + obs_sceneitem_t* sceneItem = GetSceneItemFromId(scene, id); + obs_source_t* sceneItemSource = obs_sceneitem_get_source(sceneItem); + + QString sceneItemName = obs_source_get_name(sceneItemSource); + if (nameInfoItem && (QString(name) != sceneItemName)) { + return nullptr; + } + + return sceneItem; + } else if (nameInfoItem) { + return GetSceneItemFromName(scene, name); + } + + return nullptr; +} + bool Utils::IsValidAlignment(const uint32_t alignment) { switch (alignment) { case OBS_ALIGN_CENTER: diff --git a/src/Utils.h b/src/Utils.h index 5934ad4e..7ae51297 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -39,11 +39,11 @@ namespace Utils { obs_data_array_t* GetSceneItems(obs_source_t* source); obs_data_t* GetSceneItemData(obs_sceneitem_t* item); - // These two functions support nested lookup into groups + // These functions support nested lookup into groups obs_sceneitem_t* GetSceneItemFromName(obs_scene_t* scene, QString name); obs_sceneitem_t* GetSceneItemFromId(obs_scene_t* scene, int64_t id); - obs_sceneitem_t* GetSceneItemFromItem(obs_scene_t* scene, obs_data_t* item); + obs_scene_t* GetSceneFromNameOrCurrent(QString sceneName); obs_data_t* GetSceneItemPropertiesData(obs_sceneitem_t* item); From 51ec3ede1f8aae6861aa527fbf9b50deaca153c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 21:42:10 +0200 Subject: [PATCH 05/11] utils: add GetSceneItemFromRequestField --- src/Utils.cpp | 15 +++++++++++++++ src/Utils.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/Utils.cpp b/src/Utils.cpp index a104e05c..e80e7e50 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -297,6 +297,21 @@ obs_sceneitem_t* Utils::GetSceneItemFromItem(obs_scene_t* scene, obs_data_t* ite return nullptr; } +obs_sceneitem_t* Utils::GetSceneItemFromRequestField(obs_scene_t* scene, obs_data_item_t* dataItem) +{ + obs_data_type dataType = obs_data_item_gettype(dataItem); + + if (dataType == OBS_DATA_OBJECT) { + OBSDataAutoRelease itemData = obs_data_item_get_obj(dataItem); + return GetSceneItemFromItem(scene, itemData); + } else if (dataType == OBS_DATA_STRING) { + const char* name = obs_data_item_get_string(dataItem); + return GetSceneItemFromName(scene, name); + } + + return nullptr; +} + bool Utils::IsValidAlignment(const uint32_t alignment) { switch (alignment) { case OBS_ALIGN_CENTER: diff --git a/src/Utils.h b/src/Utils.h index 7ae51297..dbe2481f 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -43,6 +43,7 @@ namespace Utils { obs_sceneitem_t* GetSceneItemFromName(obs_scene_t* scene, QString name); obs_sceneitem_t* GetSceneItemFromId(obs_scene_t* scene, int64_t id); obs_sceneitem_t* GetSceneItemFromItem(obs_scene_t* scene, obs_data_t* item); + obs_sceneitem_t* GetSceneItemFromRequestField(obs_scene_t* scene, obs_data_item_t* dataItem); obs_scene_t* GetSceneFromNameOrCurrent(QString sceneName); obs_data_t* GetSceneItemPropertiesData(obs_sceneitem_t* item); From 0fcf770043cee6286db5f3d28b04472ee77c80f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 22:07:55 +0200 Subject: [PATCH 06/11] requests(scene items): implement object mode on "item" request field --- src/WSRequestHandler_SceneItems.cpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index 55058fed..651604dd 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -45,18 +45,14 @@ RpcResponse WSRequestHandler::GetSceneItemProperties(const RpcRequest& request) return request.failed("missing request parameters"); } - QString itemName = obs_data_get_string(request.parameters(), "item"); - if (itemName.isEmpty()) { - return request.failed("invalid request parameters"); - } - QString sceneName = obs_data_get_string(request.parameters(), "scene-name"); OBSScene scene = Utils::GetSceneFromNameOrCurrent(sceneName); if (!scene) { return request.failed("requested scene doesn't exist"); } - OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromName(scene, itemName); + OBSDataItemAutoRelease itemField = obs_data_item_byname("item"); + OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromName(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); } @@ -100,19 +96,14 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) return request.failed("missing request parameters"); } - QString itemName = obs_data_get_string(request.parameters(), "item"); - if (itemName.isEmpty()) { - return request.failed("invalid request parameters"); - } - QString sceneName = obs_data_get_string(request.parameters(), "scene-name"); OBSScene scene = Utils::GetSceneFromNameOrCurrent(sceneName); if (!scene) { return request.failed("requested scene doesn't exist"); } - OBSSceneItemAutoRelease sceneItem = - Utils::GetSceneItemFromName(scene, itemName); + OBSDataItemAutoRelease itemField = obs_data_item_byname("item"); + OBSSceneItemAutoRelease sceneItem =Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); } @@ -272,24 +263,18 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) * @since 4.2.0 */ RpcResponse WSRequestHandler::ResetSceneItem(const RpcRequest& request) { - // TODO: remove this request, or refactor it to ResetSource - if (!request.hasField("item")) { return request.failed("missing request parameters"); } - const char* itemName = obs_data_get_string(request.parameters(), "item"); - if (!itemName) { - return request.failed("invalid request parameters"); - } - const char* sceneName = obs_data_get_string(request.parameters(), "scene-name"); OBSScene scene = Utils::GetSceneFromNameOrCurrent(sceneName); if (!scene) { return request.failed("requested scene doesn't exist"); } - OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromName(scene, itemName); + OBSDataItemAutoRelease itemField = obs_data_item_byname("item"); + OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); } From be14947668eecee4c030b0844f3180de50b945fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 22:12:54 +0200 Subject: [PATCH 07/11] oops --- src/WSRequestHandler_SceneItems.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index 651604dd..4e3b8e62 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -51,14 +51,16 @@ RpcResponse WSRequestHandler::GetSceneItemProperties(const RpcRequest& request) return request.failed("requested scene doesn't exist"); } - OBSDataItemAutoRelease itemField = obs_data_item_byname("item"); - OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromName(scene, itemField); + OBSDataItemAutoRelease itemField = obs_data_item_byname(request.parameters(), "item"); + OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); } OBSDataAutoRelease data = Utils::GetSceneItemPropertiesData(sceneItem); - obs_data_set_string(data, "name", itemName.toUtf8()); + + OBSSourceAutoRelease sceneItemSource = obs_sceneitem_get_source(sceneItem); + obs_data_set_string(data, "name", obs_source_get_name(sceneItemSource)); return request.success(data); } @@ -102,7 +104,7 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) return request.failed("requested scene doesn't exist"); } - OBSDataItemAutoRelease itemField = obs_data_item_byname("item"); + OBSDataItemAutoRelease itemField = obs_data_item_byname(request.parameters(), "item"); OBSSceneItemAutoRelease sceneItem =Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); @@ -273,7 +275,7 @@ RpcResponse WSRequestHandler::ResetSceneItem(const RpcRequest& request) { return request.failed("requested scene doesn't exist"); } - OBSDataItemAutoRelease itemField = obs_data_item_byname("item"); + OBSDataItemAutoRelease itemField = obs_data_item_byname(request.parameters(), "item"); OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); From fbebf1c7d3df41c1bc6b32d509deb79a0fcdfc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 23:04:20 +0200 Subject: [PATCH 08/11] requests(scene item): fix docs --- src/WSRequestHandler_SceneItems.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index 4e3b8e62..d616e723 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -7,7 +7,9 @@ * Coordinates are relative to the item's parent (the scene or group it belongs to). * * @param {String (optional)} `scene-name` Name of the scene the scene item belongs to. Defaults to the current scene. -* @param {String} `item` Scene Item name. +* @param {String | Object} `item` Scene Item name (if this field is a string) or specification (if it is an object). +* @param {String (optional)} `item.name` Scene Item name (if the `item` field is an object) +* @param {int (optional)} `item.id` Scene Item ID (if the `item` field is an object) * * @return {String} `name` Scene Item name. * @return {int} `position.x` The x position of the source from the left. @@ -70,7 +72,9 @@ RpcResponse WSRequestHandler::GetSceneItemProperties(const RpcRequest& request) * Coordinates are relative to the item's parent (the scene or group it belongs to). * * @param {String (optional)} `scene-name` Name of the scene the source item belongs to. Defaults to the current scene. -* @param {String} `item` Scene Item name. +* @param {String | Object} `item` Scene Item name (if this field is a string) or specification (if it is an object). +* @param {String (optional)} `item.name` Scene Item name (if the `item` field is an object) +* @param {int (optional)} `item.id` Scene Item ID (if the `item` field is an object) * @param {int (optional)} `position.x` The new x position of the source. * @param {int (optional)} `position.y` The new y position of the source. * @param {int (optional)} `position.alignment` The new alignment of the source. @@ -257,7 +261,9 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) * Reset a scene item. * * @param {String (optional)} `scene-name` Name of the scene the scene item belongs to. Defaults to the current scene. -* @param {String} `item` Scene item name. +* @param {String | Object} `item` Scene Item name (if this field is a string) or specification (if it is an object). +* @param {String (optional)} `item.name` Scene Item name (if the `item` field is an object) +* @param {int (optional)} `item.id` Scene Item ID (if the `item` field is an object) * * @api requests * @name ResetSceneItem From 83f702fbabd132bb1de6d896d390ba6ac2c7705b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 23:28:07 +0200 Subject: [PATCH 09/11] requests(GetSceneItemProperties): add itemId response field --- src/WSRequestHandler_SceneItems.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index d616e723..ed089880 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -12,6 +12,7 @@ * @param {int (optional)} `item.id` Scene Item ID (if the `item` field is an object) * * @return {String} `name` Scene Item name. +* @return {int} `itemId` Scene Item ID. * @return {int} `position.x` The x position of the source from the left. * @return {int} `position.y` The y position of the source from the top. * @return {int} `position.alignment` The point on the source that the item is manipulated from. @@ -63,6 +64,7 @@ RpcResponse WSRequestHandler::GetSceneItemProperties(const RpcRequest& request) OBSSourceAutoRelease sceneItemSource = obs_sceneitem_get_source(sceneItem); obs_data_set_string(data, "name", obs_source_get_name(sceneItemSource)); + obs_data_set_int(data, "itemId", obs_sceneitem_get_id(sceneItem)); return request.success(data); } From 8b731f3ba496a3dec706da0aec2c0b4abbcdfc63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Sun, 29 Mar 2020 23:55:45 +0200 Subject: [PATCH 10/11] fixes --- src/Utils.cpp | 4 +-- src/WSRequestHandler_SceneItems.cpp | 53 ++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index e80e7e50..dd5ad14a 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -299,13 +299,13 @@ obs_sceneitem_t* Utils::GetSceneItemFromItem(obs_scene_t* scene, obs_data_t* ite obs_sceneitem_t* Utils::GetSceneItemFromRequestField(obs_scene_t* scene, obs_data_item_t* dataItem) { - obs_data_type dataType = obs_data_item_gettype(dataItem); + enum obs_data_type dataType = obs_data_item_gettype(dataItem); if (dataType == OBS_DATA_OBJECT) { OBSDataAutoRelease itemData = obs_data_item_get_obj(dataItem); return GetSceneItemFromItem(scene, itemData); } else if (dataType == OBS_DATA_STRING) { - const char* name = obs_data_item_get_string(dataItem); + QString name = obs_data_item_get_string(dataItem); return GetSceneItemFromName(scene, name); } diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index ed089880..829d36eb 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -48,13 +48,15 @@ RpcResponse WSRequestHandler::GetSceneItemProperties(const RpcRequest& request) return request.failed("missing request parameters"); } - QString sceneName = obs_data_get_string(request.parameters(), "scene-name"); + OBSData params = request.parameters(); + + QString sceneName = obs_data_get_string(params, "scene-name"); OBSScene scene = Utils::GetSceneFromNameOrCurrent(sceneName); if (!scene) { return request.failed("requested scene doesn't exist"); } - OBSDataItemAutoRelease itemField = obs_data_item_byname(request.parameters(), "item"); + OBSDataItemAutoRelease itemField = obs_data_item_byname(params, "item"); OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); @@ -62,7 +64,7 @@ RpcResponse WSRequestHandler::GetSceneItemProperties(const RpcRequest& request) OBSDataAutoRelease data = Utils::GetSceneItemPropertiesData(sceneItem); - OBSSourceAutoRelease sceneItemSource = obs_sceneitem_get_source(sceneItem); + OBSSource sceneItemSource = obs_sceneitem_get_source(sceneItem); obs_data_set_string(data, "name", obs_source_get_name(sceneItemSource)); obs_data_set_int(data, "itemId", obs_sceneitem_get_id(sceneItem)); @@ -104,13 +106,15 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) return request.failed("missing request parameters"); } - QString sceneName = obs_data_get_string(request.parameters(), "scene-name"); + OBSData params = request.parameters(); + + QString sceneName = obs_data_get_string(params, "scene-name"); OBSScene scene = Utils::GetSceneFromNameOrCurrent(sceneName); if (!scene) { return request.failed("requested scene doesn't exist"); } - OBSDataItemAutoRelease itemField = obs_data_item_byname(request.parameters(), "item"); + OBSDataItemAutoRelease itemField = obs_data_item_byname(params, "item"); OBSSceneItemAutoRelease sceneItem =Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); @@ -125,51 +129,59 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) vec2 oldPosition; OBSDataAutoRelease positionError = obs_data_create(); obs_sceneitem_get_pos(sceneItem, &oldPosition); - OBSDataAutoRelease reqPosition = obs_data_get_obj(request.parameters(), "position"); + + OBSDataAutoRelease reqPosition = obs_data_get_obj(params, "position"); vec2 newPosition = oldPosition; + if (obs_data_has_user_value(reqPosition, "x")) { newPosition.x = obs_data_get_int(reqPosition, "x"); } if (obs_data_has_user_value(reqPosition, "y")) { newPosition.y = obs_data_get_int(reqPosition, "y"); } + if (obs_data_has_user_value(reqPosition, "alignment")) { const uint32_t alignment = obs_data_get_int(reqPosition, "alignment"); if (Utils::IsValidAlignment(alignment)) { obs_sceneitem_set_alignment(sceneItem, alignment); - } - else { + } else { badRequest = true; obs_data_set_string(positionError, "alignment", "invalid"); obs_data_set_obj(errorData, "position", positionError); } } + obs_sceneitem_set_pos(sceneItem, &newPosition); } if (request.hasField("rotation")) { - obs_sceneitem_set_rot(sceneItem, (float)obs_data_get_double(request.parameters(), "rotation")); + obs_sceneitem_set_rot(sceneItem, (float)obs_data_get_double(params, "rotation")); } if (request.hasField("scale")) { vec2 oldScale; obs_sceneitem_get_scale(sceneItem, &oldScale); - OBSDataAutoRelease reqScale = obs_data_get_obj(request.parameters(), "scale"); vec2 newScale = oldScale; + + OBSDataAutoRelease reqScale = obs_data_get_obj(params, "scale"); + if (obs_data_has_user_value(reqScale, "x")) { newScale.x = obs_data_get_double(reqScale, "x"); } if (obs_data_has_user_value(reqScale, "y")) { newScale.y = obs_data_get_double(reqScale, "y"); } + obs_sceneitem_set_scale(sceneItem, &newScale); } if (request.hasField("crop")) { obs_sceneitem_crop oldCrop; obs_sceneitem_get_crop(sceneItem, &oldCrop); - OBSDataAutoRelease reqCrop = obs_data_get_obj(request.parameters(), "crop"); + + OBSDataAutoRelease reqCrop = obs_data_get_obj(params, "crop"); obs_sceneitem_crop newCrop = oldCrop; + if (obs_data_has_user_value(reqCrop, "top")) { newCrop.top = obs_data_get_int(reqCrop, "top"); } @@ -182,21 +194,23 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) if (obs_data_has_user_value(reqCrop, "left")) { newCrop.left = obs_data_get_int(reqCrop, "left"); } + obs_sceneitem_set_crop(sceneItem, &newCrop); } if (request.hasField("visible")) { - obs_sceneitem_set_visible(sceneItem, obs_data_get_bool(request.parameters(), "visible")); + obs_sceneitem_set_visible(sceneItem, obs_data_get_bool(params, "visible")); } if (request.hasField("locked")) { - obs_sceneitem_set_locked(sceneItem, obs_data_get_bool(request.parameters(), "locked")); + obs_sceneitem_set_locked(sceneItem, obs_data_get_bool(params, "locked")); } if (request.hasField("bounds")) { bool badBounds = false; OBSDataAutoRelease boundsError = obs_data_create(); - OBSDataAutoRelease reqBounds = obs_data_get_obj(request.parameters(), "bounds"); + OBSDataAutoRelease reqBounds = obs_data_get_obj(params, "bounds"); + if (obs_data_has_user_value(reqBounds, "type")) { QString newBoundsType = obs_data_get_string(reqBounds, "type"); if (newBoundsType == "OBS_BOUNDS_NONE") { @@ -225,16 +239,20 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) obs_data_set_string(boundsError, "type", "invalid"); } } + vec2 oldBounds; obs_sceneitem_get_bounds(sceneItem, &oldBounds); vec2 newBounds = oldBounds; + if (obs_data_has_user_value(reqBounds, "x")) { newBounds.x = obs_data_get_double(reqBounds, "x"); } if (obs_data_has_user_value(reqBounds, "y")) { newBounds.y = obs_data_get_double(reqBounds, "y"); } + obs_sceneitem_set_bounds(sceneItem, &newBounds); + if (obs_data_has_user_value(reqBounds, "alignment")) { const uint32_t bounds_alignment = obs_data_get_int(reqBounds, "alignment"); if (Utils::IsValidAlignment(bounds_alignment)) { @@ -245,6 +263,7 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) obs_data_set_string(boundsError, "alignment", "invalid"); } } + if (badBounds) { obs_data_set_obj(errorData, "bounds", boundsError); } @@ -277,13 +296,15 @@ RpcResponse WSRequestHandler::ResetSceneItem(const RpcRequest& request) { return request.failed("missing request parameters"); } - const char* sceneName = obs_data_get_string(request.parameters(), "scene-name"); + OBSData params = request.parameters(); + + const char* sceneName = obs_data_get_string(params, "scene-name"); OBSScene scene = Utils::GetSceneFromNameOrCurrent(sceneName); if (!scene) { return request.failed("requested scene doesn't exist"); } - OBSDataItemAutoRelease itemField = obs_data_item_byname(request.parameters(), "item"); + OBSDataItemAutoRelease itemField = obs_data_item_byname(params, "item"); OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); From 3604995c2fa5b6f0c6abba6d46ed562a323bde77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lepin?= Date: Mon, 30 Mar 2020 00:02:36 +0200 Subject: [PATCH 11/11] requests(DeleteSceneItem + DuplicateSceneItem): backport dual "item" behaviour to existing functions --- src/WSRequestHandler_SceneItems.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/WSRequestHandler_SceneItems.cpp b/src/WSRequestHandler_SceneItems.cpp index 829d36eb..c1fd8522 100644 --- a/src/WSRequestHandler_SceneItems.cpp +++ b/src/WSRequestHandler_SceneItems.cpp @@ -115,7 +115,7 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request) } OBSDataItemAutoRelease itemField = obs_data_item_byname(params, "item"); - OBSSceneItemAutoRelease sceneItem =Utils::GetSceneItemFromRequestField(scene, itemField); + OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("specified scene item doesn't exist"); } @@ -533,8 +533,8 @@ RpcResponse WSRequestHandler::DeleteSceneItem(const RpcRequest& request) { return request.failed("requested scene doesn't exist"); } - OBSDataAutoRelease item = obs_data_get_obj(request.parameters(), "item"); - OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromItem(scene, item); + OBSDataItemAutoRelease itemField = obs_data_item_byname(request.parameters(), "item"); + OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromRequestField(scene, itemField); if (!sceneItem) { return request.failed("item with id/name combination not found in specified scene"); } @@ -586,8 +586,8 @@ RpcResponse WSRequestHandler::DuplicateSceneItem(const RpcRequest& request) { return request.failed("requested toScene doesn't exist"); } - OBSDataAutoRelease item = obs_data_get_obj(request.parameters(), "item"); - OBSSceneItemAutoRelease referenceItem = Utils::GetSceneItemFromItem(fromScene, item); + OBSDataItemAutoRelease itemField = obs_data_item_byname(request.parameters(), "item"); + OBSSceneItemAutoRelease referenceItem = Utils::GetSceneItemFromRequestField(fromScene, itemField); if (!referenceItem) { return request.failed("item with id/name combination not found in specified scene"); }