fmod/core/channel/information.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::{Channel, Sound};
11
12impl Channel {
13 /// Retrieves whether the Channel is being emulated by the virtual voice system.
14 ///
15 /// See the Virtual Voices guide for more information.
16 pub fn is_virtual(&self) -> Result<bool> {
17 let mut is_virtual = FMOD_BOOL::FALSE;
18 unsafe {
19 FMOD_Channel_IsVirtual(self.inner, &mut is_virtual).to_result()?;
20 }
21 Ok(is_virtual.into())
22 }
23
24 /// Retrieves the currently playing [`Sound`].
25 ///
26 /// May return [`None`] if no [`Sound`] is playing.
27 pub fn get_current_sound(&self) -> Result<Option<Sound>> {
28 let mut sound = std::ptr::null_mut();
29 unsafe {
30 FMOD_Channel_GetCurrentSound(self.inner, &mut sound).to_result()?;
31 }
32 Ok(if sound.is_null() {
33 None
34 } else {
35 Some(Sound { inner: sound })
36 })
37 }
38
39 /// Retrieves the index of this object in the System Channel pool.
40 pub fn get_index(&self) -> Result<c_int> {
41 let mut index = 0;
42 unsafe {
43 FMOD_Channel_GetIndex(self.inner, &mut index).to_result()?;
44 }
45 Ok(index)
46 }
47}