@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,64 @@
1
+ /**
2
+ * What the renderers produce: plain drawing instructions in system coordinates (px). They know
3
+ * nothing about React or the DOM, so the same output feeds the screen SVG, the print sheet and the
4
+ * SVG export. `role` names what a shape means (tests and the export find shapes by it); `owner`
5
+ * is the id of the score element it draws (event, measure, slur), so every drawn element can be
6
+ * traced back to the score. `tone` and `font` are resolved by whoever draws the primitive.
7
+ */
8
+ export type Tone = "ink" | "rule";
9
+ /** `volta`: the ending numerals (I, II), always Times New Roman as in the reference scores. */
10
+ export type FontRole = "notes" | "text" | "lyrics" | "volta";
11
+ export type Role = "digit" | "rest" | "continuation" | "accidental" | "octave-dot" | "duration-line" | "barline" | "repeat-dot" | "tie" | "slur" | "lyric" | "chord" | "tuplet" | "hyphen" | "extender" | "elision" | "part-label" | "bracket" | "volta" | "volta-number" | "section-label"
12
+ /** The line that runs on from a section label to the end of its system. */
13
+ | "section-rule"
14
+ /** "Fine" or "D.C. al Fine" at the end of a bar. */
15
+ | "navigation" | "measure-number"
16
+ /** The text of a text bar ("2 bars instr."). */
17
+ | "text-bar"
18
+ /** A key change: "1 = F" above its bar, and the box of "5 → 3" per part (ADR 0010). */
19
+ | "key-change" | "key-change-frame"
20
+ /** A tempo change: "♩ = 60" above its bar (ADR 0041). */
21
+ | "tempo-mark" | "key-box" | "key-arrow"
22
+ /** Directions above the system (ADR 0011). */
23
+ | "dynamic" | "expression" | "hairpin"
24
+ /** Title, subtitle, info, credits, header and footer text (only the SVG export draws these). */
25
+ | "page-text";
26
+ type Base = {
27
+ role: Role;
28
+ owner?: string;
29
+ tone: Tone;
30
+ };
31
+ export type TextPrimitive = Base & {
32
+ kind: "text";
33
+ x: number;
34
+ y: number;
35
+ text: string;
36
+ size: number;
37
+ anchor: "start" | "middle" | "end";
38
+ font: FontRole;
39
+ bold?: boolean;
40
+ italic?: boolean;
41
+ };
42
+ export type LinePrimitive = Base & {
43
+ kind: "line";
44
+ x1: number;
45
+ y1: number;
46
+ x2: number;
47
+ y2: number;
48
+ width: number;
49
+ };
50
+ export type CirclePrimitive = Base & {
51
+ kind: "circle";
52
+ cx: number;
53
+ cy: number;
54
+ r: number;
55
+ };
56
+ /** A stroked outline, or (`filled`) a solid shape in its tone with no outline. */
57
+ export type PathPrimitive = Base & {
58
+ kind: "path";
59
+ d: string;
60
+ width: number;
61
+ filled?: boolean;
62
+ };
63
+ export type Primitive = TextPrimitive | LinePrimitive | CirclePrimitive | PathPrimitive;
64
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { ScoreEvent } from "../schema/types.js";
2
+ import type { RowMeasure, Row } from "../layout/systemLayout.js";
3
+ import { type Spelling } from "../notation/pitch.js";
4
+ import type { NotationProfile } from "../notation/profile.js";
5
+ import type { Primitive } from "./primitives.js";
6
+ /**
7
+ * A written pitch at `x` on a row's digit line: its digit, accidental stroke and octave dots,
8
+ * written the preferred way (a ♯6 saved earlier is drawn as a ♭7, a ♭2 as a ♯1, ...). `octaveShift`
9
+ * moves the octave dots only (a low voice drawn an octave up): the note itself is not changed.
10
+ */
11
+ export declare function renderSpelling(spelling: Spelling, at: {
12
+ x: number;
13
+ noteY: number;
14
+ owner: string;
15
+ }, profile: NotationProfile, octaveShift?: number): Primitive[];
16
+ /** A rest on each beat of a measure the part has not written yet (see `RowMeasure`). */
17
+ export declare function renderBlankMeasure(row: Row, measure: RowMeasure, profile: NotationProfile): Primitive[];
18
+ /** Digits, rests, continuation dots, accidentals and octave dots of one row's measure. */
19
+ export declare function renderSlices(row: Row, measure: RowMeasure, events: readonly ScoreEvent[], profile: NotationProfile, octaveShift?: number): Primitive[];
@@ -0,0 +1,79 @@
1
+ import { NOTATION } from "../layout/notationMetrics.js";
2
+ import { preferredSpelling } from "../notation/pitch.js";
3
+ import { renderAccidental } from "./accidentalRenderer.js";
4
+ const glyph = (role, text, slice, noteY) => ({
5
+ kind: "text",
6
+ role,
7
+ owner: slice.eventId,
8
+ x: slice.x,
9
+ y: noteY,
10
+ text,
11
+ size: NOTATION.digitSize,
12
+ anchor: "middle",
13
+ font: "notes",
14
+ tone: "ink",
15
+ });
16
+ /** Octave dots: stacked above the digit for a higher octave, below it for a lower one. */
17
+ function octaveDots(eventId, octave, x, noteY) {
18
+ const direction = octave > 0 ? -1 : 1;
19
+ return Array.from({ length: Math.abs(octave) }, (_, i) => ({
20
+ kind: "circle",
21
+ role: "octave-dot",
22
+ owner: eventId,
23
+ cx: x,
24
+ cy: noteY + direction * (NOTATION.octaveDotOffset + i * NOTATION.octaveDotStep),
25
+ r: NOTATION.octaveDotRadius,
26
+ tone: "ink",
27
+ }));
28
+ }
29
+ /**
30
+ * A written pitch at `x` on a row's digit line: its digit, accidental stroke and octave dots,
31
+ * written the preferred way (a ♯6 saved earlier is drawn as a ♭7, a ♭2 as a ♯1, ...). `octaveShift`
32
+ * moves the octave dots only (a low voice drawn an octave up): the note itself is not changed.
33
+ */
34
+ export function renderSpelling(spelling, at, profile, octaveShift = 0) {
35
+ const written = preferredSpelling(spelling);
36
+ const digit = {
37
+ kind: "text",
38
+ role: "digit",
39
+ owner: at.owner,
40
+ x: at.x,
41
+ y: at.noteY,
42
+ text: String(written.degree),
43
+ size: NOTATION.digitSize,
44
+ anchor: "middle",
45
+ font: "notes",
46
+ tone: "ink",
47
+ };
48
+ const accidental = written.accidental ? renderAccidental(profile.accidentals[written.accidental], at.x, at.noteY, at.owner) : [];
49
+ return [digit, ...accidental, ...octaveDots(at.owner, written.octave + octaveShift, at.x, at.noteY)];
50
+ }
51
+ /** One renderer per kind of written piece; a new kind is a compile error until it has one. */
52
+ const SLICE_RENDERERS = {
53
+ note: (slice, event, noteY, profile, octaveShift) => event.type === "note"
54
+ ? renderSpelling(event, { x: slice.x, noteY, owner: event.id }, profile, octaveShift)
55
+ : [],
56
+ rest: (slice, _event, noteY, profile) => [glyph("rest", profile.restGlyph, slice, noteY)],
57
+ continuation: (slice, _event, noteY, profile) => [
58
+ glyph("continuation", profile.continuationGlyph, slice, noteY),
59
+ ],
60
+ };
61
+ const kindOf = (slice) => !slice.head ? "continuation" : slice.type;
62
+ /** A rest on each beat of a measure the part has not written yet (see `RowMeasure`). */
63
+ export function renderBlankMeasure(row, measure, profile) {
64
+ return measure.blankBeatXs.map((x) => ({
65
+ kind: "text",
66
+ role: "rest",
67
+ x,
68
+ y: row.noteY,
69
+ text: profile.restGlyph,
70
+ size: NOTATION.digitSize,
71
+ anchor: "middle",
72
+ font: "notes",
73
+ tone: "ink",
74
+ }));
75
+ }
76
+ /** Digits, rests, continuation dots, accidentals and octave dots of one row's measure. */
77
+ export function renderSlices(row, measure, events, profile, octaveShift = 0) {
78
+ return measure.slices.flatMap((slice) => SLICE_RENDERERS[kindOf(slice)](slice, events[slice.eventIndex], row.noteY, profile, octaveShift));
79
+ }
@@ -0,0 +1,8 @@
1
+ import type { ScoreMusic } from "../schema/types.js";
2
+ import type { MeasureBounds, Row } from "../layout/systemLayout.js";
3
+ import type { Primitive } from "./primitives.js";
4
+ /**
5
+ * A text bar's text ("2 bars" / "instr."), centred between its bar lines and across every row of
6
+ * the system, one line under the other (ADR 0009).
7
+ */
8
+ export declare function renderTextBar(music: ScoreMusic, rows: readonly Row[], bounds: MeasureBounds): Primitive[];
@@ -0,0 +1,28 @@
1
+ import { NOTATION } from "../layout/notationMetrics.js";
2
+ /**
3
+ * A text bar's text ("2 bars" / "instr."), centred between its bar lines and across every row of
4
+ * the system, one line under the other (ADR 0009).
5
+ */
6
+ export function renderTextBar(music, rows, bounds) {
7
+ const textBar = music.measures[bounds.measureIndex].text_bar;
8
+ if (!textBar || rows.length === 0)
9
+ return [];
10
+ const lines = textBar.text.split("\n");
11
+ const top = rows[0].noteY;
12
+ const bottom = rows[rows.length - 1].noteY;
13
+ const x = (bounds.x + bounds.barX) / 2;
14
+ // The block of lines is centred on the middle of the rows; each line sits on its baseline.
15
+ const first = (top + bottom) / 2 - ((lines.length - 1) * NOTATION.textBarLine) / 2 + NOTATION.textBarSize / 3;
16
+ return lines.map((text, i) => ({
17
+ kind: "text",
18
+ role: "text-bar",
19
+ owner: bounds.measureId,
20
+ x,
21
+ y: first + i * NOTATION.textBarLine,
22
+ text,
23
+ size: NOTATION.textBarSize,
24
+ anchor: "middle",
25
+ font: "text",
26
+ tone: "ink",
27
+ }));
28
+ }
@@ -0,0 +1,7 @@
1
+ import type { Row, RowMeasure } from "../layout/systemLayout.js";
2
+ import type { Primitive } from "./primitives.js";
3
+ /**
4
+ * The tuplet marks of one part's measure. A mark over notes without duration lines (a triplet of
5
+ * quarters) stands where the duration lines are drawn; one over lined notes just above them.
6
+ */
7
+ export declare function renderTuplets(row: Pick<Row, "noteY">, measure: Pick<RowMeasure, "tuplets">): Primitive[];
@@ -0,0 +1,42 @@
1
+ import { NOTATION } from "../layout/notationMetrics.js";
2
+ /** How far the mark's ends reach past its first and last notes, and its rise to the middle. */
3
+ const OVERHANG = 3;
4
+ const RISE = 3.5;
5
+ /** Half the room left open in the middle of the arc for the number. */
6
+ const NUMBER_GAP = 4.5;
7
+ /**
8
+ * One tuplet mark: a low arc over its notes, above the duration lines, broken in the middle by
9
+ * the number ("⌒3⌒").
10
+ */
11
+ function renderTuplet(mark, base) {
12
+ const left = mark.x1 - OVERHANG;
13
+ const right = mark.x2 + OVERHANG;
14
+ const middle = (left + right) / 2;
15
+ const top = base - RISE;
16
+ const arc = (d) => ({ kind: "path", role: "tuplet", d, width: 0.8, tone: "ink" });
17
+ return [
18
+ arc(`M ${left} ${base} Q ${left} ${top}, ${middle - NUMBER_GAP} ${top}`),
19
+ arc(`M ${middle + NUMBER_GAP} ${top} Q ${right} ${top}, ${right} ${base}`),
20
+ {
21
+ kind: "text",
22
+ role: "tuplet",
23
+ x: middle,
24
+ // Text is set on its centre line, so the number sits in the gap of the arc.
25
+ y: top,
26
+ text: mark.label,
27
+ size: NOTATION.tupletSize,
28
+ anchor: "middle",
29
+ font: "text",
30
+ bold: true,
31
+ tone: "ink",
32
+ },
33
+ ];
34
+ }
35
+ /**
36
+ * The tuplet marks of one part's measure. A mark over notes without duration lines (a triplet of
37
+ * quarters) stands where the duration lines are drawn; one over lined notes just above them.
38
+ */
39
+ export function renderTuplets(row, measure) {
40
+ const lineY = row.noteY - NOTATION.durationLineOffset;
41
+ return measure.tuplets.flatMap((mark) => renderTuplet(mark, mark.lined ? lineY - 2 : lineY));
42
+ }
@@ -0,0 +1,14 @@
1
+ import type { ScoreJson } from "./scoreJson.js";
2
+ import type { ScoreInput } from "./types.js";
3
+ /** The score JSON is not usable; `path` says where ("parts[1].measures[3].events[0]"). */
4
+ export declare class ScoreFormatError extends Error {
5
+ readonly path: string;
6
+ constructor(message: string, path: string);
7
+ }
8
+ /**
9
+ * Turns the JSON a person writes into the full score document the renderer and player read:
10
+ * defaults filled, ids made, syllables spelled out. It checks the shape, not the music (a bar that
11
+ * does not add up to its time signature still plays), and throws `ScoreFormatError` when the
12
+ * JSON could not be drawn.
13
+ */
14
+ export declare function normalizeScore(json: ScoreJson): ScoreInput;
@@ -0,0 +1,123 @@
1
+ import { DEFAULT_PAGE_LAYOUT } from "../geometry/pageSetup.js";
2
+ import { DEFAULT_PAPER } from "../geometry/paper.js";
3
+ import { KEY_PITCH_CLASS } from "../notation/pitch.js";
4
+ import { isValidTime } from "../notation/time.js";
5
+ /** The score JSON is not usable; `path` says where ("parts[1].measures[3].events[0]"). */
6
+ export class ScoreFormatError extends Error {
7
+ constructor(message, path) {
8
+ super(path ? `${path}: ${message}` : message);
9
+ this.path = path;
10
+ this.name = "ScoreFormatError";
11
+ }
12
+ }
13
+ const fail = (path, message) => {
14
+ throw new ScoreFormatError(message, path);
15
+ };
16
+ const lyricOf = (value) => {
17
+ if (value === null || value === undefined)
18
+ return null;
19
+ if (typeof value !== "string")
20
+ return value;
21
+ const hyphen = value.endsWith("-");
22
+ return { text: hyphen ? value.slice(0, -1) : value, hyphen, extender: false };
23
+ };
24
+ function eventOf(event, path, id) {
25
+ if (!Number.isInteger(event.duration) || event.duration <= 0)
26
+ fail(path, "duration must be a positive whole number of ticks (480 = a quarter note)");
27
+ const common = { id: event.id ?? id, duration: event.duration, beam: event.beam ?? null, ...(event.tuplet ? { tuplet: event.tuplet } : {}) };
28
+ if (event.type === "rest")
29
+ return { ...common, type: "rest", octave: 0, accidental: null, tie: false, lyrics: [] };
30
+ if (event.type !== "note")
31
+ return fail(path, `type must be "note" or "rest"`);
32
+ if (!Number.isInteger(event.degree) || event.degree < 1 || event.degree > 7)
33
+ fail(path, "degree must be a whole number from 1 to 7");
34
+ return {
35
+ ...common,
36
+ type: "note",
37
+ degree: event.degree,
38
+ octave: event.octave ?? 0,
39
+ accidental: event.accidental ?? null,
40
+ tie: event.tie ?? false,
41
+ lyrics: (event.lyrics ?? []).map(lyricOf),
42
+ };
43
+ }
44
+ function partOf(part, index, measureCount) {
45
+ const path = `parts[${index}]`;
46
+ const id = part.id ?? `p${index + 1}`;
47
+ if (part.measures.length !== measureCount)
48
+ fail(`${path}.measures`, `has ${part.measures.length} measures but the score has ${measureCount}: every part needs one entry per measure`);
49
+ const { color, span } = part;
50
+ return {
51
+ id,
52
+ name: part.name ?? "",
53
+ abbreviation: part.abbreviation ?? "",
54
+ kind: part.kind ?? "vocal",
55
+ visible: part.visible ?? true,
56
+ slurs: part.slurs ?? [],
57
+ ...(color !== undefined ? { color } : {}),
58
+ ...(span !== undefined ? { span } : {}),
59
+ measures: part.measures.map((m, bar) => ({
60
+ events: (m.events ?? []).map((e, i) => eventOf(e, `${path}.measures[${bar}].events[${i}]`, `${id}_${bar + 1}_${i + 1}`)),
61
+ })),
62
+ };
63
+ }
64
+ const chordOf = (chord) => ({ at: 0, quality: "", accidental: null, bass: null, ...chord });
65
+ const measureOf = ({ chords, ...m }, index) => ({
66
+ time: null,
67
+ barline: "single",
68
+ repeat_start: false,
69
+ volta: null,
70
+ label: "",
71
+ break_after: null,
72
+ ...m,
73
+ id: m.id ?? `m${index + 1}`,
74
+ ...(chords ? { chords: chords.map(chordOf) } : {}),
75
+ });
76
+ /** The defaults, with the given page layout laid over them one level deep (margins, header, footer). */
77
+ function pageOf(page) {
78
+ const d = DEFAULT_PAGE_LAYOUT;
79
+ const p = page ?? {};
80
+ return {
81
+ ...d,
82
+ ...p,
83
+ margins: { ...d.margins, ...p.margins },
84
+ header: { ...d.header, ...p.header },
85
+ footer: { ...d.footer, ...p.footer },
86
+ };
87
+ }
88
+ function settingsOf(settings = {}) {
89
+ const key = settings.key ?? "C";
90
+ if (!(key in KEY_PITCH_CLASS))
91
+ fail("settings.key", `"${key}" is not a key (${Object.keys(KEY_PITCH_CLASS).join(", ")})`);
92
+ const time = settings.time ?? "4/4";
93
+ if (!isValidTime(time))
94
+ fail("settings.time", `"${time}" is not a time signature such as "4/4" or "6/8"`);
95
+ return {
96
+ key,
97
+ time,
98
+ tempo: settings.tempo ?? 96,
99
+ tempo_marking: settings.tempo_marking ?? "",
100
+ ...(settings.pickup ? { pickup: settings.pickup } : {}),
101
+ paper: settings.paper ?? DEFAULT_PAPER,
102
+ page: pageOf(settings.page),
103
+ };
104
+ }
105
+ /**
106
+ * Turns the JSON a person writes into the full score document the renderer and player read:
107
+ * defaults filled, ids made, syllables spelled out. It checks the shape, not the music (a bar that
108
+ * does not add up to its time signature still plays), and throws `ScoreFormatError` when the
109
+ * JSON could not be drawn.
110
+ */
111
+ export function normalizeScore(json) {
112
+ if (!json || !Array.isArray(json.measures) || json.measures.length === 0)
113
+ fail("measures", "needs at least one measure");
114
+ if (!Array.isArray(json.parts) || json.parts.length === 0)
115
+ fail("parts", "needs at least one part");
116
+ return {
117
+ title: json.title ?? "",
118
+ subtitle: json.subtitle ?? "",
119
+ settings: settingsOf(json.settings),
120
+ measures: json.measures.map(measureOf),
121
+ parts: json.parts.map((p, i) => partOf(p, i, json.measures.length)),
122
+ };
123
+ }
@@ -0,0 +1,11 @@
1
+ /** Score facts the title block, header and footer can show. */
2
+ export type PageMeta = {
3
+ title: string;
4
+ subtitle: string;
5
+ key: string;
6
+ time: string;
7
+ /** Ticks of the pickup (absent or 0 = none): not shown, but every layout frames the bars with it. */
8
+ pickup?: number;
9
+ tempo: number;
10
+ tempoMarking: string;
11
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import type { Chord, Degree, Direction, Lyric, PageLayout, PaperSize, RestEvent, ScoreMeasure, ScorePart, ScoreSettings } from "./types.js";
2
+ type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
3
+ /** A syllable: plain text ("Twin-" ends in a hyphen to join the next one) or the full object. */
4
+ export type LyricJson = string | Lyric | null;
5
+ /** A note as you write it by hand: only `type`, `degree` and `duration` (ticks) are needed. */
6
+ export type NoteJson = {
7
+ id?: string;
8
+ type: "note";
9
+ /** 1-7: the numbered-notation digit. */
10
+ degree: Degree;
11
+ /** Ticks: 480 = a quarter note, 960 = a half, 240 = an eighth. */
12
+ duration: number;
13
+ /** Dots above (+1) or below (-1) the digit. */
14
+ octave?: number;
15
+ accidental?: "sharp" | "flat" | null;
16
+ tie?: boolean;
17
+ lyrics?: LyricJson[];
18
+ beam?: "break" | "join" | null;
19
+ tuplet?: {
20
+ id: string;
21
+ of: number;
22
+ in: number;
23
+ } | null;
24
+ };
25
+ export type RestJson = Optional<RestEvent, "id" | "octave" | "accidental" | "tie" | "beam" | "lyrics">;
26
+ export type EventJson = NoteJson | RestJson;
27
+ /** A chord symbol above a bar: only the root is needed (`at` ticks into the bar, 0 by default). */
28
+ export type ChordJson = Optional<Chord, "at" | "quality" | "accidental" | "bass">;
29
+ export type MeasureJson = Optional<Omit<ScoreMeasure, "chords">, "id" | "time" | "barline" | "repeat_start" | "volta" | "label" | "break_after"> & {
30
+ /** Chord symbols above the bar, in time order. */
31
+ chords?: ChordJson[];
32
+ };
33
+ export type PartJson = Optional<Omit<ScorePart, "measures">, "id" | "name" | "abbreviation" | "kind" | "visible" | "slurs"> & {
34
+ /** One entry per score measure, in the same order. */
35
+ measures: {
36
+ events: EventJson[];
37
+ }[];
38
+ };
39
+ type Nested<T> = {
40
+ [K in keyof T]?: T[K] extends readonly unknown[] ? T[K] : T[K] extends object ? Partial<T[K]> : T[K];
41
+ };
42
+ export type SettingsJson = Partial<Omit<ScoreSettings, "page">> & {
43
+ page?: Nested<PageLayout> & {
44
+ margins?: Partial<PageLayout["margins"]>;
45
+ };
46
+ };
47
+ /**
48
+ * A score as JSON, the way the player accepts it. Every field the player can work out has a
49
+ * default: ids are numbered, a note needs only its digit and length, settings fall back to C major,
50
+ * 4/4, tempo 96 on A4. `normalizeScore` turns it into the full document (`ScoreInput`).
51
+ */
52
+ export type ScoreJson = {
53
+ title?: string;
54
+ subtitle?: string;
55
+ settings?: SettingsJson;
56
+ measures: MeasureJson[];
57
+ parts: PartJson[];
58
+ };
59
+ export type { Chord, Direction, PaperSize };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { type PageSetup } from "../geometry/pageSetup.js";
2
+ import type { PageMeta } from "./pageMeta.js";
3
+ import type { ScoreInput, ScoreMusic } from "./types.js";
4
+ /** A tempo the player and the editor accept: whole BPM from 30 to 300 (120 when unreadable). */
5
+ export declare const clampTempo: (t: number) => number;
6
+ /** What the player draws and plays of a score: the same page setup and facts the editor uses. */
7
+ export type ScoreView = {
8
+ music: ScoreMusic;
9
+ setup: PageSetup;
10
+ meta: PageMeta;
11
+ };
12
+ /**
13
+ * A published score as pages and page facts, read like the editor reads a saved score: a page
14
+ * setting the snapshot lacks takes its default, so the player shows what the editor showed.
15
+ */
16
+ export declare function scoreViewOf(score: ScoreInput): ScoreView;
@@ -0,0 +1,24 @@
1
+ import { DEFAULT_PAPER } from "../geometry/paper.js";
2
+ import { DEFAULT_PAGE_LAYOUT, pageSetup } from "../geometry/pageSetup.js";
3
+ /** A tempo the player and the editor accept: whole BPM from 30 to 300 (120 when unreadable). */
4
+ export const clampTempo = (t) => Math.min(300, Math.max(30, Math.round(t) || 120));
5
+ /**
6
+ * A published score as pages and page facts, read like the editor reads a saved score: a page
7
+ * setting the snapshot lacks takes its default, so the player shows what the editor showed.
8
+ */
9
+ export function scoreViewOf(score) {
10
+ const { settings } = score;
11
+ return {
12
+ music: { measures: score.measures, parts: score.parts },
13
+ setup: pageSetup(settings.paper ?? DEFAULT_PAPER, { ...DEFAULT_PAGE_LAYOUT, ...settings.page }),
14
+ meta: {
15
+ title: score.title.trim() || "Untitled score",
16
+ subtitle: score.subtitle.trim(),
17
+ key: settings.key,
18
+ time: settings.time,
19
+ pickup: settings.pickup ?? 0,
20
+ tempo: clampTempo(settings.tempo),
21
+ tempoMarking: (settings.tempo_marking ?? "").trim(),
22
+ },
23
+ };
24
+ }