BsAudioClipRTTI.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "BsRTTIType.h"
  6. #include "BsAudioClip.h"
  7. #include "BsDataStream.h"
  8. namespace BansheeEngine
  9. {
  10. /** @cond RTTI */
  11. /** @addtogroup RTTI-Impl-Core
  12. * @{
  13. */
  14. class BS_CORE_EXPORT AudioClipRTTI : public RTTIType <AudioClip, Resource, AudioClipRTTI>
  15. {
  16. private:
  17. BS_BEGIN_RTTI_MEMBERS
  18. BS_RTTI_MEMBER_PLAIN_NAMED(readMode, mDesc.readMode, 0)
  19. BS_RTTI_MEMBER_PLAIN_NAMED(format, mDesc.format, 1)
  20. BS_RTTI_MEMBER_PLAIN_NAMED(frequency, mDesc.frequency, 2)
  21. BS_RTTI_MEMBER_PLAIN_NAMED(bitDepth, mDesc.bitDepth, 3)
  22. BS_RTTI_MEMBER_PLAIN_NAMED(numChannels, mDesc.numChannels, 4)
  23. BS_RTTI_MEMBER_PLAIN(mNumSamples, 5)
  24. BS_RTTI_MEMBER_PLAIN(mStreamSize, 7)
  25. BS_RTTI_MEMBER_PLAIN(mStreamOffset, 8)
  26. BS_RTTI_MEMBER_PLAIN_NAMED(is3D, mDesc.is3D, 9)
  27. BS_RTTI_MEMBER_PLAIN(mLength, 10)
  28. BS_END_RTTI_MEMBERS
  29. SPtr<DataStream> getData(AudioClip* obj, UINT32& size)
  30. {
  31. SPtr<DataStream> stream = obj->getSourceStream(size);
  32. if (stream != nullptr && stream->isFile())
  33. LOGWRN("Saving an AudioClip which uses streaming data. Streaming data might not be available if saving to the same file.");
  34. return stream;
  35. }
  36. void setData(AudioClip* obj, const SPtr<DataStream>& val, UINT32 size)
  37. {
  38. obj->mStreamData = val->clone(); // Making sure that the AudioClip cannot modify the source stream, which is still used by the deserializer
  39. obj->mStreamSize = size;
  40. obj->mStreamOffset = (UINT32)val->tell();
  41. }
  42. public:
  43. AudioClipRTTI()
  44. :mInitMembers(this)
  45. {
  46. addDataBlockField("mData", 6, &AudioClipRTTI::getData, &AudioClipRTTI::setData, 0);
  47. }
  48. void onDeserializationEnded(IReflectable* obj, const UnorderedMap<String, UINT64>& params) override
  49. {
  50. AudioClip* clip = static_cast<AudioClip*>(obj);
  51. clip->initialize();
  52. }
  53. const String& getRTTIName() override
  54. {
  55. static String name = "AudioClip";
  56. return name;
  57. }
  58. UINT32 getRTTIId() override
  59. {
  60. return TID_AudioClip;
  61. }
  62. SPtr<IReflectable> newRTTIObject() override
  63. {
  64. return AudioClip::createEmpty();
  65. }
  66. };
  67. /** @} */
  68. /** @endcond */
  69. }