fmod/core/channel_group/
general.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 lanyard::Utf8CString;
9use std::ffi::c_int;
10
11use crate::{get_string, ChannelGroup};
12
13impl ChannelGroup {
14    /// Retrieves the name set when the group was created.
15    pub fn get_name(&self) -> Result<Utf8CString> {
16        unsafe {
17            get_string(|name| {
18                FMOD_ChannelGroup_GetName(self.inner, name.as_mut_ptr().cast(), name.len() as c_int)
19            })
20        }
21    }
22
23    /// Frees the memory for the group.
24    ///
25    /// Any [`Channel`]s or [`ChannelGroup`]s feeding into this group are moved to the master [`ChannelGroup`].
26    pub fn release(&self) -> Result<()> {
27        // release userdata
28        #[cfg(feature = "userdata-abstraction")]
29        let userdata = self.get_raw_userdata()?;
30
31        unsafe {
32            FMOD_ChannelGroup_Release(self.inner).to_result()?;
33        }
34
35        // release/remove userdata if it is not null
36        #[cfg(feature = "userdata-abstraction")]
37        if !userdata.is_null() {
38            crate::userdata::remove_userdata(userdata.into());
39            self.set_raw_userdata(std::ptr::null_mut())?;
40        }
41
42        Ok(())
43    }
44}