1*ANY for counts since 60 was arbitrary between middleC and 6*0

This commit is contained in:
2026-03-12 15:55:37 -06:00
parent 31faeb3c1b
commit eb1a537ce2
5 changed files with 39 additions and 20 deletions

View File

@@ -41,15 +41,24 @@ fn parse(s: String) -> Vec<String> {
let lines = s.split("\n").collect::<Vec<_>>();
let mut j = 0;
for i in 0..lines.len() {
match lines[i] {
"" => {
j = 0;
},
_ => {
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[{ let tmp = j; j += 1; tmp }] += &(" ".to_string() + lines[i]);
},
};
}
channels.iter().map(|x| x.split_whitespace().collect::<Vec<_>>().join(" ")).collect()
channels
.iter()
.map(|x| x.split_whitespace().collect::<Vec<_>>()
.join(" ")
)
.collect()
}
#[cfg(test)]
@@ -72,7 +81,7 @@ mod test {
fn test_two_channels_one_bar() {
assert_eq!(
super::new("src/testdata/two_channels_one_bar.txt")[0],
"2a 2b 2c".to_string()
"2*a 2*b 2*c".to_string()
);
assert_eq!(
super::new("src/testdata/two_channels_one_bar.txt")[1],
@@ -88,7 +97,7 @@ mod test {
);
assert_eq!(
super::new("src/testdata/two_channels_two_bars.txt")[1],
"2a 2b 2c 2d 2e 2f".to_string()
"2*a 2*b 2*c 2*d 2*e 2*f".to_string()
);
}

View File

@@ -112,12 +112,13 @@ impl Seq {
let s: String = s.to_string();
let s: &str = s.as_ref();
for split in s.split_whitespace() {
eprintln!("append_one({:?}) from {:?}", split.to_string(), s);
self.append_one(split.to_string());
}
}
fn append_one(&mut self, s: String) {
let re = regex::Regex::new(r"^(?<count>[0-9]*)(?<tone>.*)$").unwrap();
let re = regex::Regex::new(r"^((?<count>[0-9]+)\*)?(?<tone>.*)$").unwrap();
let captures = re.captures(&s).unwrap();
let n = match captures.name("count") {
@@ -125,7 +126,9 @@ impl Seq {
_ => 1,
} as usize;
let tone = tone::new(captures.name("tone").unwrap().as_str());
let tone_s = captures.name("tone").unwrap().as_str();
eprintln!("append_one({:?})", tone_s);
let tone = tone::new(tone_s);
self.beats.push((n, tone));
}
}
@@ -139,9 +142,9 @@ mod test {
let mut seq = new();
seq.append("c c");
seq.append("4d");
seq.append("2-");
seq.append("g 2e");
seq.append("4*d");
seq.append("2*-");
seq.append("g 2*e");
assert_eq!(seq.beats.len(), 6);
assert_eq!(seq.len(), 11);

View File

@@ -1,4 +1,11 @@
CM0 CM3 CM4 CM0
#CM0 CM3 CM4 CM0
#CM1 CM4 CM0
#CM0 CM4 CM5 CM3
# 1 4 6 4 # pop101
#GM0 GM3 GM5 GM3
60
63
6*a

View File

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

View File

@@ -1,5 +1,5 @@
a b c
2a 2b 2c
2*a 2*b 2*c
d e f
2d 2e 2f
2*d 2*e 2*f