LeviLamina
Loading...
Searching...
No Matches
SoundEngine.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/client/sound/SoundMapping.h"
7#include "mc/client/sound/VolumeMultipliers.h"
8#include "mc/deps/audio/SoundEventRepository.h"
9#include "mc/deps/audio/SoundPauseSource.h"
10#include "mc/deps/audio/SoundPlayerInterface.h"
11#include "mc/deps/core/file/PathBuffer.h"
12#include "mc/deps/core/utility/NonOwnerPointer.h"
13#include "mc/deps/core/utility/pub_sub/Connector.h"
14#include "mc/deps/core/utility/pub_sub/Subscription.h"
15
16// auto generated forward declare list
17// clang-format off
18class IFileAccess;
24class SoundEvent;
25class SoundItem;
26class SoundSystemBase;
29class Vec3;
30struct ListenerState;
33struct PlaySoundOptions;
36namespace Audio { class OnlineAudioStreamManager; }
37namespace Bedrock::Resources { class PreloadedPathHandle; }
38namespace Core { class FileSystem; }
39namespace Core { class Path; }
40namespace Core { class PathView; }
41// clang-format on
42
44public:
45 // SoundEngine inner types define
46 enum class MusicVolumeSource : uint64 {
47 CurrentTrack = 0,
48 Option = 1,
49 MusicCommand = 2,
50 BiomeDuck = 3,
51 JukeboxDuck = 4,
52 Count = 5,
53 };
54
55 using SoundEventQueue = ::std::vector<::std::pair<::std::string, ::std::shared_ptr<::SoundEvent>>>;
56
57 using ListenerStatesSpan = ::gsl::span<::std::pair<int, ::ListenerState>>;
58
59public:
60 // member variables
61 // NOLINTBEGIN
62 ::ll::TypedStorage<8, 8, ::gsl::not_null<::std::unique_ptr<::SoundSystemBase>> const> mSoundSystem;
63 ::ll::TypedStorage<8, 64, ::std::unordered_set<uint64>> mFrameUniqueSoundSet;
64 ::ll::TypedStorage<8, 144, ::SoundEventRepository> mSoundEventRepository;
65 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::IReadWriteOptions>> mOptions;
66 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::TextToSpeechClient>> mTTSClient;
67 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mMainVolumeOptionSubscription;
68 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mSoundVolumeOptionSubscription;
69 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mMusicVolumeOptionSubscription;
70 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mTextToSpeechVolumeOptionSubscription;
71 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mOnPauseStateChangeSubscription;
72 ::ll::TypedStorage<8, 24, ::std::vector<::Bedrock::PubSub::Subscription>> mSoundCategoryVolumeOptionSubscriptions;
73 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::ResourcePackManager>> mResourceManager;
74 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::LinkedAssetValidator>> mLinkedAssetValidator;
75 ::ll::TypedStorage<4, 140, ::VolumeMultipliers<5>> mMusicVolumeMultipliers;
76 ::ll::TypedStorage<4, 4, float> mMainVolume;
77 ::ll::TypedStorage<4, 4, float> mTTSVolume;
78 ::ll::TypedStorage<1, 1, bool> mMuted;
79 ::ll::TypedStorage<1, 1, bool> mFadeToStopMusic;
80 ::ll::TypedStorage<8, 392, ::SoundMapping> mSounds;
81 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::Audio::OnlineAudioStreamManager>> mOnlineStreamManager;
82 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::StreamingAudioExperiment> const> mStreamingExperiment;
83 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::Core::FileSystem>> mFileSystem;
84 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::IFileAccess>> mFileAccess;
85 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mDataPath;
86 ::ll::TypedStorage<8, 8, ::std::shared_mutex> mResourceLoadManagerMutex;
87 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::ResourceLoadManager>> mResourceLoadManager;
88 // NOLINTEND
89
90public:
91 // virtual functions
92 // NOLINTBEGIN
93 virtual ~SoundEngine() /*override*/ = default;
94
95 virtual void pauseMusic(bool state) /*override*/;
96
97 virtual uint64 play(
98 ::std::string const& name,
99 ::Vec3 const& pos,
100 float volume,
101 float pitch,
102 ::std::optional<::ServerSoundHandle> serverSoundHandle
103 ) /*override*/;
104
105 virtual uint64 play(::PlaySoundOptions options) /*override*/;
106
107 virtual void stop(::std::string const& name) /*override*/;
108
109 virtual void stop(uint64 handle) /*override*/;
110
111 virtual void stop(::ServerSoundHandle serverSoundHandle) /*override*/;
112
113 virtual void setVolume(::ServerSoundHandle serverSoundHandle, float volume) /*override*/;
114
115 virtual void setPitch(::ServerSoundHandle serverSoundHandle, float pitch) /*override*/;
116
117 virtual void fade(::ServerSoundHandle serverSoundHandle, float duration, float targetVolume) /*override*/;
118
119 virtual void setPlaybackPosition(::ServerSoundHandle serverSoundHandle, float seconds) /*override*/;
120
121 virtual void pause(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source) /*override*/;
122
123 virtual void resume(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source) /*override*/;
124
125 virtual void stopAllSounds() /*override*/;
126
127 virtual void pauseAllPlayingSounds(::SoundPauseSource source) /*override*/;
128
129 virtual void resumeAllPreviouslyPlayingSounds(::SoundPauseSource source) /*override*/;
130
131 virtual ::std::optional<::std::string> getSubtitle(::std::string const& name) const /*override*/;
132
133 virtual uint64 playUI(::std::string const& name, float volume, float pitch) /*override*/;
134
135 virtual void playMusic(::std::string const& eventName, float volume, uint& playlistIndex) /*override*/;
136
137 virtual void playMusic(::std::string const& eventName, float volume) /*override*/;
138
139 virtual bool isLoadingMusic() const /*override*/;
140
141 virtual bool isPlayingMusicEvent(::std::string const& eventName) const /*override*/;
142
143 virtual bool isPlayingMusic(::Core::PathView soundPath) const /*override*/;
144
145 virtual void fadeToStopMusic(float fadeSeconds) /*override*/;
146
147 virtual void setMusicCommandVolumeMultiplier(float volumeMultiplier) /*override*/;
148
149 virtual void fadeOut(uint64 handle, float duration) /*override*/;
150
151 virtual void stopMusic() /*override*/;
152
153 virtual uint64 registerLoop(
154 ::std::string const& name,
155 ::std::function<void(::LoopingSoundState&)> getSoundState,
156 float fadeInDuration,
157 float fadeOutDuration
158 ) /*override*/;
159
160 virtual void unregisterLoop(uint64 handle, bool hard) /*override*/;
161
162 virtual bool isPlayingSound(uint64 handle) const /*override*/;
163
164 virtual bool isPlayingSound(::Core::Path const& soundName) const /*override*/;
165
166 virtual bool isPlayingSound(::ServerSoundHandle serverSoundHandle) const /*override*/;
167
168 virtual uint64 playAttached(
169 ::std::string const& eventName,
170 ::std::function<void(::SoundInstanceProperties&)>&& getSoundProperties
171 ) /*override*/;
172
173 virtual bool getItem(::std::string const& eventName, ::Core::PathView soundPath, ::SoundItem& soundItem) const
174 /*override*/;
175
176 virtual ::Core::PathBuffer<::std::string> const& getCurrentlyPlayingMusicPath() /*override*/;
177
178 virtual void displaySoundEngineStats(::std::string& debugOutputFormat) const;
179
180 virtual ::std::optional<::PlayingSoundAttributes> tryGetPlayingSoundAttributes(uint64 handle) const /*override*/;
181
182 virtual ::std::optional<::LoopingSoundAttributes> tryGetLoopingSoundAttributes(uint64 handle) const /*override*/;
183 // NOLINTEND
184
185public:
186 // member functions
187 // NOLINTBEGIN
188 MCAPI void _loadSoundEvents(
189 ::std::vector<::std::pair<::std::string, ::std::shared_ptr<::SoundEvent>>>& soundEvents,
190 ::Bedrock::NonOwnerPointer<::LinkedAssetValidator> validator
191 );
192
193 MCAPI bool
194 _tryPlayMusicFromStreamingExperiment(::std::string const& eventName, ::SoundItem const& soundItem, float volume);
195
196 MCAPI void load(
197 bool,
198 ::Bedrock::NonOwnerPointer<::LinkedAssetValidator> validator,
199 ::std::shared_ptr<::std::vector<::Bedrock::Resources::PreloadedPathHandle>> preloadHandles
200 );
201
202 MCAPI uint64 playFromMemory(
203 ::Core::Path const& soundName,
204 char const* data,
205 uint64 dataSize,
206 bool is3D,
207 float minDistance,
208 float maxDistance,
209 float volume,
210 float pitch,
211 bool useLegacyMaxDistance,
212 bool isTTS
213 );
214
215 MCAPI void registerPauseManagerCallback(::Bedrock::PubSub::Connector<void(bool)>& connector);
216
217 MCAPI void setOptions(::std::shared_ptr<::IReadWriteOptions> options);
218
219 MCAPI void setTTSClient(::std::shared_ptr<::TextToSpeechClient> ttsClient);
220
221 MCAPI void update(::gsl::span<::std::pair<int, ::ListenerState>> listenerStates, float elapsedTime);
222 // NOLINTEND
223
224public:
225 // virtual function thunks
226 // NOLINTBEGIN
227 MCAPI void $pauseMusic(bool state);
228
229 MCAPI uint64 $play(
230 ::std::string const& name,
231 ::Vec3 const& pos,
232 float volume,
233 float pitch,
234 ::std::optional<::ServerSoundHandle> serverSoundHandle
235 );
236
237 MCAPI uint64 $play(::PlaySoundOptions options);
238
239 MCAPI void $stop(::std::string const& name);
240
241 MCAPI void $stop(uint64 handle);
242
243 MCAPI void $stop(::ServerSoundHandle serverSoundHandle);
244
245 MCAPI void $setVolume(::ServerSoundHandle serverSoundHandle, float volume);
246
247 MCAPI void $setPitch(::ServerSoundHandle serverSoundHandle, float pitch);
248
249 MCAPI void $fade(::ServerSoundHandle serverSoundHandle, float duration, float targetVolume);
250
251 MCAPI void $setPlaybackPosition(::ServerSoundHandle serverSoundHandle, float seconds);
252
253 MCAPI void $pause(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source);
254
255 MCAPI void $resume(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source);
256
257 MCAPI void $stopAllSounds();
258
259 MCAPI void $pauseAllPlayingSounds(::SoundPauseSource source);
260
261 MCAPI void $resumeAllPreviouslyPlayingSounds(::SoundPauseSource source);
262
263 MCAPI ::std::optional<::std::string> $getSubtitle(::std::string const& name) const;
264
265 MCAPI uint64 $playUI(::std::string const& name, float volume, float pitch);
266
267 MCAPI void $playMusic(::std::string const& eventName, float volume, uint& playlistIndex);
268
269 MCAPI void $playMusic(::std::string const& eventName, float volume);
270
271 MCAPI bool $isLoadingMusic() const;
272
273 MCAPI bool $isPlayingMusicEvent(::std::string const& eventName) const;
274
275 MCAPI bool $isPlayingMusic(::Core::PathView soundPath) const;
276
277 MCAPI void $fadeToStopMusic(float fadeSeconds);
278
279 MCAPI void $setMusicCommandVolumeMultiplier(float volumeMultiplier);
280
281 MCAPI void $fadeOut(uint64 handle, float duration);
282
283 MCAPI void $stopMusic();
284
285 MCAPI uint64 $registerLoop(
286 ::std::string const& name,
287 ::std::function<void(::LoopingSoundState&)> getSoundState,
288 float fadeInDuration,
289 float fadeOutDuration
290 );
291
292 MCAPI void $unregisterLoop(uint64 handle, bool hard);
293
294 MCAPI bool $isPlayingSound(uint64 handle) const;
295
296 MCAPI bool $isPlayingSound(::Core::Path const& soundName) const;
297
298 MCAPI bool $isPlayingSound(::ServerSoundHandle serverSoundHandle) const;
299
300 MCAPI uint64 $playAttached(
301 ::std::string const& eventName,
302 ::std::function<void(::SoundInstanceProperties&)>&& getSoundProperties
303 );
304
305 MCAPI bool $getItem(::std::string const& eventName, ::Core::PathView soundPath, ::SoundItem& soundItem) const;
306
307 MCAPI ::Core::PathBuffer<::std::string> const& $getCurrentlyPlayingMusicPath();
308
309 MCAPI void $displaySoundEngineStats(::std::string& debugOutputFormat) const;
310
311 MCAPI ::std::optional<::PlayingSoundAttributes> $tryGetPlayingSoundAttributes(uint64 handle) const;
312
313 MCAPI ::std::optional<::LoopingSoundAttributes> $tryGetLoopingSoundAttributes(uint64 handle) const;
314 // NOLINTEND
315};
Definition OnlineAudioStreamManager.h:19
Definition PreloadedPathHandle.h:16
Definition FileSystem.h:28
Definition PathView.h:19
Definition Path.h:11
Definition IFileAccess.h:15
Definition IReadWriteOptions.h:5
Definition LinkedAssetValidator.h:8
Definition ResourceLoadManager.h:18
Definition ResourcePackManager.h:38
Definition ServerSoundHandle.h:5
Definition SoundEngine.h:5
Definition SoundEvent.h:10
Definition SoundItem.h:5
Definition SoundPlayerInterface.h:24
Definition SoundSystemBase.h:5
Definition StreamingAudioExperiment.h:5
Definition TextToSpeechClient.h:5
Definition Vec3.h:10
Definition ListenerState.h:5
Definition LoopingSoundAttributes.h:8
Definition LoopingSoundState.h:5
Definition PlaySoundOptions.h:5
Definition PlayingSoundAttributes.h:5
Definition SoundInstanceProperties.h:5