woelper 4 tahun lalu
induk
melakukan
c42a906ce0
2 mengubah file dengan 18 tambahan dan 6 penghapusan
  1. 13 2
      src/base.rs
  2. 5 4
      src/main.rs

+ 13 - 2
src/base.rs

@@ -4,18 +4,29 @@ use std::thread;
 use std::time::Duration;
 use std::fs::File;
 
-#[derive(Clone)]
+#[derive(Clone, Default)]
 pub struct Sound {
     pub location: PathBuf,
+    data: Vec<u8>,
+    pub roll: i32,
+    pub rate: i32
 }
 
 impl Sound {
+    pub fn new(location: &str) -> Sound {
+        Sound {
+            location: PathBuf::from(location),
+            data: vec![],
+            roll: 0,
+            rate: 8
+        }
+    }
     pub fn play(&self, device: &rodio::Device) {
         if let Ok(file) = std::fs::File::open(&self.location) {
             // let dec = rodio::Decoder::new(BufReader::new(file)).unwrap();
             let reader = BufReader::new(file);
             let d = device.clone();
-            let sink = rodio::play_once(d, reader).unwrap().detach();
+            let _sink = rodio::play_once(d, reader).unwrap().detach();
 
         }
     }

+ 5 - 4
src/main.rs

@@ -12,11 +12,13 @@ fn main() {
 
     let dev = rodio::default_output_device().unwrap();
 
-    let hat = Sound{location: PathBuf::from("media/c64sid-ch1.wav")};
-    let snare = Sound{location: PathBuf::from("media/c64sid-snare12.wav")};
-    let kick = Sound{location: PathBuf::from("media/c64sid-kick5.wav")};
+    let hat = Sound::new("media/c64sid-ch1.wav");
+    let snare = Sound::new("media/c64sid-snare12.wav");
+    let kick = Sound::new("media/c64sid-kick5.wav");
 
     let mut bar = Bar::default();
+    
+    
     bar.repeat = 2;
     bar.sounds = vec!(
         kick.clone(),
@@ -31,5 +33,4 @@ fn main() {
 
     bar.play(&dev);
 
-
 }