complex files
This commit is contained in:
38
src/play.rs
38
src/play.rs
@@ -11,14 +11,30 @@ fn from_string(s: String) -> String {
|
|||||||
reader
|
reader
|
||||||
.read_to_string(&mut content)
|
.read_to_string(&mut content)
|
||||||
.expect(format!("failed to read {}", s).as_ref());
|
.expect(format!("failed to read {}", s).as_ref());
|
||||||
content.split_whitespace().collect::<Vec<_>>().join(" ")
|
content
|
||||||
|
.split("\n")
|
||||||
|
.map(|x| x.split_whitespace().collect::<Vec<_>>().join(" "))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n")
|
||||||
}
|
}
|
||||||
Err(_) => s,
|
Err(_) => s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(s: String) -> Vec<String> {
|
fn parse(s: String) -> Vec<String> {
|
||||||
vec![s]
|
let mut channels = vec![];
|
||||||
|
let lines = s.split("\n").collect::<Vec<_>>();
|
||||||
|
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::<Vec<_>>().join(" ")).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -41,7 +57,23 @@ mod test {
|
|||||||
fn test_two_channels_one_bar() {
|
fn test_two_channels_one_bar() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::new("src/testdata/two_channels_one_bar.txt")[0],
|
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()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,10 +92,6 @@ impl Seq {
|
|||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
let tone = self._pop();
|
let tone = self._pop();
|
||||||
eprintln!(
|
|
||||||
" popped ({:?}, {}): had_more={}, beats={:?} eof={} from {}",
|
|
||||||
tone, changed, self.had_more, self.beats, self.eof, eof_before,
|
|
||||||
);
|
|
||||||
(tone, changed)
|
(tone, changed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
src/testdata/two_channels_one_bar.txt
vendored
4
src/testdata/two_channels_one_bar.txt
vendored
@@ -1,2 +1,2 @@
|
|||||||
a b c
|
2a 2b 2c
|
||||||
a5 b5 c5
|
. a5 . b5 . c5
|
||||||
|
|||||||
5
src/testdata/two_channels_two_bars.txt
vendored
Normal file
5
src/testdata/two_channels_two_bars.txt
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
a b c
|
||||||
|
2a 2b 2c
|
||||||
|
|
||||||
|
d e f
|
||||||
|
2d 2e 2f
|
||||||
Reference in New Issue
Block a user