fmod/studio/event_description/sample_data.rs
1// Copyright (c) 2024 Lily Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use fmod_sys::*;
8
9use crate::studio::{EventDescription, LoadingState};
10
11impl EventDescription {
12 /// Loads non-streaming sample data used by the event.
13 ///
14 /// This function will load all non-streaming sample data required by the event and any referenced events.
15 ///
16 /// Sample data is loaded asynchronously, [`EventDescription::get_sample_loading_state`] may be used to poll the loading state.
17 pub fn load_sample_data(&self) -> Result<()> {
18 unsafe { FMOD_Studio_EventDescription_LoadSampleData(self.inner).to_result() }
19 }
20
21 /// Unloads all non-streaming sample data.
22 ///
23 /// Sample data will not be unloaded until all instances of the event are released.
24 pub fn unload_sample_data(&self) -> Result<()> {
25 unsafe { FMOD_Studio_EventDescription_UnloadSampleData(self.inner).to_result() }
26 }
27
28 /// Retrieves the sample data loading state.
29 ///
30 /// If the event is invalid, then the returned state is [`LoadingState::Unloaded`] and this function returns [`FMOD_RESULT::FMOD_ERR_INVALID_HANDLE`].
31 pub fn get_sample_loading_state(&self) -> Result<LoadingState> {
32 let mut loading_state = 0;
33
34 let error = unsafe {
35 FMOD_Studio_EventDescription_GetSampleLoadingState(self.inner, &mut loading_state)
36 .to_error()
37 };
38
39 LoadingState::try_from_ffi(loading_state, error)
40 }
41}