@mcqj/vexflow 0.0.1-alpha.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 (300) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +208 -0
  3. package/build/cjs/vexflow-bravura.js +2 -0
  4. package/build/cjs/vexflow-bravura.js.map +1 -0
  5. package/build/cjs/vexflow-core.js +2 -0
  6. package/build/cjs/vexflow-core.js.map +1 -0
  7. package/build/cjs/vexflow-debug-with-tests.js +43475 -0
  8. package/build/cjs/vexflow-debug-with-tests.js.map +1 -0
  9. package/build/cjs/vexflow-debug.js +19194 -0
  10. package/build/cjs/vexflow-debug.js.map +1 -0
  11. package/build/cjs/vexflow.js +2 -0
  12. package/build/cjs/vexflow.js.map +1 -0
  13. package/build/esm/entry/vexflow-bravura.js +17 -0
  14. package/build/esm/entry/vexflow-core.js +4 -0
  15. package/build/esm/entry/vexflow-debug-with-tests.js +38 -0
  16. package/build/esm/entry/vexflow-debug.js +31 -0
  17. package/build/esm/entry/vexflow.js +31 -0
  18. package/build/esm/package.json +3 -0
  19. package/build/esm/src/accidental.js +330 -0
  20. package/build/esm/src/annotation.js +231 -0
  21. package/build/esm/src/articulation.js +281 -0
  22. package/build/esm/src/barnote.js +56 -0
  23. package/build/esm/src/beam.js +644 -0
  24. package/build/esm/src/bend.js +186 -0
  25. package/build/esm/src/boundingbox.js +59 -0
  26. package/build/esm/src/canvascontext.js +216 -0
  27. package/build/esm/src/chordsymbol.js +325 -0
  28. package/build/esm/src/clef.js +120 -0
  29. package/build/esm/src/clefnote.js +35 -0
  30. package/build/esm/src/crescendo.js +78 -0
  31. package/build/esm/src/curve.js +126 -0
  32. package/build/esm/src/dot.js +129 -0
  33. package/build/esm/src/easyscore.js +374 -0
  34. package/build/esm/src/element.js +409 -0
  35. package/build/esm/src/factory.js +463 -0
  36. package/build/esm/src/flag.js +22 -0
  37. package/build/esm/src/font.js +237 -0
  38. package/build/esm/src/fonts/academico.js +1 -0
  39. package/build/esm/src/fonts/academicobold.js +1 -0
  40. package/build/esm/src/fonts/bravura.js +1 -0
  41. package/build/esm/src/fonts/gonville.js +1 -0
  42. package/build/esm/src/fonts/petaluma.js +1 -0
  43. package/build/esm/src/fonts/petalumascript.js +1 -0
  44. package/build/esm/src/formatter.js +610 -0
  45. package/build/esm/src/fraction.js +170 -0
  46. package/build/esm/src/frethandfinger.js +141 -0
  47. package/build/esm/src/ghostnote.js +50 -0
  48. package/build/esm/src/glyphnote.js +44 -0
  49. package/build/esm/src/glyphs.js +2936 -0
  50. package/build/esm/src/gracenote.js +106 -0
  51. package/build/esm/src/gracenotegroup.js +138 -0
  52. package/build/esm/src/gracetabnote.js +11 -0
  53. package/build/esm/src/index.js +86 -0
  54. package/build/esm/src/keymanager.js +99 -0
  55. package/build/esm/src/keysignature.js +220 -0
  56. package/build/esm/src/keysignote.js +28 -0
  57. package/build/esm/src/metrics.js +237 -0
  58. package/build/esm/src/modifier.js +121 -0
  59. package/build/esm/src/modifiercontext.js +110 -0
  60. package/build/esm/src/multimeasurerest.js +127 -0
  61. package/build/esm/src/music.js +322 -0
  62. package/build/esm/src/note.js +383 -0
  63. package/build/esm/src/notehead.js +89 -0
  64. package/build/esm/src/notesubgroup.js +59 -0
  65. package/build/esm/src/ornament.js +192 -0
  66. package/build/esm/src/parenthesis.js +61 -0
  67. package/build/esm/src/parser.js +164 -0
  68. package/build/esm/src/pedalmarking.js +168 -0
  69. package/build/esm/src/registry.js +81 -0
  70. package/build/esm/src/rendercontext.js +20 -0
  71. package/build/esm/src/renderer.js +112 -0
  72. package/build/esm/src/repeatnote.js +17 -0
  73. package/build/esm/src/stave.js +579 -0
  74. package/build/esm/src/stavebarline.js +237 -0
  75. package/build/esm/src/staveconnector.js +180 -0
  76. package/build/esm/src/stavehairpin.js +115 -0
  77. package/build/esm/src/staveline.js +199 -0
  78. package/build/esm/src/stavemodifier.js +56 -0
  79. package/build/esm/src/stavenote.js +861 -0
  80. package/build/esm/src/staverepetition.js +120 -0
  81. package/build/esm/src/stavesection.js +36 -0
  82. package/build/esm/src/stavetempo.js +110 -0
  83. package/build/esm/src/stavetext.js +55 -0
  84. package/build/esm/src/stavetie.js +186 -0
  85. package/build/esm/src/stavevolta.js +53 -0
  86. package/build/esm/src/stem.js +133 -0
  87. package/build/esm/src/stemmablenote.js +193 -0
  88. package/build/esm/src/stringnumber.js +228 -0
  89. package/build/esm/src/strokes.js +164 -0
  90. package/build/esm/src/svgcontext.js +402 -0
  91. package/build/esm/src/system.js +166 -0
  92. package/build/esm/src/tables.js +696 -0
  93. package/build/esm/src/tabnote.js +278 -0
  94. package/build/esm/src/tabslide.js +68 -0
  95. package/build/esm/src/tabstave.js +17 -0
  96. package/build/esm/src/tabtie.js +19 -0
  97. package/build/esm/src/textbracket.js +128 -0
  98. package/build/esm/src/textdynamics.js +53 -0
  99. package/build/esm/src/textnote.js +116 -0
  100. package/build/esm/src/tickable.js +224 -0
  101. package/build/esm/src/tickcontext.js +189 -0
  102. package/build/esm/src/timesignature.js +169 -0
  103. package/build/esm/src/timesignote.js +30 -0
  104. package/build/esm/src/tremolo.js +30 -0
  105. package/build/esm/src/tuning.js +55 -0
  106. package/build/esm/src/tuplet.js +258 -0
  107. package/build/esm/src/typeguard.js +30 -0
  108. package/build/esm/src/util.js +67 -0
  109. package/build/esm/src/version.js +3 -0
  110. package/build/esm/src/vexflow.js +309 -0
  111. package/build/esm/src/vibrato.js +68 -0
  112. package/build/esm/src/vibratobracket.js +44 -0
  113. package/build/esm/src/voice.js +178 -0
  114. package/build/esm/src/web.js +15 -0
  115. package/build/esm/tests/accidental_tests.js +1055 -0
  116. package/build/esm/tests/annotation_tests.js +381 -0
  117. package/build/esm/tests/articulation_tests.js +432 -0
  118. package/build/esm/tests/auto_beam_formatting_tests.js +551 -0
  119. package/build/esm/tests/barline_tests.js +52 -0
  120. package/build/esm/tests/beam_tests.js +669 -0
  121. package/build/esm/tests/bend_tests.js +223 -0
  122. package/build/esm/tests/boundingbox_tests.js +53 -0
  123. package/build/esm/tests/browser_test_runner.js +128 -0
  124. package/build/esm/tests/chordsymbol_tests.js +405 -0
  125. package/build/esm/tests/clef_tests.js +141 -0
  126. package/build/esm/tests/crossbeam_tests.js +306 -0
  127. package/build/esm/tests/curve_tests.js +152 -0
  128. package/build/esm/tests/demo_petzold_tests.js +335 -0
  129. package/build/esm/tests/dot_tests.js +119 -0
  130. package/build/esm/tests/easyscore_tests.js +488 -0
  131. package/build/esm/tests/factory_tests.js +44 -0
  132. package/build/esm/tests/font_tests.js +134 -0
  133. package/build/esm/tests/formatter/framestack.js +61 -0
  134. package/build/esm/tests/formatter/tests.js +251 -0
  135. package/build/esm/tests/formatter_tests.js +759 -0
  136. package/build/esm/tests/fraction_tests.js +72 -0
  137. package/build/esm/tests/ghostnote_tests.js +77 -0
  138. package/build/esm/tests/glyphnote_tests.js +119 -0
  139. package/build/esm/tests/gracenote_tests.js +414 -0
  140. package/build/esm/tests/gracetabnote_tests.js +79 -0
  141. package/build/esm/tests/index.js +68 -0
  142. package/build/esm/tests/key_clef_tests.js +106 -0
  143. package/build/esm/tests/keymanager_tests.js +68 -0
  144. package/build/esm/tests/keysignature_tests.js +322 -0
  145. package/build/esm/tests/mocks.js +70 -0
  146. package/build/esm/tests/modifier_tests.js +24 -0
  147. package/build/esm/tests/multimeasurerest_tests.js +141 -0
  148. package/build/esm/tests/music_tests.js +161 -0
  149. package/build/esm/tests/node_test_runner.js +31 -0
  150. package/build/esm/tests/notehead_tests.js +224 -0
  151. package/build/esm/tests/notesubgroup_tests.js +149 -0
  152. package/build/esm/tests/offscreencanvas_tests.js +47 -0
  153. package/build/esm/tests/ornament_tests.js +333 -0
  154. package/build/esm/tests/parser_tests.js +122 -0
  155. package/build/esm/tests/pedalmarking_tests.js +91 -0
  156. package/build/esm/tests/percussion_tests.js +184 -0
  157. package/build/esm/tests/playwright/flow.spec.js +127 -0
  158. package/build/esm/tests/playwright/visual_helpers.js +30 -0
  159. package/build/esm/tests/registry_tests.js +64 -0
  160. package/build/esm/tests/renderer_tests.js +113 -0
  161. package/build/esm/tests/rests_tests.js +266 -0
  162. package/build/esm/tests/rhythm_tests.js +357 -0
  163. package/build/esm/tests/stave_tests.js +570 -0
  164. package/build/esm/tests/staveconnector_tests.js +402 -0
  165. package/build/esm/tests/stavehairpin_tests.js +90 -0
  166. package/build/esm/tests/staveline_tests.js +123 -0
  167. package/build/esm/tests/stavemodifier_tests.js +51 -0
  168. package/build/esm/tests/stavenote_tests.js +936 -0
  169. package/build/esm/tests/stavetie_tests.js +137 -0
  170. package/build/esm/tests/stringnumber_tests.js +283 -0
  171. package/build/esm/tests/strokes_tests.js +289 -0
  172. package/build/esm/tests/style_tests.js +96 -0
  173. package/build/esm/tests/tabnote_tests.js +462 -0
  174. package/build/esm/tests/tabslide_tests.js +133 -0
  175. package/build/esm/tests/tabstave_tests.js +24 -0
  176. package/build/esm/tests/tabtie_tests.js +171 -0
  177. package/build/esm/tests/test_runner.js +23 -0
  178. package/build/esm/tests/textbracket_tests.js +100 -0
  179. package/build/esm/tests/textnote_tests.js +216 -0
  180. package/build/esm/tests/threevoice_tests.js +132 -0
  181. package/build/esm/tests/tickcontext_tests.js +36 -0
  182. package/build/esm/tests/timesignature_tests.js +173 -0
  183. package/build/esm/tests/tremolo_tests.js +34 -0
  184. package/build/esm/tests/tuning_tests.js +56 -0
  185. package/build/esm/tests/tuplet_tests.js +711 -0
  186. package/build/esm/tests/typeguard_tests.js +82 -0
  187. package/build/esm/tests/unison_tests.js +74 -0
  188. package/build/esm/tests/vexflow_test_helpers.js +318 -0
  189. package/build/esm/tests/vf_prefix_tests.js +101 -0
  190. package/build/esm/tests/vibrato_tests.js +93 -0
  191. package/build/esm/tests/vibratobracket_tests.js +45 -0
  192. package/build/esm/tests/vitest/job-0.test.js +2 -0
  193. package/build/esm/tests/vitest/job-1.test.js +2 -0
  194. package/build/esm/tests/vitest/job-2.test.js +2 -0
  195. package/build/esm/tests/vitest/job-3.test.js +2 -0
  196. package/build/esm/tests/vitest/run.js +5 -0
  197. package/build/esm/tests/vitest.setup.js +44 -0
  198. package/build/esm/tests/voice_tests.js +69 -0
  199. package/build/types/entry/vexflow-bravura.d.ts +3 -0
  200. package/build/types/entry/vexflow-core.d.ts +3 -0
  201. package/build/types/entry/vexflow-debug.d.ts +3 -0
  202. package/build/types/entry/vexflow.d.ts +3 -0
  203. package/build/types/src/accidental.d.ts +60 -0
  204. package/build/types/src/annotation.d.ts +58 -0
  205. package/build/types/src/articulation.d.ts +78 -0
  206. package/build/types/src/barnote.d.ts +29 -0
  207. package/build/types/src/beam.d.ts +158 -0
  208. package/build/types/src/bend.d.ts +67 -0
  209. package/build/types/src/boundingbox.d.ts +42 -0
  210. package/build/types/src/canvascontext.d.ts +93 -0
  211. package/build/types/src/chordsymbol.d.ts +109 -0
  212. package/build/types/src/clef.d.ts +38 -0
  213. package/build/types/src/clefnote.d.ts +17 -0
  214. package/build/types/src/crescendo.d.ts +26 -0
  215. package/build/types/src/curve.d.ts +42 -0
  216. package/build/types/src/dot.d.ts +19 -0
  217. package/build/types/src/easyscore.d.ts +152 -0
  218. package/build/types/src/element.d.ts +278 -0
  219. package/build/types/src/factory.d.ts +273 -0
  220. package/build/types/src/flag.d.ts +12 -0
  221. package/build/types/src/font.d.ts +96 -0
  222. package/build/types/src/fonts/academico.d.ts +1 -0
  223. package/build/types/src/fonts/academicobold.d.ts +1 -0
  224. package/build/types/src/fonts/bravura.d.ts +1 -0
  225. package/build/types/src/fonts/gonville.d.ts +1 -0
  226. package/build/types/src/fonts/petaluma.d.ts +1 -0
  227. package/build/types/src/fonts/petalumascript.d.ts +1 -0
  228. package/build/types/src/formatter.d.ts +226 -0
  229. package/build/types/src/fraction.d.ts +65 -0
  230. package/build/types/src/frethandfinger.d.ts +19 -0
  231. package/build/types/src/ghostnote.d.ts +16 -0
  232. package/build/types/src/glyphnote.d.ts +14 -0
  233. package/build/types/src/glyphs.d.ts +2935 -0
  234. package/build/types/src/gracenote.d.ts +17 -0
  235. package/build/types/src/gracenotegroup.d.ts +33 -0
  236. package/build/types/src/gracetabnote.d.ts +5 -0
  237. package/build/types/src/index.d.ts +86 -0
  238. package/build/types/src/keymanager.d.ts +25 -0
  239. package/build/types/src/keysignature.d.ts +50 -0
  240. package/build/types/src/keysignote.d.ts +11 -0
  241. package/build/types/src/metrics.d.ts +25 -0
  242. package/build/types/src/modifier.d.ts +90 -0
  243. package/build/types/src/modifiercontext.d.ts +48 -0
  244. package/build/types/src/multimeasurerest.d.ts +61 -0
  245. package/build/types/src/music.d.ts +91 -0
  246. package/build/types/src/note.d.ts +232 -0
  247. package/build/types/src/notehead.d.ts +50 -0
  248. package/build/types/src/notesubgroup.d.ts +18 -0
  249. package/build/types/src/ornament.d.ts +71 -0
  250. package/build/types/src/parenthesis.d.ts +21 -0
  251. package/build/types/src/parser.d.ts +45 -0
  252. package/build/types/src/pedalmarking.d.ts +63 -0
  253. package/build/types/src/registry.d.ts +40 -0
  254. package/build/types/src/rendercontext.d.ts +59 -0
  255. package/build/types/src/renderer.d.ts +35 -0
  256. package/build/types/src/repeatnote.d.ts +6 -0
  257. package/build/types/src/stave.d.ts +181 -0
  258. package/build/types/src/stavebarline.d.ts +38 -0
  259. package/build/types/src/staveconnector.d.ts +53 -0
  260. package/build/types/src/stavehairpin.d.ts +56 -0
  261. package/build/types/src/staveline.d.ts +49 -0
  262. package/build/types/src/stavemodifier.d.ts +35 -0
  263. package/build/types/src/stavenote.d.ts +150 -0
  264. package/build/types/src/staverepetition.d.ts +30 -0
  265. package/build/types/src/stavesection.d.ts +8 -0
  266. package/build/types/src/stavetempo.d.ts +43 -0
  267. package/build/types/src/stavetext.d.ts +11 -0
  268. package/build/types/src/stavetie.d.ts +104 -0
  269. package/build/types/src/stavevolta.d.ts +15 -0
  270. package/build/types/src/stem.d.ts +58 -0
  271. package/build/types/src/stemmablenote.d.ts +39 -0
  272. package/build/types/src/stringnumber.d.ts +26 -0
  273. package/build/types/src/strokes.d.ts +35 -0
  274. package/build/types/src/svgcontext.d.ts +135 -0
  275. package/build/types/src/system.d.ts +121 -0
  276. package/build/types/src/tables.d.ts +86 -0
  277. package/build/types/src/tabnote.d.ts +45 -0
  278. package/build/types/src/tabslide.d.ts +36 -0
  279. package/build/types/src/tabstave.d.ts +7 -0
  280. package/build/types/src/tabtie.d.ts +18 -0
  281. package/build/types/src/textbracket.d.ts +45 -0
  282. package/build/types/src/textdynamics.d.ts +34 -0
  283. package/build/types/src/textnote.d.ts +48 -0
  284. package/build/types/src/tickable.d.ts +149 -0
  285. package/build/types/src/tickcontext.d.ts +112 -0
  286. package/build/types/src/timesignature.d.ts +75 -0
  287. package/build/types/src/timesignote.d.ts +11 -0
  288. package/build/types/src/tremolo.d.ts +12 -0
  289. package/build/types/src/tuning.d.ts +23 -0
  290. package/build/types/src/tuplet.d.ts +98 -0
  291. package/build/types/src/typeguard.d.ts +100 -0
  292. package/build/types/src/util.d.ts +42 -0
  293. package/build/types/src/version.d.ts +3 -0
  294. package/build/types/src/vexflow.d.ts +261 -0
  295. package/build/types/src/vibrato.d.ts +20 -0
  296. package/build/types/src/vibratobracket.d.ts +28 -0
  297. package/build/types/src/voice.d.ts +109 -0
  298. package/build/types/src/web.d.ts +2 -0
  299. package/package.json +145 -0
  300. package/tests/flow.html +256 -0
@@ -0,0 +1,759 @@
1
+ import { VexFlow } from '../src/vexflow.js';
2
+ import { VexFlowTests } from './vexflow_test_helpers.js';
3
+ import { Accidental } from '../src/accidental.js';
4
+ import { Annotation, AnnotationVerticalJustify } from '../src/annotation.js';
5
+ import { Articulation } from '../src/articulation.js';
6
+ import { Beam } from '../src/beam.js';
7
+ import { Bend } from '../src/bend.js';
8
+ import { Dot } from '../src/dot.js';
9
+ import { Element } from '../src/element.js';
10
+ import { FontWeight } from '../src/font.js';
11
+ import { Formatter } from '../src/formatter.js';
12
+ import { FretHandFinger } from '../src/frethandfinger.js';
13
+ import { Glyphs } from '../src/glyphs.js';
14
+ import { Metrics } from '../src/metrics.js';
15
+ import { ModifierPosition } from '../src/modifier.js';
16
+ import { Note } from '../src/note.js';
17
+ import { Registry } from '../src/registry.js';
18
+ import { Stave } from '../src/stave.js';
19
+ import { StaveConnector } from '../src/staveconnector.js';
20
+ import { StaveNote } from '../src/stavenote.js';
21
+ import { Stem } from '../src/stem.js';
22
+ import { StringNumber } from '../src/stringnumber.js';
23
+ import { Tuplet } from '../src/tuplet.js';
24
+ import { Voice } from '../src/voice.js';
25
+ import { MockTickable } from './mocks.js';
26
+ const QUARTER_NOTE_DURATION = VexFlow.RESOLUTION / 4;
27
+ function createTickable(beat) {
28
+ return new MockTickable().setTicks(beat);
29
+ }
30
+ function getTestVoices() {
31
+ const BEAT = VexFlow.RESOLUTION / 4;
32
+ const tickables1 = [
33
+ createTickable(BEAT).setWidth(10),
34
+ createTickable(BEAT * 2).setWidth(20),
35
+ createTickable(BEAT).setWidth(30),
36
+ ];
37
+ const tickables2 = [
38
+ createTickable(BEAT * 2).setWidth(10),
39
+ createTickable(BEAT).setWidth(20),
40
+ createTickable(BEAT).setWidth(30),
41
+ ];
42
+ const voice1 = new Voice(VexFlow.TIME4_4);
43
+ const voice2 = new Voice(VexFlow.TIME4_4);
44
+ voice1.addTickables(tickables1);
45
+ voice2.addTickables(tickables2);
46
+ return [voice1, voice2];
47
+ }
48
+ const FormatterTests = {
49
+ Start() {
50
+ VexFlowTests.module('Formatter');
51
+ VexFlowTests.test('getResolutionMultiplier', getResolutionMultiplier);
52
+ VexFlowTests.test('TickContext Building', buildTickContexts);
53
+ const run = VexFlowTests.runTests;
54
+ run('Penultimate Note Padding', penultimateNote);
55
+ run('Whitespace and justify', rightJustify);
56
+ run('Notehead padding', noteHeadPadding);
57
+ run('Justification and alignment with accidentals', accidentalJustification);
58
+ run('Long measure taking full space', longMeasureProblems);
59
+ run('Vertical alignment - few unaligned beats', unalignedNoteDurations1);
60
+ run('Vertical alignment - many unaligned beats', unalignedNoteDurations2, { globalSoftmax: false });
61
+ run('Vertical alignment - many unaligned beats (global softmax)', unalignedNoteDurations2, { globalSoftmax: true });
62
+ run('Vertical alignment - many mixed elements', alignedMixedElements, { globalSoftmax: true });
63
+ run('StaveNote - Justification', justifyStaveNotes);
64
+ run('Notes with Tab', notesWithTab);
65
+ run('Multiple Staves - Justified', multiStaves, { debug: true });
66
+ run('Softmax', softMax);
67
+ run('Mixtime', mixTime);
68
+ run('Tight', tightNotes1);
69
+ run('Tight 2', tightNotes2);
70
+ run('Annotations', annotations);
71
+ run('Proportional Formatting - No Tuning', proportional, { debug: true, iterations: 0 });
72
+ run('Proportional Formatting - No Justification', proportional, { justify: false, debug: true, iterations: 0 });
73
+ run('Proportional Formatting (20 iterations)', proportional, { debug: true, iterations: 20, alpha: 0.5 });
74
+ },
75
+ };
76
+ function getGlyphWidth(glyph) {
77
+ const el = new Element();
78
+ el.setText(glyph);
79
+ return el.getWidth();
80
+ }
81
+ function getResolutionMultiplier(assert) {
82
+ const [voice1, voice2] = getTestVoices();
83
+ assert.equal(voice1.getResolutionMultiplier(), voice2.getResolutionMultiplier(), 'Voices with same smallest duration have the same resolution multiplier');
84
+ assert.equal(Formatter.getResolutionMultiplier([voice1, voice2]), voice1.getResolutionMultiplier(), 'LCM of voice1, voice2 is voice1');
85
+ const TIME1_4 = {
86
+ numBeats: 1,
87
+ beatValue: 4,
88
+ resolution: VexFlow.RESOLUTION,
89
+ };
90
+ const tickables3 = [];
91
+ for (let i = 0; i < 3; i++) {
92
+ tickables3.push(new StaveNote({ keys: ['f/4'], duration: '8' }).setWidth(15));
93
+ }
94
+ new Tuplet(tickables3, { numNotes: 3, notesOccupied: 2 });
95
+ const voice3 = new Voice(TIME1_4);
96
+ voice3.addTickables(tickables3);
97
+ const tickables4 = [];
98
+ for (let i = 0; i < 5; i++) {
99
+ tickables4.push(new StaveNote({ keys: ['f/4'], duration: '16' }).setWidth(9));
100
+ }
101
+ new Tuplet(tickables4, { numNotes: 5, notesOccupied: 4 });
102
+ const voice4 = new Voice(TIME1_4);
103
+ voice4.addTickables(tickables4);
104
+ assert.notEqual(voice3.getResolutionMultiplier(), voice4.getResolutionMultiplier());
105
+ assert.notEqual(Formatter.getResolutionMultiplier([voice3, voice4]), voice3.getResolutionMultiplier(), 'LCM of RM of voices 3 and 4 is neither RM(3) nor RM(4)');
106
+ assert.notEqual(Formatter.getResolutionMultiplier([voice3, voice4]), voice4.getResolutionMultiplier(), 'LCM of RM of voices 3 and 4 is neither RM(3) nor RM(4)');
107
+ }
108
+ function buildTickContexts(assert) {
109
+ const [voice1, voice2] = getTestVoices();
110
+ const tickables1 = voice1.getTickables();
111
+ const tickables2 = voice2.getTickables();
112
+ const formatter = new Formatter();
113
+ const tContexts = formatter.createTickContexts([voice1, voice2]);
114
+ assert.equal(tContexts.list.length, 4, 'Voices should have four tick contexts');
115
+ assert.throws(() => formatter.getMinTotalWidth(), /NoMinTotalWidth/, 'Expected to throw exception');
116
+ assert.ok(formatter.preCalculateMinTotalWidth([voice1, voice2]), 'Successfully runs preCalculateMinTotalWidth');
117
+ assert.equal(formatter.getMinTotalWidth(), 88, 'Get minimum total width without passing voices');
118
+ formatter.preFormat();
119
+ assert.equal(formatter.getMinTotalWidth(), 88, 'Minimum total width');
120
+ assert.equal(tickables1[0].getX(), tickables2[0].getX(), 'First notes of both voices have the same X');
121
+ assert.equal(tickables1[2].getX(), tickables2[2].getX(), 'Last notes of both voices have the same X');
122
+ assert.ok(tickables1[1].getX() < tickables2[1].getX(), 'Second note of voice 2 is to the right of the second note of voice 1');
123
+ }
124
+ function rightJustify(options) {
125
+ const f = VexFlowTests.makeFactory(options, 1200, 150);
126
+ const getTickables = (time, n, duration, duration2) => {
127
+ const tickar = [];
128
+ let i = 0;
129
+ for (i = 0; i < n; ++i) {
130
+ const dd = i === n - 1 ? duration2 : duration;
131
+ tickar.push(new StaveNote({ keys: ['f/4'], duration: dd }));
132
+ }
133
+ return new Voice(time).addTickables(tickar);
134
+ };
135
+ const renderTest = (time, n, duration, duration2, x, width) => {
136
+ const formatter = f.Formatter();
137
+ const stave = f.Stave({ x, y: 20, width });
138
+ const voice = getTickables(time, n, duration, duration2);
139
+ formatter.joinVoices([voice]).formatToStave([voice], stave);
140
+ stave.drawWithStyle();
141
+ voice.draw(f.getContext(), stave);
142
+ };
143
+ renderTest({ numBeats: 4, beatValue: 4, resolution: 4 * QUARTER_NOTE_DURATION }, 3, '4', '2', 10, 300);
144
+ renderTest({ numBeats: 4, beatValue: 4, resolution: 4 * QUARTER_NOTE_DURATION }, 1, 'w', 'w', 310, 300);
145
+ renderTest({ numBeats: 3, beatValue: 4, resolution: 4 * QUARTER_NOTE_DURATION }, 3, '4', '4', 610, 300);
146
+ renderTest({ numBeats: 3, beatValue: 4, resolution: 4 * QUARTER_NOTE_DURATION }, 6, '8', '8', 910, 300);
147
+ options.assert.ok(true);
148
+ }
149
+ function penultimateNote(options) {
150
+ const f = VexFlowTests.makeFactory(options, 500, 550);
151
+ const score = f.EasyScore();
152
+ const staffWidth = 310;
153
+ let system = undefined;
154
+ let voices = [];
155
+ let notes = [];
156
+ let note = undefined;
157
+ let stave = undefined;
158
+ let y = 10;
159
+ const draw = (softmax) => {
160
+ system = f.System({
161
+ width: staffWidth,
162
+ y,
163
+ formatOptions: { alignRests: true },
164
+ details: { softmaxFactor: softmax },
165
+ });
166
+ notes = [];
167
+ voices = [];
168
+ note = score.notes('C4/8/r', { clef: 'bass' })[0];
169
+ notes.push(note);
170
+ note = score.notes('A3/8', { stem: 'up', clef: 'bass' })[0];
171
+ notes.push(note);
172
+ note = score.notes('C4/4', { stem: 'up', clef: 'bass' })[0];
173
+ notes.push(note);
174
+ voices.push(score.voice(notes).setMode(2));
175
+ notes = [];
176
+ note = score.notes('( F3 A3 )/4', { stem: 'down', clef: 'bass' })[0];
177
+ notes.push(note);
178
+ note = score.notes('B4/4/r', {})[0];
179
+ notes.push(note);
180
+ voices.push(score.voice(notes).setMode(2));
181
+ notes = [];
182
+ stave = system.addStave({ voices: voices });
183
+ stave.addClef('bass');
184
+ stave.addTimeSignature('2/4');
185
+ voices = [];
186
+ f.draw();
187
+ f.getContext().fillText(`softmax: ${softmax.toString()}`, staffWidth + 20, y + 50);
188
+ y += 100;
189
+ };
190
+ draw(15);
191
+ draw(10);
192
+ draw(5);
193
+ draw(2);
194
+ draw(1);
195
+ options.assert.ok(true);
196
+ }
197
+ function noteHeadPadding(options) {
198
+ const registry = new Registry();
199
+ Registry.enableDefaultRegistry(registry);
200
+ const f = VexFlowTests.makeFactory(options, 600, 300);
201
+ const score = f.EasyScore();
202
+ score.set({ time: '9/8' });
203
+ const notes1 = score.notes('(d5 f5)/8,(c5 e5)/8,(d5 f5)/8,(c5 e5)/2.');
204
+ const beams = [new Beam(notes1.slice(0, 3), true)];
205
+ const voice1 = new Voice().setMode(Voice.Mode.SOFT);
206
+ const notes2 = score.notes('(g4 an4)/2.,(g4 a4)/4.', { clef: 'treble' });
207
+ const voice2 = new Voice().setMode(Voice.Mode.SOFT);
208
+ voice2.addTickables(notes2);
209
+ voice1.addTickables(notes1);
210
+ const formatter = f.Formatter().joinVoices([voice1]).joinVoices([voice2]);
211
+ const width = formatter.preCalculateMinTotalWidth([voice1, voice2]);
212
+ formatter.format([voice1, voice2], width);
213
+ const staveWidth = width + Stave.defaultPadding;
214
+ const stave1 = f.Stave({ y: 50, width: staveWidth });
215
+ const stave2 = f.Stave({ y: 150, width: staveWidth });
216
+ stave1.drawWithStyle();
217
+ stave2.drawWithStyle();
218
+ voice1.draw(f.getContext(), stave1);
219
+ voice2.draw(f.getContext(), stave2);
220
+ beams.forEach((b) => b.setContext(f.getContext()).drawWithStyle());
221
+ options.assert.ok(true);
222
+ }
223
+ function longMeasureProblems(options) {
224
+ const registry = new Registry();
225
+ Registry.enableDefaultRegistry(registry);
226
+ const f = VexFlowTests.makeFactory(options, 1500, 300);
227
+ const score = f.EasyScore();
228
+ score.set({ time: '4/4' });
229
+ 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');
230
+ const voice1 = new Voice().setMode(Voice.Mode.SOFT);
231
+ 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' });
232
+ const voice2 = new Voice().setMode(Voice.Mode.SOFT);
233
+ voice2.addTickables(notes2);
234
+ voice1.addTickables(notes1);
235
+ const formatter = f.Formatter().joinVoices([voice1]).joinVoices([voice2]);
236
+ const width = formatter.preCalculateMinTotalWidth([voice1, voice2]);
237
+ formatter.format([voice1, voice2], width);
238
+ const stave1 = f.Stave({ y: 50, width: width + Stave.defaultPadding });
239
+ const stave2 = f.Stave({ y: 200, width: width + Stave.defaultPadding });
240
+ stave1.drawWithStyle();
241
+ stave2.drawWithStyle();
242
+ voice1.draw(f.getContext(), stave1);
243
+ voice2.draw(f.getContext(), stave2);
244
+ options.assert.ok(true);
245
+ }
246
+ function accidentalJustification(options) {
247
+ const f = VexFlowTests.makeFactory(options, 600, 300);
248
+ const score = f.EasyScore();
249
+ const notes11 = score.notes('a4/2, a4/4, a4/8, ab4/16, an4/16');
250
+ const voice11 = score.voice(notes11, { time: '4/4' });
251
+ const notes21 = score.notes('c4/2, d4/8, d4/8, e4/8, e4/8');
252
+ const voice21 = score.voice(notes21, { time: '4/4' });
253
+ let beams = Beam.generateBeams(notes11.slice(2));
254
+ beams = beams.concat(beams, Beam.generateBeams(notes21.slice(1, 3)));
255
+ beams = beams.concat(Beam.generateBeams(notes21.slice(3)));
256
+ const formatter = f.Formatter({}).joinVoices([voice11]).joinVoices([voice21]);
257
+ const width = formatter.preCalculateMinTotalWidth([voice11, voice21]);
258
+ const stave11 = f.Stave({ y: 20, width: width + Stave.defaultPadding });
259
+ const stave21 = f.Stave({ y: 130, width: width + Stave.defaultPadding });
260
+ formatter.format([voice11, voice21], width);
261
+ const ctx = f.getContext();
262
+ stave11.setContext(ctx).drawWithStyle();
263
+ stave21.setContext(ctx).drawWithStyle();
264
+ voice11.draw(ctx, stave11);
265
+ voice21.draw(ctx, stave21);
266
+ beams.forEach((b) => b.setContext(ctx).drawWithStyle());
267
+ options.assert.ok(true);
268
+ }
269
+ function unalignedNoteDurations1(options) {
270
+ const f = VexFlowTests.makeFactory(options, 600, 250);
271
+ const score = f.EasyScore();
272
+ const notes11 = [
273
+ new StaveNote({ keys: ['a/4'], duration: '8' }),
274
+ new StaveNote({ keys: ['b/4'], duration: '4' }),
275
+ new StaveNote({ keys: ['b/4'], duration: '8' }),
276
+ ];
277
+ const notes21 = [
278
+ new StaveNote({ keys: ['a/4'], duration: '16' }),
279
+ new StaveNote({ keys: ['b/4.'], duration: '4' }),
280
+ new StaveNote({ keys: ['a/4'], duration: '8d' }),
281
+ ];
282
+ Dot.buildAndAttach([notes21[2]], { all: true });
283
+ const ctx = f.getContext();
284
+ const voice11 = score.voice(notes11, { time: '2/4' }).setMode(Voice.Mode.SOFT);
285
+ const voice21 = score.voice(notes21, { time: '2/4' }).setMode(Voice.Mode.SOFT);
286
+ const beams21 = Beam.generateBeams(notes21);
287
+ const beams11 = Beam.generateBeams(notes11);
288
+ const formatter = new Formatter();
289
+ formatter.joinVoices([voice11]);
290
+ formatter.joinVoices([voice21]);
291
+ const width = formatter.preCalculateMinTotalWidth([voice11, voice21]);
292
+ const stave11 = f.Stave({ y: 20, width: width + Stave.defaultPadding });
293
+ const stave21 = f.Stave({ y: 130, width: width + Stave.defaultPadding });
294
+ formatter.format([voice11, voice21], width);
295
+ stave11.setContext(ctx).drawWithStyle();
296
+ stave21.setContext(ctx).drawWithStyle();
297
+ voice11.draw(ctx, stave11);
298
+ voice21.draw(ctx, stave21);
299
+ beams21.forEach((b) => b.setContext(ctx).drawWithStyle());
300
+ beams11.forEach((b) => b.setContext(ctx).drawWithStyle());
301
+ options.assert.ok(voice11.getTickables()[1].getX() > voice21.getTickables()[1].getX());
302
+ }
303
+ function unalignedNoteDurations2(options) {
304
+ const notes1 = [
305
+ new StaveNote({ keys: ['b/4'], duration: '8r' }),
306
+ new StaveNote({ keys: ['g/4'], duration: '16' }),
307
+ new StaveNote({ keys: ['c/5'], duration: '16' }),
308
+ new StaveNote({ keys: ['e/5'], duration: '16' }),
309
+ new StaveNote({ keys: ['g/4'], duration: '16' }),
310
+ new StaveNote({ keys: ['c/5'], duration: '16' }),
311
+ new StaveNote({ keys: ['e/5'], duration: '16' }),
312
+ new StaveNote({ keys: ['b/4'], duration: '8r' }),
313
+ new StaveNote({ keys: ['g/4'], duration: '16' }),
314
+ new StaveNote({ keys: ['c/5'], duration: '16' }),
315
+ new StaveNote({ keys: ['e/5'], duration: '16' }),
316
+ new StaveNote({ keys: ['g/4'], duration: '16' }),
317
+ new StaveNote({ keys: ['c/5'], duration: '16' }),
318
+ new StaveNote({ keys: ['e/5'], duration: '16' }),
319
+ ];
320
+ const notes2 = [
321
+ new StaveNote({ keys: ['a/4'], duration: '16r' }),
322
+ new StaveNote({ keys: ['e/4.'], duration: '8d' }),
323
+ new StaveNote({ keys: ['e/4'], duration: '4' }),
324
+ new StaveNote({ keys: ['a/4'], duration: '16r' }),
325
+ new StaveNote({ keys: ['e/4.'], duration: '8d' }),
326
+ new StaveNote({ keys: ['e/4'], duration: '4' }),
327
+ ];
328
+ const f = VexFlowTests.makeFactory(options, 750, 280);
329
+ const context = f.getContext();
330
+ const voice1 = new Voice({ numBeats: 4, beatValue: 4 });
331
+ voice1.addTickables(notes1);
332
+ const voice2 = new Voice({ numBeats: 4, beatValue: 4 });
333
+ voice2.addTickables(notes2);
334
+ const formatter = new Formatter({ globalSoftmax: options.params.globalSoftmax });
335
+ formatter.joinVoices([voice1]);
336
+ formatter.joinVoices([voice2]);
337
+ const width = formatter.preCalculateMinTotalWidth([voice1, voice2]);
338
+ formatter.format([voice1, voice2], width);
339
+ const stave1 = new Stave(10, 40, width + Stave.defaultPadding);
340
+ const stave2 = new Stave(10, 100, width + Stave.defaultPadding);
341
+ stave1.setContext(context).drawWithStyle();
342
+ stave2.setContext(context).drawWithStyle();
343
+ voice1.draw(context, stave1);
344
+ voice2.draw(context, stave2);
345
+ options.assert.ok(voice1.getTickables()[1].getX() > voice2.getTickables()[1].getX());
346
+ }
347
+ function alignedMixedElements(options) {
348
+ const f = VexFlowTests.makeFactory(options, 800, 500);
349
+ const context = f.getContext();
350
+ const stave = new Stave(10, 200, 400);
351
+ const stave2 = new Stave(410, 200, 400);
352
+ const notes = [
353
+ new StaveNote({ keys: ['c/5'], duration: '8' })
354
+ .addModifier(new Accidental('##'), 0)
355
+ .addModifier(new FretHandFinger('4').setPosition(ModifierPosition.BELOW), 0)
356
+ .addModifier(new StringNumber('3').setPosition(ModifierPosition.BELOW), 0)
357
+ .addModifier(new Articulation('a.').setPosition(ModifierPosition.BELOW), 0)
358
+ .addModifier(new Articulation('a>').setPosition(ModifierPosition.BELOW), 0)
359
+ .addModifier(new Articulation('a^').setPosition(ModifierPosition.BELOW), 0)
360
+ .addModifier(new Articulation('am').setPosition(ModifierPosition.BELOW), 0)
361
+ .addModifier(new Articulation('a@u').setPosition(ModifierPosition.BELOW), 0)
362
+ .addModifier(new Annotation('yyyy').setVerticalJustification(AnnotationVerticalJustify.BOTTOM), 0)
363
+ .addModifier(new Annotation('xxxx').setVerticalJustification(AnnotationVerticalJustify.BOTTOM).setFont('sans-serif', 20), 0)
364
+ .addModifier(new Annotation('ttt').setVerticalJustification(AnnotationVerticalJustify.BOTTOM).setFont('sans-serif', 20), 0),
365
+ new StaveNote({ keys: ['c/5'], duration: '8', stemDirection: Stem.DOWN })
366
+ .addModifier(new StringNumber('3').setPosition(ModifierPosition.BELOW), 0)
367
+ .addModifier(new Articulation('a.').setPosition(ModifierPosition.BELOW), 0)
368
+ .addModifier(new Articulation('a>').setPosition(ModifierPosition.BELOW), 0),
369
+ new StaveNote({ keys: ['c/5'], duration: '8' }),
370
+ ];
371
+ const notes2 = [
372
+ new StaveNote({ keys: ['c/5'], duration: '8' })
373
+ .addModifier(new StringNumber('3').setPosition(ModifierPosition.ABOVE), 0)
374
+ .addModifier(new Articulation('a.').setPosition(ModifierPosition.ABOVE), 0)
375
+ .addModifier(new Annotation('yyyy').setVerticalJustification(AnnotationVerticalJustify.TOP), 0),
376
+ new StaveNote({ keys: ['c/5'], duration: '8', stemDirection: Stem.DOWN })
377
+ .addModifier(new FretHandFinger('4').setPosition(ModifierPosition.ABOVE), 0)
378
+ .addModifier(new StringNumber('3').setPosition(ModifierPosition.ABOVE), 0)
379
+ .addModifier(new Articulation('a.').setPosition(ModifierPosition.ABOVE), 0)
380
+ .addModifier(new Articulation('a>').setPosition(ModifierPosition.ABOVE), 0)
381
+ .addModifier(new Articulation('a^').setPosition(ModifierPosition.ABOVE), 0)
382
+ .addModifier(new Articulation('am').setPosition(ModifierPosition.ABOVE), 0)
383
+ .addModifier(new Articulation('a@u').setPosition(ModifierPosition.ABOVE), 0)
384
+ .addModifier(new Annotation('yyyy').setVerticalJustification(AnnotationVerticalJustify.TOP), 0)
385
+ .addModifier(new Annotation('xxxx').setVerticalJustification(AnnotationVerticalJustify.TOP).setFont('sans-serif', 20), 0)
386
+ .addModifier(new Annotation('ttt').setVerticalJustification(AnnotationVerticalJustify.TOP).setFont('sans-serif', 20), 0),
387
+ new StaveNote({ keys: ['c/5'], duration: '8' }),
388
+ ];
389
+ const tuplet = new Tuplet(notes).setTupletLocation(-1);
390
+ const tuplet2 = new Tuplet(notes2).setTupletLocation(1);
391
+ Formatter.FormatAndDraw(context, stave, notes);
392
+ Formatter.FormatAndDraw(context, stave2, notes2);
393
+ stave.setContext(context).drawWithStyle();
394
+ stave2.setContext(context).drawWithStyle();
395
+ tuplet.setContext(context).drawWithStyle();
396
+ tuplet2.setContext(context).drawWithStyle();
397
+ options.assert.ok(true);
398
+ }
399
+ function justifyStaveNotes(options) {
400
+ const f = VexFlowTests.makeFactory(options, 520, 280);
401
+ const ctx = f.getContext();
402
+ const score = f.EasyScore();
403
+ let y = 30;
404
+ function justifyToWidth(width) {
405
+ f.Stave({ y: y }).addClef('treble');
406
+ const voices = [
407
+ score.voice(score.notes('(cbb4 en4 a4)/2, (d4 e4 f4)/8, (d4 f4 a4)/8, (cn4 f#4 a4)/4', { stem: 'down' })),
408
+ score.voice(score.notes('(bb4 e#5 a5)/4, (d5 e5 f5)/2, (c##5 fb5 a5)/4', { stem: 'up' })),
409
+ ];
410
+ f.Formatter()
411
+ .joinVoices(voices)
412
+ .format(voices, width - (Stave.defaultPadding + getGlyphWidth(Glyphs.gClef)));
413
+ voices[0].getTickables().forEach((note) => Note.plotMetrics(ctx, note, y + 140));
414
+ voices[1].getTickables().forEach((note) => Note.plotMetrics(ctx, note, y - 20));
415
+ y += 210;
416
+ }
417
+ justifyToWidth(520);
418
+ f.draw();
419
+ options.assert.ok(true);
420
+ }
421
+ function notesWithTab(options) {
422
+ const f = VexFlowTests.makeFactory(options, 420, 580);
423
+ const score = f.EasyScore();
424
+ let y = 10;
425
+ function justifyToWidth(width) {
426
+ const stave = f.Stave({ y: y }).addClef('treble');
427
+ const voice = score.voice(score.notes('d#4/2, (c4 d4)/8, d4/8, (c#4 e4 a4)/4', { stem: 'up' }));
428
+ y += 100;
429
+ f.TabStave({ y: y }).addTabGlyph().setNoteStartX(stave.getNoteStartX());
430
+ const tabVoice = score.voice([
431
+ f
432
+ .TabNote({ positions: [{ str: 3, fret: 6 }], duration: '2' })
433
+ .addModifier(new Bend([{ type: Bend.UP, text: 'Full' }]), 0),
434
+ f
435
+ .TabNote({
436
+ positions: [
437
+ { str: 2, fret: 3 },
438
+ { str: 3, fret: 5 },
439
+ ],
440
+ duration: '8',
441
+ })
442
+ .addModifier(new Bend([{ type: Bend.UP, text: 'Unison' }]), 1),
443
+ f.TabNote({ positions: [{ str: 3, fret: 7 }], duration: '8' }),
444
+ f.TabNote({
445
+ positions: [
446
+ { str: 3, fret: 6 },
447
+ { str: 4, fret: 7 },
448
+ { str: 2, fret: 5 },
449
+ ],
450
+ duration: '4',
451
+ }),
452
+ ]);
453
+ f.Formatter().joinVoices([voice]).joinVoices([tabVoice]).format([voice, tabVoice], width);
454
+ y += 150;
455
+ }
456
+ justifyToWidth(0);
457
+ justifyToWidth(300);
458
+ f.draw();
459
+ options.assert.ok(true);
460
+ }
461
+ function multiStaves(options) {
462
+ const f = VexFlowTests.makeFactory(options, 600, 400);
463
+ const ctx = f.getContext();
464
+ const score = f.EasyScore();
465
+ const notes11 = score.notes('f4/4, d4/8, g4/4, eb4/8');
466
+ const notes21 = score.notes('d4/8, d4, d4, d4, e4, eb4');
467
+ const notes31 = score.notes('a5/8, a5, a5, a5, a5, a5', { stem: 'down' });
468
+ let voices = [
469
+ score.voice(notes11, { time: '6/8' }),
470
+ score.voice(notes21, { time: '6/8' }),
471
+ score.voice(notes31, { time: '6/8' }),
472
+ ];
473
+ let formatter = f.Formatter();
474
+ voices.forEach((v) => formatter.joinVoices([v]));
475
+ let width = formatter.preCalculateMinTotalWidth(voices);
476
+ formatter.format(voices, width);
477
+ let beams = [
478
+ new Beam(notes21.slice(0, 3), true),
479
+ new Beam(notes21.slice(3, 6), true),
480
+ new Beam(notes31.slice(0, 3), true),
481
+ new Beam(notes31.slice(3, 6), true),
482
+ ];
483
+ const staveYs = [20, 130, 250];
484
+ let staveWidth = width + getGlyphWidth(Glyphs.gClef) + getGlyphWidth(Glyphs.timeSig8) + Stave.defaultPadding;
485
+ let staves = [
486
+ f.Stave({ y: staveYs[0], width: staveWidth }).addClef('treble').addTimeSignature('6/8'),
487
+ f.Stave({ y: staveYs[1], width: staveWidth }).addClef('treble').addTimeSignature('6/8'),
488
+ f.Stave({ y: staveYs[2], width: staveWidth }).addClef('bass').addTimeSignature('6/8'),
489
+ ];
490
+ f.StaveConnector({
491
+ topStave: staves[1],
492
+ bottomStave: staves[2],
493
+ type: 'brace',
494
+ });
495
+ for (let i = 0; i < staves.length; ++i) {
496
+ staves[i].setContext(ctx).drawWithStyle();
497
+ voices[i].draw(ctx, staves[i]);
498
+ }
499
+ beams.forEach((beam) => beam.setContext(ctx).drawWithStyle());
500
+ const notes12 = score.notes('ab4/4, bb4/8, (cb5 eb5)/4[stem="down"], d5/8[stem="down"]');
501
+ const notes22 = score.notes('(eb4 ab4)/4., (c4 eb4 ab4)/4, db5/8', { stem: 'up' });
502
+ const notes32 = score.notes('a5/8, a5, a5, a5, a5, a5', { stem: 'down' });
503
+ voices = [
504
+ score.voice(notes12, { time: '6/8' }),
505
+ score.voice(notes22, { time: '6/8' }),
506
+ score.voice(notes32, { time: '6/8' }),
507
+ ];
508
+ formatter = f.Formatter();
509
+ voices.forEach((v) => formatter.joinVoices([v]));
510
+ width = formatter.preCalculateMinTotalWidth(voices);
511
+ const staveX = staves[0].getX() + staves[0].getWidth();
512
+ staveWidth = width + Stave.defaultPadding;
513
+ staves = [
514
+ f.Stave({ x: staveX, y: staveYs[0], width: staveWidth }),
515
+ f.Stave({ x: staveX, y: staveYs[1], width: staveWidth }),
516
+ f.Stave({ x: staveX, y: staveYs[2], width: staveWidth }),
517
+ ];
518
+ formatter.format(voices, width);
519
+ beams = [
520
+ new Beam(notes32.slice(0, 3), true),
521
+ new Beam(notes32.slice(3, 6), true),
522
+ ];
523
+ for (let i = 0; i < staves.length; ++i) {
524
+ staves[i].setContext(ctx).drawWithStyle();
525
+ voices[i].draw(ctx, staves[i]);
526
+ voices[i].getTickables().forEach((note) => Note.plotMetrics(ctx, note, staveYs[i] - 20));
527
+ }
528
+ beams.forEach((beam) => beam.setContext(ctx).drawWithStyle());
529
+ options.assert.ok(true);
530
+ }
531
+ function proportional(options) {
532
+ const debug = options.params.debug;
533
+ Registry.enableDefaultRegistry(new Registry());
534
+ const f = VexFlowTests.makeFactory(options, 775, 750);
535
+ const system = f.System({
536
+ x: 50,
537
+ autoWidth: true,
538
+ debugFormatter: debug,
539
+ noJustification: !(options.params.justify === undefined && true),
540
+ formatIterations: options.params.iterations,
541
+ details: { alpha: options.params.alpha },
542
+ });
543
+ const score = f.EasyScore();
544
+ const voices = [
545
+ score.notes('c5/8, c5'),
546
+ score.tuplet(score.notes('a4/8, a4, a4'), { notesOccupied: 2 }),
547
+ score.notes('c5/16, c5, c5, c5'),
548
+ score.tuplet(score.notes('a4/16, a4, a4, a4, a4'), { notesOccupied: 4 }),
549
+ score.tuplet(score.notes('a4/32, a4, a4, a4, a4, a4, a4'), { notesOccupied: 8 }),
550
+ ];
551
+ const createVoice = (notes) => score.voice(notes, { time: '1/4' });
552
+ const createStave = (voice) => system
553
+ .addStave({ voices: [voice], debugNoteMetrics: debug })
554
+ .addClef('treble')
555
+ .addTimeSignature('1/4');
556
+ voices.map(createVoice).forEach(createStave);
557
+ system.addConnector().setType(StaveConnector.type.BRACKET);
558
+ f.draw();
559
+ Registry.disableDefaultRegistry();
560
+ options.assert.ok(true);
561
+ }
562
+ function softMax(options) {
563
+ const f = VexFlowTests.makeFactory(options, 550, 500);
564
+ const textX = 450 / 0.8;
565
+ f.getContext().scale(0.8, 0.8);
566
+ function draw(y, factor) {
567
+ const score = f.EasyScore();
568
+ const system = f.System({
569
+ x: 100,
570
+ y,
571
+ details: { softmaxFactor: factor },
572
+ autoWidth: true,
573
+ });
574
+ system
575
+ .addStave({
576
+ voices: [
577
+ score.voice(score
578
+ .notes('C#5/h, a4/q')
579
+ .concat(score.beam(score.notes('Abb4/8, A4/8')))
580
+ .concat(score.beam(score.notes('A4/16, A#4, A4, Ab4/32, A4'))), { time: '5/4' }),
581
+ ],
582
+ })
583
+ .addClef('treble')
584
+ .addTimeSignature('5/4');
585
+ f.draw();
586
+ f.getContext().fillText(`softmax: ${factor.toString()}`, textX, y + 50);
587
+ options.assert.ok(true);
588
+ }
589
+ draw(50, 1);
590
+ draw(150, 2);
591
+ draw(250, 5);
592
+ draw(350, 10);
593
+ draw(450, 15);
594
+ }
595
+ function mixTime(options) {
596
+ const f = VexFlowTests.makeFactory(options, 400 + Stave.defaultPadding, 250);
597
+ f.getContext().scale(0.8, 0.8);
598
+ const score = f.EasyScore();
599
+ const system = f.System({
600
+ details: {},
601
+ autoWidth: true,
602
+ debugFormatter: true,
603
+ });
604
+ system
605
+ .addStave({
606
+ voices: [score.voice(score.notes('C#5/q, B4').concat(score.beam(score.notes('A4/8, E4, C4, D4'))))],
607
+ })
608
+ .addClef('treble')
609
+ .addTimeSignature('4/4');
610
+ system
611
+ .addStave({
612
+ voices: [score.voice(score.notes('C#5/q, B4, B4').concat(score.tuplet(score.beam(score.notes('A4/8, E4, C4')))))],
613
+ })
614
+ .addClef('treble')
615
+ .addTimeSignature('4/4');
616
+ f.draw();
617
+ options.assert.ok(true);
618
+ }
619
+ function tightNotes1(options) {
620
+ const f = VexFlowTests.makeFactory(options, 440, 250);
621
+ f.getContext().scale(0.8, 0.8);
622
+ const score = f.EasyScore();
623
+ const system = f.System({
624
+ autoWidth: true,
625
+ debugFormatter: true,
626
+ details: { maxIterations: 10 },
627
+ });
628
+ system
629
+ .addStave({
630
+ voices: [
631
+ score.voice(score.beam(score.notes('B4/16, B4, B4, B4, B4, B4, B4, B4')).concat(score.notes('B4/q, B4'))),
632
+ ],
633
+ })
634
+ .addClef('treble')
635
+ .addTimeSignature('4/4');
636
+ system
637
+ .addStave({
638
+ voices: [
639
+ score.voice(score.notes('B4/q, B4').concat(score.beam(score.notes('B4/16, B4, B4, B4, B4, B4, B4, B4')))),
640
+ ],
641
+ })
642
+ .addClef('treble')
643
+ .addTimeSignature('4/4');
644
+ f.draw();
645
+ options.assert.ok(true);
646
+ }
647
+ function tightNotes2(options) {
648
+ const f = VexFlowTests.makeFactory(options, 440, 250);
649
+ f.getContext().scale(0.8, 0.8);
650
+ const score = f.EasyScore();
651
+ const system = f.System({
652
+ autoWidth: true,
653
+ debugFormatter: true,
654
+ });
655
+ system
656
+ .addStave({
657
+ voices: [
658
+ score.voice(score.beam(score.notes('B4/16, B4, B4, B4, B4, B4, B4, B4')).concat(score.notes('B4/q, B4'))),
659
+ ],
660
+ })
661
+ .addClef('treble')
662
+ .addTimeSignature('4/4');
663
+ system
664
+ .addStave({
665
+ voices: [score.voice(score.notes('B4/w'))],
666
+ })
667
+ .addClef('treble')
668
+ .addTimeSignature('4/4');
669
+ f.draw();
670
+ options.assert.ok(true);
671
+ }
672
+ function annotations(options) {
673
+ const pageWidth = 916;
674
+ const pageHeight = 600;
675
+ const f = VexFlowTests.makeFactory(options, pageWidth, pageHeight);
676
+ const context = f.getContext();
677
+ const lyrics1 = ['ipso', 'ipso-', 'ipso', 'ipso', 'ipsoz', 'ipso-', 'ipso', 'ipso', 'ipso', 'ip', 'ipso'];
678
+ const lyrics2 = ['ipso', 'ipso-', 'ipsoz', 'ipso', 'ipso', 'ipso-', 'ipso', 'ipso', 'ipso', 'ip', 'ipso'];
679
+ const smar = [
680
+ {
681
+ sm: 5,
682
+ width: 550,
683
+ lyrics: lyrics1,
684
+ title: '550px,softMax:5',
685
+ },
686
+ {
687
+ sm: 5,
688
+ width: 550,
689
+ lyrics: lyrics2,
690
+ title: '550px,softmax:5,different word order',
691
+ },
692
+ {
693
+ sm: 10,
694
+ width: 550,
695
+ lyrics: lyrics2,
696
+ title: '550px,softmax:10',
697
+ },
698
+ {
699
+ sm: 15,
700
+ width: 550,
701
+ lyrics: lyrics2,
702
+ title: '550px,softmax:15',
703
+ },
704
+ ];
705
+ const rowSize = 140;
706
+ const beats = 12;
707
+ const beatsPer = 8;
708
+ const beamGroup = 3;
709
+ const durations = ['8d', '16', '8', '8d', '16', '8', '8d', '16', '8', '4', '8'];
710
+ const beams = [];
711
+ let y = 40;
712
+ smar.forEach((sm) => {
713
+ const stave = new Stave(10, y, sm.width);
714
+ const notes = [];
715
+ let iii = 0;
716
+ context.fillText(sm.title, 100, y);
717
+ y += rowSize;
718
+ durations.forEach((dd) => {
719
+ const note = new StaveNote({ keys: ['b/4'], duration: dd });
720
+ if (dd.indexOf('d') >= 0) {
721
+ Dot.buildAndAttach([note], { all: true });
722
+ }
723
+ if (sm.lyrics.length > iii) {
724
+ note.addModifier(new Annotation(sm.lyrics[iii])
725
+ .setVerticalJustification(Annotation.VerticalJustify.BOTTOM)
726
+ .setFont(Metrics.get('fontFamily'), 12, FontWeight.NORMAL));
727
+ }
728
+ notes.push(note);
729
+ iii += 1;
730
+ });
731
+ notes.forEach((note) => {
732
+ if (note.getDuration().indexOf('d') >= 0) {
733
+ Dot.buildAndAttach([note], { all: true });
734
+ }
735
+ });
736
+ let notesToBeam = [];
737
+ notes.forEach((note) => {
738
+ if (note.getIntrinsicTicks() < QUARTER_NOTE_DURATION) {
739
+ notesToBeam.push(note);
740
+ if (notesToBeam.length >= beamGroup) {
741
+ beams.push(new Beam(notesToBeam));
742
+ notesToBeam = [];
743
+ }
744
+ }
745
+ else {
746
+ notesToBeam = [];
747
+ }
748
+ });
749
+ const voice1 = new Voice({ numBeats: beats, beatValue: beatsPer }).setMode(Voice.Mode.SOFT).addTickables(notes);
750
+ const fmt = new Formatter({ softmaxFactor: sm.sm, maxIterations: 2 }).joinVoices([voice1]);
751
+ fmt.format([voice1], sm.width - 11);
752
+ stave.setContext(context).drawWithStyle();
753
+ voice1.draw(context, stave);
754
+ beams.forEach((b) => b.setContext(context).drawWithStyle());
755
+ });
756
+ options.assert.ok(true);
757
+ }
758
+ VexFlowTests.register(FormatterTests);
759
+ export { FormatterTests };