diff --git a/src/play.rs b/src/play.rs index 3d31e5d..914b702 100644 --- a/src/play.rs +++ b/src/play.rs @@ -11,14 +11,30 @@ fn from_string(s: String) -> String { reader .read_to_string(&mut content) .expect(format!("failed to read {}", s).as_ref()); - content.split_whitespace().collect::>().join(" ") + content + .split("\n") + .map(|x| x.split_whitespace().collect::>().join(" ")) + .collect::>() + .join("\n") } Err(_) => s, } } fn parse(s: String) -> Vec { - vec![s] + let mut channels = vec![]; + let lines = s.split("\n").collect::>(); + let mut j = 0; + for i in 0..lines.len() { + while channels.len() <= j { + channels.push("".to_string()); + } + match lines[i] { + "" => { j = 0; }, + _ => channels[{ let tmp = j; j += 1; tmp }] += &(" ".to_string() + lines[i]), + }; + } + channels.iter().map(|x| x.split_whitespace().collect::>().join(" ")).collect() } #[cfg(test)] @@ -41,7 +57,23 @@ mod test { fn test_two_channels_one_bar() { assert_eq!( super::new("src/testdata/two_channels_one_bar.txt")[0], - "a b c".to_string() + "2a 2b 2c".to_string() + ); + assert_eq!( + super::new("src/testdata/two_channels_one_bar.txt")[1], + ". a5 . b5 . c5".to_string() + ); + } + + #[test] + fn test_two_channels_two_bars() { + assert_eq!( + super::new("src/testdata/two_channels_two_bars.txt")[0], + "a b c d e f".to_string() + ); + assert_eq!( + super::new("src/testdata/two_channels_two_bars.txt")[1], + "2a 2b 2c 2d 2e 2f".to_string() ); } } diff --git a/src/seq.rs b/src/seq.rs index dcfbd0a..a3a8696 100644 --- a/src/seq.rs +++ b/src/seq.rs @@ -92,10 +92,6 @@ impl Seq { changed = true; } let tone = self._pop(); - eprintln!( - " popped ({:?}, {}): had_more={}, beats={:?} eof={} from {}", - tone, changed, self.had_more, self.beats, self.eof, eof_before, - ); (tone, changed) } diff --git a/src/testdata/two_channels_one_bar.txt b/src/testdata/two_channels_one_bar.txt index 31734d0..58b8fea 100644 --- a/src/testdata/two_channels_one_bar.txt +++ b/src/testdata/two_channels_one_bar.txt @@ -1,2 +1,2 @@ -a b c -a5 b5 c5 +2a 2b 2c +. a5 . b5 . c5 diff --git a/src/testdata/two_channels_two_bars.txt b/src/testdata/two_channels_two_bars.txt new file mode 100644 index 0000000..4ab8240 --- /dev/null +++ b/src/testdata/two_channels_two_bars.txt @@ -0,0 +1,5 @@ +a b c +2a 2b 2c + +d e f +2d 2e 2f