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,670 @@
1
+ import { VexFlowTests } from './vexflow_test_helpers.js';
2
+ import { Accidental } from '../src/accidental.js';
3
+ import { Annotation, AnnotationVerticalJustify } from '../src/annotation.js';
4
+ import { Articulation } from '../src/articulation.js';
5
+ import { Beam } from '../src/beam.js';
6
+ import { Bend } from '../src/bend.js';
7
+ import { Dot } from '../src/dot.js';
8
+ import { Flow } from '../src/flow.js';
9
+ import { Font, FontWeight } from '../src/font.js';
10
+ import { Formatter } from '../src/formatter.js';
11
+ import { FretHandFinger } from '../src/frethandfinger.js';
12
+ import { ModifierPosition } from '../src/modifier.js';
13
+ import { Note } from '../src/note.js';
14
+ import { Registry } from '../src/registry.js';
15
+ import { Stave } from '../src/stave.js';
16
+ import { StaveConnector } from '../src/staveconnector.js';
17
+ import { StaveNote } from '../src/stavenote.js';
18
+ import { Stem } from '../src/stem.js';
19
+ import { StringNumber } from '../src/stringnumber.js';
20
+ import { Tables } from '../src/tables.js';
21
+ import { Tuplet } from '../src/tuplet.js';
22
+ import { Voice } from '../src/voice.js';
23
+ import { MockTickable } from './mocks.js';
24
+ const FormatterTests = {
25
+ Start() {
26
+ QUnit.module('Formatter');
27
+ test('TickContext Building', buildTickContexts);
28
+ const run = VexFlowTests.runTests;
29
+ run('Whitespace and justify', rightJustify);
30
+ run('Notehead padding', noteHeadPadding);
31
+ run('Justification and alignment with accidentals', accidentalJustification);
32
+ run('Long measure taking full space', longMeasureProblems);
33
+ run('Vertical alignment - few unaligned beats', unalignedNoteDurations1);
34
+ run('Vertical alignment - many unaligned beats', unalignedNoteDurations2, { globalSoftmax: false });
35
+ run('Vertical alignment - many unaligned beats (global softmax)', unalignedNoteDurations2, { globalSoftmax: true });
36
+ run('Vertical alignment - many mixed elements', alignedMixedElements, { globalSoftmax: true });
37
+ run('StaveNote - Justification', justifyStaveNotes);
38
+ run('Notes with Tab', notesWithTab);
39
+ run('Multiple Staves - Justified', multiStaves, { debug: true });
40
+ run('Softmax', softMax);
41
+ run('Mixtime', mixTime);
42
+ run('Tight', tightNotes1);
43
+ run('Tight 2', tightNotes2);
44
+ run('Annotations', annotations);
45
+ run('Proportional Formatting - No Tuning', proportional, { debug: true, iterations: 0 });
46
+ run('Proportional Formatting - No Justification', proportional, { justify: false, debug: true, iterations: 0 });
47
+ run('Proportional Formatting (20 iterations)', proportional, { debug: true, iterations: 20, alpha: 0.5 });
48
+ },
49
+ };
50
+ function getGlyphWidth(glyphName) {
51
+ const musicFont = Tables.currentMusicFont();
52
+ const glyph = musicFont.getGlyphs()[glyphName];
53
+ const widthInEm = (glyph.x_max - glyph.x_min) / musicFont.getResolution();
54
+ return widthInEm * 38 * Font.scaleToPxFrom.pt;
55
+ }
56
+ function buildTickContexts() {
57
+ function createTickable(beat) {
58
+ return new MockTickable().setTicks(beat);
59
+ }
60
+ const BEAT = (1 * Flow.RESOLUTION) / 4;
61
+ const tickables1 = [
62
+ createTickable(BEAT).setWidth(10),
63
+ createTickable(BEAT * 2).setWidth(20),
64
+ createTickable(BEAT).setWidth(30),
65
+ ];
66
+ const tickables2 = [
67
+ createTickable(BEAT * 2).setWidth(10),
68
+ createTickable(BEAT).setWidth(20),
69
+ createTickable(BEAT).setWidth(30),
70
+ ];
71
+ const voice1 = new Voice(Flow.TIME4_4);
72
+ const voice2 = new Voice(Flow.TIME4_4);
73
+ voice1.addTickables(tickables1);
74
+ voice2.addTickables(tickables2);
75
+ const formatter = new Formatter();
76
+ const tContexts = formatter.createTickContexts([voice1, voice2]);
77
+ equal(tContexts.list.length, 4, 'Voices should have four tick contexts');
78
+ throws(() => formatter.getMinTotalWidth(), /NoMinTotalWidth/, 'Expected to throw exception');
79
+ ok(formatter.preCalculateMinTotalWidth([voice1, voice2]), 'Successfully runs preCalculateMinTotalWidth');
80
+ equal(formatter.getMinTotalWidth(), 88, 'Get minimum total width without passing voices');
81
+ formatter.preFormat();
82
+ equal(formatter.getMinTotalWidth(), 88, 'Minimum total width');
83
+ equal(tickables1[0].getX(), tickables2[0].getX(), 'First notes of both voices have the same X');
84
+ equal(tickables1[2].getX(), tickables2[2].getX(), 'Last notes of both voices have the same X');
85
+ ok(tickables1[1].getX() < tickables2[1].getX(), 'Second note of voice 2 is to the right of the second note of voice 1');
86
+ }
87
+ function rightJustify(options) {
88
+ const f = VexFlowTests.makeFactory(options, 1200, 300);
89
+ const getTickables = (time, n, duration, duration2) => {
90
+ const tickar = [];
91
+ let i = 0;
92
+ for (i = 0; i < n; ++i) {
93
+ const dd = i === n - 1 ? duration2 : duration;
94
+ tickar.push(new StaveNote({ keys: ['f/4'], duration: dd }));
95
+ }
96
+ return new Voice(time).addTickables(tickar);
97
+ };
98
+ const renderTest = (time, n, duration, duration2, x, width) => {
99
+ const formatter = f.Formatter();
100
+ const stave = f.Stave({ x, y: 40, width });
101
+ const voice = getTickables(time, n, duration, duration2);
102
+ formatter.joinVoices([voice]).formatToStave([voice], stave);
103
+ stave.draw();
104
+ voice.draw(f.getContext(), stave);
105
+ };
106
+ renderTest({ num_beats: 4, beat_value: 4, resolution: 4 * 4096 }, 3, '4', '2', 10, 300);
107
+ renderTest({ num_beats: 4, beat_value: 4, resolution: 4 * 4096 }, 1, 'w', 'w', 310, 300);
108
+ renderTest({ num_beats: 3, beat_value: 4, resolution: 4 * 4096 }, 3, '4', '4', 610, 300);
109
+ renderTest({ num_beats: 3, beat_value: 4, resolution: 4 * 4096 }, 6, '8', '8', 910, 300);
110
+ ok(true);
111
+ }
112
+ function noteHeadPadding(options) {
113
+ const registry = new Registry();
114
+ Registry.enableDefaultRegistry(registry);
115
+ const f = VexFlowTests.makeFactory(options, 600, 300);
116
+ const score = f.EasyScore();
117
+ score.set({ time: '9/8' });
118
+ const notes1 = score.notes('(d5 f5)/8,(c5 e5)/8,(d5 f5)/8,(c5 e5)/2.');
119
+ const beams = [new Beam(notes1.slice(0, 3), true)];
120
+ const voice1 = new Voice().setMode(Voice.Mode.SOFT);
121
+ const notes2 = score.notes('(g4 an4)/2.,(g4 a4)/4.', { clef: 'treble' });
122
+ const voice2 = new Voice().setMode(Voice.Mode.SOFT);
123
+ voice2.addTickables(notes2);
124
+ voice1.addTickables(notes1);
125
+ const formatter = f.Formatter().joinVoices([voice1]).joinVoices([voice2]);
126
+ const width = formatter.preCalculateMinTotalWidth([voice1, voice2]);
127
+ formatter.format([voice1, voice2], width);
128
+ const staveWidth = width + Stave.defaultPadding;
129
+ const stave1 = f.Stave({ y: 50, width: staveWidth });
130
+ const stave2 = f.Stave({ y: 150, width: staveWidth });
131
+ stave1.draw();
132
+ stave2.draw();
133
+ voice1.draw(f.getContext(), stave1);
134
+ voice2.draw(f.getContext(), stave2);
135
+ beams.forEach((b) => b.setContext(f.getContext()).draw());
136
+ ok(true);
137
+ }
138
+ function longMeasureProblems(options) {
139
+ const registry = new Registry();
140
+ Registry.enableDefaultRegistry(registry);
141
+ const f = VexFlowTests.makeFactory(options, 1500, 300);
142
+ const score = f.EasyScore();
143
+ score.set({ time: '4/4' });
144
+ const notes1 = score.notes('b4/4,b4/8,b4/8,b4/4,b4/4,b4/2,b4/2,b4/4,b4/8,b4/8,b4/4,b4/4,b4/2,b4/2,b4/4,b4/8,b4/8,b4/4,b4/4,b4/2,b4/2,b4/4,b4/2,b4/8,b4/8');
145
+ const voice1 = new Voice().setMode(Voice.Mode.SOFT);
146
+ const notes2 = score.notes('d3/4,(ab3 f4)/2,d3/4,ab3/4,d3/2,ab3/4,d3/4,ab3/2,d3/4,ab3/4,d3/2,ab3/4,d3/4,ab3/2,d3/4,ab3/4,d3/2,ab3/4,d4/4,d4/2,d4/4', { clef: 'bass' });
147
+ const voice2 = new Voice().setMode(Voice.Mode.SOFT);
148
+ voice2.addTickables(notes2);
149
+ voice1.addTickables(notes1);
150
+ const formatter = f.Formatter().joinVoices([voice1]).joinVoices([voice2]);
151
+ const width = formatter.preCalculateMinTotalWidth([voice1, voice2]);
152
+ formatter.format([voice1, voice2], width);
153
+ const stave1 = f.Stave({ y: 50, width: width + Stave.defaultPadding });
154
+ const stave2 = f.Stave({ y: 200, width: width + Stave.defaultPadding });
155
+ stave1.draw();
156
+ stave2.draw();
157
+ voice1.draw(f.getContext(), stave1);
158
+ voice2.draw(f.getContext(), stave2);
159
+ ok(true);
160
+ }
161
+ function accidentalJustification(options) {
162
+ const f = VexFlowTests.makeFactory(options, 600, 300);
163
+ const score = f.EasyScore();
164
+ const notes11 = score.notes('a4/2, a4/4, a4/8, ab4/16, an4/16');
165
+ const voice11 = score.voice(notes11, { time: '4/4' });
166
+ const notes21 = score.notes('c4/2, d4/8, d4/8, e4/8, e4/8');
167
+ const voice21 = score.voice(notes21, { time: '4/4' });
168
+ let beams = Beam.generateBeams(notes11.slice(2));
169
+ beams = beams.concat(beams, Beam.generateBeams(notes21.slice(1, 3)));
170
+ beams = beams.concat(Beam.generateBeams(notes21.slice(3)));
171
+ const formatter = f.Formatter({ softmaxFactor: 100 }).joinVoices([voice11]).joinVoices([voice21]);
172
+ const width = formatter.preCalculateMinTotalWidth([voice11, voice21]);
173
+ const stave11 = f.Stave({ y: 20, width: width + Stave.defaultPadding });
174
+ const stave21 = f.Stave({ y: 130, width: width + Stave.defaultPadding });
175
+ formatter.format([voice11, voice21], width);
176
+ const ctx = f.getContext();
177
+ stave11.setContext(ctx).draw();
178
+ stave21.setContext(ctx).draw();
179
+ voice11.draw(ctx, stave11);
180
+ voice21.draw(ctx, stave21);
181
+ beams.forEach((b) => b.setContext(ctx).draw());
182
+ ok(true);
183
+ }
184
+ function unalignedNoteDurations1(options) {
185
+ const f = VexFlowTests.makeFactory(options, 600, 250);
186
+ const score = f.EasyScore();
187
+ const notes11 = [
188
+ new StaveNote({ keys: ['a/4'], duration: '8' }),
189
+ new StaveNote({ keys: ['b/4'], duration: '4' }),
190
+ new StaveNote({ keys: ['b/4'], duration: '8' }),
191
+ ];
192
+ const notes21 = [
193
+ new StaveNote({ keys: ['a/4'], duration: '16' }),
194
+ new StaveNote({ keys: ['b/4.'], duration: '4' }),
195
+ new StaveNote({ keys: ['a/4'], duration: '8d' }),
196
+ ];
197
+ Dot.buildAndAttach([notes21[2]], { all: true });
198
+ const ctx = f.getContext();
199
+ const voice11 = score.voice(notes11, { time: '2/4' }).setMode(Voice.Mode.SOFT);
200
+ const voice21 = score.voice(notes21, { time: '2/4' }).setMode(Voice.Mode.SOFT);
201
+ const beams21 = Beam.generateBeams(notes21);
202
+ const beams11 = Beam.generateBeams(notes11);
203
+ const formatter = new Formatter();
204
+ formatter.joinVoices([voice11]);
205
+ formatter.joinVoices([voice21]);
206
+ const width = formatter.preCalculateMinTotalWidth([voice11, voice21]);
207
+ const stave11 = f.Stave({ y: 20, width: width + Stave.defaultPadding });
208
+ const stave21 = f.Stave({ y: 130, width: width + Stave.defaultPadding });
209
+ formatter.format([voice11, voice21], width);
210
+ stave11.setContext(ctx).draw();
211
+ stave21.setContext(ctx).draw();
212
+ voice11.draw(ctx, stave11);
213
+ voice21.draw(ctx, stave21);
214
+ beams21.forEach((b) => b.setContext(ctx).draw());
215
+ beams11.forEach((b) => b.setContext(ctx).draw());
216
+ ok(voice11.getTickables()[1].getX() > voice21.getTickables()[1].getX());
217
+ }
218
+ function unalignedNoteDurations2(options) {
219
+ const notes1 = [
220
+ new StaveNote({ keys: ['b/4'], duration: '8r' }),
221
+ new StaveNote({ keys: ['g/4'], duration: '16' }),
222
+ new StaveNote({ keys: ['c/5'], duration: '16' }),
223
+ new StaveNote({ keys: ['e/5'], duration: '16' }),
224
+ new StaveNote({ keys: ['g/4'], duration: '16' }),
225
+ new StaveNote({ keys: ['c/5'], duration: '16' }),
226
+ new StaveNote({ keys: ['e/5'], duration: '16' }),
227
+ new StaveNote({ keys: ['b/4'], duration: '8r' }),
228
+ new StaveNote({ keys: ['g/4'], duration: '16' }),
229
+ new StaveNote({ keys: ['c/5'], duration: '16' }),
230
+ new StaveNote({ keys: ['e/5'], duration: '16' }),
231
+ new StaveNote({ keys: ['g/4'], duration: '16' }),
232
+ new StaveNote({ keys: ['c/5'], duration: '16' }),
233
+ new StaveNote({ keys: ['e/5'], duration: '16' }),
234
+ ];
235
+ const notes2 = [
236
+ new StaveNote({ keys: ['a/4'], duration: '16r' }),
237
+ new StaveNote({ keys: ['e/4.'], duration: '8d' }),
238
+ new StaveNote({ keys: ['e/4'], duration: '4' }),
239
+ new StaveNote({ keys: ['a/4'], duration: '16r' }),
240
+ new StaveNote({ keys: ['e/4.'], duration: '8d' }),
241
+ new StaveNote({ keys: ['e/4'], duration: '4' }),
242
+ ];
243
+ const f = VexFlowTests.makeFactory(options, 750, 280);
244
+ const context = f.getContext();
245
+ const voice1 = new Voice({ num_beats: 4, beat_value: 4 });
246
+ voice1.addTickables(notes1);
247
+ const voice2 = new Voice({ num_beats: 4, beat_value: 4 });
248
+ voice2.addTickables(notes2);
249
+ const formatter = new Formatter({ softmaxFactor: 100, globalSoftmax: options.params.globalSoftmax });
250
+ formatter.joinVoices([voice1]);
251
+ formatter.joinVoices([voice2]);
252
+ const width = formatter.preCalculateMinTotalWidth([voice1, voice2]);
253
+ formatter.format([voice1, voice2], width);
254
+ const stave1 = new Stave(10, 40, width + Stave.defaultPadding);
255
+ const stave2 = new Stave(10, 100, width + Stave.defaultPadding);
256
+ stave1.setContext(context).draw();
257
+ stave2.setContext(context).draw();
258
+ voice1.draw(context, stave1);
259
+ voice2.draw(context, stave2);
260
+ ok(voice1.getTickables()[1].getX() > voice2.getTickables()[1].getX());
261
+ }
262
+ function alignedMixedElements(options) {
263
+ const f = VexFlowTests.makeFactory(options, 800, 500);
264
+ const context = f.getContext();
265
+ const stave = new Stave(10, 200, 400);
266
+ const stave2 = new Stave(410, 200, 400);
267
+ const notes = [
268
+ new StaveNote({ keys: ['c/5'], duration: '8' })
269
+ .addModifier(new Accidental('##'), 0)
270
+ .addModifier(new FretHandFinger('4').setPosition(ModifierPosition.BELOW), 0)
271
+ .addModifier(new StringNumber('3').setPosition(ModifierPosition.BELOW), 0)
272
+ .addModifier(new Articulation('a.').setPosition(ModifierPosition.BELOW), 0)
273
+ .addModifier(new Articulation('a>').setPosition(ModifierPosition.BELOW), 0)
274
+ .addModifier(new Articulation('a^').setPosition(ModifierPosition.BELOW), 0)
275
+ .addModifier(new Articulation('am').setPosition(ModifierPosition.BELOW), 0)
276
+ .addModifier(new Articulation('a@u').setPosition(ModifierPosition.BELOW), 0)
277
+ .addModifier(new Annotation('yyyy').setVerticalJustification(AnnotationVerticalJustify.BOTTOM), 0)
278
+ .addModifier(new Annotation('xxxx').setVerticalJustification(AnnotationVerticalJustify.BOTTOM).setFont('sans-serif', 20), 0)
279
+ .addModifier(new Annotation('ttt').setVerticalJustification(AnnotationVerticalJustify.BOTTOM).setFont('sans-serif', 20), 0),
280
+ new StaveNote({ keys: ['c/5'], duration: '8', stem_direction: Stem.DOWN })
281
+ .addModifier(new StringNumber('3').setPosition(ModifierPosition.BELOW), 0)
282
+ .addModifier(new Articulation('a.').setPosition(ModifierPosition.BELOW), 0)
283
+ .addModifier(new Articulation('a>').setPosition(ModifierPosition.BELOW), 0),
284
+ new StaveNote({ keys: ['c/5'], duration: '8' }),
285
+ ];
286
+ const notes2 = [
287
+ new StaveNote({ keys: ['c/5'], duration: '8' })
288
+ .addModifier(new StringNumber('3').setPosition(ModifierPosition.ABOVE), 0)
289
+ .addModifier(new Articulation('a.').setPosition(ModifierPosition.ABOVE), 0)
290
+ .addModifier(new Annotation('yyyy').setVerticalJustification(AnnotationVerticalJustify.TOP), 0),
291
+ new StaveNote({ keys: ['c/5'], duration: '8', stem_direction: Stem.DOWN })
292
+ .addModifier(new FretHandFinger('4').setPosition(ModifierPosition.ABOVE), 0)
293
+ .addModifier(new StringNumber('3').setPosition(ModifierPosition.ABOVE), 0)
294
+ .addModifier(new Articulation('a.').setPosition(ModifierPosition.ABOVE), 0)
295
+ .addModifier(new Articulation('a>').setPosition(ModifierPosition.ABOVE), 0)
296
+ .addModifier(new Articulation('a^').setPosition(ModifierPosition.ABOVE), 0)
297
+ .addModifier(new Articulation('am').setPosition(ModifierPosition.ABOVE), 0)
298
+ .addModifier(new Articulation('a@u').setPosition(ModifierPosition.ABOVE), 0)
299
+ .addModifier(new Annotation('yyyy').setVerticalJustification(AnnotationVerticalJustify.TOP), 0)
300
+ .addModifier(new Annotation('xxxx').setVerticalJustification(AnnotationVerticalJustify.TOP).setFont('sans-serif', 20), 0)
301
+ .addModifier(new Annotation('ttt').setVerticalJustification(AnnotationVerticalJustify.TOP).setFont('sans-serif', 20), 0),
302
+ new StaveNote({ keys: ['c/5'], duration: '8' }),
303
+ ];
304
+ const tuplet = new Tuplet(notes).setTupletLocation(-1);
305
+ const tuplet2 = new Tuplet(notes2).setTupletLocation(1);
306
+ Formatter.FormatAndDraw(context, stave, notes);
307
+ Formatter.FormatAndDraw(context, stave2, notes2);
308
+ stave.setContext(context).draw();
309
+ stave2.setContext(context).draw();
310
+ tuplet.setContext(context).draw();
311
+ tuplet2.setContext(context).draw();
312
+ ok(true);
313
+ }
314
+ function justifyStaveNotes(options) {
315
+ const f = VexFlowTests.makeFactory(options, 520, 280);
316
+ const ctx = f.getContext();
317
+ const score = f.EasyScore();
318
+ let y = 30;
319
+ function justifyToWidth(width) {
320
+ f.Stave({ y: y }).addClef('treble');
321
+ const voices = [
322
+ score.voice(score.notes('(cbb4 en4 a4)/2, (d4 e4 f4)/8, (d4 f4 a4)/8, (cn4 f#4 a4)/4', { stem: 'down' })),
323
+ score.voice(score.notes('(bb4 e#5 a5)/4, (d5 e5 f5)/2, (c##5 fb5 a5)/4', { stem: 'up' })),
324
+ ];
325
+ f.Formatter()
326
+ .joinVoices(voices)
327
+ .format(voices, width - (Stave.defaultPadding + getGlyphWidth('gClef')));
328
+ voices[0].getTickables().forEach((note) => Note.plotMetrics(ctx, note, y + 140));
329
+ voices[1].getTickables().forEach((note) => Note.plotMetrics(ctx, note, y - 20));
330
+ y += 210;
331
+ }
332
+ justifyToWidth(520);
333
+ f.draw();
334
+ ok(true);
335
+ }
336
+ function notesWithTab(options) {
337
+ const f = VexFlowTests.makeFactory(options, 420, 580);
338
+ const score = f.EasyScore();
339
+ let y = 10;
340
+ function justifyToWidth(width) {
341
+ const stave = f.Stave({ y: y }).addClef('treble');
342
+ const voice = score.voice(score.notes('d#4/2, (c4 d4)/8, d4/8, (c#4 e4 a4)/4', { stem: 'up' }));
343
+ y += 100;
344
+ f.TabStave({ y: y }).addTabGlyph().setNoteStartX(stave.getNoteStartX());
345
+ const tabVoice = score.voice([
346
+ f.TabNote({ positions: [{ str: 3, fret: 6 }], duration: '2' }).addModifier(new Bend('Full'), 0),
347
+ f
348
+ .TabNote({
349
+ positions: [
350
+ { str: 2, fret: 3 },
351
+ { str: 3, fret: 5 },
352
+ ],
353
+ duration: '8',
354
+ })
355
+ .addModifier(new Bend('Unison'), 1),
356
+ f.TabNote({ positions: [{ str: 3, fret: 7 }], duration: '8' }),
357
+ f.TabNote({
358
+ positions: [
359
+ { str: 3, fret: 6 },
360
+ { str: 4, fret: 7 },
361
+ { str: 2, fret: 5 },
362
+ ],
363
+ duration: '4',
364
+ }),
365
+ ]);
366
+ f.Formatter().joinVoices([voice]).joinVoices([tabVoice]).format([voice, tabVoice], width);
367
+ y += 150;
368
+ }
369
+ justifyToWidth(0);
370
+ justifyToWidth(300);
371
+ f.draw();
372
+ ok(true);
373
+ }
374
+ function multiStaves(options) {
375
+ const f = VexFlowTests.makeFactory(options, 600, 400);
376
+ const ctx = f.getContext();
377
+ const score = f.EasyScore();
378
+ const notes11 = score.notes('f4/4, d4/8, g4/4, eb4/8');
379
+ const notes21 = score.notes('d4/8, d4, d4, d4, e4, eb4');
380
+ const notes31 = score.notes('a5/8, a5, a5, a5, a5, a5', { stem: 'down' });
381
+ let voices = [
382
+ score.voice(notes11, { time: '6/8' }),
383
+ score.voice(notes21, { time: '6/8' }),
384
+ score.voice(notes31, { time: '6/8' }),
385
+ ];
386
+ let formatter = f.Formatter();
387
+ voices.forEach((v) => formatter.joinVoices([v]));
388
+ let width = formatter.preCalculateMinTotalWidth(voices);
389
+ formatter.format(voices, width);
390
+ let beams = [
391
+ new Beam(notes21.slice(0, 3), true),
392
+ new Beam(notes21.slice(3, 6), true),
393
+ new Beam(notes31.slice(0, 3), true),
394
+ new Beam(notes31.slice(3, 6), true),
395
+ ];
396
+ const staveYs = [20, 130, 250];
397
+ let staveWidth = width + getGlyphWidth('gClef') + getGlyphWidth('timeSig8') + Stave.defaultPadding;
398
+ let staves = [
399
+ f.Stave({ y: staveYs[0], width: staveWidth }).addClef('treble').addTimeSignature('6/8'),
400
+ f.Stave({ y: staveYs[1], width: staveWidth }).addClef('treble').addTimeSignature('6/8'),
401
+ f.Stave({ y: staveYs[2], width: staveWidth }).addClef('bass').addTimeSignature('6/8'),
402
+ ];
403
+ f.StaveConnector({
404
+ top_stave: staves[1],
405
+ bottom_stave: staves[2],
406
+ type: 'brace',
407
+ });
408
+ for (let i = 0; i < staves.length; ++i) {
409
+ staves[i].setContext(ctx).draw();
410
+ voices[i].draw(ctx, staves[i]);
411
+ }
412
+ beams.forEach((beam) => beam.setContext(ctx).draw());
413
+ const notes12 = score.notes('ab4/4, bb4/8, (cb5 eb5)/4[stem="down"], d5/8[stem="down"]');
414
+ const notes22 = score.notes('(eb4 ab4)/4., (c4 eb4 ab4)/4, db5/8', { stem: 'up' });
415
+ const notes32 = score.notes('a5/8, a5, a5, a5, a5, a5', { stem: 'down' });
416
+ voices = [
417
+ score.voice(notes12, { time: '6/8' }),
418
+ score.voice(notes22, { time: '6/8' }),
419
+ score.voice(notes32, { time: '6/8' }),
420
+ ];
421
+ formatter = f.Formatter();
422
+ voices.forEach((v) => formatter.joinVoices([v]));
423
+ width = formatter.preCalculateMinTotalWidth(voices);
424
+ const staveX = staves[0].getX() + staves[0].getWidth();
425
+ staveWidth = width + Stave.defaultPadding;
426
+ staves = [
427
+ f.Stave({ x: staveX, y: staveYs[0], width: staveWidth }),
428
+ f.Stave({ x: staveX, y: staveYs[1], width: staveWidth }),
429
+ f.Stave({ x: staveX, y: staveYs[2], width: staveWidth }),
430
+ ];
431
+ formatter.format(voices, width);
432
+ beams = [
433
+ new Beam(notes32.slice(0, 3), true),
434
+ new Beam(notes32.slice(3, 6), true),
435
+ ];
436
+ for (let i = 0; i < staves.length; ++i) {
437
+ staves[i].setContext(ctx).draw();
438
+ voices[i].draw(ctx, staves[i]);
439
+ voices[i].getTickables().forEach((note) => Note.plotMetrics(ctx, note, staveYs[i] - 20));
440
+ }
441
+ beams.forEach((beam) => beam.setContext(ctx).draw());
442
+ ok(true);
443
+ }
444
+ function proportional(options) {
445
+ const debug = options.params.debug;
446
+ Registry.enableDefaultRegistry(new Registry());
447
+ const f = VexFlowTests.makeFactory(options, 775, 750);
448
+ const system = f.System({
449
+ x: 50,
450
+ autoWidth: true,
451
+ debugFormatter: debug,
452
+ noJustification: !(options.params.justify === undefined && true),
453
+ formatIterations: options.params.iterations,
454
+ details: { alpha: options.params.alpha },
455
+ });
456
+ const score = f.EasyScore();
457
+ const voices = [
458
+ score.notes('c5/8, c5'),
459
+ score.tuplet(score.notes('a4/8, a4, a4'), { notes_occupied: 2 }),
460
+ score.notes('c5/16, c5, c5, c5'),
461
+ score.tuplet(score.notes('a4/16, a4, a4, a4, a4'), { notes_occupied: 4 }),
462
+ score.tuplet(score.notes('a4/32, a4, a4, a4, a4, a4, a4'), { notes_occupied: 8 }),
463
+ ];
464
+ const createVoice = (notes) => score.voice(notes, { time: '1/4' });
465
+ const createStave = (voice) => system
466
+ .addStave({ voices: [voice], debugNoteMetrics: debug })
467
+ .addClef('treble')
468
+ .addTimeSignature('1/4');
469
+ voices.map(createVoice).forEach(createStave);
470
+ system.addConnector().setType(StaveConnector.type.BRACKET);
471
+ f.draw();
472
+ Registry.disableDefaultRegistry();
473
+ ok(true);
474
+ }
475
+ function softMax(options) {
476
+ const f = VexFlowTests.makeFactory(options, 550, 500);
477
+ f.getContext().scale(0.8, 0.8);
478
+ function draw(y, factor) {
479
+ const score = f.EasyScore();
480
+ const system = f.System({
481
+ x: 100,
482
+ y,
483
+ details: { softmaxFactor: factor },
484
+ autoWidth: true,
485
+ });
486
+ system
487
+ .addStave({
488
+ voices: [
489
+ score.voice(score
490
+ .notes('C#5/h, a4/q')
491
+ .concat(score.beam(score.notes('Abb4/8, A4/8')))
492
+ .concat(score.beam(score.notes('A4/16, A#4, A4, Ab4/32, A4'))), { time: '5/4' }),
493
+ ],
494
+ })
495
+ .addClef('treble')
496
+ .addTimeSignature('5/4');
497
+ f.draw();
498
+ ok(true);
499
+ }
500
+ draw(50, 1);
501
+ draw(150, 2);
502
+ draw(250, 10);
503
+ draw(350, 20);
504
+ draw(450, 200);
505
+ }
506
+ function mixTime(options) {
507
+ const f = VexFlowTests.makeFactory(options, 400 + Stave.defaultPadding, 250);
508
+ f.getContext().scale(0.8, 0.8);
509
+ const score = f.EasyScore();
510
+ const system = f.System({
511
+ details: { softmaxFactor: 100 },
512
+ autoWidth: true,
513
+ debugFormatter: true,
514
+ });
515
+ system
516
+ .addStave({
517
+ voices: [score.voice(score.notes('C#5/q, B4').concat(score.beam(score.notes('A4/8, E4, C4, D4'))))],
518
+ })
519
+ .addClef('treble')
520
+ .addTimeSignature('4/4');
521
+ system
522
+ .addStave({
523
+ voices: [score.voice(score.notes('C#5/q, B4, B4').concat(score.tuplet(score.beam(score.notes('A4/8, E4, C4')))))],
524
+ })
525
+ .addClef('treble')
526
+ .addTimeSignature('4/4');
527
+ f.draw();
528
+ ok(true);
529
+ }
530
+ function tightNotes1(options) {
531
+ const f = VexFlowTests.makeFactory(options, 440, 250);
532
+ f.getContext().scale(0.8, 0.8);
533
+ const score = f.EasyScore();
534
+ const system = f.System({
535
+ autoWidth: true,
536
+ debugFormatter: true,
537
+ details: { maxIterations: 10 },
538
+ });
539
+ system
540
+ .addStave({
541
+ voices: [
542
+ score.voice(score.beam(score.notes('B4/16, B4, B4, B4, B4, B4, B4, B4')).concat(score.notes('B4/q, B4'))),
543
+ ],
544
+ })
545
+ .addClef('treble')
546
+ .addTimeSignature('4/4');
547
+ system
548
+ .addStave({
549
+ voices: [
550
+ score.voice(score.notes('B4/q, B4').concat(score.beam(score.notes('B4/16, B4, B4, B4, B4, B4, B4, B4')))),
551
+ ],
552
+ })
553
+ .addClef('treble')
554
+ .addTimeSignature('4/4');
555
+ f.draw();
556
+ ok(true);
557
+ }
558
+ function tightNotes2(options) {
559
+ const f = VexFlowTests.makeFactory(options, 440, 250);
560
+ f.getContext().scale(0.8, 0.8);
561
+ const score = f.EasyScore();
562
+ const system = f.System({
563
+ autoWidth: true,
564
+ debugFormatter: true,
565
+ });
566
+ system
567
+ .addStave({
568
+ voices: [
569
+ score.voice(score.beam(score.notes('B4/16, B4, B4, B4, B4, B4, B4, B4')).concat(score.notes('B4/q, B4'))),
570
+ ],
571
+ })
572
+ .addClef('treble')
573
+ .addTimeSignature('4/4');
574
+ system
575
+ .addStave({
576
+ voices: [score.voice(score.notes('B4/w'))],
577
+ })
578
+ .addClef('treble')
579
+ .addTimeSignature('4/4');
580
+ f.draw();
581
+ ok(true);
582
+ }
583
+ function annotations(options) {
584
+ const pageWidth = 916;
585
+ const pageHeight = 600;
586
+ const f = VexFlowTests.makeFactory(options, pageWidth, pageHeight);
587
+ const context = f.getContext();
588
+ const lyrics1 = ['ipso', 'ipso-', 'ipso', 'ipso', 'ipsoz', 'ipso-', 'ipso', 'ipso', 'ipso', 'ip', 'ipso'];
589
+ const lyrics2 = ['ipso', 'ipso-', 'ipsoz', 'ipso', 'ipso', 'ipso-', 'ipso', 'ipso', 'ipso', 'ip', 'ipso'];
590
+ const smar = [
591
+ {
592
+ sm: 5,
593
+ width: 550,
594
+ lyrics: lyrics1,
595
+ title: '550px,softMax:5',
596
+ },
597
+ {
598
+ sm: 10,
599
+ width: 550,
600
+ lyrics: lyrics2,
601
+ title: '550px,softmax:10,different word order',
602
+ },
603
+ {
604
+ sm: 5,
605
+ width: 550,
606
+ lyrics: lyrics2,
607
+ title: '550px,softmax:5',
608
+ },
609
+ {
610
+ sm: 100,
611
+ width: 550,
612
+ lyrics: lyrics2,
613
+ title: '550px,softmax:100',
614
+ },
615
+ ];
616
+ const rowSize = 140;
617
+ const beats = 12;
618
+ const beatsPer = 8;
619
+ const beamGroup = 3;
620
+ const durations = ['8d', '16', '8', '8d', '16', '8', '8d', '16', '8', '4', '8'];
621
+ const beams = [];
622
+ let y = 40;
623
+ smar.forEach((sm) => {
624
+ const stave = new Stave(10, y, sm.width);
625
+ const notes = [];
626
+ let iii = 0;
627
+ context.fillText(sm.title, 100, y);
628
+ y += rowSize;
629
+ durations.forEach((dd) => {
630
+ const note = new StaveNote({ keys: ['b/4'], duration: dd });
631
+ if (dd.indexOf('d') >= 0) {
632
+ Dot.buildAndAttach([note], { all: true });
633
+ }
634
+ if (sm.lyrics.length > iii) {
635
+ note.addModifier(new Annotation(sm.lyrics[iii])
636
+ .setVerticalJustification(Annotation.VerticalJustify.BOTTOM)
637
+ .setFont(Font.SERIF, 12, FontWeight.NORMAL));
638
+ }
639
+ notes.push(note);
640
+ iii += 1;
641
+ });
642
+ notes.forEach((note) => {
643
+ if (note.getDuration().indexOf('d') >= 0) {
644
+ Dot.buildAndAttach([note], { all: true });
645
+ }
646
+ });
647
+ let notesToBeam = [];
648
+ notes.forEach((note) => {
649
+ if (note.getIntrinsicTicks() < 4096) {
650
+ notesToBeam.push(note);
651
+ if (notesToBeam.length >= beamGroup) {
652
+ beams.push(new Beam(notesToBeam));
653
+ notesToBeam = [];
654
+ }
655
+ }
656
+ else {
657
+ notesToBeam = [];
658
+ }
659
+ });
660
+ const voice1 = new Voice({ num_beats: beats, beat_value: beatsPer }).setMode(Voice.Mode.SOFT).addTickables(notes);
661
+ const fmt = new Formatter({ softmaxFactor: sm.sm, maxIterations: 2 }).joinVoices([voice1]);
662
+ fmt.format([voice1], sm.width - 11);
663
+ stave.setContext(context).draw();
664
+ voice1.draw(context, stave);
665
+ beams.forEach((b) => b.setContext(context).draw());
666
+ });
667
+ ok(true);
668
+ }
669
+ VexFlowTests.register(FormatterTests);
670
+ export { FormatterTests };