@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,1055 @@
1
+ import { VexFlowTests } from './vexflow_test_helpers.js';
2
+ import { Accidental } from '../src/accidental.js';
3
+ import { Beam } from '../src/beam.js';
4
+ import { Dot } from '../src/dot.js';
5
+ import { Formatter } from '../src/formatter.js';
6
+ import { Glyphs } from '../src/glyphs.js';
7
+ import { ModifierContext } from '../src/modifiercontext.js';
8
+ import { Note } from '../src/note.js';
9
+ import { Stave } from '../src/stave.js';
10
+ import { StaveNote } from '../src/stavenote.js';
11
+ import { Stem } from '../src/stem.js';
12
+ import { TickContext } from '../src/tickcontext.js';
13
+ import { TimeSigNote } from '../src/timesignote.js';
14
+ import { isAccidental } from '../src/typeguard.js';
15
+ import { Voice } from '../src/voice.js';
16
+ const AccidentalTests = {
17
+ Start() {
18
+ VexFlowTests.module('Accidental');
19
+ VexFlowTests.test('Automatic Accidentals - Simple Tests', autoAccidentalWorking);
20
+ const run = VexFlowTests.runTests;
21
+ run('Bounding Box', basic, { drawBoundingBox: true });
22
+ run('Accidental Padding', formatAccidentalSpaces);
23
+ run('Basic', basic, { drawBoundingBox: false });
24
+ run('Stem Down', basicStemDown);
25
+ run('Cautionary Accidental', cautionary);
26
+ run('Accidental Arrangement Special Cases', specialCases);
27
+ run('Multi Voice', multiVoice);
28
+ run('Microtonal', microtonal);
29
+ run('Microtonal (Iranian)', microtonalIranian);
30
+ run('Sagittal', sagittal);
31
+ run('Automatic Accidentals', automaticAccidentals0);
32
+ run('Automatic Accidentals - C major scale in Ab', automaticAccidentals1);
33
+ run('Automatic Accidentals - No Accidentals Necessary', automaticAccidentals2);
34
+ run('Automatic Accidentals - No Accidentals Necessary (EasyScore)', automaticAccidentals3);
35
+ run('Automatic Accidentals - Multi Voice Inline', automaticAccidentalsMultiVoiceInline);
36
+ run('Automatic Accidentals - Multi Voice Offset', automaticAccidentalsMultiVoiceOffset);
37
+ run('Automatic Accidentals - Key C, Single Octave', automaticAccidentalsCornerCases1);
38
+ run('Automatic Accidentals - Key C, Two Octaves', automaticAccidentalsCornerCases2);
39
+ run('Automatic Accidentals - Key C#, Single Octave', automaticAccidentalsCornerCases3);
40
+ run('Automatic Accidentals - Key C#, Two Octaves', automaticAccidentalsCornerCases4);
41
+ run('Factory API', factoryAPI);
42
+ },
43
+ };
44
+ function hasAccidental(note) {
45
+ return note.getModifiers().some((modifier) => isAccidental(modifier));
46
+ }
47
+ function makeNewAccid(factory) {
48
+ return (type) => factory.Accidental({ type });
49
+ }
50
+ function autoAccidentalWorking(assert) {
51
+ const createStaveNote = (noteStruct) => new StaveNote(noteStruct);
52
+ let notes = [
53
+ { keys: ['bb/4'], duration: '4' },
54
+ { keys: ['bb/4'], duration: '4' },
55
+ { keys: ['g#/4'], duration: '4' },
56
+ { keys: ['g/4'], duration: '4' },
57
+ { keys: ['b/4'], duration: '4' },
58
+ { keys: ['b/4'], duration: '4' },
59
+ { keys: ['a#/4'], duration: '4' },
60
+ { keys: ['g#/4'], duration: '4' },
61
+ ].map(createStaveNote);
62
+ let voice = new Voice().setMode(Voice.Mode.SOFT).addTickables(notes);
63
+ Accidental.applyAccidentals([voice], 'F');
64
+ assert.equal(hasAccidental(notes[0]), false, 'No flat because of key signature');
65
+ assert.equal(hasAccidental(notes[1]), false, 'No flat because of key signature');
66
+ assert.equal(hasAccidental(notes[2]), true, 'Added a sharp');
67
+ assert.equal(hasAccidental(notes[3]), true, 'Back to natural');
68
+ assert.equal(hasAccidental(notes[4]), true, 'Back to natural');
69
+ assert.equal(hasAccidental(notes[5]), false, 'Natural remembered');
70
+ assert.equal(hasAccidental(notes[6]), true, 'Added sharp');
71
+ assert.equal(hasAccidental(notes[7]), true, 'Added sharp');
72
+ notes = [
73
+ { keys: ['e#/4'], duration: '4' },
74
+ { keys: ['cb/4'], duration: '4' },
75
+ { keys: ['fb/4'], duration: '4' },
76
+ { keys: ['b#/4'], duration: '4' },
77
+ { keys: ['b#/4'], duration: '4' },
78
+ { keys: ['cb/5'], duration: '4' },
79
+ { keys: ['fb/5'], duration: '4' },
80
+ { keys: ['e#/4'], duration: '4' },
81
+ ].map(createStaveNote);
82
+ voice = new Voice().setMode(Voice.Mode.SOFT).addTickables(notes);
83
+ Accidental.applyAccidentals([voice], 'A');
84
+ assert.equal(hasAccidental(notes[0]), true, 'Added sharp');
85
+ assert.equal(hasAccidental(notes[1]), true, 'Added flat');
86
+ assert.equal(hasAccidental(notes[2]), true, 'Added flat');
87
+ assert.equal(hasAccidental(notes[3]), true, 'Added sharp');
88
+ assert.equal(hasAccidental(notes[4]), false, 'Sharp remembered');
89
+ assert.equal(hasAccidental(notes[5]), true, 'Added flat(different octave)');
90
+ assert.equal(hasAccidental(notes[6]), true, 'Added flat(different octave)');
91
+ assert.equal(hasAccidental(notes[7]), false, 'sharp remembered');
92
+ notes = [
93
+ { keys: ['c/4'], duration: '4' },
94
+ { keys: ['cb/4'], duration: '4' },
95
+ { keys: ['cb/4'], duration: '4' },
96
+ { keys: ['c#/4'], duration: '4' },
97
+ { keys: ['c#/4'], duration: '4' },
98
+ { keys: ['cbb/4'], duration: '4' },
99
+ { keys: ['cbb/4'], duration: '4' },
100
+ { keys: ['c##/4'], duration: '4' },
101
+ { keys: ['c##/4'], duration: '4' },
102
+ { keys: ['c/4'], duration: '4' },
103
+ { keys: ['c/4'], duration: '4' },
104
+ ].map(createStaveNote);
105
+ voice = new Voice().setMode(Voice.Mode.SOFT).addTickables(notes);
106
+ Accidental.applyAccidentals([voice], 'C');
107
+ assert.equal(hasAccidental(notes[0]), false, 'No accidental');
108
+ assert.equal(hasAccidental(notes[1]), true, 'Added flat');
109
+ assert.equal(hasAccidental(notes[2]), false, 'Flat remembered');
110
+ assert.equal(hasAccidental(notes[3]), true, 'Sharp added');
111
+ assert.equal(hasAccidental(notes[4]), false, 'Sharp remembered');
112
+ assert.equal(hasAccidental(notes[5]), true, 'Added doubled flat');
113
+ assert.equal(hasAccidental(notes[6]), false, 'Double flat remembered');
114
+ assert.equal(hasAccidental(notes[7]), true, 'Added double sharp');
115
+ assert.equal(hasAccidental(notes[8]), false, 'Double sharp rememberd');
116
+ assert.equal(hasAccidental(notes[9]), true, 'Added natural');
117
+ assert.equal(hasAccidental(notes[10]), false, 'Natural remembered');
118
+ }
119
+ function formatAccidentalSpaces(options) {
120
+ const f = VexFlowTests.makeFactory(options, 750, 280);
121
+ const context = f.getContext();
122
+ const softmaxFactor = 100;
123
+ const notes = [
124
+ new StaveNote({
125
+ keys: ['e##/5'],
126
+ duration: '8d',
127
+ }).addModifier(new Accidental('##'), 0),
128
+ new StaveNote({
129
+ keys: ['Bb/4', 'Bn/4'],
130
+ duration: '16',
131
+ })
132
+ .addModifier(new Accidental('b'), 0)
133
+ .addModifier(new Accidental('n'), 0),
134
+ new StaveNote({
135
+ keys: ['f/3'],
136
+ duration: '8',
137
+ }),
138
+ new StaveNote({
139
+ keys: ['a/3'],
140
+ duration: '16',
141
+ }),
142
+ new StaveNote({
143
+ keys: ['e/4', 'g/4'],
144
+ duration: '16',
145
+ })
146
+ .addModifier(new Accidental('bb'), 0)
147
+ .addModifier(new Accidental('bb'), 1),
148
+ new StaveNote({
149
+ keys: ['d/4'],
150
+ duration: '16',
151
+ }),
152
+ new StaveNote({
153
+ keys: ['e/4', 'g/4'],
154
+ duration: '16',
155
+ })
156
+ .addModifier(new Accidental('#'), 0)
157
+ .addModifier(new Accidental('#'), 1),
158
+ new StaveNote({
159
+ keys: ['g/4'],
160
+ duration: '32',
161
+ }),
162
+ new StaveNote({
163
+ keys: ['a/4'],
164
+ duration: '32',
165
+ }),
166
+ new StaveNote({
167
+ keys: ['g/4'],
168
+ duration: '16',
169
+ }),
170
+ new StaveNote({
171
+ keys: ['Db/4', 'Dn/4'],
172
+ duration: 'q',
173
+ })
174
+ .addModifier(new Accidental('b'), 0)
175
+ .addModifier(new Accidental('n'), 0),
176
+ ];
177
+ Dot.buildAndAttach([notes[0]], { all: true });
178
+ const beams = Beam.generateBeams(notes);
179
+ const voice = new Voice({
180
+ numBeats: 4,
181
+ beatValue: 4,
182
+ });
183
+ voice.addTickables(notes);
184
+ const formatter = new Formatter({ softmaxFactor }).joinVoices([voice]);
185
+ const width = formatter.preCalculateMinTotalWidth([voice]);
186
+ const stave = new Stave(10, 40, width + 20);
187
+ stave.setContext(context).drawWithStyle();
188
+ formatter.format([voice], width);
189
+ voice.draw(context, stave);
190
+ beams.forEach((b) => b.setContext(context).drawWithStyle());
191
+ notes.forEach((note) => Note.plotMetrics(context, note, 30));
192
+ VexFlowTests.plotLegendForNoteWidth(context, 300, 150);
193
+ options.assert.ok(true);
194
+ }
195
+ function basic(options) {
196
+ const f = VexFlowTests.makeFactory(options, 700, 240);
197
+ const accid = makeNewAccid(f);
198
+ f.Stave({ x: 10, y: 10, width: 550 });
199
+ const notes = [
200
+ f
201
+ .StaveNote({ keys: ['c/4', 'e/4', 'a/4'], duration: '1' })
202
+ .addModifier(accid('b'), 0)
203
+ .addModifier(accid('#'), 1),
204
+ f
205
+ .StaveNote({ keys: ['e/4', 'f/4', 'a/4', 'c/5', 'e/5', 'g/5', 'd/4'], duration: '2' })
206
+ .addModifier(accid('##'), 6)
207
+ .addModifier(accid('n'), 0)
208
+ .addModifier(accid('bb'), 1)
209
+ .addModifier(accid('b'), 2)
210
+ .addModifier(accid('#'), 3)
211
+ .addModifier(accid('n'), 4)
212
+ .addModifier(accid('bb'), 5),
213
+ f
214
+ .StaveNote({ keys: ['g/5', 'f/4', 'g/4', 'a/4', 'b/4', 'c/5', 'e/5'], duration: '16' })
215
+ .addModifier(accid('n'), 1)
216
+ .addModifier(accid('#'), 2)
217
+ .addModifier(accid('#'), 3)
218
+ .addModifier(accid('b'), 4)
219
+ .addModifier(accid('bb'), 5)
220
+ .addModifier(accid('##'), 6)
221
+ .addModifier(accid('#'), 0),
222
+ f
223
+ .StaveNote({ keys: ['a/3', 'c/4', 'e/4', 'b/4', 'd/5', 'g/5'], duration: '1' })
224
+ .addModifier(accid('#'), 0)
225
+ .addModifier(accid('##').setAsCautionary(), 1)
226
+ .addModifier(accid('#').setAsCautionary(), 2)
227
+ .addModifier(accid('b'), 3)
228
+ .addModifier(accid('bb').setAsCautionary(), 4)
229
+ .addModifier(accid('b').setAsCautionary(), 5),
230
+ ];
231
+ Formatter.SimpleFormat(notes, 10, { paddingBetween: 45 });
232
+ notes.forEach((note, index) => {
233
+ Note.plotMetrics(f.getContext(), note, 140);
234
+ options.assert.ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
235
+ note.getModifiersByType('Accidental').forEach((accid, index) => {
236
+ options.assert.ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
237
+ });
238
+ });
239
+ f.draw();
240
+ if (options.params.drawBoundingBox === true) {
241
+ notes.forEach((note) => {
242
+ const elements = note.getModifiersByType('Accidental');
243
+ elements.forEach((element) => VexFlowTests.drawBoundingBox(f.getContext(), element));
244
+ });
245
+ }
246
+ VexFlowTests.plotLegendForNoteWidth(f.getContext(), 480, 140);
247
+ options.assert.ok(true, 'Full Accidental');
248
+ }
249
+ function genAccidentals() {
250
+ const accs = ['#', '##', 'b', 'bb', 'n', '{', '}', 'db', 'd', '++', '+', '+-'];
251
+ accs.push('bs', 'bss', 'o', 'k', 'bbs', '++-', 'ashs', 'afhf');
252
+ for (let u = 0xe260; u <= 0xe269; u++) {
253
+ accs.push(String.fromCodePoint(u));
254
+ }
255
+ for (let u = 0xe270; u <= 0xe27b; u++) {
256
+ accs.push(String.fromCodePoint(u));
257
+ }
258
+ for (let u = 0xe280; u <= 0xe285; u++) {
259
+ accs.push(String.fromCodePoint(u));
260
+ }
261
+ for (let u = 0xe290; u <= 0xe29c; u++) {
262
+ accs.push(String.fromCodePoint(u));
263
+ }
264
+ for (let u = 0xe2a0; u <= 0xe2a5; u++) {
265
+ accs.push(String.fromCodePoint(u));
266
+ }
267
+ for (let u = 0xe2b0; u <= 0xe2b7; u++) {
268
+ accs.push(String.fromCodePoint(u));
269
+ }
270
+ for (let u = 0xe2c0; u <= 0xe2fb; u++) {
271
+ accs.push(String.fromCodePoint(u));
272
+ }
273
+ for (let u = 0xe300; u <= 0xe30f; u++) {
274
+ accs.push(String.fromCodePoint(u));
275
+ }
276
+ for (let u = 0xe310; u <= 0xe335; u++) {
277
+ switch (u) {
278
+ case 0xe31a:
279
+ case 0xe31b:
280
+ case 0xe31e:
281
+ case 0xe31f:
282
+ break;
283
+ default:
284
+ accs.push(String.fromCodePoint(u));
285
+ }
286
+ }
287
+ for (let u = 0xe340; u <= 0xe367; u++) {
288
+ accs.push(String.fromCodePoint(u));
289
+ }
290
+ for (let u = 0xe370; u <= 0xe387; u++) {
291
+ accs.push(String.fromCodePoint(u));
292
+ }
293
+ for (let u = 0xe390; u <= 0xe3ad; u++) {
294
+ accs.push(String.fromCodePoint(u));
295
+ }
296
+ for (let u = 0xe3b0; u <= 0xe3ef; u++) {
297
+ accs.push(String.fromCodePoint(u));
298
+ }
299
+ for (let u = 0xe3f0; u <= 0xe3f3; u++) {
300
+ accs.push(String.fromCodePoint(u));
301
+ }
302
+ for (let u = 0xe3f4; u <= 0xe3f7; u++) {
303
+ accs.push(String.fromCodePoint(u));
304
+ }
305
+ for (let u = 0xe420; u <= 0xe435; u++) {
306
+ accs.push(String.fromCodePoint(u));
307
+ }
308
+ for (let u = 0xe440; u <= 0xe447; u++) {
309
+ accs.push(String.fromCodePoint(u));
310
+ }
311
+ for (let u = 0xe450; u <= 0xe457; u++) {
312
+ accs.push(String.fromCodePoint(u));
313
+ }
314
+ for (let u = 0xe460; u <= 0xe461; u++) {
315
+ accs.push(String.fromCodePoint(u));
316
+ }
317
+ for (let u = 0xe470; u <= 0xe48f; u++) {
318
+ accs.push(String.fromCodePoint(u));
319
+ }
320
+ return accs;
321
+ }
322
+ const accidentals = genAccidentals();
323
+ function cautionary(options) {
324
+ const staveCount = 20;
325
+ const notesPerStave = 22;
326
+ const scale = 0.85;
327
+ const staveWidth = 900;
328
+ const staveHeight = 75;
329
+ let i = 0;
330
+ let j = 0;
331
+ const f = VexFlowTests.makeFactory(options, staveWidth + 10, staveHeight * staveCount + 10);
332
+ f.getContext().scale(scale, scale);
333
+ const accids = Object.values(accidentals).filter((accid) => accid !== '{' && accid !== '}');
334
+ for (i = 0; i < staveCount; ++i) {
335
+ const stave = f.Stave({ x: 0, y: 10 + (staveHeight / scale) * i, width: staveWidth / scale });
336
+ const score = f.EasyScore();
337
+ const rowMap = [];
338
+ for (j = 0; j < notesPerStave && j + i * notesPerStave < accids.length; ++j) {
339
+ rowMap.push(accids[j + i * notesPerStave]);
340
+ }
341
+ const notes = rowMap.map((accidType) => f
342
+ .StaveNote({ keys: ['a/4'], duration: '4', stemDirection: Stem.UP })
343
+ .addModifier(f.Accidental({ type: accidType }), 0));
344
+ const voice = score.voice(notes, { time: rowMap.length + '/4' });
345
+ voice.getTickables().forEach((tickable) => {
346
+ tickable
347
+ .getModifiers()
348
+ .filter((modifier) => modifier.getAttribute('type') === Accidental.CATEGORY)
349
+ .forEach((accid) => accid.setAsCautionary());
350
+ });
351
+ f.Formatter().joinVoices([voice]).formatToStave([voice], stave);
352
+ f.draw();
353
+ }
354
+ options.assert.ok(true, 'Must successfully render cautionary accidentals');
355
+ }
356
+ function specialCases(options) {
357
+ const f = VexFlowTests.makeFactory(options, 700, 240);
358
+ const accid = makeNewAccid(f);
359
+ f.Stave({ x: 10, y: 10, width: 550 });
360
+ const notes = [
361
+ f
362
+ .StaveNote({ keys: ['f/4', 'd/5'], duration: '1' })
363
+ .addModifier(accid('#'), 0)
364
+ .addModifier(accid('b'), 1),
365
+ f
366
+ .StaveNote({ keys: ['c/4', 'g/4'], duration: '2' })
367
+ .addModifier(accid('##'), 0)
368
+ .addModifier(accid('##'), 1),
369
+ f
370
+ .StaveNote({ keys: ['b/3', 'd/4', 'f/4'], duration: '16' })
371
+ .addModifier(accid('#'), 0)
372
+ .addModifier(accid('#'), 1)
373
+ .addModifier(accid('##'), 2),
374
+ f
375
+ .StaveNote({ keys: ['g/4', 'a/4', 'c/5', 'e/5'], duration: '16' })
376
+ .addModifier(accid('b'), 0)
377
+ .addModifier(accid('b'), 1)
378
+ .addModifier(accid('n'), 3),
379
+ f
380
+ .StaveNote({ keys: ['e/4', 'g/4', 'b/4', 'c/5'], duration: '4' })
381
+ .addModifier(accid('b').setAsCautionary(), 0)
382
+ .addModifier(accid('b').setAsCautionary(), 1)
383
+ .addModifier(accid('bb'), 2)
384
+ .addModifier(accid('b'), 3),
385
+ f
386
+ .StaveNote({ keys: ['b/3', 'e/4', 'a/4', 'd/5', 'g/5'], duration: '8' })
387
+ .addModifier(accid('bb'), 0)
388
+ .addModifier(accid('b').setAsCautionary(), 1)
389
+ .addModifier(accid('n').setAsCautionary(), 2)
390
+ .addModifier(accid('#'), 3)
391
+ .addModifier(accid('n').setAsCautionary(), 4),
392
+ ];
393
+ Formatter.SimpleFormat(notes, 0, { paddingBetween: 20 });
394
+ notes.forEach((note, index) => {
395
+ Note.plotMetrics(f.getContext(), note, 140);
396
+ options.assert.ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
397
+ note.getModifiersByType('Accidental').forEach((accid, index) => {
398
+ options.assert.ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
399
+ });
400
+ });
401
+ f.draw();
402
+ VexFlowTests.plotLegendForNoteWidth(f.getContext(), 480, 140);
403
+ options.assert.ok(true, 'Full Accidental');
404
+ }
405
+ function basicStemDown(options) {
406
+ const f = VexFlowTests.makeFactory(options, 700, 240);
407
+ const accid = makeNewAccid(f);
408
+ f.Stave({ x: 10, y: 10, width: 550 });
409
+ const notes = [
410
+ f
411
+ .StaveNote({ keys: ['c/4', 'e/4', 'a/4'], duration: 'w', stemDirection: -1 })
412
+ .addModifier(accid('b'), 0)
413
+ .addModifier(accid('#'), 1),
414
+ f
415
+ .StaveNote({ keys: ['d/4', 'e/4', 'f/4', 'a/4', 'c/5', 'e/5', 'g/5'], duration: '2', stemDirection: -1 })
416
+ .addModifier(accid('##'), 0)
417
+ .addModifier(accid('n'), 1)
418
+ .addModifier(accid('bb'), 2)
419
+ .addModifier(accid('b'), 3)
420
+ .addModifier(accid('#'), 4)
421
+ .addModifier(accid('n'), 5)
422
+ .addModifier(accid('bb'), 6),
423
+ f
424
+ .StaveNote({ keys: ['f/4', 'g/4', 'a/4', 'b/4', 'c/5', 'e/5', 'g/5'], duration: '16', stemDirection: -1 })
425
+ .addModifier(accid('n'), 0)
426
+ .addModifier(accid('#'), 1)
427
+ .addModifier(accid('#'), 2)
428
+ .addModifier(accid('b'), 3)
429
+ .addModifier(accid('bb'), 4)
430
+ .addModifier(accid('##'), 5)
431
+ .addModifier(accid('#'), 6),
432
+ ];
433
+ Formatter.SimpleFormat(notes, 0, { paddingBetween: 30 });
434
+ notes.forEach((note, noteIndex) => {
435
+ Note.plotMetrics(f.getContext(), note, 140);
436
+ options.assert.ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + noteIndex + ' has accidentals');
437
+ note.getModifiersByType('Accidental').forEach((accid, accidIndex) => {
438
+ options.assert.ok(accid.getWidth() > 0, 'Accidental ' + accidIndex + ' has set width');
439
+ });
440
+ });
441
+ f.draw();
442
+ VexFlowTests.plotLegendForNoteWidth(f.getContext(), 480, 140);
443
+ options.assert.ok(true, 'Full Accidental');
444
+ }
445
+ function multiVoice(options) {
446
+ function showNotes(note1, note2, stave, ctx, x) {
447
+ const modifierContext = new ModifierContext();
448
+ note1.addToModifierContext(modifierContext);
449
+ note2.addToModifierContext(modifierContext);
450
+ new TickContext().addTickable(note1).addTickable(note2).preFormat().setX(x);
451
+ note1.setContext(ctx).drawWithStyle();
452
+ note2.setContext(ctx).drawWithStyle();
453
+ Note.plotMetrics(ctx, note1, 180);
454
+ Note.plotMetrics(ctx, note2, 15);
455
+ }
456
+ const f = VexFlowTests.makeFactory(options, 460, 250);
457
+ const accid = makeNewAccid(f);
458
+ const stave = f.Stave({ x: 10, y: 45, width: 420 });
459
+ const ctx = f.getContext();
460
+ stave.drawWithStyle();
461
+ let note1 = f
462
+ .StaveNote({ keys: ['c/4', 'e/4', 'a/4'], duration: '2', stemDirection: -1 })
463
+ .addModifier(accid('b'), 0)
464
+ .addModifier(accid('n'), 1)
465
+ .addModifier(accid('#'), 2)
466
+ .setStave(stave);
467
+ let note2 = f
468
+ .StaveNote({ keys: ['d/5', 'a/5', 'b/5'], duration: '2', stemDirection: 1 })
469
+ .addModifier(accid('b'), 0)
470
+ .addModifier(accid('bb'), 1)
471
+ .addModifier(accid('##'), 2)
472
+ .setStave(stave);
473
+ showNotes(note1, note2, stave, ctx, 60);
474
+ note1 = f
475
+ .StaveNote({ keys: ['c/4', 'e/4', 'c/5'], duration: '2', stemDirection: -1 })
476
+ .addModifier(accid('b'), 0)
477
+ .addModifier(accid('n'), 1)
478
+ .addModifier(accid('#'), 2)
479
+ .setStave(stave);
480
+ note2 = f
481
+ .StaveNote({ keys: ['d/5', 'a/5', 'b/5'], duration: '4', stemDirection: 1 })
482
+ .addModifier(accid('b'), 0)
483
+ .setStave(stave);
484
+ showNotes(note1, note2, stave, ctx, 150);
485
+ note1 = f
486
+ .StaveNote({ keys: ['d/4', 'c/5', 'd/5'], duration: '2', stemDirection: -1 })
487
+ .addModifier(accid('b'), 0)
488
+ .addModifier(accid('n'), 1)
489
+ .addModifier(accid('#'), 2)
490
+ .setStave(stave);
491
+ note2 = f
492
+ .StaveNote({ keys: ['d/5', 'a/5', 'b/5'], duration: '4', stemDirection: 1 })
493
+ .addModifier(accid('b'), 0)
494
+ .setStave(stave);
495
+ showNotes(note1, note2, stave, ctx, 250);
496
+ VexFlowTests.plotLegendForNoteWidth(ctx, 350, 150);
497
+ options.assert.ok(true, 'Full Accidental');
498
+ }
499
+ function microtonal(options) {
500
+ const f = VexFlowTests.makeFactory(options, 700, 240);
501
+ const accid = makeNewAccid(f);
502
+ const ctx = f.getContext();
503
+ f.Stave({ x: 10, y: 10, width: 650 });
504
+ const notes = [
505
+ f
506
+ .StaveNote({ keys: ['c/4', 'e/4', 'a/4'], duration: '1' })
507
+ .addModifier(accid('db'), 0)
508
+ .addModifier(accid('d'), 1),
509
+ f
510
+ .StaveNote({ keys: ['d/4', 'e/4', 'f/4', 'a/4', 'c/5', 'e/5', 'g/5'], duration: '2' })
511
+ .addModifier(accid('bbs'), 0)
512
+ .addModifier(accid('++'), 1)
513
+ .addModifier(accid('+'), 2)
514
+ .addModifier(accid('d'), 3)
515
+ .addModifier(accid('db'), 4)
516
+ .addModifier(accid('+'), 5)
517
+ .addModifier(accid('##'), 6),
518
+ f
519
+ .StaveNote({ keys: ['f/4', 'g/4', 'a/4', 'b/4', 'c/5', 'e/5', 'g/5'], duration: '16' })
520
+ .addModifier(accid('++'), 0)
521
+ .addModifier(accid('bbs'), 1)
522
+ .addModifier(accid('+'), 2)
523
+ .addModifier(accid('b'), 3)
524
+ .addModifier(accid('db'), 4)
525
+ .addModifier(accid('##'), 5)
526
+ .addModifier(accid('#'), 6),
527
+ f
528
+ .StaveNote({ keys: ['a/3', 'c/4', 'e/4', 'b/4', 'd/5', 'g/5'], duration: '1' })
529
+ .addModifier(accid('#'), 0)
530
+ .addModifier(accid('db').setAsCautionary(), 1)
531
+ .addModifier(accid('bbs').setAsCautionary(), 2)
532
+ .addModifier(accid('b'), 3)
533
+ .addModifier(accid('++').setAsCautionary(), 4)
534
+ .addModifier(accid('d').setAsCautionary(), 5),
535
+ f
536
+ .StaveNote({ keys: ['f/4', 'g/4', 'a/4', 'b/4', 'd/5', 'g/5'], duration: '16' })
537
+ .addModifier(accid('++-'), 0)
538
+ .addModifier(accid('+-'), 1)
539
+ .addModifier(accid('bs'), 2)
540
+ .addModifier(accid('bss'), 3)
541
+ .addModifier(accid('afhf'), 4)
542
+ .addModifier(accid('ashs'), 5),
543
+ ];
544
+ Formatter.SimpleFormat(notes, 0, { paddingBetween: 35 });
545
+ notes.forEach((note, index) => {
546
+ Note.plotMetrics(f.getContext(), note, 140);
547
+ options.assert.ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
548
+ note.getModifiersByType('Accidental').forEach((accid, index) => {
549
+ options.assert.ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
550
+ });
551
+ });
552
+ f.draw();
553
+ VexFlowTests.plotLegendForNoteWidth(ctx, 580, 140);
554
+ options.assert.ok(true, 'Microtonal Accidental');
555
+ }
556
+ function microtonalIranian(options) {
557
+ const f = VexFlowTests.makeFactory(options, 700, 240);
558
+ const accid = makeNewAccid(f);
559
+ const ctx = f.getContext();
560
+ f.Stave({ x: 10, y: 10, width: 650 });
561
+ const notes = [
562
+ f
563
+ .StaveNote({ keys: ['c/4', 'e/4', 'a/4'], duration: '1' })
564
+ .addModifier(accid('k'), 0)
565
+ .addModifier(accid('o'), 1),
566
+ f
567
+ .StaveNote({ keys: ['d/4', 'e/4', 'f/4', 'a/4', 'c/5', 'e/5', 'g/5'], duration: '2' })
568
+ .addModifier(accid('b'), 0)
569
+ .addModifier(accid('k'), 1)
570
+ .addModifier(accid('n'), 2)
571
+ .addModifier(accid('o'), 3)
572
+ .addModifier(accid('#'), 4)
573
+ .addModifier(accid('bb'), 5)
574
+ .addModifier(accid('##'), 6),
575
+ f
576
+ .StaveNote({ keys: ['f/4', 'g/4', 'a/4', 'b/4', 'c/5', 'e/5', 'g/5'], duration: '16' })
577
+ .addModifier(accid('o'), 0)
578
+ .addModifier(accid('k'), 1)
579
+ .addModifier(accid('n'), 2)
580
+ .addModifier(accid('b'), 3)
581
+ .addModifier(accid('bb'), 4)
582
+ .addModifier(accid('##'), 5)
583
+ .addModifier(accid('#'), 6),
584
+ f
585
+ .StaveNote({ keys: ['a/3', 'c/4', 'e/4', 'b/4', 'd/5', 'g/5'], duration: '1' })
586
+ .addModifier(accid('#'), 0)
587
+ .addModifier(accid('o').setAsCautionary(), 1)
588
+ .addModifier(accid('n').setAsCautionary(), 2)
589
+ .addModifier(accid('b'), 3)
590
+ .addModifier(accid('k').setAsCautionary(), 4),
591
+ f
592
+ .StaveNote({ keys: ['f/4', 'g/4', 'a/4', 'b/4'], duration: '16' })
593
+ .addModifier(accid('k'), 0)
594
+ .addModifier(accid('k'), 1)
595
+ .addModifier(accid('k'), 2)
596
+ .addModifier(accid('k'), 3),
597
+ ];
598
+ Formatter.SimpleFormat(notes, 0, { paddingBetween: 35 });
599
+ notes.forEach((note, index) => {
600
+ Note.plotMetrics(f.getContext(), note, 140);
601
+ options.assert.ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
602
+ note.getModifiersByType('Accidental').forEach((accid, index) => {
603
+ options.assert.ok(accid.getWidth() > 0, 'Accidental ' + index + ' has set width');
604
+ });
605
+ });
606
+ f.draw();
607
+ VexFlowTests.plotLegendForNoteWidth(ctx, 580, 140);
608
+ options.assert.ok(true, 'Microtonal Accidental (Iranian)');
609
+ }
610
+ function sagittal(options) {
611
+ const f = VexFlowTests.makeFactory(options, 700, 240);
612
+ const accid = makeNewAccid(f);
613
+ const ctx = f.getContext();
614
+ f.Stave({ x: 10, y: 10, width: 650 });
615
+ const { accSagittal11LargeDiesisDown, accSagittal11MediumDiesisUp, accSagittal35LargeDiesisDown, accSagittal5CommaDown, accSagittal7CommaDown, accSagittalFlat7CDown, } = Glyphs;
616
+ const notes = [
617
+ f
618
+ .StaveNote({ keys: ['d/4', 'f/4', 'b/4', 'b/4'], duration: '4' })
619
+ .addModifier(accid(accSagittal11MediumDiesisUp), 1)
620
+ .addModifier(accid(accSagittal5CommaDown), 2)
621
+ .addModifier(accid('b'), 3)
622
+ .addModifier(accid(accSagittal7CommaDown), 3),
623
+ f
624
+ .StaveNote({ keys: ['d/4', 'f/4', 'a/4', 'b/4'], duration: '4' })
625
+ .addModifier(accid(accSagittal35LargeDiesisDown), 2),
626
+ f.StaveNote({ keys: ['c/4', 'e/4', 'g/4', 'c/5'], duration: '8' }).addModifier(accid(accSagittal5CommaDown), 1),
627
+ f
628
+ .StaveNote({ keys: ['c/4', 'e/4', 'g/4', 'b/4'], duration: '8' })
629
+ .addModifier(accid('b'), 1)
630
+ .addModifier(accid(accSagittal7CommaDown), 1)
631
+ .addModifier(accid(accSagittal11LargeDiesisDown), 3),
632
+ f
633
+ .StaveNote({ keys: ['d/4', 'f/4', 'b/4', 'b/4'], duration: '4' })
634
+ .addModifier(accid(accSagittal11MediumDiesisUp), 1)
635
+ .addModifier(accid(accSagittal5CommaDown), 2)
636
+ .addModifier(accid(accSagittalFlat7CDown), 3),
637
+ f
638
+ .StaveNote({ keys: ['d/4', 'f/4', 'a/4', 'b/4'], duration: '4' })
639
+ .addModifier(accid(accSagittal35LargeDiesisDown), 2),
640
+ f.StaveNote({ keys: ['c/4', 'e/4', 'g/4', 'c/5'], duration: '8' }).addModifier(accid(accSagittal5CommaDown), 1),
641
+ f
642
+ .StaveNote({ keys: ['c/4', 'e/4', 'g/4', 'b/4'], duration: '8' })
643
+ .addModifier(accid(accSagittalFlat7CDown), 1)
644
+ .addModifier(accid(accSagittal11LargeDiesisDown), 3),
645
+ ];
646
+ f.StaveTie({
647
+ from: notes[0],
648
+ to: notes[1],
649
+ firstIndexes: [0, 1],
650
+ lastIndexes: [0, 1],
651
+ });
652
+ f.StaveTie({
653
+ from: notes[0],
654
+ to: notes[1],
655
+ firstIndexes: [3],
656
+ lastIndexes: [3],
657
+ options: {
658
+ direction: Stem.DOWN,
659
+ },
660
+ });
661
+ f.StaveTie({
662
+ from: notes[4],
663
+ to: notes[5],
664
+ firstIndexes: [0, 1],
665
+ lastIndexes: [0, 1],
666
+ });
667
+ f.StaveTie({
668
+ from: notes[4],
669
+ to: notes[5],
670
+ firstIndexes: [3],
671
+ lastIndexes: [3],
672
+ options: {
673
+ direction: Stem.DOWN,
674
+ },
675
+ });
676
+ f.Beam({ notes: notes.slice(2, 4) });
677
+ f.Beam({ notes: notes.slice(6, 8) });
678
+ Formatter.SimpleFormat(notes);
679
+ notes.forEach((note, index) => {
680
+ Note.plotMetrics(f.getContext(), note, 140);
681
+ options.assert.ok(note.getModifiersByType('Accidental').length > 0, 'Note ' + index + ' has accidentals');
682
+ });
683
+ f.draw();
684
+ VexFlowTests.plotLegendForNoteWidth(ctx, 580, 140);
685
+ options.assert.ok(true, 'Sagittal');
686
+ }
687
+ function automaticAccidentals0(options) {
688
+ const f = VexFlowTests.makeFactory(options, 700, 200);
689
+ const stave = f.Stave();
690
+ const notes = [
691
+ { keys: ['c/4', 'c/5'], duration: '4' },
692
+ { keys: ['c#/4', 'c#/5'], duration: '4' },
693
+ { keys: ['c#/4', 'c#/5'], duration: '4' },
694
+ { keys: ['c##/4', 'c##/5'], duration: '4' },
695
+ { keys: ['c##/4', 'c##/5'], duration: '4' },
696
+ { keys: ['c/4', 'c/5'], duration: '4' },
697
+ { keys: ['cn/4', 'cn/5'], duration: '4' },
698
+ { keys: ['cbb/4', 'cbb/5'], duration: '4' },
699
+ { keys: ['cbb/4', 'cbb/5'], duration: '4' },
700
+ { keys: ['cb/4', 'cb/5'], duration: '4' },
701
+ { keys: ['cb/4', 'cb/5'], duration: '4' },
702
+ { keys: ['c/4', 'c/5'], duration: '4' },
703
+ ].map(f.StaveNote.bind(f));
704
+ const gracenotes = [{ keys: ['d#/4'], duration: '16', slash: true }].map(f.GraceNote.bind(f));
705
+ notes[0].addModifier(f.GraceNoteGroup({ notes: gracenotes }).beamNotes(), 0);
706
+ const voice = f
707
+ .Voice()
708
+ .setMode(Voice.Mode.SOFT)
709
+ .addTickable(new TimeSigNote('12/4').setStave(stave))
710
+ .addTickables(notes);
711
+ Accidental.applyAccidentals([voice], 'C');
712
+ new Formatter().joinVoices([voice]).formatToStave([voice], stave);
713
+ f.draw();
714
+ options.assert.ok(true);
715
+ }
716
+ function automaticAccidentals1(options) {
717
+ const f = VexFlowTests.makeFactory(options, 700, 150);
718
+ const stave = f.Stave().addKeySignature('Ab');
719
+ const notes = [
720
+ { keys: ['c/4'], duration: '4' },
721
+ { keys: ['d/4'], duration: '4' },
722
+ { keys: ['e/4'], duration: '4' },
723
+ { keys: ['f/4'], duration: '4' },
724
+ { keys: ['g/4'], duration: '4' },
725
+ { keys: ['a/4'], duration: '4' },
726
+ { keys: ['b/4'], duration: '4' },
727
+ { keys: ['c/5'], duration: '4' },
728
+ ].map(f.StaveNote.bind(f));
729
+ const voice = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes);
730
+ Accidental.applyAccidentals([voice], 'Ab');
731
+ new Formatter().joinVoices([voice]).formatToStave([voice], stave);
732
+ f.draw();
733
+ options.assert.ok(true);
734
+ }
735
+ function automaticAccidentals2(options) {
736
+ const f = VexFlowTests.makeFactory(options, 700, 150);
737
+ const stave = f.Stave().addKeySignature('A');
738
+ const notes = [
739
+ { keys: ['a/4'], duration: '4' },
740
+ { keys: ['b/4'], duration: '4' },
741
+ { keys: ['c#/5'], duration: '4' },
742
+ { keys: ['d/5'], duration: '4' },
743
+ { keys: ['e/5'], duration: '4' },
744
+ { keys: ['f#/5'], duration: '4' },
745
+ { keys: ['g#/5'], duration: '4' },
746
+ { keys: ['a/5'], duration: '4' },
747
+ ].map(f.StaveNote.bind(f));
748
+ const voice = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes);
749
+ Accidental.applyAccidentals([voice], 'A');
750
+ new Formatter().joinVoices([voice]).formatToStave([voice], stave);
751
+ f.draw();
752
+ options.assert.ok(true);
753
+ }
754
+ function automaticAccidentals3(options) {
755
+ const f = VexFlowTests.makeFactory(options, 700, 150);
756
+ const stave = f.Stave().addKeySignature('A');
757
+ const score = f.EasyScore();
758
+ score.set({ time: '8/4' });
759
+ const notes = score.notes('A4/q, B4/q, C#5/q, D5/q, E5/q,F#5/q, G#5/q, A5/q', { stem: 'UP' });
760
+ const voice = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes);
761
+ Accidental.applyAccidentals([voice], 'A');
762
+ new Formatter().joinVoices([voice]).formatToStave([voice], stave);
763
+ f.draw();
764
+ options.assert.ok(true);
765
+ }
766
+ function automaticAccidentalsMultiVoiceInline(options) {
767
+ const f = VexFlowTests.makeFactory(options, 700, 150);
768
+ const stave = f.Stave().addKeySignature('Ab');
769
+ const notes0 = [
770
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
771
+ { keys: ['d/4'], duration: '4', stemDirection: -1 },
772
+ { keys: ['e/4'], duration: '4', stemDirection: -1 },
773
+ { keys: ['f/4'], duration: '4', stemDirection: -1 },
774
+ { keys: ['g/4'], duration: '4', stemDirection: -1 },
775
+ { keys: ['a/4'], duration: '4', stemDirection: -1 },
776
+ { keys: ['b/4'], duration: '4', stemDirection: -1 },
777
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
778
+ ].map(f.StaveNote.bind(f));
779
+ const notes1 = [
780
+ { keys: ['c/5'], duration: '4' },
781
+ { keys: ['d/5'], duration: '4' },
782
+ { keys: ['e/5'], duration: '4' },
783
+ { keys: ['f/5'], duration: '4' },
784
+ { keys: ['g/5'], duration: '4' },
785
+ { keys: ['a/5'], duration: '4' },
786
+ { keys: ['b/5'], duration: '4' },
787
+ { keys: ['c/6'], duration: '4' },
788
+ ].map(f.StaveNote.bind(f));
789
+ const voice0 = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes0);
790
+ const voice1 = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes1);
791
+ Accidental.applyAccidentals([voice0, voice1], 'Ab');
792
+ options.assert.equal(hasAccidental(notes0[0]), false);
793
+ options.assert.equal(hasAccidental(notes0[1]), true);
794
+ options.assert.equal(hasAccidental(notes0[2]), true);
795
+ options.assert.equal(hasAccidental(notes0[3]), false);
796
+ options.assert.equal(hasAccidental(notes0[4]), false);
797
+ options.assert.equal(hasAccidental(notes0[5]), true);
798
+ options.assert.equal(hasAccidental(notes0[6]), true);
799
+ options.assert.equal(hasAccidental(notes0[7]), false);
800
+ options.assert.equal(hasAccidental(notes1[0]), false);
801
+ options.assert.equal(hasAccidental(notes1[1]), true);
802
+ options.assert.equal(hasAccidental(notes1[2]), true);
803
+ options.assert.equal(hasAccidental(notes1[3]), false);
804
+ options.assert.equal(hasAccidental(notes1[4]), false);
805
+ options.assert.equal(hasAccidental(notes1[5]), true);
806
+ options.assert.equal(hasAccidental(notes1[6]), true);
807
+ options.assert.equal(hasAccidental(notes1[7]), false);
808
+ new Formatter().joinVoices([voice0, voice1]).formatToStave([voice0, voice1], stave);
809
+ f.draw();
810
+ options.assert.ok(true);
811
+ }
812
+ function automaticAccidentalsMultiVoiceOffset(options) {
813
+ const f = VexFlowTests.makeFactory(options, 700, 150);
814
+ const stave = f.Stave().addKeySignature('Cb');
815
+ const notes0 = [
816
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
817
+ { keys: ['d/4'], duration: '4', stemDirection: -1 },
818
+ { keys: ['e/4'], duration: '4', stemDirection: -1 },
819
+ { keys: ['f/4'], duration: '4', stemDirection: -1 },
820
+ { keys: ['g/4'], duration: '4', stemDirection: -1 },
821
+ { keys: ['a/4'], duration: '4', stemDirection: -1 },
822
+ { keys: ['b/4'], duration: '4', stemDirection: -1 },
823
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
824
+ ].map(f.StaveNote.bind(f));
825
+ const notes1 = [
826
+ { keys: ['c/5'], duration: '8' },
827
+ { keys: ['c/5'], duration: '4' },
828
+ { keys: ['d/5'], duration: '4' },
829
+ { keys: ['e/5'], duration: '4' },
830
+ { keys: ['f/5'], duration: '4' },
831
+ { keys: ['g/5'], duration: '4' },
832
+ { keys: ['a/5'], duration: '4' },
833
+ { keys: ['b/5'], duration: '4' },
834
+ { keys: ['c/6'], duration: '4' },
835
+ ].map(f.StaveNote.bind(f));
836
+ const voice0 = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes0);
837
+ const voice1 = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes1);
838
+ Accidental.applyAccidentals([voice0, voice1], 'Cb');
839
+ options.assert.equal(hasAccidental(notes0[0]), true);
840
+ options.assert.equal(hasAccidental(notes0[1]), true);
841
+ options.assert.equal(hasAccidental(notes0[2]), true);
842
+ options.assert.equal(hasAccidental(notes0[3]), true);
843
+ options.assert.equal(hasAccidental(notes0[4]), true);
844
+ options.assert.equal(hasAccidental(notes0[5]), true);
845
+ options.assert.equal(hasAccidental(notes0[6]), true);
846
+ options.assert.equal(hasAccidental(notes0[7]), false, 'Natural Remembered');
847
+ options.assert.equal(hasAccidental(notes1[0]), true);
848
+ options.assert.equal(hasAccidental(notes1[1]), false);
849
+ options.assert.equal(hasAccidental(notes1[2]), true);
850
+ options.assert.equal(hasAccidental(notes1[3]), true);
851
+ options.assert.equal(hasAccidental(notes1[4]), true);
852
+ options.assert.equal(hasAccidental(notes1[5]), true);
853
+ options.assert.equal(hasAccidental(notes1[6]), true);
854
+ options.assert.equal(hasAccidental(notes1[7]), true);
855
+ new Formatter().joinVoices([voice0, voice1]).formatToStave([voice0, voice1], stave);
856
+ f.draw();
857
+ options.assert.ok(true);
858
+ }
859
+ function automaticAccidentalsCornerCases1(options) {
860
+ const f = VexFlowTests.makeFactory(options, 700, 150);
861
+ const stave = f.Stave().addKeySignature('C');
862
+ const notes0 = [
863
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
864
+ { keys: ['c#/4'], duration: '4', stemDirection: -1 },
865
+ { keys: ['c#/4'], duration: '4', stemDirection: -1 },
866
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
867
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
868
+ { keys: ['cb/4'], duration: '4', stemDirection: -1 },
869
+ { keys: ['cb/4'], duration: '4', stemDirection: -1 },
870
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
871
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
872
+ ].map(f.StaveNote.bind(f));
873
+ const voice0 = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes0);
874
+ Accidental.applyAccidentals([voice0], 'C');
875
+ options.assert.equal(hasAccidental(notes0[0]), false);
876
+ options.assert.equal(hasAccidental(notes0[1]), true);
877
+ options.assert.equal(hasAccidental(notes0[2]), false);
878
+ options.assert.equal(hasAccidental(notes0[3]), true);
879
+ options.assert.equal(hasAccidental(notes0[4]), false);
880
+ options.assert.equal(hasAccidental(notes0[5]), true);
881
+ options.assert.equal(hasAccidental(notes0[6]), false);
882
+ options.assert.equal(hasAccidental(notes0[7]), true);
883
+ options.assert.equal(hasAccidental(notes0[8]), false);
884
+ new Formatter().joinVoices([voice0]).formatToStave([voice0], stave);
885
+ f.draw();
886
+ options.assert.ok(true);
887
+ }
888
+ function automaticAccidentalsCornerCases2(options) {
889
+ const f = VexFlowTests.makeFactory(options, 700, 150);
890
+ const stave = f.Stave().addKeySignature('C');
891
+ const notes0 = [
892
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
893
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
894
+ { keys: ['c#/4'], duration: '4', stemDirection: -1 },
895
+ { keys: ['c#/5'], duration: '4', stemDirection: -1 },
896
+ { keys: ['c#/4'], duration: '4', stemDirection: -1 },
897
+ { keys: ['c#/5'], duration: '4', stemDirection: -1 },
898
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
899
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
900
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
901
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
902
+ { keys: ['cb/4'], duration: '4', stemDirection: -1 },
903
+ { keys: ['cb/5'], duration: '4', stemDirection: -1 },
904
+ { keys: ['cb/4'], duration: '4', stemDirection: -1 },
905
+ { keys: ['cb/5'], duration: '4', stemDirection: -1 },
906
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
907
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
908
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
909
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
910
+ ].map(f.StaveNote.bind(f));
911
+ const voice0 = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes0);
912
+ Accidental.applyAccidentals([voice0], 'C');
913
+ options.assert.equal(hasAccidental(notes0[0]), false);
914
+ options.assert.equal(hasAccidental(notes0[2]), true);
915
+ options.assert.equal(hasAccidental(notes0[4]), false);
916
+ options.assert.equal(hasAccidental(notes0[6]), true);
917
+ options.assert.equal(hasAccidental(notes0[8]), false);
918
+ options.assert.equal(hasAccidental(notes0[10]), true);
919
+ options.assert.equal(hasAccidental(notes0[12]), false);
920
+ options.assert.equal(hasAccidental(notes0[14]), true);
921
+ options.assert.equal(hasAccidental(notes0[16]), false);
922
+ options.assert.equal(hasAccidental(notes0[1]), false);
923
+ options.assert.equal(hasAccidental(notes0[3]), true);
924
+ options.assert.equal(hasAccidental(notes0[5]), false);
925
+ options.assert.equal(hasAccidental(notes0[7]), true);
926
+ options.assert.equal(hasAccidental(notes0[9]), false);
927
+ options.assert.equal(hasAccidental(notes0[11]), true);
928
+ options.assert.equal(hasAccidental(notes0[13]), false);
929
+ options.assert.equal(hasAccidental(notes0[15]), true);
930
+ options.assert.equal(hasAccidental(notes0[17]), false);
931
+ new Formatter().joinVoices([voice0]).formatToStave([voice0], stave);
932
+ f.draw();
933
+ options.assert.ok(true);
934
+ }
935
+ function automaticAccidentalsCornerCases3(options) {
936
+ const f = VexFlowTests.makeFactory(options, 700, 150);
937
+ const stave = f.Stave().addKeySignature('C#');
938
+ const notes0 = [
939
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
940
+ { keys: ['c#/4'], duration: '4', stemDirection: -1 },
941
+ { keys: ['c#/4'], duration: '4', stemDirection: -1 },
942
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
943
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
944
+ { keys: ['cb/4'], duration: '4', stemDirection: -1 },
945
+ { keys: ['cb/4'], duration: '4', stemDirection: -1 },
946
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
947
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
948
+ ].map(f.StaveNote.bind(f));
949
+ const voice0 = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes0);
950
+ Accidental.applyAccidentals([voice0], 'C#');
951
+ options.assert.equal(hasAccidental(notes0[0]), true);
952
+ options.assert.equal(hasAccidental(notes0[1]), true);
953
+ options.assert.equal(hasAccidental(notes0[2]), false);
954
+ options.assert.equal(hasAccidental(notes0[3]), true);
955
+ options.assert.equal(hasAccidental(notes0[4]), false);
956
+ options.assert.equal(hasAccidental(notes0[5]), true);
957
+ options.assert.equal(hasAccidental(notes0[6]), false);
958
+ options.assert.equal(hasAccidental(notes0[7]), true);
959
+ options.assert.equal(hasAccidental(notes0[8]), false);
960
+ new Formatter().joinVoices([voice0]).formatToStave([voice0], stave);
961
+ f.draw();
962
+ options.assert.ok(true);
963
+ }
964
+ function automaticAccidentalsCornerCases4(options) {
965
+ const f = VexFlowTests.makeFactory(options, 700, 150);
966
+ const stave = f.Stave().addKeySignature('C#');
967
+ const notes0 = [
968
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
969
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
970
+ { keys: ['c#/4'], duration: '4', stemDirection: -1 },
971
+ { keys: ['c#/5'], duration: '4', stemDirection: -1 },
972
+ { keys: ['c#/4'], duration: '4', stemDirection: -1 },
973
+ { keys: ['c#/5'], duration: '4', stemDirection: -1 },
974
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
975
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
976
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
977
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
978
+ { keys: ['cb/4'], duration: '4', stemDirection: -1 },
979
+ { keys: ['cb/5'], duration: '4', stemDirection: -1 },
980
+ { keys: ['cb/4'], duration: '4', stemDirection: -1 },
981
+ { keys: ['cb/5'], duration: '4', stemDirection: -1 },
982
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
983
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
984
+ { keys: ['c/4'], duration: '4', stemDirection: -1 },
985
+ { keys: ['c/5'], duration: '4', stemDirection: -1 },
986
+ ].map(f.StaveNote.bind(f));
987
+ const voice0 = f.Voice().setMode(Voice.Mode.SOFT).addTickables(notes0);
988
+ Accidental.applyAccidentals([voice0], 'C#');
989
+ options.assert.equal(hasAccidental(notes0[0]), true);
990
+ options.assert.equal(hasAccidental(notes0[2]), true);
991
+ options.assert.equal(hasAccidental(notes0[4]), false);
992
+ options.assert.equal(hasAccidental(notes0[6]), true);
993
+ options.assert.equal(hasAccidental(notes0[8]), false);
994
+ options.assert.equal(hasAccidental(notes0[10]), true);
995
+ options.assert.equal(hasAccidental(notes0[12]), false);
996
+ options.assert.equal(hasAccidental(notes0[14]), true);
997
+ options.assert.equal(hasAccidental(notes0[16]), false);
998
+ options.assert.equal(hasAccidental(notes0[1]), true);
999
+ options.assert.equal(hasAccidental(notes0[3]), true);
1000
+ options.assert.equal(hasAccidental(notes0[5]), false);
1001
+ options.assert.equal(hasAccidental(notes0[7]), true);
1002
+ options.assert.equal(hasAccidental(notes0[9]), false);
1003
+ options.assert.equal(hasAccidental(notes0[11]), true);
1004
+ options.assert.equal(hasAccidental(notes0[13]), false);
1005
+ options.assert.equal(hasAccidental(notes0[15]), true);
1006
+ options.assert.equal(hasAccidental(notes0[17]), false);
1007
+ new Formatter().joinVoices([voice0]).formatToStave([voice0], stave);
1008
+ f.draw();
1009
+ options.assert.ok(true);
1010
+ }
1011
+ function factoryAPI(options) {
1012
+ const f = VexFlowTests.makeFactory(options, 700, 240);
1013
+ f.Stave({ x: 10, y: 10, width: 550 });
1014
+ const accid = makeNewAccid(f);
1015
+ const notes = [
1016
+ f
1017
+ .StaveNote({ keys: ['c/4', 'e/4', 'a/4'], duration: 'w' })
1018
+ .addModifier(accid('b'), 0)
1019
+ .addModifier(accid('#'), 1),
1020
+ f
1021
+ .StaveNote({ keys: ['d/4', 'e/4', 'f/4', 'a/4', 'c/5', 'e/5', 'g/5'], duration: 'h' })
1022
+ .addModifier(accid('##'), 0)
1023
+ .addModifier(accid('n'), 1)
1024
+ .addModifier(accid('bb'), 2)
1025
+ .addModifier(accid('b'), 3)
1026
+ .addModifier(accid('#'), 4)
1027
+ .addModifier(accid('n'), 5)
1028
+ .addModifier(accid('bb'), 6),
1029
+ f
1030
+ .StaveNote({ keys: ['f/4', 'g/4', 'a/4', 'b/4', 'c/5', 'e/5', 'g/5'], duration: '16' })
1031
+ .addModifier(accid('n'), 0)
1032
+ .addModifier(accid('#'), 1)
1033
+ .addModifier(accid('#'), 2)
1034
+ .addModifier(accid('b'), 3)
1035
+ .addModifier(accid('bb'), 4)
1036
+ .addModifier(accid('##'), 5)
1037
+ .addModifier(accid('#'), 6),
1038
+ f
1039
+ .StaveNote({ keys: ['a/3', 'c/4', 'e/4', 'b/4', 'd/5', 'g/5'], duration: 'w' })
1040
+ .addModifier(accid('#'), 0)
1041
+ .addModifier(accid('##').setAsCautionary(), 1)
1042
+ .addModifier(accid('#').setAsCautionary(), 2)
1043
+ .addModifier(accid('b'), 3)
1044
+ .addModifier(accid('bb').setAsCautionary(), 4)
1045
+ .addModifier(accid('b').setAsCautionary(), 5),
1046
+ ];
1047
+ Formatter.SimpleFormat(notes);
1048
+ notes.forEach((n, i) => {
1049
+ options.assert.ok(n.getModifiersByType('Accidental').length > 0, 'Note ' + i + ' has accidentals');
1050
+ });
1051
+ f.draw();
1052
+ options.assert.ok(true, 'Factory API');
1053
+ }
1054
+ VexFlowTests.register(AccidentalTests);
1055
+ export { AccidentalTests };