AkAudioBankGenerationHelpers.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. /*------------------------------------------------------------------------------------
  16. AkAudioBankGenerationHelpers.cpp: Wwise Helpers to generate banks from the editor and when cooking.
  17. ------------------------------------------------------------------------------------*/
  18. #include "AkAudioBankGenerationHelpers.h"
  19. #include "AkAudioDevice.h"
  20. #include "AkSettings.h"
  21. #include "AkSettingsPerUser.h"
  22. #include "WwiseUnrealDefines.h"
  23. #include "IAudiokineticTools.h"
  24. #include "AssetManagement/AkAssetDatabase.h"
  25. #include "ObjectTools.h"
  26. #if UE_5_0_OR_LATER
  27. #include "HAL/PlatformFileManager.h"
  28. #else
  29. #include "HAL/PlatformFilemanager.h"
  30. #endif
  31. #include "Interfaces/IMainFrameModule.h"
  32. #include "Misc/Paths.h"
  33. #include "Misc/ScopedSlowTask.h"
  34. #include "Framework/Application/SlateApplication.h"
  35. #include "Widgets/SWindow.h"
  36. #include "AssetManagement/WwiseProjectInfo.h"
  37. #include "UI/SGenerateSoundBanks.h"
  38. #define LOCTEXT_NAMESPACE "AkAudio"
  39. namespace AkAudioBankGenerationHelper
  40. {
  41. FString GetWwiseConsoleApplicationPath()
  42. {
  43. const UAkSettingsPerUser* AkSettingsPerUser = GetDefault<UAkSettingsPerUser>();
  44. FString ApplicationToRun;
  45. ApplicationToRun.Empty();
  46. if (AkSettingsPerUser)
  47. {
  48. #if PLATFORM_WINDOWS
  49. ApplicationToRun = AkSettingsPerUser->WwiseWindowsInstallationPath.Path;
  50. #else
  51. ApplicationToRun = AkSettingsPerUser->WwiseMacInstallationPath.FilePath;
  52. #endif
  53. if (FPaths::IsRelative(ApplicationToRun))
  54. {
  55. ApplicationToRun = FPaths::ConvertRelativePathToFull(WwiseUnrealHelper::GetProjectDirectory(), ApplicationToRun);
  56. }
  57. if (!(ApplicationToRun.EndsWith(TEXT("/")) || ApplicationToRun.EndsWith(TEXT("\\"))))
  58. {
  59. ApplicationToRun += TEXT("/");
  60. }
  61. #if PLATFORM_WINDOWS
  62. if (FPaths::FileExists(ApplicationToRun + TEXT("Authoring/x64/Release/bin/WwiseConsole.exe")))
  63. {
  64. ApplicationToRun += TEXT("Authoring/x64/Release/bin/WwiseConsole.exe");
  65. }
  66. else
  67. {
  68. ApplicationToRun += TEXT("Authoring/Win32/Release/bin/WwiseConsole.exe");
  69. }
  70. ApplicationToRun.ReplaceInline(TEXT("/"), TEXT("\\"));
  71. #elif PLATFORM_MAC
  72. ApplicationToRun += TEXT("Contents/Tools/WwiseConsole.sh");
  73. ApplicationToRun = TEXT("\"") + ApplicationToRun + TEXT("\"");
  74. #endif
  75. }
  76. return ApplicationToRun;
  77. }
  78. void CreateGenerateSoundDataWindow(bool ProjectSave)
  79. {
  80. if (!FApp::CanEverRender())
  81. {
  82. return;
  83. }
  84. if (AkAssetDatabase::Get().CheckIfLoadingAssets())
  85. {
  86. return;
  87. }
  88. TSharedRef<SWindow> WidgetWindow = SNew(SWindow)
  89. .Title(LOCTEXT("AkAudioGenerateSoundData", "Generate SoundBanks"))
  90. .ClientSize(FVector2D(600.f, 332.f))
  91. .SupportsMaximize(false).SupportsMinimize(false)
  92. .SizingRule(ESizingRule::FixedSize)
  93. .FocusWhenFirstShown(true);
  94. TSharedRef<SGenerateSoundBanks> WindowContent = SNew(SGenerateSoundBanks);
  95. if (!WindowContent->ShouldDisplayWindow())
  96. {
  97. return;
  98. }
  99. // Add our SGenerateSoundBanks to the window
  100. WidgetWindow->SetContent(WindowContent);
  101. // Set focus to our SGenerateSoundBanks widget, so our keyboard keys work right away
  102. WidgetWindow->SetWidgetToFocusOnActivate(WindowContent);
  103. // This creates a windows that blocks the rest of the UI. You can only interact with the "Generate SoundBanks" window.
  104. // If you choose to use this, comment the rest of the function.
  105. //GEditor->EditorAddModalWindow(WidgetWindow);
  106. // This creates a window that still allows you to interact with the rest of the editor. If there is an attempt to delete
  107. // a UAkAudioBank (from the content browser) while this window is opened, the editor will generate a (cryptic) error message
  108. TSharedPtr<SWindow> ParentWindow;
  109. if (FModuleManager::Get().IsModuleLoaded("MainFrame"))
  110. {
  111. IMainFrameModule& MainFrame = FModuleManager::GetModuleChecked<IMainFrameModule>("MainFrame");
  112. ParentWindow = MainFrame.GetParentWindow();
  113. }
  114. if (ParentWindow.IsValid())
  115. {
  116. // Parent the window to the main frame
  117. FSlateApplication::Get().AddModalWindow(WidgetWindow, ParentWindow.ToSharedRef());
  118. }
  119. else
  120. {
  121. // Spawn new window
  122. FSlateApplication::Get().AddWindow(WidgetWindow);
  123. }
  124. }
  125. }
  126. #undef LOCTEXT_NAMESPACE