vexflow 4.0.1-beta.1 → 4.0.1

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 (353) hide show
  1. package/README.md +48 -65
  2. package/build/cjs/vexflow-bravura.js +2 -2
  3. package/build/cjs/vexflow-bravura.js.map +1 -1
  4. package/build/cjs/vexflow-core.js +2 -2
  5. package/build/cjs/vexflow-core.js.map +1 -1
  6. package/build/cjs/vexflow-debug-with-tests.js +724 -697
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +550 -610
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow-font-gonville.js +1 -1
  11. package/build/cjs/vexflow-font-gonville.js.map +1 -1
  12. package/build/cjs/vexflow-gonville.js +2 -2
  13. package/build/cjs/vexflow-gonville.js.map +1 -1
  14. package/build/cjs/vexflow-petaluma.js +2 -2
  15. package/build/cjs/vexflow-petaluma.js.map +1 -1
  16. package/build/cjs/vexflow.js +2 -2
  17. package/build/cjs/vexflow.js.map +1 -1
  18. package/build/esm/entry/vexflow-bravura.js +10 -0
  19. package/build/esm/entry/vexflow-core.js +53 -0
  20. package/build/esm/entry/vexflow-debug-with-tests.js +11 -0
  21. package/build/esm/entry/vexflow-debug.js +8 -0
  22. package/build/esm/entry/vexflow-font-bravura.js +7 -0
  23. package/build/esm/entry/vexflow-font-custom.js +7 -0
  24. package/build/esm/entry/vexflow-font-gonville.js +7 -0
  25. package/build/esm/entry/vexflow-font-petaluma.js +7 -0
  26. package/build/esm/entry/vexflow-gonville.js +10 -0
  27. package/build/esm/entry/vexflow-petaluma.js +10 -0
  28. package/build/esm/entry/vexflow.js +8 -0
  29. package/build/esm/src/accidental.js +348 -0
  30. package/build/esm/src/annotation.js +238 -0
  31. package/build/esm/src/articulation.js +267 -0
  32. package/build/esm/src/barnote.js +58 -0
  33. package/build/esm/src/beam.js +644 -0
  34. package/build/esm/src/bend.js +202 -0
  35. package/build/esm/src/boundingbox.js +59 -0
  36. package/build/esm/src/boundingboxcomputation.js +107 -0
  37. package/build/esm/src/canvascontext.js +202 -0
  38. package/build/esm/src/chordsymbol.js +578 -0
  39. package/build/esm/src/clef.js +153 -0
  40. package/build/esm/src/clefnote.js +65 -0
  41. package/build/esm/src/crescendo.js +77 -0
  42. package/build/esm/src/curve.js +118 -0
  43. package/build/esm/src/dot.js +137 -0
  44. package/build/esm/src/easyscore.js +374 -0
  45. package/build/esm/src/element.js +216 -0
  46. package/build/esm/src/factory.js +445 -0
  47. package/build/esm/src/flow.js +288 -0
  48. package/build/esm/src/font.js +262 -0
  49. package/build/esm/src/fonts/bravura_glyphs.js +3239 -0
  50. package/build/esm/src/fonts/bravura_metrics.js +507 -0
  51. package/build/esm/src/fonts/custom_glyphs.js +78 -0
  52. package/build/esm/src/fonts/custom_metrics.js +5 -0
  53. package/build/esm/src/fonts/gonville_glyphs.js +828 -0
  54. package/build/esm/src/fonts/gonville_metrics.js +421 -0
  55. package/build/esm/src/fonts/load_all.js +10 -0
  56. package/build/esm/src/fonts/load_bravura.js +6 -0
  57. package/build/esm/src/fonts/load_custom.js +6 -0
  58. package/build/esm/src/fonts/load_gonville.js +6 -0
  59. package/build/esm/src/fonts/load_petaluma.js +6 -0
  60. package/build/esm/src/fonts/petaluma_glyphs.js +1335 -0
  61. package/build/esm/src/fonts/petaluma_metrics.js +536 -0
  62. package/build/esm/src/fonts/petalumascript_glyphs.js +863 -0
  63. package/build/esm/src/fonts/robotoslab_glyphs.js +863 -0
  64. package/build/esm/src/fonts/textfonts.js +44 -0
  65. package/build/esm/src/formatter.js +585 -0
  66. package/build/esm/src/fraction.js +171 -0
  67. package/build/esm/src/frethandfinger.js +156 -0
  68. package/build/esm/src/ghostnote.js +50 -0
  69. package/build/esm/src/glyph.js +337 -0
  70. package/build/esm/src/glyphnote.js +55 -0
  71. package/build/esm/src/gracenote.js +133 -0
  72. package/build/esm/src/gracenotegroup.js +128 -0
  73. package/build/esm/src/gracetabnote.js +12 -0
  74. package/build/esm/src/index.js +89 -0
  75. package/build/esm/src/keymanager.js +99 -0
  76. package/build/esm/src/keysignature.js +250 -0
  77. package/build/esm/src/keysignote.js +28 -0
  78. package/build/esm/src/modifier.js +128 -0
  79. package/build/esm/src/modifiercontext.js +110 -0
  80. package/build/esm/src/multimeasurerest.js +173 -0
  81. package/build/esm/src/music.js +322 -0
  82. package/build/esm/src/note.js +371 -0
  83. package/build/esm/src/notehead.js +169 -0
  84. package/build/esm/src/notesubgroup.js +59 -0
  85. package/build/esm/src/ornament.js +206 -0
  86. package/build/esm/src/parenthesis.js +76 -0
  87. package/build/esm/src/parser.js +164 -0
  88. package/build/esm/src/pedalmarking.js +192 -0
  89. package/build/esm/src/registry.js +81 -0
  90. package/build/esm/src/rendercontext.js +24 -0
  91. package/build/esm/src/renderer.js +112 -0
  92. package/build/esm/src/repeatnote.js +22 -0
  93. package/build/esm/src/stave.js +547 -0
  94. package/build/esm/src/stavebarline.js +182 -0
  95. package/build/esm/src/staveconnector.js +196 -0
  96. package/build/esm/src/stavehairpin.js +120 -0
  97. package/build/esm/src/staveline.js +215 -0
  98. package/build/esm/src/stavemodifier.js +77 -0
  99. package/build/esm/src/stavenote.js +860 -0
  100. package/build/esm/src/staverepetition.js +155 -0
  101. package/build/esm/src/stavesection.js +58 -0
  102. package/build/esm/src/stavetempo.js +91 -0
  103. package/build/esm/src/stavetext.js +82 -0
  104. package/build/esm/src/stavetie.js +141 -0
  105. package/build/esm/src/stavevolta.js +67 -0
  106. package/build/esm/src/stem.js +131 -0
  107. package/build/esm/src/stemmablenote.js +193 -0
  108. package/build/esm/src/stringnumber.js +231 -0
  109. package/build/esm/src/strokes.js +200 -0
  110. package/build/esm/src/svgcontext.js +414 -0
  111. package/build/esm/src/system.js +109 -0
  112. package/build/esm/src/tables.js +1102 -0
  113. package/build/esm/src/tabnote.js +299 -0
  114. package/build/esm/src/tabslide.js +76 -0
  115. package/build/esm/src/tabstave.js +17 -0
  116. package/build/esm/src/tabtie.js +19 -0
  117. package/build/esm/src/textbracket.js +144 -0
  118. package/build/esm/src/textdynamics.js +81 -0
  119. package/build/esm/src/textformatter.js +177 -0
  120. package/build/esm/src/textnote.js +174 -0
  121. package/build/esm/src/tickable.js +214 -0
  122. package/build/esm/src/tickcontext.js +170 -0
  123. package/build/esm/src/timesigglyph.js +85 -0
  124. package/build/esm/src/timesignature.js +89 -0
  125. package/build/esm/src/timesignote.js +32 -0
  126. package/build/esm/src/tremolo.js +47 -0
  127. package/build/esm/src/tuning.js +54 -0
  128. package/build/esm/src/tuplet.js +240 -0
  129. package/build/esm/src/typeguard.js +30 -0
  130. package/build/esm/src/util.js +58 -0
  131. package/build/esm/src/version.js +3 -3
  132. package/build/esm/src/vex.js +51 -0
  133. package/build/esm/src/vibrato.js +100 -0
  134. package/build/esm/src/vibratobracket.js +50 -0
  135. package/build/esm/src/voice.js +187 -0
  136. package/build/esm/src/web.js +15 -0
  137. package/build/esm/tests/accidental_tests.js +974 -0
  138. package/build/esm/tests/annotation_tests.js +390 -0
  139. package/build/esm/tests/articulation_tests.js +365 -0
  140. package/build/esm/tests/auto_beam_formatting_tests.js +548 -0
  141. package/build/esm/tests/bach_tests.js +335 -0
  142. package/build/esm/tests/barline_tests.js +52 -0
  143. package/build/esm/tests/beam_tests.js +614 -0
  144. package/build/esm/tests/bend_tests.js +215 -0
  145. package/build/esm/tests/boundingbox_tests.js +53 -0
  146. package/build/esm/tests/boundingboxcomputation_tests.js +183 -0
  147. package/build/esm/tests/chordsymbol_tests.js +320 -0
  148. package/build/esm/tests/clef_tests.js +131 -0
  149. package/build/esm/tests/curve_tests.js +118 -0
  150. package/build/esm/tests/dot_tests.js +123 -0
  151. package/build/esm/tests/easyscore_tests.js +462 -0
  152. package/build/esm/tests/factory_tests.js +44 -0
  153. package/build/esm/tests/font_tests.js +135 -0
  154. package/build/esm/tests/formatter/framestack.js +61 -0
  155. package/build/esm/tests/formatter/tests.js +203 -0
  156. package/build/esm/tests/formatter_tests.js +670 -0
  157. package/build/esm/tests/fraction_tests.js +72 -0
  158. package/build/esm/tests/ghostnote_tests.js +77 -0
  159. package/build/esm/tests/glyphnote_tests.js +113 -0
  160. package/build/esm/tests/gracenote_tests.js +413 -0
  161. package/build/esm/tests/gracetabnote_tests.js +79 -0
  162. package/build/esm/tests/index.js +68 -0
  163. package/build/esm/tests/key_clef_tests.js +103 -0
  164. package/build/esm/tests/keymanager_tests.js +68 -0
  165. package/build/esm/tests/keysignature_tests.js +308 -0
  166. package/build/esm/tests/mocks.js +71 -0
  167. package/build/esm/tests/modifier_tests.js +24 -0
  168. package/build/esm/tests/multimeasurerest_tests.js +141 -0
  169. package/build/esm/tests/music_tests.js +161 -0
  170. package/build/esm/tests/notehead_tests.js +137 -0
  171. package/build/esm/tests/notesubgroup_tests.js +149 -0
  172. package/build/esm/tests/offscreencanvas_tests.js +47 -0
  173. package/build/esm/tests/ornament_tests.js +298 -0
  174. package/build/esm/tests/parser_tests.js +122 -0
  175. package/build/esm/tests/pedalmarking_tests.js +64 -0
  176. package/build/esm/tests/percussion_tests.js +180 -0
  177. package/build/esm/tests/registry_tests.js +64 -0
  178. package/build/esm/tests/renderer_tests.js +113 -0
  179. package/build/esm/tests/rests_tests.js +248 -0
  180. package/build/esm/tests/rhythm_tests.js +357 -0
  181. package/build/esm/tests/stave_tests.js +560 -0
  182. package/build/esm/tests/staveconnector_tests.js +402 -0
  183. package/build/esm/tests/stavehairpin_tests.js +90 -0
  184. package/build/esm/tests/staveline_tests.js +122 -0
  185. package/build/esm/tests/stavemodifier_tests.js +51 -0
  186. package/build/esm/tests/stavenote_tests.js +867 -0
  187. package/build/esm/tests/stavetie_tests.js +108 -0
  188. package/build/esm/tests/stringnumber_tests.js +259 -0
  189. package/build/esm/tests/strokes_tests.js +275 -0
  190. package/build/esm/tests/style_tests.js +98 -0
  191. package/build/esm/tests/support/qunit.js +2765 -0
  192. package/build/esm/tests/tabnote_tests.js +474 -0
  193. package/build/esm/tests/tabslide_tests.js +135 -0
  194. package/build/esm/tests/tabstave_tests.js +23 -0
  195. package/build/esm/tests/tabtie_tests.js +173 -0
  196. package/build/esm/tests/textbracket_tests.js +100 -0
  197. package/build/esm/tests/textformatter_tests.js +24 -0
  198. package/build/esm/tests/textnote_tests.js +215 -0
  199. package/build/esm/tests/threevoice_tests.js +132 -0
  200. package/build/esm/tests/tickcontext_tests.js +36 -0
  201. package/build/esm/tests/timesignature_tests.js +134 -0
  202. package/build/esm/tests/tremolo_tests.js +75 -0
  203. package/build/esm/tests/tuning_tests.js +56 -0
  204. package/build/esm/tests/tuplet_tests.js +450 -0
  205. package/build/esm/tests/typeguard_tests.js +82 -0
  206. package/build/esm/tests/vexflow_test_helpers.js +266 -0
  207. package/build/esm/tests/vf_prefix_tests.js +115 -0
  208. package/build/esm/tests/vibrato_tests.js +92 -0
  209. package/build/esm/tests/vibratobracket_tests.js +45 -0
  210. package/build/esm/tests/voice_tests.js +69 -0
  211. package/build/types/entry/vexflow-bravura.d.ts +2 -0
  212. package/build/types/entry/vexflow-core.d.ts +2 -0
  213. package/build/types/entry/vexflow-debug.d.ts +2 -0
  214. package/build/types/entry/vexflow-font-bravura.d.ts +3771 -0
  215. package/build/types/entry/vexflow-font-custom.d.ts +86 -0
  216. package/build/types/entry/vexflow-font-gonville.d.ts +1267 -0
  217. package/build/types/entry/vexflow-font-petaluma.d.ts +1896 -0
  218. package/build/types/entry/vexflow-gonville.d.ts +2 -0
  219. package/build/types/entry/vexflow-petaluma.d.ts +2 -0
  220. package/build/types/entry/vexflow.d.ts +2 -0
  221. package/build/types/src/accidental.d.ts +66 -0
  222. package/build/types/src/annotation.d.ts +61 -0
  223. package/build/types/src/articulation.d.ts +62 -0
  224. package/build/types/src/barnote.d.ts +29 -0
  225. package/build/types/src/beam.d.ts +153 -0
  226. package/build/types/src/bend.d.ts +73 -0
  227. package/build/types/src/boundingbox.d.ts +42 -0
  228. package/build/types/src/boundingboxcomputation.d.ts +33 -0
  229. package/build/types/src/canvascontext.d.ts +89 -0
  230. package/build/types/src/chordsymbol.d.ts +149 -0
  231. package/build/types/src/clef.d.ts +48 -0
  232. package/build/types/src/clefnote.d.ts +25 -0
  233. package/build/types/src/crescendo.d.ts +27 -0
  234. package/build/types/src/curve.d.ts +41 -0
  235. package/build/types/src/dot.d.ts +20 -0
  236. package/build/types/src/easyscore.d.ts +152 -0
  237. package/build/types/src/element.d.ts +202 -0
  238. package/build/types/src/factory.d.ts +274 -0
  239. package/build/types/src/flow.d.ts +260 -0
  240. package/build/types/src/font.d.ts +180 -0
  241. package/build/types/src/fonts/bravura_glyphs.d.ts +3239 -0
  242. package/build/types/src/fonts/bravura_metrics.d.ts +533 -0
  243. package/build/types/src/fonts/custom_glyphs.d.ts +78 -0
  244. package/build/types/src/fonts/custom_metrics.d.ts +5 -0
  245. package/build/types/src/fonts/gonville_glyphs.d.ts +828 -0
  246. package/build/types/src/fonts/gonville_metrics.d.ts +440 -0
  247. package/build/types/src/fonts/load_all.d.ts +1 -0
  248. package/build/types/src/fonts/load_bravura.d.ts +1 -0
  249. package/build/types/src/fonts/load_custom.d.ts +1 -0
  250. package/build/types/src/fonts/load_gonville.d.ts +1 -0
  251. package/build/types/src/fonts/load_petaluma.d.ts +1 -0
  252. package/build/types/src/fonts/petaluma_glyphs.d.ts +1335 -0
  253. package/build/types/src/fonts/petaluma_metrics.d.ts +562 -0
  254. package/build/types/src/fonts/petalumascript_glyphs.d.ts +863 -0
  255. package/build/types/src/fonts/robotoslab_glyphs.d.ts +863 -0
  256. package/build/types/src/fonts/textfonts.d.ts +1 -0
  257. package/build/types/src/formatter.d.ts +203 -0
  258. package/build/types/src/fraction.d.ts +62 -0
  259. package/build/types/src/frethandfinger.d.ts +22 -0
  260. package/build/types/src/ghostnote.d.ts +16 -0
  261. package/build/types/src/glyph.d.ts +141 -0
  262. package/build/types/src/glyphnote.d.ts +17 -0
  263. package/build/types/src/gracenote.d.ts +19 -0
  264. package/build/types/src/gracenotegroup.d.ts +33 -0
  265. package/build/types/src/gracetabnote.d.ts +5 -0
  266. package/build/types/src/index.d.ts +89 -0
  267. package/build/types/src/keymanager.d.ts +25 -0
  268. package/build/types/src/keysignature.d.ts +50 -0
  269. package/build/types/src/keysignote.d.ts +11 -0
  270. package/build/types/src/modifier.d.ts +97 -0
  271. package/build/types/src/modifiercontext.d.ts +45 -0
  272. package/build/types/src/multimeasurerest.d.ts +61 -0
  273. package/build/types/src/music.d.ts +91 -0
  274. package/build/types/src/note.d.ts +232 -0
  275. package/build/types/src/notehead.d.ts +70 -0
  276. package/build/types/src/notesubgroup.d.ts +18 -0
  277. package/build/types/src/ornament.d.ts +76 -0
  278. package/build/types/src/parenthesis.d.ts +22 -0
  279. package/build/types/src/parser.d.ts +45 -0
  280. package/build/types/src/pedalmarking.d.ts +69 -0
  281. package/build/types/src/registry.d.ts +40 -0
  282. package/build/types/src/rendercontext.d.ts +64 -0
  283. package/build/types/src/renderer.d.ts +35 -0
  284. package/build/types/src/repeatnote.d.ts +6 -0
  285. package/build/types/src/stave.d.ts +186 -0
  286. package/build/types/src/stavebarline.d.ts +28 -0
  287. package/build/types/src/staveconnector.d.ts +67 -0
  288. package/build/types/src/stavehairpin.d.ts +56 -0
  289. package/build/types/src/staveline.d.ts +54 -0
  290. package/build/types/src/stavemodifier.d.ts +44 -0
  291. package/build/types/src/stavenote.d.ts +154 -0
  292. package/build/types/src/staverepetition.d.ts +32 -0
  293. package/build/types/src/stavesection.d.ts +15 -0
  294. package/build/types/src/stavetempo.d.ts +25 -0
  295. package/build/types/src/stavetext.d.ts +25 -0
  296. package/build/types/src/stavetie.d.ts +59 -0
  297. package/build/types/src/stavevolta.d.ts +21 -0
  298. package/build/types/src/stem.d.ts +58 -0
  299. package/build/types/src/stemmablenote.d.ts +39 -0
  300. package/build/types/src/stringnumber.d.ts +27 -0
  301. package/build/types/src/strokes.d.ts +33 -0
  302. package/build/types/src/svgcontext.d.ts +131 -0
  303. package/build/types/src/system.d.ts +92 -0
  304. package/build/types/src/tables.d.ts +96 -0
  305. package/build/types/src/tabnote.d.ts +44 -0
  306. package/build/types/src/tabslide.d.ts +34 -0
  307. package/build/types/src/tabstave.d.ts +7 -0
  308. package/build/types/src/tabtie.d.ts +18 -0
  309. package/build/types/src/textbracket.d.ts +55 -0
  310. package/build/types/src/textdynamics.d.ts +39 -0
  311. package/build/types/src/textformatter.d.ts +109 -0
  312. package/build/types/src/textnote.d.ts +49 -0
  313. package/build/types/src/tickable.d.ts +140 -0
  314. package/build/types/src/tickcontext.d.ts +82 -0
  315. package/build/types/src/timesigglyph.d.ts +14 -0
  316. package/build/types/src/timesignature.d.ts +26 -0
  317. package/build/types/src/timesignote.d.ts +11 -0
  318. package/build/types/src/tremolo.d.ts +17 -0
  319. package/build/types/src/tuning.d.ts +23 -0
  320. package/build/types/src/tuplet.d.ts +105 -0
  321. package/build/types/src/typeguard.d.ts +99 -0
  322. package/build/types/src/util.d.ts +27 -0
  323. package/build/types/src/version.d.ts +3 -0
  324. package/build/types/src/vex.d.ts +18 -0
  325. package/build/types/src/vibrato.d.ts +29 -0
  326. package/build/types/src/vibratobracket.d.ts +33 -0
  327. package/build/types/src/voice.d.ts +108 -0
  328. package/build/types/src/web.d.ts +2 -0
  329. package/entry/vexflow-bravura.ts +3 -3
  330. package/entry/vexflow-core.ts +3 -3
  331. package/entry/vexflow-debug-with-tests.ts +16 -2
  332. package/entry/vexflow-debug.ts +11 -3
  333. package/entry/vexflow-gonville.ts +3 -3
  334. package/entry/vexflow-petaluma.ts +3 -3
  335. package/entry/vexflow.ts +3 -3
  336. package/package.json +1 -1
  337. package/src/annotation.ts +38 -6
  338. package/src/articulation.ts +8 -2
  339. package/src/beam.ts +53 -6
  340. package/src/easyscore.ts +11 -1
  341. package/src/factory.ts +16 -2
  342. package/src/flow.ts +35 -20
  343. package/src/font.ts +0 -4
  344. package/src/fonts/gonville_glyphs.ts +4 -4
  345. package/src/formatter.ts +24 -8
  346. package/src/glyph.ts +8 -0
  347. package/src/index.ts +2 -7
  348. package/src/note.ts +2 -1
  349. package/src/staveline.ts +2 -5
  350. package/src/stavenote.ts +13 -9
  351. package/src/stavetext.ts +3 -3
  352. package/src/system.ts +1 -7
  353. package/src/textnote.ts +9 -11
@@ -0,0 +1,860 @@
1
+ import { BoundingBox } from './boundingbox.js';
2
+ import { Modifier } from './modifier.js';
3
+ import { NoteHead } from './notehead.js';
4
+ import { Stem } from './stem.js';
5
+ import { StemmableNote } from './stemmablenote.js';
6
+ import { Tables } from './tables.js';
7
+ import { defined, log, midLine, RuntimeError, warn } from './util.js';
8
+ function showDeprecationWarningForNoteHeads() {
9
+ console.warn('StaveNote.note_heads is deprecated. Use StaveNote.noteHeads instead.', 'This accessor will be removed in VexFlow 5.0.');
10
+ }
11
+ function L(...args) {
12
+ if (StaveNote.DEBUG)
13
+ log('Vex.Flow.StaveNote', args);
14
+ }
15
+ const isInnerNoteIndex = (note, index) => index === (note.getStemDirection() === Stem.UP ? note.keyProps.length - 1 : 0);
16
+ function shiftRestVertical(rest, note, dir) {
17
+ const delta = dir;
18
+ rest.line += delta;
19
+ rest.maxLine += delta;
20
+ rest.minLine += delta;
21
+ rest.note.setKeyLine(0, rest.note.getKeyLine(0) + delta);
22
+ }
23
+ function centerRest(rest, noteU, noteL) {
24
+ const delta = rest.line - midLine(noteU.minLine, noteL.maxLine);
25
+ rest.note.setKeyLine(0, rest.note.getKeyLine(0) - delta);
26
+ rest.line -= delta;
27
+ rest.maxLine -= delta;
28
+ rest.minLine -= delta;
29
+ }
30
+ export class StaveNote extends StemmableNote {
31
+ constructor(noteStruct) {
32
+ var _a, _b, _c;
33
+ super(noteStruct);
34
+ this.minLine = 0;
35
+ this.maxLine = 0;
36
+ this.ledgerLineStyle = {};
37
+ this.clef = (_a = noteStruct.clef) !== null && _a !== void 0 ? _a : 'treble';
38
+ this.octave_shift = (_b = noteStruct.octave_shift) !== null && _b !== void 0 ? _b : 0;
39
+ this.glyph = Tables.getGlyphProps(this.duration, this.noteType);
40
+ defined(this.glyph, 'BadArguments', `No glyph found for duration '${this.duration}' and type '${this.noteType}'`);
41
+ this.displaced = false;
42
+ this.dot_shiftY = 0;
43
+ this.use_default_head_x = false;
44
+ this._noteHeads = [];
45
+ this.modifiers = [];
46
+ this.render_options = Object.assign(Object.assign({}, this.render_options), { glyph_font_scale: noteStruct.glyph_font_scale || Tables.NOTATION_FONT_SCALE, stroke_px: noteStruct.stroke_px || StaveNote.LEDGER_LINE_OFFSET });
47
+ this.calculateKeyProps();
48
+ this.buildStem();
49
+ if (noteStruct.auto_stem) {
50
+ this.autoStem();
51
+ }
52
+ else {
53
+ this.setStemDirection((_c = noteStruct.stem_direction) !== null && _c !== void 0 ? _c : Stem.UP);
54
+ }
55
+ this.reset();
56
+ this.buildFlag();
57
+ }
58
+ static get CATEGORY() {
59
+ return "StaveNote";
60
+ }
61
+ static get STEM_UP() {
62
+ return Stem.UP;
63
+ }
64
+ static get STEM_DOWN() {
65
+ return Stem.DOWN;
66
+ }
67
+ static get LEDGER_LINE_OFFSET() {
68
+ return 3;
69
+ }
70
+ static get minNoteheadPadding() {
71
+ const musicFont = Tables.currentMusicFont();
72
+ return musicFont.lookupMetric('glyphs.noteHead.minPadding');
73
+ }
74
+ static format(notes, state) {
75
+ if (!notes || notes.length < 2)
76
+ return false;
77
+ const notesList = [];
78
+ for (let i = 0; i < notes.length; i++) {
79
+ const props = notes[i].getKeyProps();
80
+ const line = props[0].line;
81
+ let minL = props[props.length - 1].line;
82
+ const stemDirection = notes[i].getStemDirection();
83
+ const stemMax = notes[i].getStemLength() / 10;
84
+ const stemMin = notes[i].getStemMinimumLength() / 10;
85
+ let maxL;
86
+ if (notes[i].isRest()) {
87
+ maxL = line + notes[i].glyph.line_above;
88
+ minL = line - notes[i].glyph.line_below;
89
+ }
90
+ else {
91
+ maxL = stemDirection === 1 ? props[props.length - 1].line + stemMax : props[props.length - 1].line;
92
+ minL = stemDirection === 1 ? props[0].line : props[0].line - stemMax;
93
+ }
94
+ notesList.push({
95
+ line: props[0].line,
96
+ maxLine: maxL,
97
+ minLine: minL,
98
+ isrest: notes[i].isRest(),
99
+ stemDirection: stemDirection,
100
+ stemMax,
101
+ stemMin,
102
+ voice_shift: notes[i].getVoiceShiftWidth(),
103
+ is_displaced: notes[i].isDisplaced(),
104
+ note: notes[i],
105
+ });
106
+ }
107
+ const voices = notesList.length;
108
+ let noteU = notesList[0];
109
+ const noteM = voices > 2 ? notesList[1] : undefined;
110
+ let noteL = voices > 2 ? notesList[2] : notesList[1];
111
+ if (voices === 2 && noteU.stemDirection === -1 && noteL.stemDirection === 1) {
112
+ noteU = notesList[1];
113
+ noteL = notesList[0];
114
+ }
115
+ const voiceXShift = Math.max(noteU.voice_shift, noteL.voice_shift);
116
+ let xShift = 0;
117
+ if (voices === 2) {
118
+ const lineSpacing = noteU.note.hasStem() && noteL.note.hasStem() && noteU.stemDirection === noteL.stemDirection ? 0.0 : 0.5;
119
+ if (noteL.isrest && noteU.isrest && noteU.note.duration === noteL.note.duration) {
120
+ noteL.note.render_options.draw = false;
121
+ }
122
+ else if (noteU.minLine <= noteL.maxLine + lineSpacing) {
123
+ if (noteU.isrest) {
124
+ shiftRestVertical(noteU, noteL, 1);
125
+ }
126
+ else if (noteL.isrest) {
127
+ shiftRestVertical(noteL, noteU, -1);
128
+ }
129
+ else {
130
+ const lineDiff = Math.abs(noteU.line - noteL.line);
131
+ if (noteU.note.hasStem() && noteL.note.hasStem()) {
132
+ let whiteNoteHeadCount = 0;
133
+ let blackNoteHeadCount = 0;
134
+ if (Tables.durationToNumber(noteU.note.duration) === 2) {
135
+ whiteNoteHeadCount++;
136
+ }
137
+ else if (Tables.durationToNumber(noteU.note.duration) > 2) {
138
+ blackNoteHeadCount++;
139
+ }
140
+ if (Tables.durationToNumber(noteL.note.duration) === 2) {
141
+ whiteNoteHeadCount++;
142
+ }
143
+ else if (Tables.durationToNumber(noteL.note.duration) > 2) {
144
+ blackNoteHeadCount++;
145
+ }
146
+ if ((whiteNoteHeadCount !== 2 && blackNoteHeadCount !== 2) ||
147
+ noteU.note.getModifiersByType("Dot").length !== noteL.note.getModifiersByType("Dot").length) {
148
+ xShift = voiceXShift + 2;
149
+ if (noteU.stemDirection === noteL.stemDirection) {
150
+ noteU.note.setXShift(xShift);
151
+ }
152
+ else {
153
+ noteL.note.setXShift(xShift);
154
+ }
155
+ }
156
+ else if (lineDiff < 1 && lineDiff > 0) {
157
+ xShift = voiceXShift + 2;
158
+ if (noteU.stemDirection === noteL.stemDirection) {
159
+ noteU.note.setXShift(xShift);
160
+ }
161
+ else {
162
+ noteL.note.setXShift(xShift);
163
+ }
164
+ }
165
+ else if (noteU.note.voice !== noteL.note.voice) {
166
+ if (noteU.stemDirection === noteL.stemDirection) {
167
+ if (noteU.line != noteL.line) {
168
+ xShift = voiceXShift + 2;
169
+ noteU.note.setXShift(xShift);
170
+ }
171
+ else {
172
+ if (noteL.stemDirection === 1) {
173
+ noteL.stemDirection = -1;
174
+ noteL.note.setStemDirection(-1);
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ else {
181
+ xShift = voiceXShift + 2;
182
+ if (noteU.stemDirection === noteL.stemDirection) {
183
+ noteU.note.setXShift(xShift);
184
+ }
185
+ else {
186
+ noteL.note.setXShift(xShift);
187
+ }
188
+ }
189
+ }
190
+ }
191
+ state.right_shift += xShift;
192
+ return true;
193
+ }
194
+ if (!noteM)
195
+ throw new RuntimeError('InvalidState', 'noteM not defined.');
196
+ if (noteM.isrest && !noteU.isrest && !noteL.isrest) {
197
+ if (noteU.minLine <= noteM.maxLine || noteM.minLine <= noteL.maxLine) {
198
+ const restHeight = noteM.maxLine - noteM.minLine;
199
+ const space = noteU.minLine - noteL.maxLine;
200
+ if (restHeight < space) {
201
+ centerRest(noteM, noteU, noteL);
202
+ }
203
+ else {
204
+ xShift = voiceXShift + 2;
205
+ noteM.note.setXShift(xShift);
206
+ if (noteL.note.hasBeam() === false) {
207
+ noteL.stemDirection = -1;
208
+ noteL.note.setStemDirection(-1);
209
+ }
210
+ if (noteU.minLine <= noteL.maxLine && noteU.note.hasBeam() === false) {
211
+ noteU.stemDirection = 1;
212
+ noteU.note.setStemDirection(1);
213
+ }
214
+ }
215
+ state.right_shift += xShift;
216
+ return true;
217
+ }
218
+ }
219
+ if (noteU.isrest && noteM.isrest && noteL.isrest) {
220
+ noteU.note.render_options.draw = false;
221
+ noteL.note.render_options.draw = false;
222
+ state.right_shift += xShift;
223
+ return true;
224
+ }
225
+ if (noteM.isrest && noteU.isrest && noteM.minLine <= noteL.maxLine) {
226
+ noteM.note.render_options.draw = false;
227
+ }
228
+ if (noteM.isrest && noteL.isrest && noteU.minLine <= noteM.maxLine) {
229
+ noteM.note.render_options.draw = false;
230
+ }
231
+ if (noteU.isrest && noteU.minLine <= noteM.maxLine) {
232
+ shiftRestVertical(noteU, noteM, 1);
233
+ }
234
+ if (noteL.isrest && noteM.minLine <= noteL.maxLine) {
235
+ shiftRestVertical(noteL, noteM, -1);
236
+ }
237
+ if (noteU.minLine <= noteM.maxLine + 0.5 || noteM.minLine <= noteL.maxLine) {
238
+ xShift = voiceXShift + 2;
239
+ noteM.note.setXShift(xShift);
240
+ if (noteL.note.hasBeam() === false) {
241
+ noteL.stemDirection = -1;
242
+ noteL.note.setStemDirection(-1);
243
+ }
244
+ if (noteU.minLine <= noteL.maxLine && noteU.note.hasBeam() === false) {
245
+ noteU.stemDirection = 1;
246
+ noteU.note.setStemDirection(1);
247
+ }
248
+ }
249
+ state.right_shift += xShift;
250
+ return true;
251
+ }
252
+ static postFormat(notes) {
253
+ if (!notes)
254
+ return false;
255
+ notes.forEach((note) => note.postFormat());
256
+ return true;
257
+ }
258
+ reset() {
259
+ super.reset();
260
+ const noteHeadStyles = this._noteHeads.map((noteHead) => noteHead.getStyle());
261
+ this.buildNoteHeads();
262
+ this._noteHeads.forEach((noteHead, index) => {
263
+ const noteHeadStyle = noteHeadStyles[index];
264
+ if (noteHeadStyle)
265
+ noteHead.setStyle(noteHeadStyle);
266
+ });
267
+ const stave = this.stave;
268
+ if (stave) {
269
+ this._noteHeads.forEach((head) => head.setStave(stave));
270
+ }
271
+ this.calcNoteDisplacements();
272
+ return this;
273
+ }
274
+ setBeam(beam) {
275
+ this.beam = beam;
276
+ this.calcNoteDisplacements();
277
+ if (this.stem) {
278
+ this.stem.setExtension(this.getStemExtension());
279
+ }
280
+ return this;
281
+ }
282
+ buildStem() {
283
+ this.setStem(new Stem({ hide: !!this.isRest() }));
284
+ return this;
285
+ }
286
+ buildNoteHeads() {
287
+ this._noteHeads = [];
288
+ const stemDirection = this.getStemDirection();
289
+ const keys = this.getKeys();
290
+ let lastLine = undefined;
291
+ let lineDiff = undefined;
292
+ let displaced = false;
293
+ let start;
294
+ let end;
295
+ let step;
296
+ if (stemDirection === Stem.UP) {
297
+ start = 0;
298
+ end = keys.length;
299
+ step = 1;
300
+ }
301
+ else {
302
+ start = keys.length - 1;
303
+ end = -1;
304
+ step = -1;
305
+ }
306
+ for (let i = start; i !== end; i += step) {
307
+ const noteProps = this.keyProps[i];
308
+ const line = noteProps.line;
309
+ if (lastLine === undefined) {
310
+ lastLine = line;
311
+ }
312
+ else {
313
+ lineDiff = Math.abs(lastLine - line);
314
+ if (lineDiff === 0 || lineDiff === 0.5) {
315
+ displaced = !displaced;
316
+ }
317
+ else {
318
+ displaced = false;
319
+ this.use_default_head_x = true;
320
+ }
321
+ }
322
+ lastLine = line;
323
+ const notehead = new NoteHead({
324
+ duration: this.duration,
325
+ note_type: this.noteType,
326
+ displaced,
327
+ stem_direction: stemDirection,
328
+ custom_glyph_code: noteProps.code,
329
+ glyph_font_scale: this.render_options.glyph_font_scale,
330
+ x_shift: noteProps.shift_right,
331
+ stem_up_x_offset: noteProps.stem_up_x_offset,
332
+ stem_down_x_offset: noteProps.stem_down_x_offset,
333
+ line: noteProps.line,
334
+ });
335
+ this._noteHeads[i] = notehead;
336
+ }
337
+ }
338
+ autoStem() {
339
+ this.setStemDirection(this.calculateOptimalStemDirection());
340
+ }
341
+ calculateOptimalStemDirection() {
342
+ this.minLine = this.keyProps[0].line;
343
+ this.maxLine = this.keyProps[this.keyProps.length - 1].line;
344
+ const MIDDLE_LINE = 3;
345
+ const decider = (this.minLine + this.maxLine) / 2;
346
+ const stemDirection = decider < MIDDLE_LINE ? Stem.UP : Stem.DOWN;
347
+ return stemDirection;
348
+ }
349
+ calculateKeyProps() {
350
+ let lastLine;
351
+ for (let i = 0; i < this.keys.length; ++i) {
352
+ const key = this.keys[i];
353
+ if (this.glyph.rest)
354
+ this.glyph.position = key;
355
+ const options = { octave_shift: this.octave_shift || 0 };
356
+ const props = Tables.keyProperties(key, this.clef, options);
357
+ if (!props) {
358
+ throw new RuntimeError('BadArguments', `Invalid key for note properties: ${key}`);
359
+ }
360
+ if (props.key === 'R') {
361
+ if (this.duration === '1' || this.duration === 'w') {
362
+ props.line = 4;
363
+ }
364
+ else {
365
+ props.line = 3;
366
+ }
367
+ }
368
+ const line = props.line;
369
+ if (lastLine == undefined) {
370
+ lastLine = line;
371
+ }
372
+ else {
373
+ if (Math.abs(lastLine - line) === 0.5) {
374
+ this.displaced = true;
375
+ props.displaced = true;
376
+ if (this.keyProps.length > 0) {
377
+ this.keyProps[i - 1].displaced = true;
378
+ }
379
+ }
380
+ }
381
+ lastLine = line;
382
+ this.keyProps.push(props);
383
+ }
384
+ lastLine = undefined;
385
+ this.keyProps.forEach((key) => {
386
+ if (lastLine && key.line < lastLine) {
387
+ warn('Unsorted keys in note will be sorted. ' + 'See https://github.com/0xfe/vexflow/issues/104 for details.');
388
+ }
389
+ lastLine = key.line;
390
+ });
391
+ this.keyProps.sort((a, b) => a.line - b.line);
392
+ }
393
+ getBoundingBox() {
394
+ var _a, _b;
395
+ if (!this.preFormatted) {
396
+ throw new RuntimeError('UnformattedNote', "Can't call getBoundingBox on an unformatted note.");
397
+ }
398
+ const { width: w, modLeftPx, leftDisplacedHeadPx } = this.getMetrics();
399
+ const x = this.getAbsoluteX() - modLeftPx - leftDisplacedHeadPx;
400
+ let minY = 0;
401
+ let maxY = 0;
402
+ const halfLineSpacing = ((_b = (_a = this.getStave()) === null || _a === void 0 ? void 0 : _a.getSpacingBetweenLines()) !== null && _b !== void 0 ? _b : 0) / 2;
403
+ const lineSpacing = halfLineSpacing * 2;
404
+ if (this.isRest()) {
405
+ const y = this.ys[0];
406
+ const frac = Tables.durationToFraction(this.duration);
407
+ if (frac.equals(1) || frac.equals(2)) {
408
+ minY = y - halfLineSpacing;
409
+ maxY = y + halfLineSpacing;
410
+ }
411
+ else {
412
+ minY = y - this.glyph.line_above * lineSpacing;
413
+ maxY = y + this.glyph.line_below * lineSpacing;
414
+ }
415
+ }
416
+ else if (this.glyph.stem) {
417
+ const ys = this.getStemExtents();
418
+ ys.baseY += halfLineSpacing * this.getStemDirection();
419
+ minY = Math.min(ys.topY, ys.baseY);
420
+ maxY = Math.max(ys.topY, ys.baseY);
421
+ }
422
+ else {
423
+ minY = 0;
424
+ maxY = 0;
425
+ for (let i = 0; i < this.ys.length; ++i) {
426
+ const yy = this.ys[i];
427
+ if (i === 0) {
428
+ minY = yy;
429
+ maxY = yy;
430
+ }
431
+ else {
432
+ minY = Math.min(yy, minY);
433
+ maxY = Math.max(yy, maxY);
434
+ }
435
+ }
436
+ minY -= halfLineSpacing;
437
+ maxY += halfLineSpacing;
438
+ }
439
+ return new BoundingBox(x, minY, w, maxY - minY);
440
+ }
441
+ getLineNumber(isTopNote) {
442
+ if (!this.keyProps.length) {
443
+ throw new RuntimeError('NoKeyProps', "Can't get bottom note line, because note is not initialized properly.");
444
+ }
445
+ let resultLine = this.keyProps[0].line;
446
+ for (let i = 0; i < this.keyProps.length; i++) {
447
+ const thisLine = this.keyProps[i].line;
448
+ if (isTopNote) {
449
+ if (thisLine > resultLine)
450
+ resultLine = thisLine;
451
+ }
452
+ else {
453
+ if (thisLine < resultLine)
454
+ resultLine = thisLine;
455
+ }
456
+ }
457
+ return resultLine;
458
+ }
459
+ isRest() {
460
+ return this.glyph.rest;
461
+ }
462
+ isChord() {
463
+ return !this.isRest() && this.keys.length > 1;
464
+ }
465
+ hasStem() {
466
+ return this.glyph.stem;
467
+ }
468
+ hasFlag() {
469
+ return super.hasFlag() && !this.isRest();
470
+ }
471
+ getStemX() {
472
+ if (this.noteType === 'r') {
473
+ return this.getCenterGlyphX();
474
+ }
475
+ else {
476
+ return super.getStemX() + (this.stem_direction ? Stem.WIDTH / (2 * -this.stem_direction) : 0);
477
+ }
478
+ }
479
+ getYForTopText(textLine) {
480
+ const extents = this.getStemExtents();
481
+ return Math.min(this.checkStave().getYForTopText(textLine), extents.topY - this.render_options.annotation_spacing * (textLine + 1));
482
+ }
483
+ getYForBottomText(textLine) {
484
+ const extents = this.getStemExtents();
485
+ return Math.max(this.checkStave().getYForTopText(textLine), extents.baseY + this.render_options.annotation_spacing * textLine);
486
+ }
487
+ setStave(stave) {
488
+ super.setStave(stave);
489
+ const ys = this._noteHeads.map((notehead) => {
490
+ notehead.setStave(stave);
491
+ return notehead.getY();
492
+ });
493
+ this.setYs(ys);
494
+ if (this.stem) {
495
+ const { y_top, y_bottom } = this.getNoteHeadBounds();
496
+ this.stem.setYBounds(y_top, y_bottom);
497
+ }
498
+ return this;
499
+ }
500
+ isDisplaced() {
501
+ return this.displaced;
502
+ }
503
+ setNoteDisplaced(displaced) {
504
+ this.displaced = displaced;
505
+ return this;
506
+ }
507
+ getTieRightX() {
508
+ let tieStartX = this.getAbsoluteX();
509
+ tieStartX += this.getGlyphWidth() + this.x_shift + this.rightDisplacedHeadPx;
510
+ if (this.modifierContext)
511
+ tieStartX += this.modifierContext.getRightShift();
512
+ return tieStartX;
513
+ }
514
+ getTieLeftX() {
515
+ let tieEndX = this.getAbsoluteX();
516
+ tieEndX += this.x_shift - this.leftDisplacedHeadPx;
517
+ return tieEndX;
518
+ }
519
+ getLineForRest() {
520
+ let restLine = this.keyProps[0].line;
521
+ if (this.keyProps.length > 1) {
522
+ const lastLine = this.keyProps[this.keyProps.length - 1].line;
523
+ const top = Math.max(restLine, lastLine);
524
+ const bot = Math.min(restLine, lastLine);
525
+ restLine = midLine(top, bot);
526
+ }
527
+ return restLine;
528
+ }
529
+ getModifierStartXY(position, index, options = {}) {
530
+ var _a, _b;
531
+ if (!this.preFormatted) {
532
+ throw new RuntimeError('UnformattedNote', "Can't call GetModifierStartXY on an unformatted note");
533
+ }
534
+ if (this.ys.length === 0) {
535
+ throw new RuntimeError('NoYValues', 'No Y-Values calculated for this note.');
536
+ }
537
+ const { ABOVE, BELOW, LEFT, RIGHT } = Modifier.Position;
538
+ let x = 0;
539
+ if (position === LEFT) {
540
+ x = -1 * 2;
541
+ }
542
+ else if (position === RIGHT) {
543
+ x = this.getGlyphWidth() + this.x_shift + 2;
544
+ if (this.stem_direction === Stem.UP &&
545
+ this.hasFlag() &&
546
+ (options.forceFlagRight || isInnerNoteIndex(this, index))) {
547
+ x += (_b = (_a = this === null || this === void 0 ? void 0 : this.flag) === null || _a === void 0 ? void 0 : _a.getMetrics().width) !== null && _b !== void 0 ? _b : 0;
548
+ }
549
+ }
550
+ else if (position === BELOW || position === ABOVE) {
551
+ x = this.getGlyphWidth() / 2;
552
+ }
553
+ return {
554
+ x: this.getAbsoluteX() + x,
555
+ y: this.ys[index],
556
+ };
557
+ }
558
+ setStyle(style) {
559
+ super.setStyle(style);
560
+ this._noteHeads.forEach((notehead) => notehead.setStyle(style));
561
+ if (this.stem)
562
+ this.stem.setStyle(style);
563
+ return this;
564
+ }
565
+ setStemStyle(style) {
566
+ const stem = this.getStem();
567
+ if (stem)
568
+ stem.setStyle(style);
569
+ return this;
570
+ }
571
+ getStemStyle() {
572
+ var _a;
573
+ return (_a = this.stem) === null || _a === void 0 ? void 0 : _a.getStyle();
574
+ }
575
+ setLedgerLineStyle(style) {
576
+ this.ledgerLineStyle = style;
577
+ }
578
+ getLedgerLineStyle() {
579
+ return this.ledgerLineStyle;
580
+ }
581
+ setFlagStyle(style) {
582
+ this.flagStyle = style;
583
+ }
584
+ getFlagStyle() {
585
+ return this.flagStyle;
586
+ }
587
+ setKeyStyle(index, style) {
588
+ this._noteHeads[index].setStyle(style);
589
+ return this;
590
+ }
591
+ setKeyLine(index, line) {
592
+ this.keyProps[index].line = line;
593
+ this.reset();
594
+ return this;
595
+ }
596
+ getKeyLine(index) {
597
+ return this.keyProps[index].line;
598
+ }
599
+ getVoiceShiftWidth() {
600
+ return this.getGlyphWidth() * (this.displaced ? 2 : 1);
601
+ }
602
+ calcNoteDisplacements() {
603
+ this.setLeftDisplacedHeadPx(this.displaced && this.stem_direction === Stem.DOWN ? this.getGlyphWidth() : 0);
604
+ this.setRightDisplacedHeadPx(!this.hasFlag() && this.displaced && this.stem_direction === Stem.UP ? this.getGlyphWidth() : 0);
605
+ }
606
+ preFormat() {
607
+ if (this.preFormatted)
608
+ return;
609
+ let noteHeadPadding = 0;
610
+ if (this.modifierContext) {
611
+ this.modifierContext.preFormat();
612
+ if (this.modifierContext.getWidth() === 0) {
613
+ noteHeadPadding = StaveNote.minNoteheadPadding;
614
+ }
615
+ }
616
+ let width = this.getGlyphWidth() + this.leftDisplacedHeadPx + this.rightDisplacedHeadPx + noteHeadPadding;
617
+ if (this.shouldDrawFlag() && this.stem_direction === Stem.UP) {
618
+ width += this.getGlyphWidth();
619
+ }
620
+ this.setWidth(width);
621
+ this.preFormatted = true;
622
+ }
623
+ getNoteHeadBounds() {
624
+ let yTop = +Infinity;
625
+ let yBottom = -Infinity;
626
+ let nonDisplacedX;
627
+ let displacedX;
628
+ let highestLine = this.checkStave().getNumLines();
629
+ let lowestLine = 1;
630
+ let highestDisplacedLine;
631
+ let lowestDisplacedLine;
632
+ let highestNonDisplacedLine = highestLine;
633
+ let lowestNonDisplacedLine = lowestLine;
634
+ this._noteHeads.forEach((notehead) => {
635
+ const line = notehead.getLine();
636
+ const y = notehead.getY();
637
+ yTop = Math.min(y, yTop);
638
+ yBottom = Math.max(y, yBottom);
639
+ if (displacedX === undefined && notehead.isDisplaced()) {
640
+ displacedX = notehead.getAbsoluteX();
641
+ }
642
+ if (nonDisplacedX === undefined && !notehead.isDisplaced()) {
643
+ nonDisplacedX = notehead.getAbsoluteX();
644
+ }
645
+ highestLine = Math.max(line, highestLine);
646
+ lowestLine = Math.min(line, lowestLine);
647
+ if (notehead.isDisplaced()) {
648
+ highestDisplacedLine = highestDisplacedLine === undefined ? line : Math.max(line, highestDisplacedLine);
649
+ lowestDisplacedLine = lowestDisplacedLine === undefined ? line : Math.min(line, lowestDisplacedLine);
650
+ }
651
+ else {
652
+ highestNonDisplacedLine = Math.max(line, highestNonDisplacedLine);
653
+ lowestNonDisplacedLine = Math.min(line, lowestNonDisplacedLine);
654
+ }
655
+ }, this);
656
+ return {
657
+ y_top: yTop,
658
+ y_bottom: yBottom,
659
+ displaced_x: displacedX,
660
+ non_displaced_x: nonDisplacedX,
661
+ highest_line: highestLine,
662
+ lowest_line: lowestLine,
663
+ highest_displaced_line: highestDisplacedLine,
664
+ lowest_displaced_line: lowestDisplacedLine,
665
+ highest_non_displaced_line: highestNonDisplacedLine,
666
+ lowest_non_displaced_line: lowestNonDisplacedLine,
667
+ };
668
+ }
669
+ getNoteHeadBeginX() {
670
+ return this.getAbsoluteX() + this.x_shift;
671
+ }
672
+ getNoteHeadEndX() {
673
+ const xBegin = this.getNoteHeadBeginX();
674
+ return xBegin + this.getGlyphWidth();
675
+ }
676
+ get noteHeads() {
677
+ return this._noteHeads.slice();
678
+ }
679
+ get note_heads() {
680
+ showDeprecationWarningForNoteHeads();
681
+ return this.noteHeads;
682
+ }
683
+ drawLedgerLines() {
684
+ const stave = this.checkStave();
685
+ const { glyph, render_options: { stroke_px }, } = this;
686
+ const ctx = this.checkContext();
687
+ const width = glyph.getWidth() + stroke_px * 2;
688
+ const doubleWidth = 2 * (glyph.getWidth() + stroke_px) - Stem.WIDTH / 2;
689
+ if (this.isRest())
690
+ return;
691
+ if (!ctx) {
692
+ throw new RuntimeError('NoCanvasContext', "Can't draw without a canvas context.");
693
+ }
694
+ const { highest_line, lowest_line, highest_displaced_line, highest_non_displaced_line, lowest_displaced_line, lowest_non_displaced_line, displaced_x, non_displaced_x, } = this.getNoteHeadBounds();
695
+ if (highest_line < 6 && lowest_line > 0)
696
+ return;
697
+ const min_x = Math.min(displaced_x !== null && displaced_x !== void 0 ? displaced_x : 0, non_displaced_x !== null && non_displaced_x !== void 0 ? non_displaced_x : 0);
698
+ const drawLedgerLine = (y, normal, displaced) => {
699
+ let x;
700
+ if (displaced && normal)
701
+ x = min_x - stroke_px;
702
+ else if (normal)
703
+ x = (non_displaced_x !== null && non_displaced_x !== void 0 ? non_displaced_x : 0) - stroke_px;
704
+ else
705
+ x = (displaced_x !== null && displaced_x !== void 0 ? displaced_x : 0) - stroke_px;
706
+ const ledgerWidth = normal && displaced ? doubleWidth : width;
707
+ ctx.beginPath();
708
+ ctx.moveTo(x, y);
709
+ ctx.lineTo(x + ledgerWidth, y);
710
+ ctx.stroke();
711
+ };
712
+ const style = Object.assign(Object.assign({}, stave.getDefaultLedgerLineStyle()), this.getLedgerLineStyle());
713
+ this.applyStyle(ctx, style);
714
+ for (let line = 6; line <= highest_line; ++line) {
715
+ const normal = non_displaced_x !== undefined && line <= highest_non_displaced_line;
716
+ const displaced = highest_displaced_line !== undefined && line <= highest_displaced_line;
717
+ drawLedgerLine(stave.getYForNote(line), normal, displaced);
718
+ }
719
+ for (let line = 0; line >= lowest_line; --line) {
720
+ const normal = non_displaced_x !== undefined && line >= lowest_non_displaced_line;
721
+ const displaced = lowest_displaced_line !== undefined && line >= lowest_displaced_line;
722
+ drawLedgerLine(stave.getYForNote(line), normal, displaced);
723
+ }
724
+ this.restoreStyle(ctx, style);
725
+ }
726
+ drawModifiers() {
727
+ const ctx = this.checkContext();
728
+ ctx.openGroup('modifiers');
729
+ for (let i = 0; i < this.modifiers.length; i++) {
730
+ const modifier = this.modifiers[i];
731
+ const index = modifier.checkIndex();
732
+ const notehead = this._noteHeads[index];
733
+ const noteheadStyle = notehead.getStyle();
734
+ notehead.applyStyle(ctx, noteheadStyle);
735
+ modifier.setContext(ctx);
736
+ modifier.drawWithStyle();
737
+ notehead.restoreStyle(ctx, noteheadStyle);
738
+ }
739
+ ctx.closeGroup();
740
+ }
741
+ shouldDrawFlag() {
742
+ const hasStem = this.stem !== undefined;
743
+ const hasFlag = this.glyph.flag;
744
+ const hasNoBeam = this.beam === undefined;
745
+ return hasStem && hasFlag && hasNoBeam;
746
+ }
747
+ drawFlag() {
748
+ var _a, _b, _c, _d, _e;
749
+ const ctx = this.checkContext();
750
+ if (!ctx) {
751
+ throw new RuntimeError('NoCanvasContext', "Can't draw without a canvas context.");
752
+ }
753
+ if (this.shouldDrawFlag()) {
754
+ const { y_top, y_bottom } = this.getNoteHeadBounds();
755
+ const noteStemHeight = this.stem.getHeight();
756
+ const flagX = this.getStemX();
757
+ const flagY = this.getStemDirection() === Stem.DOWN
758
+ ?
759
+ y_top -
760
+ noteStemHeight +
761
+ 2 -
762
+ (this.glyph ? this.glyph.stem_down_extension : 0) * this.getStaveNoteScale() -
763
+ ((_b = (_a = this.flag) === null || _a === void 0 ? void 0 : _a.getMetrics().y_shift) !== null && _b !== void 0 ? _b : 0) * (1 - this.getStaveNoteScale())
764
+ :
765
+ y_bottom -
766
+ noteStemHeight -
767
+ 2 +
768
+ (this.glyph ? this.glyph.stem_up_extension : 0) * this.getStaveNoteScale() -
769
+ ((_d = (_c = this.flag) === null || _c === void 0 ? void 0 : _c.getMetrics().y_shift) !== null && _d !== void 0 ? _d : 0) * (1 - this.getStaveNoteScale());
770
+ ctx.openGroup('flag', undefined, { pointerBBox: true });
771
+ this.applyStyle(ctx, this.getFlagStyle());
772
+ (_e = this.flag) === null || _e === void 0 ? void 0 : _e.render(ctx, flagX, flagY);
773
+ this.restoreStyle(ctx, this.getFlagStyle());
774
+ ctx.closeGroup();
775
+ }
776
+ }
777
+ drawNoteHeads() {
778
+ const ctx = this.checkContext();
779
+ this._noteHeads.forEach((notehead) => {
780
+ ctx.openGroup('notehead', undefined, { pointerBBox: true });
781
+ notehead.setContext(ctx).draw();
782
+ ctx.closeGroup();
783
+ });
784
+ }
785
+ drawStem(stemOptions) {
786
+ const ctx = this.checkContext();
787
+ if (stemOptions) {
788
+ this.setStem(new Stem(stemOptions));
789
+ }
790
+ if (this.shouldDrawFlag() && this.stem) {
791
+ this.stem.adjustHeightForFlag();
792
+ }
793
+ if (this.stem) {
794
+ ctx.openGroup('stem', undefined, { pointerBBox: true });
795
+ this.stem.setContext(ctx).draw();
796
+ ctx.closeGroup();
797
+ }
798
+ }
799
+ getStaveNoteScale() {
800
+ return 1.0;
801
+ }
802
+ getStemExtension() {
803
+ const super_stem_extension = super.getStemExtension();
804
+ if (!this.glyph.stem) {
805
+ return super_stem_extension;
806
+ }
807
+ const stem_direction = this.getStemDirection();
808
+ if (stem_direction !== this.calculateOptimalStemDirection()) {
809
+ return super_stem_extension;
810
+ }
811
+ let mid_line_distance;
812
+ const MIDDLE_LINE = 3;
813
+ if (stem_direction === Stem.UP) {
814
+ mid_line_distance = MIDDLE_LINE - this.maxLine;
815
+ }
816
+ else {
817
+ mid_line_distance = this.minLine - MIDDLE_LINE;
818
+ }
819
+ const lines_over_octave_from_mid_line = mid_line_distance - 3.5;
820
+ if (lines_over_octave_from_mid_line <= 0) {
821
+ return super_stem_extension;
822
+ }
823
+ const stave = this.getStave();
824
+ let spacing_between_lines = 10;
825
+ if (stave != undefined) {
826
+ spacing_between_lines = stave.getSpacingBetweenLines();
827
+ }
828
+ return super_stem_extension + lines_over_octave_from_mid_line * spacing_between_lines;
829
+ }
830
+ draw() {
831
+ if (this.render_options.draw === false)
832
+ return;
833
+ if (this.ys.length === 0) {
834
+ throw new RuntimeError('NoYValues', "Can't draw note without Y values.");
835
+ }
836
+ const ctx = this.checkContext();
837
+ const xBegin = this.getNoteHeadBeginX();
838
+ const shouldRenderStem = this.hasStem() && !this.beam;
839
+ this._noteHeads.forEach((notehead) => notehead.setX(xBegin));
840
+ if (this.stem) {
841
+ const stemX = this.getStemX();
842
+ this.stem.setNoteHeadXBounds(stemX, stemX);
843
+ }
844
+ L('Rendering ', this.isChord() ? 'chord :' : 'note :', this.keys);
845
+ this.applyStyle();
846
+ this.setAttribute('el', ctx.openGroup('stavenote', this.getAttribute('id')));
847
+ this.drawLedgerLines();
848
+ ctx.openGroup('note', undefined, { pointerBBox: true });
849
+ if (shouldRenderStem)
850
+ this.drawStem();
851
+ this.drawNoteHeads();
852
+ this.drawFlag();
853
+ ctx.closeGroup();
854
+ this.drawModifiers();
855
+ ctx.closeGroup();
856
+ this.restoreStyle();
857
+ this.setRendered();
858
+ }
859
+ }
860
+ StaveNote.DEBUG = false;