WaapiDataSource.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #pragma once
  16. #include "CoreMinimal.h"
  17. #include "IWwiseBrowserDataSource.h"
  18. #include "WwiseItemType.h"
  19. #include "../WwiseBrowserForwards.h"
  20. #include "WaapiPicker/SWaapiPicker.h"
  21. class FJsonValue;
  22. class FJsonObject;
  23. DECLARE_DELEGATE_OneParam(FOnWaapiSelectionChange, const TArray<TSharedPtr<FWwiseTreeItem>>&)
  24. enum EWwiseConnectionStatus
  25. {
  26. Connected,
  27. SettingDisabled,
  28. WrongProjectOpened,
  29. WwiseNotOpen
  30. };
  31. struct WaapiTransformStringField
  32. {
  33. const FString keyArg;
  34. const TArray<FString> valueStringArgs;
  35. const TArray<int32> valueNumberArgs;
  36. };
  37. struct WWiseWaapiItem
  38. {
  39. FGuid Guid;
  40. FName Name;
  41. FName FullPath;
  42. };
  43. class FWaapiDataSource : IWwiseBrowserDataSource
  44. {
  45. public :
  46. DECLARE_DELEGATE(FOnWaapiDataSourceRefreshed)
  47. // IWwiseBrowserDataSource
  48. virtual ~FWaapiDataSource() override;
  49. // Sets up the connection to WAAPI
  50. virtual bool Init() override;
  51. virtual void ConstructTree(bool bShouldRefresh) override;
  52. // Constructs the top-level root for the given type, along with its direct children
  53. virtual FWwiseTreeItemPtr ConstructTreeRoot(EWwiseItemType::Type Type) override;
  54. virtual int32 LoadChildren(const FGuid& InParentId, const FString& InParentPath, TArray<FWwiseTreeItemPtr>& OutChildren) override;
  55. virtual int32 LoadChildren(FWwiseTreeItemPtr ParentTreeItem) override;
  56. virtual int32 GetChildItemCount(const FWwiseTreeItemPtr& InParentItem) override;
  57. virtual FWwiseTreeItemPtr GetRootItem(EWwiseItemType::Type RootType) override;
  58. FWwiseTreeItemPtr GetRootItem(const FString& InFullPath);
  59. virtual FWwiseTreeItemPtr LoadFilteredRootItem(EWwiseItemType::Type RootType, TSharedPtr<StringFilter> CurrentFilterText) override;
  60. // FWaapiDataSource
  61. bool TearDown();
  62. FWwiseTreeItemPtr ConstructWwiseTreeItem(const TSharedPtr<FJsonObject>& InItemInfoObj);
  63. FWwiseTreeItemPtr ConstructWwiseTreeItem(const TSharedPtr<FJsonValue>& InJsonItem);
  64. FWwiseTreeItemPtr FindItemFromPath(const FWwiseTreeItemPtr& InParentItem, const FString& InCurrentItemPath);
  65. FWwiseTreeItemPtr FindItemFromPath(const FString& InCurrentItemPath);
  66. FWwiseTreeItemPtr FindOrConstructTreeItemFromJsonObject(const TSharedPtr<FJsonObject>& ObjectJson);
  67. void FindAndCreateItems(FWwiseTreeItemPtr CurrentItem);
  68. FString GetItemWorkUnitPath(FWwiseTreeItemPtr InItem);
  69. bool LoadWaapiInfo(const FString& InFromField, const FString& InFromString, TSharedPtr<FJsonObject>& OutJsonResult, const TArray<WaapiTransformStringField>& TransformFields);
  70. bool IsTreeDirty();
  71. void Tick(const double InCurrentTime, const float InDeltaTime);
  72. FString LoadProjectName();
  73. EWwiseConnectionStatus IsProjectLoaded();
  74. void SelectInProjectExplorer(TArray<FWwiseTreeItemPtr>& InTreeItems);
  75. /**
  76. * Call WAAPI to get information about an object form the path or the id of the object (inFrom).
  77. *
  78. * @param inFromField The path or the id from which the data will be get.
  79. * @param outJsonResult A JSON object that contains useful information about the call process, gets the object infos or gets an error infos in case the call failed.
  80. * @return A boolean to ensure that the call was successfully done.
  81. */
  82. static bool CallWaapiGetInfoFrom(const FString& inFromField, const FString& inFromString, TSharedPtr<FJsonObject>& outJsonResult, const TArray<TransformStringField>& TransformFields);
  83. void HandleFindWwiseItemInProjectExplorerCommandExecute(const TArray<FWwiseTreeItemPtr>& SelectedItems) const;
  84. FOnWaapiDataSourceRefreshed WaapiDataSourceRefreshed;
  85. FOnWaapiSelectionChange WwiseSelectionChange;
  86. FOnWaapiSelectionChange WwiseExpansionChange;
  87. private:
  88. /** Root items, one for each type of Wwise object */
  89. FCriticalSection WaapiRootItemsLock;
  90. TArray< FWwiseTreeItemPtr > RootItems;
  91. TArray<FGuid> ItemsToCreate;
  92. // Container paths along the Browser Tree
  93. TMap<FString, FWwiseTreeItemPtr> NodesByPath;
  94. FDelegateHandle ProjectLoadedHandle;
  95. FDelegateHandle ConnectionLostHandle;
  96. FDelegateHandle ClientBeginDestroyHandle;
  97. // WAAPI Callbacks
  98. void OnProjectLoadedCallback();
  99. void OnConnectionLostCallback();
  100. void OnWaapiClientBeginDestroyCallback();
  101. void OnWaapiRenamed(uint64_t Id, TSharedPtr<FJsonObject> Response);
  102. void OnWaapiChildAdded(uint64_t Id, TSharedPtr<FJsonObject> Response);
  103. void OnWaapiChildRemoved(uint64_t Id, TSharedPtr<FJsonObject> Response);
  104. void OnWwiseSelectionChanged(uint64_t Id, TSharedPtr<FJsonObject> Response);
  105. void SubscribeWaapiCallbacks();
  106. void UnsubscribeWaapiCallbacks();
  107. void RemoveClientCallbacks();
  108. struct FWaapiSubscriptionIds
  109. {
  110. uint64 Renamed = 0;
  111. uint64 ChildAdded = 0;
  112. uint64 ChildRemoved = 0;
  113. uint64 SelectionChanged = 0;
  114. } WaapiSubscriptionIds;
  115. };