@nodelyra/not-angka 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +38 -2
- package/THIRD_PARTY.md +24 -0
- package/dist/esm/cursor/activeChord.d.ts +12 -0
- package/dist/esm/cursor/activeChord.js +36 -0
- package/dist/esm/cursor/beatDot.d.ts +30 -0
- package/dist/esm/cursor/beatDot.js +49 -0
- package/dist/esm/cursor/drawnTop.d.ts +9 -0
- package/dist/esm/cursor/drawnTop.js +16 -0
- package/dist/esm/cursor/pageBoxes.d.ts +28 -0
- package/dist/esm/cursor/pageBoxes.js +75 -0
- package/dist/esm/cursor/playbackCursor.d.ts +25 -0
- package/dist/esm/cursor/playbackCursor.js +42 -0
- package/dist/esm/cursor/playingStyle.d.ts +16 -0
- package/dist/esm/cursor/playingStyle.js +34 -0
- package/dist/esm/cursor/playingTones.d.ts +8 -0
- package/dist/esm/cursor/playingTones.js +16 -0
- package/dist/esm/cursor/target.d.ts +47 -0
- package/dist/esm/cursor/target.js +63 -0
- package/dist/esm/export/pageText.d.ts +8 -0
- package/dist/esm/export/pageText.js +80 -0
- package/dist/esm/export/svgExport.d.ts +46 -0
- package/dist/esm/export/svgExport.js +88 -0
- package/dist/esm/geometry/metrics.d.ts +42 -0
- package/dist/esm/geometry/metrics.js +52 -0
- package/dist/esm/geometry/pageSetup.d.ts +61 -0
- package/dist/esm/geometry/pageSetup.js +85 -0
- package/dist/esm/geometry/paper.d.ts +16 -0
- package/dist/esm/geometry/paper.js +16 -0
- package/dist/esm/index.d.ts +35 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/layout/LayoutEngine.d.ts +64 -0
- package/dist/esm/layout/LayoutEngine.js +92 -0
- package/dist/esm/layout/arcs.d.ts +20 -0
- package/dist/esm/layout/arcs.js +53 -0
- package/dist/esm/layout/barlineShapes.d.ts +52 -0
- package/dist/esm/layout/barlineShapes.js +71 -0
- package/dist/esm/layout/directions.d.ts +48 -0
- package/dist/esm/layout/directions.js +122 -0
- package/dist/esm/layout/elementBoxes.d.ts +17 -0
- package/dist/esm/layout/elementBoxes.js +72 -0
- package/dist/esm/layout/floating.d.ts +29 -0
- package/dist/esm/layout/floating.js +39 -0
- package/dist/esm/layout/keyMarks.d.ts +26 -0
- package/dist/esm/layout/keyMarks.js +30 -0
- package/dist/esm/layout/lyricAlign.d.ts +6 -0
- package/dist/esm/layout/lyricAlign.js +15 -0
- package/dist/esm/layout/lyricWords.d.ts +13 -0
- package/dist/esm/layout/lyricWords.js +27 -0
- package/dist/esm/layout/lyricsLayout.d.ts +55 -0
- package/dist/esm/layout/lyricsLayout.js +122 -0
- package/dist/esm/layout/markings.d.ts +97 -0
- package/dist/esm/layout/markings.js +150 -0
- package/dist/esm/layout/measurePlan.d.ts +74 -0
- package/dist/esm/layout/measurePlan.js +232 -0
- package/dist/esm/layout/measureSegments.d.ts +24 -0
- package/dist/esm/layout/measureSegments.js +64 -0
- package/dist/esm/layout/notationMetrics.d.ts +110 -0
- package/dist/esm/layout/notationMetrics.js +122 -0
- package/dist/esm/layout/systemBreaking.d.ts +59 -0
- package/dist/esm/layout/systemBreaking.js +137 -0
- package/dist/esm/layout/systemLayout.d.ts +138 -0
- package/dist/esm/layout/systemLayout.js +266 -0
- package/dist/esm/layout/tupletSpacing.d.ts +9 -0
- package/dist/esm/layout/tupletSpacing.js +33 -0
- package/dist/esm/layout/tuplets.d.ts +30 -0
- package/dist/esm/layout/tuplets.js +39 -0
- package/dist/esm/model/hiddenParts.d.ts +23 -0
- package/dist/esm/model/hiddenParts.js +39 -0
- package/dist/esm/model/locate.d.ts +18 -0
- package/dist/esm/model/locate.js +31 -0
- package/dist/esm/model/lowVoices.d.ts +9 -0
- package/dist/esm/model/lowVoices.js +20 -0
- package/dist/esm/model/partColors.d.ts +13 -0
- package/dist/esm/model/partColors.js +10 -0
- package/dist/esm/model/partSpan.d.ts +25 -0
- package/dist/esm/model/partSpan.js +49 -0
- package/dist/esm/model/rowPresence.d.ts +14 -0
- package/dist/esm/model/rowPresence.js +19 -0
- package/dist/esm/model/sharedLyrics.d.ts +23 -0
- package/dist/esm/model/sharedLyrics.js +68 -0
- package/dist/esm/model/textBars.d.ts +12 -0
- package/dist/esm/model/textBars.js +21 -0
- package/dist/esm/model/tickRanges.d.ts +22 -0
- package/dist/esm/model/tickRanges.js +34 -0
- package/dist/esm/model/unisons.d.ts +69 -0
- package/dist/esm/model/unisons.js +181 -0
- package/dist/esm/notation/chords.d.ts +12 -0
- package/dist/esm/notation/chords.js +29 -0
- package/dist/esm/notation/elision.d.ts +24 -0
- package/dist/esm/notation/elision.js +47 -0
- package/dist/esm/notation/keys.d.ts +50 -0
- package/dist/esm/notation/keys.js +59 -0
- package/dist/esm/notation/lyricAlign.d.ts +7 -0
- package/dist/esm/notation/lyricAlign.js +15 -0
- package/dist/esm/notation/navigation.d.ts +3 -0
- package/dist/esm/notation/navigation.js +5 -0
- package/dist/esm/notation/pitch.d.ts +39 -0
- package/dist/esm/notation/pitch.js +74 -0
- package/dist/esm/notation/pitchName.d.ts +2 -0
- package/dist/esm/notation/pitchName.js +3 -0
- package/dist/esm/notation/profile.d.ts +35 -0
- package/dist/esm/notation/profile.js +16 -0
- package/dist/esm/notation/rhythm.d.ts +59 -0
- package/dist/esm/notation/rhythm.js +116 -0
- package/dist/esm/notation/time.d.ts +98 -0
- package/dist/esm/notation/time.js +85 -0
- package/dist/esm/performance/compilePerformance.d.ts +7 -0
- package/dist/esm/performance/compilePerformance.js +8 -0
- package/dist/esm/performance/dynamics.d.ts +6 -0
- package/dist/esm/performance/dynamics.js +78 -0
- package/dist/esm/performance/model.d.ts +56 -0
- package/dist/esm/performance/model.js +1 -0
- package/dist/esm/performance/playOrder.d.ts +16 -0
- package/dist/esm/performance/playOrder.js +64 -0
- package/dist/esm/performance/readScore.d.ts +4 -0
- package/dist/esm/performance/readScore.js +58 -0
- package/dist/esm/performance/timeline.d.ts +10 -0
- package/dist/esm/performance/timeline.js +144 -0
- package/dist/esm/playback/audioOutput.d.ts +46 -0
- package/dist/esm/playback/audioOutput.js +106 -0
- package/dist/esm/playback/clock.d.ts +16 -0
- package/dist/esm/playback/clock.js +44 -0
- package/dist/esm/playback/createPlayerStore.d.ts +79 -0
- package/dist/esm/playback/createPlayerStore.js +135 -0
- package/dist/esm/playback/cues.d.ts +34 -0
- package/dist/esm/playback/cues.js +52 -0
- package/dist/esm/playback/errors.d.ts +6 -0
- package/dist/esm/playback/errors.js +6 -0
- package/dist/esm/playback/metronome.d.ts +13 -0
- package/dist/esm/playback/metronome.js +15 -0
- package/dist/esm/playback/mix.d.ts +9 -0
- package/dist/esm/playback/mix.js +8 -0
- package/dist/esm/playback/pass.d.ts +27 -0
- package/dist/esm/playback/pass.js +36 -0
- package/dist/esm/playback/schedule.d.ts +7 -0
- package/dist/esm/playback/schedule.js +12 -0
- package/dist/esm/playback/session.d.ts +46 -0
- package/dist/esm/playback/session.js +107 -0
- package/dist/esm/playback/source.d.ts +6 -0
- package/dist/esm/playback/source.js +1 -0
- package/dist/esm/playback/start.d.ts +28 -0
- package/dist/esm/playback/start.js +38 -0
- package/dist/esm/playback/timing.d.ts +14 -0
- package/dist/esm/playback/timing.js +11 -0
- package/dist/esm/playback/types.d.ts +60 -0
- package/dist/esm/playback/types.js +1 -0
- package/dist/esm/playback/volume.d.ts +12 -0
- package/dist/esm/playback/volume.js +8 -0
- package/dist/esm/player/ControlBar.d.ts +22 -0
- package/dist/esm/player/ControlBar.js +77 -0
- package/dist/esm/player/CursorPainter.d.ts +17 -0
- package/dist/esm/player/CursorPainter.js +53 -0
- package/dist/esm/player/InfoLine.d.ts +6 -0
- package/dist/esm/player/InfoLine.js +23 -0
- package/dist/esm/player/PageView.d.ts +10 -0
- package/dist/esm/player/PageView.js +16 -0
- package/dist/esm/player/actions.d.ts +24 -0
- package/dist/esm/player/actions.js +26 -0
- package/dist/esm/player/balanceSystems.d.ts +8 -0
- package/dist/esm/player/balanceSystems.js +18 -0
- package/dist/esm/player/createExcerptPlayer.d.ts +33 -0
- package/dist/esm/player/createExcerptPlayer.js +169 -0
- package/dist/esm/player/createScorePlayer.d.ts +24 -0
- package/dist/esm/player/createScorePlayer.js +118 -0
- package/dist/esm/player/dom.d.ts +6 -0
- package/dist/esm/player/dom.js +15 -0
- package/dist/esm/player/embeddedFonts.d.ts +1 -0
- package/dist/esm/player/embeddedFonts.js +3 -0
- package/dist/esm/player/exclusivePlayback.d.ts +10 -0
- package/dist/esm/player/exclusivePlayback.js +13 -0
- package/dist/esm/player/followCursor.d.ts +5 -0
- package/dist/esm/player/followCursor.js +16 -0
- package/dist/esm/player/icons.d.ts +7 -0
- package/dist/esm/player/icons.js +9 -0
- package/dist/esm/player/injectFonts.d.ts +8 -0
- package/dist/esm/player/injectFonts.js +19 -0
- package/dist/esm/player/loadExcerpt.d.ts +21 -0
- package/dist/esm/player/loadExcerpt.js +123 -0
- package/dist/esm/player/loadScore.d.ts +12 -0
- package/dist/esm/player/loadScore.js +12 -0
- package/dist/esm/player/mountExcerpts.d.ts +30 -0
- package/dist/esm/player/mountExcerpts.js +109 -0
- package/dist/esm/player/playhead.d.ts +12 -0
- package/dist/esm/player/playhead.js +14 -0
- package/dist/esm/player/shadowStyles.d.ts +5 -0
- package/dist/esm/player/shadowStyles.js +23 -0
- package/dist/esm/player/staticSvg.d.ts +7 -0
- package/dist/esm/player/staticSvg.js +10 -0
- package/dist/esm/player/styles.d.ts +28 -0
- package/dist/esm/player/styles.js +98 -0
- package/dist/esm/player/theme.d.ts +8 -0
- package/dist/esm/player/theme.js +13 -0
- package/dist/esm/player/types.d.ts +76 -0
- package/dist/esm/player/types.js +12 -0
- package/dist/esm/rendering/SystemRenderer.d.ts +6 -0
- package/dist/esm/rendering/SystemRenderer.js +58 -0
- package/dist/esm/rendering/accidentalRenderer.d.ts +4 -0
- package/dist/esm/rendering/accidentalRenderer.js +41 -0
- package/dist/esm/rendering/arcRenderer.d.ts +9 -0
- package/dist/esm/rendering/arcRenderer.js +32 -0
- package/dist/esm/rendering/barlineRenderer.d.ts +8 -0
- package/dist/esm/rendering/barlineRenderer.js +59 -0
- package/dist/esm/rendering/directionRenderer.d.ts +4 -0
- package/dist/esm/rendering/directionRenderer.js +50 -0
- package/dist/esm/rendering/durationLineRenderer.d.ts +9 -0
- package/dist/esm/rendering/durationLineRenderer.js +27 -0
- package/dist/esm/rendering/dynamicGlyphs.d.ts +25 -0
- package/dist/esm/rendering/dynamicGlyphs.js +56 -0
- package/dist/esm/rendering/frameRenderer.d.ts +17 -0
- package/dist/esm/rendering/frameRenderer.js +252 -0
- package/dist/esm/rendering/keyMarkRenderer.d.ts +8 -0
- package/dist/esm/rendering/keyMarkRenderer.js +57 -0
- package/dist/esm/rendering/lyricsRenderer.d.ts +4 -0
- package/dist/esm/rendering/lyricsRenderer.js +44 -0
- package/dist/esm/rendering/primitives.d.ts +64 -0
- package/dist/esm/rendering/primitives.js +1 -0
- package/dist/esm/rendering/sliceRenderer.d.ts +19 -0
- package/dist/esm/rendering/sliceRenderer.js +79 -0
- package/dist/esm/rendering/textBarRenderer.d.ts +8 -0
- package/dist/esm/rendering/textBarRenderer.js +28 -0
- package/dist/esm/rendering/tupletRenderer.d.ts +7 -0
- package/dist/esm/rendering/tupletRenderer.js +42 -0
- package/dist/esm/schema/normalize.d.ts +14 -0
- package/dist/esm/schema/normalize.js +123 -0
- package/dist/esm/schema/pageMeta.d.ts +11 -0
- package/dist/esm/schema/pageMeta.js +1 -0
- package/dist/esm/schema/scoreJson.d.ts +59 -0
- package/dist/esm/schema/scoreJson.js +1 -0
- package/dist/esm/schema/scoreView.d.ts +16 -0
- package/dist/esm/schema/scoreView.js +24 -0
- package/dist/esm/schema/types.d.ts +339 -0
- package/dist/esm/schema/types.js +1 -0
- package/dist/esm/text/creditLines.d.ts +12 -0
- package/dist/esm/text/creditLines.js +11 -0
- package/dist/esm/text/fonts.d.ts +50 -0
- package/dist/esm/text/fonts.js +98 -0
- package/dist/esm/text/headerFooter.d.ts +13 -0
- package/dist/esm/text/headerFooter.js +21 -0
- package/dist/esm/text/textLines.d.ts +7 -0
- package/dist/esm/text/textLines.js +13 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/nodelyra-player.global.js +65 -0
- package/dist/nodelyra-player.global.js.map +1 -0
- package/dist/nodelyra-player.lite.global.js +63 -0
- package/dist/nodelyra-player.lite.global.js.map +1 -0
- package/examples/blog-excerpt.html +54 -0
- package/examples/twinkle.html +23 -0
- package/examples/twinkle.json +91 -0
- package/package.json +70 -4
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { lyricsHiddenAt } from "../model/sharedLyrics.js";
|
|
2
|
+
import { sliceMeasure } from "../notation/rhythm.js";
|
|
3
|
+
import { beatOnsets, groupOf } from "../notation/time.js";
|
|
4
|
+
import { syllableShift } from "./lyricAlign.js";
|
|
5
|
+
import { joinedWords } from "./lyricWords.js";
|
|
6
|
+
import { NOTATION, textWidth } from "./notationMetrics.js";
|
|
7
|
+
import { tupletOnsets } from "./tuplets.js";
|
|
8
|
+
import { spaceTuplets } from "./tupletSpacing.js";
|
|
9
|
+
/**
|
|
10
|
+
* The width a measure asks for on its system: natural, plus what its bar line was dragged by, but
|
|
11
|
+
* never narrower than compact (the layout never draws it narrower, so the line cannot overrun).
|
|
12
|
+
*/
|
|
13
|
+
export const plannedWidth = (plan) => Math.max(plan.compactWidth, plan.naturalWidth + plan.adjust);
|
|
14
|
+
const HYPHEN_ROOM = 5;
|
|
15
|
+
/** Room for a syllable that stands alone: its width, air before the next, its hyphen. */
|
|
16
|
+
const syllableRoom = (l, lyricWidth) => lyricWidth(l.text) + NOTATION.lyricPad + (l.hyphen ? HYPHEN_ROOM : 0);
|
|
17
|
+
/** Record that the column at `onset` needs at least `lean`. */
|
|
18
|
+
function addLean(leans, onset, lean) {
|
|
19
|
+
const current = leans.get(onset) ?? { before: 0, after: 0 };
|
|
20
|
+
leans.set(onset, {
|
|
21
|
+
before: Math.max(current.before, lean.before),
|
|
22
|
+
after: Math.max(current.after, lean.after),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* One part's syllables in this measure: the room each head piece needs for its syllables (by
|
|
27
|
+
* onset), and the words sung across notes. A syllable inside such a word needs only its own
|
|
28
|
+
* width, so the notes of the word sit as close as their syllables (each note stays centred over
|
|
29
|
+
* its own syllable); the air around the word goes outside it (see `fitWords`).
|
|
30
|
+
*/
|
|
31
|
+
function partLyrics(heads, measureIndex, lyricWidth) {
|
|
32
|
+
const room = new Map();
|
|
33
|
+
const leans = new Map();
|
|
34
|
+
const words = [];
|
|
35
|
+
const grow = (onset, width) => room.set(onset, Math.max(room.get(onset) ?? 0, width));
|
|
36
|
+
const lines = Math.max(0, ...heads.map((h) => h.lyrics.length));
|
|
37
|
+
for (let line = 0; line < lines; line++) {
|
|
38
|
+
const sung = heads.map((h) => ({ lyric: h.lyrics[line] ?? null, measureIndex }));
|
|
39
|
+
const inWord = new Set();
|
|
40
|
+
for (const word of joinedWords(sung)) {
|
|
41
|
+
word.forEach((i) => {
|
|
42
|
+
inWord.add(i);
|
|
43
|
+
grow(heads[i].onset, lyricWidth(sung[i].lyric.text));
|
|
44
|
+
});
|
|
45
|
+
const last = word[word.length - 1];
|
|
46
|
+
words.push({ from: heads[word[0]].onset, to: heads[last].onset, hyphenAfter: sung[last].lyric.hyphen });
|
|
47
|
+
}
|
|
48
|
+
sung.forEach(({ lyric }, i) => {
|
|
49
|
+
if (!lyric || inWord.has(i))
|
|
50
|
+
return;
|
|
51
|
+
grow(heads[i].onset, syllableRoom(lyric, lyricWidth));
|
|
52
|
+
// Centred off its note by `shift`, it keeps that much more air on the side it leans to,
|
|
53
|
+
// so it clears its neighbour as a centred one would.
|
|
54
|
+
const shift = syllableShift(lyric, lyricWidth(lyric.text));
|
|
55
|
+
if (shift !== 0)
|
|
56
|
+
addLean(leans, heads[i].onset, { before: -shift, after: shift });
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return { room, leans, words };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Keep each word's notes together (no stretching and no beat gap between them) and put the air
|
|
63
|
+
* a lone syllable keeps on both sides around the whole word instead.
|
|
64
|
+
*/
|
|
65
|
+
function fitWords(columns, words) {
|
|
66
|
+
const index = (onset) => columns.findIndex((c) => c.onset === onset);
|
|
67
|
+
for (const word of words) {
|
|
68
|
+
const first = index(word.from);
|
|
69
|
+
const last = index(word.to);
|
|
70
|
+
columns[first].joinsNext = true;
|
|
71
|
+
for (let k = first + 1; k <= last; k++)
|
|
72
|
+
columns[k].joinedFromPrevious = true;
|
|
73
|
+
const air = NOTATION.lyricPad / 2;
|
|
74
|
+
columns[first].padBefore = Math.max(columns[first].padBefore, air);
|
|
75
|
+
columns[last].padAfter = Math.max(columns[last].padAfter, air + (word.hyphenAfter ? HYPHEN_ROOM : 0));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Give each column the air its aligned syllables lean into (see `partLyrics`). */
|
|
79
|
+
function fitLeans(columns, leans) {
|
|
80
|
+
for (const column of columns) {
|
|
81
|
+
const lean = leans.get(column.onset);
|
|
82
|
+
if (!lean)
|
|
83
|
+
continue;
|
|
84
|
+
column.padBefore = Math.max(column.padBefore, lean.before);
|
|
85
|
+
column.padAfter = Math.max(column.padAfter, lean.after);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The narrowest equal width for `beat`'s columns: the plain note spacing, widened only so that
|
|
90
|
+
* neighbouring syllables of the beat stay apart. A syllable sung over several notes ("Tu" over
|
|
91
|
+
* "3 2 3 5") spreads over them; if the first or last syllable still reaches past the beat, the
|
|
92
|
+
* beat gets that much air on that side instead of wider gaps between its notes.
|
|
93
|
+
*/
|
|
94
|
+
function evenBeat(beat) {
|
|
95
|
+
const n = beat.length;
|
|
96
|
+
const sung = beat.flatMap((c, i) => (c.minWidth > NOTATION.slot ? [i] : []));
|
|
97
|
+
let width = NOTATION.slot;
|
|
98
|
+
sung.forEach((i, k) => {
|
|
99
|
+
const next = sung[k + 1];
|
|
100
|
+
if (next !== undefined)
|
|
101
|
+
width = Math.max(width, (beat[i].minWidth + beat[next].minWidth) / 2 / (next - i));
|
|
102
|
+
});
|
|
103
|
+
const reach = (index, columns) => Math.max(0, beat[index].minWidth / 2 - (columns + 0.5) * width);
|
|
104
|
+
const first = sung[0];
|
|
105
|
+
const last = sung.at(-1);
|
|
106
|
+
return {
|
|
107
|
+
width,
|
|
108
|
+
before: first === undefined ? 0 : reach(first, first),
|
|
109
|
+
after: last === undefined ? 0 : reach(last, n - 1 - last),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Space the notes of a beat evenly and closely ("3 2 3 5" under one syllable): every column of
|
|
114
|
+
* the beat gets the same width. Beats with a word sung across notes keep their own spacing.
|
|
115
|
+
*/
|
|
116
|
+
function evenBeats(columns) {
|
|
117
|
+
const beats = Map.groupBy(columns, (c) => c.beat);
|
|
118
|
+
for (const beat of beats.values()) {
|
|
119
|
+
const fitted = beat.some((c) => c.joinsNext || c.joinedFromPrevious || c.padBefore || c.padAfter);
|
|
120
|
+
if (beat.length < 2 || fitted)
|
|
121
|
+
continue;
|
|
122
|
+
const { width, before, after } = evenBeat(beat);
|
|
123
|
+
for (const c of beat)
|
|
124
|
+
c.minWidth = width;
|
|
125
|
+
beat[0].padBefore = before;
|
|
126
|
+
beat[beat.length - 1].padAfter = after;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** Space the tuplets of every part evenly (see `spaceTuplets`). */
|
|
130
|
+
function fitTuplets(columns, music, measureIndex, slices) {
|
|
131
|
+
const tuplets = slices.flatMap((partSlices, partIndex) => tupletOnsets(partSlices, music.parts[partIndex].measures[measureIndex].events));
|
|
132
|
+
if (tuplets.length === 0)
|
|
133
|
+
return columns;
|
|
134
|
+
const occupied = new Set([
|
|
135
|
+
...slices.flat().map((s) => s.onset),
|
|
136
|
+
...(music.measures[measureIndex].chords ?? []).map((c) => c.at),
|
|
137
|
+
]);
|
|
138
|
+
return spaceTuplets(columns, tuplets, occupied);
|
|
139
|
+
}
|
|
140
|
+
function columnsOf(music, measureIndex, frame, slices, lyricWidth) {
|
|
141
|
+
const byOnset = new Map();
|
|
142
|
+
const add = (onset, beat, width) => {
|
|
143
|
+
const column = byOnset.get(onset);
|
|
144
|
+
if (column)
|
|
145
|
+
column.minWidth = Math.max(column.minWidth, width);
|
|
146
|
+
else
|
|
147
|
+
byOnset.set(onset, {
|
|
148
|
+
onset,
|
|
149
|
+
beat,
|
|
150
|
+
minWidth: Math.max(NOTATION.slot, width),
|
|
151
|
+
joinsNext: false,
|
|
152
|
+
joinedFromPrevious: false,
|
|
153
|
+
padBefore: 0,
|
|
154
|
+
padAfter: 0,
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
// Every beat keeps at least its first column, so an empty measure still shows its length (a
|
|
158
|
+
// pickup bar only its own beats). Chords float over these beat columns and take no room: they
|
|
159
|
+
// never move the notes.
|
|
160
|
+
const beatOf = (onset) => groupOf(frame, onset);
|
|
161
|
+
for (const onset of beatOnsets(frame))
|
|
162
|
+
add(onset, beatOf(onset), 0);
|
|
163
|
+
const words = [];
|
|
164
|
+
const leans = new Map();
|
|
165
|
+
slices.forEach((partSlices, partIndex) => {
|
|
166
|
+
const events = music.parts[partIndex].measures[measureIndex].events;
|
|
167
|
+
const heads = partSlices.flatMap((s) => {
|
|
168
|
+
const event = events[s.eventIndex];
|
|
169
|
+
// Lyrics shared with a part below take room there only (ADR 0014).
|
|
170
|
+
const hidden = lyricsHiddenAt(music.measures[measureIndex], music.parts[partIndex].id, s.onset);
|
|
171
|
+
return s.head && event.type === "note" && !hidden ? [{ onset: s.onset, lyrics: event.lyrics }] : [];
|
|
172
|
+
});
|
|
173
|
+
const sung = partLyrics(heads, measureIndex, lyricWidth);
|
|
174
|
+
for (const s of partSlices)
|
|
175
|
+
add(s.onset, s.beat, sung.room.get(s.onset) ?? 0);
|
|
176
|
+
words.push(...sung.words);
|
|
177
|
+
for (const [onset, lean] of sung.leans)
|
|
178
|
+
addLean(leans, onset, lean);
|
|
179
|
+
});
|
|
180
|
+
const columns = [...byOnset.values()].sort((a, b) => a.onset - b.onset);
|
|
181
|
+
fitWords(columns, words);
|
|
182
|
+
fitLeans(columns, leans);
|
|
183
|
+
evenBeats(columns);
|
|
184
|
+
return fitTuplets(columns, music, measureIndex, slices);
|
|
185
|
+
}
|
|
186
|
+
/** The beat gap before a column: none inside a word sung across notes or a tuplet, or within a beat. */
|
|
187
|
+
export const gapBefore = (column, previous) => previous && column.beat !== previous.beat && !column.joinedFromPrevious && !column.inTuplet ? NOTATION.beatGap : 0;
|
|
188
|
+
/** Columns that take extra room when a system is stretched: not the notes of a joined word. */
|
|
189
|
+
export const stretches = (column) => !column.joinsNext && !column.joinedFromPrevious;
|
|
190
|
+
const HEAVY_BARLINES = new Set(["double", "final", "repeat_end"]);
|
|
191
|
+
export function planMeasure(music, measureIndex, frame, lyricWidth, keyMark = null) {
|
|
192
|
+
const measure = music.measures[measureIndex];
|
|
193
|
+
const slices = music.parts.map((part) => part.visible ? sliceMeasure(part.measures[measureIndex].events, frame.meter, frame.phase) : []);
|
|
194
|
+
// A text bar writes no notes: it has no columns, only room for its text.
|
|
195
|
+
const columns = measure.text_bar ? [] : columnsOf(music, measureIndex, frame, slices, lyricWidth);
|
|
196
|
+
const lead = NOTATION.measurePad +
|
|
197
|
+
(measure.repeat_start ? NOTATION.repeatStartWidth : 0) +
|
|
198
|
+
(keyMark?.pivots && keyMark.at === 0 ? NOTATION.pivotWidth + NOTATION.pivotGap : 0);
|
|
199
|
+
const tail = NOTATION.measurePad +
|
|
200
|
+
NOTATION.barWidth +
|
|
201
|
+
(HEAVY_BARLINES.has(measure.barline) ? NOTATION.heavyBarExtra : 0);
|
|
202
|
+
const adjust = measure.width_adjust ?? 0;
|
|
203
|
+
const text = measure.text_bar ? textBarWidth(measure.text_bar.text) : 0;
|
|
204
|
+
const { naturalWidth, compactWidth } = widthsOf(lead, tail, columns);
|
|
205
|
+
return {
|
|
206
|
+
measureIndex,
|
|
207
|
+
frame,
|
|
208
|
+
slices,
|
|
209
|
+
columns,
|
|
210
|
+
lead,
|
|
211
|
+
tail,
|
|
212
|
+
naturalWidth: naturalWidth + text,
|
|
213
|
+
compactWidth: compactWidth + text,
|
|
214
|
+
adjust,
|
|
215
|
+
from: 0,
|
|
216
|
+
to: null,
|
|
217
|
+
keyMark,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/** The room a text bar's text takes: its widest line and air either side. */
|
|
221
|
+
export function textBarWidth(text) {
|
|
222
|
+
const widest = Math.max(0, ...text.split("\n").map((line) => textWidth(line, NOTATION.textBarSize)));
|
|
223
|
+
return widest + 2 * NOTATION.textBarPad;
|
|
224
|
+
}
|
|
225
|
+
/** The natural and compact widths of columns between a lead and a tail. */
|
|
226
|
+
export function widthsOf(lead, tail, columns) {
|
|
227
|
+
const gaps = columns.reduce((sum, c, i) => sum + gapBefore(c, columns[i - 1]), 0);
|
|
228
|
+
return {
|
|
229
|
+
naturalWidth: lead + tail + gaps + columns.reduce((sum, c) => sum + c.padBefore + c.minWidth + c.padAfter, 0),
|
|
230
|
+
compactWidth: lead + tail + gaps + columns.length * NOTATION.slot,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type MeasurePlan } from "./measurePlan.js";
|
|
2
|
+
/**
|
|
3
|
+
* A bar split across two systems (ADR 0008): its first beats end one system with no bar line, the
|
|
4
|
+
* rest start the next one and close with the bar's bar line. Each part is planned as a segment of
|
|
5
|
+
* the bar's plan, so both keep the columns (and so the spacing) the whole bar would have.
|
|
6
|
+
*/
|
|
7
|
+
/** Whether `tick` lies in the segment's part of the bar. */
|
|
8
|
+
export declare const holdsTick: (segment: Pick<MeasurePlan, "from" | "to">, tick: number) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Where a bar (or a segment of it) may be split: every beat inside it that no written piece of
|
|
11
|
+
* any part runs across (a tuplet over two beats, for one), in time order.
|
|
12
|
+
*/
|
|
13
|
+
export declare function splitPoints(plan: MeasurePlan): number[];
|
|
14
|
+
/** The beats of the bar from `from` up to `to` (null = its end). */
|
|
15
|
+
export declare const beatsBetween: (plan: MeasurePlan, from: number, to: number | null) => number;
|
|
16
|
+
/**
|
|
17
|
+
* The part of a whole bar's plan from `from` to `to` (ticks; null = the bar's end). Only the part
|
|
18
|
+
* that starts the bar keeps its opening (a repeat-start sign); only the part that ends it keeps
|
|
19
|
+
* its bar line. A part that goes on on the next system keeps none of the bar's drag either: the
|
|
20
|
+
* drag belongs to the bar line, which the last part draws.
|
|
21
|
+
*/
|
|
22
|
+
export declare function segmentOf(plan: MeasurePlan, from: number, to: number | null): MeasurePlan;
|
|
23
|
+
/** How a bar is laid out: whole, or in two parts when `splitAt` is a beat it may be split at. */
|
|
24
|
+
export declare function measureSegments(plan: MeasurePlan, splitAt: number | null | undefined): MeasurePlan[];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { beatOnsets } from "../notation/time.js";
|
|
2
|
+
import { widthsOf } from "./measurePlan.js";
|
|
3
|
+
import { NOTATION } from "./notationMetrics.js";
|
|
4
|
+
/**
|
|
5
|
+
* A bar split across two systems (ADR 0008): its first beats end one system with no bar line, the
|
|
6
|
+
* rest start the next one and close with the bar's bar line. Each part is planned as a segment of
|
|
7
|
+
* the bar's plan, so both keep the columns (and so the spacing) the whole bar would have.
|
|
8
|
+
*/
|
|
9
|
+
/** Whether `tick` lies in the segment's part of the bar. */
|
|
10
|
+
export const holdsTick = (segment, tick) => tick >= segment.from && (segment.to === null || tick < segment.to);
|
|
11
|
+
/**
|
|
12
|
+
* Where a bar (or a segment of it) may be split: every beat inside it that no written piece of
|
|
13
|
+
* any part runs across (a tuplet over two beats, for one), in time order.
|
|
14
|
+
*/
|
|
15
|
+
export function splitPoints(plan) {
|
|
16
|
+
// A bar without columns is a text bar: its text is never split.
|
|
17
|
+
if (plan.columns.length === 0)
|
|
18
|
+
return [];
|
|
19
|
+
const end = plan.to ?? plan.frame.length;
|
|
20
|
+
const crossed = (tick) => plan.slices.some((part) => part.some((s) => s.onset < tick && tick < s.onset + s.length));
|
|
21
|
+
return beatOnsets(plan.frame).filter((tick) => tick > plan.from && tick < end && !crossed(tick));
|
|
22
|
+
}
|
|
23
|
+
/** The beats of the bar from `from` up to `to` (null = its end). */
|
|
24
|
+
export const beatsBetween = (plan, from, to) => beatOnsets(plan.frame).filter((tick) => tick >= from && (to === null || tick < to)).length;
|
|
25
|
+
/**
|
|
26
|
+
* The part of a whole bar's plan from `from` to `to` (ticks; null = the bar's end). Only the part
|
|
27
|
+
* that starts the bar keeps its opening (a repeat-start sign); only the part that ends it keeps
|
|
28
|
+
* its bar line. A part that goes on on the next system keeps none of the bar's drag either: the
|
|
29
|
+
* drag belongs to the bar line, which the last part draws.
|
|
30
|
+
*/
|
|
31
|
+
export function segmentOf(plan, from, to) {
|
|
32
|
+
if (from === plan.from && to === plan.to)
|
|
33
|
+
return plan;
|
|
34
|
+
const segment = { from, to };
|
|
35
|
+
const columns = plan.columns.filter((c) => holdsTick(segment, c.onset));
|
|
36
|
+
// A key change goes with the part of the bar it takes over in (ADR 0017). A part that starts
|
|
37
|
+
// with it opens with its box, so the box takes room in that part's lead.
|
|
38
|
+
// Its box may instead close the part before, at the end of its line (`boxAbove`).
|
|
39
|
+
const keyMark = plan.keyMark && holdsTick(segment, plan.keyMark.at) ? plan.keyMark : null;
|
|
40
|
+
const withBox = (mark) => mark !== null && mark.pivots !== null;
|
|
41
|
+
const opensWithBox = from > 0 && keyMark?.at === from && !keyMark.boxAbove && withBox(keyMark);
|
|
42
|
+
const closingKeyMark = to !== null && plan.keyMark?.at === to && plan.keyMark.boxAbove ? plan.keyMark : null;
|
|
43
|
+
const boxRoom = NOTATION.pivotWidth + NOTATION.pivotGap;
|
|
44
|
+
const lead = from === 0 ? plan.lead : NOTATION.measurePad + (opensWithBox ? boxRoom : 0);
|
|
45
|
+
const tail = to === null ? plan.tail : NOTATION.measurePad + (withBox(closingKeyMark) ? boxRoom : 0);
|
|
46
|
+
return {
|
|
47
|
+
...plan,
|
|
48
|
+
...segment,
|
|
49
|
+
slices: plan.slices.map((part) => part.filter((s) => holdsTick(segment, s.onset))),
|
|
50
|
+
columns,
|
|
51
|
+
lead,
|
|
52
|
+
tail,
|
|
53
|
+
...widthsOf(lead, tail, columns),
|
|
54
|
+
adjust: to === null ? plan.adjust : 0,
|
|
55
|
+
keyMark,
|
|
56
|
+
closingKeyMark,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** How a bar is laid out: whole, or in two parts when `splitAt` is a beat it may be split at. */
|
|
60
|
+
export function measureSegments(plan, splitAt) {
|
|
61
|
+
if (splitAt == null || !splitPoints(plan).includes(splitAt))
|
|
62
|
+
return [plan];
|
|
63
|
+
return [segmentOf(plan, 0, splitAt), segmentOf(plan, splitAt, null)];
|
|
64
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sizes of the notation, in px at 96 dpi (shared by screen, print and SVG export). The layout
|
|
3
|
+
* positions everything from these numbers and the renderers draw with the same ones, so nothing
|
|
4
|
+
* is measured in the DOM. Proportions follow the reference score (a compact SATB choir page).
|
|
5
|
+
*/
|
|
6
|
+
export declare const NOTATION: {
|
|
7
|
+
/** Digits, rests and continuation dots. */
|
|
8
|
+
readonly digitSize: 15;
|
|
9
|
+
/** Smallest room for one written piece (a digit or a dot). */
|
|
10
|
+
readonly slot: 11;
|
|
11
|
+
/** Extra air after each beat, so beats read as groups. */
|
|
12
|
+
readonly beatGap: 4;
|
|
13
|
+
/** Air inside a measure, before its first and after its last piece. */
|
|
14
|
+
readonly measurePad: 5;
|
|
15
|
+
/** Room for the bar line at the end of a measure. */
|
|
16
|
+
readonly barWidth: 8;
|
|
17
|
+
/** Extra room for a heavy bar line (double, final, repeat). */
|
|
18
|
+
readonly heavyBarExtra: 6;
|
|
19
|
+
/** Room for a repeat-start sign at the start of a measure. */
|
|
20
|
+
readonly repeatStartWidth: 12;
|
|
21
|
+
/** The system bracket, then the part labels; the music starts `labelGap` after the widest. */
|
|
22
|
+
readonly bracketX: 3;
|
|
23
|
+
readonly labelX: 12;
|
|
24
|
+
readonly labelGap: 5;
|
|
25
|
+
/** One part's note row: duration lines, octave dots above, the digits, dots below, arcs. */
|
|
26
|
+
readonly noteRowHeight: 32;
|
|
27
|
+
/**
|
|
28
|
+
* Digit centre, measured from the top of the row: room for the top duration line above
|
|
29
|
+
* (`durationLineOffset`), and below for low-octave dots and arcs (`arcOffset + arcDepth`).
|
|
30
|
+
*/
|
|
31
|
+
readonly digitY: 16;
|
|
32
|
+
readonly digitHalfHeight: 6;
|
|
33
|
+
/**
|
|
34
|
+
* Duration lines: the first (longest) one this far above the digit centre, so it sits at the
|
|
35
|
+
* same height in every beat; each deeper, shorter one `lineGap` closer to the digits.
|
|
36
|
+
*/
|
|
37
|
+
readonly durationLineOffset: 15;
|
|
38
|
+
readonly lineGap: 3;
|
|
39
|
+
/** Octave dots: the first this far from the digit centre (just clear of the glyph). */
|
|
40
|
+
readonly octaveDotOffset: 8.5;
|
|
41
|
+
readonly octaveDotStep: 3.5;
|
|
42
|
+
readonly octaveDotRadius: 1.4;
|
|
43
|
+
/** Ties and slurs start this far below the digit centre and dip `arcDepth` more. */
|
|
44
|
+
readonly arcOffset: 11;
|
|
45
|
+
readonly arcDepth: 4;
|
|
46
|
+
readonly accidentalSize: 9;
|
|
47
|
+
/** Accidental strokes through a digit: half their width and height, and line width. */
|
|
48
|
+
readonly strokeHalfWidth: 4.5;
|
|
49
|
+
readonly strokeHalfHeight: 8;
|
|
50
|
+
readonly strokeWidth: 1.6;
|
|
51
|
+
/** Space kept between neighbouring syllables. */
|
|
52
|
+
readonly lyricPad: 4;
|
|
53
|
+
readonly labelSize: 11;
|
|
54
|
+
readonly rowGap: 6;
|
|
55
|
+
/** Space between every two parts, with or without lyrics. */
|
|
56
|
+
readonly partGap: 1;
|
|
57
|
+
readonly barHalfHeight: 11;
|
|
58
|
+
/** Room above a system that has a volta bracket or a section label. */
|
|
59
|
+
readonly headroom: 21;
|
|
60
|
+
/**
|
|
61
|
+
* Chord symbols: their size, and the air between one and the first row's top duration line.
|
|
62
|
+
* They float: no room is kept for them (see `layout/floating.ts`), and they take no width.
|
|
63
|
+
*/
|
|
64
|
+
readonly chordSize: 13;
|
|
65
|
+
readonly chordAir: 5;
|
|
66
|
+
/** A text bar's text ("2 bars instr."): its size, line height and the air either side of it. */
|
|
67
|
+
readonly textBarSize: 13;
|
|
68
|
+
readonly textBarLine: 16;
|
|
69
|
+
readonly textBarPad: 14;
|
|
70
|
+
/** The key-change box ("5 → 3" per part): its width, the air after it, the arrow's size. */
|
|
71
|
+
readonly pivotWidth: 46;
|
|
72
|
+
readonly pivotGap: 8;
|
|
73
|
+
readonly pivotArrowSize: 11;
|
|
74
|
+
/**
|
|
75
|
+
* Directions (ADR 0011): a dynamic's and an expression's size, and a hairpin's half opening.
|
|
76
|
+
* They float above the chords and take no room of their own.
|
|
77
|
+
*/
|
|
78
|
+
/** A volta bracket's line stands this far above the row, its numeral's circle has this radius. */
|
|
79
|
+
readonly voltaRise: 12;
|
|
80
|
+
readonly voltaRadius: 7.5;
|
|
81
|
+
/** Air between the lowest stroke of a dynamic (the tail of its p or f) and the beat line under it. */
|
|
82
|
+
readonly beatLineGap: 2;
|
|
83
|
+
readonly dynamicSize: 13;
|
|
84
|
+
readonly expressionSize: 10;
|
|
85
|
+
readonly hairpinHalf: 3.5;
|
|
86
|
+
/**
|
|
87
|
+
* Tuplets: extra room above a row that has one, the size of its number, and the air between
|
|
88
|
+
* two of its notes.
|
|
89
|
+
*/
|
|
90
|
+
readonly tupletRoom: 8;
|
|
91
|
+
readonly tupletSize: 8;
|
|
92
|
+
readonly tupletGap: 2;
|
|
93
|
+
};
|
|
94
|
+
/** Width of a syllable as the lyrics font sets it (layout units). */
|
|
95
|
+
export type LyricMeasure = (text: string) => number;
|
|
96
|
+
/** How lyrics are set: font size, line height and syllable widths, all in layout units. */
|
|
97
|
+
export type LyricStyle = {
|
|
98
|
+
size: number;
|
|
99
|
+
lineHeight: number;
|
|
100
|
+
width: LyricMeasure;
|
|
101
|
+
};
|
|
102
|
+
/** The lyric size the layout uses when none is given (px at the default note size). */
|
|
103
|
+
export declare const DEFAULT_LYRIC_SIZE = 18;
|
|
104
|
+
/**
|
|
105
|
+
* Lyrics at `size` in a font that is `widthScale` times as wide as the regular sans `textWidth`
|
|
106
|
+
* estimates (an extra-condensed face is about 0.7). Lines get a little air (18 -> 20).
|
|
107
|
+
*/
|
|
108
|
+
export declare function lyricStyle(size: number, widthScale: number): LyricStyle;
|
|
109
|
+
/** Glyph-width estimate of text in the score's sans font (narrow letters count less). */
|
|
110
|
+
export declare function textWidth(text: string, size: number): number;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { withoutElisions } from "../notation/elision.js";
|
|
2
|
+
/**
|
|
3
|
+
* Sizes of the notation, in px at 96 dpi (shared by screen, print and SVG export). The layout
|
|
4
|
+
* positions everything from these numbers and the renderers draw with the same ones, so nothing
|
|
5
|
+
* is measured in the DOM. Proportions follow the reference score (a compact SATB choir page).
|
|
6
|
+
*/
|
|
7
|
+
export const NOTATION = {
|
|
8
|
+
/** Digits, rests and continuation dots. */
|
|
9
|
+
digitSize: 15,
|
|
10
|
+
/** Smallest room for one written piece (a digit or a dot). */
|
|
11
|
+
slot: 11,
|
|
12
|
+
/** Extra air after each beat, so beats read as groups. */
|
|
13
|
+
beatGap: 4,
|
|
14
|
+
/** Air inside a measure, before its first and after its last piece. */
|
|
15
|
+
measurePad: 5,
|
|
16
|
+
/** Room for the bar line at the end of a measure. */
|
|
17
|
+
barWidth: 8,
|
|
18
|
+
/** Extra room for a heavy bar line (double, final, repeat). */
|
|
19
|
+
heavyBarExtra: 6,
|
|
20
|
+
/** Room for a repeat-start sign at the start of a measure. */
|
|
21
|
+
repeatStartWidth: 12,
|
|
22
|
+
/** The system bracket, then the part labels; the music starts `labelGap` after the widest. */
|
|
23
|
+
bracketX: 3,
|
|
24
|
+
labelX: 12,
|
|
25
|
+
labelGap: 5,
|
|
26
|
+
/** One part's note row: duration lines, octave dots above, the digits, dots below, arcs. */
|
|
27
|
+
noteRowHeight: 32,
|
|
28
|
+
/**
|
|
29
|
+
* Digit centre, measured from the top of the row: room for the top duration line above
|
|
30
|
+
* (`durationLineOffset`), and below for low-octave dots and arcs (`arcOffset + arcDepth`).
|
|
31
|
+
*/
|
|
32
|
+
digitY: 16,
|
|
33
|
+
digitHalfHeight: 6,
|
|
34
|
+
/**
|
|
35
|
+
* Duration lines: the first (longest) one this far above the digit centre, so it sits at the
|
|
36
|
+
* same height in every beat; each deeper, shorter one `lineGap` closer to the digits.
|
|
37
|
+
*/
|
|
38
|
+
durationLineOffset: 15,
|
|
39
|
+
lineGap: 3,
|
|
40
|
+
/** Octave dots: the first this far from the digit centre (just clear of the glyph). */
|
|
41
|
+
octaveDotOffset: 8.5,
|
|
42
|
+
octaveDotStep: 3.5,
|
|
43
|
+
octaveDotRadius: 1.4,
|
|
44
|
+
/** Ties and slurs start this far below the digit centre and dip `arcDepth` more. */
|
|
45
|
+
arcOffset: 11,
|
|
46
|
+
arcDepth: 4,
|
|
47
|
+
accidentalSize: 9,
|
|
48
|
+
/** Accidental strokes through a digit: half their width and height, and line width. */
|
|
49
|
+
strokeHalfWidth: 4.5,
|
|
50
|
+
strokeHalfHeight: 8,
|
|
51
|
+
strokeWidth: 1.6,
|
|
52
|
+
/** Space kept between neighbouring syllables. */
|
|
53
|
+
lyricPad: 4,
|
|
54
|
+
labelSize: 11,
|
|
55
|
+
rowGap: 6,
|
|
56
|
+
/** Space between every two parts, with or without lyrics. */
|
|
57
|
+
partGap: 1,
|
|
58
|
+
barHalfHeight: 11,
|
|
59
|
+
/** Room above a system that has a volta bracket or a section label. */
|
|
60
|
+
headroom: 21,
|
|
61
|
+
/**
|
|
62
|
+
* Chord symbols: their size, and the air between one and the first row's top duration line.
|
|
63
|
+
* They float: no room is kept for them (see `layout/floating.ts`), and they take no width.
|
|
64
|
+
*/
|
|
65
|
+
chordSize: 13,
|
|
66
|
+
chordAir: 5,
|
|
67
|
+
/** A text bar's text ("2 bars instr."): its size, line height and the air either side of it. */
|
|
68
|
+
textBarSize: 13,
|
|
69
|
+
textBarLine: 16,
|
|
70
|
+
textBarPad: 14,
|
|
71
|
+
/** The key-change box ("5 → 3" per part): its width, the air after it, the arrow's size. */
|
|
72
|
+
pivotWidth: 46,
|
|
73
|
+
pivotGap: 8,
|
|
74
|
+
pivotArrowSize: 11,
|
|
75
|
+
/**
|
|
76
|
+
* Directions (ADR 0011): a dynamic's and an expression's size, and a hairpin's half opening.
|
|
77
|
+
* They float above the chords and take no room of their own.
|
|
78
|
+
*/
|
|
79
|
+
/** A volta bracket's line stands this far above the row, its numeral's circle has this radius. */
|
|
80
|
+
voltaRise: 12,
|
|
81
|
+
voltaRadius: 7.5,
|
|
82
|
+
/** Air between the lowest stroke of a dynamic (the tail of its p or f) and the beat line under it. */
|
|
83
|
+
beatLineGap: 2,
|
|
84
|
+
dynamicSize: 13,
|
|
85
|
+
expressionSize: 10,
|
|
86
|
+
hairpinHalf: 3.5,
|
|
87
|
+
/**
|
|
88
|
+
* Tuplets: extra room above a row that has one, the size of its number, and the air between
|
|
89
|
+
* two of its notes.
|
|
90
|
+
*/
|
|
91
|
+
tupletRoom: 8,
|
|
92
|
+
tupletSize: 8,
|
|
93
|
+
tupletGap: 2,
|
|
94
|
+
};
|
|
95
|
+
/** The lyric size the layout uses when none is given (px at the default note size). */
|
|
96
|
+
export const DEFAULT_LYRIC_SIZE = 18;
|
|
97
|
+
/**
|
|
98
|
+
* Lyrics at `size` in a font that is `widthScale` times as wide as the regular sans `textWidth`
|
|
99
|
+
* estimates (an extra-condensed face is about 0.7). Lines get a little air (18 -> 20).
|
|
100
|
+
*/
|
|
101
|
+
export function lyricStyle(size, widthScale) {
|
|
102
|
+
return {
|
|
103
|
+
size,
|
|
104
|
+
lineHeight: Math.round((size * 10) / 9),
|
|
105
|
+
width: (text) => textWidth(withoutElisions(text), size) * widthScale,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** Glyph-width estimate of text in the score's sans font (narrow letters count less). */
|
|
109
|
+
export function textWidth(text, size) {
|
|
110
|
+
let ems = 0;
|
|
111
|
+
for (const char of text) {
|
|
112
|
+
if ("iljtf.,;:'’!|() ".includes(char))
|
|
113
|
+
ems += 0.3;
|
|
114
|
+
else if ("mwMW".includes(char))
|
|
115
|
+
ems += 0.82;
|
|
116
|
+
else if (char === char.toUpperCase() && /[A-Z]/.test(char))
|
|
117
|
+
ems += 0.66;
|
|
118
|
+
else
|
|
119
|
+
ems += 0.55;
|
|
120
|
+
}
|
|
121
|
+
return ems * size;
|
|
122
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { MeasureBreak, ScoreMeasure } from "../schema/types.js";
|
|
2
|
+
import { type MeasurePlan } from "./measurePlan.js";
|
|
3
|
+
/** A line break a move sets or clears, by measure index. */
|
|
4
|
+
export type BreakEdit = {
|
|
5
|
+
measureIndex: number;
|
|
6
|
+
breakAfter: MeasureBreak | null;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* What moving music to another system changes: where its bar is split afterwards (`splitAt`
|
|
10
|
+
* ticks, null = not split; ADR 0008) and the line breaks that keep the systems where they go.
|
|
11
|
+
* `beats`: how many beats move; null when the whole bar (or all that is left of it) moves.
|
|
12
|
+
*/
|
|
13
|
+
export type MoveEdit = {
|
|
14
|
+
measureIndex: number;
|
|
15
|
+
beats: number | null;
|
|
16
|
+
splitAt: number | null;
|
|
17
|
+
breaks: BreakEdit[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Bringing the next system's first beats up onto this one: how much the system's measures must
|
|
21
|
+
* give (`room`, layout px; zero or less when it fits already) and how far a drag must already have
|
|
22
|
+
* gone before this option is reached (`reach`: what the option with one beat fewer adds).
|
|
23
|
+
*/
|
|
24
|
+
export type PullOption = MoveEdit & {
|
|
25
|
+
room: number;
|
|
26
|
+
reach: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Moving the previous system's last beats down to start this system: the width that moves
|
|
30
|
+
* (`width`), and how much this system's first measure must give back of the width its bar line
|
|
31
|
+
* was dragged wider by so that both fit on one line (`narrowFirst`, 0 when they fit as they are).
|
|
32
|
+
*/
|
|
33
|
+
export type PushOption = MoveEdit & {
|
|
34
|
+
width: number;
|
|
35
|
+
narrowFirst: number;
|
|
36
|
+
};
|
|
37
|
+
/** Which measures (or parts of a split bar) share a system (one line of every part), PRD FR-049 / FR-064. */
|
|
38
|
+
export type SystemPlan = {
|
|
39
|
+
measures: MeasurePlan[];
|
|
40
|
+
/**
|
|
41
|
+
* Stretch the measures to the full width: every system but the last, and the last when it is
|
|
42
|
+
* nearly full, unless the score's final bar line was dragged (then it ends where it was dropped).
|
|
43
|
+
*/
|
|
44
|
+
justify: boolean;
|
|
45
|
+
/** The score's last system, which ends at its final bar line. */
|
|
46
|
+
final: boolean;
|
|
47
|
+
/** The user asked for a new page after this system. */
|
|
48
|
+
pageBreakAfter: boolean;
|
|
49
|
+
/** Fewest beats first; empty when nothing follows or the system ends at a page break. */
|
|
50
|
+
pullNext: PullOption[];
|
|
51
|
+
/** Fewest beats first; empty on the first system or when nothing would fit a line. */
|
|
52
|
+
pushIn: PushOption[];
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Fill systems with whole measures, greedily, honouring line and page breaks set on measures and
|
|
56
|
+
* bars split across systems (their first part always ends a system). A measure wider than a
|
|
57
|
+
* system gets a system of its own. `plans` are the whole bars; `measures` carry their breaks and splits.
|
|
58
|
+
*/
|
|
59
|
+
export declare function breakSystems(plans: readonly MeasurePlan[], measures: readonly Pick<ScoreMeasure, "break_after" | "split_at">[], width: number): SystemPlan[];
|