barmark 0.21.0 → 0.23.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.
- package/CHANGELOG.md +191 -1
- package/README.md +8 -4
- package/dist/chart/barLine.d.ts +7 -3
- package/dist/chart/barLine.js +110 -76
- package/dist/chart/document.js +25 -9
- package/dist/chart/endingLines.d.ts +13 -0
- package/dist/chart/endingLines.js +136 -0
- package/dist/chart/expand.d.ts +20 -7
- package/dist/chart/expand.js +149 -39
- package/dist/chart/index.d.ts +2 -1
- package/dist/chart/index.js +2 -1
- package/dist/chart/lines.js +27 -11
- package/dist/chart/lyricRows.js +20 -5
- package/dist/chart/parse.d.ts +3 -1
- package/dist/chart/parse.js +68 -25
- package/dist/chart/parts.d.ts +3 -1
- package/dist/chart/parts.js +131 -23
- package/dist/chart/pedal.d.ts +5 -1
- package/dist/chart/pedal.js +53 -20
- package/dist/chart/pickup.d.ts +15 -0
- package/dist/chart/pickup.js +41 -0
- package/dist/chart/print.d.ts +11 -1
- package/dist/chart/print.js +72 -13
- package/dist/chart/repeats.d.ts +2 -2
- package/dist/chart/repeats.js +27 -15
- package/dist/chart/shares.d.ts +7 -0
- package/dist/chart/shares.js +20 -0
- package/dist/chart/systems.js +22 -6
- package/dist/chart/transpose.d.ts +3 -1
- package/dist/chart/transpose.js +20 -3
- package/dist/chart/types.d.ts +23 -5
- package/dist/chart/verses.d.ts +14 -3
- package/dist/chart/verses.js +365 -103
- package/dist/chords/parse.js +48 -25
- package/dist/chords/stacked.d.ts +45 -0
- package/dist/chords/stacked.js +122 -0
- package/package.json +2 -2
package/dist/chart/print.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { isBar } from "./barLine.js";
|
|
1
|
+
import { isBar, simpleSlots } from "./barLine.js";
|
|
2
2
|
import { printDirection } from "./direction.js";
|
|
3
3
|
import { beatsOf } from "./directives.js";
|
|
4
4
|
import { readDocument } from "./document.js";
|
|
5
5
|
import { printKey } from "./keys.js";
|
|
6
6
|
import { extractPart, parseChart } from "./parse.js";
|
|
7
|
+
import { splitSyllable } from "./syllable.js";
|
|
7
8
|
/** A slot with no attack of its own continues whatever sounds before it. A repeated chord name is a re-attack. */
|
|
8
9
|
function continues(sounding, s) {
|
|
9
10
|
if (s.kind === "hold")
|
|
@@ -62,7 +63,16 @@ const printLyricSlot = (s) => {
|
|
|
62
63
|
return printSyllable(s.syllable);
|
|
63
64
|
return s.kind === "hold" ? "/" : "--";
|
|
64
65
|
};
|
|
66
|
+
/** An unreadable slot as written: a dotted member's dot goes back before its syllable. */
|
|
67
|
+
function printUnread(text, dotted) {
|
|
68
|
+
if (!dotted)
|
|
69
|
+
return text;
|
|
70
|
+
const { note, syllable } = splitSyllable(text);
|
|
71
|
+
return `${note}.${syllable === null ? "" : `:${syllable}`}`;
|
|
72
|
+
}
|
|
65
73
|
function printSimple(s) {
|
|
74
|
+
if (s.kind === "unknown" && s.text !== undefined)
|
|
75
|
+
return printUnread(s.text, Boolean(s.dotted));
|
|
66
76
|
const body = s.kind === "chord" ? s.chord.canonical + (s.voicing?.canonical ?? "") : SYMBOLS[s.kind];
|
|
67
77
|
const sung = s.kind === "chord" && s.syllable ? `:${printSyllable(s.syllable)}` : "";
|
|
68
78
|
return printMarks(s) + body + (s.dotted ? "." : "") + sung;
|
|
@@ -189,9 +199,25 @@ const labelsOf = (p) => [
|
|
|
189
199
|
p.label ?? "",
|
|
190
200
|
...(p.lines ?? []).map((n) => (n ? `${p.label}.${n}` : (p.label ?? ""))),
|
|
191
201
|
];
|
|
202
|
+
/** The parts' places by label (the first of each) and their widest label, found once for every system printed. */
|
|
203
|
+
const partsKnown = new WeakMap();
|
|
204
|
+
function partsIndex(parts) {
|
|
205
|
+
const known = partsKnown.get(parts);
|
|
206
|
+
if (known)
|
|
207
|
+
return known;
|
|
208
|
+
const at = new Map();
|
|
209
|
+
parts.forEach((p, i) => {
|
|
210
|
+
if (!at.has(p.label))
|
|
211
|
+
at.set(p.label, i);
|
|
212
|
+
});
|
|
213
|
+
const width = Math.max(...parts.flatMap(labelsOf).map((label) => label.length));
|
|
214
|
+
const made = { at, width };
|
|
215
|
+
partsKnown.set(parts, made);
|
|
216
|
+
return made;
|
|
217
|
+
}
|
|
192
218
|
/** Score order: by part, then by the part's line, a bare line first. */
|
|
193
219
|
function scoreOf(l, parsed) {
|
|
194
|
-
const at = parsed.parts.
|
|
220
|
+
const at = partsIndex(parsed.parts).at.get(l.part) ?? -1;
|
|
195
221
|
const line = l.lineName === undefined ? -1 : (parsed.parts[at]?.lines ?? []).indexOf(l.lineName);
|
|
196
222
|
return at * 10 + line + 1;
|
|
197
223
|
}
|
|
@@ -236,9 +262,7 @@ function alignBlock(lines, rows, bars, width) {
|
|
|
236
262
|
function alignSystem(block, parsed, beatsFor, edit) {
|
|
237
263
|
const system = block.lines;
|
|
238
264
|
const labelled = system[0]?.system !== undefined;
|
|
239
|
-
const width = labelled
|
|
240
|
-
? Math.max(...parsed.parts.flatMap(labelsOf).map((label) => label.length))
|
|
241
|
-
: 0;
|
|
265
|
+
const width = labelled ? partsIndex(parsed.parts).width : 0;
|
|
242
266
|
const sorted = labelled
|
|
243
267
|
? [...system].sort((a, b) => scoreOf(a, parsed) - scoreOf(b, parsed))
|
|
244
268
|
: system;
|
|
@@ -261,7 +285,7 @@ function alignSystem(block, parsed, beatsFor, edit) {
|
|
|
261
285
|
const isUnder = (r, headings) => {
|
|
262
286
|
if (!r.covers.length)
|
|
263
287
|
return false;
|
|
264
|
-
const last =
|
|
288
|
+
const last = lastOf(r.covers);
|
|
265
289
|
let lo = 0;
|
|
266
290
|
let hi = headings.length;
|
|
267
291
|
while (lo < hi) {
|
|
@@ -273,6 +297,16 @@ const isUnder = (r, headings) => {
|
|
|
273
297
|
}
|
|
274
298
|
return !((headings[lo] ?? Number.POSITIVE_INFINITY) < r.line);
|
|
275
299
|
};
|
|
300
|
+
/** The last line a row covers; rows share one list per unit, so it is found once for all of them. */
|
|
301
|
+
const lastKnown = new WeakMap();
|
|
302
|
+
function lastOf(covers) {
|
|
303
|
+
let last = lastKnown.get(covers);
|
|
304
|
+
if (last === undefined) {
|
|
305
|
+
last = Math.max(...covers);
|
|
306
|
+
lastKnown.set(covers, last);
|
|
307
|
+
}
|
|
308
|
+
return last;
|
|
309
|
+
}
|
|
276
310
|
/** The block a bar line is in: its system's, or its own. */
|
|
277
311
|
const blockKey = (l) => (l.kind === "bars" || l.kind === "invalid") && l.system !== undefined
|
|
278
312
|
? `system ${l.system}`
|
|
@@ -290,11 +324,18 @@ function blocksOf(lines) {
|
|
|
290
324
|
blockFor(blocks, l).lines.push(l);
|
|
291
325
|
const byLine = new Map(lines.map((l) => [l.line, l]));
|
|
292
326
|
const headings = lines.flatMap((l) => (l.kind === "section" ? [l.line] : []));
|
|
327
|
+
// Rows share one list of covered lines per unit: its first kept line is found once.
|
|
328
|
+
const firstOf = new Map();
|
|
329
|
+
const firstKept = (covers) => {
|
|
330
|
+
if (!firstOf.has(covers))
|
|
331
|
+
firstOf.set(covers, covers.map((n) => byLine.get(n)).find((l) => l !== undefined));
|
|
332
|
+
return firstOf.get(covers);
|
|
333
|
+
};
|
|
293
334
|
for (const r of lines) {
|
|
294
335
|
if (r.kind !== "lyrics" || !isUnder(r, headings))
|
|
295
336
|
continue;
|
|
296
337
|
// An extracted part keeps only some of a system's lines.
|
|
297
|
-
const first = r.covers
|
|
338
|
+
const first = firstKept(r.covers);
|
|
298
339
|
if (!first)
|
|
299
340
|
continue;
|
|
300
341
|
const block = blockFor(blocks, first);
|
|
@@ -327,16 +368,17 @@ function systemTexts(parsed, errored, beatsFor, edit) {
|
|
|
327
368
|
}
|
|
328
369
|
/** Each line's beat counts on its first play, every part's lines included. */
|
|
329
370
|
function beatsOfLines(parsed) {
|
|
330
|
-
|
|
371
|
+
// Each line's bar count, once: counting it again for every bar played costs the line's bars squared.
|
|
372
|
+
const cellsOf = new Map(parsed.lines.map((l) => [l.line, l.kind === "bars" ? l.cells.filter(isBar).length : 0]));
|
|
331
373
|
const firstPlay = new Map();
|
|
332
374
|
for (const b of parsed.bars) {
|
|
333
375
|
const lines = new Set([b.line, ...(b.parts ?? []).flatMap((p) => (p ? [p.line] : []))]);
|
|
334
376
|
for (const line of lines) {
|
|
335
|
-
const l = byLine.get(line);
|
|
336
377
|
const meters = firstPlay.get(line) ?? [];
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
firstPlay.set(line,
|
|
378
|
+
if (meters.length < (cellsOf.get(line) ?? 0)) {
|
|
379
|
+
meters.push(beatsOf(b.meter));
|
|
380
|
+
firstPlay.set(line, meters);
|
|
381
|
+
}
|
|
340
382
|
}
|
|
341
383
|
}
|
|
342
384
|
return (l) => {
|
|
@@ -354,8 +396,25 @@ function beatsOfLines(parsed) {
|
|
|
354
396
|
export function printParsed(text, parsed, edit = (l) => l) {
|
|
355
397
|
return printLines(text, parsed, edit, new Set());
|
|
356
398
|
}
|
|
399
|
+
/** The unreadable slots of a bar line, or of any cells (grammar 2.3): unknown harmony that keeps its text. */
|
|
400
|
+
export const unreadSlots = (l) => simpleSlots(l.cells).filter((s) => s.kind === "unknown" && s.text !== undefined);
|
|
401
|
+
/**
|
|
402
|
+
* The lines that print as written (spec §8): every line with an error,
|
|
403
|
+
* except a bar line whose only errors are its unreadable slots, one each,
|
|
404
|
+
* which prints in canonical form with each slot's text as written.
|
|
405
|
+
*/
|
|
406
|
+
export function printedAsWritten(parsed) {
|
|
407
|
+
const errors = new Map();
|
|
408
|
+
for (const d of parsed.diagnostics)
|
|
409
|
+
if (d.severity === "error")
|
|
410
|
+
errors.set(d.line, (errors.get(d.line) ?? 0) + 1);
|
|
411
|
+
for (const l of parsed.lines)
|
|
412
|
+
if (l.kind === "bars" && errors.get(l.line) === unreadSlots(l).length)
|
|
413
|
+
errors.delete(l.line);
|
|
414
|
+
return new Set(errors.keys());
|
|
415
|
+
}
|
|
357
416
|
function linePrinter(parsed, edit) {
|
|
358
|
-
const errored =
|
|
417
|
+
const errored = printedAsWritten(parsed);
|
|
359
418
|
const beatsFor = beatsOfLines(parsed);
|
|
360
419
|
const systems = systemTexts(parsed, errored, beatsFor, edit);
|
|
361
420
|
return (raw, l) => {
|
package/dist/chart/repeats.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ export type Entry = {
|
|
|
4
4
|
line: Line;
|
|
5
5
|
repeat: Repeat;
|
|
6
6
|
};
|
|
7
|
-
/** One ending: the passes it plays on and its bar
|
|
7
|
+
/** One ending: the passes it plays on and its bar lines (grammar 5.1). */
|
|
8
8
|
export type Ending = {
|
|
9
9
|
passes: number[];
|
|
10
|
-
|
|
10
|
+
entries: Entry[];
|
|
11
11
|
};
|
|
12
12
|
/** A line, or a `|: … :|` repeat; one with endings plays `repeat` passes, each taking its ending. */
|
|
13
13
|
export type Item = ({
|
package/dist/chart/repeats.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BETWEEN_ENDINGS } from "./endingLines.js";
|
|
1
2
|
const passesToken = (b) => `|${(b.ending ?? []).join(",")}`;
|
|
2
3
|
const asLine = (line) => ({ kind: "line", line, repeat: null });
|
|
3
4
|
const highestPass = (endings) => Math.max(...endings.flatMap((b) => b.ending ?? []));
|
|
@@ -16,40 +17,44 @@ function passProblems(endings, last) {
|
|
|
16
17
|
problems.push([last, `the last ending must be the one for pass ${highest}`]);
|
|
17
18
|
return problems;
|
|
18
19
|
}
|
|
19
|
-
/** Every ending but the last goes back with
|
|
20
|
+
/** Every ending but the last goes back with `:|` on its last line; the last plays on. */
|
|
20
21
|
function closeProblems(endings, last) {
|
|
21
|
-
return endings.flatMap((b) => {
|
|
22
|
+
return endings.flatMap(({ head: b, lines }) => {
|
|
23
|
+
const closes = lines.at(-1)?.closes ?? false;
|
|
22
24
|
if (b === last)
|
|
23
|
-
return
|
|
24
|
-
return
|
|
25
|
+
return closes ? [[b, "the last ending plays on, so it doesn't close with :|"]] : [];
|
|
26
|
+
return closes ? [] : [[b, "an ending before the last goes back with :|"]];
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
/** A repeat with its endings, or, if they have problems, each line played once. */
|
|
28
30
|
function closeEndings(e, error) {
|
|
29
|
-
const
|
|
31
|
+
const heads = e.endings.map((x) => x.head);
|
|
32
|
+
const last = heads.at(-1);
|
|
30
33
|
if (!last)
|
|
31
34
|
return [];
|
|
32
|
-
const problems = [...passProblems(
|
|
35
|
+
const problems = [...passProblems(heads, last), ...closeProblems(e.endings, last)];
|
|
33
36
|
for (const [b, message] of problems)
|
|
34
37
|
error(b.line, message, passesToken(b));
|
|
35
38
|
const between = e.between.map((x) => asLine(x.line));
|
|
39
|
+
const written = e.endings.flatMap((x) => x.lines);
|
|
36
40
|
if (problems.length)
|
|
37
|
-
return [...e.entries.map((x) => asLine(x.line)), ...
|
|
38
|
-
const endings = e.endings.map((
|
|
39
|
-
passes:
|
|
40
|
-
|
|
41
|
+
return [...e.entries.map((x) => asLine(x.line)), ...written.map(asLine), ...between];
|
|
42
|
+
const endings = e.endings.map((x) => ({
|
|
43
|
+
passes: x.head.ending ?? [],
|
|
44
|
+
entries: x.lines.map((line) => ({ line, repeat: null })),
|
|
41
45
|
}));
|
|
42
|
-
const repeat = highestPass(
|
|
46
|
+
const repeat = highestPass(heads);
|
|
43
47
|
return [{ kind: "bracket", line: e.line, entries: e.entries, repeat, endings }, ...between];
|
|
44
48
|
}
|
|
45
49
|
/** An ending line starts the endings of the open repeat, or continues them. */
|
|
46
50
|
function takeEnding(st, bars, error) {
|
|
47
51
|
if (bars.repeat !== null)
|
|
48
52
|
error(bars.line, "x N on an ending: the endings give the count", passesToken(bars));
|
|
53
|
+
const ending = { head: bars, lines: [bars] };
|
|
49
54
|
if (st.open)
|
|
50
|
-
st.endings = { ...st.open, endings: [
|
|
55
|
+
st.endings = { ...st.open, endings: [ending], between: [] };
|
|
51
56
|
else if (st.endings)
|
|
52
|
-
st.endings.endings.push(
|
|
57
|
+
st.endings.endings.push(ending);
|
|
53
58
|
else {
|
|
54
59
|
error(bars.line, "an ending follows the bars of a |: … :| repeat", passesToken(bars));
|
|
55
60
|
st.items.push(asLine(bars));
|
|
@@ -91,8 +96,13 @@ function addEntry(st, entry) {
|
|
|
91
96
|
else
|
|
92
97
|
st.items.push({ kind: "line", ...entry });
|
|
93
98
|
}
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
const repeatToken = (r) => (r === "open" ? "x ..." : `x${r}`);
|
|
100
|
+
/** A line an ending continues onto (grammar 5.1) joins it; its own `x N` is an error, as on the ending's first line. */
|
|
101
|
+
function continueEnding(e, bars, error) {
|
|
102
|
+
if (bars.repeat !== null)
|
|
103
|
+
error(bars.line, "x N on an ending: the endings give the count", repeatToken(bars.repeat));
|
|
104
|
+
e.endings.at(-1)?.lines.push(bars);
|
|
105
|
+
}
|
|
96
106
|
/**
|
|
97
107
|
* Pair `|:` and `:|` within one section's lines, with the endings that
|
|
98
108
|
* follow a repeat (grammar 5.1). Problems are reported, and what cannot
|
|
@@ -108,6 +118,8 @@ export function pairRepeats(lines, error) {
|
|
|
108
118
|
for (const l of lines) {
|
|
109
119
|
if (l.kind === "bars" && l.ending)
|
|
110
120
|
takeEnding(st, l, error);
|
|
121
|
+
else if (l.kind === "bars" && l.continues && st.endings)
|
|
122
|
+
continueEnding(st.endings, l, error);
|
|
111
123
|
else if (st.endings && BETWEEN_ENDINGS.has(l.kind))
|
|
112
124
|
st.endings.between.push({ line: l, repeat: null });
|
|
113
125
|
else {
|
package/dist/chart/shares.d.ts
CHANGED
|
@@ -25,4 +25,11 @@ export declare function slotTimes<T extends Member>(slots: (T | {
|
|
|
25
25
|
kind: "group";
|
|
26
26
|
members: T[];
|
|
27
27
|
})[], meter: Meter): Timed<T>[];
|
|
28
|
+
/**
|
|
29
|
+
* `make` remembered by its written data (compared by identity) and the
|
|
30
|
+
* meter it plays in: a bar played again shares what its first play made,
|
|
31
|
+
* so a chart's cost is its written size plus its plays, never their
|
|
32
|
+
* product. Callers never mutate what it returns.
|
|
33
|
+
*/
|
|
34
|
+
export declare function perWritten<K extends object, T>(make: (written: K, meter: Meter) => T): (written: K, meter: Meter) => T;
|
|
28
35
|
export {};
|
package/dist/chart/shares.js
CHANGED
|
@@ -29,3 +29,23 @@ export function slotTimes(slots, meter) {
|
|
|
29
29
|
}
|
|
30
30
|
return out;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* `make` remembered by its written data (compared by identity) and the
|
|
34
|
+
* meter it plays in: a bar played again shares what its first play made,
|
|
35
|
+
* so a chart's cost is its written size plus its plays, never their
|
|
36
|
+
* product. Callers never mutate what it returns.
|
|
37
|
+
*/
|
|
38
|
+
export function perWritten(make) {
|
|
39
|
+
const seen = new WeakMap();
|
|
40
|
+
return (written, meter) => {
|
|
41
|
+
let byMeter = seen.get(written);
|
|
42
|
+
if (!byMeter) {
|
|
43
|
+
byMeter = new Map();
|
|
44
|
+
seen.set(written, byMeter);
|
|
45
|
+
}
|
|
46
|
+
const key = `${meter.n}/${meter.d}`;
|
|
47
|
+
if (!byMeter.has(key))
|
|
48
|
+
byMeter.set(key, make(written, meter));
|
|
49
|
+
return byMeter.get(key);
|
|
50
|
+
};
|
|
51
|
+
}
|
package/dist/chart/systems.js
CHANGED
|
@@ -73,14 +73,30 @@ function numberSystems(lines) {
|
|
|
73
73
|
*/
|
|
74
74
|
function referenceLines(lines) {
|
|
75
75
|
const bySystem = new Map();
|
|
76
|
-
for (const l of lines)
|
|
77
|
-
if (l.kind
|
|
78
|
-
|
|
76
|
+
for (const l of lines) {
|
|
77
|
+
if (l.kind !== "bars" || l.system === undefined)
|
|
78
|
+
continue;
|
|
79
|
+
const members = bySystem.get(l.system);
|
|
80
|
+
if (members)
|
|
81
|
+
members.push(l);
|
|
82
|
+
else
|
|
83
|
+
bySystem.set(l.system, [l]);
|
|
84
|
+
}
|
|
79
85
|
const refs = new Map();
|
|
80
86
|
for (const [system, members] of bySystem) {
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
87
|
+
// Each structure counted once, not each line against every other.
|
|
88
|
+
const shapes = members.map(structureOf);
|
|
89
|
+
const votes = new Map();
|
|
90
|
+
for (const shape of shapes)
|
|
91
|
+
votes.set(shape, (votes.get(shape) ?? 0) + 1);
|
|
92
|
+
let best = 0;
|
|
93
|
+
shapes.forEach((shape, i) => {
|
|
94
|
+
if ((votes.get(shape) ?? 0) > (votes.get(shapes[best] ?? "") ?? 0))
|
|
95
|
+
best = i;
|
|
96
|
+
});
|
|
97
|
+
const ref = members[best];
|
|
98
|
+
if (ref)
|
|
99
|
+
refs.set(system, ref);
|
|
84
100
|
}
|
|
85
101
|
return refs;
|
|
86
102
|
}
|
|
@@ -9,7 +9,9 @@ export type TransposeBy = {
|
|
|
9
9
|
* The chart in another key, as canonical text (spec §8). Chord roots, slash
|
|
10
10
|
* basses, note sets and every `key:` line move; text never does. Spelling
|
|
11
11
|
* follows the interval from the chart's first key, so every chord keeps its
|
|
12
|
-
* place in the key.
|
|
12
|
+
* place in the key. A slot that can't be read stays as written, with a
|
|
13
|
+
* warning, and its line's other chords move; a line excluded for an error
|
|
14
|
+
* stays as written, with a warning; a
|
|
13
15
|
* target that isn't a key, or a target key for a chart with none, returns
|
|
14
16
|
* the text unchanged with an error. Never throws.
|
|
15
17
|
*/
|
package/dist/chart/transpose.js
CHANGED
|
@@ -5,7 +5,7 @@ import { printChord } from "../chords/print.js";
|
|
|
5
5
|
import { parseDirectiveLine } from "./directives.js";
|
|
6
6
|
import { alterOf, conventionalKey, plain, SHARPS, spellPitch } from "./keys.js";
|
|
7
7
|
import { parseChart } from "./parse.js";
|
|
8
|
-
import { printParsed } from "./print.js";
|
|
8
|
+
import { printedAsWritten, printParsed, unreadSlots } from "./print.js";
|
|
9
9
|
const mod = (n, m) => ((n % m) + m) % m;
|
|
10
10
|
/** The key `semitones` away, spelled with the fewest accidentals; sharps win a tie (F# over Gb). */
|
|
11
11
|
function nearestKey(key, semitones) {
|
|
@@ -90,11 +90,23 @@ function moveLine(l, move, warn) {
|
|
|
90
90
|
return { ...l, set: { ...l.set, key: { ...l.set.key, tonic: move.spell(l.set.key.tonic) } } };
|
|
91
91
|
return l;
|
|
92
92
|
}
|
|
93
|
+
/** A warning for an unreadable slot (grammar 2.3), which transposing leaves as written. */
|
|
94
|
+
const unmoved = (line, slot) => {
|
|
95
|
+
const token = slot.kind === "unknown" ? (slot.text ?? "?") : "";
|
|
96
|
+
return {
|
|
97
|
+
line,
|
|
98
|
+
severity: "warning",
|
|
99
|
+
message: `${token} can't move: it can't be read, so it stays as written`,
|
|
100
|
+
token,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
93
103
|
/**
|
|
94
104
|
* The chart in another key, as canonical text (spec §8). Chord roots, slash
|
|
95
105
|
* basses, note sets and every `key:` line move; text never does. Spelling
|
|
96
106
|
* follows the interval from the chart's first key, so every chord keeps its
|
|
97
|
-
* place in the key.
|
|
107
|
+
* place in the key. A slot that can't be read stays as written, with a
|
|
108
|
+
* warning, and its line's other chords move; a line excluded for an error
|
|
109
|
+
* stays as written, with a warning; a
|
|
98
110
|
* target that isn't a key, or a target key for a chart with none, returns
|
|
99
111
|
* the text unchanged with an error. Never throws.
|
|
100
112
|
*/
|
|
@@ -106,13 +118,18 @@ export function transposeChart(text, by) {
|
|
|
106
118
|
return { text, diagnostics: [move] };
|
|
107
119
|
const physical = text.replace(/^/, "").split(/\r?\n/);
|
|
108
120
|
const diagnostics = [];
|
|
109
|
-
|
|
121
|
+
const asWritten = printedAsWritten(parsed);
|
|
122
|
+
for (const line of asWritten)
|
|
110
123
|
diagnostics.push({
|
|
111
124
|
line,
|
|
112
125
|
severity: "warning",
|
|
113
126
|
message: "not transposed: this line has an error",
|
|
114
127
|
token: physical[line - 1]?.trim() ?? "",
|
|
115
128
|
});
|
|
129
|
+
for (const l of parsed.lines)
|
|
130
|
+
if (l.kind === "bars" && !asWritten.has(l.line))
|
|
131
|
+
for (const s of unreadSlots(l))
|
|
132
|
+
diagnostics.push(unmoved(l.line, s));
|
|
116
133
|
const warn = (line, token) => diagnostics.push({
|
|
117
134
|
line,
|
|
118
135
|
severity: "warning",
|
package/dist/chart/types.d.ts
CHANGED
|
@@ -106,8 +106,14 @@ export type SimpleSlot = ({
|
|
|
106
106
|
} | {
|
|
107
107
|
kind: "silence";
|
|
108
108
|
push?: Push;
|
|
109
|
-
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Unknown harmony: a written `?`, or a slot that can't be read (an error,
|
|
112
|
+
* grammar principle 4), which keeps the author's `text` as written.
|
|
113
|
+
*/
|
|
114
|
+
| {
|
|
110
115
|
kind: "unknown";
|
|
116
|
+
text?: string;
|
|
111
117
|
}) & {
|
|
112
118
|
/** A dotted member of a two-member group (grammar 2.2): three quarters of its slot. */
|
|
113
119
|
dotted?: true;
|
|
@@ -199,6 +205,11 @@ export type Line = {
|
|
|
199
205
|
repeat: Repeat;
|
|
200
206
|
/** The passes an ending plays on (grammar 5.1), in order; null for any other bar line. */
|
|
201
207
|
ending: number[] | null;
|
|
208
|
+
/**
|
|
209
|
+
* On a plain bar line that continues an ending onto another line
|
|
210
|
+
* (grammar 5.1): that ending's passes. Absent on every other line.
|
|
211
|
+
*/
|
|
212
|
+
continues?: number[];
|
|
202
213
|
/** The declared label of the part whose line this is (grammar 7.4); absent on a tutti line and in a single-part chart. */
|
|
203
214
|
part?: string;
|
|
204
215
|
/** The part's line this is (`RH` in `Pno.RH`, grammar 7.6), as first spelled; absent on a part's bare line. */
|
|
@@ -255,12 +266,17 @@ export type Line = {
|
|
|
255
266
|
system?: number;
|
|
256
267
|
};
|
|
257
268
|
export type PlayedBar = {
|
|
258
|
-
/**
|
|
269
|
+
/**
|
|
270
|
+
* 1-based position in play order (not a bar number: a replay gives a bar
|
|
271
|
+
* a new position); fermatas are not counted.
|
|
272
|
+
*/
|
|
259
273
|
index: number;
|
|
260
274
|
/**
|
|
261
|
-
*
|
|
262
|
-
* (
|
|
263
|
-
*
|
|
275
|
+
* The bar's number as written, as `parseChart` and `extractPart` number
|
|
276
|
+
* it (`expand` counts from 1): 0 for a pickup (grammar 2.4), else
|
|
277
|
+
* counting from 1, each written bar once (`%` included, fermatas not) in
|
|
278
|
+
* written order: a repeat or replay plays its bars under the numbers they
|
|
279
|
+
* were written with.
|
|
264
280
|
*/
|
|
265
281
|
written: number;
|
|
266
282
|
line: number;
|
|
@@ -397,6 +413,8 @@ export type ChartParse = {
|
|
|
397
413
|
events: ChartEvent[];
|
|
398
414
|
/** `events` flattened, with an open repeat's pass included once. */
|
|
399
415
|
bars: PlayedBar[];
|
|
416
|
+
/** True when the chart's first written bar is a pickup (grammar 2.4); it is then written bar 0. */
|
|
417
|
+
pickup: boolean;
|
|
400
418
|
sections: SectionOccurrence[];
|
|
401
419
|
/** Sorted by line, then errors before warnings. */
|
|
402
420
|
diagnostics: ChartDiagnostic[];
|
package/dist/chart/verses.d.ts
CHANGED
|
@@ -16,8 +16,15 @@ export type Singer = {
|
|
|
16
16
|
};
|
|
17
17
|
/** The parts as the parse reports them: each that sings with the line it sings on. */
|
|
18
18
|
export declare function withSings(parts: DeclaredPart[], singers: Singer[]): DeclaredPart[];
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The rows that sing: `over` gives those over a bar line under a replay
|
|
21
|
+
* heading (null for none), or undefined; `all` is every row over some
|
|
22
|
+
* line, in written order.
|
|
23
|
+
*/
|
|
24
|
+
type Rows = {
|
|
25
|
+
over: (replay: number | null, line: number) => LyricsLine[] | undefined;
|
|
26
|
+
all: LyricsLine[];
|
|
27
|
+
};
|
|
21
28
|
/**
|
|
22
29
|
* The words each played bar sings (grammar 4.3, 7.7), for `expand` to
|
|
23
30
|
* attach as it plays the line that sings: the syllables on its notes
|
|
@@ -27,11 +34,15 @@ type Rows = Map<string, LyricsLine[]>;
|
|
|
27
34
|
* starts, a `:/` with nothing sung before it to hold, and a pass that
|
|
28
35
|
* sings nothing where other passes sing, warn. `finish`, after playing,
|
|
29
36
|
* warns of each numbered row never sung.
|
|
37
|
+
*
|
|
38
|
+
* A bar played again shares what its first play read (its notes' and its
|
|
39
|
+
* rows' syllables, by the written slots, the meter and what each row
|
|
40
|
+
* holds as it begins): a pass costs only the verses it sings.
|
|
30
41
|
*/
|
|
31
42
|
declare function singing(rows: Rows, who: Singer | null): {
|
|
32
43
|
sing: Sing;
|
|
33
44
|
diagnostics: ChartDiagnostic[];
|
|
34
|
-
finish: () => void;
|
|
45
|
+
finish: (stopped?: boolean) => void;
|
|
35
46
|
};
|
|
36
47
|
/** One voice that sings (grammar 7.7): its singer, null for the chart's words when no part sings, and its words. */
|
|
37
48
|
export type Voice = {
|