fmod/core/sound_group/
sound.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::{Sound, SoundGroup};
11
12impl SoundGroup {
13    /// Retrieves the current number of sounds in this sound group.
14    pub fn get_sound_count(&self) -> Result<c_int> {
15        let mut count = 0;
16        unsafe { FMOD_SoundGroup_GetNumSounds(self.inner, &mut count).to_result()? };
17        Ok(count)
18    }
19
20    /// Retrieves a sound.
21    ///
22    /// Use [`SoundGroup::get_sound_count`] in conjunction with this function to enumerate all sounds in a [`SoundGroup`].
23    pub fn get_sound(&self, index: c_int) -> Result<Sound> {
24        let mut sound = std::ptr::null_mut();
25        unsafe { FMOD_SoundGroup_GetSound(self.inner, index, &mut sound).to_result()? };
26        Ok(sound.into())
27    }
28
29    /// Retrieves the number of currently playing [`Channel`]s for the [`SoundGroup`].
30    ///
31    /// This routine returns the number of [`Channel`]s playing.
32    /// If the [`SoundGroup`] only has one [`Sound`], and that [`Sound`] is playing twice, the figure returned will be two.
33    pub fn get_playing_count(&self) -> Result<c_int> {
34        let mut count = 0;
35        unsafe { FMOD_SoundGroup_GetNumPlaying(self.inner, &mut count).to_result()? };
36        Ok(count)
37    }
38
39    /// Stops all sounds within this soundgroup.
40    pub fn stop(&self) -> Result<()> {
41        unsafe { FMOD_SoundGroup_Stop(self.inner).to_result() }
42    }
43}