Feat: fixes and demo
Some checks failed
Deploy Website / deploy (push) Failing after 4m50s

This commit is contained in:
2026-02-23 01:18:43 +01:00
parent f6c7438886
commit 2a2b3c5651
3 changed files with 94 additions and 42 deletions

View File

@@ -237,12 +237,14 @@ impl Forth {
};
let emit_with_cycling = |cmd: &CmdRegister,
emit_idx: usize,
arp_idx: usize,
poly_idx: usize,
delta_secs: f64,
outputs: &mut Vec<String>|
-> Result<Option<Value>, String> {
let (sound_opt, params) = cmd.snapshot().ok_or("nothing to emit")?;
let resolved_sound_val = sound_opt.map(|sv| resolve_cycling(sv, emit_idx));
let resolved_sound_val =
sound_opt.map(|sv| resolve_value(sv, arp_idx, poly_idx));
let sound_str = match &resolved_sound_val {
Some(v) => Some(v.as_str()?.to_string()),
None => None,
@@ -250,7 +252,7 @@ impl Forth {
let resolved_params: Vec<(&str, String)> = params
.iter()
.map(|(k, v)| {
let resolved = resolve_cycling(v, emit_idx);
let resolved = resolve_value(v, arp_idx, poly_idx);
if let Value::CycleList(_) | Value::ArpList(_) = v {
if let Some(span) = resolved.span() {
if let Some(trace) = trace_cell.borrow_mut().as_mut() {
@@ -544,6 +546,7 @@ impl Forth {
Op::Emit => {
if has_arp_list(cmd) {
let arp_count = compute_arp_count(cmd);
let poly_count = compute_poly_count(cmd);
let explicit_deltas = !cmd.deltas().is_empty();
let delta_list: Vec<Value> = if explicit_deltas {
cmd.deltas().to_vec()
@@ -570,12 +573,16 @@ impl Forth {
ctx.nudge_secs
+ (i as f64 / count as f64) * ctx.step_duration()
};
if let Some(sound_val) =
emit_with_cycling(cmd, i, delta_secs, outputs)?
{
if let Some(span) = sound_val.span() {
if let Some(trace) = trace_cell.borrow_mut().as_mut() {
trace.selected_spans.push(span);
for poly_i in 0..poly_count {
if let Some(sound_val) =
emit_with_cycling(cmd, i, poly_i, delta_secs, outputs)?
{
if let Some(span) = sound_val.span() {
if let Some(trace) =
trace_cell.borrow_mut().as_mut()
{
trace.selected_spans.push(span);
}
}
}
}
@@ -599,7 +606,7 @@ impl Forth {
}
}
if let Some(sound_val) =
emit_with_cycling(cmd, poly_idx, delta_secs, outputs)?
emit_with_cycling(cmd, 0, poly_idx, delta_secs, outputs)?
{
if let Some(span) = sound_val.span() {
if let Some(trace) =
@@ -1241,9 +1248,10 @@ impl Forth {
Op::MidiEmit => {
let (_, params) = cmd.snapshot().unwrap_or((None, &[]));
// Build schedule: (emit_idx, delta_secs) — same logic as Op::Emit
let schedule: Vec<(usize, f64)> = if has_arp_list(cmd) {
// Build schedule: (arp_idx, poly_idx, delta_secs)
let schedule: Vec<(usize, usize, f64)> = if has_arp_list(cmd) {
let arp_count = compute_arp_count(cmd);
let poly_count = compute_poly_count(cmd);
let explicit = !cmd.deltas().is_empty();
let delta_list = cmd.deltas();
let count = if explicit {
@@ -1251,20 +1259,22 @@ impl Forth {
} else {
arp_count
};
(0..count)
.map(|i| {
let delta_secs = if explicit {
let frac = delta_list[i % delta_list.len()]
.as_float()
.unwrap_or(0.0);
ctx.nudge_secs + frac * ctx.step_duration()
} else {
ctx.nudge_secs
+ (i as f64 / count as f64) * ctx.step_duration()
};
(i, delta_secs)
})
.collect()
let mut sched = Vec::with_capacity(count * poly_count);
for i in 0..count {
let delta_secs = if explicit {
let frac = delta_list[i % delta_list.len()]
.as_float()
.unwrap_or(0.0);
ctx.nudge_secs + frac * ctx.step_duration()
} else {
ctx.nudge_secs
+ (i as f64 / count as f64) * ctx.step_duration()
};
for poly_i in 0..poly_count {
sched.push((i, poly_i, delta_secs));
}
}
sched
} else {
let poly_count = compute_poly_count(cmd);
let deltas: Vec<f64> = if cmd.deltas().is_empty() {
@@ -1279,6 +1289,7 @@ impl Forth {
for poly_idx in 0..poly_count {
for &frac in &deltas {
sched.push((
0,
poly_idx,
ctx.nudge_secs + frac * ctx.step_duration(),
));
@@ -1287,14 +1298,14 @@ impl Forth {
sched
};
for (emit_idx, delta_secs) in schedule {
for (arp_idx, poly_idx, delta_secs) in schedule {
let get_int = |name: &str| -> Option<i64> {
params
.iter()
.rev()
.find(|(k, _)| *k == name)
.and_then(|(_, v)| {
resolve_cycling(v, emit_idx).as_int().ok()
resolve_value(v, arp_idx, poly_idx).as_int().ok()
})
};
let get_float = |name: &str| -> Option<f64> {
@@ -1303,7 +1314,7 @@ impl Forth {
.rev()
.find(|(k, _)| *k == name)
.and_then(|(_, v)| {
resolve_cycling(v, emit_idx).as_float().ok()
resolve_value(v, arp_idx, poly_idx).as_float().ok()
})
};
let chan = get_int("chan")
@@ -1680,10 +1691,13 @@ where
Ok(())
}
fn resolve_cycling(val: &Value, emit_idx: usize) -> Cow<'_, Value> {
fn resolve_value(val: &Value, arp_idx: usize, poly_idx: usize) -> Cow<'_, Value> {
match val {
Value::CycleList(items) | Value::ArpList(items) if !items.is_empty() => {
Cow::Owned(items[emit_idx % items.len()].clone())
Value::ArpList(items) if !items.is_empty() => {
Cow::Owned(items[arp_idx % items.len()].clone())
}
Value::CycleList(items) if !items.is_empty() => {
Cow::Owned(items[poly_idx % items.len()].clone())
}
other => Cow::Borrowed(other),
}