@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.
Files changed (251) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -2
  3. package/THIRD_PARTY.md +24 -0
  4. package/dist/esm/cursor/activeChord.d.ts +12 -0
  5. package/dist/esm/cursor/activeChord.js +36 -0
  6. package/dist/esm/cursor/beatDot.d.ts +30 -0
  7. package/dist/esm/cursor/beatDot.js +49 -0
  8. package/dist/esm/cursor/drawnTop.d.ts +9 -0
  9. package/dist/esm/cursor/drawnTop.js +16 -0
  10. package/dist/esm/cursor/pageBoxes.d.ts +28 -0
  11. package/dist/esm/cursor/pageBoxes.js +75 -0
  12. package/dist/esm/cursor/playbackCursor.d.ts +25 -0
  13. package/dist/esm/cursor/playbackCursor.js +42 -0
  14. package/dist/esm/cursor/playingStyle.d.ts +16 -0
  15. package/dist/esm/cursor/playingStyle.js +34 -0
  16. package/dist/esm/cursor/playingTones.d.ts +8 -0
  17. package/dist/esm/cursor/playingTones.js +16 -0
  18. package/dist/esm/cursor/target.d.ts +47 -0
  19. package/dist/esm/cursor/target.js +63 -0
  20. package/dist/esm/export/pageText.d.ts +8 -0
  21. package/dist/esm/export/pageText.js +80 -0
  22. package/dist/esm/export/svgExport.d.ts +46 -0
  23. package/dist/esm/export/svgExport.js +88 -0
  24. package/dist/esm/geometry/metrics.d.ts +42 -0
  25. package/dist/esm/geometry/metrics.js +52 -0
  26. package/dist/esm/geometry/pageSetup.d.ts +61 -0
  27. package/dist/esm/geometry/pageSetup.js +85 -0
  28. package/dist/esm/geometry/paper.d.ts +16 -0
  29. package/dist/esm/geometry/paper.js +16 -0
  30. package/dist/esm/index.d.ts +35 -0
  31. package/dist/esm/index.js +23 -0
  32. package/dist/esm/layout/LayoutEngine.d.ts +64 -0
  33. package/dist/esm/layout/LayoutEngine.js +92 -0
  34. package/dist/esm/layout/arcs.d.ts +20 -0
  35. package/dist/esm/layout/arcs.js +53 -0
  36. package/dist/esm/layout/barlineShapes.d.ts +52 -0
  37. package/dist/esm/layout/barlineShapes.js +71 -0
  38. package/dist/esm/layout/directions.d.ts +48 -0
  39. package/dist/esm/layout/directions.js +122 -0
  40. package/dist/esm/layout/elementBoxes.d.ts +17 -0
  41. package/dist/esm/layout/elementBoxes.js +72 -0
  42. package/dist/esm/layout/floating.d.ts +29 -0
  43. package/dist/esm/layout/floating.js +39 -0
  44. package/dist/esm/layout/keyMarks.d.ts +26 -0
  45. package/dist/esm/layout/keyMarks.js +30 -0
  46. package/dist/esm/layout/lyricAlign.d.ts +6 -0
  47. package/dist/esm/layout/lyricAlign.js +15 -0
  48. package/dist/esm/layout/lyricWords.d.ts +13 -0
  49. package/dist/esm/layout/lyricWords.js +27 -0
  50. package/dist/esm/layout/lyricsLayout.d.ts +55 -0
  51. package/dist/esm/layout/lyricsLayout.js +122 -0
  52. package/dist/esm/layout/markings.d.ts +97 -0
  53. package/dist/esm/layout/markings.js +150 -0
  54. package/dist/esm/layout/measurePlan.d.ts +74 -0
  55. package/dist/esm/layout/measurePlan.js +232 -0
  56. package/dist/esm/layout/measureSegments.d.ts +24 -0
  57. package/dist/esm/layout/measureSegments.js +64 -0
  58. package/dist/esm/layout/notationMetrics.d.ts +110 -0
  59. package/dist/esm/layout/notationMetrics.js +122 -0
  60. package/dist/esm/layout/systemBreaking.d.ts +59 -0
  61. package/dist/esm/layout/systemBreaking.js +137 -0
  62. package/dist/esm/layout/systemLayout.d.ts +138 -0
  63. package/dist/esm/layout/systemLayout.js +266 -0
  64. package/dist/esm/layout/tupletSpacing.d.ts +9 -0
  65. package/dist/esm/layout/tupletSpacing.js +33 -0
  66. package/dist/esm/layout/tuplets.d.ts +30 -0
  67. package/dist/esm/layout/tuplets.js +39 -0
  68. package/dist/esm/model/hiddenParts.d.ts +23 -0
  69. package/dist/esm/model/hiddenParts.js +39 -0
  70. package/dist/esm/model/locate.d.ts +18 -0
  71. package/dist/esm/model/locate.js +31 -0
  72. package/dist/esm/model/lowVoices.d.ts +9 -0
  73. package/dist/esm/model/lowVoices.js +20 -0
  74. package/dist/esm/model/partColors.d.ts +13 -0
  75. package/dist/esm/model/partColors.js +10 -0
  76. package/dist/esm/model/partSpan.d.ts +25 -0
  77. package/dist/esm/model/partSpan.js +49 -0
  78. package/dist/esm/model/rowPresence.d.ts +14 -0
  79. package/dist/esm/model/rowPresence.js +19 -0
  80. package/dist/esm/model/sharedLyrics.d.ts +23 -0
  81. package/dist/esm/model/sharedLyrics.js +68 -0
  82. package/dist/esm/model/textBars.d.ts +12 -0
  83. package/dist/esm/model/textBars.js +21 -0
  84. package/dist/esm/model/tickRanges.d.ts +22 -0
  85. package/dist/esm/model/tickRanges.js +34 -0
  86. package/dist/esm/model/unisons.d.ts +69 -0
  87. package/dist/esm/model/unisons.js +181 -0
  88. package/dist/esm/notation/chords.d.ts +12 -0
  89. package/dist/esm/notation/chords.js +29 -0
  90. package/dist/esm/notation/elision.d.ts +24 -0
  91. package/dist/esm/notation/elision.js +47 -0
  92. package/dist/esm/notation/keys.d.ts +50 -0
  93. package/dist/esm/notation/keys.js +59 -0
  94. package/dist/esm/notation/lyricAlign.d.ts +7 -0
  95. package/dist/esm/notation/lyricAlign.js +15 -0
  96. package/dist/esm/notation/navigation.d.ts +3 -0
  97. package/dist/esm/notation/navigation.js +5 -0
  98. package/dist/esm/notation/pitch.d.ts +39 -0
  99. package/dist/esm/notation/pitch.js +74 -0
  100. package/dist/esm/notation/pitchName.d.ts +2 -0
  101. package/dist/esm/notation/pitchName.js +3 -0
  102. package/dist/esm/notation/profile.d.ts +35 -0
  103. package/dist/esm/notation/profile.js +16 -0
  104. package/dist/esm/notation/rhythm.d.ts +59 -0
  105. package/dist/esm/notation/rhythm.js +116 -0
  106. package/dist/esm/notation/time.d.ts +98 -0
  107. package/dist/esm/notation/time.js +85 -0
  108. package/dist/esm/performance/compilePerformance.d.ts +7 -0
  109. package/dist/esm/performance/compilePerformance.js +8 -0
  110. package/dist/esm/performance/dynamics.d.ts +6 -0
  111. package/dist/esm/performance/dynamics.js +78 -0
  112. package/dist/esm/performance/model.d.ts +56 -0
  113. package/dist/esm/performance/model.js +1 -0
  114. package/dist/esm/performance/playOrder.d.ts +16 -0
  115. package/dist/esm/performance/playOrder.js +64 -0
  116. package/dist/esm/performance/readScore.d.ts +4 -0
  117. package/dist/esm/performance/readScore.js +58 -0
  118. package/dist/esm/performance/timeline.d.ts +10 -0
  119. package/dist/esm/performance/timeline.js +144 -0
  120. package/dist/esm/playback/audioOutput.d.ts +46 -0
  121. package/dist/esm/playback/audioOutput.js +106 -0
  122. package/dist/esm/playback/clock.d.ts +16 -0
  123. package/dist/esm/playback/clock.js +44 -0
  124. package/dist/esm/playback/createPlayerStore.d.ts +79 -0
  125. package/dist/esm/playback/createPlayerStore.js +135 -0
  126. package/dist/esm/playback/cues.d.ts +34 -0
  127. package/dist/esm/playback/cues.js +52 -0
  128. package/dist/esm/playback/errors.d.ts +6 -0
  129. package/dist/esm/playback/errors.js +6 -0
  130. package/dist/esm/playback/metronome.d.ts +13 -0
  131. package/dist/esm/playback/metronome.js +15 -0
  132. package/dist/esm/playback/mix.d.ts +9 -0
  133. package/dist/esm/playback/mix.js +8 -0
  134. package/dist/esm/playback/pass.d.ts +27 -0
  135. package/dist/esm/playback/pass.js +36 -0
  136. package/dist/esm/playback/schedule.d.ts +7 -0
  137. package/dist/esm/playback/schedule.js +12 -0
  138. package/dist/esm/playback/session.d.ts +46 -0
  139. package/dist/esm/playback/session.js +107 -0
  140. package/dist/esm/playback/source.d.ts +6 -0
  141. package/dist/esm/playback/source.js +1 -0
  142. package/dist/esm/playback/start.d.ts +28 -0
  143. package/dist/esm/playback/start.js +38 -0
  144. package/dist/esm/playback/timing.d.ts +14 -0
  145. package/dist/esm/playback/timing.js +11 -0
  146. package/dist/esm/playback/types.d.ts +60 -0
  147. package/dist/esm/playback/types.js +1 -0
  148. package/dist/esm/playback/volume.d.ts +12 -0
  149. package/dist/esm/playback/volume.js +8 -0
  150. package/dist/esm/player/ControlBar.d.ts +22 -0
  151. package/dist/esm/player/ControlBar.js +77 -0
  152. package/dist/esm/player/CursorPainter.d.ts +17 -0
  153. package/dist/esm/player/CursorPainter.js +53 -0
  154. package/dist/esm/player/InfoLine.d.ts +6 -0
  155. package/dist/esm/player/InfoLine.js +23 -0
  156. package/dist/esm/player/PageView.d.ts +10 -0
  157. package/dist/esm/player/PageView.js +16 -0
  158. package/dist/esm/player/actions.d.ts +24 -0
  159. package/dist/esm/player/actions.js +26 -0
  160. package/dist/esm/player/balanceSystems.d.ts +8 -0
  161. package/dist/esm/player/balanceSystems.js +18 -0
  162. package/dist/esm/player/createExcerptPlayer.d.ts +33 -0
  163. package/dist/esm/player/createExcerptPlayer.js +169 -0
  164. package/dist/esm/player/createScorePlayer.d.ts +24 -0
  165. package/dist/esm/player/createScorePlayer.js +118 -0
  166. package/dist/esm/player/dom.d.ts +6 -0
  167. package/dist/esm/player/dom.js +15 -0
  168. package/dist/esm/player/embeddedFonts.d.ts +1 -0
  169. package/dist/esm/player/embeddedFonts.js +3 -0
  170. package/dist/esm/player/exclusivePlayback.d.ts +10 -0
  171. package/dist/esm/player/exclusivePlayback.js +13 -0
  172. package/dist/esm/player/followCursor.d.ts +5 -0
  173. package/dist/esm/player/followCursor.js +16 -0
  174. package/dist/esm/player/icons.d.ts +7 -0
  175. package/dist/esm/player/icons.js +9 -0
  176. package/dist/esm/player/injectFonts.d.ts +8 -0
  177. package/dist/esm/player/injectFonts.js +19 -0
  178. package/dist/esm/player/loadExcerpt.d.ts +21 -0
  179. package/dist/esm/player/loadExcerpt.js +123 -0
  180. package/dist/esm/player/loadScore.d.ts +12 -0
  181. package/dist/esm/player/loadScore.js +12 -0
  182. package/dist/esm/player/mountExcerpts.d.ts +30 -0
  183. package/dist/esm/player/mountExcerpts.js +109 -0
  184. package/dist/esm/player/playhead.d.ts +12 -0
  185. package/dist/esm/player/playhead.js +14 -0
  186. package/dist/esm/player/shadowStyles.d.ts +5 -0
  187. package/dist/esm/player/shadowStyles.js +23 -0
  188. package/dist/esm/player/staticSvg.d.ts +7 -0
  189. package/dist/esm/player/staticSvg.js +10 -0
  190. package/dist/esm/player/styles.d.ts +28 -0
  191. package/dist/esm/player/styles.js +98 -0
  192. package/dist/esm/player/theme.d.ts +8 -0
  193. package/dist/esm/player/theme.js +13 -0
  194. package/dist/esm/player/types.d.ts +76 -0
  195. package/dist/esm/player/types.js +12 -0
  196. package/dist/esm/rendering/SystemRenderer.d.ts +6 -0
  197. package/dist/esm/rendering/SystemRenderer.js +58 -0
  198. package/dist/esm/rendering/accidentalRenderer.d.ts +4 -0
  199. package/dist/esm/rendering/accidentalRenderer.js +41 -0
  200. package/dist/esm/rendering/arcRenderer.d.ts +9 -0
  201. package/dist/esm/rendering/arcRenderer.js +32 -0
  202. package/dist/esm/rendering/barlineRenderer.d.ts +8 -0
  203. package/dist/esm/rendering/barlineRenderer.js +59 -0
  204. package/dist/esm/rendering/directionRenderer.d.ts +4 -0
  205. package/dist/esm/rendering/directionRenderer.js +50 -0
  206. package/dist/esm/rendering/durationLineRenderer.d.ts +9 -0
  207. package/dist/esm/rendering/durationLineRenderer.js +27 -0
  208. package/dist/esm/rendering/dynamicGlyphs.d.ts +25 -0
  209. package/dist/esm/rendering/dynamicGlyphs.js +56 -0
  210. package/dist/esm/rendering/frameRenderer.d.ts +17 -0
  211. package/dist/esm/rendering/frameRenderer.js +252 -0
  212. package/dist/esm/rendering/keyMarkRenderer.d.ts +8 -0
  213. package/dist/esm/rendering/keyMarkRenderer.js +57 -0
  214. package/dist/esm/rendering/lyricsRenderer.d.ts +4 -0
  215. package/dist/esm/rendering/lyricsRenderer.js +44 -0
  216. package/dist/esm/rendering/primitives.d.ts +64 -0
  217. package/dist/esm/rendering/primitives.js +1 -0
  218. package/dist/esm/rendering/sliceRenderer.d.ts +19 -0
  219. package/dist/esm/rendering/sliceRenderer.js +79 -0
  220. package/dist/esm/rendering/textBarRenderer.d.ts +8 -0
  221. package/dist/esm/rendering/textBarRenderer.js +28 -0
  222. package/dist/esm/rendering/tupletRenderer.d.ts +7 -0
  223. package/dist/esm/rendering/tupletRenderer.js +42 -0
  224. package/dist/esm/schema/normalize.d.ts +14 -0
  225. package/dist/esm/schema/normalize.js +123 -0
  226. package/dist/esm/schema/pageMeta.d.ts +11 -0
  227. package/dist/esm/schema/pageMeta.js +1 -0
  228. package/dist/esm/schema/scoreJson.d.ts +59 -0
  229. package/dist/esm/schema/scoreJson.js +1 -0
  230. package/dist/esm/schema/scoreView.d.ts +16 -0
  231. package/dist/esm/schema/scoreView.js +24 -0
  232. package/dist/esm/schema/types.d.ts +339 -0
  233. package/dist/esm/schema/types.js +1 -0
  234. package/dist/esm/text/creditLines.d.ts +12 -0
  235. package/dist/esm/text/creditLines.js +11 -0
  236. package/dist/esm/text/fonts.d.ts +50 -0
  237. package/dist/esm/text/fonts.js +98 -0
  238. package/dist/esm/text/headerFooter.d.ts +13 -0
  239. package/dist/esm/text/headerFooter.js +21 -0
  240. package/dist/esm/text/textLines.d.ts +7 -0
  241. package/dist/esm/text/textLines.js +13 -0
  242. package/dist/index.cjs +65 -0
  243. package/dist/index.cjs.map +1 -0
  244. package/dist/nodelyra-player.global.js +65 -0
  245. package/dist/nodelyra-player.global.js.map +1 -0
  246. package/dist/nodelyra-player.lite.global.js +63 -0
  247. package/dist/nodelyra-player.lite.global.js.map +1 -0
  248. package/examples/blog-excerpt.html +54 -0
  249. package/examples/twinkle.html +23 -0
  250. package/examples/twinkle.json +91 -0
  251. package/package.json +70 -4
@@ -0,0 +1,92 @@
1
+ import { pageMetrics, CONTINUATION_TOP_GAP, SMALL_TITLE_HEIGHT, titleBlockHeight, } from "../geometry/metrics.js";
2
+ import { framesOf } from "../notation/time.js";
3
+ import { layoutArcs } from "./arcs.js";
4
+ import { directionBoxes, layoutDirections } from "./directions.js";
5
+ import { elementBoxes } from "./elementBoxes.js";
6
+ import { layoutLyrics } from "./lyricsLayout.js";
7
+ import { layoutMarkings } from "./markings.js";
8
+ import { keyMarksOf } from "./keyMarks.js";
9
+ import { planMeasure } from "./measurePlan.js";
10
+ import { LYRICS_FONTS, DEFAULT_LYRICS_FONT } from "../text/fonts.js";
11
+ import { DEFAULT_LYRIC_SIZE, lyricStyle, NOTATION } from "./notationMetrics.js";
12
+ import { breakSystems } from "./systemBreaking.js";
13
+ import { headroomOf, layoutSystem, musicLeft } from "./systemLayout.js";
14
+ /** Lyrics in the default font and size, for layouts that do not name them. */
15
+ const DEFAULT_LYRICS = lyricStyle(DEFAULT_LYRIC_SIZE, LYRICS_FONTS[DEFAULT_LYRICS_FONT].widthScale);
16
+ /**
17
+ * Room on a page that is not for notation: page 1 holds the page heading (title, info and
18
+ * credits); every later page holds the small running title and keeps `CONTINUATION_TOP_GAP` free
19
+ * under the top margin. The heading and the running title need the title block; the gap does not.
20
+ */
21
+ export function reservedHeight(setup, firstPage, lines) {
22
+ if (firstPage)
23
+ return setup.header.title_block ? titleBlockHeight(setup.header, lines) : 0;
24
+ return CONTINUATION_TOP_GAP + (setup.header.title_block ? SMALL_TITLE_HEIGHT : 0);
25
+ }
26
+ const partsWithMusic = (music) => new Set(music.parts.flatMap((p, i) => (p.measures.some((m) => m.events.length > 0) ? [i] : [])));
27
+ /** Systems of the score at a given width, before they are put on pages (PRD FR-064). */
28
+ export function layoutSystems({ music, time, pickup = 0, lyrics: style = DEFAULT_LYRICS, key = "C" }, width) {
29
+ const frames = framesOf(music, time, pickup);
30
+ const keyMarks = keyMarksOf(music, key);
31
+ const left = musicLeft(music);
32
+ const plans = breakSystems(music.measures.map((_, i) => planMeasure(music, i, frames[i], style.width, keyMarks[i])), music.measures, width - left);
33
+ const sounding = partsWithMusic(music);
34
+ // Every system gets the same room above its first row, the most any system needs (its volta
35
+ // brackets and section labels sit in it), so the space between systems reads evenly.
36
+ const headroom = Math.max(0, ...plans.map((plan) => headroomOf(music, plan)));
37
+ const layouts = plans.map((plan) => layoutSystem(music, plan, width, sounding, left, style.lineHeight, headroom));
38
+ const arcs = layoutArcs(music, layouts);
39
+ const directions = layoutDirections(music, layouts);
40
+ const systems = layouts.map((system, i) => {
41
+ const lyrics = layoutLyrics(music, system, style);
42
+ return {
43
+ ...system,
44
+ arcs: arcs[i],
45
+ directions: directions[i],
46
+ lyrics,
47
+ markings: layoutMarkings(music, system, i === layouts.length - 1),
48
+ boxes: [...elementBoxes(music, system, lyrics), ...directionBoxes(directions[i])],
49
+ };
50
+ });
51
+ return { systems, plans };
52
+ }
53
+ /**
54
+ * Lay the score out on pages (PRD FR-065): a pure function of the music and the page setup, so
55
+ * the editor canvas, the printed PDF and the SVG export break at the same places. Pages break
56
+ * between systems, or where a measure asks for a page break. An empty score still has one page.
57
+ */
58
+ export function paginate(input, setup, options = {}) {
59
+ const m = pageMetrics(setup);
60
+ const lines = {
61
+ titleLines: options.titleLines ?? 1,
62
+ subtitleLines: options.subtitleLines ?? 0,
63
+ };
64
+ // Lay out at the base note size, `scale` times smaller than the page, and draw it scaled.
65
+ const scale = setup.note_size / NOTATION.digitSize;
66
+ const lyrics = input.lyrics ??
67
+ lyricStyle(setup.lyric_size / scale, LYRICS_FONTS[setup.lyrics_font].widthScale);
68
+ const { systems, plans } = layoutSystems({ ...input, lyrics }, m.contentWidth / scale);
69
+ const pages = [{ systems: [] }];
70
+ let y = 0;
71
+ const available = () => m.contentHeight - reservedHeight(setup, pages.length === 1, lines);
72
+ systems.forEach((system, i) => {
73
+ const page = pages[pages.length - 1];
74
+ const height = system.height * scale;
75
+ const top = page.systems.length === 0 ? 0 : y + setup.system_spacing * scale;
76
+ if (page.systems.length > 0 && top + height > available()) {
77
+ pages.push({ systems: [{ ...system, y: 0, scale, bracket: setup.system_bracket, lowVoicesUp: setup.low_voices_octave_up }] });
78
+ y = height;
79
+ }
80
+ else {
81
+ page.systems.push({ ...system, y: top, scale, bracket: setup.system_bracket, lowVoicesUp: setup.low_voices_octave_up });
82
+ y = top + height;
83
+ }
84
+ if (plans[i].pageBreakAfter && i < systems.length - 1) {
85
+ pages.push({ systems: [] });
86
+ y = 0;
87
+ }
88
+ });
89
+ return pages;
90
+ }
91
+ /** Height of a page's notation (its last system's bottom), in page px. */
92
+ export const notationHeight = (page) => page.systems.reduce((h, s) => Math.max(h, s.y + s.height * s.scale), 0);
@@ -0,0 +1,20 @@
1
+ import type { ScoreMusic } from "../schema/types.js";
2
+ import type { SystemLayout } from "./systemLayout.js";
3
+ /**
4
+ * Tie and slur geometry (PRD FR-063). An arc joins two note heads of one part. When its notes are
5
+ * on different systems it is drawn in two halves: open at the end of the first system and open at
6
+ * the start of the next one.
7
+ */
8
+ export type Arc = {
9
+ kind: "tie" | "slur";
10
+ /** The tie's first note id, or the slur id: what selecting/deleting the arc acts on. */
11
+ owner: string;
12
+ x1: number;
13
+ x2: number;
14
+ /** Where the arc starts and ends vertically (it curves away from the notes from here). */
15
+ y: number;
16
+ openStart: boolean;
17
+ openEnd: boolean;
18
+ };
19
+ /** The arcs of every system, by system index. */
20
+ export declare function layoutArcs(music: ScoreMusic, systems: readonly SystemLayout[]): Arc[][];
@@ -0,0 +1,53 @@
1
+ import { NOTATION } from "./notationMetrics.js";
2
+ function headIndex(systems) {
3
+ const heads = new Map();
4
+ systems.forEach((system, index) => system.rows.forEach((row) => row.measures.forEach((m) => m.slices.forEach((s) => {
5
+ if (s.head)
6
+ heads.set(s.eventId, { system: index, x: s.x, y: row.noteY + NOTATION.arcOffset });
7
+ }))));
8
+ return heads;
9
+ }
10
+ /** Note pairs to connect: ties (a note to the next note of its part) and slurs. */
11
+ function connections(music) {
12
+ const pairs = [];
13
+ for (const part of music.parts) {
14
+ const events = part.measures.flatMap((m) => m.events);
15
+ events.forEach((e, i) => {
16
+ const next = events[i + 1];
17
+ if (e.type === "note" && e.tie && next?.type === "note")
18
+ pairs.push({ kind: "tie", owner: e.id, from: e.id, to: next.id });
19
+ });
20
+ for (const slur of part.slurs)
21
+ pairs.push({ kind: "slur", owner: slur.id, from: slur.start, to: slur.end });
22
+ }
23
+ return pairs;
24
+ }
25
+ /** Room left between an arc that continues on the next system and the closing bar line. */
26
+ const BAR_CLEARANCE = 3;
27
+ /**
28
+ * Where an arc that continues on the next system stops: just before the system's last bar line,
29
+ * which sits at the right margin, so the arc never runs past the music.
30
+ */
31
+ function systemEnd(system) {
32
+ const last = system.measures.at(-1);
33
+ return (last ? last.barX : system.width) - BAR_CLEARANCE;
34
+ }
35
+ /** The arcs of every system, by system index. */
36
+ export function layoutArcs(music, systems) {
37
+ const heads = headIndex(systems);
38
+ const arcs = systems.map(() => []);
39
+ for (const { kind, owner, from, to } of connections(music)) {
40
+ const a = heads.get(from);
41
+ const b = heads.get(to);
42
+ if (!a || !b)
43
+ continue; // a hidden part draws nothing
44
+ const base = { kind, owner, openStart: false, openEnd: false };
45
+ if (a.system === b.system) {
46
+ arcs[a.system].push({ ...base, x1: a.x, x2: b.x, y: a.y });
47
+ continue;
48
+ }
49
+ arcs[a.system].push({ ...base, x1: a.x, x2: systemEnd(systems[a.system]), y: a.y, openEnd: true });
50
+ arcs[b.system].push({ ...base, x1: systems[b.system].left, x2: b.x, y: b.y, openStart: true });
51
+ }
52
+ return arcs;
53
+ }
@@ -0,0 +1,52 @@
1
+ import type { BarlineType, ScoreMusic } from "../schema/types.js";
2
+ export type Stroke = {
3
+ dx: number;
4
+ width: number;
5
+ };
6
+ /**
7
+ * `throughLyrics`: joins the next part's bar line even across lyrics (final and repeat bars).
8
+ * Repeat dots are drawn once per system, in the middle of the whole bar (the reference's `:`).
9
+ */
10
+ export type BarShape = {
11
+ strokes: Stroke[];
12
+ dots?: number;
13
+ throughLyrics?: boolean;
14
+ };
15
+ /**
16
+ * Every kind of bar line as data (PRD FR-044..FR-046): strokes relative to the bar centre, and
17
+ * repeat dots to the left (negative) or right (positive). A new kind is a new entry.
18
+ */
19
+ export declare const BARLINE_SHAPES: Record<BarlineType, BarShape>;
20
+ /**
21
+ * How a measure's repeat start is written: `sign` is the thick + thin bar with its dots; at the
22
+ * start of a system, where the system bracket already opens the music, only the dots (`dots`).
23
+ */
24
+ export type RepeatStart = "none" | "sign" | "dots";
25
+ export declare const REPEAT_START_SHAPES: Record<RepeatStart, BarShape | null>;
26
+ /** The repeat start a measure gets, given whether it opens its system. */
27
+ export declare function repeatStartOf(repeatStart: boolean, opensSystem: boolean): RepeatStart;
28
+ /**
29
+ * The bar line actually drawn at the end of a measure: a plain single bar line gives way to a
30
+ * repeat-start sign that follows it on the same system (the sign is the bar line there), so the
31
+ * two never stack into a triple line. Any other kind is kept (`:||:` keeps both signs).
32
+ */
33
+ export declare function closingBarline(barline: BarlineType, nextStartsRepeat: boolean): BarlineType;
34
+ /** How far a bar line's strokes reach left and right of its centre (px). */
35
+ export declare function barlineEdges(barline: BarlineType): {
36
+ left: number;
37
+ right: number;
38
+ };
39
+ /** A measure (or part of a split bar, ADR 0008) on a system, as the bar lines around it see it. */
40
+ type PlacedBar = {
41
+ measureIndex: number;
42
+ from: number;
43
+ to: number | null;
44
+ };
45
+ /**
46
+ * The bar line drawn after the system's measure `i`: none after a bar's first part (the bar goes
47
+ * on on the next system), else its own, which gives way to a repeat start right after it.
48
+ */
49
+ export declare function drawnBarline(music: ScoreMusic, measures: readonly PlacedBar[], i: number): BarlineType;
50
+ /** The repeat start drawn at the system's measure `i`: only where its bar starts. */
51
+ export declare const drawnRepeatStart: (music: ScoreMusic, measures: readonly PlacedBar[], i: number) => RepeatStart;
52
+ export {};
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The geometry of bar lines, shared by the layout (what a measure's interior is) and the renderer
3
+ * (what is drawn). Pure data and arithmetic: no drawing here.
4
+ */
5
+ const THIN = 1;
6
+ const THICK = 2.6;
7
+ /**
8
+ * Every kind of bar line as data (PRD FR-044..FR-046): strokes relative to the bar centre, and
9
+ * repeat dots to the left (negative) or right (positive). A new kind is a new entry.
10
+ */
11
+ export const BARLINE_SHAPES = {
12
+ single: { strokes: [{ dx: 0, width: THIN }] },
13
+ double: { strokes: [{ dx: -1.8, width: THIN }, { dx: 1.8, width: THIN }] },
14
+ final: {
15
+ strokes: [{ dx: -2.4, width: THIN }, { dx: 1.6, width: THICK }],
16
+ throughLyrics: true,
17
+ },
18
+ repeat_end: {
19
+ strokes: [{ dx: -1.2, width: THIN }, { dx: 2.4, width: THICK }],
20
+ dots: -5,
21
+ throughLyrics: true,
22
+ },
23
+ none: { strokes: [] },
24
+ };
25
+ export const REPEAT_START_SHAPES = {
26
+ none: null,
27
+ sign: {
28
+ strokes: [{ dx: -2.4, width: THICK }, { dx: 1.6, width: THIN }],
29
+ dots: 5,
30
+ throughLyrics: true,
31
+ },
32
+ dots: { strokes: [], dots: 0 },
33
+ };
34
+ /** The repeat start a measure gets, given whether it opens its system. */
35
+ export function repeatStartOf(repeatStart, opensSystem) {
36
+ if (!repeatStart)
37
+ return "none";
38
+ return opensSystem ? "dots" : "sign";
39
+ }
40
+ /**
41
+ * The bar line actually drawn at the end of a measure: a plain single bar line gives way to a
42
+ * repeat-start sign that follows it on the same system (the sign is the bar line there), so the
43
+ * two never stack into a triple line. Any other kind is kept (`:||:` keeps both signs).
44
+ */
45
+ export function closingBarline(barline, nextStartsRepeat) {
46
+ return barline === "single" && nextStartsRepeat ? "none" : barline;
47
+ }
48
+ /** How far a bar line's strokes reach left and right of its centre (px). */
49
+ export function barlineEdges(barline) {
50
+ const strokes = BARLINE_SHAPES[barline].strokes;
51
+ if (strokes.length === 0)
52
+ return { left: 0, right: 0 };
53
+ return {
54
+ left: Math.min(...strokes.map((s) => s.dx - s.width / 2)),
55
+ right: Math.max(...strokes.map((s) => s.dx + s.width / 2)),
56
+ };
57
+ }
58
+ /**
59
+ * The bar line drawn after the system's measure `i`: none after a bar's first part (the bar goes
60
+ * on on the next system), else its own, which gives way to a repeat start right after it.
61
+ */
62
+ export function drawnBarline(music, measures, i) {
63
+ const bar = measures[i];
64
+ if (bar.to !== null)
65
+ return "none";
66
+ const next = measures[i + 1];
67
+ const nextStartsRepeat = next ? next.from === 0 && music.measures[next.measureIndex].repeat_start : false;
68
+ return closingBarline(music.measures[bar.measureIndex].barline, nextStartsRepeat);
69
+ }
70
+ /** The repeat start drawn at the system's measure `i`: only where its bar starts. */
71
+ export const drawnRepeatStart = (music, measures, i) => repeatStartOf(measures[i].from === 0 && music.measures[measures[i].measureIndex].repeat_start, i === 0);
@@ -0,0 +1,48 @@
1
+ import type { ScoreMusic } from "../schema/types.js";
2
+ import type { ElementBox } from "./elementBoxes.js";
3
+ import type { SystemLayout } from "./systemLayout.js";
4
+ /**
5
+ * Directions above the system (ADR 0011): dynamics ("mp"), expression text ("sotto voce") and
6
+ * hairpins, floating over the beat lines. A hairpin that runs on to a later system is drawn
7
+ * in parts, open where it goes on, as ties are.
8
+ */
9
+ type Unlifted = {
10
+ kind: "dynamic";
11
+ key: string;
12
+ x: number;
13
+ text: string;
14
+ } | {
15
+ kind: "text";
16
+ key: string;
17
+ x: number;
18
+ text: string;
19
+ } | {
20
+ kind: "hairpin";
21
+ key: string;
22
+ x1: number;
23
+ x2: number;
24
+ shape: "cresc" | "dim";
25
+ openStart: boolean;
26
+ openEnd: boolean;
27
+ };
28
+ /** `lift`: how far it rides above its baseline to clear a chord it meets (0: it meets none). */
29
+ export type PlacedDirection = Unlifted & {
30
+ lift: number;
31
+ };
32
+ /** One system's directions and the baseline they sit on (system coordinates). */
33
+ export type SystemDirections = {
34
+ y: number;
35
+ items: PlacedDirection[];
36
+ };
37
+ /**
38
+ * Where a direction rests: over the beat lines (the first, longest duration line is
39
+ * `durationLineOffset` above the digits), over the first row's bar lines, and above a chord it
40
+ * meets (see `CHORD_LIFT`). It floats: no room is kept for it, so directions never move the notation, the chords or
41
+ * the space between systems; they are drawn over whatever is above the row.
42
+ */
43
+ export declare const directionBaseline: (headroom: number) => number;
44
+ /** Every system's directions, by system index. */
45
+ export declare function layoutDirections(music: ScoreMusic, systems: readonly SystemLayout[]): SystemDirections[];
46
+ /** A box around each direction (a hairpin's parts share its key), above the selection overlay's notes. */
47
+ export declare function directionBoxes({ y: baseline, items }: SystemDirections): ElementBox[];
48
+ export {};
@@ -0,0 +1,122 @@
1
+ import { targetKey } from "../cursor/target.js";
2
+ import { dynamicBox, dynamicWidth, DESCENT_EM } from "../rendering/dynamicGlyphs.js";
3
+ import { CHORD_LIFT, hiddenByChord } from "./floating.js";
4
+ import { chordMarks } from "./markings.js";
5
+ import { holdsTick } from "./measureSegments.js";
6
+ import { NOTATION, textWidth } from "./notationMetrics.js";
7
+ /**
8
+ * Where a direction rests: over the beat lines (the first, longest duration line is
9
+ * `durationLineOffset` above the digits), over the first row's bar lines, and above a chord it
10
+ * meets (see `CHORD_LIFT`). It floats: no room is kept for it, so directions never move the notation, the chords or
11
+ * the space between systems; they are drawn over whatever is above the row.
12
+ */
13
+ export const directionBaseline = (headroom) => headroom + NOTATION.digitY - NOTATION.durationLineOffset - NOTATION.beatLineGap - DESCENT_EM * NOTATION.dynamicSize;
14
+ const keyOf = (measureId, d) => targetKey({ kind: "direction", measureId, at: d.at, type: d.type });
15
+ function spotOf(systems, measureId, at) {
16
+ for (const [system, layout] of systems.entries()) {
17
+ const bounds = layout.measures.find((m) => m.measureId === measureId && holdsTick(m, at));
18
+ if (bounds)
19
+ return { system, x: xOf(bounds, at) };
20
+ }
21
+ // Past the last column of the bar (a hairpin to its end): where its last part ends.
22
+ for (const [system, layout] of systems.entries().toArray().toReversed()) {
23
+ const bounds = layout.measures.find((m) => m.measureId === measureId);
24
+ if (bounds)
25
+ return { system, x: bounds.barX - NOTATION.measurePad };
26
+ }
27
+ return null;
28
+ }
29
+ /** A column's centre, or the start of the bar's music when no column sits at `at`. */
30
+ const xOf = (bounds, at) => bounds.centers.get(at) ?? (at > 0 ? bounds.barX - NOTATION.measurePad : bounds.x + NOTATION.measurePad + NOTATION.slot / 2);
31
+ /** Air between a dynamic and a hairpin that starts or ends at it. */
32
+ const DYNAMIC_GAP = 3;
33
+ const dynamicHalf = (level) => dynamicWidth(level, NOTATION.dynamicSize) / 2 + DYNAMIC_GAP;
34
+ /** The dynamic drawn at a spot, if any: a hairpin starts after it and ends before it. */
35
+ function dynamicAt(music, measureId, at) {
36
+ const measure = music.measures.find((m) => m.id === measureId);
37
+ if (hiddenByChord(measure, at))
38
+ return null;
39
+ const found = (measure?.directions ?? []).find((d) => d.type === "dynamic" && d.at === at);
40
+ return found?.type === "dynamic" ? found.level : null;
41
+ }
42
+ /** A hairpin's parts, one per system it reaches, clear of the dynamics at its ends. */
43
+ function placeHairpin(music, systems, measureId, hairpin, out) {
44
+ const from = spotOf(systems, measureId, hairpin.at);
45
+ const to = spotOf(systems, hairpin.end.measure, hairpin.end.at);
46
+ if (!from || !to || to.system < from.system)
47
+ return;
48
+ const startDynamic = dynamicAt(music, measureId, hairpin.at);
49
+ const endDynamic = dynamicAt(music, hairpin.end.measure, hairpin.end.at);
50
+ const x1 = from.x + (startDynamic ? dynamicHalf(startDynamic) : 0);
51
+ const x2 = to.x - (endDynamic ? dynamicHalf(endDynamic) : 0);
52
+ const key = keyOf(measureId, hairpin);
53
+ for (let system = from.system; system <= to.system; system++) {
54
+ const layout = systems[system];
55
+ const last = layout.measures.at(-1);
56
+ out[system].push({
57
+ kind: "hairpin",
58
+ key,
59
+ shape: hairpin.shape,
60
+ x1: system === from.system ? x1 : layout.left,
61
+ x2: system === to.system ? x2 : (last?.barX ?? layout.width) - NOTATION.measurePad,
62
+ openStart: system !== from.system,
63
+ openEnd: system !== to.system,
64
+ });
65
+ }
66
+ }
67
+ /** Every system's directions, by system index. */
68
+ export function layoutDirections(music, systems) {
69
+ const out = systems.map(() => []);
70
+ for (const measure of music.measures)
71
+ for (const direction of measure.directions ?? []) {
72
+ if (direction.type === "hairpin") {
73
+ placeHairpin(music, systems, measure.id, direction, out);
74
+ continue;
75
+ }
76
+ if (direction.type === "dynamic" && hiddenByChord(measure, direction.at))
77
+ continue;
78
+ const spot = spotOf(systems, measure.id, direction.at);
79
+ if (!spot)
80
+ continue;
81
+ const key = keyOf(measure.id, direction);
82
+ out[spot.system].push(direction.type === "dynamic"
83
+ ? { kind: "dynamic", key, x: spot.x, text: direction.level }
84
+ : { kind: "text", key, x: spot.x - NOTATION.slot / 2, text: direction.text });
85
+ }
86
+ return systems.map((system, i) => {
87
+ const chords = chordSpans(music, system);
88
+ return {
89
+ y: directionBaseline(system.headroom),
90
+ items: out[i].map((item) => ({ ...item, lift: meetsChord(extentOf(item), chords) ? CHORD_LIFT : 0 })),
91
+ };
92
+ });
93
+ }
94
+ /** The width each chord's text takes, centred on its column. */
95
+ const chordSpans = (music, system) => chordMarks(music, system).map((chord) => {
96
+ const half = (textWidth(chord.text, NOTATION.chordSize) * 1.1) / 2;
97
+ return [chord.x - half, chord.x + half];
98
+ });
99
+ /** Where a direction is drawn along the row. */
100
+ function extentOf(item) {
101
+ if (item.kind === "hairpin")
102
+ return [item.x1, item.x2];
103
+ if (item.kind === "text")
104
+ return [item.x - 2, item.x - 2 + textWidth(item.text, NOTATION.expressionSize) * 1.1 + 4];
105
+ const half = dynamicWidth(item.text, NOTATION.dynamicSize) / 2;
106
+ return [item.x - half, item.x + half];
107
+ }
108
+ const meetsChord = ([left, right], chords) => chords.some(([from, to]) => left < to + DYNAMIC_GAP && from - DYNAMIC_GAP < right);
109
+ /** A box around each direction (a hairpin's parts share its key), above the selection overlay's notes. */
110
+ export function directionBoxes({ y: baseline, items }) {
111
+ const height = NOTATION.dynamicSize + 4;
112
+ return items.map((item) => {
113
+ const y = baseline - item.lift;
114
+ const top = y - NOTATION.dynamicSize;
115
+ if (item.kind === "hairpin")
116
+ return { key: item.key, x: item.x1, y: top, width: Math.max(NOTATION.slot, item.x2 - item.x1), height };
117
+ if (item.kind === "dynamic")
118
+ return { key: item.key, ...dynamicBox(item.text, item.x, y, NOTATION.dynamicSize) };
119
+ const width = Math.max(NOTATION.slot, textWidth(item.text, NOTATION.expressionSize) * 1.1 + 4);
120
+ return { key: item.key, x: item.x - 2, y: top, width, height };
121
+ });
122
+ }
@@ -0,0 +1,17 @@
1
+ import type { ScoreMusic } from "../schema/types.js";
2
+ import type { SystemLyrics } from "./lyricsLayout.js";
3
+ import type { SystemLayout } from "./systemLayout.js";
4
+ /**
5
+ * The selectable area of every editable element on a system (PRD §7.6 LayoutElement): a part's
6
+ * measure, a note or rest, a syllable, a chord symbol. Keys are selection keys. Boxes drive clicking, the
7
+ * selection overlay, rectangle selection and inline editors; they are never exported.
8
+ * Order matters: later boxes sit on top (measure < event < syllable < chord).
9
+ */
10
+ export type ElementBox = {
11
+ key: string;
12
+ x: number;
13
+ y: number;
14
+ width: number;
15
+ height: number;
16
+ };
17
+ export declare function elementBoxes(music: ScoreMusic, system: SystemLayout, lyrics: SystemLyrics): ElementBox[];
@@ -0,0 +1,72 @@
1
+ import { targetKey } from "../cursor/target.js";
2
+ import { barlineEdges, drawnBarline, drawnRepeatStart, REPEAT_START_SHAPES } from "./barlineShapes.js";
3
+ import { drawnIn } from "../model/rowPresence.js";
4
+ import { chordCenter, chordMarks } from "./markings.js";
5
+ import { NOTATION, textWidth } from "./notationMetrics.js";
6
+ /**
7
+ * Air kept between a measure's box and the bar lines around it, so its outline never touches them:
8
+ * after what opens the measure, and (a little more, where the outline met the bar line most) before
9
+ * its closing bar line.
10
+ */
11
+ const BAR_CLEARANCE_LEFT = 2;
12
+ const BAR_CLEARANCE_RIGHT = 4;
13
+ /**
14
+ * Where a measure's interior runs: from just right of what is drawn at its start (the previous
15
+ * measure's bar line, or its own repeat-start sign) to just left of its closing bar line. The
16
+ * measure box (selection, problem marks, clicks) stays inside its bar lines.
17
+ */
18
+ function measureInterior(music, measures, i) {
19
+ const bounds = measures[i];
20
+ const previous = measures[i - 1];
21
+ const afterBar = previous ? previous.barX + barlineEdges(drawnBarline(music, measures, i - 1)).right : bounds.x;
22
+ const sign = REPEAT_START_SHAPES[drawnRepeatStart(music, measures, i)];
23
+ const signX = bounds.x + NOTATION.repeatStartWidth / 2;
24
+ const afterSign = sign && sign.strokes.length ? signX + Math.max(...sign.strokes.map((s) => s.dx + s.width / 2)) : bounds.x;
25
+ const left = Math.max(afterBar, afterSign) + (previous || sign ? BAR_CLEARANCE_LEFT : 0);
26
+ const right = bounds.barX + barlineEdges(drawnBarline(music, measures, i)).left - BAR_CLEARANCE_RIGHT;
27
+ return { x: left, width: Math.max(0, right - left) };
28
+ }
29
+ export function elementBoxes(music, system, lyrics) {
30
+ const measureBoxes = [];
31
+ const eventBoxes = [];
32
+ for (const row of system.rows) {
33
+ const partId = music.parts[row.partIndex].id;
34
+ system.measures.forEach((bounds, i) => {
35
+ // Nothing to select or write outside the bars a part plays, or where it is merged or hidden.
36
+ if (!drawnIn(music, music.parts[row.partIndex], bounds.measureIndex))
37
+ return;
38
+ measureBoxes.push({
39
+ key: targetKey({ kind: "measure", partId, measureId: bounds.measureId }),
40
+ ...measureInterior(music, system.measures, i),
41
+ y: row.y,
42
+ height: NOTATION.noteRowHeight,
43
+ });
44
+ });
45
+ for (const m of row.measures)
46
+ for (const s of m.slices)
47
+ if (s.head)
48
+ eventBoxes.push({
49
+ key: targetKey({ kind: "event", eventId: s.eventId }),
50
+ x: s.x - NOTATION.slot / 2,
51
+ y: row.y + 2,
52
+ width: NOTATION.slot,
53
+ height: NOTATION.noteRowHeight - 4,
54
+ });
55
+ }
56
+ const lyricBoxes = lyrics.syllables.map((s) => ({
57
+ key: targetKey({ kind: "lyric", eventId: s.eventId, line: s.line }),
58
+ x: s.x - Math.max(s.width, NOTATION.slot) / 2,
59
+ y: s.y - system.lyricLineHeight / 2,
60
+ width: Math.max(s.width, NOTATION.slot),
61
+ height: system.lyricLineHeight,
62
+ }));
63
+ return [...measureBoxes, ...eventBoxes, ...lyricBoxes, ...chordBoxes(music, system)];
64
+ }
65
+ /** A box around each chord symbol, over its text above the first row. */
66
+ function chordBoxes(music, system) {
67
+ const top = chordCenter(system.headroom) - NOTATION.chordSize / 2 - 2;
68
+ return chordMarks(music, system).map((chord) => {
69
+ const width = Math.max(NOTATION.slot, textWidth(chord.text, NOTATION.chordSize) + 4);
70
+ return { key: chord.key, x: chord.x - width / 2, y: top, width, height: NOTATION.chordSize + 4 };
71
+ });
72
+ }
@@ -0,0 +1,29 @@
1
+ import type { ScoreMeasure } from "../schema/types.js";
2
+ /**
3
+ * What floats above a row and how far it reaches (px above the row's top). Chords and directions
4
+ * are drawn right over the beat lines and keep no room of their own, so nothing else moves for
5
+ * them: a direction rides above a chord only where the two meet, and a volta bracket or a section
6
+ * label rides up only over the bars that have something under it. Reaches here are per bar (a
7
+ * bar's chords and directions), a safe upper bound that can be known before the system is laid out.
8
+ */
9
+ type Bar = Pick<ScoreMeasure, "volta" | "directions" | "chords">;
10
+ /** How far a chord's text reaches above the row. */
11
+ export declare const CHORD_REACH: number;
12
+ /** How far a dynamic reaches above the row when nothing is under it. */
13
+ export declare const DYNAMIC_REACH: number;
14
+ /** How far a direction rides up to clear a chord it meets. */
15
+ export declare const CHORD_LIFT: number;
16
+ /** A chord and a dynamic on the same beat: the chord is drawn, the dynamic is not (it stays in the score). */
17
+ export declare const hiddenByChord: (bar: Pick<Bar, "chords"> | undefined, at: number) => boolean;
18
+ /** How far what is written in a bar reaches above the row (0: nothing). */
19
+ export declare const barReach: (bar: Bar) => number;
20
+ /** How far a volta bracket rides up over its bar: 0 when nothing is written there. */
21
+ export declare const bracketLiftOfBar: (bar: Bar) => number;
22
+ /** The most any of the bars reaches. */
23
+ export declare const reachOf: (bars: readonly Bar[]) => number;
24
+ /**
25
+ * How far a system's upper bands ride up, and so the room it keeps above them: its brackets by
26
+ * the most any needs, its labels (when it has any) to clear whatever is written under them.
27
+ */
28
+ export declare function bandLiftOf(bars: readonly Bar[], hasLabels: boolean): number;
29
+ export {};
@@ -0,0 +1,39 @@
1
+ import { ASCENT_EM, DESCENT_EM } from "../rendering/dynamicGlyphs.js";
2
+ import { NOTATION } from "./notationMetrics.js";
3
+ /** The first row's top duration line, below the row's top by this much. */
4
+ const BEAT_LINE = NOTATION.digitY - NOTATION.durationLineOffset;
5
+ /** Air kept between floating things, and above the last one before a bracket or label. */
6
+ const AIR = 2;
7
+ /** How far a chord's text reaches above the row. */
8
+ export const CHORD_REACH = NOTATION.chordSize + NOTATION.chordAir - BEAT_LINE;
9
+ /** How far a dynamic reaches above the row when nothing is under it. */
10
+ export const DYNAMIC_REACH = (ASCENT_EM + DESCENT_EM) * NOTATION.dynamicSize + NOTATION.beatLineGap - BEAT_LINE;
11
+ /** How far a direction rides up to clear a chord it meets. */
12
+ export const CHORD_LIFT = CHORD_REACH + BEAT_LINE;
13
+ const hasChords = (bar) => (bar.chords ?? []).length > 0;
14
+ /** A chord and a dynamic on the same beat: the chord is drawn, the dynamic is not (it stays in the score). */
15
+ export const hiddenByChord = (bar, at) => (bar?.chords ?? []).some((chord) => chord.at === at);
16
+ /** Whether the bar draws any direction (a dynamic hidden by a chord leaves no mark, so no room). */
17
+ const hasDirections = (bar) => (bar.directions ?? []).some((d) => d.type !== "dynamic" || !hiddenByChord(bar, d.at));
18
+ /** How far what is written in a bar reaches above the row (0: nothing). */
19
+ export const barReach = (bar) => Math.max(hasChords(bar) ? CHORD_REACH : 0, hasDirections(bar) ? DYNAMIC_REACH + (hasChords(bar) ? CHORD_LIFT : 0) : 0);
20
+ /** How far a volta bracket rides up over its bar: 0 when nothing is written there. */
21
+ export const bracketLiftOfBar = (bar) => bar.volta !== null
22
+ ? Math.max(0, barReach(bar) + AIR + NOTATION.voltaRadius - NOTATION.voltaRise)
23
+ : 0;
24
+ /** The most any of the bars reaches. */
25
+ export const reachOf = (bars) => Math.max(0, ...bars.map(barReach));
26
+ /** Where a section label, tempo or key change stands, above the (raised) brackets when there are any. */
27
+ const LABEL_HALF = 5;
28
+ const LABEL_OFFSET = 10; // below the bracket band's top: no bracket
29
+ const LABEL_OFFSET_OVER_BRACKETS = LABEL_OFFSET + NOTATION.headroom;
30
+ /**
31
+ * How far a system's upper bands ride up, and so the room it keeps above them: its brackets by
32
+ * the most any needs, its labels (when it has any) to clear whatever is written under them.
33
+ */
34
+ export function bandLiftOf(bars, hasLabels) {
35
+ const brackets = Math.max(0, ...bars.map(bracketLiftOfBar));
36
+ const base = bars.some((bar) => bar.volta !== null) ? LABEL_OFFSET_OVER_BRACKETS : LABEL_OFFSET;
37
+ const labels = hasLabels ? Math.max(0, reachOf(bars) + AIR + LABEL_HALF - base) : 0;
38
+ return Math.max(brackets, labels);
39
+ }
@@ -0,0 +1,26 @@
1
+ import type { ScoreMusic } from "../schema/types.js";
2
+ import type { Spelling } from "../notation/pitch.js";
3
+ /**
4
+ * What a key change writes (ADR 0010): "1 = F" above where it takes over and, unless the bar
5
+ * hides it, a box before the notes from there with each part's last note before the change, in
6
+ * the old key and as the same pitch in the new one ("5 → 3"), so singers can find the new 1. A
7
+ * change partway through a bar (ADR 0017) takes over at `at`.
8
+ */
9
+ export type Pivot = {
10
+ from: Spelling;
11
+ to: Spelling;
12
+ };
13
+ export type KeyMark = {
14
+ key: string;
15
+ /** Where the change takes over: ticks from the bar's start (0 = the whole bar). */
16
+ at: number;
17
+ /** By part index: null for a part with no note before the change. Null when the box is hidden. */
18
+ pivots: (Pivot | null)[] | null;
19
+ /**
20
+ * The box goes at the end of the line above when the bar is split at the change (ADR 0017),
21
+ * after the last notes in the old key; otherwise it opens the notes from the change on.
22
+ */
23
+ boxAbove: boolean;
24
+ };
25
+ /** The key mark at every measure: null where the key does not change. */
26
+ export declare function keyMarksOf(music: ScoreMusic, scoreKey: string): (KeyMark | null)[];