3
0

MiniAudioPlaybackComponentController.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #pragma once
  9. #include <AzCore/Asset/AssetCommon.h>
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <AzCore/Component/TransformBus.h>
  13. #include <MiniAudio/MiniAudioBus.h>
  14. #include <MiniAudio/MiniAudioPlaybackBus.h>
  15. #include "MiniAudioPlaybackComponentConfig.h"
  16. struct ma_sound;
  17. namespace MiniAudio
  18. {
  19. class MiniAudioPlaybackComponentController
  20. : public MiniAudioPlaybackRequestBus::Handler
  21. , public AZ::Data::AssetBus::MultiHandler
  22. {
  23. friend class EditorMiniAudioPlaybackComponent;
  24. public:
  25. AZ_CLASS_ALLOCATOR(MiniAudioPlaybackComponentController, AZ::SystemAllocator, 0);
  26. AZ_RTTI(MiniAudioPlaybackComponentController, "{1c3f1578-b190-4b49-a0c6-223f40bd9fe5}");
  27. MiniAudioPlaybackComponentController();
  28. explicit MiniAudioPlaybackComponentController(const MiniAudioPlaybackComponentConfig& config);
  29. ~MiniAudioPlaybackComponentController() override;
  30. static void Reflect(AZ::ReflectContext* context);
  31. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  32. void Activate(const AZ::EntityComponentIdPair& entityComponentIdPair);
  33. void Deactivate();
  34. void SetConfiguration(const MiniAudioPlaybackComponentConfig& config);
  35. const MiniAudioPlaybackComponentConfig& GetConfiguration() const;
  36. // MiniAudioPlaybackRequestBus
  37. void Play() override;
  38. void Stop() override;
  39. void Pause() override;
  40. void SetVolumePercentage(float volume) override;
  41. float GetVolumePercentage() const override;
  42. void SetVolumeDecibels(float volumeDecibels) override;
  43. float GetVolumeDecibels() const override;
  44. void SetLooping(bool loop) override;
  45. bool IsLooping() const override;
  46. AZ::Data::Asset<SoundAsset> GetSoundAsset() const override;
  47. void SetSoundAsset(AZ::Data::Asset<SoundAsset> soundAsset) override;
  48. SoundAssetRef GetSoundAssetRef() const override;
  49. void SetSoundAssetRef(const SoundAssetRef& soundAssetRef) override;
  50. float GetInnerAngleInRadians() const override;
  51. void SetInnerAngleInRadians(float innerAngleInRadians) override;
  52. float GetInnerAngleInDegrees() const override;
  53. void SetInnerAngleInDegrees(float innerAngleInDegrees) override;
  54. float GetOuterAngleInRadians() const override;
  55. void SetOuterAngleInRadians(float outerAngleInRadians) override;
  56. float GetOuterAngleInDegrees() const override;
  57. void SetOuterAngleInDegrees(float outerAngleInDegrees) override;
  58. float GetOuterVolumePercentage() const override;
  59. void SetOuterVolumePercentage(float outerVolume) override;
  60. float GetOuterVolumeDecibels() const override;
  61. void SetOuterVolumeDecibels(float outerVolumeDecibels) override;
  62. bool GetFixedDirecion() const override;
  63. void SetFixedDirecion(bool fixedDirection) override;
  64. float GetDirectionalAttenuationFactor() const override;
  65. void SetDirectionalAttenuationFactor(float directionalAttenuationFactor) override;
  66. AZ::Vector3 GetDirection() const override;
  67. void SetDirection(const AZ::Vector3& direction) override;
  68. // MultiHandler
  69. void OnAssetReady(AZ::Data::Asset<AZ::Data::AssetData> asset) override;
  70. private:
  71. AZ::EntityComponentIdPair m_entityComponentIdPair;
  72. void OnWorldTransformChanged(const AZ::Transform& world);
  73. AZ::TransformChangedEvent::Handler m_entityMovedHandler{[this](
  74. [[maybe_unused]] const AZ::Transform& local, const AZ::Transform& world)
  75. {
  76. OnWorldTransformChanged(world);
  77. }};
  78. MiniAudioPlaybackComponentConfig m_config;
  79. void OnConfigurationUpdated();
  80. void LoadSound();
  81. void UnloadSound();
  82. AZStd::unique_ptr<ma_sound> m_sound;
  83. AZStd::string m_soundName;
  84. };
  85. } // namespace MiniAudio