fmod/core/channel_control/mod.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::*;
8
9mod callback;
10mod dsp;
11mod filtering;
12mod general;
13mod panning;
14mod playback;
15mod scheduling;
16mod spatialization;
17mod volume;
18pub use callback::{ChannelControlCallback, ChannelControlType};
19
20// 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`.
21// The C++ API provides a base class `ChannelControl` that `Channel` and `ChannelGroup` inherits from.
22// 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.
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24#[repr(transparent)] // so we can transmute between types
25pub struct ChannelControl {
26 pub(crate) inner: *mut FMOD_CHANNELCONTROL,
27 // FIXME: if the above assumption is invalid, could we possibly add a bool to track if this is a Channel or ChannelGroup?
28 // there's no real way to get a ChannelControl from FMOD's C API, this is a pure rust construct specific to this api,
29 // so it would be feasible
30}
31
32unsafe impl Send for ChannelControl {}
33unsafe impl Sync for ChannelControl {}
34
35impl From<*mut FMOD_CHANNELCONTROL> for ChannelControl {
36 fn from(value: *mut FMOD_CHANNELCONTROL) -> Self {
37 ChannelControl {
38 inner: value.cast(),
39 }
40 }
41}
42
43impl From<ChannelControl> for *mut FMOD_CHANNELCONTROL {
44 fn from(value: ChannelControl) -> Self {
45 value.inner.cast()
46 }
47}