use fmod_sys::*;
use std::{ops::Deref, ptr::NonNull};
use crate::ChannelControl;
mod information;
mod playback_control;
#[cfg(doc)]
use crate::{ChannelGroup, System};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(transparent)] pub struct Channel {
pub(crate) inner: NonNull<FMOD_CHANNEL>,
}
#[cfg(not(feature = "thread-unsafe"))]
unsafe impl Send for Channel {}
#[cfg(not(feature = "thread-unsafe"))]
unsafe impl Sync for Channel {}
impl Channel {
pub unsafe fn from_ffi(value: *mut FMOD_CHANNEL) -> Self {
let inner = NonNull::new(value).unwrap();
Channel { inner }
}
pub fn as_ptr(self) -> *mut FMOD_CHANNEL {
self.inner.as_ptr()
}
}
impl From<Channel> for *mut FMOD_CHANNEL {
fn from(value: Channel) -> Self {
value.inner.as_ptr()
}
}
impl Deref for Channel {
type Target = ChannelControl;
fn deref(&self) -> &Self::Target {
#[cfg(debug_assertions)]
unsafe {
let control = FMOD_Channel_CastToControl(self.inner.as_ptr());
assert_eq!(
control as usize,
self.inner.as_ptr() as usize,
"ChannelControl cast was not equivalent! THIS IS A MAJOR BUG. PLEASE REPORT THIS!"
);
}
unsafe { &*std::ptr::from_ref(self).cast::<ChannelControl>() }
}
}