rscenes_raylib_connector/ext/
sound.rs

1use crate::raudio::RaudioImpl;
2use raylib_ffi::*;
3use std::fmt::Display;
4
5pub trait SoundExt: Sized {
6    /// Load sound from file
7    fn load(filename: impl Display) -> Result<Self, String>;
8    /// Load sound from wave data
9    fn load_from_wave(wave: Wave) -> Self;
10
11    /// Create a new sound that shares the same sample data as the source sound, does not own the sound data
12    fn alias(self) -> Self;
13    /// Check whether a sound is ready
14    fn is_ready(self) -> bool;
15    /// Unload wave data
16    fn unload(self);
17    /// Unload a sound alias (does not deallocate sample data)
18    fn unload_alias(self);
19    /// Play a sound
20    fn play(self);
21    /// Stop playing a sound
22    fn stop(self);
23    /// Pause a sound
24    fn pause(self);
25    /// Resume a paused sound
26    fn resume(self);
27    /// Check whether a sound is currently playing
28    fn is_playing(self) -> bool;
29    /// Set volume for a sound (1.0 is max level)
30    fn set_volume(self, volume: f32);
31    /// Set pitch for a sound (1.0 is base level)
32    fn set_pitch(self, pitch: f32);
33    /// Set pan for a sound (0.5 is center)
34    fn set_pan(self, pan: f32);
35}
36
37impl SoundExt for Sound {
38    fn load(filename: impl Display) -> Result<Self, String> {
39        RaudioImpl::__load_sound(filename)
40    }
41
42    fn load_from_wave(wave: Wave) -> Self {
43        RaudioImpl::__load_sound_from_wave(wave)
44    }
45
46    fn alias(self) -> Self {
47        RaudioImpl::__load_sound_alias(self)
48    }
49
50    fn is_ready(self) -> bool {
51        RaudioImpl::__is_sound_ready(self)
52    }
53
54    fn unload(self) {
55        RaudioImpl::__unload_sound(self)
56    }
57
58    fn unload_alias(self) {
59        RaudioImpl::__unload_sound_alias(self)
60    }
61
62    fn play(self) {
63        RaudioImpl::__play_sound(self)
64    }
65
66    fn stop(self) {
67        RaudioImpl::__stop_sound(self)
68    }
69
70    fn pause(self) {
71        RaudioImpl::__pause_sound(self)
72    }
73
74    fn resume(self) {
75        RaudioImpl::__resume_sound(self)
76    }
77
78    fn is_playing(self) -> bool {
79        RaudioImpl::__is_sound_playing(self)
80    }
81
82    fn set_volume(self, volume: f32) {
83        RaudioImpl::__set_sound_volume(self, volume)
84    }
85
86    fn set_pitch(self, pitch: f32) {
87        RaudioImpl::__set_sound_pitch(self, pitch)
88    }
89
90    fn set_pan(self, pan: f32) {
91        RaudioImpl::__set_sound_pan(self, pan)
92    }
93}