1/**************************************************************************/
2/* audio_stream_player.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#ifndef AUDIO_STREAM_PLAYER_H
32#define AUDIO_STREAM_PLAYER_H
33
34#include "core/templates/safe_refcount.h"
35#include "scene/main/node.h"
36#include "scene/scene_string_names.h"
37#include "servers/audio/audio_stream.h"
38
39class AudioStreamPlayer : public Node {
40 GDCLASS(AudioStreamPlayer, Node);
41
42public:
43 enum MixTarget {
44 MIX_TARGET_STEREO,
45 MIX_TARGET_SURROUND,
46 MIX_TARGET_CENTER
47 };
48
49private:
50 Vector<Ref<AudioStreamPlayback>> stream_playbacks;
51 Ref<AudioStream> stream;
52
53 SafeFlag active;
54
55 float pitch_scale = 1.0;
56 float volume_db = 0.0;
57 bool autoplay = false;
58 StringName bus = SceneStringNames::get_singleton()->Master;
59 int max_polyphony = 1;
60
61 MixTarget mix_target = MIX_TARGET_STEREO;
62
63 void _set_playing(bool p_enable);
64 bool _is_active() const;
65
66 void _bus_layout_changed();
67
68 Vector<AudioFrame> _get_volume_vector();
69
70protected:
71 void _validate_property(PropertyInfo &p_property) const;
72 void _notification(int p_what);
73 static void _bind_methods();
74
75public:
76 void set_stream(Ref<AudioStream> p_stream);
77 Ref<AudioStream> get_stream() const;
78
79 void set_volume_db(float p_volume);
80 float get_volume_db() const;
81
82 void set_pitch_scale(float p_pitch_scale);
83 float get_pitch_scale() const;
84
85 void set_max_polyphony(int p_max_polyphony);
86 int get_max_polyphony() const;
87
88 void play(float p_from_pos = 0.0);
89 void seek(float p_seconds);
90 void stop();
91 bool is_playing() const;
92 float get_playback_position();
93
94 void set_bus(const StringName &p_bus);
95 StringName get_bus() const;
96
97 void set_autoplay(bool p_enable);
98 bool is_autoplay_enabled();
99
100 void set_mix_target(MixTarget p_target);
101 MixTarget get_mix_target() const;
102
103 void set_stream_paused(bool p_pause);
104 bool get_stream_paused() const;
105
106 bool has_stream_playback();
107 Ref<AudioStreamPlayback> get_stream_playback();
108
109 AudioStreamPlayer();
110 ~AudioStreamPlayer();
111};
112
113VARIANT_ENUM_CAST(AudioStreamPlayer::MixTarget)
114
115#endif // AUDIO_STREAM_PLAYER_H
116