char-slop/chordpad.vibed.software

git clone https://git.t4t.associates/char-slop/chordpad.vibed.software

Charlotte Somallow midi import as chords040fec5

main
1.3 KiB45 linesraw
1import { assertEquals } from "@std/assert";
2import { chordsOf } from "./chords.ts";
3
4const note = (start: number, dur: number, pitch: number) => ({ start, dur, pitch, vel: 1 });
5const layout = (notes: ReturnType<typeof note>[]) =>
6  chordsOf(notes).map(c => [c.start, c.start + c.dur, c.notes]);
7
8Deno.test("block chords come out one chord each, leaving silences empty", () => {
9  assertEquals(
10    layout([
11      note(0, 2, 64),
12      note(0, 2, 60),
13      note(0, 2, 67),
14      note(3, 1, 65),
15      note(3, 1, 69),
16      note(3, 1, 60),
17    ]),
18    [
19      [0, 2, [60, 64, 67]],
20      [3, 4, [60, 65, 69]],
21    ],
22  );
23});
24
25Deno.test("a new chord starts wherever a note comes in or drops out", () => {
26  assertEquals(layout([note(0, 4, 48), note(0, 2, 64), note(1, 1, 67), note(2, 2, 65)]), [
27    [0, 1, [48, 64]],
28    [1, 2, [48, 64, 67]],
29    [2, 4, [48, 65]],
30  ]);
31});
32
33Deno.test("the same notes struck again straight after carry on as one chord", () => {
34  assertEquals(layout([note(0, 1, 60), note(0, 1, 64), note(1, 1, 64), note(1, 1, 60)]), [
35    [0, 2, [60, 64]],
36  ]);
37});
38
39Deno.test("a pitch doubled across overlapping notes is one chord tone", () => {
40  assertEquals(layout([note(0, 2, 60), note(1, 2, 60), note(1, 1, 67)]), [
41    [0, 1, [60]],
42    [1, 2, [60, 67]],
43    [2, 3, [60]],
44  ]);
45});