time for strings

This commit is contained in:
2026-03-11 13:06:07 -06:00
parent 5f149414b2
commit 63f96b2d5f

View File

@@ -43,7 +43,7 @@ pub struct Seq {
beats: Vec<(i32, tone::Tone)>, beats: Vec<(i32, tone::Tone)>,
} }
pub fn new() -> Seq { fn new() -> Seq {
Seq::new() Seq::new()
} }
@@ -54,7 +54,7 @@ impl Seq {
} }
} }
pub fn pop(&mut self) -> Option<tone::Tone> { fn pop(&mut self) -> Option<tone::Tone> {
match self.beats.len() { match self.beats.len() {
0 => None, 0 => None,
_ => match self.beats[0].0 { _ => match self.beats[0].0 {
@@ -67,7 +67,7 @@ impl Seq {
} }
} }
pub fn append<S: ToString>(&mut self, s: S) { fn append<S: ToString>(&mut self, s: S) {
self.append_one(s.to_string()); self.append_one(s.to_string());
} }
@@ -94,14 +94,21 @@ mod test {
let mut seq = new(); let mut seq = new();
seq.append("c"); seq.append("c");
seq.append("4d"); seq.append("4d");
assert_eq!(seq.beats.len(), 2); seq.append("g 2e");
assert_eq!(seq.beats.len(), 4);
assert_eq!(seq.beats[0], (1 as i32, tone::new("c"))); assert_eq!(seq.beats[0], (1 as i32, tone::new("c")));
assert_eq!(seq.beats[1], (4 as i32, tone::new("d"))); assert_eq!(seq.beats[1], (4 as i32, tone::new("d")));
assert_eq!(seq.beats[2], (1 as i32, tone::new("g")));
assert_eq!(seq.beats[3], (2 as i32, tone::new("e")));
assert_eq!(seq.pop(), Some(tone::new("c"))); assert_eq!(seq.pop(), Some(tone::new("c")));
for _ in 0..4 { for _ in 0..4 {
assert_eq!(seq.pop(), Some(tone::new("d"))); assert_eq!(seq.pop(), Some(tone::new("d")));
} }
assert_eq!(seq.pop(), Some(tone::new("g")));
for _ in 0..2 {
assert_eq!(seq.pop(), Some(tone::new("e")));
}
assert_eq!(seq.pop(), None); assert_eq!(seq.pop(), None);
} }
} }