2019-07-02 04:10:55 +00:00
|
|
|
pub mod base;
|
|
|
|
use base::{Genre, Jukebox};
|
2019-05-11 20:39:46 +00:00
|
|
|
|
|
|
|
pub struct AudioFrontend {
|
2019-07-02 04:10:55 +00:00
|
|
|
pub(crate) model: Jukebox,
|
2019-05-11 20:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AudioFrontend {
|
2019-07-02 04:10:55 +00:00
|
|
|
pub(crate) fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
model: Jukebox::new(Genre::Bgm),
|
2019-06-28 17:05:20 +00:00
|
|
|
}
|
2019-05-18 19:28:12 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 04:10:55 +00:00
|
|
|
/// Play audio.
|
|
|
|
pub(crate) fn play(&mut self) {
|
|
|
|
let path = base::select_random_music(&Genre::Bgm);
|
2019-06-28 17:05:20 +00:00
|
|
|
|
2019-07-02 04:10:55 +00:00
|
|
|
match self.model.player.is_paused() {
|
|
|
|
true => match self.model.get_genre() {
|
|
|
|
Genre::Bgm => self.model.player.resume(),
|
|
|
|
Genre::Sfx => unimplemented!(), // TODO: add support for sound effects.
|
|
|
|
Genre::None => (),
|
|
|
|
},
|
|
|
|
false => self.model.player.load(&path),
|
2019-05-18 19:28:12 +00:00
|
|
|
}
|
2019-05-11 20:39:46 +00:00
|
|
|
}
|
2019-05-19 19:31:32 +00:00
|
|
|
|
2019-07-02 04:10:55 +00:00
|
|
|
/// Construct in `no-audio` mode for debugging.
|
|
|
|
pub(crate) fn no_audio() -> Self {
|
|
|
|
Self {
|
|
|
|
model: Jukebox::new(Genre::None),
|
2019-05-20 16:54:54 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-11 20:39:46 +00:00
|
|
|
}
|