reststs AND rustfmt changed whitespace

This commit is contained in:
Bel LaPointe
2026-03-11 15:32:22 -06:00
parent a2a5465fb0
commit beb6595f42
4 changed files with 285 additions and 263 deletions

View File

@@ -1,5 +1,5 @@
use crate::tone;
use crate::syn;
use crate::tone;
pub struct SynSeq {
seqs: std::collections::HashMap<i32, Seq>,
@@ -21,7 +21,7 @@ impl SynSeq {
let mut seq = new();
seq.append(s);
self.seqs.insert(ch, seq);
},
}
};
}
@@ -29,13 +29,11 @@ impl SynSeq {
for (ch, seq) in self.seqs.iter_mut() {
let ch = ch.clone();
match seq.pop() {
(Some(tone), changed) if changed => {
self.syn.set(ch, Some(tone.clone()))
},
(Some(tone), changed) if changed => self.syn.set(ch, Some(tone.clone())),
(None, changed) if changed => {
self.syn.set(ch, None);
},
_ => {},
}
_ => {}
};
}
self.syn.render(left, right);
@@ -97,7 +95,7 @@ impl Seq {
_ => {
self.beats[0].0 -= 1;
Some(self.beats[0].1.clone())
},
}
},
}
}
@@ -111,7 +109,7 @@ impl Seq {
}
fn append_one(&mut self, s: String) {
let re = regex::Regex::new(r"^(?<count>[0-9]*)(?<tone>[a-z].*)$").unwrap();
let re = regex::Regex::new(r"^(?<count>[0-9]*)(?<tone>.*)$").unwrap();
let captures = re.captures(&s).unwrap();
let n = match captures.name("count") {
@@ -134,21 +132,25 @@ mod test {
seq.append("c");
seq.append("4d");
seq.append("2-");
seq.append("g 2e");
assert_eq!(seq.beats.len(), 4);
assert_eq!(seq.len(), 8);
assert_eq!(seq.beats.len(), 5);
assert_eq!(seq.len(), 10);
assert_eq!(seq.beats[0], (1 as usize, tone::new("c")));
assert_eq!(seq.beats[1], (4 as usize, tone::new("d")));
assert_eq!(seq.beats[2], (1 as usize, tone::new("g")));
assert_eq!(seq.beats[3], (2 as usize, tone::new("e")));
assert_eq!(seq.beats[2], (2 as usize, tone::new("!")));
assert_eq!(seq.beats[3], (1 as usize, tone::new("g")));
assert_eq!(seq.beats[4], (2 as usize, tone::new("e")));
assert_eq!(seq.pop(), (Some(tone::new("c")), true));
assert_eq!(seq.pop(), (Some(tone::new("d")), true));
for _ in 1..4 {
assert_eq!(seq.pop(), (Some(tone::new("d")), false));
}
assert_eq!(seq.pop(), (Some(tone::new(".")), true));
assert_eq!(seq.pop(), (Some(tone::new("?")), false));
assert_eq!(seq.pop(), (Some(tone::new("g")), true));
assert_eq!(seq.pop(), (Some(tone::new("e")), true));
assert_eq!(seq.pop(), (Some(tone::new("e")), false));

View File

@@ -1,5 +1,5 @@
use rustysynth::Synthesizer;
use rustysynth::SoundFont;
use rustysynth::Synthesizer;
use rustysynth::SynthesizerSettings;
use std::sync::Arc;
@@ -17,7 +17,10 @@ impl Syn {
pub fn new(debug: bool, sound_font: String, sample_rate: usize) -> Syn {
match debug {
false => Syn::new_real(sound_font, sample_rate),
true => Syn::Text{m: std::collections::HashMap::new(), i: 0},
true => Syn::Text {
m: std::collections::HashMap::new(),
i: 0,
},
}
}
@@ -37,10 +40,10 @@ impl Syn {
// velocity=[0..128)
Syn::Real(syn) => {
syn.note_off_all_channel(ch, false);
},
}
Syn::Text { m, .. } => {
m.remove(&ch);
},
}
};
if let Some(tone) = b {
self.tone_on(ch, tone);
@@ -54,14 +57,16 @@ impl Syn {
Syn::Real(syn) => syn.note_on(ch, b.i32(), 127),
Syn::Text { m, .. } => {
match m.get_mut(&ch) {
Some(m2) => { m2.insert(b.i32(), 127); },
Some(m2) => {
m2.insert(b.i32(), 127);
}
None => {
let mut m2 = std::collections::HashMap::new();
m2.insert(b.i32(), 127);
m.insert(ch, m2);
},
}
};
},
}
};
}
@@ -70,11 +75,12 @@ impl Syn {
Syn::Real(syn) => syn.note_off(ch, b.i32()),
Syn::Text { m, .. } => {
match m.get_mut(&ch) {
Some(m) => { m.remove(&b.i32()); },
None => {},
Some(m) => {
m.remove(&b.i32());
}
None => {}
};
},
}
};
}
@@ -84,7 +90,7 @@ impl Syn {
Syn::Text { m, i } => {
eprintln!("{} | render[{}]({:?})", chrono::prelude::Utc::now(), i, m);
*i += 1;
},
}
};
}
}

View File

@@ -8,11 +8,15 @@ pub fn new<S: ToString>(s: S) -> Tone {
impl Tone {
fn new(s: String) -> Tone {
let re = regex::Regex::new(r"^((?<letter>^[a-g])(?<sharpness>[+-]?)(?<octave>[1-5]?)|(?<numeric>[0-9]+))$").unwrap();
let captures = re.captures(s.as_ref()).unwrap();
let re = regex::Regex::new(r"^((?<letter>^[a-g])(?<sharpness>[+-]?)(?<octave>[1-5]?)|(?<numeric>[0-9]+)|(?<rest>[^a-zA-Z0-9]))$").unwrap();
let captures = re
.captures(&s)
.expect(format!("tone '{}' does not match regex", s).as_ref());
Tone(match captures.name("numeric") {
Some(number) => number.as_str().parse::<i32>().unwrap(),
None => {
None => match captures.name("rest") {
Some(_) => 0,
_ => {
let mut result = match captures.name("letter").unwrap().as_str() {
"a" => 57,
"b" => 59,
@@ -41,6 +45,7 @@ impl Tone {
} as i32;
result
}
},
})
}
@@ -54,18 +59,27 @@ impl Tone {
mod test {
#[test]
fn test_tone_new() {
eprintln!("numeric");
assert_eq!(super::new("60").i32(), 60);
eprintln!("rests");
assert_eq!(super::new("-").i32(), 0);
assert_eq!(super::new(".").i32(), 0);
eprintln!("alpha");
assert_eq!(super::new("c").i32(), 60);
assert_eq!(super::new("e").i32(), 64);
assert_eq!(super::new("g").i32(), 67);
eprintln!("alpha mod");
assert_eq!(super::new("c+").i32(), 60 + 1);
assert_eq!(super::new("c-").i32(), 60 - 1);
eprintln!("alpha octave");
assert_eq!(super::new("c3").i32(), 60);
assert_eq!(super::new("c4").i32(), 60 + 12);
eprintln!("alpha mod octave");
assert_eq!(super::new("c+4").i32(), 60 + 12 + 1);
}
}