1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsCorePrerequisites.h"
6#include "Reflection/BsRTTIType.h"
7#include "Audio/BsAudioClip.h"
8#include "FileSystem/BsDataStream.h"
9
10namespace bs
11{
12 /** @cond RTTI */
13 /** @addtogroup RTTI-Impl-Core
14 * @{
15 */
16
17 class BS_CORE_EXPORT AudioClipRTTI : public RTTIType <AudioClip, Resource, AudioClipRTTI>
18 {
19 private:
20 BS_BEGIN_RTTI_MEMBERS
21 BS_RTTI_MEMBER_PLAIN_NAMED(readMode, mDesc.readMode, 0)
22 BS_RTTI_MEMBER_PLAIN_NAMED(format, mDesc.format, 1)
23 BS_RTTI_MEMBER_PLAIN_NAMED(frequency, mDesc.frequency, 2)
24 BS_RTTI_MEMBER_PLAIN_NAMED(bitDepth, mDesc.bitDepth, 3)
25 BS_RTTI_MEMBER_PLAIN_NAMED(numChannels, mDesc.numChannels, 4)
26 BS_RTTI_MEMBER_PLAIN(mNumSamples, 5)
27 BS_RTTI_MEMBER_PLAIN(mStreamSize, 7)
28 BS_RTTI_MEMBER_PLAIN(mStreamOffset, 8)
29 BS_RTTI_MEMBER_PLAIN_NAMED(is3D, mDesc.is3D, 9)
30 BS_RTTI_MEMBER_PLAIN(mLength, 10)
31 BS_END_RTTI_MEMBERS
32
33 SPtr<DataStream> getData(AudioClip* obj, UINT32& size)
34 {
35 SPtr<DataStream> stream = obj->getSourceStream(size);
36 if (stream != nullptr && stream->isFile())
37 LOGWRN("Saving an AudioClip which uses streaming data. Streaming data might not be available if saving to the same file.");
38
39 return stream;
40 }
41
42 void setData(AudioClip* obj, const SPtr<DataStream>& val, UINT32 size)
43 {
44 obj->mStreamData = val->clone(); // Making sure that the AudioClip cannot modify the source stream, which is still used by the deserializer
45 obj->mStreamSize = size;
46 obj->mStreamOffset = (UINT32)val->tell();
47 }
48
49 public:
50 AudioClipRTTI()
51 {
52 addDataBlockField("mData", 6, &AudioClipRTTI::getData, &AudioClipRTTI::setData);
53 }
54
55 void onDeserializationEnded(IReflectable* obj, SerializationContext* context) override
56 {
57 AudioClip* clip = static_cast<AudioClip*>(obj);
58 clip->initialize();
59 }
60
61 const String& getRTTIName() override
62 {
63 static String name = "AudioClip";
64 return name;
65 }
66
67 UINT32 getRTTIId() override
68 {
69 return TID_AudioClip;
70 }
71
72 SPtr<IReflectable> newRTTIObject() override
73 {
74 return AudioClip::createEmpty();
75 }
76 };
77
78 /** @} */
79 /** @endcond */
80}
81