Feat: lots of things, preparing for live gig
Some checks failed
Deploy Website / deploy (push) Failing after 4m50s
Some checks failed
Deploy Website / deploy (push) Failing after 4m50s
This commit is contained in:
@@ -80,7 +80,9 @@ pub enum Op {
|
||||
Mtof,
|
||||
Ftom,
|
||||
SetTempo,
|
||||
Every,
|
||||
Every(Option<SourceSpan>),
|
||||
Bjork(Option<SourceSpan>),
|
||||
PBjork(Option<SourceSpan>),
|
||||
Quotation(Arc<[Op]>, Option<SourceSpan>),
|
||||
When,
|
||||
Unless,
|
||||
|
||||
@@ -838,13 +838,36 @@ impl Forth {
|
||||
stack.push(Value::Int(if result { 1 } else { 0 }, None));
|
||||
}
|
||||
|
||||
Op::Every => {
|
||||
Op::Every(word_span) => {
|
||||
let n = pop_int(stack)?;
|
||||
let quot = pop(stack)?;
|
||||
if n <= 0 {
|
||||
return Err("every count must be > 0".into());
|
||||
}
|
||||
let result = ctx.iter as i64 % n == 0;
|
||||
stack.push(Value::Int(if result { 1 } else { 0 }, None));
|
||||
record_resolved(&trace_cell, *word_span, ResolvedValue::Bool(result));
|
||||
if result {
|
||||
run_quotation(quot, stack, outputs, cmd)?;
|
||||
}
|
||||
}
|
||||
|
||||
Op::Bjork(word_span) | Op::PBjork(word_span) => {
|
||||
let n = pop_int(stack)?;
|
||||
let k = pop_int(stack)?;
|
||||
let quot = pop(stack)?;
|
||||
if n <= 0 || k < 0 {
|
||||
return Err("bjork: n must be > 0, k must be >= 0".into());
|
||||
}
|
||||
let counter = match &ops[pc] {
|
||||
Op::Bjork(_) => ctx.runs,
|
||||
_ => ctx.iter,
|
||||
};
|
||||
let pos = counter % n as usize;
|
||||
let hit = k >= n || euclidean_hit(k as usize, n as usize, pos);
|
||||
record_resolved(&trace_cell, *word_span, ResolvedValue::Bool(hit));
|
||||
if hit {
|
||||
run_quotation(quot, stack, outputs, cmd)?;
|
||||
}
|
||||
}
|
||||
|
||||
Op::Quotation(quote_ops, body_span) => {
|
||||
@@ -1424,6 +1447,13 @@ fn emit_output(
|
||||
outputs.push(out);
|
||||
}
|
||||
|
||||
fn euclidean_hit(k: usize, n: usize, pos: usize) -> bool {
|
||||
if k == 0 {
|
||||
return false;
|
||||
}
|
||||
((pos + 1) * k) / n != (pos * k) / n
|
||||
}
|
||||
|
||||
fn euclidean_rhythm(k: usize, n: usize, rotation: usize) -> Vec<i64> {
|
||||
if k == 0 || n == 0 {
|
||||
return Vec::new();
|
||||
|
||||
@@ -68,7 +68,9 @@ pub(super) fn simple_op(name: &str) -> Option<Op> {
|
||||
"choose" => Op::Choose(None),
|
||||
"bounce" => Op::Bounce(None),
|
||||
"wchoose" => Op::WChoose(None),
|
||||
"every" => Op::Every,
|
||||
"every" => Op::Every(None),
|
||||
"bjork" => Op::Bjork(None),
|
||||
"pbjork" => Op::PBjork(None),
|
||||
"chance" => Op::ChanceExec(None),
|
||||
"prob" => Op::ProbExec(None),
|
||||
"coin" => Op::Coin(None),
|
||||
@@ -192,7 +194,9 @@ fn attach_span(op: &mut Op, span: SourceSpan) {
|
||||
match op {
|
||||
Op::Rand(s) | Op::ExpRand(s) | Op::LogRand(s) | Op::Coin(s)
|
||||
| Op::Choose(s) | Op::WChoose(s) | Op::Cycle(s) | Op::PCycle(s)
|
||||
| Op::Bounce(s) | Op::ChanceExec(s) | Op::ProbExec(s) => *s = Some(span),
|
||||
| Op::Bounce(s) | Op::ChanceExec(s) | Op::ProbExec(s)
|
||||
| Op::Every(s)
|
||||
| Op::Bjork(s) | Op::PBjork(s) => *s = Some(span),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -839,6 +839,36 @@ pub(super) const WORDS: &[Word] = &[
|
||||
compile: Param,
|
||||
varargs: true,
|
||||
},
|
||||
Word {
|
||||
name: "smear",
|
||||
aliases: &[],
|
||||
category: "Mod FX",
|
||||
stack: "(v.. --)",
|
||||
desc: "Set smear allpass chain wet/dry mix (0=bypass, 1=full wet)",
|
||||
example: "0.5 smear",
|
||||
compile: Param,
|
||||
varargs: true,
|
||||
},
|
||||
Word {
|
||||
name: "smearfreq",
|
||||
aliases: &[],
|
||||
category: "Mod FX",
|
||||
stack: "(v.. --)",
|
||||
desc: "Set smear allpass break frequency in Hz",
|
||||
example: "800 smearfreq",
|
||||
compile: Param,
|
||||
varargs: true,
|
||||
},
|
||||
Word {
|
||||
name: "smearfb",
|
||||
aliases: &[],
|
||||
category: "Mod FX",
|
||||
stack: "(v.. --)",
|
||||
desc: "Set smear feedback for resonance (0-0.95)",
|
||||
example: "0.8 smearfb",
|
||||
compile: Param,
|
||||
varargs: true,
|
||||
},
|
||||
Word {
|
||||
name: "chorus",
|
||||
aliases: &[],
|
||||
|
||||
@@ -198,9 +198,29 @@ pub(super) const WORDS: &[Word] = &[
|
||||
name: "every",
|
||||
aliases: &[],
|
||||
category: "Time",
|
||||
stack: "(n -- bool)",
|
||||
desc: "True every nth iteration",
|
||||
example: "4 every",
|
||||
stack: "(quot n --)",
|
||||
desc: "Execute quotation every nth iteration",
|
||||
example: "{ 2 distort } 4 every",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "bjork",
|
||||
aliases: &[],
|
||||
category: "Time",
|
||||
stack: "(quot k n --)",
|
||||
desc: "Execute quotation using Euclidean distribution over step runs",
|
||||
example: "{ 2 distort } 3 8 bjork",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
Word {
|
||||
name: "pbjork",
|
||||
aliases: &[],
|
||||
category: "Time",
|
||||
stack: "(quot k n --)",
|
||||
desc: "Execute quotation using Euclidean distribution over pattern iterations",
|
||||
example: "{ 2 distort } 3 8 pbjork",
|
||||
compile: Simple,
|
||||
varargs: false,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user