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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (331) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +92 -24
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +38 -16
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow-font-gonville.js +1 -1
  10. package/build/cjs/vexflow-font-gonville.js.map +1 -1
  11. package/build/cjs/vexflow-gonville.js +2 -2
  12. package/build/cjs/vexflow-gonville.js.map +1 -1
  13. package/build/cjs/vexflow-petaluma.js +2 -2
  14. package/build/cjs/vexflow-petaluma.js.map +1 -1
  15. package/build/cjs/vexflow.js +2 -2
  16. package/build/cjs/vexflow.js.map +1 -1
  17. package/build/esm/entry/vexflow-bravura.js +11 -0
  18. package/build/esm/entry/vexflow-core.js +54 -0
  19. package/build/esm/entry/vexflow-debug-with-tests.js +4 -0
  20. package/build/esm/entry/vexflow-debug.js +3 -0
  21. package/build/esm/entry/vexflow-font-bravura.js +7 -0
  22. package/build/esm/entry/vexflow-font-custom.js +7 -0
  23. package/build/esm/entry/vexflow-font-gonville.js +7 -0
  24. package/build/esm/entry/vexflow-font-petaluma.js +7 -0
  25. package/build/esm/entry/vexflow-gonville.js +11 -0
  26. package/build/esm/entry/vexflow-petaluma.js +11 -0
  27. package/build/esm/entry/vexflow.js +9 -0
  28. package/build/esm/src/accidental.js +348 -0
  29. package/build/esm/src/annotation.js +232 -0
  30. package/build/esm/src/articulation.js +267 -0
  31. package/build/esm/src/barnote.js +58 -0
  32. package/build/esm/src/beam.js +632 -0
  33. package/build/esm/src/bend.js +202 -0
  34. package/build/esm/src/boundingbox.js +59 -0
  35. package/build/esm/src/boundingboxcomputation.js +107 -0
  36. package/build/esm/src/canvascontext.js +202 -0
  37. package/build/esm/src/chordsymbol.js +578 -0
  38. package/build/esm/src/clef.js +153 -0
  39. package/build/esm/src/clefnote.js +65 -0
  40. package/build/esm/src/crescendo.js +77 -0
  41. package/build/esm/src/curve.js +118 -0
  42. package/build/esm/src/dot.js +137 -0
  43. package/build/esm/src/easyscore.js +374 -0
  44. package/build/esm/src/element.js +216 -0
  45. package/build/esm/src/factory.js +440 -0
  46. package/build/esm/src/flow.js +275 -0
  47. package/build/esm/src/font.js +264 -0
  48. package/build/esm/src/fonts/bravura_glyphs.js +3239 -0
  49. package/build/esm/src/fonts/bravura_metrics.js +507 -0
  50. package/build/esm/src/fonts/custom_glyphs.js +78 -0
  51. package/build/esm/src/fonts/custom_metrics.js +5 -0
  52. package/build/esm/src/fonts/gonville_glyphs.js +828 -0
  53. package/build/esm/src/fonts/gonville_metrics.js +421 -0
  54. package/build/esm/src/fonts/load_all.js +10 -0
  55. package/build/esm/src/fonts/load_bravura.js +6 -0
  56. package/build/esm/src/fonts/load_custom.js +6 -0
  57. package/build/esm/src/fonts/load_gonville.js +6 -0
  58. package/build/esm/src/fonts/load_petaluma.js +6 -0
  59. package/build/esm/src/fonts/petaluma_glyphs.js +1335 -0
  60. package/build/esm/src/fonts/petaluma_metrics.js +536 -0
  61. package/build/esm/src/fonts/petalumascript_glyphs.js +863 -0
  62. package/build/esm/src/fonts/robotoslab_glyphs.js +863 -0
  63. package/build/esm/src/fonts/textfonts.js +44 -0
  64. package/build/esm/src/formatter.js +568 -0
  65. package/build/esm/src/fraction.js +171 -0
  66. package/build/esm/src/frethandfinger.js +156 -0
  67. package/build/esm/src/ghostnote.js +50 -0
  68. package/build/esm/src/glyph.js +331 -0
  69. package/build/esm/src/glyphnote.js +55 -0
  70. package/build/esm/src/gracenote.js +133 -0
  71. package/build/esm/src/gracenotegroup.js +128 -0
  72. package/build/esm/src/gracetabnote.js +12 -0
  73. package/build/esm/src/index.js +91 -0
  74. package/build/esm/src/keymanager.js +99 -0
  75. package/build/esm/src/keysignature.js +250 -0
  76. package/build/esm/src/keysignote.js +28 -0
  77. package/build/esm/src/modifier.js +128 -0
  78. package/build/esm/src/modifiercontext.js +110 -0
  79. package/build/esm/src/multimeasurerest.js +173 -0
  80. package/build/esm/src/music.js +322 -0
  81. package/build/esm/src/note.js +371 -0
  82. package/build/esm/src/notehead.js +169 -0
  83. package/build/esm/src/notesubgroup.js +59 -0
  84. package/build/esm/src/ornament.js +206 -0
  85. package/build/esm/src/parenthesis.js +76 -0
  86. package/build/esm/src/parser.js +164 -0
  87. package/build/esm/src/pedalmarking.js +192 -0
  88. package/build/esm/src/registry.js +81 -0
  89. package/build/esm/src/rendercontext.js +24 -0
  90. package/build/esm/src/renderer.js +112 -0
  91. package/build/esm/src/repeatnote.js +22 -0
  92. package/build/esm/src/stave.js +547 -0
  93. package/build/esm/src/stavebarline.js +182 -0
  94. package/build/esm/src/staveconnector.js +196 -0
  95. package/build/esm/src/stavehairpin.js +120 -0
  96. package/build/esm/src/staveline.js +218 -0
  97. package/build/esm/src/stavemodifier.js +77 -0
  98. package/build/esm/src/stavenote.js +855 -0
  99. package/build/esm/src/staverepetition.js +155 -0
  100. package/build/esm/src/stavesection.js +58 -0
  101. package/build/esm/src/stavetempo.js +91 -0
  102. package/build/esm/src/stavetext.js +82 -0
  103. package/build/esm/src/stavetie.js +141 -0
  104. package/build/esm/src/stavevolta.js +67 -0
  105. package/build/esm/src/stem.js +131 -0
  106. package/build/esm/src/stemmablenote.js +193 -0
  107. package/build/esm/src/stringnumber.js +231 -0
  108. package/build/esm/src/strokes.js +200 -0
  109. package/build/esm/src/svgcontext.js +414 -0
  110. package/build/esm/src/system.js +116 -0
  111. package/build/esm/src/tables.js +1102 -0
  112. package/build/esm/src/tabnote.js +299 -0
  113. package/build/esm/src/tabslide.js +76 -0
  114. package/build/esm/src/tabstave.js +17 -0
  115. package/build/esm/src/tabtie.js +19 -0
  116. package/build/esm/src/textbracket.js +144 -0
  117. package/build/esm/src/textdynamics.js +81 -0
  118. package/build/esm/src/textformatter.js +177 -0
  119. package/build/esm/src/textnote.js +176 -0
  120. package/build/esm/src/tickable.js +214 -0
  121. package/build/esm/src/tickcontext.js +170 -0
  122. package/build/esm/src/timesigglyph.js +85 -0
  123. package/build/esm/src/timesignature.js +89 -0
  124. package/build/esm/src/timesignote.js +32 -0
  125. package/build/esm/src/tremolo.js +47 -0
  126. package/build/esm/src/tuning.js +54 -0
  127. package/build/esm/src/tuplet.js +240 -0
  128. package/build/esm/src/typeguard.js +30 -0
  129. package/build/esm/src/util.js +58 -0
  130. package/build/esm/src/version.js +3 -3
  131. package/build/esm/src/vex.js +51 -0
  132. package/build/esm/src/vibrato.js +100 -0
  133. package/build/esm/src/vibratobracket.js +50 -0
  134. package/build/esm/src/voice.js +187 -0
  135. package/build/esm/src/web.js +15 -0
  136. package/build/esm/tests/accidental_tests.js +974 -0
  137. package/build/esm/tests/annotation_tests.js +377 -0
  138. package/build/esm/tests/articulation_tests.js +365 -0
  139. package/build/esm/tests/auto_beam_formatting_tests.js +548 -0
  140. package/build/esm/tests/bach_tests.js +335 -0
  141. package/build/esm/tests/barline_tests.js +52 -0
  142. package/build/esm/tests/beam_tests.js +595 -0
  143. package/build/esm/tests/bend_tests.js +215 -0
  144. package/build/esm/tests/boundingbox_tests.js +53 -0
  145. package/build/esm/tests/boundingboxcomputation_tests.js +183 -0
  146. package/build/esm/tests/chordsymbol_tests.js +320 -0
  147. package/build/esm/tests/clef_tests.js +131 -0
  148. package/build/esm/tests/curve_tests.js +118 -0
  149. package/build/esm/tests/dot_tests.js +123 -0
  150. package/build/esm/tests/easyscore_tests.js +459 -0
  151. package/build/esm/tests/factory_tests.js +44 -0
  152. package/build/esm/tests/font_tests.js +135 -0
  153. package/build/esm/tests/formatter/framestack.js +61 -0
  154. package/build/esm/tests/formatter/tests.js +203 -0
  155. package/build/esm/tests/formatter_tests.js +669 -0
  156. package/build/esm/tests/fraction_tests.js +72 -0
  157. package/build/esm/tests/ghostnote_tests.js +77 -0
  158. package/build/esm/tests/glyphnote_tests.js +113 -0
  159. package/build/esm/tests/gracenote_tests.js +413 -0
  160. package/build/esm/tests/gracetabnote_tests.js +79 -0
  161. package/build/esm/tests/index.js +68 -0
  162. package/build/esm/tests/key_clef_tests.js +103 -0
  163. package/build/esm/tests/keymanager_tests.js +68 -0
  164. package/build/esm/tests/keysignature_tests.js +308 -0
  165. package/build/esm/tests/mocks.js +71 -0
  166. package/build/esm/tests/modifier_tests.js +24 -0
  167. package/build/esm/tests/multimeasurerest_tests.js +141 -0
  168. package/build/esm/tests/music_tests.js +161 -0
  169. package/build/esm/tests/notehead_tests.js +137 -0
  170. package/build/esm/tests/notesubgroup_tests.js +149 -0
  171. package/build/esm/tests/offscreencanvas_tests.js +47 -0
  172. package/build/esm/tests/ornament_tests.js +298 -0
  173. package/build/esm/tests/parser_tests.js +122 -0
  174. package/build/esm/tests/pedalmarking_tests.js +64 -0
  175. package/build/esm/tests/percussion_tests.js +180 -0
  176. package/build/esm/tests/registry_tests.js +64 -0
  177. package/build/esm/tests/renderer_tests.js +113 -0
  178. package/build/esm/tests/rests_tests.js +248 -0
  179. package/build/esm/tests/rhythm_tests.js +357 -0
  180. package/build/esm/tests/stave_tests.js +560 -0
  181. package/build/esm/tests/staveconnector_tests.js +402 -0
  182. package/build/esm/tests/stavehairpin_tests.js +90 -0
  183. package/build/esm/tests/staveline_tests.js +122 -0
  184. package/build/esm/tests/stavemodifier_tests.js +51 -0
  185. package/build/esm/tests/stavenote_tests.js +867 -0
  186. package/build/esm/tests/stavetie_tests.js +108 -0
  187. package/build/esm/tests/stringnumber_tests.js +259 -0
  188. package/build/esm/tests/strokes_tests.js +275 -0
  189. package/build/esm/tests/style_tests.js +98 -0
  190. package/build/esm/tests/support/qunit.js +2765 -0
  191. package/build/esm/tests/tabnote_tests.js +474 -0
  192. package/build/esm/tests/tabslide_tests.js +135 -0
  193. package/build/esm/tests/tabstave_tests.js +23 -0
  194. package/build/esm/tests/tabtie_tests.js +173 -0
  195. package/build/esm/tests/textbracket_tests.js +100 -0
  196. package/build/esm/tests/textformatter_tests.js +24 -0
  197. package/build/esm/tests/textnote_tests.js +215 -0
  198. package/build/esm/tests/threevoice_tests.js +132 -0
  199. package/build/esm/tests/tickcontext_tests.js +36 -0
  200. package/build/esm/tests/timesignature_tests.js +134 -0
  201. package/build/esm/tests/tremolo_tests.js +75 -0
  202. package/build/esm/tests/tuning_tests.js +56 -0
  203. package/build/esm/tests/tuplet_tests.js +450 -0
  204. package/build/esm/tests/typeguard_tests.js +82 -0
  205. package/build/esm/tests/vexflow_test_helpers.js +266 -0
  206. package/build/esm/tests/vf_prefix_tests.js +115 -0
  207. package/build/esm/tests/vibrato_tests.js +92 -0
  208. package/build/esm/tests/vibratobracket_tests.js +45 -0
  209. package/build/esm/tests/voice_tests.js +69 -0
  210. package/build/types/entry/vexflow-bravura.d.ts +3 -0
  211. package/build/types/entry/vexflow-core.d.ts +3 -0
  212. package/build/types/entry/vexflow-debug.d.ts +3 -0
  213. package/build/types/entry/vexflow-font-bravura.d.ts +3771 -0
  214. package/build/types/entry/vexflow-font-custom.d.ts +86 -0
  215. package/build/types/entry/vexflow-font-gonville.d.ts +1267 -0
  216. package/build/types/entry/vexflow-font-petaluma.d.ts +1896 -0
  217. package/build/types/entry/vexflow-gonville.d.ts +3 -0
  218. package/build/types/entry/vexflow-petaluma.d.ts +3 -0
  219. package/build/types/entry/vexflow.d.ts +3 -0
  220. package/build/types/src/accidental.d.ts +66 -0
  221. package/build/types/src/annotation.d.ts +60 -0
  222. package/build/types/src/articulation.d.ts +62 -0
  223. package/build/types/src/barnote.d.ts +29 -0
  224. package/build/types/src/beam.d.ts +124 -0
  225. package/build/types/src/bend.d.ts +73 -0
  226. package/build/types/src/boundingbox.d.ts +42 -0
  227. package/build/types/src/boundingboxcomputation.d.ts +33 -0
  228. package/build/types/src/canvascontext.d.ts +89 -0
  229. package/build/types/src/chordsymbol.d.ts +149 -0
  230. package/build/types/src/clef.d.ts +48 -0
  231. package/build/types/src/clefnote.d.ts +25 -0
  232. package/build/types/src/crescendo.d.ts +27 -0
  233. package/build/types/src/curve.d.ts +41 -0
  234. package/build/types/src/dot.d.ts +20 -0
  235. package/build/types/src/easyscore.d.ts +148 -0
  236. package/build/types/src/element.d.ts +202 -0
  237. package/build/types/src/factory.d.ts +271 -0
  238. package/build/types/src/flow.d.ts +245 -0
  239. package/build/types/src/font.d.ts +181 -0
  240. package/build/types/src/fonts/bravura_glyphs.d.ts +3239 -0
  241. package/build/types/src/fonts/bravura_metrics.d.ts +533 -0
  242. package/build/types/src/fonts/custom_glyphs.d.ts +78 -0
  243. package/build/types/src/fonts/custom_metrics.d.ts +5 -0
  244. package/build/types/src/fonts/gonville_glyphs.d.ts +828 -0
  245. package/build/types/src/fonts/gonville_metrics.d.ts +440 -0
  246. package/build/types/src/fonts/load_all.d.ts +1 -0
  247. package/build/types/src/fonts/load_bravura.d.ts +1 -0
  248. package/build/types/src/fonts/load_custom.d.ts +1 -0
  249. package/build/types/src/fonts/load_gonville.d.ts +1 -0
  250. package/build/types/src/fonts/load_petaluma.d.ts +1 -0
  251. package/build/types/src/fonts/petaluma_glyphs.d.ts +1335 -0
  252. package/build/types/src/fonts/petaluma_metrics.d.ts +562 -0
  253. package/build/types/src/fonts/petalumascript_glyphs.d.ts +863 -0
  254. package/build/types/src/fonts/robotoslab_glyphs.d.ts +863 -0
  255. package/build/types/src/fonts/textfonts.d.ts +1 -0
  256. package/build/types/src/formatter.d.ts +203 -0
  257. package/build/types/src/fraction.d.ts +62 -0
  258. package/build/types/src/frethandfinger.d.ts +22 -0
  259. package/build/types/src/ghostnote.d.ts +16 -0
  260. package/build/types/src/glyph.d.ts +139 -0
  261. package/build/types/src/glyphnote.d.ts +17 -0
  262. package/build/types/src/gracenote.d.ts +19 -0
  263. package/build/types/src/gracenotegroup.d.ts +33 -0
  264. package/build/types/src/gracetabnote.d.ts +5 -0
  265. package/build/types/src/index.d.ts +91 -0
  266. package/build/types/src/keymanager.d.ts +25 -0
  267. package/build/types/src/keysignature.d.ts +50 -0
  268. package/build/types/src/keysignote.d.ts +11 -0
  269. package/build/types/src/modifier.d.ts +97 -0
  270. package/build/types/src/modifiercontext.d.ts +45 -0
  271. package/build/types/src/multimeasurerest.d.ts +61 -0
  272. package/build/types/src/music.d.ts +91 -0
  273. package/build/types/src/note.d.ts +231 -0
  274. package/build/types/src/notehead.d.ts +70 -0
  275. package/build/types/src/notesubgroup.d.ts +18 -0
  276. package/build/types/src/ornament.d.ts +76 -0
  277. package/build/types/src/parenthesis.d.ts +22 -0
  278. package/build/types/src/parser.d.ts +45 -0
  279. package/build/types/src/pedalmarking.d.ts +69 -0
  280. package/build/types/src/registry.d.ts +40 -0
  281. package/build/types/src/rendercontext.d.ts +64 -0
  282. package/build/types/src/renderer.d.ts +35 -0
  283. package/build/types/src/repeatnote.d.ts +6 -0
  284. package/build/types/src/stave.d.ts +186 -0
  285. package/build/types/src/stavebarline.d.ts +28 -0
  286. package/build/types/src/staveconnector.d.ts +67 -0
  287. package/build/types/src/stavehairpin.d.ts +56 -0
  288. package/build/types/src/staveline.d.ts +57 -0
  289. package/build/types/src/stavemodifier.d.ts +44 -0
  290. package/build/types/src/stavenote.d.ts +154 -0
  291. package/build/types/src/staverepetition.d.ts +32 -0
  292. package/build/types/src/stavesection.d.ts +15 -0
  293. package/build/types/src/stavetempo.d.ts +25 -0
  294. package/build/types/src/stavetext.d.ts +25 -0
  295. package/build/types/src/stavetie.d.ts +59 -0
  296. package/build/types/src/stavevolta.d.ts +21 -0
  297. package/build/types/src/stem.d.ts +58 -0
  298. package/build/types/src/stemmablenote.d.ts +39 -0
  299. package/build/types/src/stringnumber.d.ts +27 -0
  300. package/build/types/src/strokes.d.ts +33 -0
  301. package/build/types/src/svgcontext.d.ts +131 -0
  302. package/build/types/src/system.d.ts +92 -0
  303. package/build/types/src/tables.d.ts +96 -0
  304. package/build/types/src/tabnote.d.ts +44 -0
  305. package/build/types/src/tabslide.d.ts +34 -0
  306. package/build/types/src/tabstave.d.ts +7 -0
  307. package/build/types/src/tabtie.d.ts +18 -0
  308. package/build/types/src/textbracket.d.ts +55 -0
  309. package/build/types/src/textdynamics.d.ts +39 -0
  310. package/build/types/src/textformatter.d.ts +109 -0
  311. package/build/types/src/textnote.d.ts +49 -0
  312. package/build/types/src/tickable.d.ts +140 -0
  313. package/build/types/src/tickcontext.d.ts +82 -0
  314. package/build/types/src/timesigglyph.d.ts +14 -0
  315. package/build/types/src/timesignature.d.ts +26 -0
  316. package/build/types/src/timesignote.d.ts +11 -0
  317. package/build/types/src/tremolo.d.ts +17 -0
  318. package/build/types/src/tuning.d.ts +23 -0
  319. package/build/types/src/tuplet.d.ts +105 -0
  320. package/build/types/src/typeguard.d.ts +99 -0
  321. package/build/types/src/util.d.ts +27 -0
  322. package/build/types/src/version.d.ts +3 -0
  323. package/build/types/src/vex.d.ts +18 -0
  324. package/build/types/src/vibrato.d.ts +29 -0
  325. package/build/types/src/vibratobracket.d.ts +33 -0
  326. package/build/types/src/voice.d.ts +108 -0
  327. package/build/types/src/web.d.ts +2 -0
  328. package/package.json +1 -1
  329. package/src/annotation.ts +27 -6
  330. package/src/articulation.ts +8 -2
  331. package/src/fonts/gonville_glyphs.ts +4 -4
@@ -0,0 +1,161 @@
1
+ import { VexFlowTests } from './vexflow_test_helpers.js';
2
+ import { KeyManager } from '../src/keymanager.js';
3
+ import { Music } from '../src/music.js';
4
+ const MusicTests = {
5
+ Start() {
6
+ QUnit.module('MusicTests');
7
+ test('Valid Notes', validNotes);
8
+ test('Valid Keys', validKeys);
9
+ test('Note Values', noteValue);
10
+ test('Interval Values', intervalValue);
11
+ test('Relative Notes', relativeNotes);
12
+ test('Relative Note Names', relativeNoteNames);
13
+ test('Canonical Notes', canonicalNotes);
14
+ test('Canonical Intervals', canonicalIntervals);
15
+ test('Scale Tones', scaleTones);
16
+ test('Scale Intervals', scaleIntervals);
17
+ },
18
+ };
19
+ function validNotes() {
20
+ expect(10);
21
+ const music = new Music();
22
+ let parts = music.getNoteParts('c');
23
+ equal(parts.root, 'c');
24
+ equal(parts.accidental, null);
25
+ parts = music.getNoteParts('C');
26
+ equal(parts.root, 'c');
27
+ equal(parts.accidental, null);
28
+ parts = music.getNoteParts('c#');
29
+ equal(parts.root, 'c');
30
+ equal(parts.accidental, '#');
31
+ parts = music.getNoteParts('c##');
32
+ equal(parts.root, 'c');
33
+ equal(parts.accidental, '##');
34
+ throws(() => music.getNoteParts('r'), /BadArguments/, 'Invalid note: r');
35
+ throws(() => music.getNoteParts(''), /BadArguments/, "Invalid note: ''");
36
+ }
37
+ function validKeys() {
38
+ expect(18);
39
+ const music = new Music();
40
+ let parts = music.getKeyParts('c');
41
+ equal(parts.root, 'c');
42
+ equal(parts.accidental, null);
43
+ equal(parts.type, 'M');
44
+ parts = music.getKeyParts('d#');
45
+ equal(parts.root, 'd');
46
+ equal(parts.accidental, '#');
47
+ equal(parts.type, 'M');
48
+ parts = music.getKeyParts('fbm');
49
+ equal(parts.root, 'f');
50
+ equal(parts.accidental, 'b');
51
+ equal(parts.type, 'm');
52
+ parts = music.getKeyParts('c#mel');
53
+ equal(parts.root, 'c');
54
+ equal(parts.accidental, '#');
55
+ equal(parts.type, 'mel');
56
+ parts = music.getKeyParts('g#harm');
57
+ equal(parts.root, 'g');
58
+ equal(parts.accidental, '#');
59
+ equal(parts.type, 'harm');
60
+ throws(() => music.getKeyParts('r'), /BadArguments/, 'Invalid key: r');
61
+ throws(() => music.getKeyParts(''), /BadArguments/, `Invalid key: ''`);
62
+ throws(() => music.getKeyParts('#m'), /BadArguments/, 'Invalid key: #m');
63
+ }
64
+ function noteValue() {
65
+ expect(3);
66
+ const music = new Music();
67
+ let note = music.getNoteValue('c');
68
+ equal(note, 0);
69
+ throws(() => music.getNoteValue('r'), /BadArguments/, 'Invalid note name');
70
+ note = music.getNoteValue('f#');
71
+ equal(note, 6);
72
+ }
73
+ function intervalValue() {
74
+ expect(2);
75
+ const music = new Music();
76
+ const value = music.getIntervalValue('b2');
77
+ equal(value, 1);
78
+ throws(() => music.getIntervalValue('7'), /BadArguments/, 'Invalid interval name');
79
+ }
80
+ function relativeNotes() {
81
+ expect(8);
82
+ const music = new Music();
83
+ let value = music.getRelativeNoteValue(music.getNoteValue('c'), music.getIntervalValue('b5'));
84
+ equal(value, 6);
85
+ throws(() => music.getRelativeNoteValue(music.getNoteValue('bc'), music.getIntervalValue('b2')), /BadArguments/, 'Invalid note');
86
+ throws(() => music.getRelativeNoteValue(music.getNoteValue('b'), music.getIntervalValue('p3')), /BadArguments/, 'Invalid interval');
87
+ value = music.getRelativeNoteValue(music.getNoteValue('d'), music.getIntervalValue('2'), -1);
88
+ equal(value, 0);
89
+ throws(() => music.getRelativeNoteValue(music.getNoteValue('b'), music.getIntervalValue('p4'), 0), /BadArguments/, 'Invalid direction: 0');
90
+ value = music.getRelativeNoteValue(music.getNoteValue('b'), music.getIntervalValue('b5'));
91
+ equal(value, 5);
92
+ value = music.getRelativeNoteValue(music.getNoteValue('c'), music.getIntervalValue('b2'), -1);
93
+ equal(value, 11);
94
+ value = music.getRelativeNoteValue(music.getNoteValue('g'), music.getIntervalValue('p5'));
95
+ equal(value, 2);
96
+ }
97
+ function relativeNoteNames() {
98
+ expect(9);
99
+ const music = new Music();
100
+ equal(music.getRelativeNoteName('b', music.getNoteValue('c#')), 'b##');
101
+ equal(music.getRelativeNoteName('c', music.getNoteValue('c')), 'c');
102
+ equal(music.getRelativeNoteName('c', music.getNoteValue('db')), 'c#');
103
+ equal(music.getRelativeNoteName('c', music.getNoteValue('b')), 'cb');
104
+ equal(music.getRelativeNoteName('c#', music.getNoteValue('db')), 'c#');
105
+ equal(music.getRelativeNoteName('e', music.getNoteValue('f#')), 'e##');
106
+ equal(music.getRelativeNoteName('e', music.getNoteValue('d#')), 'eb');
107
+ equal(music.getRelativeNoteName('e', music.getNoteValue('fb')), 'e');
108
+ throws(() => music.getRelativeNoteName('e', music.getNoteValue('g#')), /BadArguments/, 'Too far away. Notes not related.');
109
+ }
110
+ function canonicalNotes() {
111
+ expect(3);
112
+ const music = new Music();
113
+ equal(music.getCanonicalNoteName(0), 'c');
114
+ equal(music.getCanonicalNoteName(2), 'd');
115
+ throws(() => music.getCanonicalNoteName(-1), /BadArguments/, 'Invalid note value');
116
+ }
117
+ function canonicalIntervals() {
118
+ expect(3);
119
+ const music = new Music();
120
+ equal(music.getCanonicalIntervalName(0), 'unison');
121
+ equal(music.getCanonicalIntervalName(2), 'M2');
122
+ throws(() => music.getCanonicalIntervalName(-1), /BadArguments/, 'Invalid interval value');
123
+ }
124
+ function scaleTones() {
125
+ expect(24);
126
+ const music = new Music();
127
+ const manager = new KeyManager('CM');
128
+ const c_major = music.getScaleTones(music.getNoteValue('c'), Music.scales.major);
129
+ let values = ['c', 'd', 'e', 'f', 'g', 'a', 'b'];
130
+ equal(c_major.length, 7);
131
+ for (let i = 0; i < c_major.length; ++i) {
132
+ equal(music.getCanonicalNoteName(c_major[i]), values[i]);
133
+ }
134
+ const c_dorian = music.getScaleTones(music.getNoteValue('c'), Music.scales.dorian);
135
+ values = ['c', 'd', 'eb', 'f', 'g', 'a', 'bb'];
136
+ let note = null;
137
+ equal(c_dorian.length, 7);
138
+ for (let i = 0; i < c_dorian.length; ++i) {
139
+ note = music.getCanonicalNoteName(c_dorian[i]);
140
+ equal(manager.selectNote(note).note, values[i]);
141
+ }
142
+ const c_mixolydian = music.getScaleTones(music.getNoteValue('c'), Music.scales.mixolydian);
143
+ values = ['c', 'd', 'e', 'f', 'g', 'a', 'bb'];
144
+ equal(c_mixolydian.length, 7);
145
+ for (let i = 0; i < c_mixolydian.length; ++i) {
146
+ note = music.getCanonicalNoteName(c_mixolydian[i]);
147
+ equal(manager.selectNote(note).note, values[i]);
148
+ }
149
+ }
150
+ function scaleIntervals() {
151
+ expect(6);
152
+ const m = new Music();
153
+ equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('c'), m.getNoteValue('d'))), 'M2');
154
+ equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('g'), m.getNoteValue('c'))), 'p4');
155
+ equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('c'), m.getNoteValue('c'))), 'unison');
156
+ equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('f'), m.getNoteValue('cb'))), 'dim5');
157
+ equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('d'), m.getNoteValue('c'), 1)), 'b7');
158
+ equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('d'), m.getNoteValue('c'), -1)), 'M2');
159
+ }
160
+ VexFlowTests.register(MusicTests);
161
+ export { MusicTests };
@@ -0,0 +1,137 @@
1
+ import { VexFlowTests } from './vexflow_test_helpers.js';
2
+ import { Flow } from '../src/flow.js';
3
+ import { Formatter } from '../src/formatter.js';
4
+ import { NoteHead } from '../src/notehead.js';
5
+ import { Stave } from '../src/stave.js';
6
+ import { StaveNote } from '../src/stavenote.js';
7
+ import { TickContext } from '../src/tickcontext.js';
8
+ import { Voice } from '../src/voice.js';
9
+ const NoteHeadTests = {
10
+ Start() {
11
+ QUnit.module('NoteHead');
12
+ const run = VexFlowTests.runTests;
13
+ run('Basic', basic);
14
+ run('Various Heads', variousHeads);
15
+ run('Drum Chord Heads', drumChordHeads);
16
+ run('Bounding Boxes', basicBoundingBoxes);
17
+ },
18
+ };
19
+ function setContextStyle(ctx) {
20
+ ctx.scale(1.8, 1.8);
21
+ ctx.fillStyle = '#221';
22
+ ctx.strokeStyle = '#221';
23
+ ctx.font = '10pt Arial';
24
+ }
25
+ function basic(options, contextBuilder) {
26
+ const ctx = contextBuilder(options.elementId, 450, 250);
27
+ setContextStyle(ctx);
28
+ const stave = new Stave(10, 0, 250).addClef('treble');
29
+ stave.setContext(ctx).draw();
30
+ const formatter = new Formatter();
31
+ const voice = new Voice(Flow.TIME4_4).setStrict(false);
32
+ const note_head1 = new NoteHead({ duration: '4', line: 3 });
33
+ const note_head2 = new NoteHead({ duration: '1', line: 2.5 });
34
+ const note_head3 = new NoteHead({ duration: '2', line: 0 });
35
+ voice.addTickables([note_head1, note_head2, note_head3]);
36
+ formatter.joinVoices([voice]).formatToStave([voice], stave);
37
+ voice.draw(ctx, stave);
38
+ ok('Basic NoteHead test');
39
+ }
40
+ function showNote(noteStruct, stave, ctx, x) {
41
+ const note = new StaveNote(noteStruct).setStave(stave);
42
+ new TickContext().addTickable(note).preFormat().setX(x);
43
+ note.setContext(ctx).draw();
44
+ return note;
45
+ }
46
+ function variousHeads(options, contextBuilder) {
47
+ const notes = [
48
+ { keys: ['g/5/d0'], duration: '4' },
49
+ { keys: ['g/5/d1'], duration: '4' },
50
+ { keys: ['g/5/d2'], duration: '4' },
51
+ { keys: ['g/5/d3'], duration: '4' },
52
+ { keys: ['x/'], duration: '1' },
53
+ { keys: ['g/5/t0'], duration: '1' },
54
+ { keys: ['g/5/t1'], duration: '4' },
55
+ { keys: ['g/5/t2'], duration: '4' },
56
+ { keys: ['g/5/t3'], duration: '4' },
57
+ { keys: ['x/'], duration: '1' },
58
+ { keys: ['g/5/x0'], duration: '1' },
59
+ { keys: ['g/5/x1'], duration: '4' },
60
+ { keys: ['g/5/x2'], duration: '4' },
61
+ { keys: ['g/5/x3'], duration: '4' },
62
+ { keys: ['x/'], duration: '1' },
63
+ { keys: ['g/5/s1'], duration: '4' },
64
+ { keys: ['g/5/s2'], duration: '4' },
65
+ { keys: ['x/'], duration: '1' },
66
+ { keys: ['g/5/r1'], duration: '4' },
67
+ { keys: ['g/5/r2'], duration: '4' },
68
+ ];
69
+ const ctx = contextBuilder(options.elementId, notes.length * 25 + 100, 240);
70
+ for (let staveNum = 0; staveNum < 2; ++staveNum) {
71
+ const stave = new Stave(10, 10 + staveNum * 120, notes.length * 25 + 75)
72
+ .addClef('percussion')
73
+ .setContext(ctx)
74
+ .draw();
75
+ for (let i = 0; i < notes.length; ++i) {
76
+ const note = notes[i];
77
+ note.stem_direction = staveNum === 0 ? -1 : 1;
78
+ const staveNote = showNote(note, stave, ctx, (i + 1) * 25);
79
+ ok(staveNote.getX() > 0, 'Note ' + i + ' has X value');
80
+ ok(staveNote.getYs().length > 0, 'Note ' + i + ' has Y values');
81
+ }
82
+ }
83
+ }
84
+ function drumChordHeads(options, contextBuilder) {
85
+ const notes = [
86
+ { keys: ['a/4/d0', 'g/5/x3'], duration: '4' },
87
+ { keys: ['a/4/x3', 'g/5/d0'], duration: '4' },
88
+ { keys: ['a/4/d1', 'g/5/x2'], duration: '4' },
89
+ { keys: ['a/4/x2', 'g/5/d1'], duration: '4' },
90
+ { keys: ['a/4/d2', 'g/5/x1'], duration: '4' },
91
+ { keys: ['a/4/x1', 'g/5/d2'], duration: '4' },
92
+ { keys: ['a/4/d3', 'g/5/x0'], duration: '4' },
93
+ { keys: ['a/4/x0', 'g/5/d3'], duration: '4' },
94
+ { keys: ['a/4', 'g/5/d0'], duration: '4' },
95
+ { keys: ['a/4/x3', 'g/5'], duration: '4' },
96
+ { keys: ['a/4/t0', 'g/5/s1'], duration: '4' },
97
+ { keys: ['a/4/s1', 'g/5/t0'], duration: '4' },
98
+ { keys: ['a/4/t1', 'g/5/s2'], duration: '4' },
99
+ { keys: ['a/4/s2', 'g/5/t1'], duration: '4' },
100
+ { keys: ['a/4/t2', 'g/5/r1'], duration: '4' },
101
+ { keys: ['a/4/r1', 'g/5/t2'], duration: '4' },
102
+ { keys: ['a/4/t3', 'g/5/r2'], duration: '4' },
103
+ { keys: ['a/4/r2', 'g/5/t3'], duration: '4' },
104
+ ];
105
+ const ctx = contextBuilder(options.elementId, notes.length * 25 + 100, 240);
106
+ for (let h = 0; h < 2; ++h) {
107
+ const stave = new Stave(10, 10 + h * 120, notes.length * 25 + 75).addClef('percussion').setContext(ctx).draw();
108
+ for (let i = 0; i < notes.length; ++i) {
109
+ const note = notes[i];
110
+ note.stem_direction = h === 0 ? -1 : 1;
111
+ const staveNote = showNote(note, stave, ctx, (i + 1) * 25);
112
+ ok(staveNote.getX() > 0, 'Note ' + i + ' has X value');
113
+ ok(staveNote.getYs().length > 0, 'Note ' + i + ' has Y values');
114
+ }
115
+ }
116
+ }
117
+ function basicBoundingBoxes(options, contextBuilder) {
118
+ const ctx = contextBuilder(options.elementId, 450, 250);
119
+ setContextStyle(ctx);
120
+ const stave = new Stave(10, 0, 250).addClef('treble');
121
+ stave.setContext(ctx).draw();
122
+ const formatter = new Formatter();
123
+ const voice = new Voice(Flow.TIME4_4).setStrict(false);
124
+ const nh1 = new NoteHead({ duration: '4', line: 3 });
125
+ const nh2 = new NoteHead({ duration: '2', line: 2.5 });
126
+ const nh3 = new NoteHead({ duration: '1', line: 0 });
127
+ voice.addTickables([nh1, nh2, nh3]);
128
+ formatter.joinVoices([voice]).formatToStave([voice], stave);
129
+ voice.draw(ctx, stave);
130
+ for (const bb of [nh1.getBoundingBox(), nh2.getBoundingBox(), nh3.getBoundingBox()]) {
131
+ ctx.rect(bb.getX(), bb.getY(), bb.getW(), bb.getH());
132
+ }
133
+ ctx.stroke();
134
+ ok('NoteHead Bounding Boxes');
135
+ }
136
+ VexFlowTests.register(NoteHeadTests);
137
+ export { NoteHeadTests };
@@ -0,0 +1,149 @@
1
+ import { VexFlowTests } from './vexflow_test_helpers.js';
2
+ import { BarNote } from '../src/barnote.js';
3
+ import { Note } from '../src/note.js';
4
+ import { BarlineType } from '../src/stavebarline.js';
5
+ const NoteSubGroupTests = {
6
+ Start() {
7
+ QUnit.module('NoteSubGroup');
8
+ const run = VexFlowTests.runTests;
9
+ run('Basic - ClefNote, TimeSigNote and BarNote', basic);
10
+ run('Multi Voice', multiVoiceSingleDraw);
11
+ run('Multi Voice Multiple Draws', multiVoiceDoubleDraw);
12
+ run('Multi Staff', multiStaff);
13
+ },
14
+ };
15
+ function createShortcuts(f) {
16
+ return {
17
+ createStaveNote: (noteStruct) => f.StaveNote(noteStruct),
18
+ addAccidental: (note, accid) => note.addModifier(f.Accidental({ type: accid }), 0),
19
+ addSubGroup: (note, subNotes) => note.addModifier(f.NoteSubGroup({ notes: subNotes }), 0),
20
+ };
21
+ }
22
+ function basic(options) {
23
+ const f = VexFlowTests.makeFactory(options, 750, 200);
24
+ const ctx = f.getContext();
25
+ const stave = f.Stave({ width: 600 }).addClef('treble');
26
+ const { createStaveNote, addAccidental, addSubGroup } = createShortcuts(f);
27
+ const notes = [
28
+ { keys: ['f/5'], stem_direction: -1, duration: '4' },
29
+ { keys: ['d/4'], stem_direction: -1, duration: '4', clef: 'bass' },
30
+ { keys: ['g/4'], stem_direction: -1, duration: '4', clef: 'alto' },
31
+ { keys: ['a/4'], stem_direction: -1, duration: '4', clef: 'alto' },
32
+ { keys: ['c/4'], stem_direction: -1, duration: '4', clef: 'tenor' },
33
+ { keys: ['c/3'], stem_direction: +1, duration: '4', clef: 'tenor' },
34
+ { keys: ['d/4'], stem_direction: -1, duration: '4', clef: 'tenor' },
35
+ { keys: ['f/4'], stem_direction: -1, duration: '4', clef: 'tenor' },
36
+ ].map(createStaveNote);
37
+ addAccidental(notes[1], '#');
38
+ addAccidental(notes[2], 'n');
39
+ addSubGroup(notes[1], [f.ClefNote({ type: 'bass', options: { size: 'small' } })]);
40
+ addSubGroup(notes[2], [f.ClefNote({ type: 'alto', options: { size: 'small' } })]);
41
+ addSubGroup(notes[4], [f.ClefNote({ type: 'tenor', options: { size: 'small' } }), new BarNote()]);
42
+ addSubGroup(notes[5], [f.TimeSigNote({ time: '6/8' })]);
43
+ addSubGroup(notes[6], [new BarNote(BarlineType.REPEAT_BEGIN)]);
44
+ addAccidental(notes[4], 'b');
45
+ addAccidental(notes[6], 'bb');
46
+ const voice = f.Voice().setStrict(false).addTickables(notes);
47
+ f.Formatter().joinVoices([voice]).formatToStave([voice], stave);
48
+ f.draw();
49
+ notes.forEach((note) => Note.plotMetrics(ctx, note, 150));
50
+ VexFlowTests.plotLegendForNoteWidth(ctx, 620, 120);
51
+ ok(true, 'all pass');
52
+ }
53
+ function multiVoiceSingleDraw(options) {
54
+ multiVoiceHelper(options, 1);
55
+ }
56
+ function multiVoiceDoubleDraw(options) {
57
+ multiVoiceHelper(options, 2);
58
+ }
59
+ function multiVoiceHelper(options, numDraws) {
60
+ const f = VexFlowTests.makeFactory(options, 550, 200);
61
+ const ctx = f.getContext();
62
+ const stave = f.Stave().addClef('treble');
63
+ const { createStaveNote, addAccidental, addSubGroup } = createShortcuts(f);
64
+ const notes1 = [
65
+ { keys: ['f/5'], stem_direction: 1, duration: '4' },
66
+ { keys: ['d/4'], stem_direction: 1, duration: '4', clef: 'bass' },
67
+ { keys: ['c/5'], stem_direction: 1, duration: '4', clef: 'alto' },
68
+ { keys: ['c/5'], stem_direction: 1, duration: '4', clef: 'soprano' },
69
+ ].map(createStaveNote);
70
+ const notes2 = [
71
+ { keys: ['c/4'], stem_direction: -1, duration: '4' },
72
+ { keys: ['c/3'], stem_direction: -1, duration: '4', clef: 'bass' },
73
+ { keys: ['d/4'], stem_direction: -1, duration: '4', clef: 'alto' },
74
+ { keys: ['f/4'], stem_direction: -1, duration: '4', clef: 'soprano' },
75
+ ].map(createStaveNote);
76
+ addAccidental(notes1[1], '#');
77
+ addSubGroup(notes1[1], [
78
+ f.ClefNote({ type: 'bass', options: { size: 'small' } }),
79
+ new BarNote(BarlineType.REPEAT_BEGIN),
80
+ f.TimeSigNote({ time: '3/4' }),
81
+ ]);
82
+ addSubGroup(notes2[2], [
83
+ f.ClefNote({ type: 'alto', options: { size: 'small' } }),
84
+ f.TimeSigNote({ time: '9/8' }),
85
+ new BarNote(BarlineType.DOUBLE),
86
+ ]);
87
+ addSubGroup(notes1[3], [f.ClefNote({ type: 'soprano', options: { size: 'small' } })]);
88
+ addAccidental(notes1[2], 'b');
89
+ addAccidental(notes2[3], '#');
90
+ const voices = [f.Voice().addTickables(notes1), f.Voice().addTickables(notes2)];
91
+ f.Formatter().joinVoices(voices).formatToStave(voices, stave);
92
+ for (let i = 0; i < numDraws; i++) {
93
+ f.draw();
94
+ }
95
+ notes1.forEach((note) => Note.plotMetrics(ctx, note, 150));
96
+ ok(true, 'all pass');
97
+ }
98
+ function multiStaff(options) {
99
+ const f = VexFlowTests.makeFactory(options, 550, 400);
100
+ const { createStaveNote, addAccidental, addSubGroup } = createShortcuts(f);
101
+ const stave1 = f.Stave({ x: 15, y: 30, width: 500 }).setClef('treble');
102
+ const notes1 = [
103
+ { keys: ['f/5'], stem_direction: 1, duration: '4' },
104
+ { keys: ['d/4'], stem_direction: 1, duration: '4', clef: 'bass' },
105
+ { keys: ['c/5'], stem_direction: 1, duration: '4', clef: 'alto' },
106
+ { keys: ['c/5'], stem_direction: 1, duration: '4', clef: 'soprano' },
107
+ ].map(createStaveNote);
108
+ const notes2 = [
109
+ { keys: ['c/4'], stem_direction: -1, duration: '4' },
110
+ { keys: ['c/3'], stem_direction: -1, duration: '4', clef: 'bass' },
111
+ { keys: ['d/4'], stem_direction: -1, duration: '4', clef: 'alto' },
112
+ { keys: ['f/4'], stem_direction: -1, duration: '4', clef: 'soprano' },
113
+ ].map(createStaveNote);
114
+ const stave2 = f.Stave({ x: 15, y: 150, width: 500 }).setClef('bass');
115
+ const notes3 = [
116
+ { keys: ['e/3'], duration: '8', stem_direction: -1, clef: 'bass' },
117
+ { keys: ['g/4'], duration: '8', stem_direction: 1, clef: 'treble' },
118
+ { keys: ['d/4'], duration: '8', stem_direction: 1, clef: 'treble' },
119
+ { keys: ['f/4'], duration: '8', stem_direction: 1, clef: 'treble' },
120
+ { keys: ['c/4'], duration: '8', stem_direction: 1, clef: 'treble' },
121
+ { keys: ['g/3'], duration: '8', stem_direction: -1, clef: 'bass' },
122
+ { keys: ['d/3'], duration: '8', stem_direction: -1, clef: 'bass' },
123
+ { keys: ['f/3'], duration: '8', stem_direction: -1, clef: 'bass' },
124
+ ].map(createStaveNote);
125
+ f.StaveConnector({ top_stave: stave1, bottom_stave: stave2, type: 'brace' });
126
+ f.StaveConnector({ top_stave: stave1, bottom_stave: stave2, type: 'singleLeft' });
127
+ f.StaveConnector({ top_stave: stave1, bottom_stave: stave2, type: 'singleRight' });
128
+ f.Beam({ notes: notes3.slice(1, 4) });
129
+ f.Beam({ notes: notes3.slice(5) });
130
+ addAccidental(notes1[1], '#');
131
+ addSubGroup(notes1[1], [f.ClefNote({ type: 'bass', options: { size: 'small' } }), f.TimeSigNote({ time: '3/4' })]);
132
+ addSubGroup(notes2[2], [f.ClefNote({ type: 'alto', options: { size: 'small' } }), f.TimeSigNote({ time: '9/8' })]);
133
+ addSubGroup(notes1[3], [f.ClefNote({ type: 'soprano', options: { size: 'small' } })]);
134
+ addSubGroup(notes3[1], [f.ClefNote({ type: 'treble', options: { size: 'small' } })]);
135
+ addSubGroup(notes3[5], [f.ClefNote({ type: 'bass', options: { size: 'small' } })]);
136
+ addAccidental(notes3[0], '#');
137
+ addAccidental(notes3[3], 'b');
138
+ addAccidental(notes3[5], '#');
139
+ addAccidental(notes1[2], 'b');
140
+ addAccidental(notes2[3], '#');
141
+ const voice1 = f.Voice().addTickables(notes1);
142
+ const voice2 = f.Voice().addTickables(notes2);
143
+ const voice3 = f.Voice().addTickables(notes3);
144
+ f.Formatter().joinVoices([voice1, voice2]).joinVoices([voice3]).formatToStave([voice1, voice2, voice3], stave1);
145
+ f.draw();
146
+ ok(true, 'all pass');
147
+ }
148
+ VexFlowTests.register(NoteSubGroupTests);
149
+ export { NoteSubGroupTests };
@@ -0,0 +1,47 @@
1
+ import { VexFlowTests } from './vexflow_test_helpers.js';
2
+ import { CanvasContext } from '../src/canvascontext.js';
3
+ import { Formatter } from '../src/formatter.js';
4
+ import { Stave } from '../src/stave.js';
5
+ import { BarlineType } from '../src/stavebarline.js';
6
+ import { StaveNote } from '../src/stavenote.js';
7
+ import { globalObject } from '../src/util.js';
8
+ const OffscreenCanvasTests = {
9
+ Start() {
10
+ if (globalObject().OffscreenCanvas === undefined) {
11
+ return;
12
+ }
13
+ QUnit.module('OffscreenCanvas');
14
+ test('Simple Test', simpleTest);
15
+ },
16
+ };
17
+ function simpleTest() {
18
+ const offscreenCanvas = new OffscreenCanvas(550, 200);
19
+ const offscreenCtx = offscreenCanvas.getContext('2d');
20
+ if (offscreenCtx == null) {
21
+ throw new Error("Couldn't create offscreen context");
22
+ }
23
+ const ctx = new CanvasContext(offscreenCtx);
24
+ const stave = new Stave(10, 50, 200);
25
+ stave.setEndBarType(BarlineType.END);
26
+ stave.addClef('treble').setContext(ctx).draw();
27
+ const notes = [
28
+ new StaveNote({ keys: ['c/4'], duration: 'q' }),
29
+ new StaveNote({ keys: ['d/4'], duration: 'q' }),
30
+ new StaveNote({ keys: ['b/4'], duration: 'qr' }),
31
+ new StaveNote({ keys: ['c/4', 'e/4', 'g/4'], duration: 'q' }),
32
+ ];
33
+ Formatter.FormatAndDraw(ctx, stave, notes);
34
+ const imgBmp = offscreenCanvas.transferToImageBitmap();
35
+ const canvas = document.createElement('canvas');
36
+ canvas.width = offscreenCanvas.width;
37
+ canvas.height = offscreenCanvas.height;
38
+ const canvasCtx = canvas.getContext('2d');
39
+ if (canvasCtx == null) {
40
+ throw new Error("Couldn't create canvas context");
41
+ }
42
+ canvasCtx.drawImage(imgBmp, 0, 0);
43
+ document.body.appendChild(canvas);
44
+ ok(true, 'all pass');
45
+ }
46
+ VexFlowTests.register(OffscreenCanvasTests);
47
+ export { OffscreenCanvasTests };