Feat: polyphony + iterator reset
Some checks failed
Deploy Website / deploy (push) Failing after 4m48s
Some checks failed
Deploy Website / deploy (push) Failing after 4m48s
This commit is contained in:
@@ -74,22 +74,6 @@ fn dupn_alias() {
|
||||
expect_int("5 3 ! + +", 15);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tcycle_creates_cycle_list() {
|
||||
let outputs = expect_outputs(r#"0.0 at 60 64 67 3 tcycle note sine s ."#, 1);
|
||||
assert!(outputs[0].contains("note/60"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tcycle_with_multiple_emits() {
|
||||
let f = forth();
|
||||
let ctx = default_ctx();
|
||||
let outputs = f.evaluate(r#"0 0.5 2 at 60 64 2 tcycle note sine s ."#, &ctx).unwrap();
|
||||
assert_eq!(outputs.len(), 2);
|
||||
assert!(outputs[0].contains("note/60"));
|
||||
assert!(outputs[1].contains("note/64"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cycle_zero_count_error() {
|
||||
expect_error("1 2 3 0 cycle", "cycle count must be > 0");
|
||||
@@ -99,8 +83,3 @@ fn cycle_zero_count_error() {
|
||||
fn choose_zero_count_error() {
|
||||
expect_error("1 2 3 0 choose", "choose count must be > 0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tcycle_zero_count_error() {
|
||||
expect_error("1 2 3 0 tcycle", "tcycle count must be > 0");
|
||||
}
|
||||
|
||||
@@ -106,3 +106,35 @@ fn param_only_multiple_params() {
|
||||
assert!(outputs[0].contains("gain/0.5"));
|
||||
assert!(!outputs[0].contains("sound/"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn polyphonic_notes() {
|
||||
let outputs = expect_outputs(r#"60 64 67 note sine s ."#, 3);
|
||||
assert!(outputs[0].contains("note/60"));
|
||||
assert!(outputs[1].contains("note/64"));
|
||||
assert!(outputs[2].contains("note/67"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn polyphonic_sounds() {
|
||||
let outputs = expect_outputs(r#"440 freq kick hat s ."#, 2);
|
||||
assert!(outputs[0].contains("sound/kick"));
|
||||
assert!(outputs[1].contains("sound/hat"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn polyphonic_cycling() {
|
||||
let outputs = expect_outputs(r#"60 64 67 note 0.5 1.0 gain sine s ."#, 3);
|
||||
assert!(outputs[0].contains("note/60"));
|
||||
assert!(outputs[0].contains("gain/0.5"));
|
||||
assert!(outputs[1].contains("note/64"));
|
||||
assert!(outputs[1].contains("gain/1"));
|
||||
assert!(outputs[2].contains("note/67"));
|
||||
assert!(outputs[2].contains("gain/0.5"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn polyphonic_with_at() {
|
||||
let outputs = expect_outputs(r#"0 0.5 at 60 64 note sine s ."#, 4);
|
||||
assert_eq!(outputs.len(), 4);
|
||||
}
|
||||
|
||||
@@ -42,13 +42,6 @@ fn get_sounds(outputs: &[String]) -> Vec<String> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_param(outputs: &[String], param: &str) -> Vec<f64> {
|
||||
outputs
|
||||
.iter()
|
||||
.map(|o| parse_params(o).get(param).copied().unwrap_or(0.0))
|
||||
.collect()
|
||||
}
|
||||
|
||||
const EPSILON: f64 = 1e-9;
|
||||
|
||||
fn approx_eq(a: f64, b: f64) -> bool {
|
||||
@@ -156,7 +149,7 @@ fn at_single_delta() {
|
||||
|
||||
#[test]
|
||||
fn at_list_deltas() {
|
||||
let outputs = expect_outputs(r#"0 0.5 2 at "kick" s ."#, 2);
|
||||
let outputs = expect_outputs(r#"0 0.5 at "kick" s ."#, 2);
|
||||
let deltas = get_deltas(&outputs);
|
||||
let step_dur = 0.125;
|
||||
assert!(approx_eq(deltas[0], 0.0), "expected delta 0, got {}", deltas[0]);
|
||||
@@ -165,7 +158,7 @@ fn at_list_deltas() {
|
||||
|
||||
#[test]
|
||||
fn at_three_deltas() {
|
||||
let outputs = expect_outputs(r#"0 0.33 0.67 3 at "kick" s ."#, 3);
|
||||
let outputs = expect_outputs(r#"0 0.33 0.67 at "kick" s ."#, 3);
|
||||
let deltas = get_deltas(&outputs);
|
||||
let step_dur = 0.125;
|
||||
assert!(approx_eq(deltas[0], 0.0), "expected delta 0");
|
||||
@@ -175,70 +168,26 @@ fn at_three_deltas() {
|
||||
|
||||
#[test]
|
||||
fn at_persists_across_emits() {
|
||||
let outputs = expect_outputs(r#"0 0.5 2 at "kick" s . "hat" s ."#, 4);
|
||||
let outputs = expect_outputs(r#"0 0.5 at "kick" s . "hat" s ."#, 4);
|
||||
let sounds = get_sounds(&outputs);
|
||||
assert_eq!(sounds, vec!["kick", "kick", "hat", "hat"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tcycle_basic() {
|
||||
let outputs = expect_outputs(r#"0 0.5 0.75 3 at 60 64 67 3 tcycle note sine s ."#, 3);
|
||||
let notes = get_param(&outputs, "note");
|
||||
assert_eq!(notes, vec![60.0, 64.0, 67.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tcycle_wraps() {
|
||||
let outputs = expect_outputs(r#"0 0.33 0.67 3 at 60 64 2 tcycle note sine s ."#, 3);
|
||||
let notes = get_param(&outputs, "note");
|
||||
assert_eq!(notes, vec![60.0, 64.0, 60.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tcycle_with_sound() {
|
||||
let outputs = expect_outputs(r#"0 0.5 2 at kick hat 2 tcycle s ."#, 2);
|
||||
let sounds = get_sounds(&outputs);
|
||||
assert_eq!(sounds, vec!["kick", "hat"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tcycle_multiple_params() {
|
||||
let outputs = expect_outputs(r#"0 0.5 0.75 3 at 60 64 67 3 tcycle note 0.5 1.0 2 tcycle gain sine s ."#, 3);
|
||||
let notes = get_param(&outputs, "note");
|
||||
let gains = get_param(&outputs, "gain");
|
||||
assert_eq!(notes, vec![60.0, 64.0, 67.0]);
|
||||
assert_eq!(gains, vec![0.5, 1.0, 0.5]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn at_reset_with_zero() {
|
||||
let outputs = expect_outputs(r#"0 0.5 2 at "kick" s . 0.0 at "hat" s ."#, 3);
|
||||
let outputs = expect_outputs(r#"0 0.5 at "kick" s . 0.0 at "hat" s ."#, 3);
|
||||
let sounds = get_sounds(&outputs);
|
||||
assert_eq!(sounds, vec!["kick", "kick", "hat"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tcycle_records_selected_spans() {
|
||||
use cagire::forth::ExecutionTrace;
|
||||
|
||||
let f = forth();
|
||||
let mut trace = ExecutionTrace::default();
|
||||
let script = r#"0 0.5 2 at kick hat 2 tcycle s ."#;
|
||||
f.evaluate_with_trace(script, &default_ctx(), &mut trace).unwrap();
|
||||
|
||||
// Should have 4 selected spans:
|
||||
// - 2 for at deltas (0 and 0.5)
|
||||
// - 2 for tcycle sound values (kick and hat)
|
||||
assert_eq!(trace.selected_spans.len(), 4, "expected 4 selected spans (2 at + 2 tcycle)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn at_records_selected_spans() {
|
||||
use cagire::forth::ExecutionTrace;
|
||||
|
||||
let f = forth();
|
||||
let mut trace = ExecutionTrace::default();
|
||||
let script = r#"0 0.5 0.75 3 at "kick" s ."#;
|
||||
let script = r#"0 0.5 0.75 at "kick" s ."#;
|
||||
f.evaluate_with_trace(script, &default_ctx(), &mut trace).unwrap();
|
||||
|
||||
// Should have 6 selected spans: 3 for at deltas + 3 for sound (one per emit)
|
||||
|
||||
Reference in New Issue
Block a user