BsCAudioSource.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsAudioSource.h"
  6. #include "BsComponent.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Components-Core
  10. * @{
  11. */
  12. /**
  13. * @copydoc AudioSource
  14. *
  15. * Wraps AudioSource as a Component.
  16. */
  17. class BS_CORE_EXPORT CAudioSource : public Component
  18. {
  19. public:
  20. CAudioSource(const HSceneObject& parent);
  21. virtual ~CAudioSource() {}
  22. /** @copydoc AudioSource::setClip */
  23. void setClip(const HAudioClip& clip);
  24. /** @copydoc AudioSource::getClip */
  25. HAudioClip getClip() const { return mAudioClip; }
  26. /** @copydoc AudioSource::setVolume */
  27. void setVolume(float volume);
  28. /** @copydoc AudioSource::getVolume */
  29. float getVolume() const { return mVolume; }
  30. /** @copydoc AudioSource::setPitch */
  31. void setPitch(float pitch);
  32. /** @copydoc AudioSource::getPitch */
  33. float getPitch() const { return mPitch; }
  34. /** @copydoc AudioSource::setIsLooping */
  35. void setIsLooping(bool loop);
  36. /** @copydoc AudioSource::getIsLooping */
  37. bool getIsLooping() const { return mLoop; }
  38. /** @copydoc AudioSource::setPriority */
  39. void setPriority(UINT32 priority);
  40. /** @copydoc AudioSource::getPriority */
  41. UINT32 getPriority() const { return mPriority; }
  42. /** @copydoc AudioSource::setMinDistance */
  43. void setMinDistance(float distance);
  44. /** @copydoc AudioSource::getMinDistance */
  45. float getMinDistance() const { return mMinDistance; }
  46. /** @copydoc AudioSource::setAttenuation */
  47. void setAttenuation(float attenuation);
  48. /** @copydoc AudioSource::getAttenuation */
  49. float getAttenuation() const { return mAttenuation; }
  50. /** @copydoc AudioSource::setTime */
  51. void setTime(float time);
  52. /** @copydoc AudioSource::getTime */
  53. float getTime() const;
  54. /** Sets whether playback should start as soon as the component is enabled. */
  55. void setPlayOnStart(bool enable) { mPlayOnStart = enable; }
  56. /** Determines should playback start as soon as the component is enabled. */
  57. bool getPlayOnStart() const { return mPlayOnStart; }
  58. /** @copydoc AudioSource::play */
  59. void play();
  60. /** @copydoc AudioSource::pause */
  61. void pause();
  62. /** @copydoc AudioSource::stop */
  63. void stop();
  64. /** @copydoc AudioSource::getState */
  65. AudioSourceState getState() const;
  66. /** @name Internal
  67. * @{
  68. */
  69. /** Returns the AudioSource implementation wrapped by this component. */
  70. AudioSource* _getInternal() const { return mInternal.get(); }
  71. /** @} */
  72. /************************************************************************/
  73. /* COMPONENT OVERRIDES */
  74. /************************************************************************/
  75. protected:
  76. friend class SceneObject;
  77. /** @copydoc Component::onInitialized() */
  78. void onInitialized() override;
  79. /** @copydoc Component::onDestroyed() */
  80. void onDestroyed() override;
  81. /** @copydoc Component::onDisabled() */
  82. void onDisabled() override;
  83. /** @copydoc Component::onEnabled() */
  84. void onEnabled() override;
  85. /** @copydoc Component::onTransformChanged() */
  86. void onTransformChanged(TransformChangedFlags flags) override;
  87. /** @copydoc Component::update() */
  88. void update() override;
  89. protected:
  90. using Component::destroyInternal;
  91. /** Creates the internal representation of the AudioSource and restores the values saved by the Component. */
  92. void restoreInternal();
  93. /** Destroys the internal AudioSource representation. */
  94. void destroyInternal();
  95. /**
  96. * Updates the transform of the internal AudioSource representation from the transform of the component's scene
  97. * object.
  98. */
  99. void updateTransform();
  100. SPtr<AudioSource> mInternal;
  101. Vector3 mLastPosition = Vector3::ZERO;
  102. Vector3 mVelocity = Vector3::ZERO;
  103. HAudioClip mAudioClip;
  104. float mVolume;
  105. float mPitch;
  106. bool mLoop;
  107. UINT32 mPriority;
  108. float mMinDistance;
  109. float mAttenuation;
  110. bool mPlayOnStart;
  111. /************************************************************************/
  112. /* RTTI */
  113. /************************************************************************/
  114. public:
  115. friend class CAudioSourceRTTI;
  116. static RTTITypeBase* getRTTIStatic();
  117. RTTITypeBase* getRTTI() const override;
  118. protected:
  119. CAudioSource() {} // Serialization only
  120. };
  121. /** @} */
  122. }