woelper 4 tahun lalu
induk
melakukan
22369ed774
4 mengubah file dengan 292 tambahan dan 13 penghapusan
  1. 232 0
      patterns/amen1.pat
  2. 9 4
      sampler.ini
  3. 24 2
      src/base.rs
  4. 27 7
      src/main.rs

+ 232 - 0
patterns/amen1.pat

@@ -0,0 +1,232 @@
+{
+  "name": "amen1",
+  "repeat": 2,
+  "bpm": 624,
+  "sounds": [
+    [
+      {
+        "name": "kick_rough.wav",
+        "location": "media\\cc0\\kick_rough.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      {
+        "name": "kick_rough.wav",
+        "location": "media\\cc0\\kick_rough.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      null,
+      null,
+      null,
+      null,
+      null,
+      null,
+      {
+        "name": "kick_rough.wav",
+        "location": "media\\cc0\\kick_rough.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      {
+        "name": "kick_rough.wav",
+        "location": "media\\cc0\\kick_rough.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      null,
+      null,
+      null
+    ],
+    [
+      null,
+      null,
+      null,
+      null,
+      {
+        "name": "snare_jungle.wav",
+        "location": "media\\cc0\\snare_jungle.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      null,
+      {
+        "name": "snare_jungle.wav",
+        "location": "media\\cc0\\snare_jungle.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      {
+        "name": "snare_jungle.wav",
+        "location": "media\\cc0\\snare_jungle.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      null,
+      {
+        "name": "snare_jungle.wav",
+        "location": "media\\cc0\\snare_jungle.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      null,
+      {
+        "name": "snare_jungle.wav",
+        "location": "media\\cc0\\snare_jungle.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      }
+    ],
+    [
+      {
+        "name": "ride_bell.wav",
+        "location": "media\\cc0\\ride_bell.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      {
+        "name": "ride_bell.wav",
+        "location": "media\\cc0\\ride_bell.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      {
+        "name": "ride_bell.wav",
+        "location": "media\\cc0\\ride_bell.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      {
+        "name": "ride_bell.wav",
+        "location": "media\\cc0\\ride_bell.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      {
+        "name": "ride_bell.wav",
+        "location": "media\\cc0\\ride_bell.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      null,
+      null,
+      {
+        "name": "ride_bell.wav",
+        "location": "media\\cc0\\ride_bell.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      {
+        "name": "ride_bell.wav",
+        "location": "media\\cc0\\ride_bell.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null
+    ],
+    [
+      null,
+      null,
+      null,
+      null,
+      null,
+      null,
+      null,
+      null,
+      null,
+      null,
+      {
+        "name": "hihiat_real.wav",
+        "location": "media\\cc0\\hihiat_real.wav",
+        "volume": 1.0,
+        "roll": 0,
+        "rollrate": 0,
+        "trim": 0.0,
+        "active": true,
+        "speed": 1.0
+      },
+      null,
+      null,
+      null,
+      null,
+      null
+    ]
+  ]
+}

+ 9 - 4
sampler.ini

@@ -9,8 +9,8 @@ Size=300,100
 Collapsed=0
 
 [Window][sources]
-Pos=749,45
-Size=246,549
+Pos=820,203
+Size=329,498
 Collapsed=0
 
 [Window][ImGui Demo]
@@ -39,7 +39,12 @@ Size=300,100
 Collapsed=0
 
 [Window][pattern]
-Pos=70,211
-Size=541,218
+Pos=28,192
+Size=707,222
+Collapsed=0
+
+[Window][patterns]
+Pos=915,12
+Size=324,186
 Collapsed=0
 

+ 24 - 2
src/base.rs

@@ -53,11 +53,15 @@ impl Sound {
     }
 
     pub fn reload(mut self) {
-        if let Ok(s) = Sound::new(&self.name) {
+        if let Ok(s) = Sound::new(&self.location.to_string_lossy()) {
             self.data = s.data;
         }
     }
 
+    pub fn reload_data(&self) -> Result<Sound, std::io::Error>{
+        Sound::new(&self.location.to_string_lossy())
+    }
+
     pub fn cursor(self: &Self) -> Cursor<Sound> {
         Cursor::new(
             Sound {
@@ -96,7 +100,7 @@ impl Default for Pattern {
             name: "Unnamed".to_string(),
             repeat: 0,
             bpm: 120,
-            sounds: vec![vec![None; 4]]
+            sounds: vec![vec![None; 8]]
         }
     }
 }
@@ -115,6 +119,9 @@ impl Pattern {
             }
         }
     }
+
+
+
     pub fn play(&mut self, device: &rodio::Device) {
         let delay = ((60.0 / self.bpm as f32)*1000.0) as u64;
         for _ in 0..self.repeat+1 {
@@ -137,11 +144,26 @@ impl Pattern {
             Ok(f) => {
                 serde_json::from_reader(BufReader::new(f))
                     .map_err(|e| e.to_string())
+                    .map(|p: Pattern| p.reload_sounds( ))
             }
             Err(e) => Err(e.to_string())
         }
     }
 
+    pub fn reload_sounds(&self) -> Pattern {
+        let mut newp = self.clone();
+        for row in &mut newp.sounds {
+            for col in row {
+                if let Some(snd) = col {
+                    dbg!(&snd);
+                    let s = snd.reload_data().unwrap();
+                    snd.data = s.data.clone();
+                }
+            }
+        }
+        newp.clone()
+    }
+
     pub fn save(&self) {
         let pattern_dir = Path::new("patterns");
 

+ 27 - 7
src/main.rs

@@ -40,6 +40,7 @@ fn main() {
     let dev = rodio::default_output_device().unwrap();
     
     let mut sounds = collect_sounds("media");
+    let mut patterns = collect_patterns("patterns");
     
     let mut timeline = Timeline::default();
 
@@ -53,8 +54,6 @@ fn main() {
     // let mut active_bar = &mut timeline.patterns[0].bars[0];
     let mut active_pattern = Pattern::default();
     let mut active_sound: Option<Sound> = None;
-    let mut active_pattern_name = ImString::new("dsd");
-    // let mut active_pattern = &mut timeline.patterns[0];
 
 
     let mut system = support_ogl::init(file!());
@@ -63,6 +62,9 @@ fn main() {
     // let system = support_glium::init(file!());
 
     system.main_loop(move |_, ui| {
+
+
+
         Window::new(im_str!("sources"))
             // .resizable(false)
             .position([400.0, 140.0], Condition::Appearing)
@@ -94,7 +96,29 @@ fn main() {
                 });
             });
 
-
+        Window::new(im_str!("patterns"))
+            // .resizable(false)
+            .position([400.0, 140.0], Condition::Appearing)
+            .collapsible(true)
+            .size([300.0, 300.0], Condition::FirstUseEver)
+            .build(ui, || {
+                ui.tree_node(im_str!("patterns"))
+                .opened(true, Condition::Appearing)
+                .build(|| {
+                    for p in &mut patterns {
+                        ui.tree_node(&im_str!("{}", p.name)).build(|| {
+                            // ui.same_line(0.0);
+                            if ui.small_button(im_str!("load")) {
+                                active_pattern = p.clone();
+                            }
+                            ui.same_line(0.0);
+                            if ui.small_button(im_str!("play")) {
+                                p.play(&dev);
+                            }
+                        });
+                    }
+                });
+            });
 
         // PATTERN WINDOW ====================================
         Window::new(im_str!("pattern"))
@@ -114,7 +138,6 @@ fn main() {
                 //     dbg!(&active_pattern_name);
                 // }
 
-         
 
                 let mut imstr_name = ImString::from(active_pattern.name.clone());
                 if ui.input_text(&im_str!("yo"), &mut imstr_name)
@@ -173,9 +196,6 @@ fn main() {
                             active_pattern.sounds[row_idx][snd_idx] = active_sound.clone();
                         }
                     }
-
-
-
                 }
 
                 ui.text(im_str!("pat {} {}", pattern_col, pattern_row));