fmod/studio/event_description/attributes.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 std::ffi::c_float;
8
9use fmod_sys::*;
10
11use crate::studio::EventDescription;
12
13impl EventDescription {
14 /// Retrieves the event's 3D status.
15 ///
16 /// An event is considered 3D if any of these conditions are met:
17 /// - The event has a Spatializer, 3D Object Spatializer, or a 3rd party spatializer on its master track.
18 /// - The event contains an automatic parameter that depends on the event's 3D attributes:
19 /// - Distance
20 /// - Event Cone Angle
21 /// - Event Orientation
22 /// - Direction
23 /// - Elevation
24 /// - Speed
25 /// - Speed (Absolute)
26 /// - The event contains any nested events which are 3D.
27 ///
28 /// Note: If the event contains nested events built to separate banks using versions of FMOD Studio prior to 2.00.10 and those banks have not been loaded then this function may fail to correctly determine the event's 3D status.
29 pub fn is_3d(&self) -> Result<bool> {
30 let mut is_3d = FMOD_BOOL::FALSE;
31 unsafe {
32 FMOD_Studio_EventDescription_Is3D(self.inner, &mut is_3d).to_result()?;
33 }
34 Ok(is_3d.into())
35 }
36
37 /// Retrieves the event's doppler status.
38 ///
39 /// Note: If the event was built to a bank using versions of FMOD Studio prior to 2.01.09, then this function will return false regardless of the event's doppler state.
40 pub fn is_doppler_enabled(&self) -> Result<bool> {
41 let mut is_doppler = FMOD_BOOL::FALSE;
42 unsafe {
43 FMOD_Studio_EventDescription_IsDopplerEnabled(self.inner, &mut is_doppler)
44 .to_result()?;
45 }
46 Ok(is_doppler.into())
47 }
48
49 /// Retrieves the event's oneshot status.
50 ///
51 /// An event is considered oneshot if it is guaranteed to terminate without intervention in bounded time after being started.
52 /// Instances of such events can be played in a fire-and-forget fashion by calling [`EventInstance::start`] immediately followed by [`EventInstance::release`].
53 ///
54 /// Note: If the event contains nested events built to separate banks and those banks have not been loaded then this function may fail to correctly determine the event's oneshot status.
55 pub fn is_oneshot(&self) -> Result<bool> {
56 let mut is_oneshot = FMOD_BOOL::FALSE;
57 unsafe {
58 FMOD_Studio_EventDescription_IsOneshot(self.inner, &mut is_oneshot).to_result()?;
59 }
60 Ok(is_oneshot.into())
61 }
62
63 /// Retrieves the event's snapshot status.
64 pub fn is_snapshot(&self) -> Result<bool> {
65 let mut is_snapshot = FMOD_BOOL::FALSE;
66 unsafe {
67 FMOD_Studio_EventDescription_IsSnapshot(self.inner, &mut is_snapshot).to_result()?;
68 }
69 Ok(is_snapshot.into())
70 }
71
72 /// Retrieves the event's stream status.
73 ///
74 /// Note: If the event contains nested events built to separate banks and those banks have not been loaded then this function may fail to correctly determine the event's stream status.
75 pub fn is_stream(&self) -> Result<bool> {
76 let mut is_stream = FMOD_BOOL::FALSE;
77 unsafe {
78 FMOD_Studio_EventDescription_IsStream(self.inner, &mut is_stream).to_result()?;
79 }
80 Ok(is_stream.into())
81 }
82
83 /// Retrieves whether the event has any sustain points.
84 pub fn has_sustain_point(&self) -> Result<bool> {
85 let mut sustain_point = FMOD_BOOL::FALSE;
86 unsafe {
87 FMOD_Studio_EventDescription_HasSustainPoint(self.inner, &mut sustain_point)
88 .to_result()?;
89 }
90 Ok(sustain_point.into())
91 }
92
93 /// Retrieves the minimum and maximum distances for 3D attenuation.
94 pub fn get_min_max_distance(&self) -> Result<(c_float, c_float)> {
95 let mut min = 0.0;
96 let mut max = 0.0;
97 unsafe {
98 FMOD_Studio_EventDescription_GetMinMaxDistance(self.inner, &mut min, &mut max)
99 .to_result()?;
100 }
101 Ok((min, max))
102 }
103
104 /// Retrieves the sound size for 3D panning.
105 ///
106 /// Retrieves the largest Sound Size value of all Spatializers and 3D Object Spatializers on the event's master track. Returns zero if there are no Spatializers or 3D Object Spatializers.
107 pub fn get_sound_size(&self) -> Result<c_float> {
108 let mut size = 0.0;
109 unsafe {
110 FMOD_Studio_EventDescription_GetSoundSize(self.inner, &mut size).to_result()?;
111 }
112 Ok(size)
113 }
114}