소스 검색

second window

woelper 4 년 전
부모
커밋
a6902ade82
4개의 변경된 파일110개의 추가작업 그리고 58개의 파일을 삭제
  1. 51 0
      Cargo.lock
  2. 3 2
      Cargo.toml
  3. 2 22
      src/base.rs
  4. 54 34
      src/main.rs

+ 51 - 0
Cargo.lock

@@ -60,6 +60,17 @@ version = "0.5.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
 
+[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi 0.3.8",
+]
+
 [[package]]
 name = "autocfg"
 version = "1.0.0"
@@ -423,6 +434,19 @@ version = "1.5.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
 
+[[package]]
+name = "env_logger"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
+dependencies = [
+ "atty",
+ "humantime",
+ "log",
+ "regex",
+ "termcolor",
+]
+
 [[package]]
 name = "failure"
 version = "0.1.6"
@@ -711,6 +735,15 @@ version = "3.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549"
 
+[[package]]
+name = "humantime"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
+dependencies = [
+ "quick-error",
+]
+
 [[package]]
 name = "image"
 version = "0.23.0"
@@ -1233,6 +1266,12 @@ dependencies = [
  "unicode-xid 0.2.0",
 ]
 
+[[package]]
+name = "quick-error"
+version = "1.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
+
 [[package]]
 name = "quote"
 version = "0.6.13"
@@ -1377,6 +1416,7 @@ dependencies = [
 name = "sampler"
 version = "0.1.0"
 dependencies = [
+ "env_logger",
  "gfx",
  "gfx_device_gl",
  "gfx_window_glutin",
@@ -1386,7 +1426,9 @@ dependencies = [
  "imgui",
  "imgui-gfx-renderer",
  "imgui-winit-support",
+ "log",
  "rodio",
+ "walkdir",
 ]
 
 [[package]]
@@ -1541,6 +1583,15 @@ version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "36ae8932fcfea38b7d3883ae2ab357b0d57a02caaa18ebb4f5ece08beaec4aa0"
 
+[[package]]
+name = "termcolor"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
+dependencies = [
+ "winapi-util",
+]
+
 [[package]]
 name = "thread_local"
 version = "1.0.1"

+ 3 - 2
Cargo.toml

@@ -17,8 +17,9 @@ rodio = "*"
 glium = { version = "0.26", default-features = true }
 image = "0.23"
 imgui = "*"
-
-
+log = "*"
+env_logger = "*"
+walkdir = "*"
 gfx = "0.18"
 gfx_device_gl = "0.16"
 gfx_window_glutin = "0.31"

+ 2 - 22
src/base.rs

@@ -12,31 +12,10 @@ use crate::rodio::Source;
 // pub fn collect
 
 
-pub struct Snd (Arc<Vec<u8>>);
-
-impl AsRef<[u8]> for Snd {
-    fn as_ref(&self) -> &[u8] {
-        &self.0
-    }
-}
-
-impl Snd {
-    pub fn load(filename: &str) -> std::io::Result<Snd> {
-        let mut buf = Vec::new();
-        let mut file = File::open(filename)?;
-        file.read_to_end(&mut buf)?;
-        Ok(Snd(Arc::new(buf)))
-    }
-    pub fn cursor(self: &Self) -> Cursor<Snd> {
-        Cursor::new(Snd(self.0.clone()))
-    }
-    pub fn decoder(self: &Self) -> Decoder<Cursor<Snd>> {
-        Decoder::new(self.cursor()).unwrap()
-    }
-}
 
 #[derive(Clone, Default, Debug)]
 pub struct Sound {
+    pub name: String,
     pub location: PathBuf,
     data: Arc<Vec<u8>>,
     volume: f32,
@@ -59,6 +38,7 @@ impl Sound {
         file.read_to_end(&mut buf)?;
         Ok(Sound{
             data: Arc::new(buf),
+            name: filename.to_string(),
             ..Default::default()
         })
     }

+ 54 - 34
src/main.rs

@@ -1,64 +1,84 @@
 use std::io::BufReader;
 use std::path::PathBuf;
-
 use std::thread;
 use std::time::Duration;
 extern crate rodio;
 mod base;
 use base::*;
-use rodio::Source;
-
+// use rodio::Source;
+use walkdir::WalkDir;
 use imgui::*;
 mod support;
-
-
-
+use log::*;
+use env_logger;
    
 
 fn main() {
-    let dev = rodio::default_output_device().unwrap();
 
+    env_logger::init();
+    let mut sounds = vec![];
+
+    for entry in WalkDir::new("media")
+        .into_iter()
+        .filter_map(|e| e.ok())
+        .filter(|e| e.path().is_file())
+    {
+        match Sound::new(&entry.path().to_string_lossy().to_string()) {
+            Ok(s) => sounds.push(s),
+            Err(e) => error!("{:?} while opening {:?}", e, entry)
+        }
+    }
 
-    let hat = Sound::new("media/c64sid-ch1.wav").unwrap();
-    let snare = Sound::new("media/c64sid-snare12.wav").unwrap();
-    let kick = Sound::new("media/c64sid-kick5.wav").unwrap();
+    let dev = rodio::default_output_device().unwrap();
 
     let mut bar = Bar::default();
     bar.bpm = 160;
-    
     bar.repeat = 2;
     
-    // bar.sounds = vec!(
-    //     kick.clone(),
-    //     hat.clone(),
-    //     snare.clone(),
-    //     hat.clone(),
-    //     kick.clone(),
-    //     hat.clone(),
-    //     snare.clone(),
-    //     hat.clone(),
-    // );
-    
-    // bar.play(&dev);
-    // thread::sleep(Duration::from_millis(200));
 
     let system = support::init(file!());
 
 
     system.main_loop(|_, ui| {
-        Window::new(im_str!("yo"))
+        Window::new(im_str!("sources"))
+            // .resizable(false)
+            .position([400.0, 140.0], Condition::Appearing)
+            .collapsible(false)
+            // .always_auto_resize(true)
+            .size([300.0, 300.0], Condition::FirstUseEver)
+            .build(ui, || {
+ 
+                ui.tree_node(im_str!("Tree")).build(|| {
+                    for s in &sounds {
+                        ui.tree_node(&im_str!("{}", s.name)).build(|| {
+                            ui.text(im_str!("blah blah"));
+                            ui.same_line(0.0);
+                            if ui.small_button(im_str!("add")) {
+                                
+                            }
+                            ui.same_line(0.0);
+                            if ui.small_button(im_str!("play")) {
+                                s.play(&dev);
+                            }
+                        });
+                    }
+                });
+
+            });
+
+            Window::new(im_str!("Hello world"))
             .size([300.0, 100.0], Condition::FirstUseEver)
             .build(ui, || {
-                ui.text(im_str!("Hello world!"));
-                ui.text(im_str!("こんにちは世界!"));
-                ui.text(im_str!("This...is...imgui-rs!"));
-                ui.separator();
-                let mouse_pos = ui.io().mouse_pos;
-                ui.text(format!(
-                    "Mouse Position: ({:.1},{:.1})",
-                    mouse_pos[0], mouse_pos[1]
-                ));
+                ui.text(im_str!("bars"));
+
+                for i in 0..bar.length {
+                    ui.same_line(0.0);
+                    ui.small_button(&im_str!("{}", i));
+                }
+        
             });
+
+
     });