vexflow 4.0.1-beta.1 → 4.0.1-beta.2

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 (331) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +92 -24
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +38 -16
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow-font-gonville.js +1 -1
  10. package/build/cjs/vexflow-font-gonville.js.map +1 -1
  11. package/build/cjs/vexflow-gonville.js +2 -2
  12. package/build/cjs/vexflow-gonville.js.map +1 -1
  13. package/build/cjs/vexflow-petaluma.js +2 -2
  14. package/build/cjs/vexflow-petaluma.js.map +1 -1
  15. package/build/cjs/vexflow.js +2 -2
  16. package/build/cjs/vexflow.js.map +1 -1
  17. package/build/esm/entry/vexflow-bravura.js +11 -0
  18. package/build/esm/entry/vexflow-core.js +54 -0
  19. package/build/esm/entry/vexflow-debug-with-tests.js +4 -0
  20. package/build/esm/entry/vexflow-debug.js +3 -0
  21. package/build/esm/entry/vexflow-font-bravura.js +7 -0
  22. package/build/esm/entry/vexflow-font-custom.js +7 -0
  23. package/build/esm/entry/vexflow-font-gonville.js +7 -0
  24. package/build/esm/entry/vexflow-font-petaluma.js +7 -0
  25. package/build/esm/entry/vexflow-gonville.js +11 -0
  26. package/build/esm/entry/vexflow-petaluma.js +11 -0
  27. package/build/esm/entry/vexflow.js +9 -0
  28. package/build/esm/src/accidental.js +348 -0
  29. package/build/esm/src/annotation.js +232 -0
  30. package/build/esm/src/articulation.js +267 -0
  31. package/build/esm/src/barnote.js +58 -0
  32. package/build/esm/src/beam.js +632 -0
  33. package/build/esm/src/bend.js +202 -0
  34. package/build/esm/src/boundingbox.js +59 -0
  35. package/build/esm/src/boundingboxcomputation.js +107 -0
  36. package/build/esm/src/canvascontext.js +202 -0
  37. package/build/esm/src/chordsymbol.js +578 -0
  38. package/build/esm/src/clef.js +153 -0
  39. package/build/esm/src/clefnote.js +65 -0
  40. package/build/esm/src/crescendo.js +77 -0
  41. package/build/esm/src/curve.js +118 -0
  42. package/build/esm/src/dot.js +137 -0
  43. package/build/esm/src/easyscore.js +374 -0
  44. package/build/esm/src/element.js +216 -0
  45. package/build/esm/src/factory.js +440 -0
  46. package/build/esm/src/flow.js +275 -0
  47. package/build/esm/src/font.js +264 -0
  48. package/build/esm/src/fonts/bravura_glyphs.js +3239 -0
  49. package/build/esm/src/fonts/bravura_metrics.js +507 -0
  50. package/build/esm/src/fonts/custom_glyphs.js +78 -0
  51. package/build/esm/src/fonts/custom_metrics.js +5 -0
  52. package/build/esm/src/fonts/gonville_glyphs.js +828 -0
  53. package/build/esm/src/fonts/gonville_metrics.js +421 -0
  54. package/build/esm/src/fonts/load_all.js +10 -0
  55. package/build/esm/src/fonts/load_bravura.js +6 -0
  56. package/build/esm/src/fonts/load_custom.js +6 -0
  57. package/build/esm/src/fonts/load_gonville.js +6 -0
  58. package/build/esm/src/fonts/load_petaluma.js +6 -0
  59. package/build/esm/src/fonts/petaluma_glyphs.js +1335 -0
  60. package/build/esm/src/fonts/petaluma_metrics.js +536 -0
  61. package/build/esm/src/fonts/petalumascript_glyphs.js +863 -0
  62. package/build/esm/src/fonts/robotoslab_glyphs.js +863 -0
  63. package/build/esm/src/fonts/textfonts.js +44 -0
  64. package/build/esm/src/formatter.js +568 -0
  65. package/build/esm/src/fraction.js +171 -0
  66. package/build/esm/src/frethandfinger.js +156 -0
  67. package/build/esm/src/ghostnote.js +50 -0
  68. package/build/esm/src/glyph.js +331 -0
  69. package/build/esm/src/glyphnote.js +55 -0
  70. package/build/esm/src/gracenote.js +133 -0
  71. package/build/esm/src/gracenotegroup.js +128 -0
  72. package/build/esm/src/gracetabnote.js +12 -0
  73. package/build/esm/src/index.js +91 -0
  74. package/build/esm/src/keymanager.js +99 -0
  75. package/build/esm/src/keysignature.js +250 -0
  76. package/build/esm/src/keysignote.js +28 -0
  77. package/build/esm/src/modifier.js +128 -0
  78. package/build/esm/src/modifiercontext.js +110 -0
  79. package/build/esm/src/multimeasurerest.js +173 -0
  80. package/build/esm/src/music.js +322 -0
  81. package/build/esm/src/note.js +371 -0
  82. package/build/esm/src/notehead.js +169 -0
  83. package/build/esm/src/notesubgroup.js +59 -0
  84. package/build/esm/src/ornament.js +206 -0
  85. package/build/esm/src/parenthesis.js +76 -0
  86. package/build/esm/src/parser.js +164 -0
  87. package/build/esm/src/pedalmarking.js +192 -0
  88. package/build/esm/src/registry.js +81 -0
  89. package/build/esm/src/rendercontext.js +24 -0
  90. package/build/esm/src/renderer.js +112 -0
  91. package/build/esm/src/repeatnote.js +22 -0
  92. package/build/esm/src/stave.js +547 -0
  93. package/build/esm/src/stavebarline.js +182 -0
  94. package/build/esm/src/staveconnector.js +196 -0
  95. package/build/esm/src/stavehairpin.js +120 -0
  96. package/build/esm/src/staveline.js +218 -0
  97. package/build/esm/src/stavemodifier.js +77 -0
  98. package/build/esm/src/stavenote.js +855 -0
  99. package/build/esm/src/staverepetition.js +155 -0
  100. package/build/esm/src/stavesection.js +58 -0
  101. package/build/esm/src/stavetempo.js +91 -0
  102. package/build/esm/src/stavetext.js +82 -0
  103. package/build/esm/src/stavetie.js +141 -0
  104. package/build/esm/src/stavevolta.js +67 -0
  105. package/build/esm/src/stem.js +131 -0
  106. package/build/esm/src/stemmablenote.js +193 -0
  107. package/build/esm/src/stringnumber.js +231 -0
  108. package/build/esm/src/strokes.js +200 -0
  109. package/build/esm/src/svgcontext.js +414 -0
  110. package/build/esm/src/system.js +116 -0
  111. package/build/esm/src/tables.js +1102 -0
  112. package/build/esm/src/tabnote.js +299 -0
  113. package/build/esm/src/tabslide.js +76 -0
  114. package/build/esm/src/tabstave.js +17 -0
  115. package/build/esm/src/tabtie.js +19 -0
  116. package/build/esm/src/textbracket.js +144 -0
  117. package/build/esm/src/textdynamics.js +81 -0
  118. package/build/esm/src/textformatter.js +177 -0
  119. package/build/esm/src/textnote.js +176 -0
  120. package/build/esm/src/tickable.js +214 -0
  121. package/build/esm/src/tickcontext.js +170 -0
  122. package/build/esm/src/timesigglyph.js +85 -0
  123. package/build/esm/src/timesignature.js +89 -0
  124. package/build/esm/src/timesignote.js +32 -0
  125. package/build/esm/src/tremolo.js +47 -0
  126. package/build/esm/src/tuning.js +54 -0
  127. package/build/esm/src/tuplet.js +240 -0
  128. package/build/esm/src/typeguard.js +30 -0
  129. package/build/esm/src/util.js +58 -0
  130. package/build/esm/src/version.js +3 -3
  131. package/build/esm/src/vex.js +51 -0
  132. package/build/esm/src/vibrato.js +100 -0
  133. package/build/esm/src/vibratobracket.js +50 -0
  134. package/build/esm/src/voice.js +187 -0
  135. package/build/esm/src/web.js +15 -0
  136. package/build/esm/tests/accidental_tests.js +974 -0
  137. package/build/esm/tests/annotation_tests.js +377 -0
  138. package/build/esm/tests/articulation_tests.js +365 -0
  139. package/build/esm/tests/auto_beam_formatting_tests.js +548 -0
  140. package/build/esm/tests/bach_tests.js +335 -0
  141. package/build/esm/tests/barline_tests.js +52 -0
  142. package/build/esm/tests/beam_tests.js +595 -0
  143. package/build/esm/tests/bend_tests.js +215 -0
  144. package/build/esm/tests/boundingbox_tests.js +53 -0
  145. package/build/esm/tests/boundingboxcomputation_tests.js +183 -0
  146. package/build/esm/tests/chordsymbol_tests.js +320 -0
  147. package/build/esm/tests/clef_tests.js +131 -0
  148. package/build/esm/tests/curve_tests.js +118 -0
  149. package/build/esm/tests/dot_tests.js +123 -0
  150. package/build/esm/tests/easyscore_tests.js +459 -0
  151. package/build/esm/tests/factory_tests.js +44 -0
  152. package/build/esm/tests/font_tests.js +135 -0
  153. package/build/esm/tests/formatter/framestack.js +61 -0
  154. package/build/esm/tests/formatter/tests.js +203 -0
  155. package/build/esm/tests/formatter_tests.js +669 -0
  156. package/build/esm/tests/fraction_tests.js +72 -0
  157. package/build/esm/tests/ghostnote_tests.js +77 -0
  158. package/build/esm/tests/glyphnote_tests.js +113 -0
  159. package/build/esm/tests/gracenote_tests.js +413 -0
  160. package/build/esm/tests/gracetabnote_tests.js +79 -0
  161. package/build/esm/tests/index.js +68 -0
  162. package/build/esm/tests/key_clef_tests.js +103 -0
  163. package/build/esm/tests/keymanager_tests.js +68 -0
  164. package/build/esm/tests/keysignature_tests.js +308 -0
  165. package/build/esm/tests/mocks.js +71 -0
  166. package/build/esm/tests/modifier_tests.js +24 -0
  167. package/build/esm/tests/multimeasurerest_tests.js +141 -0
  168. package/build/esm/tests/music_tests.js +161 -0
  169. package/build/esm/tests/notehead_tests.js +137 -0
  170. package/build/esm/tests/notesubgroup_tests.js +149 -0
  171. package/build/esm/tests/offscreencanvas_tests.js +47 -0
  172. package/build/esm/tests/ornament_tests.js +298 -0
  173. package/build/esm/tests/parser_tests.js +122 -0
  174. package/build/esm/tests/pedalmarking_tests.js +64 -0
  175. package/build/esm/tests/percussion_tests.js +180 -0
  176. package/build/esm/tests/registry_tests.js +64 -0
  177. package/build/esm/tests/renderer_tests.js +113 -0
  178. package/build/esm/tests/rests_tests.js +248 -0
  179. package/build/esm/tests/rhythm_tests.js +357 -0
  180. package/build/esm/tests/stave_tests.js +560 -0
  181. package/build/esm/tests/staveconnector_tests.js +402 -0
  182. package/build/esm/tests/stavehairpin_tests.js +90 -0
  183. package/build/esm/tests/staveline_tests.js +122 -0
  184. package/build/esm/tests/stavemodifier_tests.js +51 -0
  185. package/build/esm/tests/stavenote_tests.js +867 -0
  186. package/build/esm/tests/stavetie_tests.js +108 -0
  187. package/build/esm/tests/stringnumber_tests.js +259 -0
  188. package/build/esm/tests/strokes_tests.js +275 -0
  189. package/build/esm/tests/style_tests.js +98 -0
  190. package/build/esm/tests/support/qunit.js +2765 -0
  191. package/build/esm/tests/tabnote_tests.js +474 -0
  192. package/build/esm/tests/tabslide_tests.js +135 -0
  193. package/build/esm/tests/tabstave_tests.js +23 -0
  194. package/build/esm/tests/tabtie_tests.js +173 -0
  195. package/build/esm/tests/textbracket_tests.js +100 -0
  196. package/build/esm/tests/textformatter_tests.js +24 -0
  197. package/build/esm/tests/textnote_tests.js +215 -0
  198. package/build/esm/tests/threevoice_tests.js +132 -0
  199. package/build/esm/tests/tickcontext_tests.js +36 -0
  200. package/build/esm/tests/timesignature_tests.js +134 -0
  201. package/build/esm/tests/tremolo_tests.js +75 -0
  202. package/build/esm/tests/tuning_tests.js +56 -0
  203. package/build/esm/tests/tuplet_tests.js +450 -0
  204. package/build/esm/tests/typeguard_tests.js +82 -0
  205. package/build/esm/tests/vexflow_test_helpers.js +266 -0
  206. package/build/esm/tests/vf_prefix_tests.js +115 -0
  207. package/build/esm/tests/vibrato_tests.js +92 -0
  208. package/build/esm/tests/vibratobracket_tests.js +45 -0
  209. package/build/esm/tests/voice_tests.js +69 -0
  210. package/build/types/entry/vexflow-bravura.d.ts +3 -0
  211. package/build/types/entry/vexflow-core.d.ts +3 -0
  212. package/build/types/entry/vexflow-debug.d.ts +3 -0
  213. package/build/types/entry/vexflow-font-bravura.d.ts +3771 -0
  214. package/build/types/entry/vexflow-font-custom.d.ts +86 -0
  215. package/build/types/entry/vexflow-font-gonville.d.ts +1267 -0
  216. package/build/types/entry/vexflow-font-petaluma.d.ts +1896 -0
  217. package/build/types/entry/vexflow-gonville.d.ts +3 -0
  218. package/build/types/entry/vexflow-petaluma.d.ts +3 -0
  219. package/build/types/entry/vexflow.d.ts +3 -0
  220. package/build/types/src/accidental.d.ts +66 -0
  221. package/build/types/src/annotation.d.ts +60 -0
  222. package/build/types/src/articulation.d.ts +62 -0
  223. package/build/types/src/barnote.d.ts +29 -0
  224. package/build/types/src/beam.d.ts +124 -0
  225. package/build/types/src/bend.d.ts +73 -0
  226. package/build/types/src/boundingbox.d.ts +42 -0
  227. package/build/types/src/boundingboxcomputation.d.ts +33 -0
  228. package/build/types/src/canvascontext.d.ts +89 -0
  229. package/build/types/src/chordsymbol.d.ts +149 -0
  230. package/build/types/src/clef.d.ts +48 -0
  231. package/build/types/src/clefnote.d.ts +25 -0
  232. package/build/types/src/crescendo.d.ts +27 -0
  233. package/build/types/src/curve.d.ts +41 -0
  234. package/build/types/src/dot.d.ts +20 -0
  235. package/build/types/src/easyscore.d.ts +148 -0
  236. package/build/types/src/element.d.ts +202 -0
  237. package/build/types/src/factory.d.ts +271 -0
  238. package/build/types/src/flow.d.ts +245 -0
  239. package/build/types/src/font.d.ts +181 -0
  240. package/build/types/src/fonts/bravura_glyphs.d.ts +3239 -0
  241. package/build/types/src/fonts/bravura_metrics.d.ts +533 -0
  242. package/build/types/src/fonts/custom_glyphs.d.ts +78 -0
  243. package/build/types/src/fonts/custom_metrics.d.ts +5 -0
  244. package/build/types/src/fonts/gonville_glyphs.d.ts +828 -0
  245. package/build/types/src/fonts/gonville_metrics.d.ts +440 -0
  246. package/build/types/src/fonts/load_all.d.ts +1 -0
  247. package/build/types/src/fonts/load_bravura.d.ts +1 -0
  248. package/build/types/src/fonts/load_custom.d.ts +1 -0
  249. package/build/types/src/fonts/load_gonville.d.ts +1 -0
  250. package/build/types/src/fonts/load_petaluma.d.ts +1 -0
  251. package/build/types/src/fonts/petaluma_glyphs.d.ts +1335 -0
  252. package/build/types/src/fonts/petaluma_metrics.d.ts +562 -0
  253. package/build/types/src/fonts/petalumascript_glyphs.d.ts +863 -0
  254. package/build/types/src/fonts/robotoslab_glyphs.d.ts +863 -0
  255. package/build/types/src/fonts/textfonts.d.ts +1 -0
  256. package/build/types/src/formatter.d.ts +203 -0
  257. package/build/types/src/fraction.d.ts +62 -0
  258. package/build/types/src/frethandfinger.d.ts +22 -0
  259. package/build/types/src/ghostnote.d.ts +16 -0
  260. package/build/types/src/glyph.d.ts +139 -0
  261. package/build/types/src/glyphnote.d.ts +17 -0
  262. package/build/types/src/gracenote.d.ts +19 -0
  263. package/build/types/src/gracenotegroup.d.ts +33 -0
  264. package/build/types/src/gracetabnote.d.ts +5 -0
  265. package/build/types/src/index.d.ts +91 -0
  266. package/build/types/src/keymanager.d.ts +25 -0
  267. package/build/types/src/keysignature.d.ts +50 -0
  268. package/build/types/src/keysignote.d.ts +11 -0
  269. package/build/types/src/modifier.d.ts +97 -0
  270. package/build/types/src/modifiercontext.d.ts +45 -0
  271. package/build/types/src/multimeasurerest.d.ts +61 -0
  272. package/build/types/src/music.d.ts +91 -0
  273. package/build/types/src/note.d.ts +231 -0
  274. package/build/types/src/notehead.d.ts +70 -0
  275. package/build/types/src/notesubgroup.d.ts +18 -0
  276. package/build/types/src/ornament.d.ts +76 -0
  277. package/build/types/src/parenthesis.d.ts +22 -0
  278. package/build/types/src/parser.d.ts +45 -0
  279. package/build/types/src/pedalmarking.d.ts +69 -0
  280. package/build/types/src/registry.d.ts +40 -0
  281. package/build/types/src/rendercontext.d.ts +64 -0
  282. package/build/types/src/renderer.d.ts +35 -0
  283. package/build/types/src/repeatnote.d.ts +6 -0
  284. package/build/types/src/stave.d.ts +186 -0
  285. package/build/types/src/stavebarline.d.ts +28 -0
  286. package/build/types/src/staveconnector.d.ts +67 -0
  287. package/build/types/src/stavehairpin.d.ts +56 -0
  288. package/build/types/src/staveline.d.ts +57 -0
  289. package/build/types/src/stavemodifier.d.ts +44 -0
  290. package/build/types/src/stavenote.d.ts +154 -0
  291. package/build/types/src/staverepetition.d.ts +32 -0
  292. package/build/types/src/stavesection.d.ts +15 -0
  293. package/build/types/src/stavetempo.d.ts +25 -0
  294. package/build/types/src/stavetext.d.ts +25 -0
  295. package/build/types/src/stavetie.d.ts +59 -0
  296. package/build/types/src/stavevolta.d.ts +21 -0
  297. package/build/types/src/stem.d.ts +58 -0
  298. package/build/types/src/stemmablenote.d.ts +39 -0
  299. package/build/types/src/stringnumber.d.ts +27 -0
  300. package/build/types/src/strokes.d.ts +33 -0
  301. package/build/types/src/svgcontext.d.ts +131 -0
  302. package/build/types/src/system.d.ts +92 -0
  303. package/build/types/src/tables.d.ts +96 -0
  304. package/build/types/src/tabnote.d.ts +44 -0
  305. package/build/types/src/tabslide.d.ts +34 -0
  306. package/build/types/src/tabstave.d.ts +7 -0
  307. package/build/types/src/tabtie.d.ts +18 -0
  308. package/build/types/src/textbracket.d.ts +55 -0
  309. package/build/types/src/textdynamics.d.ts +39 -0
  310. package/build/types/src/textformatter.d.ts +109 -0
  311. package/build/types/src/textnote.d.ts +49 -0
  312. package/build/types/src/tickable.d.ts +140 -0
  313. package/build/types/src/tickcontext.d.ts +82 -0
  314. package/build/types/src/timesigglyph.d.ts +14 -0
  315. package/build/types/src/timesignature.d.ts +26 -0
  316. package/build/types/src/timesignote.d.ts +11 -0
  317. package/build/types/src/tremolo.d.ts +17 -0
  318. package/build/types/src/tuning.d.ts +23 -0
  319. package/build/types/src/tuplet.d.ts +105 -0
  320. package/build/types/src/typeguard.d.ts +99 -0
  321. package/build/types/src/util.d.ts +27 -0
  322. package/build/types/src/version.d.ts +3 -0
  323. package/build/types/src/vex.d.ts +18 -0
  324. package/build/types/src/vibrato.d.ts +29 -0
  325. package/build/types/src/vibratobracket.d.ts +33 -0
  326. package/build/types/src/voice.d.ts +108 -0
  327. package/build/types/src/web.d.ts +2 -0
  328. package/package.json +1 -1
  329. package/src/annotation.ts +27 -6
  330. package/src/articulation.ts +8 -2
  331. package/src/fonts/gonville_glyphs.ts +4 -4
@@ -0,0 +1,171 @@
1
+ import { RuntimeError } from './util.js';
2
+ export class Fraction {
3
+ constructor(numerator, denominator) {
4
+ this.numerator = 1;
5
+ this.denominator = 1;
6
+ this.set(numerator, denominator);
7
+ }
8
+ static get CATEGORY() {
9
+ return "Fraction";
10
+ }
11
+ static GCD(a, b) {
12
+ if (typeof a !== 'number' || Number.isNaN(a) || typeof b !== 'number' || Number.isNaN(b)) {
13
+ throw new RuntimeError('BadArgument', `Invalid numbers: ${a}, ${b}`);
14
+ }
15
+ let t;
16
+ while (b !== 0) {
17
+ t = b;
18
+ b = a % b;
19
+ a = t;
20
+ }
21
+ return a;
22
+ }
23
+ static LCM(a, b) {
24
+ return (a * b) / Fraction.GCD(a, b);
25
+ }
26
+ static LCMM(args) {
27
+ if (args.length === 0) {
28
+ return 0;
29
+ }
30
+ else if (args.length === 1) {
31
+ return args[0];
32
+ }
33
+ else if (args.length === 2) {
34
+ return Fraction.LCM(args[0], args[1]);
35
+ }
36
+ else {
37
+ return Fraction.LCM(args.shift(), Fraction.LCMM(args));
38
+ }
39
+ }
40
+ set(numerator = 1, denominator = 1) {
41
+ this.numerator = numerator;
42
+ this.denominator = denominator;
43
+ return this;
44
+ }
45
+ value() {
46
+ return this.numerator / this.denominator;
47
+ }
48
+ simplify() {
49
+ let u = this.numerator;
50
+ let d = this.denominator;
51
+ const gcd = Fraction.GCD(u, d);
52
+ u /= gcd;
53
+ d /= gcd;
54
+ if (d < 0) {
55
+ d = -d;
56
+ u = -u;
57
+ }
58
+ return this.set(u, d);
59
+ }
60
+ add(param1 = 0, param2 = 1) {
61
+ const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
62
+ const lcm = Fraction.LCM(this.denominator, otherDenominator);
63
+ const a = lcm / this.denominator;
64
+ const b = lcm / otherDenominator;
65
+ const u = this.numerator * a + otherNumerator * b;
66
+ return this.set(u, lcm);
67
+ }
68
+ subtract(param1 = 0, param2 = 1) {
69
+ const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
70
+ const lcm = Fraction.LCM(this.denominator, otherDenominator);
71
+ const a = lcm / this.denominator;
72
+ const b = lcm / otherDenominator;
73
+ const u = this.numerator * a - otherNumerator * b;
74
+ return this.set(u, lcm);
75
+ }
76
+ multiply(param1 = 1, param2 = 1) {
77
+ const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
78
+ return this.set(this.numerator * otherNumerator, this.denominator * otherDenominator);
79
+ }
80
+ divide(param1 = 1, param2 = 1) {
81
+ const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
82
+ return this.set(this.numerator * otherDenominator, this.denominator * otherNumerator);
83
+ }
84
+ equals(compare) {
85
+ const a = Fraction.__staticFractionA.copy(compare).simplify();
86
+ const b = Fraction.__staticFractionB.copy(this).simplify();
87
+ return a.numerator === b.numerator && a.denominator === b.denominator;
88
+ }
89
+ greaterThan(compare) {
90
+ const a = Fraction.__staticFractionB.copy(this);
91
+ a.subtract(compare);
92
+ return a.numerator > 0;
93
+ }
94
+ greaterThanEquals(compare) {
95
+ const a = Fraction.__staticFractionB.copy(this);
96
+ a.subtract(compare);
97
+ return a.numerator >= 0;
98
+ }
99
+ lessThan(compare) {
100
+ return !this.greaterThanEquals(compare);
101
+ }
102
+ lessThanEquals(compare) {
103
+ return !this.greaterThan(compare);
104
+ }
105
+ clone() {
106
+ return new Fraction(this.numerator, this.denominator);
107
+ }
108
+ copy(other) {
109
+ if (typeof other === 'number') {
110
+ return this.set(other, 1);
111
+ }
112
+ else {
113
+ return this.set(other.numerator, other.denominator);
114
+ }
115
+ }
116
+ quotient() {
117
+ return Math.floor(this.numerator / this.denominator);
118
+ }
119
+ remainder() {
120
+ return this.numerator % this.denominator;
121
+ }
122
+ makeAbs() {
123
+ this.denominator = Math.abs(this.denominator);
124
+ this.numerator = Math.abs(this.numerator);
125
+ return this;
126
+ }
127
+ toString() {
128
+ return `${this.numerator}/${this.denominator}`;
129
+ }
130
+ toSimplifiedString() {
131
+ return Fraction.__staticFractionTmp.copy(this).simplify().toString();
132
+ }
133
+ toMixedString() {
134
+ let s = '';
135
+ const q = this.quotient();
136
+ const f = Fraction.__staticFractionTmp.copy(this);
137
+ if (q < 0) {
138
+ f.makeAbs();
139
+ }
140
+ if (q !== 0) {
141
+ s += q;
142
+ if (f.numerator !== 0) {
143
+ s += ` ${f.toSimplifiedString()}`;
144
+ }
145
+ }
146
+ else if (f.numerator === 0) {
147
+ s = '0';
148
+ }
149
+ else {
150
+ s = f.toSimplifiedString();
151
+ }
152
+ return s;
153
+ }
154
+ parse(str) {
155
+ const i = str.split('/');
156
+ const n = parseInt(i[0], 10);
157
+ const d = i[1] ? parseInt(i[1], 10) : 1;
158
+ return this.set(n, d);
159
+ }
160
+ }
161
+ Fraction.__staticFractionA = new Fraction();
162
+ Fraction.__staticFractionB = new Fraction();
163
+ Fraction.__staticFractionTmp = new Fraction();
164
+ function getNumeratorAndDenominator(n, d = 1) {
165
+ if (typeof n === 'number') {
166
+ return [n, d];
167
+ }
168
+ else {
169
+ return [n.numerator, n.denominator];
170
+ }
171
+ }
@@ -0,0 +1,156 @@
1
+ import { Font, FontStyle, FontWeight } from './font.js';
2
+ import { Modifier, ModifierPosition } from './modifier.js';
3
+ import { Tables } from './tables.js';
4
+ import { TextFormatter } from './textformatter.js';
5
+ import { RuntimeError } from './util.js';
6
+ export class FretHandFinger extends Modifier {
7
+ constructor(finger) {
8
+ super();
9
+ this.finger = finger;
10
+ this.width = 7;
11
+ this.position = Modifier.Position.LEFT;
12
+ this.x_shift = 0;
13
+ this.y_shift = 0;
14
+ this.x_offset = 0;
15
+ this.y_offset = 0;
16
+ this.resetFont();
17
+ }
18
+ static get CATEGORY() {
19
+ return "FretHandFinger";
20
+ }
21
+ static format(nums, state) {
22
+ const { left_shift, right_shift } = state;
23
+ const num_spacing = 1;
24
+ if (!nums || nums.length === 0)
25
+ return false;
26
+ const nums_list = [];
27
+ let prev_note = null;
28
+ let shiftLeft = 0;
29
+ let shiftRight = 0;
30
+ for (let i = 0; i < nums.length; ++i) {
31
+ const num = nums[i];
32
+ const note = num.getNote();
33
+ const pos = num.getPosition();
34
+ const index = num.checkIndex();
35
+ const props = note.getKeyProps()[index];
36
+ const textFormatter = TextFormatter.create(num.textFont);
37
+ const textHeight = textFormatter.maxHeight;
38
+ if (num.position === ModifierPosition.ABOVE) {
39
+ state.top_text_line += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
40
+ }
41
+ if (num.position === ModifierPosition.BELOW) {
42
+ state.text_line += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
43
+ }
44
+ if (note !== prev_note) {
45
+ for (let n = 0; n < note.keys.length; ++n) {
46
+ if (left_shift === 0) {
47
+ shiftLeft = Math.max(note.getLeftDisplacedHeadPx(), shiftLeft);
48
+ }
49
+ if (right_shift === 0) {
50
+ shiftRight = Math.max(note.getRightDisplacedHeadPx(), shiftRight);
51
+ }
52
+ }
53
+ prev_note = note;
54
+ }
55
+ nums_list.push({
56
+ note,
57
+ num,
58
+ pos,
59
+ line: props.line,
60
+ shiftL: shiftLeft,
61
+ shiftR: shiftRight,
62
+ });
63
+ }
64
+ nums_list.sort((a, b) => b.line - a.line);
65
+ let numShiftL = 0;
66
+ let numShiftR = 0;
67
+ let xWidthL = 0;
68
+ let xWidthR = 0;
69
+ let lastLine = null;
70
+ let lastNote = null;
71
+ for (let i = 0; i < nums_list.length; ++i) {
72
+ let num_shift = 0;
73
+ const { note, pos, num, line, shiftL, shiftR } = nums_list[i];
74
+ if (line !== lastLine || note !== lastNote) {
75
+ numShiftL = left_shift + shiftL;
76
+ numShiftR = right_shift + shiftR;
77
+ }
78
+ const numWidth = num.getWidth() + num_spacing;
79
+ if (pos === Modifier.Position.LEFT) {
80
+ num.setXShift(left_shift + numShiftL);
81
+ num_shift = left_shift + numWidth;
82
+ xWidthL = num_shift > xWidthL ? num_shift : xWidthL;
83
+ }
84
+ else if (pos === Modifier.Position.RIGHT) {
85
+ num.setXShift(numShiftR);
86
+ num_shift = shiftRight + numWidth;
87
+ xWidthR = num_shift > xWidthR ? num_shift : xWidthR;
88
+ }
89
+ lastLine = line;
90
+ lastNote = note;
91
+ }
92
+ state.left_shift += xWidthL;
93
+ state.right_shift += xWidthR;
94
+ return true;
95
+ }
96
+ static easyScoreHook({ fingerings } = {}, note, builder) {
97
+ fingerings === null || fingerings === void 0 ? void 0 : fingerings.split(',').map((fingeringString) => {
98
+ const split = fingeringString.trim().split('.');
99
+ const params = { number: split[0] };
100
+ if (split[1])
101
+ params.position = split[1];
102
+ return builder.getFactory().Fingering(params);
103
+ }).map((fingering, index) => note.addModifier(fingering, index));
104
+ }
105
+ setFretHandFinger(finger) {
106
+ this.finger = finger;
107
+ return this;
108
+ }
109
+ getFretHandFinger() {
110
+ return this.finger;
111
+ }
112
+ setOffsetX(x) {
113
+ this.x_offset = x;
114
+ return this;
115
+ }
116
+ setOffsetY(y) {
117
+ this.y_offset = y;
118
+ return this;
119
+ }
120
+ draw() {
121
+ const ctx = this.checkContext();
122
+ const note = this.checkAttachedNote();
123
+ this.setRendered();
124
+ const start = note.getModifierStartXY(this.position, this.index);
125
+ let dot_x = start.x + this.x_shift + this.x_offset;
126
+ let dot_y = start.y + this.y_shift + this.y_offset + 5;
127
+ switch (this.position) {
128
+ case Modifier.Position.ABOVE:
129
+ dot_x -= 4;
130
+ dot_y -= 12;
131
+ break;
132
+ case Modifier.Position.BELOW:
133
+ dot_x -= 2;
134
+ dot_y += 10;
135
+ break;
136
+ case Modifier.Position.LEFT:
137
+ dot_x -= this.width;
138
+ break;
139
+ case Modifier.Position.RIGHT:
140
+ dot_x += 1;
141
+ break;
142
+ default:
143
+ throw new RuntimeError('InvalidPosition', `The position ${this.position} does not exist`);
144
+ }
145
+ ctx.save();
146
+ ctx.setFont(this.textFont);
147
+ ctx.fillText('' + this.finger, dot_x, dot_y);
148
+ ctx.restore();
149
+ }
150
+ }
151
+ FretHandFinger.TEXT_FONT = {
152
+ family: Font.SANS_SERIF,
153
+ size: 9,
154
+ weight: FontWeight.BOLD,
155
+ style: FontStyle.NORMAL,
156
+ };
@@ -0,0 +1,50 @@
1
+ import { StemmableNote } from './stemmablenote.js';
2
+ import { isAnnotation } from './typeguard.js';
3
+ import { RuntimeError } from './util.js';
4
+ const ERROR_MSG = 'Ghost note must have valid initialization data to identify duration.';
5
+ export class GhostNote extends StemmableNote {
6
+ static get CATEGORY() {
7
+ return "GhostNote";
8
+ }
9
+ constructor(parameter) {
10
+ if (!parameter) {
11
+ throw new RuntimeError('BadArguments', ERROR_MSG);
12
+ }
13
+ let noteStruct;
14
+ if (typeof parameter === 'string') {
15
+ noteStruct = { duration: parameter };
16
+ }
17
+ else if (typeof parameter === 'object') {
18
+ noteStruct = parameter;
19
+ }
20
+ else {
21
+ throw new RuntimeError('BadArguments', ERROR_MSG);
22
+ }
23
+ super(noteStruct);
24
+ this.setWidth(0);
25
+ }
26
+ isRest() {
27
+ return true;
28
+ }
29
+ setStave(stave) {
30
+ super.setStave(stave);
31
+ return this;
32
+ }
33
+ addToModifierContext(mc) {
34
+ return this;
35
+ }
36
+ preFormat() {
37
+ this.preFormatted = true;
38
+ return this;
39
+ }
40
+ draw() {
41
+ this.setRendered();
42
+ for (let i = 0; i < this.modifiers.length; ++i) {
43
+ const modifier = this.modifiers[i];
44
+ if (isAnnotation(modifier)) {
45
+ modifier.setContext(this.getContext());
46
+ modifier.drawWithStyle();
47
+ }
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,331 @@
1
+ import { BoundingBox } from './boundingbox.js';
2
+ import { BoundingBoxComputation } from './boundingboxcomputation.js';
3
+ import { Element } from './element.js';
4
+ import { defined, RuntimeError } from './util.js';
5
+ class GlyphCacheEntry {
6
+ constructor(fontStack, code, category) {
7
+ this.point = -1;
8
+ this.metrics = Glyph.loadMetrics(fontStack, code, category);
9
+ this.bbox = Glyph.getOutlineBoundingBox(this.metrics.outline, this.metrics.scale, this.metrics.x_shift, this.metrics.y_shift);
10
+ if (category) {
11
+ this.point = Glyph.lookupFontMetric(this.metrics.font, category, code, 'point', -1);
12
+ }
13
+ }
14
+ }
15
+ class GlyphCache {
16
+ constructor() {
17
+ this.cache = new Map();
18
+ }
19
+ lookup(code, category) {
20
+ let entries = this.cache.get(Glyph.CURRENT_CACHE_KEY);
21
+ if (entries === undefined) {
22
+ entries = {};
23
+ this.cache.set(Glyph.CURRENT_CACHE_KEY, entries);
24
+ }
25
+ const key = category ? `${code}%${category}` : code;
26
+ let entry = entries[key];
27
+ if (entry === undefined) {
28
+ entry = new GlyphCacheEntry(Glyph.MUSIC_FONT_STACK, code, category);
29
+ entries[key] = entry;
30
+ }
31
+ return entry;
32
+ }
33
+ }
34
+ class GlyphOutline {
35
+ constructor(outline, originX, originY, scale) {
36
+ this.outline = outline;
37
+ this.originX = originX;
38
+ this.originY = originY;
39
+ this.scale = scale;
40
+ this.i = 0;
41
+ }
42
+ done() {
43
+ return this.i >= this.outline.length;
44
+ }
45
+ next() {
46
+ return this.outline[this.i++];
47
+ }
48
+ nextX() {
49
+ return this.originX + this.outline[this.i++] * this.scale;
50
+ }
51
+ nextY() {
52
+ return this.originY - this.outline[this.i++] * this.scale;
53
+ }
54
+ static parse(str) {
55
+ const result = [];
56
+ const parts = str.split(' ');
57
+ let i = 0;
58
+ while (i < parts.length) {
59
+ switch (parts[i++]) {
60
+ case 'm':
61
+ result.push(0, parseInt(parts[i++]), parseInt(parts[i++]));
62
+ break;
63
+ case 'l':
64
+ result.push(1, parseInt(parts[i++]), parseInt(parts[i++]));
65
+ break;
66
+ case 'q':
67
+ result.push(2, parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]));
68
+ break;
69
+ case 'b':
70
+ result.push(3, parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]), parseInt(parts[i++]));
71
+ break;
72
+ }
73
+ }
74
+ return result;
75
+ }
76
+ }
77
+ export class Glyph extends Element {
78
+ constructor(code, point, options) {
79
+ super();
80
+ this.bbox = new BoundingBox(0, 0, 0, 0);
81
+ this.topGlyphs = [];
82
+ this.botGlyphs = [];
83
+ this.options = {};
84
+ this.scale = 1;
85
+ this.code = code;
86
+ this.point = point;
87
+ this.originShift = { x: 0, y: 0 };
88
+ this.x_shift = 0;
89
+ this.y_shift = 0;
90
+ if (options) {
91
+ this.setOptions(options);
92
+ }
93
+ else {
94
+ this.reset();
95
+ }
96
+ }
97
+ static get CATEGORY() {
98
+ return "Glyph";
99
+ }
100
+ static lookupFontMetric(font, category, code, key, defaultValue) {
101
+ let value = font.lookupMetric(`glyphs.${category}.${code}.${key}`, undefined);
102
+ if (value === undefined) {
103
+ value = font.lookupMetric(`glyphs.${category}.${key}`, defaultValue);
104
+ }
105
+ return value;
106
+ }
107
+ static lookupGlyph(fontStack, code) {
108
+ defined(fontStack, 'BadFontStack', 'Font stack is misconfigured');
109
+ let glyph;
110
+ let font;
111
+ for (let i = 0; i < fontStack.length; i++) {
112
+ font = fontStack[i];
113
+ glyph = font.getGlyphs()[code];
114
+ if (glyph)
115
+ return { glyph, font };
116
+ }
117
+ throw new RuntimeError('BadGlyph', `Glyph ${code} does not exist in font.`);
118
+ }
119
+ static loadMetrics(fontStack, code, category) {
120
+ const { glyph, font } = Glyph.lookupGlyph(fontStack, code);
121
+ if (!glyph.o)
122
+ throw new RuntimeError('BadGlyph', `Glyph ${code} has no outline defined.`);
123
+ let x_shift = 0;
124
+ let y_shift = 0;
125
+ let scale = 1;
126
+ if (category && font) {
127
+ x_shift = Glyph.lookupFontMetric(font, category, code, 'shiftX', 0);
128
+ y_shift = Glyph.lookupFontMetric(font, category, code, 'shiftY', 0);
129
+ scale = Glyph.lookupFontMetric(font, category, code, 'scale', 1);
130
+ }
131
+ const x_min = glyph.x_min;
132
+ const x_max = glyph.x_max;
133
+ const ha = glyph.ha;
134
+ if (!glyph.cached_outline) {
135
+ glyph.cached_outline = GlyphOutline.parse(glyph.o);
136
+ }
137
+ return {
138
+ x_min,
139
+ x_max,
140
+ x_shift,
141
+ y_shift,
142
+ scale,
143
+ ha,
144
+ outline: glyph.cached_outline,
145
+ font,
146
+ width: x_max - x_min,
147
+ height: ha,
148
+ };
149
+ }
150
+ static renderGlyph(ctx, x_pos, y_pos, point, code, options) {
151
+ var _a;
152
+ const data = Glyph.cache.lookup(code, options === null || options === void 0 ? void 0 : options.category);
153
+ const metrics = data.metrics;
154
+ if (data.point != -1) {
155
+ point = data.point;
156
+ }
157
+ const customScale = (_a = options === null || options === void 0 ? void 0 : options.scale) !== null && _a !== void 0 ? _a : 1;
158
+ const scale = ((point * 72.0) / (metrics.font.getResolution() * 100.0)) * metrics.scale * customScale;
159
+ Glyph.renderOutline(ctx, metrics.outline, scale, x_pos + metrics.x_shift * customScale, y_pos + metrics.y_shift * customScale);
160
+ return metrics;
161
+ }
162
+ static renderOutline(ctx, outline, scale, x_pos, y_pos) {
163
+ const go = new GlyphOutline(outline, x_pos, y_pos, scale);
164
+ ctx.beginPath();
165
+ let x, y;
166
+ while (!go.done()) {
167
+ switch (go.next()) {
168
+ case 0:
169
+ ctx.moveTo(go.nextX(), go.nextY());
170
+ break;
171
+ case 1:
172
+ ctx.lineTo(go.nextX(), go.nextY());
173
+ break;
174
+ case 2:
175
+ x = go.nextX();
176
+ y = go.nextY();
177
+ ctx.quadraticCurveTo(go.nextX(), go.nextY(), x, y);
178
+ break;
179
+ case 3:
180
+ x = go.nextX();
181
+ y = go.nextY();
182
+ ctx.bezierCurveTo(go.nextX(), go.nextY(), go.nextX(), go.nextY(), x, y);
183
+ break;
184
+ }
185
+ }
186
+ ctx.fill();
187
+ }
188
+ static getOutlineBoundingBox(outline, scale, x_pos, y_pos) {
189
+ const go = new GlyphOutline(outline, x_pos, y_pos, scale);
190
+ const bboxComp = new BoundingBoxComputation();
191
+ let penX = x_pos;
192
+ let penY = y_pos;
193
+ let x, y;
194
+ while (!go.done()) {
195
+ switch (go.next()) {
196
+ case 0:
197
+ penX = go.nextX();
198
+ penY = go.nextY();
199
+ break;
200
+ case 1:
201
+ bboxComp.addPoint(penX, penY);
202
+ penX = go.nextX();
203
+ penY = go.nextY();
204
+ bboxComp.addPoint(penX, penY);
205
+ break;
206
+ case 2:
207
+ x = go.nextX();
208
+ y = go.nextY();
209
+ bboxComp.addQuadraticCurve(penX, penY, go.nextX(), go.nextY(), x, y);
210
+ penX = x;
211
+ penY = y;
212
+ break;
213
+ case 3:
214
+ x = go.nextX();
215
+ y = go.nextY();
216
+ bboxComp.addBezierCurve(penX, penY, go.nextX(), go.nextY(), go.nextX(), go.nextY(), x, y);
217
+ penX = x;
218
+ penY = y;
219
+ break;
220
+ }
221
+ }
222
+ return new BoundingBox(bboxComp.getX1(), bboxComp.getY1(), bboxComp.width(), bboxComp.height());
223
+ }
224
+ static getWidth(code, point, category) {
225
+ const data = Glyph.cache.lookup(code, category);
226
+ if (data.point != -1) {
227
+ point = data.point;
228
+ }
229
+ const scale = (point * 72) / (data.metrics.font.getResolution() * 100);
230
+ return data.bbox.getW() * scale;
231
+ }
232
+ draw(...args) {
233
+ }
234
+ getCode() {
235
+ return this.code;
236
+ }
237
+ setOptions(options) {
238
+ this.options = Object.assign(Object.assign({}, this.options), options);
239
+ this.reset();
240
+ }
241
+ setPoint(point) {
242
+ this.point = point;
243
+ return this;
244
+ }
245
+ setStave(stave) {
246
+ this.stave = stave;
247
+ return this;
248
+ }
249
+ setXShift(x_shift) {
250
+ this.x_shift = x_shift;
251
+ return this;
252
+ }
253
+ setYShift(y_shift) {
254
+ this.y_shift = y_shift;
255
+ return this;
256
+ }
257
+ reset() {
258
+ const data = Glyph.cache.lookup(this.code, this.options.category);
259
+ this.metrics = data.metrics;
260
+ if (data.point != -1) {
261
+ this.point = data.point;
262
+ }
263
+ this.scale = (this.point * 72) / (this.metrics.font.getResolution() * 100);
264
+ this.bbox = new BoundingBox(data.bbox.getX() * this.scale, data.bbox.getY() * this.scale, data.bbox.getW() * this.scale, data.bbox.getH() * this.scale);
265
+ }
266
+ checkMetrics() {
267
+ return defined(this.metrics, 'BadGlyph', `Glyph ${this.code} is not initialized.`);
268
+ }
269
+ getMetrics() {
270
+ const metrics = this.checkMetrics();
271
+ const metricsScale = metrics.scale;
272
+ return {
273
+ x_min: metrics.x_min * this.scale * metricsScale,
274
+ x_max: metrics.x_max * this.scale * metricsScale,
275
+ width: this.bbox.getW(),
276
+ height: this.bbox.getH(),
277
+ scale: this.scale * metricsScale,
278
+ x_shift: metrics.x_shift,
279
+ y_shift: metrics.y_shift,
280
+ outline: metrics.outline,
281
+ font: metrics.font,
282
+ ha: metrics.ha,
283
+ };
284
+ }
285
+ setOriginX(x) {
286
+ const { bbox } = this;
287
+ const originX = Math.abs(bbox.getX() / bbox.getW());
288
+ const xShift = (x - originX) * bbox.getW();
289
+ this.originShift.x = -xShift;
290
+ }
291
+ setOriginY(y) {
292
+ const { bbox } = this;
293
+ const originY = Math.abs(bbox.getY() / bbox.getH());
294
+ const yShift = (y - originY) * bbox.getH();
295
+ this.originShift.y = -yShift;
296
+ }
297
+ setOrigin(x, y) {
298
+ this.setOriginX(x);
299
+ this.setOriginY(y);
300
+ }
301
+ render(ctx, x, y) {
302
+ const metrics = this.checkMetrics();
303
+ const outline = metrics.outline;
304
+ const scale = this.scale * metrics.scale;
305
+ this.setRendered();
306
+ this.applyStyle(ctx);
307
+ const xPos = x + this.originShift.x + metrics.x_shift;
308
+ const yPos = y + this.originShift.y + metrics.y_shift;
309
+ Glyph.renderOutline(ctx, outline, scale, xPos, yPos);
310
+ this.restoreStyle(ctx);
311
+ }
312
+ checkStave() {
313
+ return defined(this.stave, 'NoStave', 'No stave attached to instance.');
314
+ }
315
+ renderToStave(x) {
316
+ const context = this.checkContext();
317
+ const metrics = this.checkMetrics();
318
+ const stave = this.checkStave();
319
+ const outline = metrics.outline;
320
+ const scale = this.scale * metrics.scale;
321
+ this.setRendered();
322
+ this.applyStyle();
323
+ const xPos = x + this.x_shift + metrics.x_shift;
324
+ const yPos = stave.getYForGlyphs() + this.y_shift + metrics.y_shift;
325
+ Glyph.renderOutline(context, outline, scale, xPos, yPos);
326
+ this.restoreStyle();
327
+ }
328
+ }
329
+ Glyph.cache = new GlyphCache();
330
+ Glyph.CURRENT_CACHE_KEY = '';
331
+ Glyph.MUSIC_FONT_STACK = [];