Toast Engine
Loading...
Searching...
No Matches
audio_emitter_base.hpp
Go to the documentation of this file.
1
8#pragma once
9#include "../assets.hpp"
10
11#include <toast/export.hpp>
13
14namespace toast {
15
23class TOAST_API [[ToastNode, Hidden, Color("Beige"), Icon("AudioStreamPlayer")]] AudioEmitterBase : public Node3D {
24public:
25 [[Button]]
26 void play();
27
28 [[Button]]
29 void stop();
30
31 void pause(bool value);
32 void setParameter(std::string_view name, float value) const;
33 void setParameter(std::string_view name, bool value) const;
34 [[nodiscard]]
35 auto isPlaying() const -> bool;
36
37 void event(std::string_view path);
38 void event(toast::UID uid);
39 void playOnEnable(bool value);
40 void volume(float value);
41 void pitch(float value);
42 void allowFadeout(bool value);
43
44 void dopplerScale(float value);
45 void calculateVelocity(bool value);
46 void overrideAttenuation(bool value);
47 void minDistance(float value);
48 void maxDistance(float value);
49
50 signals::Signal<std::string_view> audio_started;
51 signals::Signal<std::string_view> audio_stopped;
52 signals::Signal<bool> audio_paused;
53
54protected:
55 virtual auto emitterPosition(const glm::vec3& listener)
56 -> glm::vec3;
57 virtual auto emitterForward() -> glm::vec3;
58 virtual auto emitterUp() -> glm::vec3;
59
60private:
61 void updateInspectorMessages() override;
62 void onEnable();
63 void onDisable();
64 void begin();
65 void lateTick();
66 void update3DState();
67 void applyProperties() const;
68
69 [[Reflect, Name("Audio Event")]]
71
72 [[Reflect]]
73 bool m_play_on_enable = false;
74
75 [[Reflect, Range(0.0, 1.0)]]
76 float m_volume = 1.0f;
77
78 [[Reflect, Range(0.5, 2.0)]]
79 float m_pitch = 1.0f;
80
81 [[Reflect]]
82 bool m_allow_fadeout = true;
83
84 [[Reflect, Range(0.0, 5.0)]]
85 float m_doppler_scale = 1.0f;
86
87 [[Reflect]]
88 bool m_calculate_velocity = true;
89
90 [[Reflect, Group("Override Attenuation")]]
91 bool m_override_attenuation = false;
92
93 [[Reflect, Group("Override Attenuation")]]
94 float m_min_distance = 1.0f;
95
96 [[Reflect, Group("Override Attenuation")]]
97 float m_max_distance = 20.0f;
98
99 uint64_t m_instance_id = 0;
100 glm::vec3 m_last_position {0.f};
101};
102
103}
Type-safe smart pointer for assets.
Definition core_types.hpp:149
Base class for shape-based audio emitters.
Definition audio_emitter_base.hpp:23
virtual auto emitterPosition(const glm::vec3 &listener) -> glm::vec3
override this to project listener to the shape's nearest surface
Definition audio_emitter_base.cpp:222
Definition node_3d.hpp:25
auto name() const noexcept -> std::string_view
Display name. Siblings may share one - this is not an identifier.
Definition node.cpp:45
auto uid() const noexcept -> const UID &
Stable unique identifier, assigned at construction or deserialization. Never changes.
Definition node.cpp:37
auto listener() noexcept -> event::Listener &
The event Listener owned by this node. Lazy-allocated, freed only with the node.
Definition node.cpp:204
Definition reflect.hpp:244
Node with 3D spatial transforms.
Definition uid.hpp:20