fmod/core/channel_control/mod.rs
1// Copyright (c) 2024 Melody Madeline 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 std::ptr::NonNull;
8
9use fmod_sys::*;
10
11mod callback;
12mod dsp;
13mod filtering;
14mod general;
15mod panning;
16mod playback;
17mod scheduling;
18mod spatialization;
19mod volume;
20pub use callback::{ChannelControlCallback, ChannelControlType};
21
22#[cfg(doc)]
23use crate::{Channel, ChannelGroup};
24
25/// An interface that represents the shared APIs between [`Channel`] and [`ChannelGroup`].
26// FMOD's C API provides two versions of functions for channels: one that takes a `*mut FMOD_CHANNEL` and one that takes a `*mut FMOD_CHANNELGROUP`.
27// The C++ API provides a base class `ChannelControl` that `Channel` and `ChannelGroup` inherits from.
28// Seeing as we can cast from FMOD_CHANNELCONTROL to Channel* (in c++) we should be able to cast from FMOD_CHANNEL(GROUP) to FMOD_CHANNELCONTROL.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30#[repr(transparent)] // so we can transmute between types
31pub struct ChannelControl {
32 pub(crate) inner: NonNull<FMOD_CHANNELCONTROL>,
33}
34
35#[cfg(not(feature = "thread-unsafe"))]
36unsafe impl Send for ChannelControl {}
37#[cfg(not(feature = "thread-unsafe"))]
38unsafe impl Sync for ChannelControl {}
39
40impl ChannelControl {
41 /// # Safety
42 ///
43 /// `value` must be a valid pointer either aquired from [`Self::as_ptr`] or FMOD.
44 ///
45 /// # Panics
46 ///
47 /// Panics if `value` is null.
48 pub unsafe fn from_ffi(value: *mut FMOD_CHANNELCONTROL) -> Self {
49 let inner = NonNull::new(value).unwrap();
50 ChannelControl { inner }
51 }
52
53 /// Converts `self` into its raw representation.
54 pub fn as_ptr(self) -> *mut FMOD_CHANNELCONTROL {
55 self.inner.as_ptr()
56 }
57}
58
59impl From<ChannelControl> for *mut FMOD_CHANNELCONTROL {
60 fn from(value: ChannelControl) -> Self {
61 value.inner.as_ptr()
62 }
63}