Unravel Engine C++ Reference
Loading...
Searching...
No Matches
audio_source_component.cpp
Go to the documentation of this file.
2
6
9
10namespace unravel
11{
13{
14 entt::meta_factory<audio_source_component>{}
15 .type("audio_source_component"_hs)
17 entt::attribute{"name", "audio_source_component"},
18 entt::attribute{"category", "AUDIO"},
19 entt::attribute{"pretty_name", "Audio Source"},
20 })
21 .func<&component_meta<audio_source_component>::exists>("component_exists"_hs)
22 .func<&component_meta<audio_source_component>::add>("component_add"_hs)
23 .func<&component_meta<audio_source_component>::remove>("component_remove"_hs)
24 .func<&component_meta<audio_source_component>::save>("component_save"_hs)
25 .func<&component_meta<audio_source_component>::load>("component_load"_hs)
27 .custom<entt::attributes>(entt::attributes{
28 entt::attribute{"name", "auto_play"},
29 entt::attribute{"pretty_name", "Auto Play"},
30 })
31 .data<&audio_source_component::set_loop, &audio_source_component::is_looping>("loop"_hs)
33 entt::attribute{"name", "loop"},
34 entt::attribute{"pretty_name", "Loop"},
35 })
36 .data<&audio_source_component::set_mute, &audio_source_component::is_muted>("mute"_hs)
38 entt::attribute{"name", "mute"},
39 entt::attribute{"pretty_name", "Mute"},
40 })
41 .data<&audio_source_component::set_volume, &audio_source_component::get_volume>("volume"_hs)
43 entt::attribute{"name", "volume"},
44 entt::attribute{"pretty_name", "Volume"},
45 entt::attribute{"min", 0.0f},
46 entt::attribute{"max", 1.0f},
47 })
48 .data<&audio_source_component::set_pitch, &audio_source_component::get_pitch>("pitch"_hs)
50 entt::attribute{"name", "pitch"},
51 entt::attribute{"pretty_name", "Pitch"},
52 entt::attribute{"tooltip", "A multiplier for the frequency (sample rate) of the source's buffer."},
53 entt::attribute{"min", 0.0f},
54 entt::attribute{"max", 5.0f},
55 })
56 .data<&audio_source_component::set_volume_rolloff, &audio_source_component::get_volume_rolloff>("volume_rolloff"_hs)
58 entt::attribute{"name", "volume_rolloff"},
59 entt::attribute{"pretty_name", "Volume Rolloff"},
60 entt::attribute{"min", 0.0f},
61 entt::attribute{"max", 10.0f},
62 })
63 .data<&audio_source_component::set_range, &audio_source_component::get_range>("range"_hs)
65 entt::attribute{"name", "range"},
66 entt::attribute{"pretty_name", "Range"},
67 })
68 .data<&audio_source_component::set_clip, &audio_source_component::get_clip>("clip"_hs)
70 entt::attribute{"name", "clip"},
71 entt::attribute{"pretty_name", "Clip"},
72 });
73}
74
76{
77 try_save(ar, ser20::make_nvp("auto_play", obj.get_autoplay()));
78 try_save(ar, ser20::make_nvp("loop", obj.is_looping()));
79 try_save(ar, ser20::make_nvp("volume", obj.get_volume()));
80 try_save(ar, ser20::make_nvp("pitch", obj.get_pitch()));
81 try_save(ar, ser20::make_nvp("volume_rolloff", obj.get_volume_rolloff()));
82 try_save(ar, ser20::make_nvp("range", obj.get_range()));
83 try_save(ar, ser20::make_nvp("clip", obj.get_clip()));
84}
87
89{
90 bool auto_play{};
91 if(try_load(ar, ser20::make_nvp("auto_play", auto_play)))
92 {
93 obj.set_autoplay(auto_play);
94 }
95
96 bool loop{};
97 if(try_load(ar, ser20::make_nvp("loop", loop)))
98 {
99 obj.set_loop(loop);
100 }
101
102 float volume{1.0f};
103 if(try_load(ar, ser20::make_nvp("volume", volume)))
104 {
105 obj.set_volume(volume);
106 }
107
108 float pitch{1.0f};
109 if(try_load(ar, ser20::make_nvp("pitch", pitch)))
110 {
111 obj.set_pitch(pitch);
112 }
113
114 float volume_rolloff{1.0f};
115 if(try_load(ar, ser20::make_nvp("volume_rolloff", volume_rolloff)))
116 {
117 obj.set_volume_rolloff(volume_rolloff);
118 }
119
121 if(try_load(ar, ser20::make_nvp("range", range)))
122 {
123 obj.set_range(range);
124 }
125
127 if(try_load(ar, ser20::make_nvp("clip", clip)))
128 {
129 obj.set_clip(clip);
130 }
131}
134} // namespace unravel
Class that contains core data for audio sources.
void set_autoplay(bool on)
Sets whether the audio source should autoplay.
auto get_autoplay() const -> bool
Gets whether the audio source is set to autoplay.
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
#define REFLECT(cls)
Definition reflection.h:133
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Represents a handle to an asset, providing access and management functions.