fmod/studio/system/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::{Utf8CStr, Utf8CString};
9use std::mem::MaybeUninit;
10
11use crate::Guid;
12use crate::studio::{System, get_string_out_size};
13use crate::{FmodResultExt, Result};
14
15impl System {
16 /// Retrieves the Core System.
17 pub fn get_core_system(&self) -> Result<crate::core::System> {
18 let mut system = std::ptr::null_mut();
19 unsafe {
20 FMOD_Studio_System_GetCoreSystem(self.inner.as_ptr(), &raw mut system).to_result()?;
21 Ok(crate::core::System::from_ffi(system))
22 }
23 }
24
25 /// Retrieves the ID for a bank, event, snapshot, bus or VCA.
26 ///
27 /// The strings bank must be loaded prior to calling this function, otherwise [`FMOD_RESULT::FMOD_ERR_EVENT_NOTFOUND`] is returned.
28 ///
29 /// The path can be copied to the system clipboard from FMOD Studio using the "Copy Path" context menu command.
30 pub fn lookup_id(&self, path: &Utf8CStr) -> Result<Guid> {
31 let mut guid = MaybeUninit::zeroed();
32 unsafe {
33 FMOD_Studio_System_LookupID(self.inner.as_ptr(), path.as_ptr(), guid.as_mut_ptr())
34 .to_result()?;
35
36 let guid = guid.assume_init().into();
37 Ok(guid)
38 }
39 }
40
41 /// Retrieves the path for a bank, event, snapshot, bus or VCA.
42 ///
43 /// The strings bank must be loaded prior to calling this function, otherwise [`FMOD_RESULT::FMOD_ERR_EVENT_NOTFOUND`] is returned.
44 pub fn lookup_path(&self, id: Guid) -> Result<Utf8CString> {
45 get_string_out_size(|path, size, ret| unsafe {
46 FMOD_Studio_System_LookupPath(self.inner.as_ptr(), &id.into(), path, size, ret)
47 })
48 }
49
50 /// Checks that the [`System`] reference is valid and has been initialized.
51 pub fn is_valid(&self) -> bool {
52 unsafe { FMOD_Studio_System_IsValid(self.inner.as_ptr()).into() }
53 }
54}