Przeglądaj źródła

rename to pattern

woelper 4 lat temu
rodzic
commit
64baa4c420
3 zmienionych plików z 54 dodań i 28 usunięć
  1. 7 2
      sampler.ini
  2. 16 6
      src/base.rs
  3. 31 20
      src/main.rs

+ 7 - 2
sampler.ini

@@ -9,7 +9,7 @@ Size=300,100
 Collapsed=0
 
 [Window][sources]
-Pos=401,140
+Pos=400,140
 Size=339,460
 Collapsed=0
 
@@ -24,7 +24,7 @@ Size=300,100
 Collapsed=0
 
 [Window][bar]
-Pos=24,248
+Pos=42,156
 Size=328,168
 Collapsed=0
 
@@ -33,3 +33,8 @@ Pos=21,42
 Size=300,100
 Collapsed=0
 
+[Window][tracks]
+Pos=56,432
+Size=300,100
+Collapsed=0
+

+ 16 - 6
src/base.rs

@@ -103,25 +103,35 @@ impl Bar {
 }
 
 #[derive(Clone, Debug)]
-pub struct Track {
+pub struct Pattern {
     pub bars: Vec<Bar>
 }
 
-impl Default for Track {
-    fn default() -> Track {
-        Track {bars: vec![Bar::default()]}
+impl Default for Pattern {
+    fn default() -> Pattern {
+        Pattern {bars: vec![Bar::default()]}
+    }
+
+}
+
+impl Pattern {
+    pub fn test(&mut self) {
+        self.bars[0].bpm = 10
+    }
+    pub fn bar_mut(&mut self, i: usize) -> &mut Bar {
+        &mut self.bars[i]
     }
 }
 
 #[derive(Clone, Debug)]
 pub struct Timeline {
-    pub tracks: Vec<Track>
+    pub tracks: Vec<Pattern>
 }
 
 impl Default for Timeline {
     fn default() -> Timeline {
         Timeline {
-            tracks: vec![Track::default()]
+            tracks: vec![Pattern::default()]
         }
     }
 }

+ 31 - 20
src/main.rs

@@ -23,17 +23,29 @@ fn collect_sounds (root: &str) -> Vec<Sound> {
 }
 fn main() {
     env_logger::init();
+    let dev = rodio::default_output_device().unwrap();
+    
     let mut sounds = collect_sounds("media");
-    let mut active_sound: usize = 0;
     
+    let mut timeline = Timeline::default();
+    // let mut track = Track::default();
+    // track.test();
+    // track.bar_mut(0).bpm = 1;
+    // track.bars[0].bpm = 1;
+    // let mut x = &mut track.bars[0];
+    // x.bpm = 1;
 
+    // dbg!(&track);
 
-    let dev = rodio::default_output_device().unwrap();
+    // return;
+    let mut active_sound: usize = 0;
+    let mut active_track: usize = 0;
+    // let mut active_bar: usize = 0;
 
-    let mut bar = Bar::default();
-    bar.bpm = 160;
 
-    let mut timeline = Timeline::default();
+    // let mut active_bar = Bar::default();
+    let mut active_bar = &mut timeline.tracks[0].bars[0];
+
 
     let mut system = support_ogl::init(file!());
     let s = system.imgui.style_mut();
@@ -58,7 +70,7 @@ fn main() {
                         ui.tree_node(&im_str!("{}", s.name)).build(|| {
                             // ui.same_line(0.0);
                             if ui.small_button(im_str!("add to bar")) {
-                                bar.sounds[active_sound] = Some(s.clone());
+                                active_bar.sounds[active_sound] = Some(s.clone());
                             }
                             ui.same_line(0.0);
                             if ui.small_button(im_str!("play")) {
@@ -72,51 +84,50 @@ fn main() {
         Window::new(im_str!("bar"))
             .size([300.0, 100.0], Condition::FirstUseEver)
             .build(ui, || {
-                ui.text(im_str!("bars"));
-                ui.same_line(0.0);
-                ui.text(im_str!("snd {}", active_sound));
 
-                for i in 0..bar.length() {
+                for i in 0..active_bar.length() {
                     ui.same_line(0.0);
                     
                     let token = match active_sound == i {
                         true => ui.push_style_color(StyleColor::Button, [1.0, 0.0, 0.0, 1.0]),
                         false => ui.push_style_color(StyleColor::CheckMark, [0.0, 0.0, 0.0, 1.0])
                     };
-
                     if ui.small_button(&im_str!("{}", i)) {
                         active_sound = i as usize;
                     }
-
                     token.pop(ui);
 
                 }
                 if ui.small_button(&im_str!("extend")) {
-                    bar.extend(1);
+                    active_bar.extend(1);
                 }
 
-                if ui.small_button(&im_str!("dbg")) {
-                    dbg!(&bar);
-                }
+                
                 if ui.small_button(&im_str!("ply")) {
-                    bar.play(&dev);
+                    active_bar.play(&dev);
                 }
             });
     
             Window::new(im_str!("sound"))
             .size([300.0, 100.0], Condition::FirstUseEver)
             .build(ui, || {
-                let snd = &bar.sounds[active_sound];
+                let snd = &active_bar.sounds[active_sound];
                 if let Some(s) = snd{
                     ui.text(im_str!("name   {}", s.name));
                     ui.text(im_str!("roll   {}", s.roll));
                     ui.text(im_str!("volume {}", s.volume));
                     ui.text(im_str!("rate   {}", s.rate));
                 }
-
-       
             });
     
+            Window::new(im_str!("tracks"))
+            .size([300.0, 100.0], Condition::FirstUseEver)
+            .build(ui, || {
+               
+                if ui.small_button(&im_str!("add")) {
+                    active_bar.play(&dev);
+                }
+            });
     
     
         });