char-slop/chordpad.vibed.software

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

Charlotte Somtrack reordering + chord bass togglingee3b50a

main
1.0 KiB35 linesraw
1import { assertEquals } from "@std/assert";
2import { voiceTrack } from "../project/harmony.ts";
3import { newChordTrack, newProject, placeChord, projectKey } from "../project/model.ts";
4import { projectMidi } from "./export.ts";
5import { parseMidi } from "./smf.ts";
6
7Deno.test("a chord track with its bass off leaves each chord's lowest note out", () => {
8  const p = newProject();
9  const chords = newChordTrack();
10  for (const [start, symbol] of [
11    [0, "C/E"],
12    [4, "F"],
13    [8, "G7"],
14  ] as const) {
15    placeChord(chords, { id: symbol, start, dur: 4, symbol });
16  }
17  p.tracks = [chords];
18  const voiced = voiceTrack(chords, projectKey(p)).map(v => [...v.notes].sort((a, b) => a - b));
19  const exported = () => {
20    const [part] = parseMidi(projectMidi(p));
21    return [0, 4, 8].map(beat =>
22      part.notes
23        .filter(n => n.start === beat)
24        .map(n => n.pitch)
25        .sort((a, b) => a - b),
26    );
27  };
28
29  assertEquals(exported(), voiced);
30  chords.bass = false;
31  assertEquals(
32    exported(),
33    voiced.map(notes => notes.slice(1)),
34  );
35});