barmark 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,44 @@
1
+ const pedalOf = (s) => (s.kind === "chord" ? s.pedal : undefined);
2
+ const membersOf = (s) => (s.kind === "group" ? s.members : [s]);
3
+ /**
4
+ * Walk a part's bars in play order with the pedal (grammar 2.9): `+`
5
+ * presses or changes it, `*` lifts it, and so do `--` and a tacet bar.
6
+ * `onRelease` hears each `*`, with whether the pedal was down.
7
+ */
8
+ function walk(bars, onRelease = () => { }) {
9
+ let down = false;
10
+ return bars.map((bar) => {
11
+ if (bar.tacet)
12
+ down = false;
13
+ return bar.slots.map((slot) => {
14
+ for (const m of membersOf(slot)) {
15
+ const pedal = pedalOf(m);
16
+ if (pedal === "release")
17
+ onRelease(bar, down);
18
+ if (pedal)
19
+ down = pedal === "press";
20
+ else if (m.kind === "silence")
21
+ down = false;
22
+ }
23
+ return down && !bar.tacet;
24
+ });
25
+ });
26
+ }
27
+ /** Whether the pedal is down at the end of each slot of each bar, in play order. The chart's end lifts it. */
28
+ export function pedalStates(bars) {
29
+ return walk(bars);
30
+ }
31
+ /** A warning for each `*` played with the pedal already up, once per line. */
32
+ export function pedalWarnings(bars) {
33
+ const lines = new Set();
34
+ walk(bars, (bar, wasDown) => {
35
+ if (!wasDown)
36
+ lines.add(bar.line);
37
+ });
38
+ return [...lines].map((line) => ({
39
+ line,
40
+ severity: "warning",
41
+ message: "* lifts the pedal, and it is already up here",
42
+ token: "*",
43
+ }));
44
+ }
@@ -44,14 +44,27 @@ export function reduceSlots(slots, beats) {
44
44
  const SYMBOLS = { hold: "/", nc: "N.C.", silence: "--", unknown: "?" };
45
45
  const PUSHES = { eighth: "<", sixteenth: "<<" };
46
46
  const ARTICULATIONS = { accent: ">", hit: "^" };
47
+ const PEDALS = { press: "+", release: "*" };
47
48
  /** A slot's leading marks: its push, then its articulation (grammar 2.7, 2.8). */
48
49
  function printMarks(s) {
49
50
  const push = "push" in s && s.push ? PUSHES[s.push] : "";
50
- return push + (s.kind === "chord" && s.articulation ? ARTICULATIONS[s.articulation] : "");
51
+ const pedal = s.kind === "chord" && s.pedal ? PEDALS[s.pedal] : "";
52
+ return pedal + push + (s.kind === "chord" && s.articulation ? ARTICULATIONS[s.articulation] : "");
51
53
  }
54
+ /** A syllable as written after its note's colon (grammar 4.3). */
55
+ const printSyllable = (s) => s.kind === "held" ? "/" : s.parts.join("~") + (s.continues ? "-" : "");
56
+ /** A lyric row's slot as written (grammar 7.7); a group's members are joined with `_`. */
57
+ const printLyricSlot = (s) => {
58
+ if (s.kind === "group")
59
+ return s.members.map(printLyricSlot).join("_");
60
+ if (s.kind === "syllable")
61
+ return printSyllable(s.syllable);
62
+ return s.kind === "hold" ? "/" : "--";
63
+ };
52
64
  function printSimple(s) {
53
65
  const body = s.kind === "chord" ? s.chord.canonical + (s.voicing?.canonical ?? "") : SYMBOLS[s.kind];
54
- return printMarks(s) + body;
66
+ const sung = s.kind === "chord" && s.syllable ? `:${printSyllable(s.syllable)}` : "";
67
+ return printMarks(s) + body + (s.dotted ? "." : "") + sung;
55
68
  }
56
69
  /** A slot in canonical spelling; a group's members are joined with `_`. */
57
70
  export function printSlot(s) {
@@ -125,6 +138,14 @@ function printDirectives(d) {
125
138
  parts.push(`feel: ${d.feel}${d.swingPercent === undefined ? "" : ` ${d.swingPercent}%`}`);
126
139
  return parts.join(", ");
127
140
  }
141
+ /** A lyric row's label: `lyrics:`, or `lyrics N:` for verse N. */
142
+ const lyricLabel = (l) => `lyrics${l.verse === null ? "" : ` ${l.verse}`}:`;
143
+ /** A lyric row's pieces, never reduced: its holds place the syllables. */
144
+ const lyricPieces = (l) => ({
145
+ open: "|",
146
+ cells: l.cells.map((c) => c.map(printLyricSlot).join(" ")),
147
+ close: "|",
148
+ });
128
149
  /** A bar line's opening, cells and closing, each printed. */
129
150
  function barPieces(l, beats) {
130
151
  return {
@@ -147,11 +168,15 @@ export function printLine(l, beats = []) {
147
168
  case "directive":
148
169
  return printDirectives(l.set);
149
170
  case "part":
150
- return `part: ${l.label ? `${l.label} = ` : ""}${l.name}`;
171
+ return `part: ${l.label ? `${l.label} = ` : ""}${l.name}${l.instrument ? `, instrument: ${l.instrument}` : ""}${l.clef ? `, clef: ${l.clef}` : ""}`;
151
172
  case "credit":
152
173
  return `${l.role}: ${l.text}`;
153
174
  case "bars":
154
175
  return joinPieces(barPieces(l, beats));
176
+ case "break":
177
+ return "---";
178
+ case "lyrics":
179
+ return `${lyricLabel(l)} ${joinPieces(lyricPieces(l))}`;
155
180
  default:
156
181
  return l.text;
157
182
  }
@@ -164,34 +189,130 @@ export function printLine(l, beats = []) {
164
189
  export function printChart(text) {
165
190
  return printParsed(text, parseChart(text));
166
191
  }
167
- /** A system's lines in score order, labels padded and pipes lined up (section 8, grammar 7.4). */
168
- function alignSystem(system, parsed, beatsFor, edit) {
169
- const score = (l) => parsed.parts.findIndex((p) => p.label === l.part);
170
- const width = Math.max(...parsed.parts.map((p) => p.label?.length ?? 0));
171
- const pieces = [...system]
172
- .sort((a, b) => score(a) - score(b))
173
- .map((l) => ({ label: l.part ?? "", ...barPieces(edit(l), beatsFor(l)) }));
174
- const columns = pieces[0]?.cells.map((_, i) => Math.max(...pieces.map((p) => p.cells[i]?.length ?? 0)));
175
- return pieces.map((p) => `${p.label.padEnd(width)} ${joinPieces({ ...p, cells: p.cells.map((c, i) => c.padEnd(columns?.[i] ?? 0)) })}`.trimEnd());
192
+ /** A labelled line's label as printed: the part's, and its line's name (`Pno.RH`, grammar 7.6). */
193
+ const labelOf = (l) => `${l.part ?? ""}${l.lineName === undefined ? "" : `.${l.lineName}`}`;
194
+ const labelsOf = (p) => [
195
+ p.label ?? "",
196
+ ...(p.lines ?? []).map((n) => (n ? `${p.label}.${n}` : (p.label ?? ""))),
197
+ ];
198
+ /** Score order: by part, then by the part's line, a bare line first. */
199
+ function scoreOf(l, parsed) {
200
+ const at = parsed.parts.findIndex((p) => p.label === l.part);
201
+ const line = l.lineName === undefined ? -1 : (parsed.parts[at]?.lines ?? []).indexOf(l.lineName);
202
+ return at * 10 + line + 1;
176
203
  }
177
- function systemsOf(lines) {
178
- const systems = new Map();
179
- for (const l of lines)
180
- if ((l.kind === "bars" || l.kind === "invalid") && l.system !== undefined)
181
- systems.set(l.system, [...(systems.get(l.system) ?? []), l]);
182
- return [...systems.values()];
204
+ /**
205
+ * The bar-line cells a row's cell `k` lies under: from its bar to the next
206
+ * bar, so a fermata, mark or direction falls in the cell before it, and
207
+ * any before the first bar in the first cell.
208
+ */
209
+ const spanOf = (k, bars, n) => [
210
+ k === 0 ? 0 : (bars[k] ?? 0),
211
+ (bars[k + 1] ?? n) - 1,
212
+ ];
213
+ const roomOf = (columns, [a, b]) => columns.slice(a, b + 1).reduce((x, y) => x + y, 0) + 3 * (b - a);
214
+ /** Each column's width: the widest of the bar lines' cells, widened for a row's cell that won't fit. */
215
+ function columnsOf(lines, rows, bars) {
216
+ const columns = (lines[0]?.cells ?? []).map((_, i) => Math.max(...lines.map((p) => p.cells[i]?.length ?? 0)));
217
+ for (const r of rows)
218
+ for (const [k, c] of r.cells.entries()) {
219
+ const room = roomOf(columns, spanOf(k, bars, columns.length));
220
+ const at = bars[k] ?? 0;
221
+ if (c.length > room)
222
+ columns[at] = (columns[at] ?? 0) + c.length - room;
223
+ }
224
+ return columns;
225
+ }
226
+ /**
227
+ * Bar lines and the lyric rows under them, labels padded to `width` and
228
+ * pipes lined up; a row's cell spans the cells of its bar (grammar 7.7).
229
+ */
230
+ function alignBlock(lines, rows, bars, width) {
231
+ const w = Math.max(width, ...rows.map((r) => r.label.length));
232
+ const columns = columnsOf(lines, rows, bars);
233
+ const print = (p, pad) => `${p.label.padEnd(w)} ${joinPieces({ ...p, cells: p.cells.map(pad) })}`.trimEnd();
234
+ const texts = new Map();
235
+ for (const p of lines)
236
+ texts.set(p.line, print(p, (c, i) => c.padEnd(columns[i] ?? 0)));
237
+ for (const r of rows)
238
+ texts.set(r.line, print(r, (c, k) => c.padEnd(roomOf(columns, spanOf(k, bars, columns.length)))));
239
+ return texts;
240
+ }
241
+ /** A system's lines in score order, labels padded and pipes lined up, with its lyric rows (section 8, grammar 7.4, 7.7). */
242
+ function alignSystem(block, parsed, beatsFor, edit) {
243
+ const system = block.lines;
244
+ const labelled = system[0]?.system !== undefined;
245
+ const width = labelled
246
+ ? Math.max(...parsed.parts.flatMap(labelsOf).map((label) => label.length))
247
+ : 0;
248
+ const sorted = labelled
249
+ ? [...system].sort((a, b) => scoreOf(a, parsed) - scoreOf(b, parsed))
250
+ : system;
251
+ // Sorted lines take the written lines' places, so the system's rows stay together.
252
+ const pieces = sorted.map((l, i) => ({
253
+ label: labelled ? labelOf(l) : "",
254
+ line: system[i]?.line ?? l.line,
255
+ ...barPieces(edit(l), beatsFor(l)),
256
+ }));
257
+ const rows = block.rows.map((r) => ({ label: lyricLabel(r), line: r.line, ...lyricPieces(r) }));
258
+ const bars = (system[0]?.cells ?? []).flatMap((c, i) => (isBar(c) ? [i] : []));
259
+ return alignBlock(pieces, rows, bars, width);
183
260
  }
184
- /** Canonical text for the lines of a multi-part chart's systems, by line number. */
261
+ /** A row lies just under its bars unless a heading comes between: under a replay heading it doesn't. */
262
+ const isUnder = (r, lines) => {
263
+ if (!r.covers.length)
264
+ return false;
265
+ const last = Math.max(...r.covers);
266
+ return !lines.some((l) => l.kind === "section" && l.line > last && l.line < r.line);
267
+ };
268
+ /** The block a bar line is in: its system's, or its own. */
269
+ const blockKey = (l) => (l.kind === "bars" || l.kind === "invalid") && l.system !== undefined
270
+ ? `system ${l.system}`
271
+ : `line ${l.line}`;
272
+ const inSystem = (l) => (l.kind === "bars" || l.kind === "invalid") && l.system !== undefined;
273
+ function blockFor(blocks, l) {
274
+ const block = blocks.get(blockKey(l)) ?? { lines: [], rows: [] };
275
+ blocks.set(blockKey(l), block);
276
+ return block;
277
+ }
278
+ /** Each system, and each bar line with rows just under it, with those rows (grammar 7.4, 7.7). */
279
+ function blocksOf(lines) {
280
+ const blocks = new Map();
281
+ for (const l of lines.filter(inSystem))
282
+ blockFor(blocks, l).lines.push(l);
283
+ const byLine = new Map(lines.map((l) => [l.line, l]));
284
+ for (const r of lines) {
285
+ if (r.kind !== "lyrics" || !isUnder(r, lines))
286
+ continue;
287
+ // An extracted part keeps only some of a system's lines.
288
+ const first = r.covers.map((n) => byLine.get(n)).find((l) => l !== undefined);
289
+ if (!first)
290
+ continue;
291
+ const block = blockFor(blocks, first);
292
+ if (!block.lines.length)
293
+ block.lines.push(first);
294
+ block.rows.push(r);
295
+ }
296
+ return [...blocks.values()];
297
+ }
298
+ /** Canonical text for the lines of systems and of bar lines with lyric rows, by line number. */
185
299
  function systemTexts(parsed, errored, beatsFor, edit) {
186
300
  const texts = new Map();
187
- for (const lines of systemsOf(parsed.lines)) {
301
+ for (const block of blocksOf(parsed.lines)) {
302
+ const { lines } = block;
188
303
  const valid = lines.filter((l) => l.kind === "bars" && !errored.has(l.line));
304
+ const rows = block.rows.filter((r) => !errored.has(r.line));
305
+ const labelled = valid[0]?.system !== undefined;
306
+ if (!labelled && !rows.length)
307
+ continue;
189
308
  // A system with an error is neither sorted nor padded, so the error's line stays where it was written.
190
- const printed = valid.length === lines.length
191
- ? alignSystem(valid, parsed, beatsFor, edit)
192
- : valid.map((l) => `${l.part} ${printLine(edit(l), beatsFor(l))}`);
193
- for (const [i, l] of valid.entries())
194
- texts.set(l.line, printed[i] ?? "");
309
+ if (valid.length === lines.length) {
310
+ for (const [line, text] of alignSystem({ lines: valid, rows }, parsed, beatsFor, edit))
311
+ texts.set(line, text);
312
+ continue;
313
+ }
314
+ for (const l of valid)
315
+ texts.set(l.line, `${labelOf(l)} ${printLine(edit(l), beatsFor(l))}`);
195
316
  }
196
317
  return texts;
197
318
  }
@@ -287,7 +408,11 @@ export function printPart(text, label) {
287
408
  .lines.filter((l) =>
288
409
  // A `part:` demoted to text (a shared label) would declare a part again in the extract.
289
410
  (l.kind === "text" && /^part\s*:/i.test(l.text)) ||
290
- ((l.kind === "part" || l.kind === "bars" || l.kind === "invalid") && !kept.has(l.line)))
411
+ ((l.kind === "part" ||
412
+ l.kind === "bars" ||
413
+ l.kind === "invalid" ||
414
+ l.kind === "lyrics") &&
415
+ !kept.has(l.line)))
291
416
  .map((l) => l.line));
292
417
  return printLines(text, parsed, (l) => l, skip);
293
418
  }
@@ -91,6 +91,8 @@ function addEntry(st, entry) {
91
91
  else
92
92
  st.items.push({ kind: "line", ...entry });
93
93
  }
94
+ /** Lines that may sit between endings (grammar 5.1): they mean nothing to the timeline. */
95
+ const BETWEEN_ENDINGS = new Set(["text", "credit", "lyrics", "break"]);
94
96
  /**
95
97
  * Pair `|:` and `:|` within one section's lines, with the endings that
96
98
  * follow a repeat (grammar 5.1). Problems are reported, and what cannot
@@ -106,7 +108,7 @@ export function pairRepeats(lines, error) {
106
108
  for (const l of lines) {
107
109
  if (l.kind === "bars" && l.ending)
108
110
  takeEnding(st, l, error);
109
- else if (st.endings && (l.kind === "text" || l.kind === "credit"))
111
+ else if (st.endings && BETWEEN_ENDINGS.has(l.kind))
110
112
  st.endings.between.push({ line: l, repeat: null });
111
113
  else {
112
114
  finish();
@@ -0,0 +1,28 @@
1
+ import type { Meter } from "./types.js";
2
+ /** A slot that may be dotted: a bar line's (grammar 2.2) or a lyric row's, which never is. */
3
+ type Member = {
4
+ kind: string;
5
+ dotted?: true;
6
+ };
7
+ /**
8
+ * How a group divides its slot (grammar 2.2), as fractions summing to 1:
9
+ * equally, or 3:1 (1:3) when one member of a pair is dotted.
10
+ */
11
+ export declare function memberShares(members: Member[]): number[];
12
+ /** A simple slot with its onset from the bar's start and its length, both in whole notes. */
13
+ export type Timed<T> = {
14
+ slot: T;
15
+ at: number;
16
+ length: number;
17
+ };
18
+ /**
19
+ * Each simple slot of a bar in order, with its onset and length in whole
20
+ * notes: the bar split evenly among its slots (grammar 2.1), and a group's
21
+ * slot among its members (2.2). A lyric row's slots are timed as a bar
22
+ * line's (7.7).
23
+ */
24
+ export declare function slotTimes<T extends Member>(slots: (T | {
25
+ kind: "group";
26
+ members: T[];
27
+ })[], meter: Meter): Timed<T>[];
28
+ export {};
@@ -0,0 +1,31 @@
1
+ /**
2
+ * How a group divides its slot (grammar 2.2), as fractions summing to 1:
3
+ * equally, or 3:1 (1:3) when one member of a pair is dotted.
4
+ */
5
+ export function memberShares(members) {
6
+ const dotted = members.findIndex((m) => m.dotted);
7
+ if (members.length === 2 && dotted >= 0)
8
+ return dotted === 0 ? [0.75, 0.25] : [0.25, 0.75];
9
+ return members.map(() => 1 / members.length);
10
+ }
11
+ /**
12
+ * Each simple slot of a bar in order, with its onset and length in whole
13
+ * notes: the bar split evenly among its slots (grammar 2.1), and a group's
14
+ * slot among its members (2.2). A lyric row's slots are timed as a bar
15
+ * line's (7.7).
16
+ */
17
+ export function slotTimes(slots, meter) {
18
+ const each = meter.n / meter.d / slots.length;
19
+ const out = [];
20
+ let at = 0;
21
+ for (const s of slots) {
22
+ const members = "members" in s ? s.members : [s];
23
+ const shares = memberShares(members);
24
+ members.forEach((slot, i) => {
25
+ const length = each * (shares[i] ?? 0);
26
+ out.push({ slot, at, length });
27
+ at += length;
28
+ });
29
+ }
30
+ return out;
31
+ }
@@ -0,0 +1,21 @@
1
+ import type { Syllable } from "./types.js";
2
+ /**
3
+ * A syllable token (grammar 4.3): `/` holds the syllable before, a
4
+ * trailing `-` continues the word, and `~` joins elided syllables on one
5
+ * note. Null when no syllable reads: the token is empty, a side of a `~`
6
+ * is, or it is a hold with a hyphen (`/-`), since a hold can't begin or
7
+ * continue a word.
8
+ */
9
+ export declare function readSyllable(text: string): Syllable | null;
10
+ /** The note part of a slot token and the syllable written after it, if any. */
11
+ export type Split = {
12
+ note: string;
13
+ syllable: string | null;
14
+ };
15
+ /**
16
+ * Split a group member at the colon after its note set's closing brace (and
17
+ * a rhythm's dot): `{C4}.:maz-` is `{C4}.` and `maz-`. A member with no
18
+ * brace splits at its first colon, so `G:la` is `G` and `la`, which the
19
+ * caller rejects: only a note set takes a syllable.
20
+ */
21
+ export declare function splitSyllable(member: string): Split;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * A syllable token (grammar 4.3): `/` holds the syllable before, a
3
+ * trailing `-` continues the word, and `~` joins elided syllables on one
4
+ * note. Null when no syllable reads: the token is empty, a side of a `~`
5
+ * is, or it is a hold with a hyphen (`/-`), since a hold can't begin or
6
+ * continue a word.
7
+ */
8
+ export function readSyllable(text) {
9
+ if (text === "/")
10
+ return { kind: "held" };
11
+ if (text === "/-")
12
+ return null;
13
+ const continues = text.endsWith("-");
14
+ const parts = (continues ? text.slice(0, -1) : text).split("~");
15
+ if (parts.some((p) => p === ""))
16
+ return null;
17
+ return { kind: "sung", parts, continues };
18
+ }
19
+ /**
20
+ * Split a group member at the colon after its note set's closing brace (and
21
+ * a rhythm's dot): `{C4}.:maz-` is `{C4}.` and `maz-`. A member with no
22
+ * brace splits at its first colon, so `G:la` is `G` and `la`, which the
23
+ * caller rejects: only a note set takes a syllable.
24
+ */
25
+ export function splitSyllable(member) {
26
+ const brace = member.indexOf("}");
27
+ const after = member[brace + 1] === "." ? brace + 2 : brace + 1;
28
+ const colon = brace < 0 ? member.indexOf(":") : member[after] === ":" ? after : -1;
29
+ if (colon < 0)
30
+ return { note: member, syllable: null };
31
+ return { note: member.slice(0, colon), syllable: member.slice(colon + 1) };
32
+ }
@@ -4,6 +4,8 @@ type BarsLine = Extract<Line, {
4
4
  }>;
5
5
  /** The marks of a bar line that shape the timeline, which every line of a system shares (grammar 7.4). */
6
6
  export declare function structureOf(l: BarsLine): string;
7
+ /** The key a part's line is grouped and played by: its label, and its line's name if any (grammar 7.6). */
8
+ export declare const streamKey: (part: string, lineName?: string) => string;
7
9
  /**
8
10
  * Group a multi-part chart's labelled bar lines into systems and check that
9
11
  * each system's lines share their bars and structure. A line that differs is
@@ -33,6 +33,21 @@ function differs(l, ref) {
33
33
  return null;
34
34
  }
35
35
  const isLabelled = (l) => (l.kind === "bars" || l.kind === "invalid") && l.part !== undefined;
36
+ /** The key a part's line is grouped and played by: its label, and its line's name if any (grammar 7.6). */
37
+ export const streamKey = (part, lineName) => (lineName === undefined ? part : `${part}.${lineName}`).toLowerCase();
38
+ /**
39
+ * What a line takes in its system, and what it can't follow there (grammar
40
+ * 7.6): each line once, and a part's named lines may follow its bare line
41
+ * but a bare line can't follow them, so a bare line after its part's
42
+ * lines starts a new system, as it did before bare lines could join.
43
+ */
44
+ function claimsOf(l) {
45
+ const part = (l.part ?? "").toLowerCase();
46
+ const own = streamKey(part, l.lineName);
47
+ if (l.lineName === undefined)
48
+ return { takes: [own], clashes: [own, `${part}#lines`] };
49
+ return { takes: [own, `${part}#lines`], clashes: [own] };
50
+ }
36
51
  /** Number each run of labelled lines with no label twice (grammar 7.4). */
37
52
  function numberSystems(lines) {
38
53
  let system = -1;
@@ -42,12 +57,13 @@ function numberSystems(lines) {
42
57
  seen = null;
43
58
  return l;
44
59
  }
45
- const label = l.part ?? "";
46
- if (!seen || seen.has(label)) {
60
+ const { takes, clashes } = claimsOf(l);
61
+ if (!seen || clashes.some((c) => seen?.has(c))) {
47
62
  system++;
48
63
  seen = new Set();
49
64
  }
50
- seen.add(label);
65
+ for (const c of takes)
66
+ seen.add(c);
51
67
  return { ...l, system };
52
68
  });
53
69
  }
@@ -1,4 +1,5 @@
1
1
  import type { ChordRecord } from "../chords/types.js";
2
+ import type { ClefName, InstrumentName } from "./instruments.js";
2
3
  export type Severity = "error" | "warning";
3
4
  export type ChartDiagnostic = {
4
5
  line: number;
@@ -28,11 +29,14 @@ export type TempoChange = {
28
29
  /** `tempo:` gives either `tempo` (a steady tempo) or `tempoChange`, never both. */
29
30
  /**
30
31
  * The part a chart is written for (grammar 7.3): `part: Electric Guitar 1`,
31
- * or with a short label, `part: Gtr = Electric Guitar 1`.
32
+ * or with a short label, `part: Gtr = Electric Guitar 1`; `instrument:`
33
+ * and `clef:` may follow, and are present only when written.
32
34
  */
33
35
  export type Part = {
34
36
  name: string;
35
37
  label?: string;
38
+ instrument?: InstrumentName;
39
+ clef?: ClefName;
36
40
  };
37
41
  export type Directives = {
38
42
  key?: Key;
@@ -54,18 +58,46 @@ export type Articulation = "accent" | "hit";
54
58
  * sixteenth, taken from the slot played just before it.
55
59
  */
56
60
  export type Push = "eighth" | "sixteenth";
61
+ /** `+` presses the sustain pedal, or changes it when it is down; `*` lifts it (grammar 2.9). */
62
+ export type Pedal = "press" | "release";
63
+ /** A syllable sung on a note (grammar 4.3). `held` is `:/`. `parts` holds elided syllables (`the~end`). */
64
+ export type Syllable = {
65
+ kind: "sung";
66
+ parts: string[];
67
+ continues: boolean;
68
+ } | {
69
+ kind: "held";
70
+ };
57
71
  /**
58
72
  * A chord slot holds a chord symbol or a note set; `chord.kind` tells
59
73
  * which. `voicing` is the exact notes written after a chord's name
60
- * (`Cmaj7{E3 G3 B3}`, grammar 4.2). The optional fields are present only
61
- * when written.
74
+ * (`Cmaj7{E3 G3 B3}`, grammar 4.2). `syllable` is sung on a note set
75
+ * (`{G4}:maz-`, grammar 4.3), never on a chord name or a voicing. The
76
+ * optional fields are present only when written.
77
+ */
78
+ /**
79
+ * A slot of a lyric row (grammar 7.7): a syllable, `/` holding the one
80
+ * before, `--` a breath (nothing sung), or `_` splitting the slot.
62
81
  */
63
- export type SimpleSlot = {
82
+ export type LyricSlot = {
83
+ kind: "syllable";
84
+ syllable: Syllable;
85
+ } | {
86
+ kind: "hold";
87
+ } | {
88
+ kind: "breath";
89
+ } | {
90
+ kind: "group";
91
+ members: LyricSlot[];
92
+ };
93
+ export type SimpleSlot = ({
64
94
  kind: "chord";
65
95
  chord: ChordRecord;
66
96
  voicing?: ChordRecord;
97
+ pedal?: Pedal;
67
98
  articulation?: Articulation;
68
99
  push?: Push;
100
+ syllable?: Syllable;
69
101
  } | {
70
102
  kind: "hold";
71
103
  } | {
@@ -76,6 +108,9 @@ export type SimpleSlot = {
76
108
  push?: Push;
77
109
  } | {
78
110
  kind: "unknown";
111
+ }) & {
112
+ /** A dotted member of a two-member group (grammar 2.2): three quarters of its slot. */
113
+ dotted?: true;
79
114
  };
80
115
  export type Slot = SimpleSlot | {
81
116
  kind: "group";
@@ -166,14 +201,38 @@ export type Line = {
166
201
  ending: number[] | null;
167
202
  /** The declared label of the part whose line this is (grammar 7.4); absent on a tutti line and in a single-part chart. */
168
203
  part?: string;
204
+ /** The part's line this is (`RH` in `Pno.RH`, grammar 7.6), as first spelled; absent on a part's bare line. */
205
+ lineName?: string;
169
206
  /** Which system a labelled line is in, from 0 in chart order. */
170
207
  system?: number;
171
208
  /** Set when the line's bars or structure differ from its system's (an error): its part is tacet there. */
172
209
  dropped?: true;
173
- } | {
210
+ }
211
+ /** A text line; `escaped` when written with a leading `\` (grammar 1), which `text` leaves off. */
212
+ | {
174
213
  kind: "text";
175
214
  line: number;
176
215
  text: string;
216
+ escaped?: true;
217
+ }
218
+ /** `---` alone (grammar 1, 7.4): ends a system, and means nothing else. */
219
+ | {
220
+ kind: "break";
221
+ line: number;
222
+ }
223
+ /**
224
+ * `lyrics:` or `lyrics N:` then a bar line (grammar 7.7): syllables on the
225
+ * beats, one cell per bar. `verse` is N, null when unnumbered. `covers`
226
+ * holds the source lines of the bar lines it lies under, in order: one,
227
+ * a system's lines, or under a replay heading the replayed section's
228
+ * line; empty when it covers none (an error).
229
+ */
230
+ | {
231
+ kind: "lyrics";
232
+ line: number;
233
+ verse: number | null;
234
+ cells: LyricSlot[][];
235
+ covers: number[];
177
236
  }
178
237
  /** `composer: …` and the other credit lines (grammar 7.5). */
179
238
  | {
@@ -192,6 +251,7 @@ export type Line = {
192
251
  text: string;
193
252
  written: number;
194
253
  part?: string;
254
+ lineName?: string;
195
255
  system?: number;
196
256
  };
197
257
  export type PlayedBar = {
@@ -233,12 +293,50 @@ export type PlayedBar = {
233
293
  * `slots` and `words` are the first part's.
234
294
  */
235
295
  parts?: PartBar[];
296
+ /** A single part's lines (grammar 7.6), as on `PartBar`: in a single-part chart or an extracted part that writes lines. */
297
+ lines?: LineBar[];
298
+ /**
299
+ * The words sung in this bar (grammar 4.3, 7.7), one entry per verse in
300
+ * verse order: on a repeat's pass N only verse N; absent when none.
301
+ */
302
+ lyrics?: PlayedLyrics[];
303
+ };
304
+ /**
305
+ * A syllable as played: `at` is its onset in whole notes from the bar's
306
+ * start; `note` is true when a note of the singing line starts there.
307
+ */
308
+ export type PlayedSyllable = {
309
+ at: number;
310
+ syllable: Syllable;
311
+ note: boolean;
312
+ };
313
+ /**
314
+ * One verse's syllables in a played bar; `part` is the label of the part
315
+ * singing (absent in a chart with no voice part).
316
+ */
317
+ export type PlayedLyrics = {
318
+ verse: number;
319
+ part?: string;
320
+ syllables: PlayedSyllable[];
236
321
  };
237
- /** One part's share of a played bar (grammar 7.4): the line it is written on, its slots and words. */
322
+ /** One part's line's share of a played bar (grammar 7.6): its name, the line it is written on, its slots and words. */
323
+ export type LineBar = {
324
+ name: string;
325
+ line: number;
326
+ slots: Slot[];
327
+ words?: Words[];
328
+ };
329
+ /**
330
+ * One part's share of a played bar (grammar 7.4): the line it is written
331
+ * on, its slots and words. A part that writes lines (7.6) has `lines`, one
332
+ * per line playing there in score order, and its first playing line's
333
+ * `line`, `slots` and `words`.
334
+ */
238
335
  export type PartBar = {
239
336
  line: number;
240
337
  slots: Slot[];
241
338
  words?: Words[];
339
+ lines?: LineBar[];
242
340
  } | null;
243
341
  /** An open repeat shows one pass; the number of passes is unknown. */
244
342
  export type ChartEvent = {
@@ -266,6 +364,16 @@ export type SectionOccurrence = {
266
364
  */
267
365
  form: number;
268
366
  };
367
+ /**
368
+ * A declared part as the parse reports it: `lines` names its lines in score
369
+ * order (grammar 7.6), present only when it writes some. `sings`, on the
370
+ * part that sings (grammar 7.7), names the line whose notes carry the
371
+ * lyrics, or is "" for its bare line; absent when it writes no notes.
372
+ */
373
+ export type DeclaredPart = Part & {
374
+ lines?: string[];
375
+ sings?: string;
376
+ };
269
377
  export type ChartParse = {
270
378
  title: string | null;
271
379
  /**
@@ -273,9 +381,9 @@ export type ChartParse = {
273
381
  * none or several.
274
382
  * @deprecated use `parts`.
275
383
  */
276
- part: Part | null;
384
+ part: DeclaredPart | null;
277
385
  /** Every part the chart declares, in score order (grammar 7.4); empty when none. */
278
- parts: Part[];
386
+ parts: DeclaredPart[];
279
387
  /** The credit lines (grammar 7.5); each list empty when none is written. */
280
388
  credits: Credits;
281
389
  lines: Line[];