Skip to main content

euv_engine/audio/
struct.rs

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