Unravel Engine C++ Reference
Loading...
Searching...
No Matches
audio_source_component.h
Go to the documentation of this file.
1#pragma once
2#include <engine/engine_export.h>
3
4#include <audiopp/source.h>
7#include <math/math.h>
8
9namespace unravel
10{
11
16class audio_source_component : public component_crtp<audio_source_component>
17{
18public:
24 void update(const math::transform& t, delta_t dt);
25
29 void on_play_begin();
30
34 void on_play_end();
35
40 void set_loop(bool on);
41
46 void set_volume(float volume);
47
52 void set_pitch(float pitch);
53
58 void set_volume_rolloff(float rolloff);
59
64 void set_range(const frange_t& range);
65
70 void set_autoplay(bool on);
71
76 auto get_autoplay() const -> bool;
77
82 auto get_volume() const -> float;
83
88 auto get_pitch() const -> float;
89
94 auto get_volume_rolloff() const -> float;
95
100 auto get_range() const -> const frange_t&;
101
106 void set_playback_position(audio::duration_t offset);
107
112 auto get_playback_position() const -> audio::duration_t;
113
118 auto get_playback_duration() const -> audio::duration_t;
119
120
124 auto play() -> bool;
125
129 void stop();
130
134 void pause();
135
139 void resume();
140
145 void set_mute(bool mute);
146
151 auto is_muted() const -> bool;
152
157 auto is_playing() const -> bool;
158
163 auto is_paused() const -> bool;
164
169 auto is_looping() const -> bool;
170
175 void set_clip(const asset_handle<audio_clip>& clip);
176
181 auto get_clip() const -> const asset_handle<audio_clip>&;
182
187 auto has_bound_sound() const -> bool;
188
189private:
193 void apply_all();
194
199 auto is_sound_valid() const -> bool;
200
205 auto create_source() -> bool;
206
207 bool auto_play_ = false;
208 bool loop_ = false;
209 bool muted_ = false;
210 float volume_ = 1.0f;
211 float pitch_ = 1.0f;
212 float volume_rolloff_ = 1.0f;
213 frange_t range_ = {1.0f, 20.0f};
214 std::shared_ptr<audio::source> source_;
216
217 bool auto_play_consumed_ = true;
218};
219
220} // namespace unravel
General purpose transformation class designed to maintain each component of the transformation separa...
Definition transform.hpp:27
Class that contains core data for audio sources.
auto get_range() const -> const frange_t &
Gets the range of the audio source.
void set_volume(float volume)
Sets the volume of the audio source.
void set_autoplay(bool on)
Sets whether the audio source should autoplay.
void set_clip(const asset_handle< audio_clip > &clip)
Sets the audio clip for the audio source.
void set_range(const frange_t &range)
Sets the range of the audio source.
void update(const math::transform &t, delta_t dt)
Updates the audio source with the given transform and delta time.
void set_loop(bool on)
Sets whether the audio source should loop.
auto is_playing() const -> bool
Checks if the audio source is currently playing.
auto get_clip() const -> const asset_handle< audio_clip > &
Gets the audio clip of the audio source.
void resume()
Resumes playing the audio source.
void set_mute(bool mute)
Sets whether the audio source is muted.
void on_play_begin()
Called when audio playback begins.
void stop()
Stops playing the audio source.
auto is_muted() const -> bool
Checks if the audio source is muted.
auto get_volume_rolloff() const -> float
Gets the volume rolloff factor of the audio source.
void on_play_end()
Called when audio playback ends.
auto is_paused() const -> bool
Checks if the audio source is currently paused.
auto has_bound_sound() const -> bool
Checks if the audio source has a valid sound bound.
auto get_pitch() const -> float
Gets the pitch of the audio source.
void set_volume_rolloff(float rolloff)
Sets the volume rolloff factor of the audio source.
void set_playback_position(audio::duration_t offset)
Sets the playback position of the audio source.
void set_pitch(float pitch)
Sets the pitch of the audio source.
auto get_autoplay() const -> bool
Gets whether the audio source is set to autoplay.
auto is_looping() const -> bool
Checks if the audio source is set to loop.
auto get_volume() const -> float
Gets the volume of the audio source.
auto get_playback_position() const -> audio::duration_t
Gets the playback position of the audio source.
void pause()
Pauses the audio source.
auto get_playback_duration() const -> audio::duration_t
Gets the total playback duration of the audio source.
auto play() -> bool
Starts playing the audio source.
std::chrono::duration< float > delta_t
Represents a handle to an asset, providing access and management functions.
CRTP (Curiously Recurring Template Pattern) base structure for components.