@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,231 @@
1
+ import { Font } from './font.js';
2
+ import { Metrics } from './metrics.js';
3
+ import { Modifier, ModifierPosition } from './modifier.js';
4
+ import { Stem } from './stem.js';
5
+ import { Tables } from './tables.js';
6
+ import { isStemmableNote, isTabNote } from './typeguard.js';
7
+ import { log } from './util.js';
8
+ function L(...args) {
9
+ if (Annotation.DEBUG)
10
+ log('VexFlow.Annotation', args);
11
+ }
12
+ export var AnnotationHorizontalJustify;
13
+ (function (AnnotationHorizontalJustify) {
14
+ AnnotationHorizontalJustify[AnnotationHorizontalJustify["LEFT"] = 1] = "LEFT";
15
+ AnnotationHorizontalJustify[AnnotationHorizontalJustify["CENTER"] = 2] = "CENTER";
16
+ AnnotationHorizontalJustify[AnnotationHorizontalJustify["RIGHT"] = 3] = "RIGHT";
17
+ AnnotationHorizontalJustify[AnnotationHorizontalJustify["CENTER_STEM"] = 4] = "CENTER_STEM";
18
+ })(AnnotationHorizontalJustify || (AnnotationHorizontalJustify = {}));
19
+ export var AnnotationVerticalJustify;
20
+ (function (AnnotationVerticalJustify) {
21
+ AnnotationVerticalJustify[AnnotationVerticalJustify["TOP"] = 1] = "TOP";
22
+ AnnotationVerticalJustify[AnnotationVerticalJustify["CENTER"] = 2] = "CENTER";
23
+ AnnotationVerticalJustify[AnnotationVerticalJustify["BOTTOM"] = 3] = "BOTTOM";
24
+ AnnotationVerticalJustify[AnnotationVerticalJustify["CENTER_STEM"] = 4] = "CENTER_STEM";
25
+ })(AnnotationVerticalJustify || (AnnotationVerticalJustify = {}));
26
+ export class Annotation extends Modifier {
27
+ static get CATEGORY() {
28
+ return "Annotation";
29
+ }
30
+ static get minAnnotationPadding() {
31
+ return Metrics.get('NoteHead.minPadding');
32
+ }
33
+ static format(annotations, state) {
34
+ if (!annotations || annotations.length === 0)
35
+ return false;
36
+ let leftWidth = 0;
37
+ let rightWidth = 0;
38
+ let maxLeftGlyphWidth = 0;
39
+ let maxRightGlyphWidth = 0;
40
+ for (let i = 0; i < annotations.length; ++i) {
41
+ const annotation = annotations[i];
42
+ const textLines = (2 + Font.convertSizeToPixelValue(annotation.fontInfo.size)) / Tables.STAVE_LINE_DISTANCE;
43
+ let verticalSpaceNeeded = textLines;
44
+ const note = annotation.checkAttachedNote();
45
+ const glyphWidth = note.getGlyphWidth();
46
+ const textWidth = annotation.getWidth();
47
+ if (annotation.horizontalJustification === AnnotationHorizontalJustify.RIGHT) {
48
+ maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
49
+ leftWidth = Math.max(leftWidth, textWidth) + Annotation.minAnnotationPadding;
50
+ }
51
+ else if (annotation.horizontalJustification === AnnotationHorizontalJustify.LEFT) {
52
+ maxRightGlyphWidth = Math.max(glyphWidth, maxRightGlyphWidth);
53
+ rightWidth = Math.max(rightWidth, textWidth);
54
+ }
55
+ else {
56
+ leftWidth = Math.max(leftWidth, textWidth / 2) + Annotation.minAnnotationPadding;
57
+ rightWidth = Math.max(rightWidth, textWidth / 2);
58
+ maxLeftGlyphWidth = Math.max(glyphWidth / 2, maxLeftGlyphWidth);
59
+ maxRightGlyphWidth = Math.max(glyphWidth / 2, maxRightGlyphWidth);
60
+ }
61
+ const stave = note.getStave();
62
+ const stemDirection = note.hasStem() ? note.getStemDirection() : Stem.UP;
63
+ let stemHeight = 0;
64
+ let lines = 5;
65
+ if (isTabNote(note)) {
66
+ if (note.renderOptions.drawStem) {
67
+ const stem = note.getStem();
68
+ if (stem) {
69
+ stemHeight = Math.abs(stem.getHeight()) / Tables.STAVE_LINE_DISTANCE;
70
+ }
71
+ }
72
+ else {
73
+ stemHeight = 0;
74
+ }
75
+ }
76
+ else if (isStemmableNote(note)) {
77
+ const stem = note.getStem();
78
+ if (stem && note.getNoteType() === 'n') {
79
+ stemHeight = Math.abs(stem.getHeight()) / Tables.STAVE_LINE_DISTANCE;
80
+ }
81
+ }
82
+ if (stave) {
83
+ lines = stave.getNumLines();
84
+ }
85
+ if (annotation.verticalJustification === this.VerticalJustify.TOP) {
86
+ let noteLine = note.getLineNumber(true);
87
+ if (isTabNote(note)) {
88
+ noteLine = lines - (note.leastString() - 0.5);
89
+ }
90
+ if (stemDirection === Stem.UP) {
91
+ noteLine += stemHeight;
92
+ }
93
+ const curTop = noteLine + state.topTextLine + 0.5;
94
+ if (curTop < lines) {
95
+ annotation.setTextLine(lines - noteLine);
96
+ verticalSpaceNeeded += lines - noteLine;
97
+ state.topTextLine = verticalSpaceNeeded;
98
+ }
99
+ else {
100
+ annotation.setTextLine(state.topTextLine);
101
+ state.topTextLine += verticalSpaceNeeded;
102
+ }
103
+ }
104
+ else if (annotation.verticalJustification === this.VerticalJustify.BOTTOM) {
105
+ let noteLine = lines - note.getLineNumber();
106
+ if (isTabNote(note)) {
107
+ noteLine = note.greatestString() - 1;
108
+ }
109
+ if (stemDirection === Stem.DOWN) {
110
+ noteLine += stemHeight;
111
+ }
112
+ const curBottom = noteLine + state.textLine + 1;
113
+ if (curBottom < lines) {
114
+ annotation.setTextLine(lines - curBottom);
115
+ verticalSpaceNeeded += lines - curBottom;
116
+ state.textLine = verticalSpaceNeeded;
117
+ }
118
+ else {
119
+ annotation.setTextLine(state.textLine);
120
+ state.textLine += verticalSpaceNeeded;
121
+ }
122
+ }
123
+ else {
124
+ annotation.setTextLine(state.textLine);
125
+ }
126
+ }
127
+ const rightOverlap = Math.min(Math.max(rightWidth - maxRightGlyphWidth, 0), Math.max(rightWidth - state.rightShift, 0));
128
+ const leftOverlap = Math.min(Math.max(leftWidth - maxLeftGlyphWidth, 0), Math.max(leftWidth - state.leftShift, 0));
129
+ state.leftShift += leftOverlap;
130
+ state.rightShift += rightOverlap;
131
+ return true;
132
+ }
133
+ constructor(text) {
134
+ super();
135
+ this.text = text;
136
+ this.horizontalJustification = AnnotationHorizontalJustify.CENTER;
137
+ this.verticalJustification = AnnotationVerticalJustify.TOP;
138
+ }
139
+ setVerticalJustification(just) {
140
+ this.verticalJustification = typeof just === 'string' ? Annotation.VerticalJustifyString[just] : just;
141
+ return this;
142
+ }
143
+ getJustification() {
144
+ return this.horizontalJustification;
145
+ }
146
+ setJustification(just) {
147
+ this.horizontalJustification = typeof just === 'string' ? Annotation.HorizontalJustifyString[just] : just;
148
+ return this;
149
+ }
150
+ draw() {
151
+ const ctx = this.checkContext();
152
+ const note = this.checkAttachedNote();
153
+ const stemDirection = note.hasStem() ? note.getStemDirection() : Stem.UP;
154
+ const start = note.getModifierStartXY(ModifierPosition.ABOVE, this.index);
155
+ this.setRendered();
156
+ const clsAttribute = this.getAttribute('class');
157
+ ctx.openGroup('annotation' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
158
+ const textWidth = this.getWidth();
159
+ const textHeight = Font.convertSizeToPixelValue(this.fontInfo.size);
160
+ let x;
161
+ let y;
162
+ if (this.horizontalJustification === AnnotationHorizontalJustify.LEFT) {
163
+ x = start.x;
164
+ }
165
+ else if (this.horizontalJustification === AnnotationHorizontalJustify.RIGHT) {
166
+ x = start.x - textWidth;
167
+ }
168
+ else if (this.horizontalJustification === AnnotationHorizontalJustify.CENTER) {
169
+ x = start.x - textWidth / 2;
170
+ }
171
+ else {
172
+ x = note.getStemX() - textWidth / 2;
173
+ }
174
+ let stemExt = {};
175
+ let spacing = 0;
176
+ const hasStem = note.hasStem();
177
+ const stave = note.checkStave();
178
+ if (hasStem) {
179
+ stemExt = note.checkStem().getExtents();
180
+ spacing = stave.getSpacingBetweenLines();
181
+ }
182
+ if (this.verticalJustification === AnnotationVerticalJustify.BOTTOM) {
183
+ const ys = note.getYs();
184
+ y = ys.reduce((a, b) => (a > b ? a : b));
185
+ y += (this.textLine + 1) * Tables.STAVE_LINE_DISTANCE + textHeight;
186
+ if (hasStem && stemDirection === Stem.DOWN) {
187
+ y = Math.max(y, stemExt.topY + textHeight + spacing * this.textLine);
188
+ }
189
+ }
190
+ else if (this.verticalJustification === AnnotationVerticalJustify.CENTER) {
191
+ const yt = note.getYForTopText(this.textLine) - 1;
192
+ const yb = stave.getYForBottomText(this.textLine);
193
+ y = yt + (yb - yt) / 2 + textHeight / 2;
194
+ }
195
+ else if (this.verticalJustification === AnnotationVerticalJustify.TOP) {
196
+ const topY = Math.min(...note.getYs());
197
+ y = topY - (this.textLine + 1) * Tables.STAVE_LINE_DISTANCE;
198
+ if (hasStem && stemDirection === Stem.UP) {
199
+ spacing = stemExt.topY < stave.getTopLineTopY() ? Tables.STAVE_LINE_DISTANCE : spacing;
200
+ y = Math.min(y, stemExt.topY - spacing * (this.textLine + 1));
201
+ }
202
+ }
203
+ else {
204
+ const extents = note.getStemExtents();
205
+ y = extents.topY + (extents.baseY - extents.topY) / 2 + textHeight / 2;
206
+ }
207
+ L('Rendering annotation: ', this.text, x, y);
208
+ this.x = x;
209
+ this.y = y;
210
+ this.renderText(ctx, 0, 0);
211
+ this.drawPointerRect();
212
+ ctx.closeGroup();
213
+ }
214
+ }
215
+ Annotation.DEBUG = false;
216
+ Annotation.HorizontalJustify = AnnotationHorizontalJustify;
217
+ Annotation.HorizontalJustifyString = {
218
+ left: AnnotationHorizontalJustify.LEFT,
219
+ right: AnnotationHorizontalJustify.RIGHT,
220
+ center: AnnotationHorizontalJustify.CENTER,
221
+ centerStem: AnnotationHorizontalJustify.CENTER_STEM,
222
+ };
223
+ Annotation.VerticalJustify = AnnotationVerticalJustify;
224
+ Annotation.VerticalJustifyString = {
225
+ above: AnnotationVerticalJustify.TOP,
226
+ top: AnnotationVerticalJustify.TOP,
227
+ below: AnnotationVerticalJustify.BOTTOM,
228
+ bottom: AnnotationVerticalJustify.BOTTOM,
229
+ center: AnnotationVerticalJustify.CENTER,
230
+ centerStem: AnnotationVerticalJustify.CENTER_STEM,
231
+ };
@@ -0,0 +1,281 @@
1
+ import { Glyphs } from './glyphs.js';
2
+ import { Modifier } from './modifier.js';
3
+ import { Stem } from './stem.js';
4
+ import { Tables } from './tables.js';
5
+ import { isGraceNote, isStaveNote, isStemmableNote, isTabNote } from './typeguard.js';
6
+ import { log, RuntimeError } from './util.js';
7
+ function L(...args) {
8
+ if (Articulation.DEBUG)
9
+ log('VexFlow.Articulation', args);
10
+ }
11
+ const { ABOVE, BELOW } = Modifier.Position;
12
+ function roundToNearestHalf(mathFn, value) {
13
+ return mathFn(value / 0.5) * 0.5;
14
+ }
15
+ function isWithinLines(line, position) {
16
+ return position === ABOVE ? line <= 5 : line >= 1;
17
+ }
18
+ function getRoundingFunction(line, position) {
19
+ if (isWithinLines(line, position)) {
20
+ if (position === ABOVE) {
21
+ return Math.ceil;
22
+ }
23
+ else {
24
+ return Math.floor;
25
+ }
26
+ }
27
+ else {
28
+ return Math.round;
29
+ }
30
+ }
31
+ function snapLineToStaff(canSitBetweenLines, line, position, offsetDirection) {
32
+ const snappedLine = roundToNearestHalf(getRoundingFunction(line, position), line);
33
+ const canSnapToStaffSpace = canSitBetweenLines && isWithinLines(snappedLine, position);
34
+ const onStaffLine = snappedLine % 1 === 0;
35
+ if (canSnapToStaffSpace && onStaffLine) {
36
+ const HALF_STAFF_SPACE = 0.5;
37
+ return snappedLine + HALF_STAFF_SPACE * -offsetDirection;
38
+ }
39
+ else {
40
+ return snappedLine;
41
+ }
42
+ }
43
+ const isStaveOrGraceNote = (note) => isStaveNote(note) || isGraceNote(note);
44
+ export function getTopY(note, textLine) {
45
+ const stemDirection = note.getStemDirection();
46
+ const { topY: stemTipY, baseY: stemBaseY } = note.getStemExtents();
47
+ if (isStaveOrGraceNote(note)) {
48
+ if (note.hasStem()) {
49
+ if (stemDirection === Stem.UP) {
50
+ return stemTipY;
51
+ }
52
+ else {
53
+ return stemBaseY;
54
+ }
55
+ }
56
+ else {
57
+ return Math.min(...note.getYs());
58
+ }
59
+ }
60
+ else if (isTabNote(note)) {
61
+ if (note.hasStem()) {
62
+ if (stemDirection === Stem.UP) {
63
+ return stemTipY;
64
+ }
65
+ else {
66
+ return note.checkStave().getYForTopText(textLine);
67
+ }
68
+ }
69
+ else {
70
+ return note.checkStave().getYForTopText(textLine);
71
+ }
72
+ }
73
+ else {
74
+ throw new RuntimeError('UnknownCategory', 'Only can get the top and bottom ys of stavenotes and tabnotes');
75
+ }
76
+ }
77
+ export function getBottomY(note, textLine) {
78
+ const stemDirection = note.getStemDirection();
79
+ const { topY: stemTipY, baseY: stemBaseY } = note.getStemExtents();
80
+ if (isStaveOrGraceNote(note)) {
81
+ if (note.hasStem()) {
82
+ if (stemDirection === Stem.UP) {
83
+ return stemBaseY;
84
+ }
85
+ else {
86
+ return stemTipY;
87
+ }
88
+ }
89
+ else {
90
+ return Math.max(...note.getYs());
91
+ }
92
+ }
93
+ else if (isTabNote(note)) {
94
+ if (note.hasStem()) {
95
+ if (stemDirection === Stem.UP) {
96
+ return note.checkStave().getYForBottomText(textLine);
97
+ }
98
+ else {
99
+ return stemTipY;
100
+ }
101
+ }
102
+ else {
103
+ return note.checkStave().getYForBottomText(textLine);
104
+ }
105
+ }
106
+ else {
107
+ throw new RuntimeError('UnknownCategory', 'Only can get the top and bottom ys of stavenotes and tabnotes');
108
+ }
109
+ }
110
+ export function getInitialOffset(note, position) {
111
+ const isOnStemTip = (position === ABOVE && note.getStemDirection() === Stem.UP) ||
112
+ (position === BELOW && note.getStemDirection() === Stem.DOWN);
113
+ if (isStaveOrGraceNote(note)) {
114
+ if (note.hasStem() && isOnStemTip) {
115
+ return 0.5;
116
+ }
117
+ else {
118
+ return 1;
119
+ }
120
+ }
121
+ else {
122
+ if (note.hasStem() && isOnStemTip) {
123
+ return 1;
124
+ }
125
+ else {
126
+ return 0;
127
+ }
128
+ }
129
+ }
130
+ export class Articulation extends Modifier {
131
+ static get CATEGORY() {
132
+ return "Articulation";
133
+ }
134
+ static format(articulations, state) {
135
+ if (!articulations || articulations.length === 0)
136
+ return false;
137
+ const margin = 0.5;
138
+ let maxGlyphWidth = 0;
139
+ const getIncrement = (articulation, line, position) => roundToNearestHalf(getRoundingFunction(line, position), articulation.height / 10 + margin);
140
+ articulations.forEach((articulation) => {
141
+ const note = articulation.checkAttachedNote();
142
+ maxGlyphWidth = Math.max(note.getGlyphWidth(), maxGlyphWidth);
143
+ let lines = 5;
144
+ const stemDirection = note.hasStem() ? note.getStemDirection() : Stem.UP;
145
+ let stemHeight = 0;
146
+ if (isStemmableNote(note)) {
147
+ const stem = note.getStem();
148
+ if (stem) {
149
+ stemHeight = Math.abs(stem.getHeight()) / Tables.STAVE_LINE_DISTANCE;
150
+ }
151
+ }
152
+ const stave = note.getStave();
153
+ if (stave) {
154
+ lines = stave.getNumLines();
155
+ }
156
+ if (articulation.getPosition() === ABOVE) {
157
+ let noteLine = note.getLineNumber(true);
158
+ if (stemDirection === Stem.UP) {
159
+ noteLine += stemHeight;
160
+ }
161
+ let increment = getIncrement(articulation, state.topTextLine, ABOVE);
162
+ const curTop = noteLine + state.topTextLine + 0.5;
163
+ if (!articulation.articulation.betweenLines && curTop < lines) {
164
+ increment += lines - curTop;
165
+ }
166
+ articulation.setTextLine(state.topTextLine);
167
+ state.topTextLine += increment;
168
+ articulation.setOrigin(0.5, 1);
169
+ }
170
+ else if (articulation.getPosition() === BELOW) {
171
+ let noteLine = Math.max(lines - note.getLineNumber(), 0);
172
+ if (stemDirection === Stem.DOWN) {
173
+ noteLine += stemHeight;
174
+ }
175
+ let increment = getIncrement(articulation, state.textLine, BELOW);
176
+ const curBottom = noteLine + state.textLine + 0.5;
177
+ if (!articulation.articulation.betweenLines && curBottom < lines) {
178
+ increment += lines - curBottom;
179
+ }
180
+ articulation.setTextLine(state.textLine);
181
+ state.textLine += increment;
182
+ articulation.setOrigin(0.5, 0);
183
+ }
184
+ });
185
+ const width = articulations
186
+ .map((articulation) => articulation.getWidth())
187
+ .reduce((maxWidth, articWidth) => Math.max(articWidth, maxWidth));
188
+ const overlap = Math.min(Math.max(width - maxGlyphWidth, 0), Math.max(width - (state.leftShift + state.rightShift), 0));
189
+ state.leftShift += overlap / 2;
190
+ state.rightShift += overlap / 2;
191
+ return true;
192
+ }
193
+ static easyScoreHook({ articulations }, note, builder) {
194
+ if (!articulations)
195
+ return;
196
+ const articNameToCode = {
197
+ staccato: 'a.',
198
+ tenuto: 'a-',
199
+ accent: 'a>',
200
+ };
201
+ articulations
202
+ .split(',')
203
+ .map((articString) => articString.trim().split('.'))
204
+ .map(([name, position]) => {
205
+ const artic = { type: articNameToCode[name] };
206
+ if (position)
207
+ artic.position = Modifier.PositionString[position];
208
+ return builder.getFactory().Articulation(artic);
209
+ })
210
+ .map((artic) => note.addModifier(artic, 0));
211
+ }
212
+ constructor(type) {
213
+ var _a;
214
+ super();
215
+ this.heightShift = 0;
216
+ this.type = type;
217
+ this.position = ABOVE;
218
+ if (!Tables.articulationCodes(this.type)) {
219
+ if (((_a = this.type.codePointAt(0)) !== null && _a !== void 0 ? _a : 0) % 2 === 0)
220
+ this.position = ABOVE;
221
+ else
222
+ this.position = BELOW;
223
+ }
224
+ this.articulation = { betweenLines: false };
225
+ this.reset();
226
+ }
227
+ reset() {
228
+ this.articulation = Tables.articulationCodes(this.type);
229
+ if (!this.articulation) {
230
+ this.articulation = { code: this.type, betweenLines: false };
231
+ }
232
+ const code = (this.position === ABOVE ? this.articulation.aboveCode : this.articulation.belowCode) ||
233
+ this.articulation.code ||
234
+ Glyphs.null;
235
+ this.text = code;
236
+ }
237
+ setBetweenLines(betweenLines = true) {
238
+ this.articulation.betweenLines = betweenLines;
239
+ return this;
240
+ }
241
+ draw() {
242
+ const ctx = this.checkContext();
243
+ const note = this.checkAttachedNote();
244
+ this.setRendered();
245
+ const index = this.checkIndex();
246
+ const { position, textLine } = this;
247
+ const canSitBetweenLines = this.articulation.betweenLines;
248
+ const stave = note.checkStave();
249
+ const staffSpace = stave.getSpacingBetweenLines();
250
+ const isTab = isTabNote(note);
251
+ const { x } = note.getModifierStartXY(position, index);
252
+ const shouldSitOutsideStaff = !canSitBetweenLines || isTab;
253
+ const initialOffset = getInitialOffset(note, position);
254
+ let y = {
255
+ [ABOVE]: () => {
256
+ const y = getTopY(note, textLine) - (textLine + initialOffset) * staffSpace;
257
+ return shouldSitOutsideStaff ? Math.min(stave.getYForTopText(Articulation.INITIAL_OFFSET), y) : y;
258
+ },
259
+ [BELOW]: () => {
260
+ const y = getBottomY(note, textLine) + (textLine + initialOffset) * staffSpace;
261
+ return shouldSitOutsideStaff ? Math.max(stave.getYForBottomText(Articulation.INITIAL_OFFSET), y) : y;
262
+ },
263
+ }[position]();
264
+ if (!isTab) {
265
+ const offsetDirection = position === ABOVE ? -1 : +1;
266
+ const noteLine = note.getKeyProps()[index].line;
267
+ const distanceFromNote = (note.getYs()[index] - y) / staffSpace;
268
+ const articLine = distanceFromNote + Number(noteLine);
269
+ const snappedLine = snapLineToStaff(canSitBetweenLines, articLine, position, offsetDirection);
270
+ if (isWithinLines(snappedLine, position))
271
+ this.setOrigin(0.5, 0.5);
272
+ y += Math.abs(snappedLine - articLine) * staffSpace * offsetDirection;
273
+ }
274
+ L(`Rendering articulation at (x: ${x}, y: ${y})`);
275
+ this.x = x;
276
+ this.y = y;
277
+ this.renderText(ctx, 0, 0);
278
+ }
279
+ }
280
+ Articulation.DEBUG = false;
281
+ Articulation.INITIAL_OFFSET = -0.5;
@@ -0,0 +1,56 @@
1
+ import { Note } from './note.js';
2
+ import { Barline, BarlineType } from './stavebarline.js';
3
+ import { log } from './util.js';
4
+ function L(...args) {
5
+ if (BarNote.DEBUG)
6
+ log('VexFlow.BarNote', args);
7
+ }
8
+ export class BarNote extends Note {
9
+ static get CATEGORY() {
10
+ return "BarNote";
11
+ }
12
+ constructor(type = BarlineType.SINGLE) {
13
+ super({ duration: 'b' });
14
+ this.metrics = {
15
+ widths: {},
16
+ };
17
+ const TYPE = BarlineType;
18
+ this.metrics.widths = {
19
+ [TYPE.SINGLE]: 8,
20
+ [TYPE.DOUBLE]: 12,
21
+ [TYPE.END]: 15,
22
+ [TYPE.REPEAT_BEGIN]: 14,
23
+ [TYPE.REPEAT_END]: 14,
24
+ [TYPE.REPEAT_BOTH]: 18,
25
+ [TYPE.NONE]: 0,
26
+ };
27
+ this.ignoreTicks = true;
28
+ this.setType(type);
29
+ }
30
+ getType() {
31
+ return this.type;
32
+ }
33
+ setType(type) {
34
+ this.type = typeof type === 'string' ? Barline.typeString[type] : type;
35
+ this.setWidth(this.metrics.widths[this.type]);
36
+ return this;
37
+ }
38
+ addToModifierContext(mc) {
39
+ return this;
40
+ }
41
+ preFormat() {
42
+ this.preFormatted = true;
43
+ return this;
44
+ }
45
+ draw() {
46
+ const ctx = this.checkContext();
47
+ L('Rendering bar line at: ', this.getAbsoluteX());
48
+ const barline = new Barline(this.type);
49
+ barline.setX(this.getAbsoluteX());
50
+ barline.setStave(this.checkStave());
51
+ barline.setContext(ctx);
52
+ barline.drawWithStyle();
53
+ this.setRendered();
54
+ }
55
+ }
56
+ BarNote.DEBUG = false;