rscenes_raylib_connector/ext/
music.rs

1use crate::raudio::RaudioImpl;
2use raylib_ffi::*;
3use std::fmt::Display;
4
5pub trait MusicExt: Sized {
6    /// Load music stream from file
7    fn load(filename: impl Display) -> Result<Self, String>;
8    /// Load music stream from data
9    fn load_from_memory(tpe: impl Display, data: &[u8]) -> Result<Self, String>;
10
11    /// Check whether a music stream is ready
12    fn is_ready(self) -> bool;
13    /// Unload music stream
14    fn unload(self);
15    /// Start music playing
16    fn play(self);
17    /// Check whether music is playing
18    fn is_playing(self) -> bool;
19    /// Updates buffers for music streaming
20    fn update(self);
21    /// Stop music playing
22    fn stop(self);
23    /// Pause music playing
24    fn pause(self);
25    /// Resume playing paused music
26    fn resume(self);
27    /// Seek music to a position (in seconds)
28    fn seek(self, position: f32);
29    /// Set volume for music (1.0 is max level)
30    fn set_volume(self, volume: f32);
31    /// Set pitch for a music (1.0 is base level)
32    fn set_pitch(self, pitch: f32);
33    /// Set pan for a music (0.5 is center)
34    fn set_pan(self, pan: f32);
35    /// Get music time length (in seconds)
36    fn get_time_length(self) -> f32;
37    /// Get current music time played (in seconds)
38    fn get_time_played(self) -> f32;
39}
40
41impl MusicExt for Music {
42    fn load(filename: impl Display) -> Result<Self, String> {
43        RaudioImpl::__load_music_stream(filename)
44    }
45
46    fn load_from_memory(tpe: impl Display, data: &[u8]) -> Result<Self, String> {
47        RaudioImpl::__load_music_stream_from_memory(tpe, data)
48    }
49
50    fn is_ready(self) -> bool {
51        RaudioImpl::__is_music_ready(self)
52    }
53
54    fn unload(self) {
55        RaudioImpl::__unload_music_stream(self)
56    }
57
58    fn play(self) {
59        RaudioImpl::__play_music_stream(self)
60    }
61
62    fn is_playing(self) -> bool {
63        RaudioImpl::__is_music_stream_playing(self)
64    }
65
66    fn update(self) {
67        RaudioImpl::__update_music_stream(self)
68    }
69
70    fn stop(self) {
71        RaudioImpl::__stop_music_stream(self)
72    }
73
74    fn pause(self) {
75        RaudioImpl::__pause_music_stream(self)
76    }
77
78    fn resume(self) {
79        RaudioImpl::__resume_music_stream(self)
80    }
81
82    fn seek(self, position: f32) {
83        RaudioImpl::__seek_music_stream(self, position)
84    }
85
86    fn set_volume(self, volume: f32) {
87        RaudioImpl::__set_music_volume(self, volume)
88    }
89
90    fn set_pitch(self, pitch: f32) {
91        RaudioImpl::__set_music_pitch(self, pitch)
92    }
93
94    fn set_pan(self, pan: f32) {
95        RaudioImpl::__set_music_pan(self, pan)
96    }
97
98    fn get_time_length(self) -> f32 {
99        RaudioImpl::__get_music_time_length(self)
100    }
101
102    fn get_time_played(self) -> f32 {
103        RaudioImpl::__get_music_time_played(self)
104    }
105}