MiniAudioEditorSystemComponent.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "MiniAudioEditorSystemComponent.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AssetBuilderSDK/AssetBuilderSDK.h>
  11. #include <AzFramework/Asset/GenericAssetHandler.h>
  12. #include <MiniAudio/SoundAsset.h>
  13. namespace MiniAudio
  14. {
  15. AZ::ComponentDescriptor* MiniAudioEditorSystemComponent_CreateDescriptor()
  16. {
  17. return MiniAudioEditorSystemComponent::CreateDescriptor();
  18. }
  19. AZ::TypeId MiniAudioEditorSystemComponent_GetTypeId()
  20. {
  21. return azrtti_typeid<MiniAudioEditorSystemComponent>();
  22. }
  23. void MiniAudioEditorSystemComponent::Reflect(AZ::ReflectContext* context)
  24. {
  25. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  26. {
  27. serializeContext->Class<MiniAudioEditorSystemComponent, AZ::Component>()->Version(1)->Attribute(
  28. AZ::Edit::Attributes::SystemComponentTags, AZStd::vector<AZ::Crc32>({ AZ_CRC_CE("AssetBuilder") }));
  29. }
  30. }
  31. void MiniAudioEditorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  32. {
  33. BaseSystemComponent::GetProvidedServices(provided);
  34. provided.push_back(AZ_CRC_CE("MiniAudioEditorService"));
  35. }
  36. void MiniAudioEditorSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  37. {
  38. BaseSystemComponent::GetIncompatibleServices(incompatible);
  39. incompatible.push_back(AZ_CRC_CE("MiniAudioEditorService"));
  40. }
  41. void MiniAudioEditorSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  42. {
  43. BaseSystemComponent::GetRequiredServices(required);
  44. }
  45. void MiniAudioEditorSystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
  46. {
  47. dependent.push_back(AZ_CRC_CE("AssetDatabaseService"));
  48. dependent.push_back(AZ_CRC_CE("AssetCatalogService"));
  49. BaseSystemComponent::GetDependentServices(dependent);
  50. }
  51. void MiniAudioEditorSystemComponent::Activate()
  52. {
  53. MiniAudioSystemComponent::Activate();
  54. AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
  55. // Register MiniSound Asset
  56. auto* materialAsset =
  57. aznew AzFramework::GenericAssetHandler<SoundAsset>("MiniSound Asset", SoundAsset::AssetGroup, SoundAsset::FileExtension);
  58. materialAsset->Register();
  59. m_assetHandlers.emplace_back(materialAsset);
  60. // Register MiniSound Asset Builder
  61. AssetBuilderSDK::AssetBuilderDesc materialAssetBuilderDescriptor;
  62. materialAssetBuilderDescriptor.m_name = "MiniSound Asset Builder";
  63. materialAssetBuilderDescriptor.m_version = 3; // bump this to rebuild all sound files
  64. materialAssetBuilderDescriptor.m_patterns.push_back(
  65. AssetBuilderSDK::AssetBuilderPattern("*.ogg", AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
  66. materialAssetBuilderDescriptor.m_patterns.push_back(
  67. AssetBuilderSDK::AssetBuilderPattern("*.flac", AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
  68. materialAssetBuilderDescriptor.m_patterns.push_back(
  69. AssetBuilderSDK::AssetBuilderPattern("*.mp3", AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
  70. materialAssetBuilderDescriptor.m_patterns.push_back(
  71. AssetBuilderSDK::AssetBuilderPattern("*.wav", AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
  72. materialAssetBuilderDescriptor.m_busId = azrtti_typeid<SoundAssetBuilder>();
  73. materialAssetBuilderDescriptor.m_createJobFunction =
  74. [this](const AssetBuilderSDK::CreateJobsRequest& request, AssetBuilderSDK::CreateJobsResponse& response)
  75. {
  76. m_soundAssetBuilder.CreateJobs(request, response);
  77. };
  78. materialAssetBuilderDescriptor.m_processJobFunction =
  79. [this](const AssetBuilderSDK::ProcessJobRequest& request, AssetBuilderSDK::ProcessJobResponse& response)
  80. {
  81. m_soundAssetBuilder.ProcessJob(request, response);
  82. };
  83. m_soundAssetBuilder.BusConnect(materialAssetBuilderDescriptor.m_busId);
  84. AssetBuilderSDK::AssetBuilderBus::Broadcast(
  85. &AssetBuilderSDK::AssetBuilderBus::Handler::RegisterBuilderInformation, materialAssetBuilderDescriptor);
  86. }
  87. void MiniAudioEditorSystemComponent::Deactivate()
  88. {
  89. m_assetHandlers.clear();
  90. AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
  91. MiniAudioSystemComponent::Deactivate();
  92. }
  93. } // namespace MiniAudio