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