fmod/studio/bank/
mod.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 std::ptr::NonNull;
8
9use fmod_sys::*;
10
11mod general;
12mod loading;
13mod lookups; // general lookups that are too small to be their own module
14
15/// Banks made in FMOD Studio contain the metadata and audio sample data required for runtime mixing and playback.
16///
17/// Audio sample data may be packed into the same bank as the event metadata which references it, or it may be packed into separate banks.
18#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
19#[repr(transparent)] // so we can transmute between types
20pub struct Bank {
21    pub(crate) inner: NonNull<FMOD_STUDIO_BANK>,
22}
23
24#[cfg(not(feature = "thread-unsafe"))]
25unsafe impl Send for Bank {}
26#[cfg(not(feature = "thread-unsafe"))]
27unsafe impl Sync for Bank {}
28
29impl Bank {
30    /// # Safety
31    ///
32    /// `value` must be a valid pointer either aquired from [`Self::as_ptr`] or FMOD.
33    ///
34    /// # Panics
35    ///
36    /// Panics if `value` is null.
37    pub unsafe fn from_ffi(value: *mut FMOD_STUDIO_BANK) -> Self {
38        let inner = NonNull::new(value).unwrap();
39        Bank { inner }
40    }
41
42    /// Converts `self` into its raw representation.
43    pub fn as_ptr(self) -> *mut FMOD_STUDIO_BANK {
44        self.inner.as_ptr()
45    }
46}
47
48impl From<Bank> for *mut FMOD_STUDIO_BANK {
49    fn from(value: Bank) -> Self {
50        value.inner.as_ptr()
51    }
52}