fmod/studio/event_description/
sample_data.rs

1// Copyright (c) 2024 Melody Madeline 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};
10use crate::{FmodResultExt, Result};
11
12impl EventDescription {
13    /// Loads non-streaming sample data used by the event.
14    ///
15    /// This function will load all non-streaming sample data required by the event and any referenced events.
16    ///
17    /// Sample data is loaded asynchronously, [`EventDescription::get_sample_loading_state`] may be used to poll the loading state.
18    pub fn load_sample_data(&self) -> Result<()> {
19        unsafe { FMOD_Studio_EventDescription_LoadSampleData(self.inner.as_ptr()).to_result() }
20    }
21
22    /// Unloads all non-streaming sample data.
23    ///
24    /// Sample data will not be unloaded until all instances of the event are released.
25    pub fn unload_sample_data(&self) -> Result<()> {
26        unsafe { FMOD_Studio_EventDescription_UnloadSampleData(self.inner.as_ptr()).to_result() }
27    }
28
29    /// Retrieves the sample data loading state.
30    ///
31    /// If the event is invalid, then the returned state is [`LoadingState::Unloaded`] and this function returns [`FMOD_RESULT::FMOD_ERR_INVALID_HANDLE`].
32    pub fn get_sample_loading_state(&self) -> Result<LoadingState> {
33        let mut loading_state = 0;
34
35        let error = unsafe {
36            FMOD_Studio_EventDescription_GetSampleLoadingState(
37                self.inner.as_ptr(),
38                &raw mut loading_state,
39            )
40            .to_error()
41        };
42
43        LoadingState::try_from_ffi(loading_state, error)
44    }
45}