| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
#include "servers/audio/audio_server.h" |
| 35 |
|
| 36 |
struct AudioFrame; |
| 37 |
class AudioStream; |
| 38 |
class AudioStreamPlayback; |
| 39 |
class AudioStreamPlayerInternal; |
| 40 |
|
| 41 |
class AudioStreamPlayer2D : public Node2D { |
| 42 |
GDCLASS(AudioStreamPlayer2D, Node2D); |
| 43 |
|
| 44 |
private: |
| 45 |
enum { |
| 46 |
MAX_OUTPUTS = 8, |
| 47 |
MAX_INTERSECT_AREAS = 32 |
| 48 |
|
| 49 |
}; |
| 50 |
|
| 51 |
AudioStreamPlayerInternal *internal = nullptr; |
| 52 |
|
| 53 |
SafeNumeric<float> setplay{ -1.0 }; |
| 54 |
Ref<AudioStreamPlayback> setplayback; |
| 55 |
|
| 56 |
Vector<AudioFrame> volume_vector; |
| 57 |
|
| 58 |
uint64_t last_mix_count = -1; |
| 59 |
bool force_update_panning = false; |
| 60 |
|
| 61 |
AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT; |
| 62 |
|
| 63 |
void _set_playing(bool p_enable); |
| 64 |
bool _is_active() const; |
| 65 |
|
| 66 |
StringName _get_actual_bus(); |
| 67 |
void _update_panning(); |
| 68 |
|
| 69 |
static void _listener_changed_cb(void *self) { reinterpret_cast<AudioStreamPlayer2D *>(self)->force_update_panning = true; } |
| 70 |
|
| 71 |
uint32_t area_mask = 1; |
| 72 |
|
| 73 |
float max_distance = 2000.0; |
| 74 |
float attenuation = 1.0; |
| 75 |
|
| 76 |
float panning_strength = 1.0f; |
| 77 |
float cached_global_panning_strength = 0.5f; |
| 78 |
|
| 79 |
protected: |
| 80 |
void _validate_property(PropertyInfo &p_property) const; |
| 81 |
void _notification(int p_what); |
| 82 |
static void _bind_methods(); |
| 83 |
|
| 84 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 85 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 86 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 87 |
|
| 88 |
#ifndef DISABLE_DEPRECATED |
| 89 |
bool _is_autoplay_enabled_bind_compat_86907(); |
| 90 |
static void _bind_compatibility_methods(); |
| 91 |
#endif |
| 92 |
|
| 93 |
public: |
| 94 |
void set_stream(Ref<AudioStream> p_stream); |
| 95 |
Ref<AudioStream> get_stream() const; |
| 96 |
|
| 97 |
void set_volume_db(float p_volume); |
| 98 |
float get_volume_db() const; |
| 99 |
|
| 100 |
void set_volume_linear(float p_volume); |
| 101 |
float get_volume_linear() const; |
| 102 |
|
| 103 |
void set_pitch_scale(float p_pitch_scale); |
| 104 |
float get_pitch_scale() const; |
| 105 |
|
| 106 |
void play(float p_from_pos = 0.0); |
| 107 |
void seek(float p_seconds); |
| 108 |
void stop(); |
| 109 |
bool is_playing() const; |
| 110 |
float get_playback_position(); |
| 111 |
|
| 112 |
void set_bus(const StringName &p_bus); |
| 113 |
StringName get_bus() const; |
| 114 |
|
| 115 |
void set_autoplay(bool p_enable); |
| 116 |
bool is_autoplay_enabled() const; |
| 117 |
|
| 118 |
void set_max_distance(float p_pixels); |
| 119 |
float get_max_distance() const; |
| 120 |
|
| 121 |
void set_attenuation(float p_curve); |
| 122 |
float get_attenuation() const; |
| 123 |
|
| 124 |
void set_area_mask(uint32_t p_mask); |
| 125 |
uint32_t get_area_mask() const; |
| 126 |
|
| 127 |
void set_stream_paused(bool p_pause); |
| 128 |
bool get_stream_paused() const; |
| 129 |
|
| 130 |
void set_max_polyphony(int p_max_polyphony); |
| 131 |
int get_max_polyphony() const; |
| 132 |
|
| 133 |
void set_panning_strength(float p_panning_strength); |
| 134 |
float get_panning_strength() const; |
| 135 |
|
| 136 |
bool has_stream_playback(); |
| 137 |
Ref<AudioStreamPlayback> get_stream_playback(); |
| 138 |
|
| 139 |
AudioServer::PlaybackType get_playback_type() const; |
| 140 |
void set_playback_type(AudioServer::PlaybackType p_playback_type); |
| 141 |
|
| 142 |
AudioStreamPlayer2D(); |
| 143 |
~AudioStreamPlayer2D(); |
| 144 |
}; |