| 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 "core/object/ref_counted.h" |
| 34 |
#include "core/templates/safe_refcount.h" |
| 35 |
#include "servers/audio/audio_server.h" |
| 36 |
|
| 37 |
class AudioStream; |
| 38 |
class AudioStreamPlayback; |
| 39 |
class AudioSamplePlayback; |
| 40 |
class Node; |
| 41 |
|
| 42 |
class AudioStreamPlayerInternal : public Object { |
| 43 |
GDCLASS(AudioStreamPlayerInternal, Object); |
| 44 |
|
| 45 |
private: |
| 46 |
struct ParameterData { |
| 47 |
StringName path; |
| 48 |
Variant value; |
| 49 |
}; |
| 50 |
|
| 51 |
static inline const String PARAM_PREFIX = "parameters/"; |
| 52 |
|
| 53 |
Node *node = nullptr; |
| 54 |
Callable play_callable; |
| 55 |
Callable stop_callable; |
| 56 |
bool physical = false; |
| 57 |
AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT; |
| 58 |
|
| 59 |
HashMap<StringName, ParameterData> playback_parameters; |
| 60 |
|
| 61 |
void _set_process(bool p_enabled); |
| 62 |
void _update_stream_parameters(); |
| 63 |
|
| 64 |
_FORCE_INLINE_ bool _is_sample() { |
| 65 |
return (AudioServer::get_singleton()->get_default_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_SAMPLE && get_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT) || get_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_SAMPLE; |
| 66 |
} |
| 67 |
|
| 68 |
public: |
| 69 |
Vector<Ref<AudioStreamPlayback>> stream_playbacks; |
| 70 |
Ref<AudioStream> stream; |
| 71 |
|
| 72 |
SafeFlag active; |
| 73 |
|
| 74 |
float pitch_scale = 1.0; |
| 75 |
float volume_db = 0.0; |
| 76 |
bool autoplay = false; |
| 77 |
StringName bus; |
| 78 |
int max_polyphony = 1; |
| 79 |
|
| 80 |
void process(); |
| 81 |
void ensure_playback_limit(); |
| 82 |
|
| 83 |
void notification(int p_what); |
| 84 |
void validate_property(PropertyInfo &p_property) const; |
| 85 |
bool set(const StringName &p_name, const Variant &p_value); |
| 86 |
bool get(const StringName &p_name, Variant &r_ret) const; |
| 87 |
void get_property_list(List<PropertyInfo> *p_list) const; |
| 88 |
|
| 89 |
void set_stream(Ref<AudioStream> p_stream); |
| 90 |
void set_pitch_scale(float p_pitch_scale); |
| 91 |
void set_max_polyphony(int p_max_polyphony); |
| 92 |
|
| 93 |
StringName get_bus() const; |
| 94 |
|
| 95 |
Ref<AudioStreamPlayback> play_basic(); |
| 96 |
void seek(float p_seconds); |
| 97 |
void stop_basic(); |
| 98 |
bool is_playing() const; |
| 99 |
float get_playback_position(); |
| 100 |
|
| 101 |
void set_playing(bool p_enable); |
| 102 |
bool is_active() const; |
| 103 |
|
| 104 |
void set_stream_paused(bool p_pause); |
| 105 |
bool get_stream_paused() const; |
| 106 |
|
| 107 |
bool has_stream_playback(); |
| 108 |
Ref<AudioStreamPlayback> get_stream_playback(); |
| 109 |
|
| 110 |
void set_playback_type(AudioServer::PlaybackType p_playback_type); |
| 111 |
AudioServer::PlaybackType get_playback_type() const; |
| 112 |
|
| 113 |
AudioStreamPlayerInternal(Node *p_node, const Callable &p_play_callable, const Callable &p_stop_callable, bool p_physical); |
| 114 |
}; |