import { assertEquals } from "@std/assert"; import { chordsOf } from "./chords.ts"; const note = (start: number, dur: number, pitch: number) => ({ start, dur, pitch, vel: 1 }); const layout = (notes: ReturnType[]) => chordsOf(notes).map(c => [c.start, c.start + c.dur, c.notes]); Deno.test("block chords come out one chord each, leaving silences empty", () => { assertEquals( layout([ note(0, 2, 64), note(0, 2, 60), note(0, 2, 67), note(3, 1, 65), note(3, 1, 69), note(3, 1, 60), ]), [ [0, 2, [60, 64, 67]], [3, 4, [60, 65, 69]], ], ); }); Deno.test("a new chord starts wherever a note comes in or drops out", () => { assertEquals(layout([note(0, 4, 48), note(0, 2, 64), note(1, 1, 67), note(2, 2, 65)]), [ [0, 1, [48, 64]], [1, 2, [48, 64, 67]], [2, 4, [48, 65]], ]); }); Deno.test("the same notes struck again straight after carry on as one chord", () => { assertEquals(layout([note(0, 1, 60), note(0, 1, 64), note(1, 1, 64), note(1, 1, 60)]), [ [0, 2, [60, 64]], ]); }); Deno.test("a pitch doubled across overlapping notes is one chord tone", () => { assertEquals(layout([note(0, 2, 60), note(1, 2, 60), note(1, 1, 67)]), [ [0, 1, [60]], [1, 2, [60, 67]], [2, 3, [60]], ]); });