diff --git a/src/play.rs b/src/play.rs index 914b702..b396ca8 100644 --- a/src/play.rs +++ b/src/play.rs @@ -12,16 +12,31 @@ fn from_string(s: String) -> String { .read_to_string(&mut content) .expect(format!("failed to read {}", s).as_ref()); content - .split("\n") - .map(|x| x.split_whitespace().collect::>().join(" ")) - .collect::>() - .join("\n") } Err(_) => s, } } fn parse(s: String) -> Vec { + let s = s + .split("\n") + .filter(|x: &&str| !x // doesnt start with # + .split_whitespace() + .collect::>() + .join("") + .starts_with("#") + ) + .map(|x| x + .split("#") + .take(1) // drop after # + .collect::>() + .join("") + .split_whitespace() + .collect::>() + .join(" ") + ) + .collect::>() + .join("\n"); let mut channels = vec![]; let lines = s.split("\n").collect::>(); let mut j = 0; @@ -76,4 +91,20 @@ mod test { "2a 2b 2c 2d 2e 2f".to_string() ); } + + #[test] + fn drop_comment_lines() { + assert_eq!( + super::new("# hello\n # world\na b c")[0], + "a b c".to_string() + ); + } + + #[test] + fn drop_comment_trailer() { + assert_eq!( + super::new("a b c # hello world")[0], + "a b c".to_string() + ); + } } diff --git a/src/testdata/chord_progressions.txt b/src/testdata/chord_progressions.txt new file mode 100644 index 0000000..eff1730 --- /dev/null +++ b/src/testdata/chord_progressions.txt @@ -0,0 +1,9 @@ +CM0 CM3 CM4 CM0 + +. + +CM1 CM4 CM0 + +. + +CM0 CM4 CM5 CM3 diff --git a/src/testdata/sandbox.txt b/src/testdata/sandbox.txt index 34f9e2c..ae649be 100644 --- a/src/testdata/sandbox.txt +++ b/src/testdata/sandbox.txt @@ -1,5 +1,4 @@ -. a . b . c -2a2 2b2 2c2 +CM0 CM3 CM4 CM0 -. d . e . f -2d2 2e2 2f2 +#CM1 CM4 CM0 +#CM0 CM4 CM5 CM3