Feat: adding some basic music theory
Some checks failed
Deploy Website / deploy (push) Failing after 4m49s
Some checks failed
Deploy Website / deploy (push) Failing after 4m49s
This commit is contained in:
@@ -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")?;
|
||||
|
||||
Reference in New Issue
Block a user