fmod/core/dsp_connection/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 std::ffi::c_void;
8
9use fmod_sys::*;
10
11use crate::{Dsp, DspConnection, DspConnectionType};
12use crate::{FmodResultExt, Result};
13
14impl DspConnection {
15 /// Retrieves the connection's input [`Dsp`] unit.
16 ///
17 /// If [`Dsp::add_input`] was just called, the connection might not be ready because the [`Dsp`] system is still queued to be connected,
18 /// and may need to wait several milliseconds for the next mix to occur.
19 /// If so the function will return [`FMOD_RESULT::FMOD_ERR_NOTREADY`].
20 pub fn get_input(&self) -> Result<Dsp> {
21 let mut dsp = std::ptr::null_mut();
22 unsafe {
23 FMOD_DSPConnection_GetInput(self.inner.as_ptr(), &raw mut dsp).to_result()?;
24 Ok(Dsp::from_ffi(dsp))
25 }
26 }
27
28 /// Retrieves the connection's output DSP unit.
29 ///
30 /// If [`Dsp::add_input`] was just called, the connection might not be ready because the [`Dsp`] system is still queued to be connected,
31 /// and may need to wait several milliseconds for the next mix to occur.
32 /// If so the function will return [`FMOD_RESULT::FMOD_ERR_NOTREADY`].
33 pub fn get_output(&self) -> Result<Dsp> {
34 let mut dsp = std::ptr::null_mut();
35 unsafe {
36 FMOD_DSPConnection_GetOutput(self.inner.as_ptr(), &raw mut dsp).to_result()?;
37 Ok(Dsp::from_ffi(dsp))
38 }
39 }
40
41 /// Retrieves the type of the connection between 2 DSP units.
42 pub fn get_type(&self) -> Result<DspConnectionType> {
43 let mut connection_type = 0;
44 unsafe {
45 FMOD_DSPConnection_GetType(self.inner.as_ptr(), &raw mut connection_type)
46 .to_result()?;
47 };
48 let connection_type = connection_type.try_into()?;
49 Ok(connection_type)
50 }
51
52 /// Sets the user data.
53 #[allow(clippy::not_unsafe_ptr_arg_deref)] // fmod doesn't dereference the passed in pointer, and the user dereferencing it is unsafe anyway
54 pub fn set_userdata(&self, userdata: *mut c_void) -> Result<()> {
55 unsafe { FMOD_DSPConnection_SetUserData(self.inner.as_ptr(), userdata).to_result() }
56 }
57
58 /// Retrieves user data.
59 pub fn get_userdata(&self) -> Result<*mut c_void> {
60 let mut userdata = std::ptr::null_mut();
61 unsafe {
62 FMOD_DSPConnection_GetUserData(self.inner.as_ptr(), &raw mut userdata).to_result()?;
63 }
64 Ok(userdata)
65 }
66}