fmod/core/channel_group/
group_management.rs

1// Copyright (c) 2024 Lily 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 std::ffi::c_int;
9
10use crate::{ChannelGroup, DspConnection};
11
12impl ChannelGroup {
13    /// Adds a [`ChannelGroup`] as an input to this group.
14    pub fn add_group(
15        &self,
16        group: ChannelGroup,
17        propgate_dsp_clock: bool,
18    ) -> Result<DspConnection> {
19        let mut dsp_connection = std::ptr::null_mut();
20        unsafe {
21            FMOD_ChannelGroup_AddGroup(
22                self.inner,
23                group.inner,
24                propgate_dsp_clock.into(),
25                &mut dsp_connection,
26            )
27            .to_result()?;
28        };
29        Ok(dsp_connection.into())
30    }
31
32    /// Retrieves the number of [`ChannelGroup`]s that feed into to this group.
33    pub fn get_group_count(&self) -> Result<c_int> {
34        let mut count = 0;
35        unsafe { FMOD_ChannelGroup_GetNumGroups(self.inner, &mut count).to_result()? }
36        Ok(count)
37    }
38
39    /// Retrieves the [`ChannelGroup`] at the specified index in the list of group inputs.
40    pub fn get_group(&self, index: c_int) -> Result<ChannelGroup> {
41        let mut group = std::ptr::null_mut();
42        unsafe { FMOD_ChannelGroup_GetGroup(self.inner, index, &mut group).to_result()? }
43        Ok(group.into())
44    }
45
46    /// Retrieves the [`ChannelGroup`] this object outputs to.
47    pub fn get_parent_group(&self) -> Result<ChannelGroup> {
48        let mut channel_group = std::ptr::null_mut();
49        unsafe {
50            FMOD_ChannelGroup_GetParentGroup(self.inner, &mut channel_group).to_result()?;
51        }
52        // FIXME: what if this is null? if it can be, what about other places we return pointers like this?
53        // do we even need to worry about this issue? we aren't returning references...
54        Ok(channel_group.into())
55    }
56}