fmod/studio/bank/
general.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::*;
8use lanyard::Utf8CString;
9use std::ffi::c_void;
10use std::mem::MaybeUninit;
11
12use crate::Guid;
13use crate::studio::{Bank, get_string_out_size};
14use crate::{FmodResultExt, Result};
15
16impl Bank {
17    /// Retrieves the GUID.
18    pub fn get_id(&self) -> Result<Guid> {
19        let mut guid = MaybeUninit::zeroed();
20        unsafe {
21            FMOD_Studio_Bank_GetID(self.inner.as_ptr(), guid.as_mut_ptr()).to_result()?;
22
23            let guid = guid.assume_init().into();
24
25            Ok(guid)
26        }
27    }
28
29    /// Retrieves the path.
30    pub fn get_path(&self) -> Result<Utf8CString> {
31        get_string_out_size(|path, size, ret| unsafe {
32            FMOD_Studio_Bank_GetPath(self.inner.as_ptr(), path, size, ret)
33        })
34    }
35
36    /// Checks that the Bank reference is valid.
37    pub fn is_valid(&self) -> bool {
38        unsafe { FMOD_Studio_Bank_IsValid(self.inner.as_ptr()).into() }
39    }
40
41    /// Sets the bank's user data.
42    ///
43    /// This function allows arbitrary user data to be attached to this object.
44    #[allow(clippy::not_unsafe_ptr_arg_deref)] // fmod doesn't dereference the passed in pointer, and the user dereferencing it is unsafe anyway
45    pub fn set_userdata(&self, userdata: *mut c_void) -> Result<()> {
46        unsafe { FMOD_Studio_Bank_SetUserData(self.inner.as_ptr(), userdata).to_result() }
47    }
48
49    /// Retrieves the bank's user data.
50    ///
51    /// This function allows arbitrary user data to be retrieved from this object.
52    pub fn get_userdata(&self) -> Result<*mut c_void> {
53        let mut userdata = std::ptr::null_mut();
54        unsafe {
55            FMOD_Studio_Bank_GetUserData(self.inner.as_ptr(), &raw mut userdata).to_result()?;
56        }
57        Ok(userdata)
58    }
59}