Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/2d/audio_stream_player_2d.h
9898 views
1
/**************************************************************************/
2
/* audio_stream_player_2d.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "scene/2d/node_2d.h"
34
#include "servers/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
struct Output {
52
AudioFrame vol;
53
int bus_index = 0;
54
Viewport *viewport = nullptr; //pointer only used for reference to previous mix
55
};
56
57
AudioStreamPlayerInternal *internal = nullptr;
58
59
SafeNumeric<float> setplay{ -1.0 };
60
Ref<AudioStreamPlayback> setplayback;
61
62
Vector<AudioFrame> volume_vector;
63
64
uint64_t last_mix_count = -1;
65
bool force_update_panning = false;
66
67
AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT;
68
69
void _set_playing(bool p_enable);
70
bool _is_active() const;
71
72
StringName _get_actual_bus();
73
void _update_panning();
74
75
static void _listener_changed_cb(void *self) { reinterpret_cast<AudioStreamPlayer2D *>(self)->force_update_panning = true; }
76
77
uint32_t area_mask = 1;
78
79
float max_distance = 2000.0;
80
float attenuation = 1.0;
81
82
float panning_strength = 1.0f;
83
float cached_global_panning_strength = 0.5f;
84
85
protected:
86
void _validate_property(PropertyInfo &p_property) const;
87
void _notification(int p_what);
88
static void _bind_methods();
89
90
bool _set(const StringName &p_name, const Variant &p_value);
91
bool _get(const StringName &p_name, Variant &r_ret) const;
92
void _get_property_list(List<PropertyInfo> *p_list) const;
93
94
#ifndef DISABLE_DEPRECATED
95
bool _is_autoplay_enabled_bind_compat_86907();
96
static void _bind_compatibility_methods();
97
#endif // DISABLE_DEPRECATED
98
99
public:
100
void set_stream(Ref<AudioStream> p_stream);
101
Ref<AudioStream> get_stream() const;
102
103
void set_volume_db(float p_volume);
104
float get_volume_db() const;
105
106
void set_volume_linear(float p_volume);
107
float get_volume_linear() const;
108
109
void set_pitch_scale(float p_pitch_scale);
110
float get_pitch_scale() const;
111
112
void play(float p_from_pos = 0.0);
113
void seek(float p_seconds);
114
void stop();
115
bool is_playing() const;
116
float get_playback_position();
117
118
void set_bus(const StringName &p_bus);
119
StringName get_bus() const;
120
121
void set_autoplay(bool p_enable);
122
bool is_autoplay_enabled() const;
123
124
void set_max_distance(float p_pixels);
125
float get_max_distance() const;
126
127
void set_attenuation(float p_curve);
128
float get_attenuation() const;
129
130
void set_area_mask(uint32_t p_mask);
131
uint32_t get_area_mask() const;
132
133
void set_stream_paused(bool p_pause);
134
bool get_stream_paused() const;
135
136
void set_max_polyphony(int p_max_polyphony);
137
int get_max_polyphony() const;
138
139
void set_panning_strength(float p_panning_strength);
140
float get_panning_strength() const;
141
142
bool has_stream_playback();
143
Ref<AudioStreamPlayback> get_stream_playback();
144
145
AudioServer::PlaybackType get_playback_type() const;
146
void set_playback_type(AudioServer::PlaybackType p_playback_type);
147
148
AudioStreamPlayer2D();
149
~AudioStreamPlayer2D();
150
};
151
152