Feat: adding some basic music theory
Some checks failed
Deploy Website / deploy (push) Failing after 4m49s

This commit is contained in:
2026-02-01 16:15:09 +01:00
parent f9c284effd
commit adee8d0d57
8 changed files with 620 additions and 1 deletions

View File

@@ -455,7 +455,11 @@ impl Forth {
let a_f = a.as_float()?;
let b_f = b.as_float()?;
let (lo, hi) = if a_f <= b_f { (a_f, b_f) } else { (b_f, a_f) };
let val = self.rng.lock().unwrap().gen_range(lo..hi);
let val = if (hi - lo).abs() < f64::EPSILON {
lo
} else {
self.rng.lock().unwrap().gen_range(lo..hi)
};
stack.push(Value::Float(val, None));
}
}
@@ -629,6 +633,13 @@ impl Forth {
stack.push(result);
}
Op::Chord(intervals) => {
let root = stack.pop().ok_or("stack underflow")?.as_int()?;
for &interval in *intervals {
stack.push(Value::Int(root + interval, None));
}
}
Op::Oct => {
let shift = stack.pop().ok_or("stack underflow")?;
let note = stack.pop().ok_or("stack underflow")?;