@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.
- package/LICENSE +22 -0
- package/README.md +208 -0
- package/build/cjs/vexflow-bravura.js +2 -0
- package/build/cjs/vexflow-bravura.js.map +1 -0
- package/build/cjs/vexflow-core.js +2 -0
- package/build/cjs/vexflow-core.js.map +1 -0
- package/build/cjs/vexflow-debug-with-tests.js +43475 -0
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -0
- package/build/cjs/vexflow-debug.js +19194 -0
- package/build/cjs/vexflow-debug.js.map +1 -0
- package/build/cjs/vexflow.js +2 -0
- package/build/cjs/vexflow.js.map +1 -0
- package/build/esm/entry/vexflow-bravura.js +17 -0
- package/build/esm/entry/vexflow-core.js +4 -0
- package/build/esm/entry/vexflow-debug-with-tests.js +38 -0
- package/build/esm/entry/vexflow-debug.js +31 -0
- package/build/esm/entry/vexflow.js +31 -0
- package/build/esm/package.json +3 -0
- package/build/esm/src/accidental.js +330 -0
- package/build/esm/src/annotation.js +231 -0
- package/build/esm/src/articulation.js +281 -0
- package/build/esm/src/barnote.js +56 -0
- package/build/esm/src/beam.js +644 -0
- package/build/esm/src/bend.js +186 -0
- package/build/esm/src/boundingbox.js +59 -0
- package/build/esm/src/canvascontext.js +216 -0
- package/build/esm/src/chordsymbol.js +325 -0
- package/build/esm/src/clef.js +120 -0
- package/build/esm/src/clefnote.js +35 -0
- package/build/esm/src/crescendo.js +78 -0
- package/build/esm/src/curve.js +126 -0
- package/build/esm/src/dot.js +129 -0
- package/build/esm/src/easyscore.js +374 -0
- package/build/esm/src/element.js +409 -0
- package/build/esm/src/factory.js +463 -0
- package/build/esm/src/flag.js +22 -0
- package/build/esm/src/font.js +237 -0
- package/build/esm/src/fonts/academico.js +1 -0
- package/build/esm/src/fonts/academicobold.js +1 -0
- package/build/esm/src/fonts/bravura.js +1 -0
- package/build/esm/src/fonts/gonville.js +1 -0
- package/build/esm/src/fonts/petaluma.js +1 -0
- package/build/esm/src/fonts/petalumascript.js +1 -0
- package/build/esm/src/formatter.js +610 -0
- package/build/esm/src/fraction.js +170 -0
- package/build/esm/src/frethandfinger.js +141 -0
- package/build/esm/src/ghostnote.js +50 -0
- package/build/esm/src/glyphnote.js +44 -0
- package/build/esm/src/glyphs.js +2936 -0
- package/build/esm/src/gracenote.js +106 -0
- package/build/esm/src/gracenotegroup.js +138 -0
- package/build/esm/src/gracetabnote.js +11 -0
- package/build/esm/src/index.js +86 -0
- package/build/esm/src/keymanager.js +99 -0
- package/build/esm/src/keysignature.js +220 -0
- package/build/esm/src/keysignote.js +28 -0
- package/build/esm/src/metrics.js +237 -0
- package/build/esm/src/modifier.js +121 -0
- package/build/esm/src/modifiercontext.js +110 -0
- package/build/esm/src/multimeasurerest.js +127 -0
- package/build/esm/src/music.js +322 -0
- package/build/esm/src/note.js +383 -0
- package/build/esm/src/notehead.js +89 -0
- package/build/esm/src/notesubgroup.js +59 -0
- package/build/esm/src/ornament.js +192 -0
- package/build/esm/src/parenthesis.js +61 -0
- package/build/esm/src/parser.js +164 -0
- package/build/esm/src/pedalmarking.js +168 -0
- package/build/esm/src/registry.js +81 -0
- package/build/esm/src/rendercontext.js +20 -0
- package/build/esm/src/renderer.js +112 -0
- package/build/esm/src/repeatnote.js +17 -0
- package/build/esm/src/stave.js +579 -0
- package/build/esm/src/stavebarline.js +237 -0
- package/build/esm/src/staveconnector.js +180 -0
- package/build/esm/src/stavehairpin.js +115 -0
- package/build/esm/src/staveline.js +199 -0
- package/build/esm/src/stavemodifier.js +56 -0
- package/build/esm/src/stavenote.js +861 -0
- package/build/esm/src/staverepetition.js +120 -0
- package/build/esm/src/stavesection.js +36 -0
- package/build/esm/src/stavetempo.js +110 -0
- package/build/esm/src/stavetext.js +55 -0
- package/build/esm/src/stavetie.js +186 -0
- package/build/esm/src/stavevolta.js +53 -0
- package/build/esm/src/stem.js +133 -0
- package/build/esm/src/stemmablenote.js +193 -0
- package/build/esm/src/stringnumber.js +228 -0
- package/build/esm/src/strokes.js +164 -0
- package/build/esm/src/svgcontext.js +402 -0
- package/build/esm/src/system.js +166 -0
- package/build/esm/src/tables.js +696 -0
- package/build/esm/src/tabnote.js +278 -0
- package/build/esm/src/tabslide.js +68 -0
- package/build/esm/src/tabstave.js +17 -0
- package/build/esm/src/tabtie.js +19 -0
- package/build/esm/src/textbracket.js +128 -0
- package/build/esm/src/textdynamics.js +53 -0
- package/build/esm/src/textnote.js +116 -0
- package/build/esm/src/tickable.js +224 -0
- package/build/esm/src/tickcontext.js +189 -0
- package/build/esm/src/timesignature.js +169 -0
- package/build/esm/src/timesignote.js +30 -0
- package/build/esm/src/tremolo.js +30 -0
- package/build/esm/src/tuning.js +55 -0
- package/build/esm/src/tuplet.js +258 -0
- package/build/esm/src/typeguard.js +30 -0
- package/build/esm/src/util.js +67 -0
- package/build/esm/src/version.js +3 -0
- package/build/esm/src/vexflow.js +309 -0
- package/build/esm/src/vibrato.js +68 -0
- package/build/esm/src/vibratobracket.js +44 -0
- package/build/esm/src/voice.js +178 -0
- package/build/esm/src/web.js +15 -0
- package/build/esm/tests/accidental_tests.js +1055 -0
- package/build/esm/tests/annotation_tests.js +381 -0
- package/build/esm/tests/articulation_tests.js +432 -0
- package/build/esm/tests/auto_beam_formatting_tests.js +551 -0
- package/build/esm/tests/barline_tests.js +52 -0
- package/build/esm/tests/beam_tests.js +669 -0
- package/build/esm/tests/bend_tests.js +223 -0
- package/build/esm/tests/boundingbox_tests.js +53 -0
- package/build/esm/tests/browser_test_runner.js +128 -0
- package/build/esm/tests/chordsymbol_tests.js +405 -0
- package/build/esm/tests/clef_tests.js +141 -0
- package/build/esm/tests/crossbeam_tests.js +306 -0
- package/build/esm/tests/curve_tests.js +152 -0
- package/build/esm/tests/demo_petzold_tests.js +335 -0
- package/build/esm/tests/dot_tests.js +119 -0
- package/build/esm/tests/easyscore_tests.js +488 -0
- package/build/esm/tests/factory_tests.js +44 -0
- package/build/esm/tests/font_tests.js +134 -0
- package/build/esm/tests/formatter/framestack.js +61 -0
- package/build/esm/tests/formatter/tests.js +251 -0
- package/build/esm/tests/formatter_tests.js +759 -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 +119 -0
- package/build/esm/tests/gracenote_tests.js +414 -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 +106 -0
- package/build/esm/tests/keymanager_tests.js +68 -0
- package/build/esm/tests/keysignature_tests.js +322 -0
- package/build/esm/tests/mocks.js +70 -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/node_test_runner.js +31 -0
- package/build/esm/tests/notehead_tests.js +224 -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 +333 -0
- package/build/esm/tests/parser_tests.js +122 -0
- package/build/esm/tests/pedalmarking_tests.js +91 -0
- package/build/esm/tests/percussion_tests.js +184 -0
- package/build/esm/tests/playwright/flow.spec.js +127 -0
- package/build/esm/tests/playwright/visual_helpers.js +30 -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 +266 -0
- package/build/esm/tests/rhythm_tests.js +357 -0
- package/build/esm/tests/stave_tests.js +570 -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 +123 -0
- package/build/esm/tests/stavemodifier_tests.js +51 -0
- package/build/esm/tests/stavenote_tests.js +936 -0
- package/build/esm/tests/stavetie_tests.js +137 -0
- package/build/esm/tests/stringnumber_tests.js +283 -0
- package/build/esm/tests/strokes_tests.js +289 -0
- package/build/esm/tests/style_tests.js +96 -0
- package/build/esm/tests/tabnote_tests.js +462 -0
- package/build/esm/tests/tabslide_tests.js +133 -0
- package/build/esm/tests/tabstave_tests.js +24 -0
- package/build/esm/tests/tabtie_tests.js +171 -0
- package/build/esm/tests/test_runner.js +23 -0
- package/build/esm/tests/textbracket_tests.js +100 -0
- package/build/esm/tests/textnote_tests.js +216 -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 +173 -0
- package/build/esm/tests/tremolo_tests.js +34 -0
- package/build/esm/tests/tuning_tests.js +56 -0
- package/build/esm/tests/tuplet_tests.js +711 -0
- package/build/esm/tests/typeguard_tests.js +82 -0
- package/build/esm/tests/unison_tests.js +74 -0
- package/build/esm/tests/vexflow_test_helpers.js +318 -0
- package/build/esm/tests/vf_prefix_tests.js +101 -0
- package/build/esm/tests/vibrato_tests.js +93 -0
- package/build/esm/tests/vibratobracket_tests.js +45 -0
- package/build/esm/tests/vitest/job-0.test.js +2 -0
- package/build/esm/tests/vitest/job-1.test.js +2 -0
- package/build/esm/tests/vitest/job-2.test.js +2 -0
- package/build/esm/tests/vitest/job-3.test.js +2 -0
- package/build/esm/tests/vitest/run.js +5 -0
- package/build/esm/tests/vitest.setup.js +44 -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.d.ts +3 -0
- package/build/types/src/accidental.d.ts +60 -0
- package/build/types/src/annotation.d.ts +58 -0
- package/build/types/src/articulation.d.ts +78 -0
- package/build/types/src/barnote.d.ts +29 -0
- package/build/types/src/beam.d.ts +158 -0
- package/build/types/src/bend.d.ts +67 -0
- package/build/types/src/boundingbox.d.ts +42 -0
- package/build/types/src/canvascontext.d.ts +93 -0
- package/build/types/src/chordsymbol.d.ts +109 -0
- package/build/types/src/clef.d.ts +38 -0
- package/build/types/src/clefnote.d.ts +17 -0
- package/build/types/src/crescendo.d.ts +26 -0
- package/build/types/src/curve.d.ts +42 -0
- package/build/types/src/dot.d.ts +19 -0
- package/build/types/src/easyscore.d.ts +152 -0
- package/build/types/src/element.d.ts +278 -0
- package/build/types/src/factory.d.ts +273 -0
- package/build/types/src/flag.d.ts +12 -0
- package/build/types/src/font.d.ts +96 -0
- package/build/types/src/fonts/academico.d.ts +1 -0
- package/build/types/src/fonts/academicobold.d.ts +1 -0
- package/build/types/src/fonts/bravura.d.ts +1 -0
- package/build/types/src/fonts/gonville.d.ts +1 -0
- package/build/types/src/fonts/petaluma.d.ts +1 -0
- package/build/types/src/fonts/petalumascript.d.ts +1 -0
- package/build/types/src/formatter.d.ts +226 -0
- package/build/types/src/fraction.d.ts +65 -0
- package/build/types/src/frethandfinger.d.ts +19 -0
- package/build/types/src/ghostnote.d.ts +16 -0
- package/build/types/src/glyphnote.d.ts +14 -0
- package/build/types/src/glyphs.d.ts +2935 -0
- package/build/types/src/gracenote.d.ts +17 -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 +86 -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/metrics.d.ts +25 -0
- package/build/types/src/modifier.d.ts +90 -0
- package/build/types/src/modifiercontext.d.ts +48 -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 +232 -0
- package/build/types/src/notehead.d.ts +50 -0
- package/build/types/src/notesubgroup.d.ts +18 -0
- package/build/types/src/ornament.d.ts +71 -0
- package/build/types/src/parenthesis.d.ts +21 -0
- package/build/types/src/parser.d.ts +45 -0
- package/build/types/src/pedalmarking.d.ts +63 -0
- package/build/types/src/registry.d.ts +40 -0
- package/build/types/src/rendercontext.d.ts +59 -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 +181 -0
- package/build/types/src/stavebarline.d.ts +38 -0
- package/build/types/src/staveconnector.d.ts +53 -0
- package/build/types/src/stavehairpin.d.ts +56 -0
- package/build/types/src/staveline.d.ts +49 -0
- package/build/types/src/stavemodifier.d.ts +35 -0
- package/build/types/src/stavenote.d.ts +150 -0
- package/build/types/src/staverepetition.d.ts +30 -0
- package/build/types/src/stavesection.d.ts +8 -0
- package/build/types/src/stavetempo.d.ts +43 -0
- package/build/types/src/stavetext.d.ts +11 -0
- package/build/types/src/stavetie.d.ts +104 -0
- package/build/types/src/stavevolta.d.ts +15 -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 +26 -0
- package/build/types/src/strokes.d.ts +35 -0
- package/build/types/src/svgcontext.d.ts +135 -0
- package/build/types/src/system.d.ts +121 -0
- package/build/types/src/tables.d.ts +86 -0
- package/build/types/src/tabnote.d.ts +45 -0
- package/build/types/src/tabslide.d.ts +36 -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 +45 -0
- package/build/types/src/textdynamics.d.ts +34 -0
- package/build/types/src/textnote.d.ts +48 -0
- package/build/types/src/tickable.d.ts +149 -0
- package/build/types/src/tickcontext.d.ts +112 -0
- package/build/types/src/timesignature.d.ts +75 -0
- package/build/types/src/timesignote.d.ts +11 -0
- package/build/types/src/tremolo.d.ts +12 -0
- package/build/types/src/tuning.d.ts +23 -0
- package/build/types/src/tuplet.d.ts +98 -0
- package/build/types/src/typeguard.d.ts +100 -0
- package/build/types/src/util.d.ts +42 -0
- package/build/types/src/version.d.ts +3 -0
- package/build/types/src/vexflow.d.ts +261 -0
- package/build/types/src/vibrato.d.ts +20 -0
- package/build/types/src/vibratobracket.d.ts +28 -0
- package/build/types/src/voice.d.ts +109 -0
- package/build/types/src/web.d.ts +2 -0
- package/package.json +145 -0
- package/tests/flow.html +256 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { VexFlowTests } from './vexflow_test_helpers.js';
|
|
2
|
+
import { KeyManager } from '../src/keymanager.js';
|
|
3
|
+
import { Music } from '../src/music.js';
|
|
4
|
+
const MusicTests = {
|
|
5
|
+
Start() {
|
|
6
|
+
VexFlowTests.module('MusicTests');
|
|
7
|
+
VexFlowTests.test('Valid Notes', validNotes);
|
|
8
|
+
VexFlowTests.test('Valid Keys', validKeys);
|
|
9
|
+
VexFlowTests.test('Note Values', noteValue);
|
|
10
|
+
VexFlowTests.test('Interval Values', intervalValue);
|
|
11
|
+
VexFlowTests.test('Relative Notes', relativeNotes);
|
|
12
|
+
VexFlowTests.test('Relative Note Names', relativeNoteNames);
|
|
13
|
+
VexFlowTests.test('Canonical Notes', canonicalNotes);
|
|
14
|
+
VexFlowTests.test('Canonical Intervals', canonicalIntervals);
|
|
15
|
+
VexFlowTests.test('Scale Tones', scaleTones);
|
|
16
|
+
VexFlowTests.test('Scale Intervals', scaleIntervals);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
function validNotes(assert) {
|
|
20
|
+
assert.expect(10);
|
|
21
|
+
const music = new Music();
|
|
22
|
+
let parts = music.getNoteParts('c');
|
|
23
|
+
assert.equal(parts.root, 'c');
|
|
24
|
+
assert.equal(parts.accidental, null);
|
|
25
|
+
parts = music.getNoteParts('C');
|
|
26
|
+
assert.equal(parts.root, 'c');
|
|
27
|
+
assert.equal(parts.accidental, null);
|
|
28
|
+
parts = music.getNoteParts('c#');
|
|
29
|
+
assert.equal(parts.root, 'c');
|
|
30
|
+
assert.equal(parts.accidental, '#');
|
|
31
|
+
parts = music.getNoteParts('c##');
|
|
32
|
+
assert.equal(parts.root, 'c');
|
|
33
|
+
assert.equal(parts.accidental, '##');
|
|
34
|
+
assert.throws(() => music.getNoteParts('r'), /BadArguments/, 'Invalid note: r');
|
|
35
|
+
assert.throws(() => music.getNoteParts(''), /BadArguments/, "Invalid note: ''");
|
|
36
|
+
}
|
|
37
|
+
function validKeys(assert) {
|
|
38
|
+
assert.expect(18);
|
|
39
|
+
const music = new Music();
|
|
40
|
+
let parts = music.getKeyParts('c');
|
|
41
|
+
assert.equal(parts.root, 'c');
|
|
42
|
+
assert.equal(parts.accidental, null);
|
|
43
|
+
assert.equal(parts.type, 'M');
|
|
44
|
+
parts = music.getKeyParts('d#');
|
|
45
|
+
assert.equal(parts.root, 'd');
|
|
46
|
+
assert.equal(parts.accidental, '#');
|
|
47
|
+
assert.equal(parts.type, 'M');
|
|
48
|
+
parts = music.getKeyParts('fbm');
|
|
49
|
+
assert.equal(parts.root, 'f');
|
|
50
|
+
assert.equal(parts.accidental, 'b');
|
|
51
|
+
assert.equal(parts.type, 'm');
|
|
52
|
+
parts = music.getKeyParts('c#mel');
|
|
53
|
+
assert.equal(parts.root, 'c');
|
|
54
|
+
assert.equal(parts.accidental, '#');
|
|
55
|
+
assert.equal(parts.type, 'mel');
|
|
56
|
+
parts = music.getKeyParts('g#harm');
|
|
57
|
+
assert.equal(parts.root, 'g');
|
|
58
|
+
assert.equal(parts.accidental, '#');
|
|
59
|
+
assert.equal(parts.type, 'harm');
|
|
60
|
+
assert.throws(() => music.getKeyParts('r'), /BadArguments/, 'Invalid key: r');
|
|
61
|
+
assert.throws(() => music.getKeyParts(''), /BadArguments/, `Invalid key: ''`);
|
|
62
|
+
assert.throws(() => music.getKeyParts('#m'), /BadArguments/, 'Invalid key: #m');
|
|
63
|
+
}
|
|
64
|
+
function noteValue(assert) {
|
|
65
|
+
assert.expect(3);
|
|
66
|
+
const music = new Music();
|
|
67
|
+
let note = music.getNoteValue('c');
|
|
68
|
+
assert.equal(note, 0);
|
|
69
|
+
assert.throws(() => music.getNoteValue('r'), /BadArguments/, 'Invalid note name');
|
|
70
|
+
note = music.getNoteValue('f#');
|
|
71
|
+
assert.equal(note, 6);
|
|
72
|
+
}
|
|
73
|
+
function intervalValue(assert) {
|
|
74
|
+
assert.expect(2);
|
|
75
|
+
const music = new Music();
|
|
76
|
+
const value = music.getIntervalValue('b2');
|
|
77
|
+
assert.equal(value, 1);
|
|
78
|
+
assert.throws(() => music.getIntervalValue('7'), /BadArguments/, 'Invalid interval name');
|
|
79
|
+
}
|
|
80
|
+
function relativeNotes(assert) {
|
|
81
|
+
assert.expect(8);
|
|
82
|
+
const music = new Music();
|
|
83
|
+
let value = music.getRelativeNoteValue(music.getNoteValue('c'), music.getIntervalValue('b5'));
|
|
84
|
+
assert.equal(value, 6);
|
|
85
|
+
assert.throws(() => music.getRelativeNoteValue(music.getNoteValue('bc'), music.getIntervalValue('b2')), /BadArguments/, 'Invalid note');
|
|
86
|
+
assert.throws(() => music.getRelativeNoteValue(music.getNoteValue('b'), music.getIntervalValue('p3')), /BadArguments/, 'Invalid interval');
|
|
87
|
+
value = music.getRelativeNoteValue(music.getNoteValue('d'), music.getIntervalValue('2'), -1);
|
|
88
|
+
assert.equal(value, 0);
|
|
89
|
+
assert.throws(() => music.getRelativeNoteValue(music.getNoteValue('b'), music.getIntervalValue('p4'), 0), /BadArguments/, 'Invalid direction: 0');
|
|
90
|
+
value = music.getRelativeNoteValue(music.getNoteValue('b'), music.getIntervalValue('b5'));
|
|
91
|
+
assert.equal(value, 5);
|
|
92
|
+
value = music.getRelativeNoteValue(music.getNoteValue('c'), music.getIntervalValue('b2'), -1);
|
|
93
|
+
assert.equal(value, 11);
|
|
94
|
+
value = music.getRelativeNoteValue(music.getNoteValue('g'), music.getIntervalValue('p5'));
|
|
95
|
+
assert.equal(value, 2);
|
|
96
|
+
}
|
|
97
|
+
function relativeNoteNames(assert) {
|
|
98
|
+
assert.expect(9);
|
|
99
|
+
const music = new Music();
|
|
100
|
+
assert.equal(music.getRelativeNoteName('b', music.getNoteValue('c#')), 'b##');
|
|
101
|
+
assert.equal(music.getRelativeNoteName('c', music.getNoteValue('c')), 'c');
|
|
102
|
+
assert.equal(music.getRelativeNoteName('c', music.getNoteValue('db')), 'c#');
|
|
103
|
+
assert.equal(music.getRelativeNoteName('c', music.getNoteValue('b')), 'cb');
|
|
104
|
+
assert.equal(music.getRelativeNoteName('c#', music.getNoteValue('db')), 'c#');
|
|
105
|
+
assert.equal(music.getRelativeNoteName('e', music.getNoteValue('f#')), 'e##');
|
|
106
|
+
assert.equal(music.getRelativeNoteName('e', music.getNoteValue('d#')), 'eb');
|
|
107
|
+
assert.equal(music.getRelativeNoteName('e', music.getNoteValue('fb')), 'e');
|
|
108
|
+
assert.throws(() => music.getRelativeNoteName('e', music.getNoteValue('g#')), /BadArguments/, 'Too far away. Notes not related.');
|
|
109
|
+
}
|
|
110
|
+
function canonicalNotes(assert) {
|
|
111
|
+
assert.expect(3);
|
|
112
|
+
const music = new Music();
|
|
113
|
+
assert.equal(music.getCanonicalNoteName(0), 'c');
|
|
114
|
+
assert.equal(music.getCanonicalNoteName(2), 'd');
|
|
115
|
+
assert.throws(() => music.getCanonicalNoteName(-1), /BadArguments/, 'Invalid note value');
|
|
116
|
+
}
|
|
117
|
+
function canonicalIntervals(assert) {
|
|
118
|
+
assert.expect(3);
|
|
119
|
+
const music = new Music();
|
|
120
|
+
assert.equal(music.getCanonicalIntervalName(0), 'unison');
|
|
121
|
+
assert.equal(music.getCanonicalIntervalName(2), 'M2');
|
|
122
|
+
assert.throws(() => music.getCanonicalIntervalName(-1), /BadArguments/, 'Invalid interval value');
|
|
123
|
+
}
|
|
124
|
+
function scaleTones(assert) {
|
|
125
|
+
assert.expect(24);
|
|
126
|
+
const music = new Music();
|
|
127
|
+
const manager = new KeyManager('CM');
|
|
128
|
+
const C_MAJOR = music.getScaleTones(music.getNoteValue('c'), Music.scales.major);
|
|
129
|
+
let values = ['c', 'd', 'e', 'f', 'g', 'a', 'b'];
|
|
130
|
+
assert.equal(C_MAJOR.length, 7);
|
|
131
|
+
for (let i = 0; i < C_MAJOR.length; ++i) {
|
|
132
|
+
assert.equal(music.getCanonicalNoteName(C_MAJOR[i]), values[i]);
|
|
133
|
+
}
|
|
134
|
+
const C_DORIAN = music.getScaleTones(music.getNoteValue('c'), Music.scales.dorian);
|
|
135
|
+
values = ['c', 'd', 'eb', 'f', 'g', 'a', 'bb'];
|
|
136
|
+
let note = null;
|
|
137
|
+
assert.equal(C_DORIAN.length, 7);
|
|
138
|
+
for (let i = 0; i < C_DORIAN.length; ++i) {
|
|
139
|
+
note = music.getCanonicalNoteName(C_DORIAN[i]);
|
|
140
|
+
assert.equal(manager.selectNote(note).note, values[i]);
|
|
141
|
+
}
|
|
142
|
+
const C_MIXOLYDIAN = music.getScaleTones(music.getNoteValue('c'), Music.scales.mixolydian);
|
|
143
|
+
values = ['c', 'd', 'e', 'f', 'g', 'a', 'bb'];
|
|
144
|
+
assert.equal(C_MIXOLYDIAN.length, 7);
|
|
145
|
+
for (let i = 0; i < C_MIXOLYDIAN.length; ++i) {
|
|
146
|
+
note = music.getCanonicalNoteName(C_MIXOLYDIAN[i]);
|
|
147
|
+
assert.equal(manager.selectNote(note).note, values[i]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function scaleIntervals(assert) {
|
|
151
|
+
assert.expect(6);
|
|
152
|
+
const m = new Music();
|
|
153
|
+
assert.equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('c'), m.getNoteValue('d'))), 'M2');
|
|
154
|
+
assert.equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('g'), m.getNoteValue('c'))), 'p4');
|
|
155
|
+
assert.equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('c'), m.getNoteValue('c'))), 'unison');
|
|
156
|
+
assert.equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('f'), m.getNoteValue('cb'))), 'dim5');
|
|
157
|
+
assert.equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('d'), m.getNoteValue('c'), 1)), 'b7');
|
|
158
|
+
assert.equal(m.getCanonicalIntervalName(m.getIntervalBetween(m.getNoteValue('d'), m.getNoteValue('c'), -1)), 'M2');
|
|
159
|
+
}
|
|
160
|
+
VexFlowTests.register(MusicTests);
|
|
161
|
+
export { MusicTests };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TestRunner } from './test_runner.js';
|
|
2
|
+
const noOp = () => undefined;
|
|
3
|
+
function createAssert(moduleName) {
|
|
4
|
+
return {
|
|
5
|
+
test: { module: { name: moduleName } },
|
|
6
|
+
deepEqual: noOp,
|
|
7
|
+
equal: noOp,
|
|
8
|
+
expect: noOp,
|
|
9
|
+
notDeepEqual: noOp,
|
|
10
|
+
notEqual: noOp,
|
|
11
|
+
notOk: noOp,
|
|
12
|
+
notStrictEqual: noOp,
|
|
13
|
+
ok: noOp,
|
|
14
|
+
propEqual: noOp,
|
|
15
|
+
strictEqual: noOp,
|
|
16
|
+
throws: noOp,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
let currentModule = '';
|
|
20
|
+
const nodeBackend = {
|
|
21
|
+
module(name) {
|
|
22
|
+
currentModule = name;
|
|
23
|
+
},
|
|
24
|
+
test(name, callback) {
|
|
25
|
+
callback(createAssert(currentModule), { moduleName: currentModule, testName: name });
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export function installNodeTestRunner() {
|
|
29
|
+
currentModule = '';
|
|
30
|
+
TestRunner.install(nodeBackend);
|
|
31
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { VexFlow } from '../src/vexflow.js';
|
|
2
|
+
import { VexFlowTests } from './vexflow_test_helpers.js';
|
|
3
|
+
import { Formatter } from '../src/formatter.js';
|
|
4
|
+
import { NoteHead } from '../src/notehead.js';
|
|
5
|
+
import { Stave } from '../src/stave.js';
|
|
6
|
+
import { StaveNote } from '../src/stavenote.js';
|
|
7
|
+
import { TickContext } from '../src/tickcontext.js';
|
|
8
|
+
import { Voice } from '../src/voice.js';
|
|
9
|
+
const NoteHeadTests = {
|
|
10
|
+
Start() {
|
|
11
|
+
VexFlowTests.module('NoteHead');
|
|
12
|
+
const run = VexFlowTests.runTests;
|
|
13
|
+
run('Basic', basic);
|
|
14
|
+
run('Various Note Heads 1', variousNoteHeads);
|
|
15
|
+
run('Various Note Heads 2', variousNoteHeads2);
|
|
16
|
+
run('Various Heads', variousHeads);
|
|
17
|
+
run('Drum Chord Heads', drumChordHeads);
|
|
18
|
+
run('Bounding Boxes', basicBoundingBoxes);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
function setContextStyle(ctx) {
|
|
22
|
+
ctx.scale(0.9, 0.9);
|
|
23
|
+
ctx.scale(2.0, 2.0);
|
|
24
|
+
ctx.font = '10pt Arial';
|
|
25
|
+
}
|
|
26
|
+
function basic(options, contextBuilder) {
|
|
27
|
+
const ctx = contextBuilder(options.elementId, 450, 250);
|
|
28
|
+
setContextStyle(ctx);
|
|
29
|
+
const stave = new Stave(10, 0, 250).addClef('treble');
|
|
30
|
+
stave.setContext(ctx).drawWithStyle();
|
|
31
|
+
const formatter = new Formatter();
|
|
32
|
+
const voice = new Voice(VexFlow.TIME4_4).setStrict(false);
|
|
33
|
+
const noteHead1 = new NoteHead({ duration: '4', line: 3 });
|
|
34
|
+
const noteHead2 = new NoteHead({ duration: '1', line: 2.5 });
|
|
35
|
+
const noteHead3 = new NoteHead({ duration: '2', line: 0 });
|
|
36
|
+
voice.addTickables([noteHead1, noteHead2, noteHead3]);
|
|
37
|
+
formatter.joinVoices([voice]).formatToStave([voice], stave);
|
|
38
|
+
voice.draw(ctx, stave);
|
|
39
|
+
options.assert.ok('Basic NoteHead test');
|
|
40
|
+
}
|
|
41
|
+
function showNote(noteStruct, stave, ctx, x) {
|
|
42
|
+
const note = new StaveNote(noteStruct).setStave(stave);
|
|
43
|
+
new TickContext().addTickable(note).preFormat().setX(x);
|
|
44
|
+
note.setContext(ctx).drawWithStyle();
|
|
45
|
+
return note;
|
|
46
|
+
}
|
|
47
|
+
function variousHeads(options, contextBuilder) {
|
|
48
|
+
const notes = [
|
|
49
|
+
{ keys: ['g/5/d0'], duration: '4' },
|
|
50
|
+
{ keys: ['g/5/d1'], duration: '4' },
|
|
51
|
+
{ keys: ['g/5/d2'], duration: '4' },
|
|
52
|
+
{ keys: ['g/5/d3'], duration: '4' },
|
|
53
|
+
{ keys: ['x/'], duration: '1' },
|
|
54
|
+
{ keys: ['g/5/t0'], duration: '1' },
|
|
55
|
+
{ keys: ['g/5/t1'], duration: '4' },
|
|
56
|
+
{ keys: ['g/5/t2'], duration: '4' },
|
|
57
|
+
{ keys: ['g/5/t3'], duration: '4' },
|
|
58
|
+
{ keys: ['x/'], duration: '1' },
|
|
59
|
+
{ keys: ['g/5/x0'], duration: '1' },
|
|
60
|
+
{ keys: ['g/5/x1'], duration: '4' },
|
|
61
|
+
{ keys: ['g/5/x2'], duration: '4' },
|
|
62
|
+
{ keys: ['g/5/x3'], duration: '4' },
|
|
63
|
+
{ keys: ['x/'], duration: '1' },
|
|
64
|
+
{ keys: ['g/5/s1'], duration: '4' },
|
|
65
|
+
{ keys: ['g/5/s2'], duration: '4' },
|
|
66
|
+
{ keys: ['x/'], duration: '1' },
|
|
67
|
+
{ keys: ['g/5/r1'], duration: '4' },
|
|
68
|
+
{ keys: ['g/5/r2'], duration: '4' },
|
|
69
|
+
];
|
|
70
|
+
const ctx = contextBuilder(options.elementId, notes.length * 25 + 100, 240);
|
|
71
|
+
for (let staveNum = 0; staveNum < 2; ++staveNum) {
|
|
72
|
+
const stave = new Stave(10, 10 + staveNum * 120, notes.length * 25 + 75)
|
|
73
|
+
.addClef('percussion')
|
|
74
|
+
.setContext(ctx)
|
|
75
|
+
.drawWithStyle();
|
|
76
|
+
for (let i = 0; i < notes.length; ++i) {
|
|
77
|
+
const note = notes[i];
|
|
78
|
+
note.stemDirection = staveNum === 0 ? -1 : 1;
|
|
79
|
+
const staveNote = showNote(note, stave, ctx, (i + 1) * 25);
|
|
80
|
+
options.assert.ok(staveNote.getX() > 0, 'Note ' + i + ' has X value');
|
|
81
|
+
options.assert.ok(staveNote.getYs().length > 0, 'Note ' + i + ' has Y values');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function variousNoteHeads(options, contextBuilder) {
|
|
86
|
+
const notes = [
|
|
87
|
+
{ keys: ['g/5/d'], duration: '1/2' },
|
|
88
|
+
{ keys: ['g/5/d'], duration: '1' },
|
|
89
|
+
{ keys: ['g/5/d'], duration: '2' },
|
|
90
|
+
{ keys: ['g/5/d'], duration: '4' },
|
|
91
|
+
{ keys: ['x/'], duration: '1' },
|
|
92
|
+
{ keys: ['g/5/x'], duration: '1/2' },
|
|
93
|
+
{ keys: ['g/5/x'], duration: '1' },
|
|
94
|
+
{ keys: ['g/5/x'], duration: '2' },
|
|
95
|
+
{ keys: ['g/5/x'], duration: '4' },
|
|
96
|
+
{ keys: ['x/'], duration: '1' },
|
|
97
|
+
{ keys: ['g/5/cx'], duration: '1/2' },
|
|
98
|
+
{ keys: ['g/5/cx'], duration: '1' },
|
|
99
|
+
{ keys: ['g/5/cx'], duration: '2' },
|
|
100
|
+
{ keys: ['g/5/cx'], duration: '4' },
|
|
101
|
+
{ keys: ['x/'], duration: '1' },
|
|
102
|
+
{ keys: ['g/5/tu'], duration: '1/2' },
|
|
103
|
+
{ keys: ['g/5/tu'], duration: '1' },
|
|
104
|
+
{ keys: ['g/5/tu'], duration: '2' },
|
|
105
|
+
{ keys: ['g/5/tu'], duration: '4' },
|
|
106
|
+
{ keys: ['x/'], duration: '1' },
|
|
107
|
+
{ keys: ['g/5/td'], duration: '1/2' },
|
|
108
|
+
{ keys: ['g/5/td'], duration: '1' },
|
|
109
|
+
{ keys: ['g/5/td'], duration: '2' },
|
|
110
|
+
{ keys: ['g/5/td'], duration: '4' },
|
|
111
|
+
{ keys: ['x/'], duration: '1' },
|
|
112
|
+
{ keys: ['g/5/sf'], duration: '1/2' },
|
|
113
|
+
{ keys: ['g/5/sf'], duration: '1' },
|
|
114
|
+
{ keys: ['g/5/sf'], duration: '2' },
|
|
115
|
+
{ keys: ['g/5/sf'], duration: '4' },
|
|
116
|
+
{ keys: ['x/'], duration: '1' },
|
|
117
|
+
{ keys: ['g/5/sb'], duration: '1/2' },
|
|
118
|
+
{ keys: ['g/5/sb'], duration: '1' },
|
|
119
|
+
{ keys: ['g/5/sb'], duration: '2' },
|
|
120
|
+
{ keys: ['g/5/sb'], duration: '4' },
|
|
121
|
+
{ keys: ['x/'], duration: '1' },
|
|
122
|
+
{ keys: ['g/5/ci'], duration: '1/2' },
|
|
123
|
+
{ keys: ['g/5/ci'], duration: '1' },
|
|
124
|
+
{ keys: ['g/5/ci'], duration: '2' },
|
|
125
|
+
{ keys: ['g/5/ci'], duration: '4' },
|
|
126
|
+
{ keys: ['x/'], duration: '1' },
|
|
127
|
+
{ keys: ['g/5/sq'], duration: '1/2' },
|
|
128
|
+
{ keys: ['g/5/sq'], duration: '1' },
|
|
129
|
+
{ keys: ['g/5/sq'], duration: '2' },
|
|
130
|
+
{ keys: ['g/5/sq'], duration: '4' },
|
|
131
|
+
{ keys: ['x/'], duration: '1' },
|
|
132
|
+
];
|
|
133
|
+
const ctx = contextBuilder(options.elementId, notes.length * 25 + 100, 240);
|
|
134
|
+
for (let staveNum = 0; staveNum < 2; ++staveNum) {
|
|
135
|
+
const stave = new Stave(10, 10 + staveNum * 120, notes.length * 25 + 75)
|
|
136
|
+
.addClef('percussion')
|
|
137
|
+
.setContext(ctx)
|
|
138
|
+
.drawWithStyle();
|
|
139
|
+
for (let i = 0; i < notes.length; ++i) {
|
|
140
|
+
const note = notes[i];
|
|
141
|
+
note.stemDirection = staveNum === 0 ? -1 : 1;
|
|
142
|
+
const staveNote = showNote(note, stave, ctx, (i + 1) * 25);
|
|
143
|
+
options.assert.ok(staveNote.getX() > 0, 'Note ' + i + ' has X value');
|
|
144
|
+
options.assert.ok(staveNote.getYs().length > 0, 'Note ' + i + ' has Y values');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function variousNoteHeads2(options, contextBuilder) {
|
|
149
|
+
const notes = [
|
|
150
|
+
{ keys: ['g/5/do'], duration: '4', autoStem: true },
|
|
151
|
+
{ keys: ['g/5/re'], duration: '4', autoStem: true },
|
|
152
|
+
{ keys: ['g/5/mi'], duration: '4', autoStem: true },
|
|
153
|
+
{ keys: ['g/5/fa'], duration: '4', autoStem: true },
|
|
154
|
+
{ keys: ['e/4/faup'], duration: '4', autoStem: true },
|
|
155
|
+
{ keys: ['g/5/so'], duration: '4', autoStem: true },
|
|
156
|
+
{ keys: ['g/5/la'], duration: '4', autoStem: true },
|
|
157
|
+
{ keys: ['g/5/ti'], duration: '4', autoStem: true },
|
|
158
|
+
];
|
|
159
|
+
const ctx = contextBuilder(options.elementId, notes.length * 25 + 100, 240);
|
|
160
|
+
const stave = new Stave(10, 10, notes.length * 25 + 75).addClef('percussion').setContext(ctx).drawWithStyle();
|
|
161
|
+
for (let i = 0; i < notes.length; ++i) {
|
|
162
|
+
const note = notes[i];
|
|
163
|
+
const staveNote = showNote(note, stave, ctx, (i + 1) * 25);
|
|
164
|
+
options.assert.ok(staveNote.getX() > 0, 'Note ' + i + ' has X value');
|
|
165
|
+
options.assert.ok(staveNote.getYs().length > 0, 'Note ' + i + ' has Y values');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function drumChordHeads(options, contextBuilder) {
|
|
169
|
+
const notes = [
|
|
170
|
+
{ keys: ['a/4/d0', 'g/5/x3'], duration: '4' },
|
|
171
|
+
{ keys: ['a/4/x3', 'g/5/d0'], duration: '4' },
|
|
172
|
+
{ keys: ['a/4/d1', 'g/5/x2'], duration: '4' },
|
|
173
|
+
{ keys: ['a/4/x2', 'g/5/d1'], duration: '4' },
|
|
174
|
+
{ keys: ['a/4/d2', 'g/5/x1'], duration: '4' },
|
|
175
|
+
{ keys: ['a/4/x1', 'g/5/d2'], duration: '4' },
|
|
176
|
+
{ keys: ['a/4/d3', 'g/5/x0'], duration: '4' },
|
|
177
|
+
{ keys: ['a/4/x0', 'g/5/d3'], duration: '4' },
|
|
178
|
+
{ keys: ['a/4', 'g/5/d0'], duration: '4' },
|
|
179
|
+
{ keys: ['a/4/x3', 'g/5'], duration: '4' },
|
|
180
|
+
{ keys: ['a/4/t0', 'g/5/s1'], duration: '4' },
|
|
181
|
+
{ keys: ['a/4/s1', 'g/5/t0'], duration: '4' },
|
|
182
|
+
{ keys: ['a/4/t1', 'g/5/s2'], duration: '4' },
|
|
183
|
+
{ keys: ['a/4/s2', 'g/5/t1'], duration: '4' },
|
|
184
|
+
{ keys: ['a/4/t2', 'g/5/r1'], duration: '4' },
|
|
185
|
+
{ keys: ['a/4/r1', 'g/5/t2'], duration: '4' },
|
|
186
|
+
{ keys: ['a/4/t3', 'g/5/r2'], duration: '4' },
|
|
187
|
+
{ keys: ['a/4/r2', 'g/5/t3'], duration: '4' },
|
|
188
|
+
];
|
|
189
|
+
const ctx = contextBuilder(options.elementId, notes.length * 25 + 100, 240);
|
|
190
|
+
for (let h = 0; h < 2; ++h) {
|
|
191
|
+
const stave = new Stave(10, 10 + h * 120, notes.length * 25 + 75)
|
|
192
|
+
.addClef('percussion')
|
|
193
|
+
.setContext(ctx)
|
|
194
|
+
.drawWithStyle();
|
|
195
|
+
for (let i = 0; i < notes.length; ++i) {
|
|
196
|
+
const note = notes[i];
|
|
197
|
+
note.stemDirection = h === 0 ? -1 : 1;
|
|
198
|
+
const staveNote = showNote(note, stave, ctx, (i + 1) * 25);
|
|
199
|
+
options.assert.ok(staveNote.getX() > 0, 'Note ' + i + ' has X value');
|
|
200
|
+
options.assert.ok(staveNote.getYs().length > 0, 'Note ' + i + ' has Y values');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function basicBoundingBoxes(options, contextBuilder) {
|
|
205
|
+
const ctx = contextBuilder(options.elementId, 450, 250);
|
|
206
|
+
setContextStyle(ctx);
|
|
207
|
+
const stave = new Stave(10, 0, 250).addClef('treble');
|
|
208
|
+
stave.setContext(ctx).drawWithStyle();
|
|
209
|
+
const formatter = new Formatter();
|
|
210
|
+
const voice = new Voice(VexFlow.TIME4_4).setStrict(false);
|
|
211
|
+
const nh1 = new StaveNote({ keys: ['b/4'], duration: '4' });
|
|
212
|
+
const nh2 = new StaveNote({ keys: ['a/4'], duration: '2' });
|
|
213
|
+
const nh3 = new NoteHead({ duration: '1', line: 0 });
|
|
214
|
+
voice.addTickables([nh1, nh2, nh3]);
|
|
215
|
+
formatter.joinVoices([voice]).formatToStave([voice], stave);
|
|
216
|
+
voice.draw(ctx, stave);
|
|
217
|
+
for (const bb of [nh1.noteHeads[0].getBoundingBox(), nh2.noteHeads[0].getBoundingBox(), nh3.getBoundingBox()]) {
|
|
218
|
+
ctx.rect(bb.getX(), bb.getY(), bb.getW(), bb.getH());
|
|
219
|
+
}
|
|
220
|
+
ctx.stroke();
|
|
221
|
+
options.assert.ok('NoteHead Bounding Boxes');
|
|
222
|
+
}
|
|
223
|
+
VexFlowTests.register(NoteHeadTests);
|
|
224
|
+
export { NoteHeadTests };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { VexFlowTests } from './vexflow_test_helpers.js';
|
|
2
|
+
import { BarNote } from '../src/barnote.js';
|
|
3
|
+
import { Note } from '../src/note.js';
|
|
4
|
+
import { BarlineType } from '../src/stavebarline.js';
|
|
5
|
+
const NoteSubGroupTests = {
|
|
6
|
+
Start() {
|
|
7
|
+
VexFlowTests.module('NoteSubGroup');
|
|
8
|
+
const run = VexFlowTests.runTests;
|
|
9
|
+
run('Basic - ClefNote, TimeSigNote and BarNote', basic);
|
|
10
|
+
run('Multi Voice', multiVoiceSingleDraw);
|
|
11
|
+
run('Multi Voice Multiple Draws', multiVoiceDoubleDraw);
|
|
12
|
+
run('Multi Staff', multiStaff);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
function createShortcuts(f) {
|
|
16
|
+
return {
|
|
17
|
+
createStaveNote: (noteStruct) => f.StaveNote(noteStruct),
|
|
18
|
+
addAccidental: (note, accid) => note.addModifier(f.Accidental({ type: accid }), 0),
|
|
19
|
+
addSubGroup: (note, subNotes) => note.addModifier(f.NoteSubGroup({ notes: subNotes }), 0),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function basic(options) {
|
|
23
|
+
const f = VexFlowTests.makeFactory(options, 750, 200);
|
|
24
|
+
const ctx = f.getContext();
|
|
25
|
+
const stave = f.Stave({ width: 600 }).addClef('treble');
|
|
26
|
+
const { createStaveNote, addAccidental, addSubGroup } = createShortcuts(f);
|
|
27
|
+
const notes = [
|
|
28
|
+
{ keys: ['f/5'], stemDirection: -1, duration: '4' },
|
|
29
|
+
{ keys: ['d/4'], stemDirection: -1, duration: '4', clef: 'bass' },
|
|
30
|
+
{ keys: ['g/4'], stemDirection: -1, duration: '4', clef: 'alto' },
|
|
31
|
+
{ keys: ['a/4'], stemDirection: -1, duration: '4', clef: 'alto' },
|
|
32
|
+
{ keys: ['c/4'], stemDirection: -1, duration: '4', clef: 'tenor' },
|
|
33
|
+
{ keys: ['c/3'], stemDirection: +1, duration: '4', clef: 'tenor' },
|
|
34
|
+
{ keys: ['d/4'], stemDirection: -1, duration: '4', clef: 'tenor' },
|
|
35
|
+
{ keys: ['f/4'], stemDirection: -1, duration: '4', clef: 'tenor' },
|
|
36
|
+
].map(createStaveNote);
|
|
37
|
+
addAccidental(notes[1], '#');
|
|
38
|
+
addAccidental(notes[2], 'n');
|
|
39
|
+
addSubGroup(notes[1], [f.ClefNote({ type: 'bass', options: { size: 'small' } })]);
|
|
40
|
+
addSubGroup(notes[2], [f.ClefNote({ type: 'alto', options: { size: 'small' } })]);
|
|
41
|
+
addSubGroup(notes[4], [f.ClefNote({ type: 'tenor', options: { size: 'small' } }), new BarNote()]);
|
|
42
|
+
addSubGroup(notes[5], [f.TimeSigNote({ time: '6/8' })]);
|
|
43
|
+
addSubGroup(notes[6], [new BarNote(BarlineType.REPEAT_BEGIN)]);
|
|
44
|
+
addAccidental(notes[4], 'b');
|
|
45
|
+
addAccidental(notes[6], 'bb');
|
|
46
|
+
const voice = f.Voice().setStrict(false).addTickables(notes);
|
|
47
|
+
f.Formatter().joinVoices([voice]).formatToStave([voice], stave);
|
|
48
|
+
f.draw();
|
|
49
|
+
notes.forEach((note) => Note.plotMetrics(ctx, note, 150));
|
|
50
|
+
VexFlowTests.plotLegendForNoteWidth(ctx, 620, 120);
|
|
51
|
+
options.assert.ok(true, 'all pass');
|
|
52
|
+
}
|
|
53
|
+
function multiVoiceSingleDraw(options) {
|
|
54
|
+
multiVoiceHelper(options, 1);
|
|
55
|
+
}
|
|
56
|
+
function multiVoiceDoubleDraw(options) {
|
|
57
|
+
multiVoiceHelper(options, 2);
|
|
58
|
+
}
|
|
59
|
+
function multiVoiceHelper(options, numDraws) {
|
|
60
|
+
const f = VexFlowTests.makeFactory(options, 550, 200);
|
|
61
|
+
const ctx = f.getContext();
|
|
62
|
+
const stave = f.Stave().addClef('treble');
|
|
63
|
+
const { createStaveNote, addAccidental, addSubGroup } = createShortcuts(f);
|
|
64
|
+
const notes1 = [
|
|
65
|
+
{ keys: ['f/5'], stemDirection: 1, duration: '4' },
|
|
66
|
+
{ keys: ['d/4'], stemDirection: 1, duration: '4', clef: 'bass' },
|
|
67
|
+
{ keys: ['c/5'], stemDirection: 1, duration: '4', clef: 'alto' },
|
|
68
|
+
{ keys: ['c/5'], stemDirection: 1, duration: '4', clef: 'soprano' },
|
|
69
|
+
].map(createStaveNote);
|
|
70
|
+
const notes2 = [
|
|
71
|
+
{ keys: ['c/4'], stemDirection: -1, duration: '4' },
|
|
72
|
+
{ keys: ['c/3'], stemDirection: -1, duration: '4', clef: 'bass' },
|
|
73
|
+
{ keys: ['d/4'], stemDirection: -1, duration: '4', clef: 'alto' },
|
|
74
|
+
{ keys: ['f/4'], stemDirection: -1, duration: '4', clef: 'soprano' },
|
|
75
|
+
].map(createStaveNote);
|
|
76
|
+
addAccidental(notes1[1], '#');
|
|
77
|
+
addSubGroup(notes1[1], [
|
|
78
|
+
f.ClefNote({ type: 'bass', options: { size: 'small' } }),
|
|
79
|
+
new BarNote(BarlineType.REPEAT_BEGIN),
|
|
80
|
+
f.TimeSigNote({ time: '3/4' }),
|
|
81
|
+
]);
|
|
82
|
+
addSubGroup(notes2[2], [
|
|
83
|
+
f.ClefNote({ type: 'alto', options: { size: 'small' } }),
|
|
84
|
+
f.TimeSigNote({ time: '9/8' }),
|
|
85
|
+
new BarNote(BarlineType.DOUBLE),
|
|
86
|
+
]);
|
|
87
|
+
addSubGroup(notes1[3], [f.ClefNote({ type: 'soprano', options: { size: 'small' } })]);
|
|
88
|
+
addAccidental(notes1[2], 'b');
|
|
89
|
+
addAccidental(notes2[3], '#');
|
|
90
|
+
const voices = [f.Voice().addTickables(notes1), f.Voice().addTickables(notes2)];
|
|
91
|
+
f.Formatter().joinVoices(voices).formatToStave(voices, stave);
|
|
92
|
+
for (let i = 0; i < numDraws; i++) {
|
|
93
|
+
f.draw();
|
|
94
|
+
}
|
|
95
|
+
notes1.forEach((note) => Note.plotMetrics(ctx, note, 150));
|
|
96
|
+
options.assert.ok(true, 'all pass');
|
|
97
|
+
}
|
|
98
|
+
function multiStaff(options) {
|
|
99
|
+
const f = VexFlowTests.makeFactory(options, 550, 400);
|
|
100
|
+
const { createStaveNote, addAccidental, addSubGroup } = createShortcuts(f);
|
|
101
|
+
const stave1 = f.Stave({ x: 15, y: 30, width: 500 }).setClef('treble');
|
|
102
|
+
const notes1 = [
|
|
103
|
+
{ keys: ['f/5'], stemDirection: 1, duration: '4' },
|
|
104
|
+
{ keys: ['d/4'], stemDirection: 1, duration: '4', clef: 'bass' },
|
|
105
|
+
{ keys: ['c/5'], stemDirection: 1, duration: '4', clef: 'alto' },
|
|
106
|
+
{ keys: ['c/5'], stemDirection: 1, duration: '4', clef: 'soprano' },
|
|
107
|
+
].map(createStaveNote);
|
|
108
|
+
const notes2 = [
|
|
109
|
+
{ keys: ['c/4'], stemDirection: -1, duration: '4' },
|
|
110
|
+
{ keys: ['c/3'], stemDirection: -1, duration: '4', clef: 'bass' },
|
|
111
|
+
{ keys: ['d/4'], stemDirection: -1, duration: '4', clef: 'alto' },
|
|
112
|
+
{ keys: ['f/4'], stemDirection: -1, duration: '4', clef: 'soprano' },
|
|
113
|
+
].map(createStaveNote);
|
|
114
|
+
const stave2 = f.Stave({ x: 15, y: 150, width: 500 }).setClef('bass');
|
|
115
|
+
const notes3 = [
|
|
116
|
+
{ keys: ['e/3'], duration: '8', stemDirection: -1, clef: 'bass' },
|
|
117
|
+
{ keys: ['g/4'], duration: '8', stemDirection: 1, clef: 'treble' },
|
|
118
|
+
{ keys: ['d/4'], duration: '8', stemDirection: 1, clef: 'treble' },
|
|
119
|
+
{ keys: ['f/4'], duration: '8', stemDirection: 1, clef: 'treble' },
|
|
120
|
+
{ keys: ['c/4'], duration: '8', stemDirection: 1, clef: 'treble' },
|
|
121
|
+
{ keys: ['g/3'], duration: '8', stemDirection: -1, clef: 'bass' },
|
|
122
|
+
{ keys: ['d/3'], duration: '8', stemDirection: -1, clef: 'bass' },
|
|
123
|
+
{ keys: ['f/3'], duration: '8', stemDirection: -1, clef: 'bass' },
|
|
124
|
+
].map(createStaveNote);
|
|
125
|
+
f.StaveConnector({ topStave: stave1, bottomStave: stave2, type: 'brace' });
|
|
126
|
+
f.StaveConnector({ topStave: stave1, bottomStave: stave2, type: 'singleLeft' });
|
|
127
|
+
f.StaveConnector({ topStave: stave1, bottomStave: stave2, type: 'singleRight' });
|
|
128
|
+
f.Beam({ notes: notes3.slice(1, 4) });
|
|
129
|
+
f.Beam({ notes: notes3.slice(5) });
|
|
130
|
+
addAccidental(notes1[1], '#');
|
|
131
|
+
addSubGroup(notes1[1], [f.ClefNote({ type: 'bass', options: { size: 'small' } }), f.TimeSigNote({ time: '3/4' })]);
|
|
132
|
+
addSubGroup(notes2[2], [f.ClefNote({ type: 'alto', options: { size: 'small' } }), f.TimeSigNote({ time: '9/8' })]);
|
|
133
|
+
addSubGroup(notes1[3], [f.ClefNote({ type: 'soprano', options: { size: 'small' } })]);
|
|
134
|
+
addSubGroup(notes3[1], [f.ClefNote({ type: 'treble', options: { size: 'small' } })]);
|
|
135
|
+
addSubGroup(notes3[5], [f.ClefNote({ type: 'bass', options: { size: 'small' } })]);
|
|
136
|
+
addAccidental(notes3[0], '#');
|
|
137
|
+
addAccidental(notes3[3], 'b');
|
|
138
|
+
addAccidental(notes3[5], '#');
|
|
139
|
+
addAccidental(notes1[2], 'b');
|
|
140
|
+
addAccidental(notes2[3], '#');
|
|
141
|
+
const voice1 = f.Voice().addTickables(notes1);
|
|
142
|
+
const voice2 = f.Voice().addTickables(notes2);
|
|
143
|
+
const voice3 = f.Voice().addTickables(notes3);
|
|
144
|
+
f.Formatter().joinVoices([voice1, voice2]).joinVoices([voice3]).formatToStave([voice1, voice2, voice3], stave1);
|
|
145
|
+
f.draw();
|
|
146
|
+
options.assert.ok(true, 'all pass');
|
|
147
|
+
}
|
|
148
|
+
VexFlowTests.register(NoteSubGroupTests);
|
|
149
|
+
export { NoteSubGroupTests };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { VexFlowTests } from './vexflow_test_helpers.js';
|
|
2
|
+
import { CanvasContext } from '../src/canvascontext.js';
|
|
3
|
+
import { Formatter } from '../src/formatter.js';
|
|
4
|
+
import { Stave } from '../src/stave.js';
|
|
5
|
+
import { BarlineType } from '../src/stavebarline.js';
|
|
6
|
+
import { StaveNote } from '../src/stavenote.js';
|
|
7
|
+
import { globalObject } from '../src/util.js';
|
|
8
|
+
const OffscreenCanvasTests = {
|
|
9
|
+
Start() {
|
|
10
|
+
if (globalObject().OffscreenCanvas === undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
VexFlowTests.module('OffscreenCanvas');
|
|
14
|
+
VexFlowTests.test('Simple Test', simpleTest);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
function simpleTest(assert) {
|
|
18
|
+
const offscreenCanvas = new OffscreenCanvas(550, 200);
|
|
19
|
+
const offscreenCtx = offscreenCanvas.getContext('2d');
|
|
20
|
+
if (offscreenCtx === null) {
|
|
21
|
+
throw new Error("Couldn't create offscreen context");
|
|
22
|
+
}
|
|
23
|
+
const ctx = new CanvasContext(offscreenCtx);
|
|
24
|
+
const stave = new Stave(10, 50, 200);
|
|
25
|
+
stave.setEndBarType(BarlineType.END);
|
|
26
|
+
stave.addClef('treble').setContext(ctx).drawWithStyle();
|
|
27
|
+
const notes = [
|
|
28
|
+
new StaveNote({ keys: ['c/4'], duration: 'q' }),
|
|
29
|
+
new StaveNote({ keys: ['d/4'], duration: 'q' }),
|
|
30
|
+
new StaveNote({ keys: ['b/4'], duration: 'qr' }),
|
|
31
|
+
new StaveNote({ keys: ['c/4', 'e/4', 'g/4'], duration: 'q' }),
|
|
32
|
+
];
|
|
33
|
+
Formatter.FormatAndDraw(ctx, stave, notes);
|
|
34
|
+
const imgBmp = offscreenCanvas.transferToImageBitmap();
|
|
35
|
+
const canvas = document.createElement('canvas');
|
|
36
|
+
canvas.width = offscreenCanvas.width;
|
|
37
|
+
canvas.height = offscreenCanvas.height;
|
|
38
|
+
const canvasCtx = canvas.getContext('2d');
|
|
39
|
+
if (canvasCtx === null) {
|
|
40
|
+
throw new Error("Couldn't create canvas context");
|
|
41
|
+
}
|
|
42
|
+
canvasCtx.drawImage(imgBmp, 0, 0);
|
|
43
|
+
document.body.appendChild(canvas);
|
|
44
|
+
assert.ok(true, 'all pass');
|
|
45
|
+
}
|
|
46
|
+
VexFlowTests.register(OffscreenCanvasTests);
|
|
47
|
+
export { OffscreenCanvasTests };
|