barmark 0.16.0 → 0.17.1
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.
- package/CHANGELOG.md +123 -1
- package/README.md +73 -0
- package/dist/chart/barLine.js +77 -8
- package/dist/chart/credits.d.ts +1 -1
- package/dist/chart/credits.js +5 -1
- package/dist/chart/document.js +30 -3
- package/dist/chart/expand.d.ts +17 -1
- package/dist/chart/expand.js +46 -20
- package/dist/chart/lines.js +34 -2
- package/dist/chart/lyricRows.d.ts +25 -0
- package/dist/chart/lyricRows.js +178 -0
- package/dist/chart/parse.d.ts +3 -1
- package/dist/chart/parse.js +74 -21
- package/dist/chart/parts.js +2 -2
- package/dist/chart/print.js +136 -24
- package/dist/chart/repeats.js +3 -1
- package/dist/chart/shares.d.ts +24 -2
- package/dist/chart/shares.js +21 -0
- package/dist/chart/syllable.d.ts +21 -0
- package/dist/chart/syllable.js +32 -0
- package/dist/chart/systems.js +7 -6
- package/dist/chart/types.d.ts +80 -4
- package/dist/chart/verses.d.ts +55 -0
- package/dist/chart/verses.js +351 -0
- package/dist/chords/intervals.js +4 -1
- package/dist/chords/vocabulary.js +3 -1
- package/package.json +1 -1
package/dist/chart/print.js
CHANGED
|
@@ -51,9 +51,20 @@ function printMarks(s) {
|
|
|
51
51
|
const pedal = s.kind === "chord" && s.pedal ? PEDALS[s.pedal] : "";
|
|
52
52
|
return pedal + push + (s.kind === "chord" && s.articulation ? ARTICULATIONS[s.articulation] : "");
|
|
53
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
|
+
};
|
|
54
64
|
function printSimple(s) {
|
|
55
65
|
const body = s.kind === "chord" ? s.chord.canonical + (s.voicing?.canonical ?? "") : SYMBOLS[s.kind];
|
|
56
|
-
|
|
66
|
+
const sung = s.kind === "chord" && s.syllable ? `:${printSyllable(s.syllable)}` : "";
|
|
67
|
+
return printMarks(s) + body + (s.dotted ? "." : "") + sung;
|
|
57
68
|
}
|
|
58
69
|
/** A slot in canonical spelling; a group's members are joined with `_`. */
|
|
59
70
|
export function printSlot(s) {
|
|
@@ -127,6 +138,14 @@ function printDirectives(d) {
|
|
|
127
138
|
parts.push(`feel: ${d.feel}${d.swingPercent === undefined ? "" : ` ${d.swingPercent}%`}`);
|
|
128
139
|
return parts.join(", ");
|
|
129
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
|
+
});
|
|
130
149
|
/** A bar line's opening, cells and closing, each printed. */
|
|
131
150
|
function barPieces(l, beats) {
|
|
132
151
|
return {
|
|
@@ -154,6 +173,10 @@ export function printLine(l, beats = []) {
|
|
|
154
173
|
return `${l.role}: ${l.text}`;
|
|
155
174
|
case "bars":
|
|
156
175
|
return joinPieces(barPieces(l, beats));
|
|
176
|
+
case "break":
|
|
177
|
+
return "---";
|
|
178
|
+
case "lyrics":
|
|
179
|
+
return `${lyricLabel(l)} ${joinPieces(lyricPieces(l))}`;
|
|
157
180
|
default:
|
|
158
181
|
return l.text;
|
|
159
182
|
}
|
|
@@ -170,7 +193,7 @@ export function printChart(text) {
|
|
|
170
193
|
const labelOf = (l) => `${l.part ?? ""}${l.lineName === undefined ? "" : `.${l.lineName}`}`;
|
|
171
194
|
const labelsOf = (p) => [
|
|
172
195
|
p.label ?? "",
|
|
173
|
-
...(p.lines ?? []).map((n) => `${p.label}.${n}`),
|
|
196
|
+
...(p.lines ?? []).map((n) => (n ? `${p.label}.${n}` : (p.label ?? ""))),
|
|
174
197
|
];
|
|
175
198
|
/** Score order: by part, then by the part's line, a bare line first. */
|
|
176
199
|
function scoreOf(l, parsed) {
|
|
@@ -178,33 +201,118 @@ function scoreOf(l, parsed) {
|
|
|
178
201
|
const line = l.lineName === undefined ? -1 : (parsed.parts[at]?.lines ?? []).indexOf(l.lineName);
|
|
179
202
|
return at * 10 + line + 1;
|
|
180
203
|
}
|
|
181
|
-
/**
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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;
|
|
189
240
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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);
|
|
196
260
|
}
|
|
197
|
-
/**
|
|
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. */
|
|
198
299
|
function systemTexts(parsed, errored, beatsFor, edit) {
|
|
199
300
|
const texts = new Map();
|
|
200
|
-
for (const
|
|
301
|
+
for (const block of blocksOf(parsed.lines)) {
|
|
302
|
+
const { lines } = block;
|
|
201
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;
|
|
202
308
|
// A system with an error is neither sorted nor padded, so the error's line stays where it was written.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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))}`);
|
|
208
316
|
}
|
|
209
317
|
return texts;
|
|
210
318
|
}
|
|
@@ -300,7 +408,11 @@ export function printPart(text, label) {
|
|
|
300
408
|
.lines.filter((l) =>
|
|
301
409
|
// A `part:` demoted to text (a shared label) would declare a part again in the extract.
|
|
302
410
|
(l.kind === "text" && /^part\s*:/i.test(l.text)) ||
|
|
303
|
-
((l.kind === "part" ||
|
|
411
|
+
((l.kind === "part" ||
|
|
412
|
+
l.kind === "bars" ||
|
|
413
|
+
l.kind === "invalid" ||
|
|
414
|
+
l.kind === "lyrics") &&
|
|
415
|
+
!kept.has(l.line)))
|
|
304
416
|
.map((l) => l.line));
|
|
305
417
|
return printLines(text, parsed, (l) => l, skip);
|
|
306
418
|
}
|
package/dist/chart/repeats.js
CHANGED
|
@@ -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
|
|
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();
|
package/dist/chart/shares.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
import type {
|
|
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
|
+
};
|
|
2
7
|
/**
|
|
3
8
|
* How a group divides its slot (grammar 2.2), as fractions summing to 1:
|
|
4
9
|
* equally, or 3:1 (1:3) when one member of a pair is dotted.
|
|
5
10
|
*/
|
|
6
|
-
export declare function memberShares(members:
|
|
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 {};
|
package/dist/chart/shares.js
CHANGED
|
@@ -8,3 +8,24 @@ export function memberShares(members) {
|
|
|
8
8
|
return dotted === 0 ? [0.75, 0.25] : [0.25, 0.75];
|
|
9
9
|
return members.map(() => 1 / members.length);
|
|
10
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
|
+
}
|
package/dist/chart/systems.js
CHANGED
|
@@ -36,16 +36,17 @@ const isLabelled = (l) => (l.kind === "bars" || l.kind === "invalid") && l.part
|
|
|
36
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
37
|
export const streamKey = (part, lineName) => (lineName === undefined ? part : `${part}.${lineName}`).toLowerCase();
|
|
38
38
|
/**
|
|
39
|
-
* What a line takes in its system, and what it can't
|
|
40
|
-
*
|
|
41
|
-
*
|
|
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.
|
|
42
43
|
*/
|
|
43
44
|
function claimsOf(l) {
|
|
44
45
|
const part = (l.part ?? "").toLowerCase();
|
|
45
|
-
if (l.lineName === undefined)
|
|
46
|
-
return { takes: [part, `${part}#bare`], clashes: [part, `${part}#lines`] };
|
|
47
46
|
const own = streamKey(part, l.lineName);
|
|
48
|
-
|
|
47
|
+
if (l.lineName === undefined)
|
|
48
|
+
return { takes: [own], clashes: [own, `${part}#lines`] };
|
|
49
|
+
return { takes: [own, `${part}#lines`], clashes: [own] };
|
|
49
50
|
}
|
|
50
51
|
/** Number each run of labelled lines with no label twice (grammar 7.4). */
|
|
51
52
|
function numberSystems(lines) {
|
package/dist/chart/types.d.ts
CHANGED
|
@@ -60,12 +60,36 @@ export type Articulation = "accent" | "hit";
|
|
|
60
60
|
export type Push = "eighth" | "sixteenth";
|
|
61
61
|
/** `+` presses the sustain pedal, or changes it when it is down; `*` lifts it (grammar 2.9). */
|
|
62
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
|
+
};
|
|
63
71
|
/**
|
|
64
72
|
* A chord slot holds a chord symbol or a note set; `chord.kind` tells
|
|
65
73
|
* which. `voicing` is the exact notes written after a chord's name
|
|
66
|
-
* (`Cmaj7{E3 G3 B3}`, grammar 4.2).
|
|
67
|
-
*
|
|
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.
|
|
68
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.
|
|
81
|
+
*/
|
|
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
|
+
};
|
|
69
93
|
export type SimpleSlot = ({
|
|
70
94
|
kind: "chord";
|
|
71
95
|
chord: ChordRecord;
|
|
@@ -73,6 +97,7 @@ export type SimpleSlot = ({
|
|
|
73
97
|
pedal?: Pedal;
|
|
74
98
|
articulation?: Articulation;
|
|
75
99
|
push?: Push;
|
|
100
|
+
syllable?: Syllable;
|
|
76
101
|
} | {
|
|
77
102
|
kind: "hold";
|
|
78
103
|
} | {
|
|
@@ -182,10 +207,32 @@ export type Line = {
|
|
|
182
207
|
system?: number;
|
|
183
208
|
/** Set when the line's bars or structure differ from its system's (an error): its part is tacet there. */
|
|
184
209
|
dropped?: true;
|
|
185
|
-
}
|
|
210
|
+
}
|
|
211
|
+
/** A text line; `escaped` when written with a leading `\` (grammar 1), which `text` leaves off. */
|
|
212
|
+
| {
|
|
186
213
|
kind: "text";
|
|
187
214
|
line: number;
|
|
188
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[];
|
|
189
236
|
}
|
|
190
237
|
/** `composer: …` and the other credit lines (grammar 7.5). */
|
|
191
238
|
| {
|
|
@@ -248,6 +295,29 @@ export type PlayedBar = {
|
|
|
248
295
|
parts?: PartBar[];
|
|
249
296
|
/** A single part's lines (grammar 7.6), as on `PartBar`: in a single-part chart or an extracted part that writes lines. */
|
|
250
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[];
|
|
251
321
|
};
|
|
252
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. */
|
|
253
323
|
export type LineBar = {
|
|
@@ -294,9 +364,15 @@ export type SectionOccurrence = {
|
|
|
294
364
|
*/
|
|
295
365
|
form: number;
|
|
296
366
|
};
|
|
297
|
-
/**
|
|
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
|
+
*/
|
|
298
373
|
export type DeclaredPart = Part & {
|
|
299
374
|
lines?: string[];
|
|
375
|
+
sings?: string;
|
|
300
376
|
};
|
|
301
377
|
export type ChartParse = {
|
|
302
378
|
title: string | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Sing } from "./expand.js";
|
|
2
|
+
import type { ChartDiagnostic, DeclaredPart, Line } from "./types.js";
|
|
3
|
+
type LyricsLine = Extract<Line, {
|
|
4
|
+
kind: "lyrics";
|
|
5
|
+
}>;
|
|
6
|
+
/**
|
|
7
|
+
* Who sings a chart's words (grammar 7.7): a part, by its label, and the
|
|
8
|
+
* line whose notes carry them (`sings`, "" for the bare line; absent when
|
|
9
|
+
* the part writes no notes). A chart with no parts whose notes carry
|
|
10
|
+
* syllables sings with no label.
|
|
11
|
+
*/
|
|
12
|
+
export type Singer = {
|
|
13
|
+
part: DeclaredPart | null;
|
|
14
|
+
label?: string;
|
|
15
|
+
sings?: string;
|
|
16
|
+
};
|
|
17
|
+
/** The parts as the parse reports them: each that sings with the line it sings on. */
|
|
18
|
+
export declare function withSings(parts: DeclaredPart[], singers: Singer[]): DeclaredPart[];
|
|
19
|
+
/** Rows by what they cover: the replay heading they are written under ("" for none) and a covered line. */
|
|
20
|
+
type Rows = Map<string, LyricsLine[]>;
|
|
21
|
+
/**
|
|
22
|
+
* The words each played bar sings (grammar 4.3, 7.7), for `expand` to
|
|
23
|
+
* attach as it plays the line that sings: the syllables on its notes
|
|
24
|
+
* (verse 1) and the rows over it, or under a replay heading with rows for
|
|
25
|
+
* the line, that replay's rows alone; on a repeat's pass N, verse N. The
|
|
26
|
+
* singer's melody is checked as it plays: a row's syllable where no note
|
|
27
|
+
* starts, a `:/` with nothing sung before it to hold, and a pass that
|
|
28
|
+
* sings nothing where other passes sing, warn. `finish`, after playing,
|
|
29
|
+
* warns of each numbered row never sung.
|
|
30
|
+
*/
|
|
31
|
+
declare function singing(rows: Rows, who: Singer | null): {
|
|
32
|
+
sing: Sing;
|
|
33
|
+
diagnostics: ChartDiagnostic[];
|
|
34
|
+
finish: () => void;
|
|
35
|
+
};
|
|
36
|
+
/** One voice that sings (grammar 7.7): its singer, null for the chart's words when no part sings, and its words. */
|
|
37
|
+
export type Voice = {
|
|
38
|
+
singer: Singer | null;
|
|
39
|
+
} & ReturnType<typeof singing>;
|
|
40
|
+
/**
|
|
41
|
+
* Every voice of a chart: each part that sings, the owner with the lyric
|
|
42
|
+
* rows; or, when no part sings, the chart's words alone. `diagnostics`
|
|
43
|
+
* are the rows' errors, `all` the parts that sing.
|
|
44
|
+
*/
|
|
45
|
+
export declare function voicesOf(lines: Line[], parts: DeclaredPart[]): {
|
|
46
|
+
voices: Voice[];
|
|
47
|
+
all: Singer[];
|
|
48
|
+
owner: Singer | null;
|
|
49
|
+
diagnostics: ChartDiagnostic[];
|
|
50
|
+
};
|
|
51
|
+
/** The voices an extract of a part, or of one of its lines, sings: its own, and the chart's words when no part sings. */
|
|
52
|
+
export declare function voicesIn(voices: Voice[], part: DeclaredPart, lineName?: string): Voice[];
|
|
53
|
+
/** Several voices' words on one line (verse order, then the voices' order), or none. */
|
|
54
|
+
export declare function together(sings: Sing[]): Sing | undefined;
|
|
55
|
+
export {};
|