@barmark/render 0.13.0 → 0.15.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 +48 -1
- package/README.md +21 -1
- package/dist/html.js +84 -23
- package/dist/model.js +91 -31
- package/dist/speech.d.ts +10 -1
- package/dist/speech.js +33 -3
- package/dist/styles.js +33 -1
- package/dist/types.d.ts +25 -4
- package/dist/verses-html.d.ts +37 -0
- package/dist/verses-html.js +57 -0
- package/dist/verses.d.ts +33 -0
- package/dist/verses.js +135 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,51 @@ package uses [semantic versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.15.0] - 2026-11-07
|
|
10
|
+
|
|
11
|
+
Needs `barmark` 0.17.0.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **Voice lines and lyrics** (barmark's grammar 4.3, 7.7): the line a part
|
|
16
|
+
sings words on draws its notes as pitch names, spaced by beat, with
|
|
17
|
+
each verse's syllables under them: hyphens within a word, an extender
|
|
18
|
+
for a held syllable (`:/`), verses numbered when there are several. A
|
|
19
|
+
lyric row on no melody draws its words in the bars it covers, spaced
|
|
20
|
+
by beat, so they wrap with their bars. A screen reader hears each bar's
|
|
21
|
+
words after its notes. The model's rows gain `sings`, `verses` and
|
|
22
|
+
`lyrics`; `--barmark-lyrics` colours the words, and `::part(lyrics)`
|
|
23
|
+
styles each verse's line. A `lyrics:` line followed by a
|
|
24
|
+
bar line, which drew as a line of text, now draws its words on the
|
|
25
|
+
beats.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- A `---` break draws nothing, and a text line written with a leading `\`
|
|
30
|
+
shows without the backslash.
|
|
31
|
+
- A part's bare line with its named lines written after it (`Vox` over
|
|
32
|
+
`Vox.Mel`, barmark's amended grammar 7.6) draws in the same system, as
|
|
33
|
+
the part's first row.
|
|
34
|
+
|
|
35
|
+
## [0.14.0] - 2026-11-04
|
|
36
|
+
|
|
37
|
+
Needs `barmark` 0.16.0.
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- **Part lines** (barmark's grammar 7.6): a system draws a row per line a
|
|
42
|
+
part writes, labelled `Pno.RH`, `Pno.LH`, in score order; a part with no
|
|
43
|
+
line there keeps its tacet row, and `part: "Pno"` draws both hands. The
|
|
44
|
+
label column is as wide as the widest line label. A screen reader
|
|
45
|
+
hears each row as its part and line: "Piano RH". `parts` in the model
|
|
46
|
+
are barmark's `DeclaredPart`, with `lines`.
|
|
47
|
+
- **Pedal marks** (grammar 2.9): "Ped." under a press and "✱" under a
|
|
48
|
+
release, the slot marked `data-pedal`; a bar with one makes room below.
|
|
49
|
+
Spoken as "pedal G" and "pedal up C".
|
|
50
|
+
- **Dotted figures** (grammar 2.2): a dotted group draws no tuplet number
|
|
51
|
+
and puts a dot after its dotted member (`data-dotted` on the group);
|
|
52
|
+
spoken "C dotted, D".
|
|
53
|
+
|
|
9
54
|
## [0.13.0] - 2026-11-04
|
|
10
55
|
|
|
11
56
|
Needs `barmark` 0.15.0.
|
|
@@ -330,7 +375,9 @@ that needs no script or as the `<barmark-chart>` web component. Requires
|
|
|
330
375
|
zoom without sideways scrolling, the element renders and re-renders, and
|
|
331
376
|
a screen reader hears "bar 9: D". Run them with `bun run test:browser`.
|
|
332
377
|
|
|
333
|
-
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.
|
|
378
|
+
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.15.0...HEAD
|
|
379
|
+
[0.15.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.14.0...render-v0.15.0
|
|
380
|
+
[0.14.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.13.0...render-v0.14.0
|
|
334
381
|
[0.13.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.12.0...render-v0.13.0
|
|
335
382
|
[0.12.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.11.0...render-v0.12.0
|
|
336
383
|
[0.11.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.10.0...render-v0.11.0
|
package/README.md
CHANGED
|
@@ -129,6 +129,7 @@ Set these custom properties on the element or anything above it:
|
|
|
129
129
|
| `--barmark-accent` | errors |
|
|
130
130
|
| `--barmark-directive` | mid-chart changes (default the muted colour) |
|
|
131
131
|
| `--barmark-note` | `###` note lines (default the ink colour) |
|
|
132
|
+
| `--barmark-lyrics` | syllables under a voice line and in lyric rows (default the ink colour) |
|
|
132
133
|
|
|
133
134
|
```css
|
|
134
135
|
barmark-chart {
|
|
@@ -142,7 +143,8 @@ barmark-chart::part(heading) {
|
|
|
142
143
|
```
|
|
143
144
|
|
|
144
145
|
`::part()` names: `title`, `meta`, `heading`, `bar`, `chord`, `text`,
|
|
145
|
-
`bar-number`, `rehearsal
|
|
146
|
+
`bar-number`, `rehearsal`, `lyrics` (each verse's line of words, inside
|
|
147
|
+
its `bar`). These, the custom properties and the
|
|
146
148
|
attributes are the public surface: changing them is a breaking change.
|
|
147
149
|
|
|
148
150
|
## Light, dark and print
|
|
@@ -196,6 +198,24 @@ shape; a tutti line is one row. The header lists the parts' names, and
|
|
|
196
198
|
each part row is announced by name to a screen reader. On a screen too
|
|
197
199
|
narrow for a section, its rows wrap one by one, as any row does.
|
|
198
200
|
|
|
201
|
+
A voice line (barmark's grammar 4.3 and 7.7: the line a part sings on,
|
|
202
|
+
such as `Vox.Mel` under a lead sheet's bare `Vox` chord line) draws each
|
|
203
|
+
note as its pitch name (every note of a set, without octaves) and
|
|
204
|
+
under it, in italics, the syllable each verse sings there: verse 1 from
|
|
205
|
+
the syllables on the notes, then each `lyrics N:` row, numbered "1.",
|
|
206
|
+
"2." left of the first bar when there are several. A hyphen follows a
|
|
207
|
+
syllable whose word goes on, and a held syllable (`:/`) draws an extender
|
|
208
|
+
line. The notes are spaced by beat, each as wide as the widest note or
|
|
209
|
+
syllable. Verses come from the parser as played, placed under the written
|
|
210
|
+
bars: a repeat's verse 2 is drawn under the bars it is sung on, and a
|
|
211
|
+
replay draws its own words. A voice line with no words draws as any part
|
|
212
|
+
line does. A lyric row on no melody (the chart's words, or a singer who
|
|
213
|
+
writes no notes there) draws its words inside the bars it covers, a line
|
|
214
|
+
per verse spaced by beat, so on a narrow screen they wrap with their
|
|
215
|
+
bars; under a system they go in its last row. A screen reader hears the
|
|
216
|
+
words after each bar's notes: "bar 2: note G four, hold, …, verse 1
|
|
217
|
+
“maz-ing”, verse 2 “grace that”".
|
|
218
|
+
|
|
199
219
|
## License
|
|
200
220
|
|
|
201
221
|
MIT. Edwin is © MuseScore Limited, under the SIL Open Font License 1.1.
|
package/dist/html.js
CHANGED
|
@@ -9,8 +9,9 @@ import { creditsText } from "./credits.js";
|
|
|
9
9
|
import { escapeHtml } from "./escape.js";
|
|
10
10
|
import { fontFaceCss } from "./font.js";
|
|
11
11
|
import { isTacet as isTacetCell, layoutChart } from "./model.js";
|
|
12
|
-
import { speakBar } from "./speech.js";
|
|
12
|
+
import { speakBar, speakVerses } from "./speech.js";
|
|
13
13
|
import { FIT_STEPS, MIN_BAR, stylesheet } from "./styles.js";
|
|
14
|
+
import { beatLinesHtml, pitchHtml, sungBar, sungSlotHtml, verseNumbersHtml, verseWidth, } from "./verses-html.js";
|
|
14
15
|
export function renderChart(text, options = {}) {
|
|
15
16
|
return `${fontStyle(options)}<barmark-chart${elementAttributes(options)}><template shadowrootmode="open">${shadowContent(text, options)}</template></barmark-chart>`;
|
|
16
17
|
}
|
|
@@ -44,17 +45,24 @@ function chartHtml(text, options) {
|
|
|
44
45
|
...(options.part && { part: options.part }),
|
|
45
46
|
});
|
|
46
47
|
const barNumbers = options.barNumbers ?? true;
|
|
47
|
-
const parts = model
|
|
48
|
+
const parts = labelled(model);
|
|
48
49
|
const settings = {
|
|
49
50
|
barNumbers,
|
|
50
51
|
gutter: barNumbers || parts,
|
|
51
52
|
numerals: numeralsOf(options),
|
|
52
53
|
};
|
|
53
54
|
// Every section's left column is as wide as the longest part label, so tutti rows line up with systems.
|
|
54
|
-
const widest = Math.max(0, ...model.parts.map((
|
|
55
|
+
const widest = Math.max(0, ...model.parts.flatMap(rowLabelsOf).map((l) => l.length));
|
|
55
56
|
const gutter = parts ? ` data-parts style="--bm-label-chars:${widest}"` : "";
|
|
56
57
|
return `<div class="bm-chart" data-theme="${themeOf(options)}"${gutter}${settings.barNumbers ? "" : ' data-bar-numbers="off"'}${options.wrap === false ? ' data-wrap="off"' : ""}>${headerHtml(model)}${model.blocks.map((b) => blockHtml(b, settings)).join("")}${copyrightHtml(model)}${options.diagnostics ? diagnosticsHtml(model) : ""}</div>`;
|
|
57
58
|
}
|
|
59
|
+
/** Whether systems have labelled rows: several parts, or one part writing lines (barmark's grammar 7.6). */
|
|
60
|
+
const labelled = (model) => model.parts.length > 1 || model.parts.some((p) => (p.lines?.length ?? 0) > 0);
|
|
61
|
+
/** A part's row labels: its own, and one per line it writes (barmark's grammar 7.6). */
|
|
62
|
+
const rowLabelsOf = (p) => [
|
|
63
|
+
p.label ?? "",
|
|
64
|
+
...(p.lines ?? []).map((n) => `${p.label ?? ""}.${n}`),
|
|
65
|
+
];
|
|
58
66
|
function headerHtml(model) {
|
|
59
67
|
const title = model.title
|
|
60
68
|
? `<h2 class="bm-title" part="title">${escapeHtml(model.title)}</h2>`
|
|
@@ -108,12 +116,16 @@ function blockHtml(block, settings) {
|
|
|
108
116
|
*/
|
|
109
117
|
function fitWidth(block) {
|
|
110
118
|
const widths = [];
|
|
119
|
+
const widen = (bars) => {
|
|
120
|
+
for (const [i, w] of bars.entries())
|
|
121
|
+
widths[i] = Math.max(widths[i] ?? 0, w);
|
|
122
|
+
};
|
|
111
123
|
for (const item of block.items) {
|
|
112
|
-
if (item.kind
|
|
113
|
-
|
|
114
|
-
item.
|
|
115
|
-
|
|
116
|
-
|
|
124
|
+
if (item.kind === "row")
|
|
125
|
+
widen(item.cells.map(cellWidth));
|
|
126
|
+
const verses = item.kind === "row" ? [...(item.verses ?? []), ...(item.lyrics ?? [])] : [];
|
|
127
|
+
for (const v of verses)
|
|
128
|
+
widen(v.cells.map(verseWidth));
|
|
117
129
|
}
|
|
118
130
|
const total = 5 + widths.reduce((a, b) => a + b, 0);
|
|
119
131
|
return FIT_STEPS.find((step) => step >= total) ?? FIT_STEPS.at(-1) ?? 0;
|
|
@@ -203,22 +215,36 @@ function gutterHtml(row, settings, part) {
|
|
|
203
215
|
function rowCells(row, numerals, ending) {
|
|
204
216
|
let n = row.barNumber;
|
|
205
217
|
const firstTacet = row.cells.findIndex(isTacetCell);
|
|
218
|
+
const firstBar = row.cells.findIndex((c) => c.kind === "slots");
|
|
206
219
|
return row.cells.map((cell, i) => {
|
|
207
220
|
const marks = repeatMarks(row, i) + (i === 0 ? ending : "");
|
|
221
|
+
const sung = {
|
|
222
|
+
pitches: row.sings === true,
|
|
223
|
+
words: [wordsOn(row.verses, i, "sung"), wordsOn(row.lyrics, i, "words")]
|
|
224
|
+
.filter(Boolean)
|
|
225
|
+
.join(", "),
|
|
226
|
+
bar: sungBar(row.verses, i),
|
|
227
|
+
first: i === firstBar,
|
|
228
|
+
beats: beatLinesHtml(row.lyrics, i, i === firstBar),
|
|
229
|
+
};
|
|
208
230
|
const html = isTacetCell(cell)
|
|
209
231
|
? tacetHtml(cell, n, marks, i === firstTacet)
|
|
210
|
-
: cellHtml(cell, n, marks, numerals);
|
|
232
|
+
: cellHtml(cell, n, marks, numerals, sung);
|
|
211
233
|
if (n !== null && cell.kind === "slots")
|
|
212
234
|
n++;
|
|
213
235
|
return html;
|
|
214
236
|
});
|
|
215
237
|
}
|
|
238
|
+
/** The words on a row's cell, as a screen reader hears them after the bar's notes. */
|
|
239
|
+
const wordsOn = (verses = [], i, label) => speakVerses(verses.map((v) => ({ verse: v.verse, syllables: v.cells[i]?.flat() ?? [] })), verses.length > 1, label);
|
|
216
240
|
const sr = (text) => (text ? `<span class="bm-sr">${text}</span>` : "");
|
|
217
241
|
/** The row's class list. */
|
|
218
242
|
function rowClasses(row, part) {
|
|
219
243
|
const classes = ["bm-row"];
|
|
220
244
|
if (part)
|
|
221
245
|
classes.push("bm-part-row");
|
|
246
|
+
if (row.sings)
|
|
247
|
+
classes.push("bm-sings");
|
|
222
248
|
if (row.cells.some(isTacetCell))
|
|
223
249
|
classes.push("bm-tacet");
|
|
224
250
|
if (row.ending)
|
|
@@ -261,14 +287,19 @@ function rowRepeatHtml(row) {
|
|
|
261
287
|
return row.closes ? `<span class="bm-sr">repeat end, play 2 times</span>` : "";
|
|
262
288
|
return repeatHtml(row.repeat).trim();
|
|
263
289
|
}
|
|
264
|
-
function cellHtml(cell, barNumber, marks, numerals) {
|
|
265
|
-
const
|
|
266
|
-
const
|
|
290
|
+
function cellHtml(cell, barNumber, marks, numerals, sung) {
|
|
291
|
+
const numeral = numerals && cell.kind === "slots" && cell.key ? { style: numerals, key: cell.key } : null;
|
|
292
|
+
const said = [speakBar(barNumber, cell, numeral !== null), sung.words].filter(Boolean);
|
|
293
|
+
const spoken = `<span class="bm-sr">${escapeHtml(said.join(", "))}</span>`;
|
|
267
294
|
if (cell.kind !== "slots")
|
|
268
295
|
return betweenBarsHtml(cell, spoken, marks);
|
|
269
296
|
const change = cell.tempoChange ? ` data-tempo-change="${cell.tempoChange}"` : "";
|
|
270
|
-
const [body, end] = barBody(cell,
|
|
271
|
-
|
|
297
|
+
const [body, end] = barBody(cell, { numeral, pitches: sung.pitches, sung: sung.bar });
|
|
298
|
+
const numbers = sung.first ? verseNumbersHtml(sung.bar) : "";
|
|
299
|
+
const drawn = `<span class="bm-bar-body" aria-hidden="true">${body}</span>`;
|
|
300
|
+
// A lyric row's lines go under the bar body, in a stack that wraps with the bar.
|
|
301
|
+
const stack = sung.beats ? `<span class="bm-bar-stack">${drawn}${sung.beats}</span>` : drawn;
|
|
302
|
+
return `<div class="bm-bar" part="bar"${cell.cut ? " data-cut" : ""}${change}${marks}>${spoken}${numbers}${stack}${end}</div>`;
|
|
272
303
|
}
|
|
273
304
|
/** What a bar shows: its meter, its slots (or `%`), and "cut"; then the words after its last slot. */
|
|
274
305
|
function barBody(cell, view) {
|
|
@@ -330,21 +361,48 @@ const FERMATA = `<svg class="bm-fermata-glyph" viewBox="0 0 24 14" width="1.4em"
|
|
|
330
361
|
/** `‹` for an eighth push, `«` for a sixteenth. */
|
|
331
362
|
const PUSH_MARK = { eighth: "‹", sixteenth: "«" };
|
|
332
363
|
const ARTICULATION_MARK = { accent: ">", hit: "^" };
|
|
364
|
+
/** The piano score's marks: Ped. under a press, ✱ under a release (barmark's grammar 2.9). */
|
|
365
|
+
const PEDAL_MARK = { press: "Ped.", release: "✱" };
|
|
333
366
|
const marksOf = (slot) => ({
|
|
334
367
|
push: "push" in slot ? (slot.push ?? null) : null,
|
|
335
368
|
articulation: slot.kind === "chord" ? (slot.articulation ?? null) : null,
|
|
369
|
+
pedal: slot.kind === "chord" ? (slot.pedal ?? null) : null,
|
|
336
370
|
});
|
|
337
|
-
|
|
371
|
+
const dataOf = (marks) => Object.entries(marks)
|
|
372
|
+
.map(([k, v]) => (v ? ` data-${k}="${v}"` : ""))
|
|
373
|
+
.join("");
|
|
374
|
+
/** A slot with its push mark before it, its accent or hit above it and its pedal mark below. */
|
|
338
375
|
function slotHtml(slot, view) {
|
|
376
|
+
const html = markedSlotHtml(slot, view);
|
|
377
|
+
// On a singing line each note, a group's members each, has its syllables under it.
|
|
378
|
+
return view.sung && slot.kind !== "group" ? sungSlotHtml(html, view.sung) : html;
|
|
379
|
+
}
|
|
380
|
+
function markedSlotHtml(slot, view) {
|
|
339
381
|
const body = unmarkedSlotHtml(slot, view);
|
|
340
|
-
const
|
|
341
|
-
|
|
382
|
+
const marks = marksOf(slot);
|
|
383
|
+
const { push, articulation, pedal } = marks;
|
|
384
|
+
if (!push && !articulation && !pedal)
|
|
342
385
|
return body;
|
|
343
|
-
const
|
|
386
|
+
const before = push ? `<span class="bm-push" aria-hidden="true">${PUSH_MARK[push]}</span>` : "";
|
|
344
387
|
const above = articulation
|
|
345
388
|
? `<span class="bm-artic">${ARTICULATION_MARK[articulation]}</span>`
|
|
346
389
|
: "";
|
|
347
|
-
|
|
390
|
+
const below = pedal
|
|
391
|
+
? `<span class="bm-pedal" aria-hidden="true">${PEDAL_MARK[pedal]}</span>`
|
|
392
|
+
: "";
|
|
393
|
+
return `<span class="bm-marked"${dataOf(marks)}>${before}${above}${body}${below}</span>`;
|
|
394
|
+
}
|
|
395
|
+
/** A group: a tuplet number over equal members, or a dotted figure with its dot (barmark's grammar 2.2). */
|
|
396
|
+
function groupHtml(members, view) {
|
|
397
|
+
const dotted = members.some((m) => m.dotted);
|
|
398
|
+
const inner = members
|
|
399
|
+
.map((m) => m.dotted
|
|
400
|
+
? `<span class="bm-dotted">${slotHtml(m, view)}<span class="bm-dot" aria-hidden="true">.</span></span>`
|
|
401
|
+
: slotHtml(m, view))
|
|
402
|
+
.join("");
|
|
403
|
+
if (dotted)
|
|
404
|
+
return `<span class="bm-group" data-count="${members.length}" data-dotted>${inner}</span>`;
|
|
405
|
+
return `<span class="bm-group" data-count="${members.length}"><span class="bm-tuplet">${members.length}</span>${inner}</span>`;
|
|
348
406
|
}
|
|
349
407
|
function unmarkedSlotHtml(slot, view) {
|
|
350
408
|
switch (slot.kind) {
|
|
@@ -359,16 +417,19 @@ function unmarkedSlotHtml(slot, view) {
|
|
|
359
417
|
case "unknown":
|
|
360
418
|
return `<span class="bm-unknown">?</span>`;
|
|
361
419
|
case "group":
|
|
362
|
-
return
|
|
420
|
+
return groupHtml(slot.members, view);
|
|
363
421
|
}
|
|
364
422
|
}
|
|
365
423
|
function chordHtml(record, view) {
|
|
424
|
+
if (record.kind === "notes" && view.pitches)
|
|
425
|
+
return pitchHtml(record);
|
|
366
426
|
if (record.kind === "notes" || !record.parts)
|
|
367
427
|
return notesHtml(record);
|
|
368
|
-
const numeral = view
|
|
369
|
-
|
|
428
|
+
const { numeral } = view;
|
|
429
|
+
const pieces = numeral ? typesetNumeral(record.parts, numeral.key, numeral.style) : null;
|
|
430
|
+
if (!pieces)
|
|
370
431
|
return piecesHtml(typesetChord(record.parts), "");
|
|
371
|
-
return piecesHtml(
|
|
432
|
+
return piecesHtml(pieces, ` data-numeral="${numeral?.style}"`);
|
|
372
433
|
}
|
|
373
434
|
function piecesHtml(p, attributes) {
|
|
374
435
|
const quality = p.quality ? `<span class="bm-quality">${p.quality}</span>` : "";
|
package/dist/model.js
CHANGED
|
@@ -5,22 +5,25 @@
|
|
|
5
5
|
* bar numbers and the slots `%` copies.
|
|
6
6
|
*/
|
|
7
7
|
import { extractPart, parseChart, } from "barmark";
|
|
8
|
+
import { landings, rowVerses, singerOf, sungVerses } from "./verses.js";
|
|
8
9
|
/** Whether a tutti bar's parts play different slots, as `%` or `/` on a tutti line can. */
|
|
9
10
|
const playedApart = (b, line) => {
|
|
10
11
|
const own = (b.parts ?? []).filter((p) => p?.line === line).map((p) => JSON.stringify(p?.slots));
|
|
11
12
|
return new Set(own).size > 1;
|
|
12
13
|
};
|
|
13
|
-
/**
|
|
14
|
+
/** What each line written plays in a bar: each part's share, or each of its lines' (barmark's grammar 7.4, 7.6). */
|
|
15
|
+
const sharesOf = (b) => b.lines ?? (b.parts ?? []).flatMap((p) => p?.lines ?? [p]);
|
|
16
|
+
/** Each part's bars on its own lines, and each line's; a tutti bar once (barmark's grammar 7.4, 7.6). */
|
|
14
17
|
function barsByLine(parse) {
|
|
15
|
-
if (parse.parts.length < 2)
|
|
18
|
+
if (parse.parts.length < 2 && !parse.parts.some((p) => p.lines))
|
|
16
19
|
return parse.bars;
|
|
17
20
|
const seen = new Set();
|
|
18
|
-
return parse.bars.flatMap((b) => (b
|
|
21
|
+
return parse.bars.flatMap((b) => sharesOf(b).flatMap((p) => {
|
|
19
22
|
const key = `${b.index}:${p?.line}`;
|
|
20
23
|
if (!p || seen.has(key))
|
|
21
24
|
return [];
|
|
22
25
|
seen.add(key);
|
|
23
|
-
const { words: _w, parts: _p, tacet: _t, ...shared } = b;
|
|
26
|
+
const { words: _w, parts: _p, tacet: _t, lines: _l, ...shared } = b;
|
|
24
27
|
const apart = playedApart(b, p.line) ? { perPart: true } : {};
|
|
25
28
|
return [
|
|
26
29
|
{ ...shared, ...apart, line: p.line, slots: p.slots, ...(p.words && { words: p.words }) },
|
|
@@ -208,28 +211,64 @@ function layoutLines(lines, occurrence, ctx) {
|
|
|
208
211
|
let previous = null;
|
|
209
212
|
for (const [i, l] of lines.entries()) {
|
|
210
213
|
const system = systemOf(l);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (systemOf(lines[i - 1]) === system)
|
|
214
|
-
continue;
|
|
215
|
-
const item = layoutSystem(systemLines(lines, i), occurrence, previous, ctx);
|
|
216
|
-
previous = lastOfSystem(item) ?? previous;
|
|
217
|
-
items.push(item);
|
|
214
|
+
// A system is laid out once, at its first line.
|
|
215
|
+
if (system !== null && systemOf(lines[i - 1]) === system)
|
|
218
216
|
continue;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const item = layoutLine(l, occurrence, previous, ctx);
|
|
225
|
-
if (!item)
|
|
226
|
-
continue;
|
|
227
|
-
if (item.kind === "row")
|
|
228
|
-
previous = lastSlots(item.cells) ?? previous;
|
|
229
|
-
items.push(item);
|
|
217
|
+
const laid = system === null
|
|
218
|
+
? layoutOne(l, occurrence, previous, ctx)
|
|
219
|
+
: layoutSystemAt(systemLines(lines, i), occurrence, previous, ctx);
|
|
220
|
+
previous = laid.previous;
|
|
221
|
+
items.push(...laid.items);
|
|
230
222
|
}
|
|
231
223
|
return items;
|
|
232
224
|
}
|
|
225
|
+
/** A system, and the words under it that no line in it sings. */
|
|
226
|
+
function layoutSystemAt(lines, occurrence, previous, ctx) {
|
|
227
|
+
const item = layoutSystem(lines, occurrence, previous, ctx);
|
|
228
|
+
const lyrics = lyricRows(lines, occurrence, ctx);
|
|
229
|
+
// The words go under the system: in its last row that plays.
|
|
230
|
+
const last = item.rows.findLastIndex((p) => p.row.kind === "row" && !p.row.cells.some(isTacet));
|
|
231
|
+
const rows = item.rows.map((p, i) => i === last && p.row.kind === "row" && lyrics.length ? { ...p, row: { ...p.row, lyrics } } : p);
|
|
232
|
+
return { items: [{ ...item, rows }], previous: lastOfSystem(item) ?? previous };
|
|
233
|
+
}
|
|
234
|
+
/** A line outside a system: as written when it has an error; a bar line with the words under it. */
|
|
235
|
+
function layoutOne(l, occurrence, previous, ctx) {
|
|
236
|
+
if (ctx.errors.has(l.line))
|
|
237
|
+
return { items: [errorItem(l.line, ctx)], previous };
|
|
238
|
+
const item = layoutLine(l, occurrence, previous, ctx);
|
|
239
|
+
if (!item)
|
|
240
|
+
return { items: [], previous };
|
|
241
|
+
if (item.kind !== "row" || l.kind !== "bars")
|
|
242
|
+
return { items: [item], previous };
|
|
243
|
+
const lyrics = lyricRows([l], occurrence, ctx);
|
|
244
|
+
const row = lyrics.length ? { ...item, lyrics } : item;
|
|
245
|
+
return { items: [row], previous: lastSlots(item.cells) ?? previous };
|
|
246
|
+
}
|
|
247
|
+
/** The written bars a bar line draws, as played in the occurrence: a cut bar as written. */
|
|
248
|
+
function landingsOn(l, played, ctx) {
|
|
249
|
+
const written = ctx.bars.filter((b) => b.line === l.line);
|
|
250
|
+
let bar = 0;
|
|
251
|
+
const bars = l.cells.map((cell) => {
|
|
252
|
+
if (cell.kind !== "slots" && cell.kind !== "simile")
|
|
253
|
+
return undefined;
|
|
254
|
+
const i = bar++;
|
|
255
|
+
return played[i] ?? written[i];
|
|
256
|
+
});
|
|
257
|
+
return landings(bars, played.length ? played : written);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The words under a row or system that no line in it sings under its
|
|
261
|
+
* slots (barmark's grammar 7.7): a lyric row on no melody, spaced by beat.
|
|
262
|
+
*/
|
|
263
|
+
function lyricRows(lines, occurrence, ctx) {
|
|
264
|
+
const drawn = lines.filter((l) => l.kind === "bars" && !ctx.errors.has(l.line));
|
|
265
|
+
const ref = drawn[0];
|
|
266
|
+
if (!ref)
|
|
267
|
+
return [];
|
|
268
|
+
const sung = new Set(drawn.flatMap((l) => singerOf(l, ctx.parse) ?? []));
|
|
269
|
+
const lands = landingsOn(ref, playedOn(ref.line, occurrence, ctx.bars), ctx);
|
|
270
|
+
return rowVerses(lands, sung);
|
|
271
|
+
}
|
|
233
272
|
const systemOf = (l) => (l?.kind === "bars" || l?.kind === "invalid") && l.system !== undefined ? l.system : null;
|
|
234
273
|
/** The lines of the system that starts at `i`. */
|
|
235
274
|
function systemLines(lines, i) {
|
|
@@ -248,20 +287,31 @@ const lastOfSystem = (item) => {
|
|
|
248
287
|
};
|
|
249
288
|
/** A bar where the part rests, in a system or a part's own view (barmark's grammar 7.4). */
|
|
250
289
|
export const isTacet = (c) => c.kind === "slots" && c.tacet === true;
|
|
251
|
-
/** A
|
|
290
|
+
/** A part's lines in a system, in score order: its bare line, then its lines (barmark's grammar 7.6). */
|
|
291
|
+
function ownLines(lines, p) {
|
|
292
|
+
const order = (l) => l.lineName === undefined ? -1 : (p.lines ?? []).indexOf(l.lineName);
|
|
293
|
+
return lines.filter((l) => l.part === p.label).sort((a, b) => order(a) - order(b));
|
|
294
|
+
}
|
|
295
|
+
/** A row's spoken name: the part's, and its line's (barmark's grammar 7.6): "Piano RH". */
|
|
296
|
+
const spokenOf = (p, l) => l.lineName === undefined ? p.name : `${p.name} ${l.lineName}`;
|
|
297
|
+
/** A system row's label: the part's, and its line's name (`Pno.RH`). */
|
|
298
|
+
const labelOf = (l) => `${l.part ?? ""}${l.lineName === undefined ? "" : `.${l.lineName}`}`;
|
|
299
|
+
/** A row per declared part, or per line it writes, in score order: its own line, its error, or tacet bars. */
|
|
252
300
|
function layoutSystem(lines, occurrence, previous, ctx) {
|
|
253
301
|
const ref = lines.find((l) => l.kind === "bars" && !ctx.errors.has(l.line));
|
|
254
302
|
const reference = ref
|
|
255
303
|
? layoutRow(ref, playedOn(ref.line, occurrence, ctx.bars), previous, ctx)
|
|
256
304
|
: null;
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
305
|
+
const ownRow = (own) => ctx.errors.has(own.line) || own.kind !== "bars"
|
|
306
|
+
? errorItem(own.line, ctx)
|
|
307
|
+
: layoutRow(own, playedOn(own.line, occurrence, ctx.bars), previous, ctx);
|
|
308
|
+
const rows = ctx.parse.parts.flatMap((p) => {
|
|
309
|
+
const own = ownLines(lines, p);
|
|
310
|
+
if (!own.length)
|
|
311
|
+
return [
|
|
312
|
+
{ label: p.label ?? "", name: p.name, row: tacetRow(reference, lines[0]?.line ?? 0) },
|
|
313
|
+
];
|
|
314
|
+
return own.map((l) => ({ label: labelOf(l), name: spokenOf(p, l), row: ownRow(l) }));
|
|
265
315
|
});
|
|
266
316
|
return {
|
|
267
317
|
kind: "system",
|
|
@@ -345,8 +395,18 @@ function layoutRow(l, played, previous, ctx) {
|
|
|
345
395
|
repeat: l.repeat,
|
|
346
396
|
ending: l.ending,
|
|
347
397
|
cells,
|
|
398
|
+
...singing(l, cells, played, ctx),
|
|
348
399
|
};
|
|
349
400
|
}
|
|
401
|
+
/** A singing line's fields: its note sets as pitch names, and the verses under its slots (barmark's grammar 7.7). */
|
|
402
|
+
function singing(l, cells, played, ctx) {
|
|
403
|
+
const singer = singerOf(l, ctx.parse);
|
|
404
|
+
if (singer === null)
|
|
405
|
+
return {};
|
|
406
|
+
const verses = sungVerses(cells, landingsOn(l, played, ctx), singer);
|
|
407
|
+
// A line with no words draws as any part line does.
|
|
408
|
+
return verses.length ? { sings: true, verses } : {};
|
|
409
|
+
}
|
|
350
410
|
/** A cell as drawn: `%` becomes the bar it copies, its slots as the parser resolved them; `previous` lends only its meter. */
|
|
351
411
|
function layoutCell(cell, played, previous) {
|
|
352
412
|
if (cell.kind === "fermata")
|
package/dist/speech.d.ts
CHANGED
|
@@ -2,10 +2,19 @@
|
|
|
2
2
|
* Spoken names: how a screen reader reads a chart as music. Built from the
|
|
3
3
|
* parsed structure, never from the symbol's text.
|
|
4
4
|
*/
|
|
5
|
-
import { type ChordRecord, type Key, type Slot } from "barmark";
|
|
5
|
+
import { type ChordRecord, type Key, type Slot, type Syllable } from "barmark";
|
|
6
6
|
import type { CellModel } from "./types.js";
|
|
7
7
|
/** A chord's name; with a key, its degree first: "five, A seven". */
|
|
8
8
|
export declare function speakChord(record: ChordRecord, key?: Key): string;
|
|
9
9
|
export declare function speakSlot(slot: Slot, key?: Key): string;
|
|
10
10
|
/** "bar 9: G, hold, D, hold"; a fermata is held until cued. With `numerals`, each chord's degree comes first. */
|
|
11
11
|
export declare function speakBar(barNumber: number | null, cell: CellModel, numerals?: boolean): string;
|
|
12
|
+
/**
|
|
13
|
+
* The words on a bar, each verse's: `sung “maz-ing”` (or `words “…”` in a
|
|
14
|
+
* lyric row on no melody), or with several verses `verse 1 “maz-ing”,
|
|
15
|
+
* verse 2 “grace that”`. Empty when nothing is sung there.
|
|
16
|
+
*/
|
|
17
|
+
export declare function speakVerses(verses: {
|
|
18
|
+
verse: number;
|
|
19
|
+
syllables: Syllable[];
|
|
20
|
+
}[], numbered: boolean, label: "sung" | "words"): string;
|
package/dist/speech.js
CHANGED
|
@@ -114,9 +114,19 @@ function speakChordSlot(slot, key) {
|
|
|
114
114
|
return `accented ${voiced}`;
|
|
115
115
|
return slot.articulation === "hit" ? `${voiced} short hit` : voiced;
|
|
116
116
|
}
|
|
117
|
+
const PEDALLED = { press: "pedal", release: "pedal up" };
|
|
117
118
|
export function speakSlot(slot, key) {
|
|
118
|
-
const
|
|
119
|
-
|
|
119
|
+
const unpushed = speakUnpushed(slot, key);
|
|
120
|
+
const said = "push" in slot && slot.push ? `${unpushed} ${PUSHED[slot.push]}` : unpushed;
|
|
121
|
+
const dotted = "dotted" in slot && slot.dotted ? `${said} dotted` : said;
|
|
122
|
+
return slot.kind === "chord" && slot.pedal ? `${PEDALLED[slot.pedal]} ${dotted}` : dotted;
|
|
123
|
+
}
|
|
124
|
+
/** "triplet: C, D, E"; a dotted figure is its members: "C dotted, D". */
|
|
125
|
+
function speakGroup(members, key) {
|
|
126
|
+
const said = members.map((m) => speakSlot(m, key)).join(", ");
|
|
127
|
+
if (members.some((m) => m.dotted))
|
|
128
|
+
return said;
|
|
129
|
+
return `${GROUPS[members.length] ?? `group of ${members.length}`}: ${said}`;
|
|
120
130
|
}
|
|
121
131
|
function speakUnpushed(slot, key) {
|
|
122
132
|
switch (slot.kind) {
|
|
@@ -131,7 +141,7 @@ function speakUnpushed(slot, key) {
|
|
|
131
141
|
case "unknown":
|
|
132
142
|
return "unknown chord";
|
|
133
143
|
case "group":
|
|
134
|
-
return
|
|
144
|
+
return speakGroup(slot.members, key);
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
147
|
/** "segno", "to coda", "dal segno al coda", "da capo al fine". */
|
|
@@ -158,3 +168,23 @@ export function speakBar(barNumber, cell, numerals = false) {
|
|
|
158
168
|
const spoken = [...slots, ...words(cell.slots.length)].join(", ");
|
|
159
169
|
return `bar${barNumber === null ? "" : ` ${barNumber}`}${meter}: ${spoken}${cut}`;
|
|
160
170
|
}
|
|
171
|
+
/** A verse's syllables as words: "maz-ing"; elided syllables apart, a held one silent. */
|
|
172
|
+
function speakSyllables(syllables) {
|
|
173
|
+
let words = "";
|
|
174
|
+
for (const s of syllables)
|
|
175
|
+
if (s.kind === "sung")
|
|
176
|
+
words += `${s.parts.join(" ")}${s.continues ? "-" : " "}`;
|
|
177
|
+
return words.trim();
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The words on a bar, each verse's: `sung “maz-ing”` (or `words “…”` in a
|
|
181
|
+
* lyric row on no melody), or with several verses `verse 1 “maz-ing”,
|
|
182
|
+
* verse 2 “grace that”`. Empty when nothing is sung there.
|
|
183
|
+
*/
|
|
184
|
+
export function speakVerses(verses, numbered, label) {
|
|
185
|
+
return verses
|
|
186
|
+
.map((v) => ({ verse: v.verse, words: speakSyllables(v.syllables) }))
|
|
187
|
+
.filter((v) => v.words)
|
|
188
|
+
.map((v) => `${numbered ? `verse ${v.verse}` : label} “${v.words}”`)
|
|
189
|
+
.join(", ");
|
|
190
|
+
}
|
package/dist/styles.js
CHANGED
|
@@ -18,6 +18,7 @@ const SIZES = {
|
|
|
18
18
|
text: 0.9,
|
|
19
19
|
noChord: 1.03,
|
|
20
20
|
noteNames: 0.9,
|
|
21
|
+
syllables: 0.9,
|
|
21
22
|
superscript: 0.84,
|
|
22
23
|
octave: 0.79,
|
|
23
24
|
tuplet: 0.84,
|
|
@@ -39,6 +40,14 @@ const ROW_GAP = 0.35;
|
|
|
39
40
|
* nothing is painted over it and any paper shows through.
|
|
40
41
|
*/
|
|
41
42
|
const BRACKET = { top: 0.6, hook: 0.3, line: 0.06 };
|
|
43
|
+
/**
|
|
44
|
+
* A singing line's lines, in chord sizes: the note's (the chart's line
|
|
45
|
+
* height), then each verse's under it. The verse numbers left of the first
|
|
46
|
+
* bar sit on the verses' lines, below the bar's top padding and the note's.
|
|
47
|
+
* A singing bar spaces its slots by beat: equal grid columns, each as wide
|
|
48
|
+
* as the widest note or syllable.
|
|
49
|
+
*/
|
|
50
|
+
const SUNG = { note: 1.3, verse: 1.25, barTop: 0.65 };
|
|
42
51
|
/** The single note's ring, in its own em: padding, and the border it spills past. */
|
|
43
52
|
const RING = { y: 0.21, x: 0.5, border: 0.07 };
|
|
44
53
|
const em = (n) => `${Number(n.toFixed(3))}em`;
|
|
@@ -136,6 +145,10 @@ const css = `
|
|
|
136
145
|
.bm-push{font:700 .8em/1 system-ui,sans-serif;color:var(--bm-muted);margin-right:.08em}
|
|
137
146
|
.bm-artic{position:absolute;left:50%;top:-.95em;transform:translateX(-50%);font:700 .7em/1 system-ui,sans-serif;color:var(--bm-ink)}
|
|
138
147
|
.bm-marked[data-push]>.bm-artic{left:calc(50% + .25em)}
|
|
148
|
+
.bm-pedal{position:absolute;left:0;bottom:-1.05em;font:italic 600 .62em/1 Georgia,serif;color:var(--bm-muted);white-space:nowrap}
|
|
149
|
+
.bm-dotted{display:inline-flex;align-items:baseline}
|
|
150
|
+
.bm-dot{font-weight:700;margin-left:.05em}
|
|
151
|
+
.bm-bar:has(.bm-pedal){padding-bottom:1.05em}
|
|
139
152
|
.bm-words{position:absolute;left:0;top:-1.05em;font:italic .62em/1 Georgia,serif;color:var(--bm-muted);white-space:nowrap}
|
|
140
153
|
.bm-bar>.bm-words-end{left:auto;right:.5em;top:.15em}
|
|
141
154
|
.bm-bar[data-ending]::after{content:attr(data-ending);position:absolute;left:.45em;top:.2em;font:italic .75em/1 Georgia,serif;color:var(--bm-muted)}
|
|
@@ -144,6 +157,25 @@ const css = `
|
|
|
144
157
|
.bm-bar[data-tempo-change]::before{content:"";position:absolute;inset:.15em 0 auto;border-top:.08em dashed var(--barmark-directive,var(--bm-muted))}
|
|
145
158
|
.bm-bar[data-cut]{outline:.08em dashed var(--bm-muted);outline-offset:-.25em}
|
|
146
159
|
.bm-cut{position:absolute;top:.3em;right:.45em;font:${em(SIZES.cut)}/1 ${SANS};color:var(--bm-muted)}
|
|
160
|
+
.bm-pitch{font-size:${em(SIZES.noteNames)}}
|
|
161
|
+
.bm-sung{display:inline-flex;flex-direction:column}
|
|
162
|
+
.bm-sung-note{height:${em(SUNG.note)}}
|
|
163
|
+
.bm-sings .bm-bar-body{display:grid;grid-auto-flow:column;grid-auto-columns:1fr;column-gap:.6em;align-items:baseline}
|
|
164
|
+
.bm-sings .bm-bar-body:has(>.bm-meter){grid-template-columns:auto}
|
|
165
|
+
.bm-sings .bm-meter{align-self:start}
|
|
166
|
+
.bm-under{height:${at(SIZES.syllables, SUNG.verse)}}
|
|
167
|
+
.bm-verse-numbers{position:absolute;right:100%;top:${em(SUNG.barTop + SUNG.note)};display:flex;flex-direction:column;align-items:flex-end;margin-right:.45em}
|
|
168
|
+
.bm-verse-numbers>.bm-verse{height:${at(SIZES.barNumber, SUNG.verse)};line-height:${at(SIZES.barNumber, SUNG.verse)}}
|
|
169
|
+
.bm-verse{font:italic ${em(SIZES.barNumber)} ${SANS};color:var(--bm-muted)}
|
|
170
|
+
.bm-bar-stack{display:flex;flex:1;flex-direction:column}
|
|
171
|
+
.bm-bar-stack>.bm-bar-body{flex:none}
|
|
172
|
+
.bm-beats{position:relative;display:flex;align-items:baseline;gap:.3em;margin-top:.15em}
|
|
173
|
+
.bm-beats>.bm-syllable-slot{flex:1 1 0;min-width:max-content}
|
|
174
|
+
.bm-beats>.bm-verse{position:absolute;right:calc(100% + ${at(SIZES.barNumber, 0.7 + 0.45)})}
|
|
175
|
+
:is(.bm-syllable-slot,.bm-under){display:flex;align-items:baseline;gap:.3em;font:italic ${em(SIZES.syllables)}/${SUNG.verse / SIZES.syllables} ${TEXT};color:var(--barmark-lyrics,var(--bm-ink));white-space:nowrap}
|
|
176
|
+
.bm-syllable{display:flex;flex:1;align-items:baseline}
|
|
177
|
+
.bm-hyphen{flex:1;text-align:center;padding-inline:.15em}
|
|
178
|
+
.bm-extender{flex:1;min-width:.8em;align-self:flex-end;margin-bottom:.3em;border-bottom:.07em solid currentColor}
|
|
147
179
|
.bm-text{grid-column:1/-1;margin:.2em 0 .5em ${at(SIZES.text, GUTTER)};font-family:${TEXT};font-size:${em(SIZES.text)}}
|
|
148
180
|
.bm-note{font-style:italic;color:var(--barmark-note,var(--bm-ink))}
|
|
149
181
|
.bm-error{grid-column:1/-1;margin:.3em 0}
|
|
@@ -152,7 +184,7 @@ const css = `
|
|
|
152
184
|
.bm-diagnostics .bm-error{color:var(--bm-accent)}
|
|
153
185
|
@media (forced-colors:active){
|
|
154
186
|
.bm-bar,.bm-row>div.bm-bar:first-of-type,.bm-row>div.bm-bar[data-repeat-start],.bm-row>div.bm-bar[data-repeat-end]{border-color:CanvasText}
|
|
155
|
-
.bm-ring,.bm-tuplet::before,.bm-tuplet::after{border-color:CanvasText}
|
|
187
|
+
.bm-ring,.bm-tuplet::before,.bm-tuplet::after,.bm-extender{border-color:CanvasText}
|
|
156
188
|
.bm-silence{background:CanvasText;forced-color-adjust:none}
|
|
157
189
|
.bm-bar[data-cut]{outline-color:CanvasText}
|
|
158
190
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChartDiagnostic, Credits, Direction, Directives, Key, Meter,
|
|
1
|
+
import type { ChartDiagnostic, Credits, DeclaredPart, Direction, Directives, Key, Meter, Repeat, Slot, Syllable, Words } from "barmark";
|
|
2
2
|
/** `part`: draw only the part with this label (barmark's grammar 7.4), as a single-part chart. */
|
|
3
3
|
export type LayoutOptions = {
|
|
4
4
|
rehearsalLetters?: boolean;
|
|
@@ -8,9 +8,9 @@ export type LayoutOptions = {
|
|
|
8
8
|
export type ChartModel = {
|
|
9
9
|
title: string | null;
|
|
10
10
|
/** What `part:` names in a single-part chart; null when the chart names none or several. */
|
|
11
|
-
part:
|
|
12
|
-
/** Every declared part, in score order (barmark's grammar 7.4). */
|
|
13
|
-
parts:
|
|
11
|
+
part: DeclaredPart | null;
|
|
12
|
+
/** Every declared part, in score order (barmark's grammar 7.4), with its lines (7.6). */
|
|
13
|
+
parts: DeclaredPart[];
|
|
14
14
|
/** The chart's credit lines (barmark's grammar 7.5). */
|
|
15
15
|
credits: Credits;
|
|
16
16
|
/** Directives before the first heading, bar line or text line. */
|
|
@@ -44,6 +44,16 @@ export type BlockItem = {
|
|
|
44
44
|
/** The passes an ending plays on; null for any other row. */
|
|
45
45
|
ending: number[] | null;
|
|
46
46
|
cells: CellModel[];
|
|
47
|
+
/** Set on a line that sings words (barmark's grammar 7.7): its note sets draw as pitch names over them. */
|
|
48
|
+
sings?: true;
|
|
49
|
+
/** The verses sung on a singing line's bars, in verse order, each syllable under its slot. */
|
|
50
|
+
verses?: Verse[];
|
|
51
|
+
/**
|
|
52
|
+
* A lyric row on no melody under this row, or under the system whose
|
|
53
|
+
* last row this is (barmark's grammar 7.7): each verse's syllables in
|
|
54
|
+
* the bars they cover, spaced by beat.
|
|
55
|
+
*/
|
|
56
|
+
lyrics?: Verse[];
|
|
47
57
|
}
|
|
48
58
|
/**
|
|
49
59
|
* A system (barmark's grammar 7.4): a row per declared part, in score
|
|
@@ -69,6 +79,17 @@ export type BlockItem = {
|
|
|
69
79
|
kind: "directive";
|
|
70
80
|
set: Directives;
|
|
71
81
|
} | ErrorItem;
|
|
82
|
+
/**
|
|
83
|
+
* One verse's syllables on a row's bars, as the parser places them: per
|
|
84
|
+
* cell (a cell that isn't a bar has none), per position, the syllables
|
|
85
|
+
* there. Under a singing line the positions are the bar's slots, a group's
|
|
86
|
+
* members each one; in a lyric row they are equal steps of the bar, as fine
|
|
87
|
+
* as its syllables need.
|
|
88
|
+
*/
|
|
89
|
+
export type Verse = {
|
|
90
|
+
verse: number;
|
|
91
|
+
cells: Syllable[][][];
|
|
92
|
+
};
|
|
72
93
|
export type ErrorItem = {
|
|
73
94
|
kind: "error";
|
|
74
95
|
line: number;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words as HTML (barmark's grammar 4.3, 7.7). A singing line draws
|
|
3
|
+
* each note as its pitch name with each verse's syllable under it, in one
|
|
4
|
+
* column per slot, so words stay under their notes however the bar is laid
|
|
5
|
+
* out or wrapped. A lyric row on no melody draws a line per verse in each
|
|
6
|
+
* bar it covers, spaced by beat, so its words wrap with their bars. Every
|
|
7
|
+
* syllable is escaped text.
|
|
8
|
+
*/
|
|
9
|
+
import type { ChordRecord, Syllable } from "barmark";
|
|
10
|
+
import type { Verse } from "./types.js";
|
|
11
|
+
/** A note set on a singing line: its notes' names, without octaves (a divisi shows each). */
|
|
12
|
+
export declare function pitchHtml(record: ChordRecord): string;
|
|
13
|
+
/**
|
|
14
|
+
* A singing line's bar as it draws: each verse's syllables by place (a
|
|
15
|
+
* slot, a group's members each one), taken in slot order as the slots draw.
|
|
16
|
+
*/
|
|
17
|
+
export type SungBar = {
|
|
18
|
+
verses: {
|
|
19
|
+
verse: number;
|
|
20
|
+
places: Syllable[][];
|
|
21
|
+
}[];
|
|
22
|
+
next: number;
|
|
23
|
+
};
|
|
24
|
+
/** A singing row's bar `i`; null when nothing is sung on the row. */
|
|
25
|
+
export declare function sungBar(verses: Verse[] | undefined, i: number): SungBar | null;
|
|
26
|
+
/** A slot of a singing line: its note, and under it a line per verse with what that verse sings there. */
|
|
27
|
+
export declare function sungSlotHtml(slot: string, bar: SungBar): string;
|
|
28
|
+
/** The verse numbers, "1.", "2.", left of a singing row's first bar, each on its verse's line; none for one verse. */
|
|
29
|
+
export declare const verseNumbersHtml: (bar: SungBar | null) => string;
|
|
30
|
+
/**
|
|
31
|
+
* A lyric row's words on no melody in the bar `i` they cover, a line per
|
|
32
|
+
* verse spaced by beat, each numbered at the row's first bar when there
|
|
33
|
+
* are several. Empty when the row has none.
|
|
34
|
+
*/
|
|
35
|
+
export declare function beatLinesHtml(verses: Verse[] | undefined, i: number, first: boolean): string;
|
|
36
|
+
/** Roughly how many em a verse's bar needs: 0.55em a character, and the gap after each place. */
|
|
37
|
+
export declare const verseWidth: (places: Syllable[][]) => number;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { splitPitch } from "./chord.js";
|
|
2
|
+
import { escapeHtml } from "./escape.js";
|
|
3
|
+
/** A note set on a singing line: its notes' names, without octaves (a divisi shows each). */
|
|
4
|
+
export function pitchHtml(record) {
|
|
5
|
+
const names = record.pitches.map((p) => splitPitch(p).name).join(" ");
|
|
6
|
+
return `<span class="bm-chord bm-pitch" part="chord">${escapeHtml(names)}</span>`;
|
|
7
|
+
}
|
|
8
|
+
/** Elided syllables (`the~end`) join under a tie, as a lead sheet prints them. */
|
|
9
|
+
const ELISION = "‿";
|
|
10
|
+
/** A syllable, with a hyphen after it when the word goes on; a held one is an extender line. */
|
|
11
|
+
function syllableHtml(s) {
|
|
12
|
+
if (s.kind === "held")
|
|
13
|
+
return `<span class="bm-extender"></span>`;
|
|
14
|
+
const hyphen = s.continues ? `<span class="bm-hyphen"> –</span>` : "";
|
|
15
|
+
return `<span class="bm-syllable">${escapeHtml(s.parts.join(ELISION))}${hyphen}</span>`;
|
|
16
|
+
}
|
|
17
|
+
const syllablesHtml = (syllables) => syllables.map(syllableHtml).join(" ");
|
|
18
|
+
/** A singing row's bar `i`; null when nothing is sung on the row. */
|
|
19
|
+
export function sungBar(verses, i) {
|
|
20
|
+
if (!verses?.length)
|
|
21
|
+
return null;
|
|
22
|
+
return { verses: verses.map((v) => ({ verse: v.verse, places: v.cells[i] ?? [] })), next: 0 };
|
|
23
|
+
}
|
|
24
|
+
/** A slot of a singing line: its note, and under it a line per verse with what that verse sings there. */
|
|
25
|
+
export function sungSlotHtml(slot, bar) {
|
|
26
|
+
const k = bar.next++;
|
|
27
|
+
const lines = bar.verses.map((v) => `<span class="bm-under" part="lyrics" data-verse="${v.verse}">${syllablesHtml(v.places[k] ?? [])}</span>`);
|
|
28
|
+
return `<span class="bm-sung"><span class="bm-sung-note">${slot}</span>${lines.join("")}</span>`;
|
|
29
|
+
}
|
|
30
|
+
/** The verse numbers, "1.", "2.", left of a singing row's first bar, each on its verse's line; none for one verse. */
|
|
31
|
+
export const verseNumbersHtml = (bar) => bar && bar.verses.length > 1
|
|
32
|
+
? `<span class="bm-verse-numbers" aria-hidden="true">${bar.verses.map((v) => `<span class="bm-verse">${v.verse}.</span>`).join("")}</span>`
|
|
33
|
+
: "";
|
|
34
|
+
/** One step of a lyric row's bar. */
|
|
35
|
+
const stepHtml = (syllables) => `<span class="bm-syllable-slot">${syllablesHtml(syllables)}</span>`;
|
|
36
|
+
/**
|
|
37
|
+
* A lyric row's words on no melody in the bar `i` they cover, a line per
|
|
38
|
+
* verse spaced by beat, each numbered at the row's first bar when there
|
|
39
|
+
* are several. Empty when the row has none.
|
|
40
|
+
*/
|
|
41
|
+
export function beatLinesHtml(verses, i, first) {
|
|
42
|
+
const numbered = (verses?.length ?? 0) > 1;
|
|
43
|
+
return (verses ?? [])
|
|
44
|
+
.map((v) => {
|
|
45
|
+
const number = numbered && first ? `<span class="bm-verse">${v.verse}.</span>` : "";
|
|
46
|
+
const steps = (v.cells[i] ?? []).map(stepHtml).join("");
|
|
47
|
+
return `<span class="bm-beats" part="lyrics" data-verse="${v.verse}" aria-hidden="true">${number}${steps}</span>`;
|
|
48
|
+
})
|
|
49
|
+
.join("");
|
|
50
|
+
}
|
|
51
|
+
/** Roughly how many em a verse's bar needs: 0.55em a character, and the gap after each place. */
|
|
52
|
+
export const verseWidth = (places) => places.length
|
|
53
|
+
? 1.5 +
|
|
54
|
+
places.reduce((w, p) => w +
|
|
55
|
+
0.6 +
|
|
56
|
+
p.reduce((c, s) => c + 0.55 * (s.kind === "sung" ? s.parts.join(" ").length + 1 : 1), 0), 0)
|
|
57
|
+
: 0;
|
package/dist/verses.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the words go (barmark's grammar 4.3, 7.7). The parser places every
|
|
3
|
+
* syllable: a verse's syllables on a played bar, each at its onset. This
|
|
4
|
+
* module only sorts them under the written bars a row draws: under a
|
|
5
|
+
* singing line's slots, or spaced by beat in a lyric row on no melody.
|
|
6
|
+
*/
|
|
7
|
+
import { type ChartParse, type Line, type PlayedBar, type PlayedLyrics } from "barmark";
|
|
8
|
+
import type { CellModel, Verse } from "./types.js";
|
|
9
|
+
type BarsLine = Extract<Line, {
|
|
10
|
+
kind: "bars";
|
|
11
|
+
}>;
|
|
12
|
+
/** A bar a row draws, as played, and every verse sung on its written bar; null for a cell that isn't a bar. */
|
|
13
|
+
export type Landing = {
|
|
14
|
+
bar: PlayedBar;
|
|
15
|
+
lyrics: PlayedLyrics[];
|
|
16
|
+
} | null;
|
|
17
|
+
/**
|
|
18
|
+
* Whose words a row sings under its slots: the label of the part whose
|
|
19
|
+
* singing line it is ("" in a chart that sings with no part declared), or
|
|
20
|
+
* null when the line doesn't sing (barmark's grammar 7.7).
|
|
21
|
+
*/
|
|
22
|
+
export declare function singerOf(l: BarsLine, parse: ChartParse): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* What lands on each cell a row draws: its bar as played, with the verses
|
|
25
|
+
* of every pass the occurrence plays over that written bar, each part's
|
|
26
|
+
* verse once (a jump's pass back sings pass 1's words again).
|
|
27
|
+
*/
|
|
28
|
+
export declare function landings(bars: (PlayedBar | undefined)[], passes: PlayedBar[]): Landing[];
|
|
29
|
+
/** The verses a singing line's part sings over its bars, each syllable under its slot. */
|
|
30
|
+
export declare function sungVerses(cells: CellModel[], lands: Landing[], key: string): Verse[];
|
|
31
|
+
/** The verses no row sings under its slots: the chart's words, or a singer's with no melody here, by beat. */
|
|
32
|
+
export declare function rowVerses(lands: Landing[], sung: Set<string>): Verse[];
|
|
33
|
+
export {};
|
package/dist/verses.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the words go (barmark's grammar 4.3, 7.7). The parser places every
|
|
3
|
+
* syllable: a verse's syllables on a played bar, each at its onset. This
|
|
4
|
+
* module only sorts them under the written bars a row draws: under a
|
|
5
|
+
* singing line's slots, or spaced by beat in a lyric row on no melody.
|
|
6
|
+
*/
|
|
7
|
+
import { memberShares, } from "barmark";
|
|
8
|
+
/** Within a rounding error: onsets are sums of fractions of a bar. */
|
|
9
|
+
const near = (a, b) => Math.abs(a - b) < 1e-9;
|
|
10
|
+
const same = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
11
|
+
const barLength = (m) => m.n / m.d;
|
|
12
|
+
/** Whose words a verse is: its part's label, or "" for the chart's. */
|
|
13
|
+
const keyOf = (v) => v.part ?? "";
|
|
14
|
+
/**
|
|
15
|
+
* Whose words a row sings under its slots: the label of the part whose
|
|
16
|
+
* singing line it is ("" in a chart that sings with no part declared), or
|
|
17
|
+
* null when the line doesn't sing (barmark's grammar 7.7).
|
|
18
|
+
*/
|
|
19
|
+
export function singerOf(l, parse) {
|
|
20
|
+
const { parts } = parse;
|
|
21
|
+
if (!parts.length)
|
|
22
|
+
return l.part === undefined && parse.bars.some(onNotes) ? "" : null;
|
|
23
|
+
const p = l.part === undefined
|
|
24
|
+
? parts.length === 1
|
|
25
|
+
? parts[0]
|
|
26
|
+
: undefined
|
|
27
|
+
: parts.find((x) => same(x.label ?? "", l.part ?? ""));
|
|
28
|
+
if (p?.sings === undefined)
|
|
29
|
+
return null;
|
|
30
|
+
// A bare line plays as the part's first line (7.6).
|
|
31
|
+
const name = l.lineName ?? p.lines?.[0] ?? "";
|
|
32
|
+
return same(name, p.sings) ? (p.label ?? "") : null;
|
|
33
|
+
}
|
|
34
|
+
/** Whether a chart with no parts sings: its verse 1 sits on notes. */
|
|
35
|
+
const onNotes = (b) => (b.lyrics ?? []).some((v) => v.syllables.some((s) => s.note));
|
|
36
|
+
/**
|
|
37
|
+
* What lands on each cell a row draws: its bar as played, with the verses
|
|
38
|
+
* of every pass the occurrence plays over that written bar, each part's
|
|
39
|
+
* verse once (a jump's pass back sings pass 1's words again).
|
|
40
|
+
*/
|
|
41
|
+
export function landings(bars, passes) {
|
|
42
|
+
return bars.map((bar) => {
|
|
43
|
+
if (!bar)
|
|
44
|
+
return null;
|
|
45
|
+
const seen = new Set();
|
|
46
|
+
const lyrics = passes
|
|
47
|
+
.filter((p) => p.written === bar.written)
|
|
48
|
+
.flatMap((p) => p.lyrics ?? [])
|
|
49
|
+
.filter((v) => {
|
|
50
|
+
const key = `${keyOf(v)}\u0000${v.verse}`;
|
|
51
|
+
if (seen.has(key))
|
|
52
|
+
return false;
|
|
53
|
+
seen.add(key);
|
|
54
|
+
return true;
|
|
55
|
+
});
|
|
56
|
+
return { bar, lyrics };
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** One part's verse in a bar, or none. */
|
|
60
|
+
const verseIn = (landing, key, verse) => landing?.lyrics.find((v) => keyOf(v) === key && v.verse === verse)?.syllables ?? [];
|
|
61
|
+
/** The verses some cell sings for `key`, or for anyone not in `skip`, in verse order. */
|
|
62
|
+
function versesOf(cells, wanted) {
|
|
63
|
+
const found = new Map();
|
|
64
|
+
for (const v of cells.flatMap((c) => c?.lyrics ?? [])) {
|
|
65
|
+
if (!wanted(keyOf(v)) || !v.syllables.length)
|
|
66
|
+
continue;
|
|
67
|
+
found.set(`${keyOf(v)}\u0000${v.verse}`, [keyOf(v), v.verse]);
|
|
68
|
+
}
|
|
69
|
+
return [...found.values()].sort((a, b) => a[1] - b[1]);
|
|
70
|
+
}
|
|
71
|
+
/** Where each of a bar's simple slots starts, as a fraction of the bar (grammar 2.1, 2.2). */
|
|
72
|
+
function slotStarts(slots) {
|
|
73
|
+
const starts = [];
|
|
74
|
+
slots.forEach((s, i) => {
|
|
75
|
+
const members = s.kind === "group" ? s.members : [s];
|
|
76
|
+
let at = i / slots.length;
|
|
77
|
+
for (const share of memberShares(members)) {
|
|
78
|
+
starts.push(at);
|
|
79
|
+
at += share / slots.length;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return starts;
|
|
83
|
+
}
|
|
84
|
+
/** A verse's syllables in a bar under its slots: each on the slot sounding at its onset. */
|
|
85
|
+
function underSlots(cell, landing, key, verse) {
|
|
86
|
+
if (cell.kind !== "slots" || !landing)
|
|
87
|
+
return [];
|
|
88
|
+
const sung = verseIn(landing, key, verse);
|
|
89
|
+
const starts = slotStarts(cell.slots);
|
|
90
|
+
// A `%` drawn as itself has no slots to sit under: its syllables sit in a row.
|
|
91
|
+
if (!starts.length)
|
|
92
|
+
return sung.length ? [sung.map((s) => s.syllable)] : [];
|
|
93
|
+
const out = starts.map(() => []);
|
|
94
|
+
const length = barLength(landing.bar.meter);
|
|
95
|
+
for (const s of sung) {
|
|
96
|
+
const i = starts.findLastIndex((at) => at < s.at / length || near(at, s.at / length));
|
|
97
|
+
out[Math.max(0, i)]?.push(s.syllable);
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
/** The verses a singing line's part sings over its bars, each syllable under its slot. */
|
|
102
|
+
export function sungVerses(cells, lands, key) {
|
|
103
|
+
return versesOf(lands, (k) => k === key).map(([, verse]) => ({
|
|
104
|
+
verse,
|
|
105
|
+
cells: cells.map((c, i) => underSlots(c, lands[i] ?? null, key, verse)),
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
/** The finest steps a bar is cut into: enough for a triplet of sixteenth triplets. */
|
|
109
|
+
const MAX_STEPS = 96;
|
|
110
|
+
/** The fewest equal steps of a bar that every onset falls on. */
|
|
111
|
+
function stepsFor(fractions) {
|
|
112
|
+
for (let n = 1; n < MAX_STEPS; n++)
|
|
113
|
+
if (fractions.every((f) => near(f * n, Math.round(f * n))))
|
|
114
|
+
return n;
|
|
115
|
+
return MAX_STEPS;
|
|
116
|
+
}
|
|
117
|
+
/** A verse's syllables in a bar on its beats: equal steps, each syllable at its onset's. */
|
|
118
|
+
function onBeats(landing, key, verse) {
|
|
119
|
+
if (!landing)
|
|
120
|
+
return [];
|
|
121
|
+
const sung = verseIn(landing, key, verse);
|
|
122
|
+
const length = barLength(landing.bar.meter);
|
|
123
|
+
const steps = stepsFor(sung.map((s) => s.at / length));
|
|
124
|
+
const out = Array.from({ length: steps }, () => []);
|
|
125
|
+
for (const s of sung)
|
|
126
|
+
out[Math.min(steps - 1, Math.round((s.at / length) * steps))]?.push(s.syllable);
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
/** The verses no row sings under its slots: the chart's words, or a singer's with no melody here, by beat. */
|
|
130
|
+
export function rowVerses(lands, sung) {
|
|
131
|
+
return versesOf(lands, (k) => !sung.has(k)).map(([key, verse]) => ({
|
|
132
|
+
verse,
|
|
133
|
+
cells: lands.map((l) => onBeats(l, key, verse)),
|
|
134
|
+
}));
|
|
135
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barmark/render",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Render barmark chord charts as a clean, accessible bar grid: HTML with Declarative Shadow DOM, or the <barmark-chart> web component.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"url": "https://github.com/kevinpeckham/barmark/issues"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"barmark": "^0.
|
|
50
|
+
"barmark": "^0.17.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|