fmod/studio/
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 crate::{Error, FmodResultExt, Result};
8use fmod_sys::*;
9use std::{ffi::c_char, os::raw::c_int};
10
11mod structs;
12
13use lanyard::Utf8CString;
14pub use structs::*;
15
16mod flags;
17pub use flags::*;
18
19mod enums;
20pub use enums::*;
21
22mod bank;
23pub use bank::*;
24
25mod bus;
26pub use bus::*;
27
28mod system;
29pub use system::*;
30
31mod command_replay;
32pub use command_replay::*;
33
34mod event_description;
35pub use event_description::*;
36
37mod event_instance;
38pub use event_instance::*;
39
40mod vca;
41pub use vca::*;
42
43fn get_string_out_size(
44    mut get_fn: impl FnMut(*mut c_char, c_int, *mut c_int) -> fmod_sys::FMOD_RESULT,
45) -> Result<Utf8CString> {
46    let mut string_len = 0;
47
48    match get_fn(std::ptr::null_mut(), 0, &raw mut string_len).to_error() {
49        Some(Error::Truncated) => {}
50        Some(err) => return Err(err),
51        _ => {}
52    }
53
54    let mut buf = vec![0u8; string_len as usize];
55    let mut expected_string_len = 0;
56
57    get_fn(
58        buf.as_mut_ptr().cast(),
59        string_len,
60        &raw mut expected_string_len,
61    )
62    .to_result()?;
63
64    debug_assert_eq!(string_len, expected_string_len);
65
66    let string = Utf8CString::from_utf8_with_nul(buf).unwrap();
67    Ok(string)
68}
69
70/// The required memory alignment of banks in user memory.
71///
72/// When using [`System::load_bank_pointer`] you must align the past slice to this alignment.
73pub const LOAD_POINT_ALIGNMENT: usize = FMOD_STUDIO_LOAD_MEMORY_ALIGNMENT as _;