Просмотр исходного кода

Merge branch 'master' of schdbr.de:woelper/sampler

Johann Woelper 4 лет назад
Родитель
Сommit
2a594db107
4 измененных файлов с 396 добавлено и 15 удалено
  1. 339 0
      patterns/test w bass.pat
  2. 2 2
      sampler.ini
  3. 49 11
      src/base.rs
  4. 6 2
      src/main.rs

+ 339 - 0
patterns/test w bass.pat

@@ -0,0 +1,339 @@
+{
+  "name": "test w bass",
+  "repeat": 2,
+  "bpm": 396,
+  "xsize": 16,
+  "ysize": 6,
+  "sounds": {
+    "0,4": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "8,4": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.74,
+      "reverse": false
+    },
+    "3,5": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.63,
+      "reverse": false
+    },
+    "11,5": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.08,
+      "reverse": false
+    },
+    "10,2": {
+      "name": "hihiat_real.wav",
+      "location": "media\\cc0\\hihiat_real.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "5,5": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.63,
+      "reverse": false
+    },
+    "4,1": {
+      "name": "snare_deep.wav",
+      "location": "media\\cc0\\snare_deep.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "0,0": {
+      "name": "kick_rough.wav",
+      "location": "media\\cc0\\kick_rough.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "14,2": {
+      "name": "hihiat_real.wav",
+      "location": "media\\cc0\\hihiat_real.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "12,4": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.74,
+      "reverse": false
+    },
+    "1,5": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.63,
+      "reverse": false
+    },
+    "10,4": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.74,
+      "reverse": false
+    },
+    "10,0": {
+      "name": "kick_rough.wav",
+      "location": "media\\cc0\\kick_rough.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "8,2": {
+      "name": "hihiat_real.wav",
+      "location": "media\\cc0\\hihiat_real.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "9,5": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.63,
+      "reverse": false
+    },
+    "12,2": {
+      "name": "hihiat_real.wav",
+      "location": "media\\cc0\\hihiat_real.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "15,5": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.63,
+      "reverse": false
+    },
+    "2,2": {
+      "name": "hihiat_real.wav",
+      "location": "media\\cc0\\hihiat_real.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "11,0": {
+      "name": "kick_rough.wav",
+      "location": "media\\cc0\\kick_rough.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "13,4": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.74,
+      "reverse": false
+    },
+    "4,2": {
+      "name": "hihiat_real.wav",
+      "location": "media\\cc0\\hihiat_real.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "0,2": {
+      "name": "hihiat_real.wav",
+      "location": "media\\cc0\\hihiat_real.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "7,0": {
+      "name": "kick_rough.wav",
+      "location": "media\\cc0\\kick_rough.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "12,1": {
+      "name": "snare_deep.wav",
+      "location": "media\\cc0\\snare_deep.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "2,4": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "13,5": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.63,
+      "reverse": false
+    },
+    "4,4": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "7,5": {
+      "name": "bass_1.wav",
+      "location": "media/cc0/bass/bass_1.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 0.63,
+      "reverse": false
+    },
+    "1,0": {
+      "name": "kick_rough.wav",
+      "location": "media\\cc0\\kick_rough.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    },
+    "6,2": {
+      "name": "hihiat_real.wav",
+      "location": "media\\cc0\\hihiat_real.wav",
+      "volume": 1.0,
+      "roll": 0,
+      "rollrate": 0,
+      "trim": 0.0,
+      "active": false,
+      "speed": 1.0,
+      "reverse": false
+    }
+  }
+}

+ 2 - 2
sampler.ini

@@ -9,7 +9,7 @@ Size=300,100
 Collapsed=0
 
 [Window][sources]
-Pos=1200,59
+Pos=789,65
 Size=361,711
 Collapsed=0
 
@@ -29,7 +29,7 @@ Size=328,168
 Collapsed=0
 
 [Window][sound]
-Pos=43,383
+Pos=132,294
 Size=354,269
 Collapsed=0
 

+ 49 - 11
src/base.rs

@@ -166,6 +166,8 @@ pub struct Pattern {
     pub ysize: usize,
     #[serde(serialize_with="ser_snds", deserialize_with="de_snds")]
     pub sounds: HashMap<(usize, usize), Sound>,
+    #[serde(skip)]
+    pub progress: Option<(usize, usize)>
 }
 
 /// Some basic defaults for a pattern.
@@ -177,25 +179,48 @@ impl Default for Pattern {
             bpm: 120,
             xsize: 8,
             ysize: 1,
-            sounds: HashMap::new()
+            sounds: HashMap::new(),
+            progress: None
         }
     }
 }
 
 impl Pattern {
-    pub fn play(&self, device: &rodio::Device) {
+    pub fn play(&self, device: &Arc<rodio::Device>) {
+
+        let pat_clone = self.clone();
+
+        let device = device.clone();
         let delay = ((60.0 / self.bpm as f32)*1000.0) as u64;
-        // loop for repeats
-        for _ in 0..self.repeat + 1 {
-            for x in 0..self.xsize {
-                for y in 0..self.ysize {
-                    if let Some(s) = self.sounds.get(&(x, y)) {
-                        s.play(device);
+        
+        thread::spawn(move || {
+            
+            // loop for repeats
+            for _ in 0..pat_clone.repeat + 1 {
+                for x in 0..pat_clone.xsize {
+                    for y in 0..pat_clone.ysize {
+                        if let Some(s) = pat_clone.sounds.get(&(x, y)) {
+                            s.play(&device);
+                        }
                     }
+                    thread::sleep(Duration::from_millis(delay));
                 }
-                thread::sleep(Duration::from_millis(delay));
             }
-        }
+        });
+        
+
+
+        // for _ in 0..self.repeat + 1 {
+        //     for x in 0..self.xsize {
+        //         for y in 0..self.ysize {
+        //             if let Some(s) = self.sounds.get(&(x, y)) {
+        //                 s.play(device);
+        //             }
+        //         }
+        //         thread::sleep(Duration::from_millis(delay));
+        //     }
+        // }
+
     }
 
     /// Deserialize a pattern from a file.
@@ -212,7 +237,7 @@ impl Pattern {
 
     /// Replace all souds in a row by a new sound.
     /// This only replaces the source, leaving other settings intact.
-    pub fn replace_sounds(&mut self, new_sound: &Sound, row: usize) {
+    pub fn replace_sound_sources(&mut self, new_sound: &Sound, row: usize) {
         for x in 0..self.xsize {
             if let Some(snd) = self.sounds.get_mut(&(x, row)) {
                 snd.location = new_sound.location.clone();
@@ -222,6 +247,19 @@ impl Pattern {
         }
     }
 
+    /// Replace all souds in a row by a new sound.
+    /// This only replaces the source, leaving other settings intact.
+    pub fn replace_sounds(&mut self, new_sound: &Sound, row: usize) {
+        for x in 0..self.xsize {
+            if let Some(snd) = self.sounds.get_mut(&(x, row)) {
+                *snd = new_sound.clone();
+            }
+        
+        }
+    }
+
+
+
     /// Guess the name from the most commpn sound in a pattern.
     pub fn name_from_row(&self, row: usize) -> String {
         let mut names: HashMap<String, usize> = HashMap::new();

+ 6 - 2
src/main.rs

@@ -12,6 +12,7 @@ use walkdir::WalkDir;
 mod support_ogl;
 // mod support_glium;
 use env_logger;
+use std::sync::Arc;
 // use log::*;
 
 fn collect_sounds (root: &str) -> Vec<Sound> {
@@ -32,13 +33,15 @@ fn collect_patterns (root: &str) -> Vec<Pattern> {
     .map(|f| Pattern::load(f.path()))
     // .map(|p| dbg!(p))
     .filter_map(|e| e.ok())
+    // .map(|p| Arc::new(p))
     .collect()
 }
 
 fn main() {
 
     env_logger::init();
-    let dev = rodio::default_output_device().unwrap();
+    // let dev = rodio::default_output_device().unwrap();
+    let dev = Arc::new(rodio::default_output_device().unwrap());
     
     let mut sounds = collect_sounds("media");
     let mut patterns = collect_patterns("patterns");
@@ -49,6 +52,7 @@ fn main() {
     let mut pattern_row: usize = 0;
     
     let mut active_pattern = Pattern::default();
+    // let mut active_pattern = Arc::new(Pattern::default());
     let mut active_sound: Option<Sound> = None;
 
     let mut system = support_ogl::init(file!());
@@ -223,7 +227,7 @@ fn main() {
                     ui.same_line(0.0);
                     if ui.small_button(&im_str!("replace src##{}",y) ){
                         if let Some(acs) = &active_sound {
-                            active_pattern.replace_sounds(acs, y);
+                            active_pattern.replace_sound_sources(acs, y);
                         }
                     }
                     ui.same_line(0.0);