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