@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,137 @@
1
+ import { plannedWidth } from "./measurePlan.js";
2
+ import { beatsBetween, measureSegments, segmentOf, splitPoints } from "./measureSegments.js";
3
+ /** A final system narrower than this share of the line keeps its natural width. */
4
+ const JUSTIFY_LAST_FROM = 0.6;
5
+ /** The narrowest a measure gets by giving back what dragging its bar line wider added. */
6
+ const undraggedWidth = (plan) => plannedWidth({ ...plan, adjust: Math.min(0, plan.adjust) });
7
+ /**
8
+ * The ways to bring the next system's first beats up: one beat more each, up to all of its first
9
+ * bar (or of the part of it there). A bar split here joins its first part on this system.
10
+ */
11
+ function pullOptions(system, used, next, ended, wholes, measures, width) {
12
+ if (!next || ended === "page")
13
+ return [];
14
+ const whole = wholes[next.measureIndex];
15
+ const last = system[system.length - 1];
16
+ // The next part continues this system's last bar: the pulled beats join that part.
17
+ const base = used - (next.from > 0 ? plannedWidth(last) : 0);
18
+ const clearLine = ended === "line" ? [{ measureIndex: last.measureIndex, breakAfter: null }] : [];
19
+ const partial = splitPoints(next).map((tick) => ({
20
+ measureIndex: next.measureIndex,
21
+ beats: beatsBetween(whole, next.from, tick),
22
+ splitAt: tick,
23
+ breaks: clearLine,
24
+ room: base + plannedWidth(segmentOf(whole, 0, tick)) - width,
25
+ }));
26
+ // All of it: a whole bar keeps the line ending after it with the break it moves down from this
27
+ // system; what is left of a split bar joins up whole and the line ends after it, as it ended at
28
+ // the split (so the systems after it stay); a bar's first part keeps its split.
29
+ const keepsLine = (ended === "line" || ended === "split") && next.to === null && !measures[next.measureIndex]?.break_after;
30
+ const all = {
31
+ measureIndex: next.measureIndex,
32
+ beats: null,
33
+ splitAt: next.to,
34
+ breaks: keepsLine ? [...clearLine, { measureIndex: next.measureIndex, breakAfter: "line" }] : clearLine,
35
+ room: base + plannedWidth(next.from > 0 ? whole : next) - width,
36
+ };
37
+ const options = [...partial, all];
38
+ const addedBy = (room) => room - (used - width);
39
+ return options.map((option, i) => ({ ...option, reach: i === 0 ? 0 : Math.max(0, addedBy(options[i - 1].room)) }));
40
+ }
41
+ /** What moves with the beats from `tick` on, if it fits a line with what is there. */
42
+ function pushPartial(from, tick) {
43
+ const { last, whole, first, joinsFirst, brk, width } = from;
44
+ const moved = segmentOf(whole, tick, null);
45
+ const free = width - plannedWidth(moved);
46
+ if (joinsFirst ? free < 0 : undraggedWidth(first) > free)
47
+ return null;
48
+ return {
49
+ measureIndex: last.measureIndex,
50
+ beats: beatsBetween(whole, tick, last.to),
51
+ splitAt: tick,
52
+ // The split ends the previous system now; a line break after the bar would end this one
53
+ // right after the beats that moved.
54
+ breaks: !joinsFirst && brk === "line" ? [{ measureIndex: last.measureIndex, breakAfter: null }] : [],
55
+ width: plannedWidth(moved) - (joinsFirst ? plannedWidth(first) : 0),
56
+ narrowFirst: joinsFirst ? 0 : Math.max(0, plannedWidth(first) - free),
57
+ };
58
+ }
59
+ /**
60
+ * The whole last bar (or its first part) moving down: the bar before it ends the previous system
61
+ * now, with the break the moving bar had (or a line break). Needs a bar to stay behind.
62
+ */
63
+ function pushWhole(from, staying) {
64
+ const { last, whole, first, joinsFirst, brk, width } = from;
65
+ if (staying < 1)
66
+ return null;
67
+ const free = width - plannedWidth(last);
68
+ if (joinsFirst ? plannedWidth(whole) > width : undraggedWidth(first) > free)
69
+ return null;
70
+ const before = last.measureIndex - 1;
71
+ const breaks = joinsFirst
72
+ ? [{ measureIndex: before, breakAfter: "line" }]
73
+ : [{ measureIndex: before, breakAfter: brk ?? "line" }, ...(brk ? [{ measureIndex: last.measureIndex, breakAfter: null }] : [])];
74
+ return {
75
+ measureIndex: last.measureIndex,
76
+ beats: null,
77
+ splitAt: null,
78
+ breaks,
79
+ width: plannedWidth(last),
80
+ narrowFirst: joinsFirst ? 0 : Math.max(0, plannedWidth(first) - free),
81
+ };
82
+ }
83
+ /**
84
+ * The ways to move the previous system's last beats down to start `system`: one beat more each,
85
+ * up to its whole last bar (or the part of it there), when what moves fits a line with what is here.
86
+ */
87
+ function pushOptions(previous, system, wholes, measures, width) {
88
+ const last = previous?.measures.at(-1);
89
+ // A bar's second part starts its system: a system that holds only that has nothing to give.
90
+ if (!previous || !last || last.from > 0)
91
+ return [];
92
+ const from = {
93
+ last,
94
+ whole: wholes[last.measureIndex],
95
+ first: system.measures[0],
96
+ joinsFirst: last.to !== null,
97
+ brk: measures[last.measureIndex]?.break_after ?? null,
98
+ width,
99
+ };
100
+ // A page break cannot move into a bar: only the whole bar moves past one.
101
+ const ticks = !from.joinsFirst && from.brk === "page" ? [] : splitPoints(last).reverse();
102
+ const options = [...ticks.map((tick) => pushPartial(from, tick)), pushWhole(from, previous.measures.length - 1)];
103
+ return options.filter((option) => option !== null);
104
+ }
105
+ /**
106
+ * Fill systems with whole measures, greedily, honouring line and page breaks set on measures and
107
+ * bars split across systems (their first part always ends a system). A measure wider than a
108
+ * system gets a system of its own. `plans` are the whole bars; `measures` carry their breaks and splits.
109
+ */
110
+ export function breakSystems(plans, measures, width) {
111
+ const segments = plans.flatMap((plan) => measureSegments(plan, measures[plan.measureIndex]?.split_at));
112
+ const systems = [];
113
+ let current = [];
114
+ let used = 0;
115
+ const flush = (ended, next, last = false) => {
116
+ if (current.length === 0)
117
+ return;
118
+ const pullNext = pullOptions(current, used, next, ended, plans, measures, width);
119
+ const finalDragged = last && current[current.length - 1].adjust !== 0;
120
+ const pageBreakAfter = ended === "page";
121
+ const justify = !last || (used >= width * JUSTIFY_LAST_FROM && !finalDragged) || pageBreakAfter;
122
+ systems.push({ measures: current, justify, final: last, pageBreakAfter, pullNext, pushIn: [] });
123
+ current = [];
124
+ used = 0;
125
+ };
126
+ segments.forEach((segment, i) => {
127
+ if (current.length > 0 && used + plannedWidth(segment) > width)
128
+ flush(null, segment);
129
+ current.push(segment);
130
+ used += plannedWidth(segment);
131
+ const ended = segment.to !== null ? "split" : (measures[segment.measureIndex]?.break_after ?? null);
132
+ if (ended)
133
+ flush(ended, segments[i + 1], i === segments.length - 1);
134
+ });
135
+ flush(null, undefined, true);
136
+ return systems.map((system, i) => ({ ...system, pushIn: pushOptions(systems[i - 1], system, plans, measures, width) }));
137
+ }
@@ -0,0 +1,138 @@
1
+ import type { MeasureBreak, ScoreMusic } from "../schema/types.js";
2
+ import { type BeamGroup, type Slice } from "../notation/rhythm.js";
3
+ import { type BarFrame } from "../notation/time.js";
4
+ import type { Pivot } from "./keyMarks.js";
5
+ import { type TupletMark } from "./tuplets.js";
6
+ import type { PullOption, PushOption, SystemPlan } from "./systemBreaking.js";
7
+ /** A written piece with its horizontal centre (system coordinates, px). */
8
+ export type PlacedSlice = Slice & {
9
+ x: number;
10
+ };
11
+ export type RowMeasure = {
12
+ measureIndex: number;
13
+ slices: PlacedSlice[];
14
+ groups: BeamGroup[];
15
+ /**
16
+ * Where a measure this part has not written yet shows a rest on each beat (one x per beat);
17
+ * empty once the part writes anything in it. Drawn only: the score stays empty.
18
+ */
19
+ blankBeatXs: number[];
20
+ /** Tuplet marks ("3" over a triplet), drawn above the duration lines. */
21
+ tuplets: TupletMark[];
22
+ };
23
+ /** One part on one system. `y` is the row's top, `noteY` the digit centre (system coordinates). */
24
+ export type Row = {
25
+ partIndex: number;
26
+ partId: string;
27
+ label: string;
28
+ /** How many parts the row stands for: more than one where merged parts share it ("SA."). */
29
+ partCount: number;
30
+ y: number;
31
+ noteY: number;
32
+ lyricLines: number;
33
+ /** The whole row, `gap` included. */
34
+ height: number;
35
+ /** Space after the row's content, before the next part (only below lyrics). */
36
+ gap: number;
37
+ measures: RowMeasure[];
38
+ };
39
+ /** Where a measure sits on the system. */
40
+ export type MeasureBounds = {
41
+ measureIndex: number;
42
+ measureId: string;
43
+ x: number;
44
+ width: number;
45
+ /** Centre of its closing bar line. */
46
+ barX: number;
47
+ /** Centre x of each of its columns, by ticks from the measure's start (where chords sit). */
48
+ centers: ReadonlyMap<number, number>;
49
+ /** The bar's meter, length and phase: where its beats are. */
50
+ frame: BarFrame;
51
+ /**
52
+ * The narrowest it may be dragged to: its compact width (its notes, without syllable room). The
53
+ * first part of a split bar keeps the width it is drawn at: it has no bar line to drag.
54
+ */
55
+ minWidth: number;
56
+ /** The width it asks for when systems are broken (natural plus its drag, at least compact). */
57
+ plannedWidth: number;
58
+ /** The part of the bar on this system (ticks; `to` null = to its end, see `MeasurePlan`). */
59
+ from: number;
60
+ to: number | null;
61
+ /** The key change written in it (ADR 0010, 0017), with where its box is drawn, if shown. */
62
+ keyMark: PlacedKeyMark | null;
63
+ /** The box of the change the next line opens with, drawn at this part's end instead (ADR 0017). */
64
+ closingKeyBox: KeyBox | null;
65
+ };
66
+ /**
67
+ * Centre x of the beat that tick `at` falls in: chords stand over beats, so one stored off the
68
+ * beat (written before chords snapped to beats) is drawn over its beat too.
69
+ */
70
+ export declare const beatX: (bounds: Pick<MeasureBounds, "centers" | "frame" | "x">, at: number) => number;
71
+ /**
72
+ * A key change on the system: the new key, where its "1 =" starts, and its box ("5 → 3" per
73
+ * part; left edge and width), if drawn.
74
+ */
75
+ export type PlacedKeyMark = {
76
+ key: string;
77
+ x: number;
78
+ box: KeyBox | null;
79
+ };
80
+ /** A key change box: its left edge and width, and each part's pivot ("5 → 3") by part index. */
81
+ export type KeyBox = {
82
+ x: number;
83
+ width: number;
84
+ pivots: (Pivot | null)[];
85
+ };
86
+ /** A line break a move sets or clears, by measure id. */
87
+ export type MovedBreak = {
88
+ measureId: string;
89
+ breakAfter: MeasureBreak | null;
90
+ };
91
+ /**
92
+ * A move of music between systems, by measure id: the bar it splits (or joins, `splitAt` null),
93
+ * the line breaks it moves, and how many beats move (null = the whole bar or what is left of it).
94
+ */
95
+ export type SystemMove = {
96
+ measureId: string;
97
+ beats: number | null;
98
+ splitAt: number | null;
99
+ breaks: MovedBreak[];
100
+ };
101
+ export type PullNext = SystemMove & Pick<PullOption, "room" | "reach">;
102
+ export type PushIn = SystemMove & Pick<PushOption, "width" | "narrowFirst">;
103
+ export type SystemLayout = {
104
+ width: number;
105
+ /** True when the measures are stretched to fill the width (its last bar line is at the margin). */
106
+ justified: boolean;
107
+ /** The score's last system: its last bar line is the final one. */
108
+ final: boolean;
109
+ /** Ways to bring the next system's first beats up by narrowing this one (fewest beats first). */
110
+ pullNext: PullNext[];
111
+ /** Ways to move the previous system's last beats down to start this one (fewest beats first). */
112
+ pushIn: PushIn[];
113
+ /** Where the music starts: right of the bracket and the part labels. */
114
+ left: number;
115
+ /** Height of one lyric line under a part. */
116
+ lyricLineHeight: number;
117
+ height: number;
118
+ /** Room above the first row (volta brackets and section labels). */
119
+ headroom: number;
120
+ rows: Row[];
121
+ measures: MeasureBounds[];
122
+ };
123
+ /**
124
+ * Where the music starts on every system: just right of the widest part label ("S.", "Disk."),
125
+ * so there is no fixed empty column between the bracket and the first notes. Labels are bold,
126
+ * hence the 10% on the width estimate.
127
+ */
128
+ export declare function musicLeft(music: ScoreMusic): number;
129
+ /**
130
+ * Room a system needs above it: one band for volta brackets, one for section labels, key changes
131
+ * and tempo marks, and what those rise to clear chords and directions under them. Chords and
132
+ * directions themselves take none.
133
+ */
134
+ export declare function headroomOf(music: ScoreMusic, plan: SystemPlan): number;
135
+ /** Lay out one system: its rows (parts) and the x of every written piece (FR-058, FR-060). */
136
+ export declare function layoutSystem(music: ScoreMusic, plan: SystemPlan, width: number, partsWithMusic: ReadonlySet<number>, left: number, lyricLineHeight: number,
137
+ /** Room above the first row; at least what this system's brackets and labels need. */
138
+ headroom?: number): SystemLayout;
@@ -0,0 +1,266 @@
1
+ import { beamGroups } from "../notation/rhythm.js";
2
+ import { beatOnsets, beatStartOf } from "../notation/time.js";
3
+ import { gapBefore, plannedWidth, stretches } from "./measurePlan.js";
4
+ import { holdsTick } from "./measureSegments.js";
5
+ import { bandLiftOf } from "./floating.js";
6
+ import { NOTATION, textWidth } from "./notationMetrics.js";
7
+ import { tupletMarks } from "./tuplets.js";
8
+ import { playsAny } from "../model/partSpan.js";
9
+ import { takesNotes } from "../model/textBars.js";
10
+ import { absentOver, drawnIn, shownAt } from "../model/rowPresence.js";
11
+ import { groupLedThroughout, joinedLabel, joinedLabels, withOnsets } from "../model/unisons.js";
12
+ import { lyricsHiddenAt } from "../model/sharedLyrics.js";
13
+ /**
14
+ * Centre x of the beat that tick `at` falls in: chords stand over beats, so one stored off the
15
+ * beat (written before chords snapped to beats) is drawn over its beat too.
16
+ */
17
+ export const beatX = (bounds, at) => bounds.centers.get(beatStartOf(bounds.frame, at)) ?? bounds.centers.get(at) ?? bounds.x;
18
+ /**
19
+ * Where a measure's key change goes. One that opens this part of the bar (at the bar's start, or
20
+ * where a split bar goes on, ADR 0017) has its box in the lead, after any repeat-start sign. One
21
+ * partway through it writes only "1 =" over the beat it takes over at: there is no room for a
22
+ * box between notes.
23
+ */
24
+ function placeKeyMark(music, m, x, centers) {
25
+ if (!m.keyMark)
26
+ return null;
27
+ const { key, pivots, at, boxAbove } = m.keyMark;
28
+ if (at !== m.from)
29
+ return { key, x: (centers.get(at) ?? x) - NOTATION.slot / 2, box: null };
30
+ if (boxAbove && at > 0)
31
+ return { key, x, box: null };
32
+ const sign = m.from === 0 && music.measures[m.measureIndex].repeat_start ? NOTATION.repeatStartWidth : 0;
33
+ const box = pivots && { x: x + sign + NOTATION.measurePad / 2, width: NOTATION.pivotWidth, pivots };
34
+ return { key, x: box?.x ?? x, box };
35
+ }
36
+ /** The box at the end of a part of a bar whose next part opens with the change (`boxAbove`), in its tail. */
37
+ function placeClosingKeyBox(m, right) {
38
+ const pivots = m.closingKeyMark?.pivots;
39
+ if (!pivots)
40
+ return null;
41
+ return { x: right - NOTATION.measurePad / 2 - NOTATION.pivotWidth, width: NOTATION.pivotWidth, pivots };
42
+ }
43
+ function moveOf(music, { measureIndex, beats, splitAt, breaks }) {
44
+ return {
45
+ measureId: music.measures[measureIndex].id,
46
+ beats,
47
+ splitAt,
48
+ breaks: breaks.map((b) => ({ measureId: music.measures[b.measureIndex].id, breakAfter: b.breakAfter })),
49
+ };
50
+ }
51
+ const pullOf = (music, option) => ({ ...moveOf(music, option), room: option.room, reach: option.reach });
52
+ const pushOf = (music, option) => ({ ...moveOf(music, option), width: option.width, narrowFirst: option.narrowFirst });
53
+ /**
54
+ * Which parts get a row on this system: visible parts with notes here. A part with no notes
55
+ * anywhere still shows (so it can be written in); a system where nothing sounds shows every
56
+ * visible part. Like the reference score, a part that joins later (Diskant) is left out before.
57
+ * A part merged into the row above (ADR 0012) or hidden (ADR 0013) in every bar of the system has
58
+ * no row; on a system that mixes such bars with others it keeps its row, blank in those bars.
59
+ */
60
+ function rowParts(music, plan, partsWithMusic) {
61
+ const indices = plan.measures.map((m) => m.measureIndex);
62
+ const pieces = piecesOf(music, plan);
63
+ const absentThroughout = (partId) => pieces.every((p) => absentOver(p.measure, partId, p.from, p.to));
64
+ // A part with a span has no row on a system it does not reach.
65
+ const visible = music.parts.flatMap((p, i) => p.visible && playsAny(music, p, indices) && !absentThroughout(p.id) ? [i] : []);
66
+ const sounding = visible.filter((i) => !partsWithMusic.has(i) ||
67
+ plan.measures.some((m) => music.parts[i].measures[m.measureIndex].events.length > 0));
68
+ if (sounding.length > 0)
69
+ return sounding;
70
+ return visible.length > 0 ? visible : [0];
71
+ }
72
+ /** The pieces of bars on a system (a bar split across systems has a piece on each). */
73
+ const piecesOf = (music, plan) => plan.measures.map((m) => ({ measure: music.measures[m.measureIndex], from: m.from, to: m.to }));
74
+ /**
75
+ * The parts a row stands for: the merged group the part leads in every bar of the system (then
76
+ * the others have no row here), or the part alone.
77
+ */
78
+ const rowGroup = (music, part, plan) => groupLedThroughout(piecesOf(music, plan), part.id) ?? [part.id];
79
+ /** A row's label: the part's abbreviation, or the merged parts' joined ("SA."). */
80
+ function rowLabel(music, part, group) {
81
+ if (group.length < 2)
82
+ return part.abbreviation;
83
+ return joinedLabel(group.flatMap((id) => music.parts.find((p) => p.id === id) ?? []));
84
+ }
85
+ /**
86
+ * Verse lines that have a drawn syllable on this system (empty verse slots take no room, nor do
87
+ * lyrics shared with a part below, ADR 0014).
88
+ */
89
+ function lyricLinesOf(music, partIndex, plan) {
90
+ const part = music.parts[partIndex];
91
+ let lines = 0;
92
+ for (const m of plan.measures)
93
+ for (const { onset, event } of withOnsets(part.measures[m.measureIndex].events))
94
+ if (event.type === "note" && !lyricsHiddenAt(music.measures[m.measureIndex], part.id, onset))
95
+ event.lyrics.forEach((lyric, line) => {
96
+ if (lyric && lyric.text.trim() !== "")
97
+ lines = Math.max(lines, line + 1);
98
+ });
99
+ return lines;
100
+ }
101
+ /**
102
+ * Where the music starts on every system: just right of the widest part label ("S.", "Disk."),
103
+ * so there is no fixed empty column between the bracket and the first notes. Labels are bold,
104
+ * hence the 10% on the width estimate.
105
+ */
106
+ export function musicLeft(music) {
107
+ const widest = Math.max(0, ...[...music.parts.filter((p) => p.visible).map((p) => p.abbreviation), ...joinedLabels(music)].map((label) => textWidth(label, NOTATION.labelSize) * 1.1));
108
+ return Math.ceil(NOTATION.labelX + widest + NOTATION.labelGap);
109
+ }
110
+ /** Centre x of every column of a measure, and the measure's right edge. */
111
+ function placeColumns(plan, x, fit) {
112
+ const centers = new Map();
113
+ let cursor = x + plan.lead;
114
+ plan.columns.forEach((column, i) => {
115
+ cursor += gapBefore(column, plan.columns[i - 1]) + column.padBefore * fit.keep;
116
+ const width = NOTATION.slot +
117
+ (column.minWidth - NOTATION.slot) * fit.keep +
118
+ (stretches(column) ? fit.extraPerColumn : 0);
119
+ centers.set(column.onset, cursor + width / 2);
120
+ cursor += width + column.padAfter * fit.keep;
121
+ });
122
+ const barRoom = plan.tail - NOTATION.measurePad;
123
+ return { centers, barX: cursor + NOTATION.measurePad + barRoom / 2, right: cursor + plan.tail };
124
+ }
125
+ /** Whether the part has a tuplet in any of the system's measures. */
126
+ const hasTuplets = (part, placed) => placed.some(({ plan }) => part.measures[plan.measureIndex].events.some((e) => e.tuplet));
127
+ /**
128
+ * Room a system needs above it: one band for volta brackets, one for section labels, key changes
129
+ * and tempo marks, and what those rise to clear chords and directions under them. Chords and
130
+ * directions themselves take none.
131
+ */
132
+ export function headroomOf(music, plan) {
133
+ const measures = plan.measures.map((m) => music.measures[m.measureIndex]);
134
+ const labelled = measures.some((m) => m.label.trim() !== "" || m.navigation || m.tempo != null) ||
135
+ plan.measures.some((m) => m.keyMark);
136
+ const bands = Number(measures.some((m) => m.volta !== null)) + Number(labelled);
137
+ // Chords and directions float and keep no room; the bands rise over what is under them.
138
+ return bands * NOTATION.headroom + bandLiftOf(measures, labelled);
139
+ }
140
+ const stretchingColumns = (m) => m.columns.filter(stretches).length;
141
+ /** Natural plus its dragged width; a measure that cannot stretch never grows past natural. */
142
+ const wantedWidth = (m) => m.naturalWidth + (stretchingColumns(m) > 0 ? m.adjust : Math.min(0, m.adjust));
143
+ /** How a measure of `width` is drawn (see `Fit`). */
144
+ function fitOf(m, width) {
145
+ if (width >= m.naturalWidth) {
146
+ const own = stretchingColumns(m);
147
+ return { extraPerColumn: own > 0 ? (width - m.naturalWidth) / own : 0, keep: 1 };
148
+ }
149
+ const give = m.naturalWidth - m.compactWidth;
150
+ return { extraPerColumn: 0, keep: give > 0 ? Math.max(0, (width - m.compactWidth) / give) : 1 };
151
+ }
152
+ /**
153
+ * How every measure is drawn: at natural plus its dragged width, plus, when the system is
154
+ * stretched to fill, an equal share of the spare width per stretching column (`stretch`). A
155
+ * measure is never narrower than compact; when a drag would make it so, it stays compact and the
156
+ * others make up the difference, so the system keeps its width.
157
+ */
158
+ function measureFits(plan, available) {
159
+ const compact = new Set();
160
+ for (;;) {
161
+ const free = plan.measures.filter((m) => !compact.has(m.measureIndex));
162
+ const used = plan.measures.reduce((sum, m) => sum + (compact.has(m.measureIndex) ? m.compactWidth : wantedWidth(m)), 0);
163
+ const columns = free.reduce((sum, m) => sum + stretchingColumns(m), 0);
164
+ const stretch = plan.justify && columns > 0 && used < available ? (available - used) / columns : 0;
165
+ const widthOf = (m) => compact.has(m.measureIndex) ? m.compactWidth : wantedWidth(m) + stretch * stretchingColumns(m);
166
+ const squeezed = free.filter((m) => widthOf(m) < m.compactWidth);
167
+ if (!squeezed.length) {
168
+ const fits = new Map(plan.measures.map((m) => [m.measureIndex, fitOf(m, widthOf(m))]));
169
+ return { fits, stretch };
170
+ }
171
+ for (const m of squeezed)
172
+ compact.add(m.measureIndex);
173
+ }
174
+ }
175
+ /** Lay out one system: its rows (parts) and the x of every written piece (FR-058, FR-060). */
176
+ export function layoutSystem(music, plan, width, partsWithMusic, left, lyricLineHeight,
177
+ /** Room above the first row; at least what this system's brackets and labels need. */
178
+ headroom = headroomOf(music, plan)) {
179
+ const { fits, stretch } = measureFits(plan, width - left);
180
+ const justified = stretch > 0;
181
+ let x = left;
182
+ const placed = plan.measures.map((m) => {
183
+ const columns = placeColumns(m, x, fits.get(m.measureIndex) ?? { extraPerColumn: 0, keep: 1 });
184
+ const width = columns.right - x;
185
+ const goesOn = m.to !== null;
186
+ const bounds = {
187
+ measureIndex: m.measureIndex,
188
+ measureId: music.measures[m.measureIndex].id,
189
+ x,
190
+ width,
191
+ barX: columns.barX,
192
+ centers: columns.centers,
193
+ frame: m.frame,
194
+ minWidth: goesOn ? width : m.compactWidth,
195
+ plannedWidth: goesOn ? width : plannedWidth(m),
196
+ from: m.from,
197
+ to: m.to,
198
+ keyMark: placeKeyMark(music, m, x, columns.centers),
199
+ closingKeyBox: placeClosingKeyBox(m, columns.right),
200
+ };
201
+ x = columns.right;
202
+ return { plan: m, columns, bounds };
203
+ });
204
+ let y = headroom;
205
+ const rows = rowParts(music, plan, partsWithMusic).map((partIndex) => {
206
+ const part = music.parts[partIndex];
207
+ const lyricLines = lyricLinesOf(music, partIndex, plan);
208
+ // Parts keep a small gap; under lyrics a larger one keeps the next part's duration lines
209
+ // off them. Without lyrics the parts sit close, as in the reference score.
210
+ const gap = NOTATION.partGap + (lyricLines > 0 ? NOTATION.rowGap : 0);
211
+ // A row with a tuplet takes a little more room above, for its mark over the duration lines.
212
+ y += hasTuplets(part, placed) ? NOTATION.tupletRoom : 0;
213
+ const height = NOTATION.noteRowHeight + lyricLines * lyricLineHeight + gap;
214
+ const group = rowGroup(music, part, plan);
215
+ const row = {
216
+ partIndex,
217
+ partId: part.id,
218
+ label: rowLabel(music, part, group),
219
+ partCount: group.length,
220
+ y,
221
+ noteY: y + NOTATION.digitY,
222
+ lyricLines,
223
+ height,
224
+ gap,
225
+ measures: placed.map(({ plan: m, columns }) => {
226
+ // Notes it sings in the row of a part above it (ADR 0012) are drawn there, not here; where
227
+ // it is hidden (ADR 0013) nothing shows, not even its written rests.
228
+ const measure = music.measures[m.measureIndex];
229
+ const drawn = drawnIn(music, part, m.measureIndex);
230
+ const slices = m.slices[partIndex]
231
+ .filter((s) => drawn && shownAt(measure, part.id, s.onset))
232
+ .map((s) => ({ ...s, x: columns.centers.get(s.onset) ?? 0 }));
233
+ const events = part.measures[m.measureIndex].events;
234
+ // Rests mark a measure the part has not written yet, never one outside the bars it plays
235
+ // or one where it sings another part's notes (ADR 0012).
236
+ const blankBeatXs = events.length > 0 || !takesNotes(music, part, m.measureIndex) || !drawnIn(music, part, m.measureIndex)
237
+ ? []
238
+ : beatOnsets(m.frame)
239
+ .filter((onset) => holdsTick(m, onset) && shownAt(measure, part.id, onset))
240
+ .map((onset) => columns.centers.get(onset) ?? 0);
241
+ return {
242
+ measureIndex: m.measureIndex,
243
+ slices,
244
+ groups: beamGroups(slices, events),
245
+ blankBeatXs,
246
+ tuplets: tupletMarks(slices, events),
247
+ };
248
+ }),
249
+ };
250
+ y += height;
251
+ return row;
252
+ });
253
+ return {
254
+ width,
255
+ justified,
256
+ final: plan.final,
257
+ pullNext: plan.pullNext.map((option) => pullOf(music, option)),
258
+ pushIn: plan.pushIn.map((option) => pushOf(music, option)),
259
+ left,
260
+ lyricLineHeight,
261
+ height: y,
262
+ headroom,
263
+ rows,
264
+ measures: placed.map((p) => p.bounds),
265
+ };
266
+ }
@@ -0,0 +1,9 @@
1
+ import type { Column } from "./measurePlan.js";
2
+ /**
3
+ * Space every tuplet's notes evenly, so its middle note stands under the number: the empty beat
4
+ * columns between them go (a triplet of quarters runs across a beat line), no beat gap opens
5
+ * inside it, and its notes take one width with the same air (`tupletGap` at least) between each
6
+ * two. A tuplet that another part writes notes inside keeps the shared spacing, since the parts
7
+ * must stay aligned.
8
+ */
9
+ export declare function spaceTuplets(columns: readonly Column[], tuplets: readonly (readonly number[])[], occupied: ReadonlySet<number>): Column[];
@@ -0,0 +1,33 @@
1
+ import { NOTATION } from "./notationMetrics.js";
2
+ /**
3
+ * Space every tuplet's notes evenly, so its middle note stands under the number: the empty beat
4
+ * columns between them go (a triplet of quarters runs across a beat line), no beat gap opens
5
+ * inside it, and its notes take one width with the same air (`tupletGap` at least) between each
6
+ * two. A tuplet that another part writes notes inside keeps the shared spacing, since the parts
7
+ * must stay aligned.
8
+ */
9
+ export function spaceTuplets(columns, tuplets, occupied) {
10
+ const inside = (onset) => tuplets.some((t) => onset > t[0] && onset < t[t.length - 1]);
11
+ const kept = columns.filter((c) => occupied.has(c.onset) || !inside(c.onset));
12
+ for (const onsets of tuplets)
13
+ evenOut(kept, onsets);
14
+ return kept;
15
+ }
16
+ /** Give one tuplet's columns the same width and air, when it owns every column it spans. */
17
+ function evenOut(columns, onsets) {
18
+ const first = columns.findIndex((c) => c.onset === onsets[0]);
19
+ const span = columns.slice(first, first + onsets.length);
20
+ if (first < 0 || span.some((c, i) => c.onset !== onsets[i]))
21
+ return;
22
+ const width = Math.max(...span.map((c) => c.minWidth));
23
+ const air = Math.max(0, ...span.slice(1).map((c, i) => span[i].padAfter + c.padBefore)) + NOTATION.tupletGap;
24
+ span.forEach((column, i) => {
25
+ column.minWidth = width;
26
+ if (i > 0) {
27
+ column.inTuplet = true;
28
+ column.padBefore = 0;
29
+ }
30
+ if (i < span.length - 1)
31
+ column.padAfter = air;
32
+ });
33
+ }
@@ -0,0 +1,30 @@
1
+ import type { ScoreEvent } from "../schema/types.js";
2
+ /**
3
+ * A tuplet's mark over its notes: from its first note's centre to its last, its number, and
4
+ * whether its notes carry duration lines (a triplet of eighths) or not (a triplet of quarters).
5
+ */
6
+ export type TupletMark = {
7
+ x1: number;
8
+ x2: number;
9
+ label: string;
10
+ lined: boolean;
11
+ };
12
+ /**
13
+ * The tuplets of one part's measure: every run of neighbouring notes that share a tuplet id
14
+ * (see `Tuplet`), marked from its first note to its last, numbered by how many it holds ("3").
15
+ */
16
+ export declare function tupletMarks(slices: readonly {
17
+ eventIndex: number;
18
+ head: boolean;
19
+ x: number;
20
+ lines: number;
21
+ }[], events: readonly ScoreEvent[]): TupletMark[];
22
+ /**
23
+ * The onsets of each tuplet's notes in one part's measure, in time order (one list per tuplet:
24
+ * the run of neighbouring notes that share its id).
25
+ */
26
+ export declare function tupletOnsets(slices: readonly {
27
+ eventIndex: number;
28
+ head: boolean;
29
+ onset: number;
30
+ }[], events: readonly ScoreEvent[]): number[][];
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The tuplets of one part's measure: every run of neighbouring notes that share a tuplet id
3
+ * (see `Tuplet`), marked from its first note to its last, numbered by how many it holds ("3").
4
+ */
5
+ export function tupletMarks(slices, events) {
6
+ const marks = [];
7
+ for (const slice of slices) {
8
+ const tuplet = slice.head ? events[slice.eventIndex]?.tuplet : null;
9
+ if (!tuplet)
10
+ continue;
11
+ const open = marks.at(-1);
12
+ const previous = events[slice.eventIndex - 1]?.tuplet?.id;
13
+ if (open && open.id === tuplet.id && previous === tuplet.id) {
14
+ open.x2 = slice.x;
15
+ open.lined || (open.lined = slice.lines > 0);
16
+ }
17
+ else
18
+ marks.push({ id: tuplet.id, x1: slice.x, x2: slice.x, label: String(tuplet.of), lined: slice.lines > 0 });
19
+ }
20
+ return marks.map(({ x1, x2, label, lined }) => ({ x1, x2, label, lined }));
21
+ }
22
+ /**
23
+ * The onsets of each tuplet's notes in one part's measure, in time order (one list per tuplet:
24
+ * the run of neighbouring notes that share its id).
25
+ */
26
+ export function tupletOnsets(slices, events) {
27
+ const runs = [];
28
+ for (const slice of slices) {
29
+ const id = slice.head ? events[slice.eventIndex]?.tuplet?.id : undefined;
30
+ if (id === undefined)
31
+ continue;
32
+ const open = runs.at(-1);
33
+ if (open && open.id === id && events[slice.eventIndex - 1]?.tuplet?.id === id)
34
+ open.onsets.push(slice.onset);
35
+ else
36
+ runs.push({ id, onsets: [slice.onset] });
37
+ }
38
+ return runs.map((run) => run.onsets);
39
+ }