Skip to main content

euv_engine/audio/
struct.rs

1use super::*;
2
3/// A wrapper around the Web Audio API `AudioContext` providing
4/// game engine audio playback and volume management.
5#[derive(Clone, Data, New)]
6pub struct GameAudioContext {
7    /// The underlying Web Audio API context.
8    #[set(pub(crate))]
9    pub(crate) context: AudioContext,
10    /// The master gain node controlling overall volume.
11    #[set(pub(crate))]
12    pub(crate) master_gain: GainNode,
13    /// The master volume level in the range 0.0 to 1.0.
14    #[get(type(copy))]
15    pub(crate) master_volume: f64,
16}
17
18/// An audio clip wrapping a decoded `AudioBuffer` with playback control.
19#[derive(Clone, Data, New)]
20pub struct AudioClip {
21    /// The decoded audio data buffer.
22    #[set(pub(crate))]
23    pub(crate) buffer: AudioBuffer,
24    /// The name identifying this clip.
25    #[set(pub(crate))]
26    pub(crate) name: String,
27    /// The current playback state.
28    #[get(type(copy))]
29    #[get_mut(pub(crate))]
30    pub(crate) state: AudioPlayState,
31    /// Whether the clip should loop when it reaches the end.
32    #[get(type(copy))]
33    #[get_mut(pub(crate))]
34    pub(crate) looping: bool,
35    /// The volume level in the range 0.0 to 1.0.
36    #[get(type(copy))]
37    #[get_mut(pub(crate))]
38    pub(crate) volume: f64,
39    /// The playback rate multiplier (1.0 = normal speed).
40    #[get(type(copy))]
41    #[get_mut(pub(crate))]
42    pub(crate) playback_rate: f64,
43    /// The currently active source node, if the clip is playing.
44    #[get_mut(pub(crate))]
45    #[set(pub(crate))]
46    #[new(skip)]
47    pub(crate) source_node: Option<AudioBufferSourceNode>,
48}