failing multi chord test from file

This commit is contained in:
Bel LaPointe
2026-03-11 16:00:41 -06:00
parent 05b49a3777
commit 8f4c7596c4
4 changed files with 57 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
use itertools::Itertools;
mod flags;
mod play;
mod seq;
mod syn;
mod tone;
@@ -16,8 +17,12 @@ fn main() {
flags.sound_font,
flags.sample_rate,
));
for i in 0..flags.play.len() {
syn_seq.append(i as i32, flags.play[i].clone());
let mut i = 0;
for p in flags.play.iter() {
for p in play::new(p.clone()) {
syn_seq.append(i as i32, p);
i += 1;
}
}
play(syn_seq, flags.sample_rate, flags.bpm);

47
src/play.rs Normal file
View File

@@ -0,0 +1,47 @@
use std::io::Read;
pub fn new<S: ToString>(s: S) -> Vec<String> {
parse(from_string(s.to_string()))
}
fn from_string(s: String) -> String {
match std::fs::File::open(s.clone()) {
Ok(mut reader) => {
let mut content = String::new();
reader
.read_to_string(&mut content)
.expect(format!("failed to read {}", s).as_ref());
content.split_whitespace().collect::<Vec<_>>().join(" ")
}
Err(_) => s,
}
}
fn parse(s: String) -> Vec<String> {
vec![s]
}
#[cfg(test)]
mod test {
#[test]
fn test_string() {
assert_eq!(super::new("a b c")[0], "a b c".to_string());
assert_eq!(super::new("a b c".to_string())[0], "a b c".to_string());
}
#[test]
fn test_single_line_file() {
assert_eq!(
super::new("src/testdata/single_line_file.txt")[0],
"a b c".to_string()
);
}
#[test]
fn test_two_channels_one_bar() {
assert_eq!(
super::new("src/testdata/two_channels_one_bar.txt")[0],
"a b c".to_string()
);
}
}

1
src/testdata/single_line_file.txt vendored Normal file
View File

@@ -0,0 +1 @@
a b c

2
src/testdata/two_channels_one_bar.txt vendored Normal file
View File

@@ -0,0 +1,2 @@
a b c
a5 b5 c5