barmark 0.20.0 → 0.22.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 +153 -1
- package/README.md +11 -5
- package/dist/chart/document.js +21 -7
- package/dist/chart/expand.d.ts +23 -4
- package/dist/chart/expand.js +156 -42
- package/dist/chart/index.d.ts +1 -0
- package/dist/chart/index.js +1 -0
- package/dist/chart/keys.d.ts +2 -0
- package/dist/chart/keys.js +2 -0
- package/dist/chart/lines.js +25 -10
- package/dist/chart/lyricRows.js +20 -5
- package/dist/chart/parse.d.ts +3 -1
- package/dist/chart/parse.js +75 -30
- package/dist/chart/parts.d.ts +3 -1
- package/dist/chart/parts.js +180 -31
- 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.js +62 -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/types.d.ts +18 -4
- package/dist/chart/verses.d.ts +14 -3
- package/dist/chart/verses.js +363 -101
- package/dist/chords/index.d.ts +1 -0
- package/dist/chords/index.js +1 -0
- package/dist/chords/name.d.ts +8 -0
- package/dist/chords/name.js +177 -0
- package/dist/chords/suffixes.d.ts +2 -0
- package/dist/chords/suffixes.js +1 -1
- package/package.json +2 -2
package/dist/chart/expand.js
CHANGED
|
@@ -2,9 +2,26 @@ import { planJump } from "./direction.js";
|
|
|
2
2
|
import { beatsOf } from "./directives.js";
|
|
3
3
|
import { pedalWarnings } from "./pedal.js";
|
|
4
4
|
import { pairRepeats } from "./repeats.js";
|
|
5
|
-
import { slotTimes } from "./shares.js";
|
|
5
|
+
import { perWritten, slotTimes } from "./shares.js";
|
|
6
6
|
/** Nested repeats multiply; expansion stops here rather than run away. */
|
|
7
7
|
export const MAX_EXPANDED_BARS = 10_000;
|
|
8
|
+
/** The bars one of `share` parts may play: its share of the cap. */
|
|
9
|
+
const barsFor = (share) => Math.max(1, Math.floor(MAX_EXPANDED_BARS / share));
|
|
10
|
+
/**
|
|
11
|
+
* The work one of `share` parts may do: ten times its bars. A part of a
|
|
12
|
+
* chart of several also reads at most this many lines, so the parts
|
|
13
|
+
* times the lines never multiply.
|
|
14
|
+
*/
|
|
15
|
+
export const workFor = (share) => barsFor(share) * 10;
|
|
16
|
+
/**
|
|
17
|
+
* The lines one of several parts reads: its share of the work, since the
|
|
18
|
+
* parts times the lines would otherwise multiply; and the first it
|
|
19
|
+
* doesn't read, if any. A chart of one part reads every line.
|
|
20
|
+
*/
|
|
21
|
+
function shareOf(lines, share, most) {
|
|
22
|
+
const unread = share > 1 ? lines[most] : undefined;
|
|
23
|
+
return unread ? { readable: lines.slice(0, most), unread } : { readable: lines };
|
|
24
|
+
}
|
|
8
25
|
/** A slot without its syllable: `%` copies a bar's notes, not its words (grammar 4.3). */
|
|
9
26
|
const unsungSimple = (s) => {
|
|
10
27
|
if (s.kind !== "chord" || !s.syllable)
|
|
@@ -45,6 +62,21 @@ function pushProblem(push, before) {
|
|
|
45
62
|
? `${push === "eighth" ? "an eighth" : "a sixteenth"} push is longer than the slot before it`
|
|
46
63
|
: null;
|
|
47
64
|
}
|
|
65
|
+
function pushesIn(slots, meter) {
|
|
66
|
+
const timed = slotTimes(slots, meter);
|
|
67
|
+
const inner = new Map();
|
|
68
|
+
timed.forEach(({ slot }, i) => {
|
|
69
|
+
const prior = timed[i - 1];
|
|
70
|
+
const problem = prior && slot.push && pushProblem(slot.push, prior.length);
|
|
71
|
+
if (problem && slot.push && !inner.has(problem))
|
|
72
|
+
inner.set(problem, slot.push);
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
first: timed[0]?.slot ?? null,
|
|
76
|
+
inner: [...inner].map(([problem, push]) => [push, problem]),
|
|
77
|
+
last: timed.at(-1)?.length ?? null,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
48
80
|
const normalize = (name) => name.toLowerCase().replace(/\s+/g, " ").trim();
|
|
49
81
|
const isWritten = (s) => s.lines.some((l) => l.kind === "bars" || l.kind === "invalid");
|
|
50
82
|
/** Grammar §6: an empty section that matches nothing, and how to fix it. */
|
|
@@ -63,22 +95,25 @@ function unmatchedReplay(heading, sections) {
|
|
|
63
95
|
export function flattenBars(events) {
|
|
64
96
|
return events.flatMap((e) => e.kind === "bar" ? [e.bar] : e.kind === "open" ? flattenBars(e.events) : []);
|
|
65
97
|
}
|
|
66
|
-
/** Remove the last bar, looking inside a final open pass and past a final fermata. */
|
|
98
|
+
/** Remove the last bar, looking inside a final open pass and past a final fermata; the bar removed, or null. */
|
|
67
99
|
function removeLastBar(events) {
|
|
68
100
|
for (let i = events.length - 1; i >= 0; i--) {
|
|
69
101
|
const e = events[i];
|
|
70
102
|
if (e?.kind === "bar") {
|
|
71
103
|
events.splice(i, 1);
|
|
72
|
-
return
|
|
104
|
+
return e.bar;
|
|
73
105
|
}
|
|
74
|
-
|
|
75
|
-
|
|
106
|
+
const inner = e?.kind === "open" ? removeLastBar(e.events) : null;
|
|
107
|
+
if (inner)
|
|
108
|
+
return inner;
|
|
76
109
|
}
|
|
77
|
-
return
|
|
110
|
+
return null;
|
|
78
111
|
}
|
|
79
112
|
/**
|
|
80
113
|
* Turn the written chart into the bars in play order: sections and their
|
|
81
|
-
* replays, repeats, directive changes, `%` and elision.
|
|
114
|
+
* replays, repeats, directive changes, `%` and elision. Its bars count
|
|
115
|
+
* `written` from 1, a pickup included; `parseChart` and `extractPart`
|
|
116
|
+
* renumber a pickup to 0 (grammar 2.4).
|
|
82
117
|
*/
|
|
83
118
|
/**
|
|
84
119
|
* `label` names the part a projected chart is (grammar 7.4), for its
|
|
@@ -90,9 +125,10 @@ pedal = true,
|
|
|
90
125
|
/** The words each bar sings, for the line that sings them (grammar 7.7). */
|
|
91
126
|
sing) {
|
|
92
127
|
const diagnostics = [];
|
|
93
|
-
const maxBars =
|
|
128
|
+
const maxBars = barsFor(share);
|
|
94
129
|
// Repeats of bodies that play no bars (fermatas only) are bounded too.
|
|
95
|
-
const maxWork =
|
|
130
|
+
const maxWork = workFor(share);
|
|
131
|
+
const { readable, unread } = shareOf(lines, share, maxWork);
|
|
96
132
|
// The return after a jump plays sections again: it reports only what the first pass did not.
|
|
97
133
|
const reported = new Set();
|
|
98
134
|
let again = false;
|
|
@@ -104,7 +140,7 @@ sing) {
|
|
|
104
140
|
diagnostics.push({ line, severity: "error", message, token });
|
|
105
141
|
};
|
|
106
142
|
const sections = [{ heading: null, lines: [] }];
|
|
107
|
-
for (const l of
|
|
143
|
+
for (const l of readable) {
|
|
108
144
|
if (l.kind === "section")
|
|
109
145
|
sections.push({ heading: l, lines: [] });
|
|
110
146
|
else if (l.kind !== "title")
|
|
@@ -192,7 +228,7 @@ sing) {
|
|
|
192
228
|
error(unused.line, "a rehearsal mark marks the bar after it; none follows", `@${unused.label}`);
|
|
193
229
|
// Pair |: and :| within each section, with any endings.
|
|
194
230
|
const itemsOf = new Map(sections.map((s) => [s, pairRepeats(s.lines, error)]));
|
|
195
|
-
const plan = planJump(
|
|
231
|
+
const plan = planJump(readable, error);
|
|
196
232
|
const start = () => ({
|
|
197
233
|
key: null,
|
|
198
234
|
time: { n: 4, d: 4 },
|
|
@@ -245,13 +281,38 @@ sing) {
|
|
|
245
281
|
let openDepth = 0;
|
|
246
282
|
const nestedOpen = new Set();
|
|
247
283
|
const checked = new Set();
|
|
248
|
-
|
|
284
|
+
/** Verses sung by bars playing again: work, counted for the message. */
|
|
285
|
+
let againSung = 0;
|
|
286
|
+
/** Bars a replay's `->` cut after they played: `count` counts them, the output doesn't. */
|
|
287
|
+
let cutBars = 0;
|
|
288
|
+
/** Stop playing, saying why: the bar cap, the verses sung again, repeats that play too much, or a part's lines. */
|
|
289
|
+
const stop = (line, why = "work") => {
|
|
249
290
|
capped = true;
|
|
250
|
-
|
|
291
|
+
const what = () => {
|
|
292
|
+
if (why === "bars")
|
|
293
|
+
return `expansion stopped at ${maxBars} bars`;
|
|
294
|
+
const after = `expansion stopped after ${count - cutBars} bars`;
|
|
295
|
+
if (why === "verses")
|
|
296
|
+
return `${after}: the bars played again sing too many verses (${againSung.toLocaleString("en-US")})`;
|
|
297
|
+
if (why === "lines")
|
|
298
|
+
return `${after}: each of ${share} parts reads at most ${maxWork} lines`;
|
|
299
|
+
return `${after}: its repeats play too many times`;
|
|
300
|
+
};
|
|
301
|
+
error(line, what(), "x");
|
|
302
|
+
};
|
|
303
|
+
/** A part that stopped reading its lines before play stopped says so. */
|
|
304
|
+
const readAll = (next) => {
|
|
305
|
+
// Play that ended (at Fine, after the jump) never reaches the lines past the share.
|
|
306
|
+
if (next && !capped && phase !== "done")
|
|
307
|
+
stop(next.line, "lines");
|
|
251
308
|
};
|
|
252
309
|
let sectionName = null;
|
|
253
310
|
/** The pass of the repeat being played, and the replay heading being played, for the words (grammar 7.7). */
|
|
254
|
-
const where = {
|
|
311
|
+
const where = {
|
|
312
|
+
pass: null,
|
|
313
|
+
passes: null,
|
|
314
|
+
replay: null,
|
|
315
|
+
};
|
|
255
316
|
let phase = "main";
|
|
256
317
|
const stopped = () => capped || phase === "jumped" || phase === "done";
|
|
257
318
|
const jumped = () => phase === "jumped";
|
|
@@ -261,15 +322,18 @@ sing) {
|
|
|
261
322
|
if (plan)
|
|
262
323
|
phase = NEXT[phase]?.[d.kind] ?? phase;
|
|
263
324
|
};
|
|
264
|
-
/** A bar
|
|
325
|
+
/** A written bar's slot count, checked the first time it plays. */
|
|
326
|
+
const checkSlots = (p, meter, line) => {
|
|
327
|
+
if (!p.own || checked.has(p))
|
|
328
|
+
return;
|
|
329
|
+
checked.add(p);
|
|
330
|
+
const warning = uneven(p.slots.length, meter, line);
|
|
331
|
+
if (warning)
|
|
332
|
+
diagnostics.push(warning);
|
|
333
|
+
};
|
|
334
|
+
/** A bar as played now; in a one-bar meter it also carries the `time:` in force (grammar 2.4). */
|
|
265
335
|
const barOf = (p, line) => {
|
|
266
336
|
const meter = p.meter ?? state.time;
|
|
267
|
-
if (p.own && !checked.has(p)) {
|
|
268
|
-
checked.add(p);
|
|
269
|
-
const warning = uneven(p.slots.length, meter, line);
|
|
270
|
-
if (warning)
|
|
271
|
-
diagnostics.push(warning);
|
|
272
|
-
}
|
|
273
337
|
const { key, tempo, change: tempoChange, feel, swingPercent } = state;
|
|
274
338
|
return {
|
|
275
339
|
index: 0,
|
|
@@ -277,6 +341,7 @@ sing) {
|
|
|
277
341
|
line,
|
|
278
342
|
section: sectionName,
|
|
279
343
|
meter,
|
|
344
|
+
...(p.meter && { time: state.time }),
|
|
280
345
|
key,
|
|
281
346
|
tempo,
|
|
282
347
|
tempoChange,
|
|
@@ -288,26 +353,63 @@ sing) {
|
|
|
288
353
|
...(p.tacet && { tacet: p.tacet }),
|
|
289
354
|
};
|
|
290
355
|
};
|
|
356
|
+
/** Where a played bar comes from, for its words (grammar 7.7). */
|
|
357
|
+
const sourceOf = (p, line) => ({
|
|
358
|
+
line,
|
|
359
|
+
bar: p.bar,
|
|
360
|
+
...where,
|
|
361
|
+
});
|
|
291
362
|
/** The bar with the words it sings here, if any (grammar 7.7). */
|
|
292
363
|
const sung = (bar, p, line) => {
|
|
293
|
-
const lyrics = sing?.(bar,
|
|
364
|
+
const lyrics = sing?.(bar, sourceOf(p, line));
|
|
294
365
|
return lyrics ? { ...bar, lyrics } : bar;
|
|
295
366
|
};
|
|
296
367
|
/** How long the slot played just before is, in whole notes; null after a fermata or at the start. */
|
|
297
368
|
const before = { length: null };
|
|
298
369
|
const pushReported = new Set();
|
|
370
|
+
const report = (line, problem, push) => {
|
|
371
|
+
const key = `${line}\u0000${problem}`;
|
|
372
|
+
if (!problem || pushReported.has(key))
|
|
373
|
+
return;
|
|
374
|
+
pushReported.add(key);
|
|
375
|
+
error(line, problem, PUSH_MARKS[push ?? "eighth"]);
|
|
376
|
+
};
|
|
377
|
+
const pushesOf = perWritten(pushesIn);
|
|
299
378
|
/** Each push takes its time from the slot played just before it (grammar 2.8). */
|
|
300
379
|
const checkPushes = (bar) => {
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
380
|
+
const { first, inner, last } = pushesOf(bar.slots, bar.meter);
|
|
381
|
+
if (first?.push)
|
|
382
|
+
report(bar.line, pushProblem(first.push, before.length), first.push);
|
|
383
|
+
for (const [push, problem] of inner)
|
|
384
|
+
report(bar.line, problem, push);
|
|
385
|
+
if (last !== null)
|
|
386
|
+
before.length = last;
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* The verses a written bar would sing playing again here: work, since
|
|
390
|
+
* many verses replayed many times would otherwise multiply. Its first
|
|
391
|
+
* play's are as many as are written, so they cost nothing more. Asked
|
|
392
|
+
* before the bar is sung, so a bar the budget stops sings nothing.
|
|
393
|
+
*/
|
|
394
|
+
const sungBefore = new Set();
|
|
395
|
+
const replayedVerses = (p, bar, line) => sungBefore.has(p) ? (sing?.verses(bar, sourceOf(p, line)) ?? 0) : 0;
|
|
396
|
+
/** Each output bar's charge for its verses, so a bar `->` cuts gives its charge back to the message. */
|
|
397
|
+
const charged = new WeakMap();
|
|
398
|
+
/** A bar as played and sung: its checks and its words, once the budget has room for it. */
|
|
399
|
+
const playBar = (p, line) => {
|
|
400
|
+
const bar = barOf(p, line);
|
|
401
|
+
const again = replayedVerses(p, bar, line);
|
|
402
|
+
if (work + again > maxWork)
|
|
403
|
+
return null;
|
|
404
|
+
work += again;
|
|
405
|
+
againSung += again;
|
|
406
|
+
sungBefore.add(p);
|
|
407
|
+
checkSlots(p, bar.meter, line);
|
|
408
|
+
checkPushes(bar);
|
|
409
|
+
const played = sung(bar, p, line);
|
|
410
|
+
if (again)
|
|
411
|
+
charged.set(played, again);
|
|
412
|
+
return played;
|
|
311
413
|
};
|
|
312
414
|
const emit = (p, line, out) => {
|
|
313
415
|
if (stopped())
|
|
@@ -323,11 +425,12 @@ sing) {
|
|
|
323
425
|
return void out.push({ kind: "fermata", line });
|
|
324
426
|
}
|
|
325
427
|
if (count >= maxBars)
|
|
326
|
-
return stop(line);
|
|
428
|
+
return stop(line, "bars");
|
|
429
|
+
const played = playBar(p, line);
|
|
430
|
+
if (!played)
|
|
431
|
+
return stop(line, "verses");
|
|
327
432
|
count++;
|
|
328
|
-
|
|
329
|
-
checkPushes(bar);
|
|
330
|
-
out.push({ kind: "bar", bar: sung(bar, p, line) });
|
|
433
|
+
out.push({ kind: "bar", bar: played });
|
|
331
434
|
};
|
|
332
435
|
/** Play `body` `repeat` times into `out`; an open repeat plays one pass inside an open event. */
|
|
333
436
|
const times = (repeat, line, out, body) => {
|
|
@@ -351,7 +454,9 @@ sing) {
|
|
|
351
454
|
};
|
|
352
455
|
/** Play `n` passes; a repeat's are numbered for the words (grammar 7.7), a plain line's are not. */
|
|
353
456
|
const passes = (n, counted, line, play) => {
|
|
354
|
-
const outer = where
|
|
457
|
+
const outer = { ...where };
|
|
458
|
+
if (counted)
|
|
459
|
+
where.passes = n;
|
|
355
460
|
for (let i = 0; i < n && !stopped(); i++) {
|
|
356
461
|
if (++work > maxWork)
|
|
357
462
|
return stop(line);
|
|
@@ -359,7 +464,7 @@ sing) {
|
|
|
359
464
|
where.pass = i + 1;
|
|
360
465
|
play();
|
|
361
466
|
}
|
|
362
|
-
where.pass
|
|
467
|
+
Object.assign(where, { pass: outer.pass, passes: outer.passes });
|
|
363
468
|
};
|
|
364
469
|
const playLine = ({ line: l, repeat }, out) => {
|
|
365
470
|
if (stopped())
|
|
@@ -390,7 +495,9 @@ sing) {
|
|
|
390
495
|
const playEndings = (it, out) => {
|
|
391
496
|
const highest = typeof it.repeat === "number" ? it.repeat : 1;
|
|
392
497
|
const first = phase === "main" ? 1 : highest;
|
|
393
|
-
const outer = where
|
|
498
|
+
const outer = { ...where };
|
|
499
|
+
// After the jump only the last pass plays.
|
|
500
|
+
where.passes = highest - first + 1;
|
|
394
501
|
for (let pass = first; pass <= highest && !stopped(); pass++) {
|
|
395
502
|
if (++work > maxWork)
|
|
396
503
|
return stop(it.line);
|
|
@@ -402,7 +509,7 @@ sing) {
|
|
|
402
509
|
if (ending)
|
|
403
510
|
playLine(ending.entry, out);
|
|
404
511
|
}
|
|
405
|
-
where.pass
|
|
512
|
+
Object.assign(where, { pass: outer.pass, passes: outer.passes });
|
|
406
513
|
};
|
|
407
514
|
const events = [];
|
|
408
515
|
const occurrences = [];
|
|
@@ -444,7 +551,13 @@ sing) {
|
|
|
444
551
|
times(h.repeat, h.line, out, (into) => playItems(itemsOf.get(source) ?? [], into));
|
|
445
552
|
where.replay = null;
|
|
446
553
|
// It cuts the last bar as written; play stopped before it (a Fine, a To Coda) never reaches it.
|
|
447
|
-
const
|
|
554
|
+
const cut = h.elided && reachesEnd(source, out) ? removeLastBar(out) : null;
|
|
555
|
+
if (cut) {
|
|
556
|
+
// The message counts what is output: the cut bar and its verses are not.
|
|
557
|
+
cutBars++;
|
|
558
|
+
againSung -= charged.get(cut) ?? 0;
|
|
559
|
+
}
|
|
560
|
+
const elided = cut !== null;
|
|
448
561
|
// A replay heading stands for its bars: its own lines (directives) come after them.
|
|
449
562
|
playItems(itemsOf.get(s) ?? [], out);
|
|
450
563
|
return { replayOf: source.heading.line, elided };
|
|
@@ -481,6 +594,7 @@ sing) {
|
|
|
481
594
|
phase = plan.to === "start" ? "return" : "seek segno";
|
|
482
595
|
playSections();
|
|
483
596
|
}
|
|
597
|
+
readAll(unread);
|
|
484
598
|
flattenBars(events).forEach((b, i) => {
|
|
485
599
|
b.index = i + 1;
|
|
486
600
|
});
|
|
@@ -499,5 +613,5 @@ sing) {
|
|
|
499
613
|
});
|
|
500
614
|
if (pedal)
|
|
501
615
|
diagnostics.push(...pedalWarnings(flattenBars(events)));
|
|
502
|
-
return { events, sections: sectionsOut, diagnostics };
|
|
616
|
+
return { events, sections: sectionsOut, diagnostics, stopped: capped };
|
|
503
617
|
}
|
package/dist/chart/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { MAX_LINES } from "./lines.js";
|
|
|
11
11
|
export { extractPart, parseChart } from "./parse.js";
|
|
12
12
|
export { projectPart } from "./parts.js";
|
|
13
13
|
export { pedalStates } from "./pedal.js";
|
|
14
|
+
export { opensWithPickup } from "./pickup.js";
|
|
14
15
|
export { printCell, printChart, printLine, printParsed, printPart, printPasses, printSlot, reduceSlots, } from "./print.js";
|
|
15
16
|
export { memberShares } from "./shares.js";
|
|
16
17
|
export { streamKey } from "./systems.js";
|
package/dist/chart/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { MAX_LINES } from "./lines.js";
|
|
|
11
11
|
export { extractPart, parseChart } from "./parse.js";
|
|
12
12
|
export { projectPart } from "./parts.js";
|
|
13
13
|
export { pedalStates } from "./pedal.js";
|
|
14
|
+
export { opensWithPickup } from "./pickup.js";
|
|
14
15
|
export { printCell, printChart, printLine, printParsed, printPart, printPasses, printSlot, reduceSlots, } from "./print.js";
|
|
15
16
|
export { memberShares } from "./shares.js";
|
|
16
17
|
export { streamKey } from "./systems.js";
|
package/dist/chart/keys.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare const alterOf: (note: string) => number;
|
|
|
6
6
|
export declare function plain(note: string): string;
|
|
7
7
|
/** Sharps (positive) or flats (negative) in a key's signature. */
|
|
8
8
|
export declare const signature: (tonic: string, mode: Mode) => number;
|
|
9
|
+
/** Whether a pitch class is one of the key's seven. */
|
|
10
|
+
export declare const inScale: (pitchClass: number, key: Key) => boolean;
|
|
9
11
|
/** A pitch class spelled in a key (or, with no key, from transposeChart's table). */
|
|
10
12
|
export declare function spellPitch(pitchClass: number, key: Key | null): string;
|
|
11
13
|
/** The same key spelled with the fewest accidentals; a tie keeps the spelling given. */
|
package/dist/chart/keys.js
CHANGED
|
@@ -56,6 +56,8 @@ const scaleOf = (mode) => {
|
|
|
56
56
|
const root = MAJOR_SCALE[start] ?? 0;
|
|
57
57
|
return MAJOR_SCALE.map((_, i) => mod((MAJOR_SCALE[(start + i) % 7] ?? 0) - root, 12));
|
|
58
58
|
};
|
|
59
|
+
/** Whether a pitch class is one of the key's seven. */
|
|
60
|
+
export const inScale = (pitchClass, key) => scaleOf(key.mode).includes(mod(pitchClass - noteSemitone(key.tonic), 12));
|
|
59
61
|
/** Notes outside the mode: the major-scale map (bII, bIII, #IV, bVI, bVII). */
|
|
60
62
|
const OUTSIDE = {
|
|
61
63
|
0: { degree: 1, alter: 0 },
|
package/dist/chart/lines.js
CHANGED
|
@@ -32,11 +32,19 @@ function nameLines(lines, report) {
|
|
|
32
32
|
});
|
|
33
33
|
return { lines: out, names };
|
|
34
34
|
}
|
|
35
|
+
/** Push `item` onto the list at `key`, starting it if new: a copy per item would cost the list squared. */
|
|
36
|
+
function pushAt(map, key, ...items) {
|
|
37
|
+
const known = map.get(key);
|
|
38
|
+
if (known)
|
|
39
|
+
known.push(...items);
|
|
40
|
+
else
|
|
41
|
+
map.set(key, items);
|
|
42
|
+
}
|
|
35
43
|
/** A system's lines by part, in written order. */
|
|
36
44
|
function byPart(system) {
|
|
37
45
|
const out = new Map();
|
|
38
46
|
for (const l of system)
|
|
39
|
-
out
|
|
47
|
+
pushAt(out, l.part ?? "", l);
|
|
40
48
|
return out;
|
|
41
49
|
}
|
|
42
50
|
/**
|
|
@@ -45,12 +53,17 @@ function byPart(system) {
|
|
|
45
53
|
* they first appear.
|
|
46
54
|
*/
|
|
47
55
|
function scoreOrder(names, systems) {
|
|
56
|
+
// Each part's first system writing two or more of its lines, found in one pass over the systems.
|
|
57
|
+
const full = new Map();
|
|
58
|
+
for (const system of systems)
|
|
59
|
+
for (const [part, own] of system) {
|
|
60
|
+
const named = own.flatMap((l) => l.lineName ?? []);
|
|
61
|
+
if (named.length > 1 && !full.has(part))
|
|
62
|
+
full.set(part, named);
|
|
63
|
+
}
|
|
48
64
|
const out = new Map();
|
|
49
65
|
for (const [part, all] of names) {
|
|
50
|
-
const
|
|
51
|
-
.map((s) => (byPart(s).get(part) ?? []).flatMap((l) => l.lineName ?? []))
|
|
52
|
-
.find((n) => n.length > 1);
|
|
53
|
-
const first = full ?? [];
|
|
66
|
+
const first = full.get(part) ?? [];
|
|
54
67
|
out.set(part, [...first, ...all.filter((n) => !first.includes(n))]);
|
|
55
68
|
}
|
|
56
69
|
return out;
|
|
@@ -62,10 +75,10 @@ function scoreOrder(names, systems) {
|
|
|
62
75
|
function bareBeside(systems) {
|
|
63
76
|
const out = new Map();
|
|
64
77
|
for (const system of systems)
|
|
65
|
-
for (const [part, own] of
|
|
78
|
+
for (const [part, own] of system) {
|
|
66
79
|
const bare = own.filter((l) => l.lineName === undefined);
|
|
67
80
|
if (bare.length && bare.length < own.length)
|
|
68
|
-
out
|
|
81
|
+
pushAt(out, part, ...bare);
|
|
69
82
|
}
|
|
70
83
|
return out;
|
|
71
84
|
}
|
|
@@ -116,9 +129,11 @@ export function checkLines(lines, parts) {
|
|
|
116
129
|
const systems = new Map();
|
|
117
130
|
for (const l of named.lines)
|
|
118
131
|
if (isLabelled(l) && l.system !== undefined && !failed.has(l.line))
|
|
119
|
-
systems
|
|
120
|
-
|
|
121
|
-
const
|
|
132
|
+
pushAt(systems, l.system, l);
|
|
133
|
+
// Each system's lines by part, once: not once for every part.
|
|
134
|
+
const parted = [...systems.values()].map(byPart);
|
|
135
|
+
const bare = bareBeside(parted);
|
|
136
|
+
const order = withBare(scoreOrder(named.names, parted), bare, report);
|
|
122
137
|
for (const system of systems.values())
|
|
123
138
|
checkSystem(system.filter((l) => !failed.has(l.line)), order, report);
|
|
124
139
|
const out = named.lines.map((l) => l.kind === "bars" && failed.has(l.line) ? { ...l, dropped: true } : l);
|
package/dist/chart/lyricRows.js
CHANGED
|
@@ -84,12 +84,22 @@ const isRow = (l) => l.kind === "lyrics" || (l.kind === "text" && !l.escaped &&
|
|
|
84
84
|
const isCovered = (l) => l.kind === "bars" || l.kind === "invalid";
|
|
85
85
|
const normalize = (name) => name.toLowerCase().replace(/\s+/g, " ").trim();
|
|
86
86
|
const plural = (n, what) => `${n} ${what}${n === 1 ? "" : "s"}`;
|
|
87
|
+
/** Each unit's reference line and its bar count, found once however many rows lie under it. */
|
|
88
|
+
const referenceOf = new WeakMap();
|
|
89
|
+
function unitReference(unit) {
|
|
90
|
+
if (referenceOf.has(unit))
|
|
91
|
+
return referenceOf.get(unit) ?? null;
|
|
92
|
+
const ref = unit.find((l) => l.kind === "bars" && !l.dropped);
|
|
93
|
+
const found = ref ? { ref, n: ref.cells.filter(isBar).length } : null;
|
|
94
|
+
referenceOf.set(unit, found);
|
|
95
|
+
return found;
|
|
96
|
+
}
|
|
87
97
|
/** Why a row can't lie under a unit, or null: its bar count must be the unit's. */
|
|
88
98
|
function countProblem(row, unit) {
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
99
|
+
const found = unitReference(unit);
|
|
100
|
+
if (!found)
|
|
91
101
|
return null;
|
|
92
|
-
const n =
|
|
102
|
+
const { ref, n } = found;
|
|
93
103
|
if (row.cells.length === n)
|
|
94
104
|
return null;
|
|
95
105
|
return `this lyric row has ${plural(row.cells.length, "bar")}; the bar line it covers has ${n} (line ${ref.line})`;
|
|
@@ -161,6 +171,8 @@ function placeRows(s, definitions) {
|
|
|
161
171
|
export function attachLyrics(lines) {
|
|
162
172
|
const diagnostics = [];
|
|
163
173
|
const covers = new Map();
|
|
174
|
+
// One list of lines for each unit, shared by its rows: a copy per row costs the rows times the unit's lines.
|
|
175
|
+
const linesOf = new Map();
|
|
164
176
|
const definitions = new Map();
|
|
165
177
|
const placed = sectionsOf(lines).flatMap((s) => placeRows(s, definitions));
|
|
166
178
|
// A row with an error of its own (kept as text) only holds its place.
|
|
@@ -170,8 +182,11 @@ export function attachLyrics(lines) {
|
|
|
170
182
|
const why = unit ? countProblem(row, unit) : problem;
|
|
171
183
|
if (why)
|
|
172
184
|
diagnostics.push({ line: row.line, severity: "error", message: why, token: "lyrics" });
|
|
173
|
-
if (unit)
|
|
174
|
-
|
|
185
|
+
if (!unit)
|
|
186
|
+
continue;
|
|
187
|
+
const own = linesOf.get(unit) ?? unit.map((l) => l.line);
|
|
188
|
+
linesOf.set(unit, own);
|
|
189
|
+
covers.set(row, own);
|
|
175
190
|
}
|
|
176
191
|
const out = lines.map((l) => (l.kind === "lyrics" ? { ...l, covers: covers.get(l) ?? [] } : l));
|
|
177
192
|
return { lines: out, diagnostics };
|
package/dist/chart/parse.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ import type { ChartDiagnostic, ChartEvent, ChartParse } from "./types.js";
|
|
|
4
4
|
* line of a system shares its structure. Where they don't, the lead's
|
|
5
5
|
* shape is kept and the first place they part is an error.
|
|
6
6
|
*/
|
|
7
|
-
export declare function zipEvents(each: ChartEvent[][], report: (d: ChartDiagnostic) => void
|
|
7
|
+
export declare function zipEvents(each: ChartEvent[][], report: (d: ChartDiagnostic) => void,
|
|
8
|
+
/** A part that stopped at a limit falls out of step because it stopped: the stop says so. */
|
|
9
|
+
stopped?: boolean): ChartEvent[];
|
|
8
10
|
/** Read a whole barmark chart: the document as written and the bars in play order. Never throws. */
|
|
9
11
|
export declare function parseChart(text: string): ChartParse;
|
|
10
12
|
/**
|