@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,30 @@
|
|
|
1
|
+
import { keyChanges, keyReader, respell } from "../notation/keys.js";
|
|
2
|
+
import { withOnsets } from "../model/unisons.js";
|
|
3
|
+
/** A part's last note before tick `at` of bar `index` (earlier in the bar, or in earlier bars), with the key it was written in. */
|
|
4
|
+
function lastNoteBefore(music, partIndex, index, at, keyAt) {
|
|
5
|
+
const measures = music.parts[partIndex].measures;
|
|
6
|
+
for (let m = index; m >= 0; m--) {
|
|
7
|
+
const placed = withOnsets(measures[m].events).filter((p) => m < index || p.onset < at);
|
|
8
|
+
for (const { event, onset } of placed.toReversed())
|
|
9
|
+
if (event.type === "note")
|
|
10
|
+
return { note: event, key: keyAt(m, onset) };
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
/** The key mark at every measure: null where the key does not change. */
|
|
15
|
+
export function keyMarksOf(music, scoreKey) {
|
|
16
|
+
const keyAt = keyReader(music.measures, scoreKey);
|
|
17
|
+
return keyChanges(music.measures, scoreKey).map((change, index) => {
|
|
18
|
+
if (!change)
|
|
19
|
+
return null;
|
|
20
|
+
const { to, at } = change;
|
|
21
|
+
const boxAbove = at > 0 && music.measures[index].key_pivot_above === true;
|
|
22
|
+
if (music.measures[index].key_pivot === false)
|
|
23
|
+
return { key: to, at, pivots: null, boxAbove };
|
|
24
|
+
const pivots = music.parts.map((part, partIndex) => {
|
|
25
|
+
const last = part.visible ? lastNoteBefore(music, partIndex, index, at, keyAt) : null;
|
|
26
|
+
return last && { from: last.note, to: respell(last.note, last.key, to) };
|
|
27
|
+
});
|
|
28
|
+
return { key: to, at, pivots: pivots.some(Boolean) ? pivots : null, boxAbove };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Lyric } from "../schema/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* How far right of its note's centre the syllable is drawn centred (negative: to the left). A
|
|
4
|
+
* left-aligned syllable starts at the note's left edge, a right-aligned one ends at its right edge.
|
|
5
|
+
*/
|
|
6
|
+
export declare const syllableShift: (lyric: Pick<Lyric, "align">, width: number) => number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { lyricAlign } from "../notation/lyricAlign.js";
|
|
2
|
+
import { NOTATION } from "./notationMetrics.js";
|
|
3
|
+
/** Half a digit's drawn width: an aligned syllable lines up with this edge of its note. */
|
|
4
|
+
const NOTE_HALF_WIDTH = NOTATION.digitSize * 0.3;
|
|
5
|
+
/** How far right of its note's centre a syllable of `width` is centred, per alignment. */
|
|
6
|
+
const CENTRE_SHIFT = {
|
|
7
|
+
left: (width) => width / 2 - NOTE_HALF_WIDTH,
|
|
8
|
+
center: () => 0,
|
|
9
|
+
right: (width) => NOTE_HALF_WIDTH - width / 2,
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* How far right of its note's centre the syllable is drawn centred (negative: to the left). A
|
|
13
|
+
* left-aligned syllable starts at the note's left edge, a right-aligned one ends at its right edge.
|
|
14
|
+
*/
|
|
15
|
+
export const syllableShift = (lyric, width) => CENTRE_SHIFT[lyricAlign(lyric)](width);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Lyric } from "../schema/types.js";
|
|
2
|
+
/** One sung note's syllable on a lyric line, and the measure it is in. */
|
|
3
|
+
export type SungSyllable = {
|
|
4
|
+
lyric: Lyric | null;
|
|
5
|
+
measureIndex: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Words sung across notes ("ting+gal" = "tinggal"), as runs of indexes into `sung` (one entry per
|
|
9
|
+
* sung note, in order): every syllable but the last joins the next, and all of them are in the
|
|
10
|
+
* same measure. A run left open (the line or measure ends first, or a note has no syllable) is
|
|
11
|
+
* not a word: its syllables are laid out as ordinary ones, so nothing can overlap.
|
|
12
|
+
*/
|
|
13
|
+
export declare function joinedWords(sung: readonly SungSyllable[]): number[][];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Words sung across notes ("ting+gal" = "tinggal"), as runs of indexes into `sung` (one entry per
|
|
3
|
+
* sung note, in order): every syllable but the last joins the next, and all of them are in the
|
|
4
|
+
* same measure. A run left open (the line or measure ends first, or a note has no syllable) is
|
|
5
|
+
* not a word: its syllables are laid out as ordinary ones, so nothing can overlap.
|
|
6
|
+
*/
|
|
7
|
+
export function joinedWords(sung) {
|
|
8
|
+
const words = [];
|
|
9
|
+
let open = null;
|
|
10
|
+
sung.forEach(({ lyric, measureIndex }, i) => {
|
|
11
|
+
if (open) {
|
|
12
|
+
const sameMeasure = sung[open[0]].measureIndex === measureIndex;
|
|
13
|
+
if (lyric && sameMeasure) {
|
|
14
|
+
open.push(i);
|
|
15
|
+
if (!lyric.join) {
|
|
16
|
+
words.push(open);
|
|
17
|
+
open = null;
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
open = null; // broken: this syllable may still start a word of its own
|
|
22
|
+
}
|
|
23
|
+
if (lyric?.join)
|
|
24
|
+
open = [i];
|
|
25
|
+
});
|
|
26
|
+
return words;
|
|
27
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ScoreMusic } from "../schema/types.js";
|
|
2
|
+
import { type LyricStyle } from "./notationMetrics.js";
|
|
3
|
+
import type { SystemLayout } from "./systemLayout.js";
|
|
4
|
+
/**
|
|
5
|
+
* Lyric positions (PRD FR-054, FR-057, FR-061). A syllable is centred under the note that sings
|
|
6
|
+
* it, or lined up with the note's left or right edge when it is aligned so; a hyphen sits halfway to the next syllable; an extender runs from the syllable to the last
|
|
7
|
+
* piece before the next sung syllable. Positions come from the notes, so moving a note moves
|
|
8
|
+
* its syllable.
|
|
9
|
+
*/
|
|
10
|
+
export type PlacedSyllable = {
|
|
11
|
+
eventId: string;
|
|
12
|
+
line: number;
|
|
13
|
+
text: string;
|
|
14
|
+
/**
|
|
15
|
+
* Centre of the syllable (hit boxes, hyphens, extenders): under its note, moved left or right
|
|
16
|
+
* by its alignment; inside a word sung across notes, its note's centre.
|
|
17
|
+
*/
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
/**
|
|
22
|
+
* Where the text is drawn from. A syllable is drawn from its centre (`x`); inside a word sung
|
|
23
|
+
* across notes ("Da" + "tang") the syllables are drawn from the point where they meet (`end`
|
|
24
|
+
* for the first, `start` for the rest), so they touch whatever the font's real widths are.
|
|
25
|
+
*/
|
|
26
|
+
anchor: "start" | "middle" | "end";
|
|
27
|
+
textX: number;
|
|
28
|
+
};
|
|
29
|
+
export type PlacedHyphen = {
|
|
30
|
+
eventId: string;
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
};
|
|
34
|
+
export type PlacedExtender = {
|
|
35
|
+
eventId: string;
|
|
36
|
+
x1: number;
|
|
37
|
+
x2: number;
|
|
38
|
+
y: number;
|
|
39
|
+
};
|
|
40
|
+
/** An arc under letters of a syllable sung as one sound ("li‿a"), from x1 to x2 at the text's foot. */
|
|
41
|
+
export type PlacedElision = {
|
|
42
|
+
eventId: string;
|
|
43
|
+
x1: number;
|
|
44
|
+
x2: number;
|
|
45
|
+
y: number;
|
|
46
|
+
};
|
|
47
|
+
export type SystemLyrics = {
|
|
48
|
+
/** Font size the syllables are set in (layout units). */
|
|
49
|
+
size: number;
|
|
50
|
+
syllables: PlacedSyllable[];
|
|
51
|
+
hyphens: PlacedHyphen[];
|
|
52
|
+
extenders: PlacedExtender[];
|
|
53
|
+
elisions: PlacedElision[];
|
|
54
|
+
};
|
|
55
|
+
export declare function layoutLyrics(music: ScoreMusic, system: SystemLayout, style: LyricStyle): SystemLyrics;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { lyricsHiddenAt } from "../model/sharedLyrics.js";
|
|
2
|
+
import { syllableShift } from "./lyricAlign.js";
|
|
3
|
+
import { joinedWords } from "./lyricWords.js";
|
|
4
|
+
import { readElisions } from "../notation/elision.js";
|
|
5
|
+
import { NOTATION } from "./notationMetrics.js";
|
|
6
|
+
const lineCenterY = (row, line, lineHeight) => row.y + NOTATION.noteRowHeight + line * lineHeight + lineHeight / 2;
|
|
7
|
+
function sungOnLine(music, row, line) {
|
|
8
|
+
const part = music.parts[row.partIndex];
|
|
9
|
+
const sung = [];
|
|
10
|
+
for (const m of row.measures) {
|
|
11
|
+
const events = part.measures[m.measureIndex].events;
|
|
12
|
+
const measure = music.measures[m.measureIndex];
|
|
13
|
+
for (const s of m.slices) {
|
|
14
|
+
const event = events[s.eventIndex];
|
|
15
|
+
// Lyrics shared with a part below are drawn there only (ADR 0014).
|
|
16
|
+
const shown = s.head && event.type === "note" && !lyricsHiddenAt(measure, part.id, s.onset);
|
|
17
|
+
const lyric = shown ? event.lyrics[line] : null;
|
|
18
|
+
if (lyric)
|
|
19
|
+
sung.push({ eventId: event.id, x: s.x, lyric, measureIndex: m.measureIndex });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return sung;
|
|
23
|
+
}
|
|
24
|
+
const ANCHOR_SHIFT = { start: 0, middle: 0.5, end: 1 };
|
|
25
|
+
/** Where the drawn text of a syllable begins. */
|
|
26
|
+
const textLeft = ({ anchor, textX }, width) => textX - ANCHOR_SHIFT[anchor] * width;
|
|
27
|
+
/** An elision arc's ends: from just inside its first letter to just inside its last. */
|
|
28
|
+
function elisionXs(plain, span, left, width) {
|
|
29
|
+
const inset = (letter) => width(letter) * 0.2;
|
|
30
|
+
const first = plain[span.from];
|
|
31
|
+
const last = plain[span.to];
|
|
32
|
+
return {
|
|
33
|
+
x1: left + width(plain.slice(0, span.from)) + inset(first),
|
|
34
|
+
x2: left + width(plain.slice(0, span.to + 1)) - inset(last),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* How each syllable of a line is drawn: centred on its note (or shifted to the note's left or
|
|
39
|
+
* right edge by its alignment), except inside a word sung across notes, where each syllable is
|
|
40
|
+
* drawn from the point it meets the previous one (the first one up to the point it meets the
|
|
41
|
+
* next) and its alignment is not used. The measure plan put the notes exactly that far apart.
|
|
42
|
+
* Then each syllable moves by the offset it was dragged by (spacing does not make room for it).
|
|
43
|
+
*/
|
|
44
|
+
function placementsOf(sung, widths) {
|
|
45
|
+
return anchoredPlacements(sung, widths).map((p, i) => movedBy(p, sung[i].lyric.offset ?? 0));
|
|
46
|
+
}
|
|
47
|
+
/** A placement moved sideways by a syllable's dragged `offset`. */
|
|
48
|
+
const movedBy = (p, offset) => offset ? { ...p, x: p.x + offset, textX: p.textX + offset } : p;
|
|
49
|
+
/** Placements from the notes, alignments and words alone, before any offset. */
|
|
50
|
+
function anchoredPlacements(sung, widths) {
|
|
51
|
+
const placed = sung.map((s, i) => {
|
|
52
|
+
const x = s.x + syllableShift(s.lyric, widths[i]);
|
|
53
|
+
return { anchor: "middle", textX: x, x };
|
|
54
|
+
});
|
|
55
|
+
for (const word of joinedWords(sung)) {
|
|
56
|
+
word.forEach((i, k) => {
|
|
57
|
+
const x = sung[i].x;
|
|
58
|
+
placed[i] =
|
|
59
|
+
k === 0
|
|
60
|
+
? { anchor: "end", textX: x + widths[i] / 2, x }
|
|
61
|
+
: { anchor: "start", textX: x - widths[i] / 2, x };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return placed;
|
|
65
|
+
}
|
|
66
|
+
/** True when an end-repeat bar line closes one of the measures `from` .. `to - 1`. */
|
|
67
|
+
const repeatEndsBetween = (music, from, to) => music.measures.slice(from, to).some((m) => m.barline === "repeat_end");
|
|
68
|
+
/** Room a hyphen that leads back to the repeat start keeps clear of the end-repeat bar line. */
|
|
69
|
+
const BAR_CLEARANCE = 4;
|
|
70
|
+
/**
|
|
71
|
+
* Where a syllable's hyphen goes: halfway to the next syllable it is sung with. Across an
|
|
72
|
+
* end-repeat bar line the word goes on at the repeat start ("Dam-" then "ping-i" on the second
|
|
73
|
+
* time), not at the next note, so the hyphen stays just after the syllable, before the bar line.
|
|
74
|
+
*/
|
|
75
|
+
function hyphenX(music, system,
|
|
76
|
+
/** The syllable's measure and right edge. */
|
|
77
|
+
from,
|
|
78
|
+
/** The next syllable on the line: its measure and left edge. */
|
|
79
|
+
next) {
|
|
80
|
+
const { measureIndex, right } = from;
|
|
81
|
+
if (next && !repeatEndsBetween(music, measureIndex, next.measureIndex))
|
|
82
|
+
return (right + next.left) / 2;
|
|
83
|
+
const bar = system.measures.find((m) => m.measureIndex === measureIndex)?.barX ?? system.width;
|
|
84
|
+
const edge = music.measures[measureIndex].barline === "repeat_end" ? bar - BAR_CLEARANCE : system.width;
|
|
85
|
+
return (right + Math.min(edge, right + 10)) / 2;
|
|
86
|
+
}
|
|
87
|
+
function layoutLine(music, row, line, system, style, out) {
|
|
88
|
+
const lyricWidth = style.width;
|
|
89
|
+
const y = lineCenterY(row, line, style.lineHeight);
|
|
90
|
+
const sung = sungOnLine(music, row, line);
|
|
91
|
+
const pieceXs = row.measures.flatMap((m) => m.slices.map((s) => s.x));
|
|
92
|
+
const widths = sung.map((s) => lyricWidth(s.lyric.text));
|
|
93
|
+
const placed = placementsOf(sung, widths);
|
|
94
|
+
sung.forEach((s, i) => {
|
|
95
|
+
const width = widths[i];
|
|
96
|
+
const right = placed[i].x + width / 2;
|
|
97
|
+
const { plain, spans } = readElisions(s.lyric.text);
|
|
98
|
+
out.syllables.push({ eventId: s.eventId, line, text: plain, y, width, ...placed[i] });
|
|
99
|
+
const left = textLeft(placed[i], width);
|
|
100
|
+
for (const span of spans)
|
|
101
|
+
out.elisions.push({ eventId: s.eventId, ...elisionXs(plain, span, left, lyricWidth), y });
|
|
102
|
+
const next = sung[i + 1];
|
|
103
|
+
if (s.lyric.hyphen) {
|
|
104
|
+
const following = next && { measureIndex: next.measureIndex, left: placed[i + 1].x - widths[i + 1] / 2 };
|
|
105
|
+
const x = hyphenX(music, system, { measureIndex: s.measureIndex, right }, following ?? null);
|
|
106
|
+
out.hyphens.push({ eventId: s.eventId, x, y });
|
|
107
|
+
}
|
|
108
|
+
if (s.lyric.extender) {
|
|
109
|
+
const before = pieceXs.filter((x) => x > s.x && (!next || x < next.x));
|
|
110
|
+
const end = (before.at(-1) ?? s.x) + NOTATION.slot / 3;
|
|
111
|
+
if (end > right + 4)
|
|
112
|
+
out.extenders.push({ eventId: s.eventId, x1: right + 2, x2: end, y: y + 4 });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
export function layoutLyrics(music, system, style) {
|
|
117
|
+
const out = { size: style.size, syllables: [], hyphens: [], extenders: [], elisions: [] };
|
|
118
|
+
for (const row of system.rows)
|
|
119
|
+
for (let line = 0; line < row.lyricLines; line++)
|
|
120
|
+
layoutLine(music, row, line, system, style, out);
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { BarlineType, ScoreMusic } from "../schema/types.js";
|
|
2
|
+
import { type SystemLayout } from "./systemLayout.js";
|
|
3
|
+
/**
|
|
4
|
+
* What is written above a system: chord symbols right above the first row, volta brackets
|
|
5
|
+
* (1st / 2nd ending), section labels ("CODA") and the number of the system's first measure
|
|
6
|
+
* (PRD FR-046, FR-048).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A volta bracket from bar line to bar line: `x1` is the centre of the bar line before its first
|
|
10
|
+
* measure (`startBar`; null at the start of a system, where `x1` is the measure's left edge) and
|
|
11
|
+
* `x2` the centre of the bar line that closes its last measure (`endBar`).
|
|
12
|
+
*/
|
|
13
|
+
export type Volta = {
|
|
14
|
+
number: number;
|
|
15
|
+
x1: number;
|
|
16
|
+
x2: number;
|
|
17
|
+
startBar: BarlineType | null;
|
|
18
|
+
endBar: BarlineType;
|
|
19
|
+
openEnd: boolean;
|
|
20
|
+
/** How far it rides up over the dynamics of the bars under it (0 when they have none). */
|
|
21
|
+
lift: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A section label ("Refr :"), starting at `x`. When it opens a system a rule runs from its end to
|
|
25
|
+
* `ruleTo` (the last bar line), as in the reference scores.
|
|
26
|
+
*/
|
|
27
|
+
export type SectionLabel = {
|
|
28
|
+
text: string;
|
|
29
|
+
x: number;
|
|
30
|
+
ruleTo: number | null;
|
|
31
|
+
};
|
|
32
|
+
/** A jump mark ("Fine", "D.C. al Fine"), right-aligned to `x`, the bar line that ends its bar. */
|
|
33
|
+
export type NavigationMark = {
|
|
34
|
+
text: string;
|
|
35
|
+
x: number;
|
|
36
|
+
};
|
|
37
|
+
/** A key change's "1 = F", starting at `x` (ADR 0010). */
|
|
38
|
+
/** "1 = F" at a key change, framed (as the reference engravings do): its text, left edge and text width. */
|
|
39
|
+
export type KeyChangeMark = {
|
|
40
|
+
text: string;
|
|
41
|
+
x: number;
|
|
42
|
+
width: number;
|
|
43
|
+
/** It opens the system: drawn at its left edge, just above the bracket, not in the label band. */
|
|
44
|
+
atBracket: boolean;
|
|
45
|
+
};
|
|
46
|
+
/** A tempo change's "♩ = 60", starting at `x`, in the label band (ADR 0041). */
|
|
47
|
+
export type TempoMark = {
|
|
48
|
+
text: string;
|
|
49
|
+
x: number;
|
|
50
|
+
};
|
|
51
|
+
/** A chord symbol, centred on `x` (its column); `key` is its selection key. */
|
|
52
|
+
export type ChordMark = {
|
|
53
|
+
key: string;
|
|
54
|
+
text: string;
|
|
55
|
+
x: number;
|
|
56
|
+
};
|
|
57
|
+
export type SystemMarkings = {
|
|
58
|
+
voltas: Volta[];
|
|
59
|
+
labels: SectionLabel[];
|
|
60
|
+
navigation: NavigationMark[];
|
|
61
|
+
keys: KeyChangeMark[];
|
|
62
|
+
tempos: TempoMark[];
|
|
63
|
+
chords: ChordMark[];
|
|
64
|
+
/** How far the section labels, tempo marks and key changes ride up to clear what is written under them. */
|
|
65
|
+
bandLift: number;
|
|
66
|
+
/** How far chords and directions reach above the first row (they float; see `layout/floating.ts`). */
|
|
67
|
+
reach: number;
|
|
68
|
+
/** The first measure's number; null on the score's first system. */
|
|
69
|
+
/** `x`: where the number ends (it is right-aligned there). */
|
|
70
|
+
measureNumber: {
|
|
71
|
+
text: string;
|
|
72
|
+
x: number;
|
|
73
|
+
} | null;
|
|
74
|
+
};
|
|
75
|
+
export declare function layoutMarkings(music: ScoreMusic, system: SystemLayout, isLastSystem: boolean): SystemMarkings;
|
|
76
|
+
/** Section label text size; a key change after a label on the same bar starts past it. */
|
|
77
|
+
export declare const LABEL_SIZE = 10;
|
|
78
|
+
/** Size of the "1 = F" text. */
|
|
79
|
+
export declare const KEY_CHANGE_SIZE: number;
|
|
80
|
+
/** Air between "1 = F" and its frame. */
|
|
81
|
+
export declare const KEY_FRAME_PAD: {
|
|
82
|
+
readonly x: 3;
|
|
83
|
+
readonly y: 4;
|
|
84
|
+
};
|
|
85
|
+
/** Size of the "♩ = 60" text: the same as "1 = F". */
|
|
86
|
+
export declare const TEMPO_MARK_SIZE: number;
|
|
87
|
+
/**
|
|
88
|
+
* Air between a chord's text and the first row's top duration line: well past the 2px its box
|
|
89
|
+
* (selection, playing highlight) reaches below the text, so the box stays clear of the line.
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* Where a chord's text sits: its centre line (text is set on its centre), so that the whole text
|
|
93
|
+
* stays above the first row's top duration line.
|
|
94
|
+
*/
|
|
95
|
+
export declare const chordCenter: (headroom: number) => number;
|
|
96
|
+
/** The chords of the system's measures, each at its column (or the measure's start, if none). */
|
|
97
|
+
export declare function chordMarks(music: ScoreMusic, system: SystemLayout): ChordMark[];
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { chordText } from "../notation/chords.js";
|
|
2
|
+
import { NAVIGATION_TEXT } from "../notation/navigation.js";
|
|
3
|
+
import { targetKey } from "../cursor/target.js";
|
|
4
|
+
import { barNumberOf } from "../model/textBars.js";
|
|
5
|
+
import { bandLiftOf, bracketLiftOfBar, reachOf } from "./floating.js";
|
|
6
|
+
import { holdsTick } from "./measureSegments.js";
|
|
7
|
+
import { keyChangeAt } from "../notation/keys.js";
|
|
8
|
+
import { NOTATION, textWidth } from "./notationMetrics.js";
|
|
9
|
+
import { beatX } from "./systemLayout.js";
|
|
10
|
+
/**
|
|
11
|
+
* How far left of the music's start a system's bar number ends (px). The number is right-aligned
|
|
12
|
+
* to that point, so a longer number grows leftwards and never runs into the first note.
|
|
13
|
+
*/
|
|
14
|
+
const MEASURE_NUMBER_NUDGE = 3;
|
|
15
|
+
export function layoutMarkings(music, system, isLastSystem) {
|
|
16
|
+
const voltas = [];
|
|
17
|
+
const labels = [];
|
|
18
|
+
const navigation = [];
|
|
19
|
+
const ruleEnd = system.measures.at(-1)?.barX ?? system.width;
|
|
20
|
+
const keys = keyChangeMarks(music, system);
|
|
21
|
+
const tempos = tempoMarks(music, system);
|
|
22
|
+
system.measures.forEach((bounds, i) => {
|
|
23
|
+
const measure = music.measures[bounds.measureIndex];
|
|
24
|
+
// A split bar's label sits where the bar starts, not over its second part.
|
|
25
|
+
if (bounds.from === 0 && measure.label.trim())
|
|
26
|
+
labels.push({ text: measure.label.trim(), x: bounds.x, ruleTo: i === 0 ? ruleEndFor(bounds.x, [...keys, ...tempos], ruleEnd) : null });
|
|
27
|
+
// A split bar's jump mark waits for the piece that ends the bar.
|
|
28
|
+
if (measure.navigation && bounds.to === null)
|
|
29
|
+
navigation.push({ text: NAVIGATION_TEXT[measure.navigation], x: bounds.barX });
|
|
30
|
+
if (measure.volta === null)
|
|
31
|
+
return;
|
|
32
|
+
const open = voltas.at(-1);
|
|
33
|
+
const previous = system.measures[i - 1];
|
|
34
|
+
const continues = open && previous && music.measures[previous.measureIndex].volta === measure.volta;
|
|
35
|
+
if (continues) {
|
|
36
|
+
open.x2 = bounds.barX;
|
|
37
|
+
open.endBar = measure.barline;
|
|
38
|
+
open.lift = Math.max(open.lift, bracketLiftOfBar(measure));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
voltas.push({
|
|
42
|
+
number: measure.volta,
|
|
43
|
+
x1: previous ? previous.barX : bounds.x,
|
|
44
|
+
x2: bounds.barX,
|
|
45
|
+
startBar: previous ? music.measures[previous.measureIndex].barline : null,
|
|
46
|
+
endBar: measure.barline,
|
|
47
|
+
openEnd: false,
|
|
48
|
+
lift: bracketLiftOfBar(measure),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
// A bracket that runs on into the next system is left open at its end.
|
|
52
|
+
const lastBounds = system.measures.at(-1);
|
|
53
|
+
// A split bar goes on on the next system, and its bracket with it.
|
|
54
|
+
const nextMeasure = lastBounds
|
|
55
|
+
? music.measures[lastBounds.measureIndex + (lastBounds.to === null ? 1 : 0)]
|
|
56
|
+
: undefined;
|
|
57
|
+
const lastVolta = voltas.at(-1);
|
|
58
|
+
if (lastVolta && !isLastSystem && nextMeasure?.volta === lastVolta.number)
|
|
59
|
+
lastVolta.openEnd = true;
|
|
60
|
+
const bars = system.measures.map((m) => music.measures[m.measureIndex]);
|
|
61
|
+
// Brackets of one system stand at one height: all ride up as far as the one that needs it most.
|
|
62
|
+
const bracketLift = Math.max(0, ...voltas.map((v) => v.lift));
|
|
63
|
+
for (const volta of voltas)
|
|
64
|
+
volta.lift = bracketLift;
|
|
65
|
+
const first = system.measures[0];
|
|
66
|
+
const measureNumber = first && first.measureIndex > 0 && first.from === 0
|
|
67
|
+
? { text: String(barNumberOf(music.measures, first.measureIndex)), x: system.left - MEASURE_NUMBER_NUDGE }
|
|
68
|
+
: null;
|
|
69
|
+
return {
|
|
70
|
+
voltas,
|
|
71
|
+
labels,
|
|
72
|
+
navigation,
|
|
73
|
+
keys,
|
|
74
|
+
tempos,
|
|
75
|
+
chords: chordMarks(music, system),
|
|
76
|
+
bandLift: bandLiftOf(bars, labels.length + navigation.length + tempos.length + keys.length > 0),
|
|
77
|
+
reach: reachOf(bars),
|
|
78
|
+
measureNumber,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Section label text size; a key change after a label on the same bar starts past it. */
|
|
82
|
+
export const LABEL_SIZE = 10;
|
|
83
|
+
/** Size of the "1 = F" text. */
|
|
84
|
+
export const KEY_CHANGE_SIZE = LABEL_SIZE + 1;
|
|
85
|
+
/** Air between "1 = F" and its frame. */
|
|
86
|
+
export const KEY_FRAME_PAD = { x: 3, y: 4 };
|
|
87
|
+
const LABEL_GAP = 8;
|
|
88
|
+
/** A section rule stops short of a key change on the same line ("1 = F" sits in the label band). */
|
|
89
|
+
function ruleEndFor(labelX, keys, end) {
|
|
90
|
+
const next = keys.map((k) => k.x).filter((x) => x > labelX && !Number.isNaN(x));
|
|
91
|
+
return next.length ? Math.min(end, Math.min(...next) - 4) : end;
|
|
92
|
+
}
|
|
93
|
+
/** Size of the "♩ = 60" text: the same as "1 = F". */
|
|
94
|
+
export const TEMPO_MARK_SIZE = KEY_CHANGE_SIZE;
|
|
95
|
+
/**
|
|
96
|
+
* "♩ = 60" over every bar that names a tempo, at the start of the bar, after its label and after
|
|
97
|
+
* a key change's frame on the same bar. A split bar's second part has none.
|
|
98
|
+
*/
|
|
99
|
+
function tempoMarks(music, system) {
|
|
100
|
+
return system.measures.flatMap((bounds, index) => {
|
|
101
|
+
const tempo = music.measures[bounds.measureIndex].tempo;
|
|
102
|
+
if (tempo == null || bounds.from !== 0)
|
|
103
|
+
return [];
|
|
104
|
+
const label = music.measures[bounds.measureIndex].label.trim();
|
|
105
|
+
const afterLabel = label ? bounds.x + textWidth(`${label} :`, LABEL_SIZE) * 1.1 + LABEL_GAP : bounds.x;
|
|
106
|
+
const key = keyMarkAt(music, system, index);
|
|
107
|
+
const afterKey = key ? key.x + key.width + KEY_FRAME_PAD.x * 2 + LABEL_GAP : 0;
|
|
108
|
+
return [{ text: `♩ = ${tempo}`, x: Math.max(afterLabel, afterKey) }];
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* "1 = F" over every key change on the system, over its box (or its bar), after any label there.
|
|
113
|
+
* A change the system opens with (its first bar, or the part of a split bar it goes on with)
|
|
114
|
+
* stands at the system's left edge, over the bracket, as in the reference engravings.
|
|
115
|
+
*/
|
|
116
|
+
function keyChangeMarks(music, system) {
|
|
117
|
+
return system.measures.flatMap((_, index) => keyMarkAt(music, system, index) ?? []);
|
|
118
|
+
}
|
|
119
|
+
/** The key change over the system's `index`th measure piece, or null. */
|
|
120
|
+
function keyMarkAt(music, system, index) {
|
|
121
|
+
const bounds = system.measures[index];
|
|
122
|
+
const mark = bounds.keyMark;
|
|
123
|
+
if (!mark)
|
|
124
|
+
return null;
|
|
125
|
+
const label = music.measures[bounds.measureIndex].label.trim();
|
|
126
|
+
const opensSystem = index === 0 && keyChangeAt(music.measures[bounds.measureIndex]) === bounds.from;
|
|
127
|
+
// The frame's left edge lines up with the bracket's.
|
|
128
|
+
const start = opensSystem ? NOTATION.bracketX + KEY_FRAME_PAD.x : mark.x;
|
|
129
|
+
const x = label ? Math.max(start, bounds.x + textWidth(`${label} :`, LABEL_SIZE) * 1.1 + LABEL_GAP) : start;
|
|
130
|
+
const text = `1 = ${mark.key}`;
|
|
131
|
+
// Bold runs a little wider than the plain measure.
|
|
132
|
+
return { text, x, width: textWidth(text, KEY_CHANGE_SIZE) * 1.08, atBracket: opensSystem && !label };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Air between a chord's text and the first row's top duration line: well past the 2px its box
|
|
136
|
+
* (selection, playing highlight) reaches below the text, so the box stays clear of the line.
|
|
137
|
+
*/
|
|
138
|
+
/**
|
|
139
|
+
* Where a chord's text sits: its centre line (text is set on its centre), so that the whole text
|
|
140
|
+
* stays above the first row's top duration line.
|
|
141
|
+
*/
|
|
142
|
+
export const chordCenter = (headroom) => headroom + NOTATION.digitY - NOTATION.durationLineOffset - NOTATION.chordAir - NOTATION.chordSize / 2;
|
|
143
|
+
/** The chords of the system's measures, each at its column (or the measure's start, if none). */
|
|
144
|
+
export function chordMarks(music, system) {
|
|
145
|
+
return system.measures.flatMap((bounds) => (music.measures[bounds.measureIndex].chords ?? []).filter((chord) => holdsTick(bounds, chord.at)).map((chord) => ({
|
|
146
|
+
key: targetKey({ kind: "chord", measureId: bounds.measureId, at: chord.at }),
|
|
147
|
+
text: chordText(chord),
|
|
148
|
+
x: beatX(bounds, chord.at),
|
|
149
|
+
})));
|
|
150
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ScoreMusic } from "../schema/types.js";
|
|
2
|
+
import { type Slice } from "../notation/rhythm.js";
|
|
3
|
+
import { type BarFrame } from "../notation/time.js";
|
|
4
|
+
import type { KeyMark } from "./keyMarks.js";
|
|
5
|
+
import { type LyricMeasure } from "./notationMetrics.js";
|
|
6
|
+
/**
|
|
7
|
+
* Horizontal plan of one measure, shared by all parts so they line up (PRD FR-059, FR-060).
|
|
8
|
+
* Every moment at which some visible part writes a piece gets a column; parts that write
|
|
9
|
+
* nothing at that moment simply leave it empty. A column is as wide as a piece, or as the widest
|
|
10
|
+
* syllable sung at that moment.
|
|
11
|
+
*/
|
|
12
|
+
export type Column = {
|
|
13
|
+
onset: number;
|
|
14
|
+
beat: number;
|
|
15
|
+
minWidth: number;
|
|
16
|
+
/** A syllable here is one word with the next sung syllable (keep the two columns tight). */
|
|
17
|
+
joinsNext: boolean;
|
|
18
|
+
/** Inside a word sung across notes, after its first column: kept tight to the column before. */
|
|
19
|
+
joinedFromPrevious: boolean;
|
|
20
|
+
/** Air before / after the column around a word sung across notes that starts / ends here. */
|
|
21
|
+
padBefore: number;
|
|
22
|
+
padAfter: number;
|
|
23
|
+
/** A tuplet's note after its first: no beat gap before it, so the tuplet stays evenly spaced. */
|
|
24
|
+
inTuplet?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type MeasurePlan = {
|
|
27
|
+
measureIndex: number;
|
|
28
|
+
/** The bar's meter, length and phase (a pickup bar starts late, see `framesOf`). */
|
|
29
|
+
frame: BarFrame;
|
|
30
|
+
/** The written pieces of each part (by part index; hidden parts have none). */
|
|
31
|
+
slices: Slice[][];
|
|
32
|
+
columns: Column[];
|
|
33
|
+
/** Room before the first column (repeat-start sign and padding). */
|
|
34
|
+
lead: number;
|
|
35
|
+
/** Room after the last column (padding and the bar line). */
|
|
36
|
+
tail: number;
|
|
37
|
+
/** The narrowest the measure can be without crowding its notes and syllables. */
|
|
38
|
+
naturalWidth: number;
|
|
39
|
+
/**
|
|
40
|
+
* The narrowest a dragged bar line may squeeze it to: one slot per column and the beat gaps.
|
|
41
|
+
* Only the room its syllables add is given up, so syllables may then touch or overlap.
|
|
42
|
+
*/
|
|
43
|
+
compactWidth: number;
|
|
44
|
+
/** Width its bar line was dragged by (`width_adjust`). */
|
|
45
|
+
adjust: number;
|
|
46
|
+
/**
|
|
47
|
+
* The part of the bar it plans, in ticks from the bar's start: all of it (`from` 0, `to` null)
|
|
48
|
+
* unless the bar is split across two systems (see `measureSegments`).
|
|
49
|
+
*/
|
|
50
|
+
from: number;
|
|
51
|
+
/** Where it stops: null = the bar's end (with its bar line); a tick = it goes on on the next system. */
|
|
52
|
+
to: number | null;
|
|
53
|
+
/** The key change written in its part of the bar, if any (ADR 0010; partway through it, ADR 0017). */
|
|
54
|
+
keyMark: KeyMark | null;
|
|
55
|
+
/**
|
|
56
|
+
* The key change the next part of a split bar opens with, when its box is drawn at the end of
|
|
57
|
+
* this part instead (`KeyMark.boxAbove`, ADR 0017); null otherwise.
|
|
58
|
+
*/
|
|
59
|
+
closingKeyMark?: KeyMark | null;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The width a measure asks for on its system: natural, plus what its bar line was dragged by, but
|
|
63
|
+
* never narrower than compact (the layout never draws it narrower, so the line cannot overrun).
|
|
64
|
+
*/
|
|
65
|
+
export declare const plannedWidth: (plan: Pick<MeasurePlan, "naturalWidth" | "compactWidth" | "adjust">) => number;
|
|
66
|
+
/** The beat gap before a column: none inside a word sung across notes or a tuplet, or within a beat. */
|
|
67
|
+
export declare const gapBefore: (column: Column, previous: Column | undefined) => number;
|
|
68
|
+
/** Columns that take extra room when a system is stretched: not the notes of a joined word. */
|
|
69
|
+
export declare const stretches: (column: Column) => boolean;
|
|
70
|
+
export declare function planMeasure(music: ScoreMusic, measureIndex: number, frame: BarFrame, lyricWidth: LyricMeasure, keyMark?: KeyMark | null): MeasurePlan;
|
|
71
|
+
/** The room a text bar's text takes: its widest line and air either side. */
|
|
72
|
+
export declare function textBarWidth(text: string): number;
|
|
73
|
+
/** The natural and compact widths of columns between a lead and a tail. */
|
|
74
|
+
export declare function widthsOf(lead: number, tail: number, columns: readonly Column[]): Pick<MeasurePlan, "naturalWidth" | "compactWidth">;
|