@barmark/render 0.14.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -1
- package/README.md +21 -1
- package/dist/html.js +47 -15
- package/dist/model.js +65 -18
- package/dist/speech.d.ts +10 -1
- package/dist/speech.js +20 -0
- package/dist/styles.js +29 -1
- package/dist/types.d.ts +22 -1
- 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 +145 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,41 @@ package uses [semantic versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.15.1] - 2026-11-07
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **Long charts lay out quickly again.** In 0.15.0 a chart with no
|
|
14
|
+
`part:` lines asked, for each of its lines, whether any bar of the chart
|
|
15
|
+
sings, so a 2,000-line chart took about three times as long as in
|
|
16
|
+
0.14.0. The answer is now worked out once a chart.
|
|
17
|
+
|
|
18
|
+
## [0.15.0] - 2026-11-07
|
|
19
|
+
|
|
20
|
+
Needs `barmark` 0.17.0.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- **Voice lines and lyrics** (barmark's grammar 4.3, 7.7): the line a part
|
|
25
|
+
sings words on draws its notes as pitch names, spaced by beat, with
|
|
26
|
+
each verse's syllables under them: hyphens within a word, an extender
|
|
27
|
+
for a held syllable (`:/`), verses numbered when there are several. A
|
|
28
|
+
lyric row on no melody draws its words in the bars it covers, spaced
|
|
29
|
+
by beat, so they wrap with their bars. A screen reader hears each bar's
|
|
30
|
+
words after its notes. The model's rows gain `sings`, `verses` and
|
|
31
|
+
`lyrics`; `--barmark-lyrics` colours the words, and `::part(lyrics)`
|
|
32
|
+
styles each verse's line. A `lyrics:` line followed by a
|
|
33
|
+
bar line, which drew as a line of text, now draws its words on the
|
|
34
|
+
beats.
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- A `---` break draws nothing, and a text line written with a leading `\`
|
|
39
|
+
shows without the backslash.
|
|
40
|
+
- A part's bare line with its named lines written after it (`Vox` over
|
|
41
|
+
`Vox.Mel`, barmark's amended grammar 7.6) draws in the same system, as
|
|
42
|
+
the part's first row.
|
|
43
|
+
|
|
9
44
|
## [0.14.0] - 2026-11-04
|
|
10
45
|
|
|
11
46
|
Needs `barmark` 0.16.0.
|
|
@@ -349,7 +384,9 @@ that needs no script or as the `<barmark-chart>` web component. Requires
|
|
|
349
384
|
zoom without sideways scrolling, the element renders and re-renders, and
|
|
350
385
|
a screen reader hears "bar 9: D". Run them with `bun run test:browser`.
|
|
351
386
|
|
|
352
|
-
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.
|
|
387
|
+
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.15.1...HEAD
|
|
388
|
+
[0.15.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.15.0...render-v0.15.1
|
|
389
|
+
[0.15.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.14.0...render-v0.15.0
|
|
353
390
|
[0.14.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.13.0...render-v0.14.0
|
|
354
391
|
[0.13.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.12.0...render-v0.13.0
|
|
355
392
|
[0.12.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.11.0...render-v0.12.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
|
}
|
|
@@ -115,12 +116,16 @@ function blockHtml(block, settings) {
|
|
|
115
116
|
*/
|
|
116
117
|
function fitWidth(block) {
|
|
117
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
|
+
};
|
|
118
123
|
for (const item of block.items) {
|
|
119
|
-
if (item.kind
|
|
120
|
-
|
|
121
|
-
item.
|
|
122
|
-
|
|
123
|
-
|
|
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));
|
|
124
129
|
}
|
|
125
130
|
const total = 5 + widths.reduce((a, b) => a + b, 0);
|
|
126
131
|
return FIT_STEPS.find((step) => step >= total) ?? FIT_STEPS.at(-1) ?? 0;
|
|
@@ -210,22 +215,36 @@ function gutterHtml(row, settings, part) {
|
|
|
210
215
|
function rowCells(row, numerals, ending) {
|
|
211
216
|
let n = row.barNumber;
|
|
212
217
|
const firstTacet = row.cells.findIndex(isTacetCell);
|
|
218
|
+
const firstBar = row.cells.findIndex((c) => c.kind === "slots");
|
|
213
219
|
return row.cells.map((cell, i) => {
|
|
214
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
|
+
};
|
|
215
230
|
const html = isTacetCell(cell)
|
|
216
231
|
? tacetHtml(cell, n, marks, i === firstTacet)
|
|
217
|
-
: cellHtml(cell, n, marks, numerals);
|
|
232
|
+
: cellHtml(cell, n, marks, numerals, sung);
|
|
218
233
|
if (n !== null && cell.kind === "slots")
|
|
219
234
|
n++;
|
|
220
235
|
return html;
|
|
221
236
|
});
|
|
222
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);
|
|
223
240
|
const sr = (text) => (text ? `<span class="bm-sr">${text}</span>` : "");
|
|
224
241
|
/** The row's class list. */
|
|
225
242
|
function rowClasses(row, part) {
|
|
226
243
|
const classes = ["bm-row"];
|
|
227
244
|
if (part)
|
|
228
245
|
classes.push("bm-part-row");
|
|
246
|
+
if (row.sings)
|
|
247
|
+
classes.push("bm-sings");
|
|
229
248
|
if (row.cells.some(isTacetCell))
|
|
230
249
|
classes.push("bm-tacet");
|
|
231
250
|
if (row.ending)
|
|
@@ -268,14 +287,19 @@ function rowRepeatHtml(row) {
|
|
|
268
287
|
return row.closes ? `<span class="bm-sr">repeat end, play 2 times</span>` : "";
|
|
269
288
|
return repeatHtml(row.repeat).trim();
|
|
270
289
|
}
|
|
271
|
-
function cellHtml(cell, barNumber, marks, numerals) {
|
|
272
|
-
const
|
|
273
|
-
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>`;
|
|
274
294
|
if (cell.kind !== "slots")
|
|
275
295
|
return betweenBarsHtml(cell, spoken, marks);
|
|
276
296
|
const change = cell.tempoChange ? ` data-tempo-change="${cell.tempoChange}"` : "";
|
|
277
|
-
const [body, end] = barBody(cell,
|
|
278
|
-
|
|
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>`;
|
|
279
303
|
}
|
|
280
304
|
/** What a bar shows: its meter, its slots (or `%`), and "cut"; then the words after its last slot. */
|
|
281
305
|
function barBody(cell, view) {
|
|
@@ -349,6 +373,11 @@ const dataOf = (marks) => Object.entries(marks)
|
|
|
349
373
|
.join("");
|
|
350
374
|
/** A slot with its push mark before it, its accent or hit above it and its pedal mark below. */
|
|
351
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) {
|
|
352
381
|
const body = unmarkedSlotHtml(slot, view);
|
|
353
382
|
const marks = marksOf(slot);
|
|
354
383
|
const { push, articulation, pedal } = marks;
|
|
@@ -392,12 +421,15 @@ function unmarkedSlotHtml(slot, view) {
|
|
|
392
421
|
}
|
|
393
422
|
}
|
|
394
423
|
function chordHtml(record, view) {
|
|
424
|
+
if (record.kind === "notes" && view.pitches)
|
|
425
|
+
return pitchHtml(record);
|
|
395
426
|
if (record.kind === "notes" || !record.parts)
|
|
396
427
|
return notesHtml(record);
|
|
397
|
-
const numeral = view
|
|
398
|
-
|
|
428
|
+
const { numeral } = view;
|
|
429
|
+
const pieces = numeral ? typesetNumeral(record.parts, numeral.key, numeral.style) : null;
|
|
430
|
+
if (!pieces)
|
|
399
431
|
return piecesHtml(typesetChord(record.parts), "");
|
|
400
|
-
return piecesHtml(
|
|
432
|
+
return piecesHtml(pieces, ` data-numeral="${numeral?.style}"`);
|
|
401
433
|
}
|
|
402
434
|
function piecesHtml(p, attributes) {
|
|
403
435
|
const quality = p.quality ? `<span class="bm-quality">${p.quality}</span>` : "";
|
package/dist/model.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
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));
|
|
@@ -210,28 +211,64 @@ function layoutLines(lines, occurrence, ctx) {
|
|
|
210
211
|
let previous = null;
|
|
211
212
|
for (const [i, l] of lines.entries()) {
|
|
212
213
|
const system = systemOf(l);
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (systemOf(lines[i - 1]) === system)
|
|
216
|
-
continue;
|
|
217
|
-
const item = layoutSystem(systemLines(lines, i), occurrence, previous, ctx);
|
|
218
|
-
previous = lastOfSystem(item) ?? previous;
|
|
219
|
-
items.push(item);
|
|
214
|
+
// A system is laid out once, at its first line.
|
|
215
|
+
if (system !== null && systemOf(lines[i - 1]) === system)
|
|
220
216
|
continue;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const item = layoutLine(l, occurrence, previous, ctx);
|
|
227
|
-
if (!item)
|
|
228
|
-
continue;
|
|
229
|
-
if (item.kind === "row")
|
|
230
|
-
previous = lastSlots(item.cells) ?? previous;
|
|
231
|
-
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);
|
|
232
222
|
}
|
|
233
223
|
return items;
|
|
234
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
|
+
}
|
|
235
272
|
const systemOf = (l) => (l?.kind === "bars" || l?.kind === "invalid") && l.system !== undefined ? l.system : null;
|
|
236
273
|
/** The lines of the system that starts at `i`. */
|
|
237
274
|
function systemLines(lines, i) {
|
|
@@ -358,8 +395,18 @@ function layoutRow(l, played, previous, ctx) {
|
|
|
358
395
|
repeat: l.repeat,
|
|
359
396
|
ending: l.ending,
|
|
360
397
|
cells,
|
|
398
|
+
...singing(l, cells, played, ctx),
|
|
361
399
|
};
|
|
362
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
|
+
}
|
|
363
410
|
/** A cell as drawn: `%` becomes the bar it copies, its slots as the parser resolved them; `previous` lends only its meter. */
|
|
364
411
|
function layoutCell(cell, played, previous) {
|
|
365
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
|
@@ -168,3 +168,23 @@ export function speakBar(barNumber, cell, numerals = false) {
|
|
|
168
168
|
const spoken = [...slots, ...words(cell.slots.length)].join(", ");
|
|
169
169
|
return `bar${barNumber === null ? "" : ` ${barNumber}`}${meter}: ${spoken}${cut}`;
|
|
170
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`;
|
|
@@ -148,6 +157,25 @@ const css = `
|
|
|
148
157
|
.bm-bar[data-tempo-change]::before{content:"";position:absolute;inset:.15em 0 auto;border-top:.08em dashed var(--barmark-directive,var(--bm-muted))}
|
|
149
158
|
.bm-bar[data-cut]{outline:.08em dashed var(--bm-muted);outline-offset:-.25em}
|
|
150
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}
|
|
151
179
|
.bm-text{grid-column:1/-1;margin:.2em 0 .5em ${at(SIZES.text, GUTTER)};font-family:${TEXT};font-size:${em(SIZES.text)}}
|
|
152
180
|
.bm-note{font-style:italic;color:var(--barmark-note,var(--bm-ink))}
|
|
153
181
|
.bm-error{grid-column:1/-1;margin:.3em 0}
|
|
@@ -156,7 +184,7 @@ const css = `
|
|
|
156
184
|
.bm-diagnostics .bm-error{color:var(--bm-accent)}
|
|
157
185
|
@media (forced-colors:active){
|
|
158
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}
|
|
159
|
-
.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}
|
|
160
188
|
.bm-silence{background:CanvasText;forced-color-adjust:none}
|
|
161
189
|
.bm-bar[data-cut]{outline-color:CanvasText}
|
|
162
190
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChartDiagnostic, Credits, DeclaredPart, Direction, Directives, Key, Meter, Repeat, Slot, Words } from "barmark";
|
|
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;
|
|
@@ -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,145 @@
|
|
|
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 && singsOnNotes(parse) ? "" : 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
|
+
/** `onNotes` over the chart, worked out once a parse: asked for each line, it would read every bar each time. */
|
|
37
|
+
const sang = new WeakMap();
|
|
38
|
+
function singsOnNotes(parse) {
|
|
39
|
+
const known = sang.get(parse);
|
|
40
|
+
if (known !== undefined)
|
|
41
|
+
return known;
|
|
42
|
+
const sings = parse.bars.some(onNotes);
|
|
43
|
+
sang.set(parse, sings);
|
|
44
|
+
return sings;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* What lands on each cell a row draws: its bar as played, with the verses
|
|
48
|
+
* of every pass the occurrence plays over that written bar, each part's
|
|
49
|
+
* verse once (a jump's pass back sings pass 1's words again).
|
|
50
|
+
*/
|
|
51
|
+
export function landings(bars, passes) {
|
|
52
|
+
return bars.map((bar) => {
|
|
53
|
+
if (!bar)
|
|
54
|
+
return null;
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
const lyrics = passes
|
|
57
|
+
.filter((p) => p.written === bar.written)
|
|
58
|
+
.flatMap((p) => p.lyrics ?? [])
|
|
59
|
+
.filter((v) => {
|
|
60
|
+
const key = `${keyOf(v)}\u0000${v.verse}`;
|
|
61
|
+
if (seen.has(key))
|
|
62
|
+
return false;
|
|
63
|
+
seen.add(key);
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
return { bar, lyrics };
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** One part's verse in a bar, or none. */
|
|
70
|
+
const verseIn = (landing, key, verse) => landing?.lyrics.find((v) => keyOf(v) === key && v.verse === verse)?.syllables ?? [];
|
|
71
|
+
/** The verses some cell sings for `key`, or for anyone not in `skip`, in verse order. */
|
|
72
|
+
function versesOf(cells, wanted) {
|
|
73
|
+
const found = new Map();
|
|
74
|
+
for (const v of cells.flatMap((c) => c?.lyrics ?? [])) {
|
|
75
|
+
if (!wanted(keyOf(v)) || !v.syllables.length)
|
|
76
|
+
continue;
|
|
77
|
+
found.set(`${keyOf(v)}\u0000${v.verse}`, [keyOf(v), v.verse]);
|
|
78
|
+
}
|
|
79
|
+
return [...found.values()].sort((a, b) => a[1] - b[1]);
|
|
80
|
+
}
|
|
81
|
+
/** Where each of a bar's simple slots starts, as a fraction of the bar (grammar 2.1, 2.2). */
|
|
82
|
+
function slotStarts(slots) {
|
|
83
|
+
const starts = [];
|
|
84
|
+
slots.forEach((s, i) => {
|
|
85
|
+
const members = s.kind === "group" ? s.members : [s];
|
|
86
|
+
let at = i / slots.length;
|
|
87
|
+
for (const share of memberShares(members)) {
|
|
88
|
+
starts.push(at);
|
|
89
|
+
at += share / slots.length;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return starts;
|
|
93
|
+
}
|
|
94
|
+
/** A verse's syllables in a bar under its slots: each on the slot sounding at its onset. */
|
|
95
|
+
function underSlots(cell, landing, key, verse) {
|
|
96
|
+
if (cell.kind !== "slots" || !landing)
|
|
97
|
+
return [];
|
|
98
|
+
const sung = verseIn(landing, key, verse);
|
|
99
|
+
const starts = slotStarts(cell.slots);
|
|
100
|
+
// A `%` drawn as itself has no slots to sit under: its syllables sit in a row.
|
|
101
|
+
if (!starts.length)
|
|
102
|
+
return sung.length ? [sung.map((s) => s.syllable)] : [];
|
|
103
|
+
const out = starts.map(() => []);
|
|
104
|
+
const length = barLength(landing.bar.meter);
|
|
105
|
+
for (const s of sung) {
|
|
106
|
+
const i = starts.findLastIndex((at) => at < s.at / length || near(at, s.at / length));
|
|
107
|
+
out[Math.max(0, i)]?.push(s.syllable);
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
/** The verses a singing line's part sings over its bars, each syllable under its slot. */
|
|
112
|
+
export function sungVerses(cells, lands, key) {
|
|
113
|
+
return versesOf(lands, (k) => k === key).map(([, verse]) => ({
|
|
114
|
+
verse,
|
|
115
|
+
cells: cells.map((c, i) => underSlots(c, lands[i] ?? null, key, verse)),
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
/** The finest steps a bar is cut into: enough for a triplet of sixteenth triplets. */
|
|
119
|
+
const MAX_STEPS = 96;
|
|
120
|
+
/** The fewest equal steps of a bar that every onset falls on. */
|
|
121
|
+
function stepsFor(fractions) {
|
|
122
|
+
for (let n = 1; n < MAX_STEPS; n++)
|
|
123
|
+
if (fractions.every((f) => near(f * n, Math.round(f * n))))
|
|
124
|
+
return n;
|
|
125
|
+
return MAX_STEPS;
|
|
126
|
+
}
|
|
127
|
+
/** A verse's syllables in a bar on its beats: equal steps, each syllable at its onset's. */
|
|
128
|
+
function onBeats(landing, key, verse) {
|
|
129
|
+
if (!landing)
|
|
130
|
+
return [];
|
|
131
|
+
const sung = verseIn(landing, key, verse);
|
|
132
|
+
const length = barLength(landing.bar.meter);
|
|
133
|
+
const steps = stepsFor(sung.map((s) => s.at / length));
|
|
134
|
+
const out = Array.from({ length: steps }, () => []);
|
|
135
|
+
for (const s of sung)
|
|
136
|
+
out[Math.min(steps - 1, Math.round((s.at / length) * steps))]?.push(s.syllable);
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
/** The verses no row sings under its slots: the chart's words, or a singer's with no melody here, by beat. */
|
|
140
|
+
export function rowVerses(lands, sung) {
|
|
141
|
+
return versesOf(lands, (k) => !sung.has(k)).map(([key, verse]) => ({
|
|
142
|
+
verse,
|
|
143
|
+
cells: lands.map((l) => onBeats(l, key, verse)),
|
|
144
|
+
}));
|
|
145
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barmark/render",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
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",
|