Debian Codegraph @

modules/interactive_music/audio_stream_playlist.h

raw symbols SCIP
1 /**************************************************************************/
2 /* audio_stream_playlist.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 "servers/audio/audio_stream.h"
34
35 class AudioStreamPlaybackPlaylist;
36
37 class AudioStreamPlaylist : public AudioStream {
38 GDCLASS(AudioStreamPlaylist, AudioStream)
39 OBJ_SAVE_TYPE(AudioStream)
40
41 private:
42 friend class AudioStreamPlaybackPlaylist;
43
44 enum {
45 MAX_STREAMS = 64
46 };
47
48 bool shuffle = false;
49 bool loop = true;
50 double fade_time = 0.3;
51
52 int stream_count = 0;
53 Ref<AudioStream> audio_streams[MAX_STREAMS];
54 HashSet<AudioStreamPlaybackPlaylist *> playbacks;
55
56 public:
57 virtual double get_bpm() const override;
58 void set_stream_count(int p_count);
59 int get_stream_count() const;
60 void set_fade_time(float p_time);
61 float get_fade_time() const;
62 void set_shuffle(bool p_shuffle);
63 bool get_shuffle() const;
64 void set_loop(bool p_loop);
65 virtual bool has_loop() const override;
66 void set_list_stream(int p_stream_index, Ref<AudioStream> p_stream);
67 Ref<AudioStream> get_list_stream(int p_stream_index) const;
68
69 virtual Ref<AudioStreamPlayback> instantiate_playback() override;
70 virtual String get_stream_name() const override;
71 virtual double get_length() const override;
72 virtual bool is_meta_stream() const override { return true; }
73
74 protected:
75 static void _bind_methods();
76 void _validate_property(PropertyInfo &r_property) const;
77 };
78
79 ///////////////////////////////////////
80
81 class AudioStreamPlaybackPlaylist : public AudioStreamPlayback {
82 GDCLASS(AudioStreamPlaybackPlaylist, AudioStreamPlayback)
83 friend class AudioStreamPlaylist;
84
85 private:
86 enum {
87 MIX_BUFFER_SIZE = 128
88 };
89 AudioFrame mix_buffer[MIX_BUFFER_SIZE];
90 AudioFrame fade_buffer[MIX_BUFFER_SIZE];
91
92 Ref<AudioStreamPlaylist> playlist;
93 Ref<AudioStreamPlayback> playback[AudioStreamPlaylist::MAX_STREAMS];
94
95 int play_order[AudioStreamPlaylist::MAX_STREAMS] = {};
96
97 double stream_todo = 0.0;
98 int fade_index = -1;
99 double fade_volume = 1.0;
100 int play_index = 0;
101 double offset = 0.0;
102
103 int loop_count = 0;
104
105 bool active = false;
106
107 void _update_order();
108
109 void _update_playback_instances();
110
111 public:
112 virtual void start(double p_from_pos = 0.0) override;
113 virtual void stop() override;
114 virtual bool is_playing() const override;
115 virtual int get_loop_count() const override; // times it looped
116 virtual double get_playback_position() const override;
117 virtual void seek(double p_time) override;
118 virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override;
119
120 virtual void tag_used_streams() override;
121
122 ~AudioStreamPlaybackPlaylist();
123 };