Make music optional.
authorBernie Innocenti <bernie@codewiz.org>
Sat, 8 Apr 2017 17:41:33 +0000 (13:41 -0400)
committerBernie Innocenti <bernie@codewiz.org>
Sat, 8 Apr 2017 17:41:33 +0000 (13:41 -0400)
Cargo.toml
main.rs
sound.rs

index cada4594ed04329d845ed9491960b1224c0ec65f..d529ef8be49ff1ee8a4aa176238eda73851ef407 100644 (file)
@@ -13,4 +13,4 @@ sdl2 = "*"
 
 [[bin]]
 name = "mandelwow"
-path = "mandelwow.rs"
+path = "main.rs"
diff --git a/main.rs b/main.rs
index dac8b37cb9f0f0dfb350d9293b762c44dd08a484..1b336887a10fbd99ece652cc71ffd12d72e84f35 100644 (file)
--- a/main.rs
+++ b/main.rs
@@ -95,7 +95,7 @@ fn bounding_box<U>(display: &glium::Display,
 }
 
 fn main() {
-    sound::start();
+    let _soundplayer = sound::start();
 
     let display = glium::glutin::WindowBuilder::new()
         //.with_dimensions(1024, 768)
index 4b946860d3221f115516022c1d41767a561534ab..d88850b1631d03640fc1d8abd7dc5f73f0ddad06 100644 (file)
--- a/sound.rs
+++ b/sound.rs
@@ -18,7 +18,7 @@ impl AudioCallback for XmCallback {
 }
 
 pub struct SoundPlayer {
-    _device: AudioDevice<XmCallback>,
+    _device: Option<AudioDevice<XmCallback>>,
 }
 
 fn play_xm(raw_xm: &[u8]) -> SoundPlayer {
@@ -42,14 +42,21 @@ fn play_xm(raw_xm: &[u8]) -> SoundPlayer {
     device.resume();
 
     SoundPlayer {
-        _device: device,
+        _device: Some(device),
     }
 }
 
 pub fn start() -> SoundPlayer {
-    let mut xm = Vec::new();
     let filename = "flora.xm";
-    File::open(filename).unwrap()
-        .read_to_end(&mut xm).unwrap();
-    return play_xm(&xm);
+    match File::open(filename) {
+        Result::Ok(mut f) => {
+            let mut xm = Vec::new();
+            f.read_to_end(&mut xm).unwrap();
+            return play_xm(&xm);
+        },
+        Result::Err(err) => {
+            println!("Couldn't open module {}: {:?}", filename, err);
+        },
+    }
+    return SoundPlayer { _device: None };
 }