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