@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,120 @@
|
|
|
1
|
+
import { Glyphs } from './glyphs.js';
|
|
2
|
+
import { Metrics } from './metrics.js';
|
|
3
|
+
import { StaveModifier } from './stavemodifier.js';
|
|
4
|
+
export class Repetition extends StaveModifier {
|
|
5
|
+
static get CATEGORY() {
|
|
6
|
+
return "Repetition";
|
|
7
|
+
}
|
|
8
|
+
constructor(type, x, yShift) {
|
|
9
|
+
super();
|
|
10
|
+
this.symbolType = type;
|
|
11
|
+
this.x = x;
|
|
12
|
+
this.xShift = 0;
|
|
13
|
+
this.yShift = yShift;
|
|
14
|
+
}
|
|
15
|
+
setShiftX(x) {
|
|
16
|
+
this.xShift = x;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
setShiftY(y) {
|
|
20
|
+
this.yShift = y;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
draw() {
|
|
24
|
+
const stave = this.checkStave();
|
|
25
|
+
const x = stave.getModifierXShift(this.getPosition());
|
|
26
|
+
this.setRendered();
|
|
27
|
+
switch (this.symbolType) {
|
|
28
|
+
case Repetition.type.CODA_RIGHT:
|
|
29
|
+
this.drawCodaFixed(stave, x + stave.getWidth());
|
|
30
|
+
break;
|
|
31
|
+
case Repetition.type.CODA_LEFT:
|
|
32
|
+
this.drawSymbolText(stave, x, 'Coda', true);
|
|
33
|
+
break;
|
|
34
|
+
case Repetition.type.SEGNO_LEFT:
|
|
35
|
+
this.drawSegnoFixed(stave, x);
|
|
36
|
+
break;
|
|
37
|
+
case Repetition.type.SEGNO_RIGHT:
|
|
38
|
+
this.drawSegnoFixed(stave, x + stave.getWidth());
|
|
39
|
+
break;
|
|
40
|
+
case Repetition.type.DC:
|
|
41
|
+
this.drawSymbolText(stave, x, 'D.C.', false);
|
|
42
|
+
break;
|
|
43
|
+
case Repetition.type.DC_AL_CODA:
|
|
44
|
+
this.drawSymbolText(stave, x, 'D.C. al', true);
|
|
45
|
+
break;
|
|
46
|
+
case Repetition.type.DC_AL_FINE:
|
|
47
|
+
this.drawSymbolText(stave, x, 'D.C. al Fine', false);
|
|
48
|
+
break;
|
|
49
|
+
case Repetition.type.DS:
|
|
50
|
+
this.drawSymbolText(stave, x, 'D.S.', false);
|
|
51
|
+
break;
|
|
52
|
+
case Repetition.type.DS_AL_CODA:
|
|
53
|
+
this.drawSymbolText(stave, x, 'D.S. al', true);
|
|
54
|
+
break;
|
|
55
|
+
case Repetition.type.DS_AL_FINE:
|
|
56
|
+
this.drawSymbolText(stave, x, 'D.S. al Fine', false);
|
|
57
|
+
break;
|
|
58
|
+
case Repetition.type.FINE:
|
|
59
|
+
this.drawSymbolText(stave, x, 'Fine', false);
|
|
60
|
+
break;
|
|
61
|
+
case Repetition.type.TO_CODA:
|
|
62
|
+
this.drawSymbolText(stave, x, 'To', true);
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
drawCodaFixed(stave, x) {
|
|
69
|
+
const y = stave.getYForTopText(stave.getNumLines());
|
|
70
|
+
this.text = Glyphs.coda;
|
|
71
|
+
this.renderText(stave.checkContext(), x, y + Metrics.get('Repetition.coda.offsetY'));
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
drawSegnoFixed(stave, x) {
|
|
75
|
+
const y = stave.getYForTopText(stave.getNumLines());
|
|
76
|
+
this.text = Glyphs.segno;
|
|
77
|
+
this.renderText(stave.checkContext(), x, y + Metrics.get('Repetition.segno.offsetY'));
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
drawSymbolText(stave, x, text, drawCoda) {
|
|
81
|
+
const ctx = stave.checkContext();
|
|
82
|
+
let textX = 0;
|
|
83
|
+
this.text = text;
|
|
84
|
+
if (drawCoda) {
|
|
85
|
+
this.text += ' \ue048';
|
|
86
|
+
}
|
|
87
|
+
this.setFont(Metrics.getFontInfo('Repetition.text'));
|
|
88
|
+
switch (this.symbolType) {
|
|
89
|
+
case Repetition.type.CODA_LEFT:
|
|
90
|
+
textX = stave.getVerticalBarWidth();
|
|
91
|
+
break;
|
|
92
|
+
case Repetition.type.DC:
|
|
93
|
+
case Repetition.type.DC_AL_FINE:
|
|
94
|
+
case Repetition.type.DS:
|
|
95
|
+
case Repetition.type.DS_AL_FINE:
|
|
96
|
+
case Repetition.type.FINE:
|
|
97
|
+
default:
|
|
98
|
+
textX =
|
|
99
|
+
x - (stave.getNoteStartX() - this.x) + stave.getWidth() - this.width - Metrics.get('Repetition.text.offsetX');
|
|
100
|
+
}
|
|
101
|
+
const y = stave.getYForTopText(stave.getNumLines()) + Metrics.get('Repetition.text.offsetY');
|
|
102
|
+
this.renderText(ctx, textX, y);
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
Repetition.type = {
|
|
107
|
+
NONE: 1,
|
|
108
|
+
CODA_LEFT: 2,
|
|
109
|
+
CODA_RIGHT: 3,
|
|
110
|
+
SEGNO_LEFT: 4,
|
|
111
|
+
SEGNO_RIGHT: 5,
|
|
112
|
+
DC: 6,
|
|
113
|
+
DC_AL_CODA: 7,
|
|
114
|
+
DC_AL_FINE: 8,
|
|
115
|
+
DS: 9,
|
|
116
|
+
DS_AL_CODA: 10,
|
|
117
|
+
DS_AL_FINE: 11,
|
|
118
|
+
FINE: 12,
|
|
119
|
+
TO_CODA: 13,
|
|
120
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Metrics } from './metrics.js';
|
|
2
|
+
import { StaveModifier } from './stavemodifier.js';
|
|
3
|
+
export class StaveSection extends StaveModifier {
|
|
4
|
+
static get CATEGORY() {
|
|
5
|
+
return "StaveSection";
|
|
6
|
+
}
|
|
7
|
+
constructor(section, x = 0, yShift = 0, drawRect = true) {
|
|
8
|
+
super();
|
|
9
|
+
this.setText(section);
|
|
10
|
+
this.x = x;
|
|
11
|
+
this.yShift = yShift;
|
|
12
|
+
this.drawRect = drawRect;
|
|
13
|
+
this.padding = Metrics.get('StaveSection.padding');
|
|
14
|
+
}
|
|
15
|
+
setDrawRect(drawRect) {
|
|
16
|
+
this.drawRect = drawRect;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
draw() {
|
|
20
|
+
const stave = this.checkStave();
|
|
21
|
+
const ctx = stave.checkContext();
|
|
22
|
+
this.setRendered();
|
|
23
|
+
this.x = stave.getX() + stave.getModifierXShift(this.getPosition());
|
|
24
|
+
const headroom = -1 * this.textMetrics.actualBoundingBoxDescent;
|
|
25
|
+
const width = this.width + 2 * this.padding;
|
|
26
|
+
const height = this.height + 2 * this.padding;
|
|
27
|
+
const y = stave.getYForTopText(1.5) + this.yShift;
|
|
28
|
+
const x = this.x + this.xShift;
|
|
29
|
+
if (this.drawRect) {
|
|
30
|
+
ctx.beginPath();
|
|
31
|
+
ctx.rect(x, y - height + headroom, width, height);
|
|
32
|
+
ctx.stroke();
|
|
33
|
+
}
|
|
34
|
+
this.renderText(ctx, this.xShift + this.padding, y - this.padding);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Glyphs } from './glyphs.js';
|
|
3
|
+
import { Metrics } from './metrics.js';
|
|
4
|
+
import { StaveModifier, StaveModifierPosition } from './stavemodifier.js';
|
|
5
|
+
export class StaveTempo extends StaveModifier {
|
|
6
|
+
static get CATEGORY() {
|
|
7
|
+
return "StaveTempo";
|
|
8
|
+
}
|
|
9
|
+
constructor(tempo, x, shiftY) {
|
|
10
|
+
super();
|
|
11
|
+
this.durationToCode = {
|
|
12
|
+
'1/4': Glyphs.metNoteDoubleWholeSquare,
|
|
13
|
+
long: Glyphs.metNoteDoubleWholeSquare,
|
|
14
|
+
'1/2': Glyphs.metNoteDoubleWhole,
|
|
15
|
+
breve: Glyphs.metNoteDoubleWhole,
|
|
16
|
+
1: Glyphs.metNoteWhole,
|
|
17
|
+
whole: Glyphs.metNoteWhole,
|
|
18
|
+
w: Glyphs.metNoteWhole,
|
|
19
|
+
2: Glyphs.metNoteHalfUp,
|
|
20
|
+
half: Glyphs.metNoteHalfUp,
|
|
21
|
+
h: Glyphs.metNoteHalfUp,
|
|
22
|
+
4: Glyphs.metNoteQuarterUp,
|
|
23
|
+
quarter: Glyphs.metNoteQuarterUp,
|
|
24
|
+
q: Glyphs.metNoteQuarterUp,
|
|
25
|
+
8: Glyphs.metNote8thUp,
|
|
26
|
+
eighth: Glyphs.metNote8thUp,
|
|
27
|
+
16: Glyphs.metNote16thUp,
|
|
28
|
+
'16th': Glyphs.metNote16thUp,
|
|
29
|
+
32: Glyphs.metNote32ndUp,
|
|
30
|
+
'32nd': Glyphs.metNote32ndUp,
|
|
31
|
+
64: Glyphs.metNote64thUp,
|
|
32
|
+
'64th': Glyphs.metNote64thUp,
|
|
33
|
+
128: Glyphs.metNote128thUp,
|
|
34
|
+
'128th': Glyphs.metNote128thUp,
|
|
35
|
+
256: Glyphs.metNote256thUp,
|
|
36
|
+
'256th': Glyphs.metNote256thUp,
|
|
37
|
+
512: Glyphs.metNote512thUp,
|
|
38
|
+
'512th': Glyphs.metNote512thUp,
|
|
39
|
+
1024: Glyphs.metNote1024thUp,
|
|
40
|
+
'1024th': Glyphs.metNote1024thUp,
|
|
41
|
+
};
|
|
42
|
+
this.tempo = tempo;
|
|
43
|
+
this.position = StaveModifierPosition.ABOVE;
|
|
44
|
+
this.x = x;
|
|
45
|
+
this.setXShift(10);
|
|
46
|
+
this.setYShift(shiftY);
|
|
47
|
+
}
|
|
48
|
+
setTempo(tempo) {
|
|
49
|
+
this.tempo = tempo;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
draw() {
|
|
53
|
+
const stave = this.checkStave();
|
|
54
|
+
const shiftX = stave.getModifierXShift(this.getPosition());
|
|
55
|
+
const ctx = stave.checkContext();
|
|
56
|
+
this.setRendered();
|
|
57
|
+
const { name, duration, dots, bpm, duration2, dots2, parenthesis } = this.tempo;
|
|
58
|
+
let x = this.x + shiftX;
|
|
59
|
+
const y = stave.getYForTopText(1);
|
|
60
|
+
const el = new Element('StaveTempo.glyph');
|
|
61
|
+
const elText = new Element('StaveTempo');
|
|
62
|
+
if (name) {
|
|
63
|
+
this.text = name;
|
|
64
|
+
this.fontInfo = Metrics.getFontInfo('StaveTempo.name');
|
|
65
|
+
this.renderText(ctx, shiftX, y);
|
|
66
|
+
x += this.getWidth() + 3;
|
|
67
|
+
}
|
|
68
|
+
if ((name && duration) || parenthesis) {
|
|
69
|
+
elText.setText('(');
|
|
70
|
+
elText.renderText(ctx, x + this.xShift, y + this.yShift);
|
|
71
|
+
x += elText.getWidth() + 3;
|
|
72
|
+
}
|
|
73
|
+
if (duration) {
|
|
74
|
+
el.setText(this.durationToCode[duration]);
|
|
75
|
+
el.renderText(ctx, x + this.xShift, y + this.yShift);
|
|
76
|
+
x += el.getWidth() + 3;
|
|
77
|
+
if (dots) {
|
|
78
|
+
el.setText(Glyphs.metAugmentationDot);
|
|
79
|
+
for (let i = 0; i < dots; i++) {
|
|
80
|
+
el.renderText(ctx, x + this.xShift, y + 2 + this.yShift);
|
|
81
|
+
x += el.getWidth() + 3;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
elText.setText('=');
|
|
85
|
+
elText.renderText(ctx, x + this.xShift, y + this.yShift);
|
|
86
|
+
x += elText.getWidth() + 3;
|
|
87
|
+
if (duration2) {
|
|
88
|
+
el.setText(this.durationToCode[duration2]);
|
|
89
|
+
el.renderText(ctx, x + this.xShift, y + this.yShift);
|
|
90
|
+
x += el.getWidth() + 3;
|
|
91
|
+
if (dots2) {
|
|
92
|
+
el.setText(Glyphs.metAugmentationDot);
|
|
93
|
+
for (let i = 0; i < dots2; i++) {
|
|
94
|
+
el.renderText(ctx, x + this.xShift, y + 2 + this.yShift);
|
|
95
|
+
x += el.getWidth() + 3;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (bpm) {
|
|
100
|
+
elText.setText('' + bpm);
|
|
101
|
+
elText.renderText(ctx, x + this.xShift, y + this.yShift);
|
|
102
|
+
x += elText.getWidth() + 3;
|
|
103
|
+
}
|
|
104
|
+
if (name || parenthesis) {
|
|
105
|
+
elText.setText(')');
|
|
106
|
+
elText.renderText(ctx, x + this.xShift, y + this.yShift);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { StaveModifier, StaveModifierPosition } from './stavemodifier.js';
|
|
2
|
+
import { TextJustification, TextNote } from './textnote.js';
|
|
3
|
+
import { RuntimeError } from './util.js';
|
|
4
|
+
export class StaveText extends StaveModifier {
|
|
5
|
+
static get CATEGORY() {
|
|
6
|
+
return "StaveText";
|
|
7
|
+
}
|
|
8
|
+
constructor(text, position, options = {}) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
super();
|
|
11
|
+
this.setText(text);
|
|
12
|
+
this.setXShift((_a = options.shiftX) !== null && _a !== void 0 ? _a : 0);
|
|
13
|
+
this.setYShift((_b = options.shiftY) !== null && _b !== void 0 ? _b : 0);
|
|
14
|
+
this.position = position;
|
|
15
|
+
this.justification = (_c = options.justification) !== null && _c !== void 0 ? _c : TextNote.Justification.CENTER;
|
|
16
|
+
}
|
|
17
|
+
draw() {
|
|
18
|
+
const stave = this.checkStave();
|
|
19
|
+
const ctx = stave.checkContext();
|
|
20
|
+
this.setRendered();
|
|
21
|
+
let x;
|
|
22
|
+
let y;
|
|
23
|
+
switch (this.position) {
|
|
24
|
+
case StaveModifierPosition.LEFT:
|
|
25
|
+
case StaveModifierPosition.RIGHT:
|
|
26
|
+
y = (stave.getYForLine(0) + stave.getBottomLineY()) / 2;
|
|
27
|
+
if (this.position === StaveModifierPosition.LEFT) {
|
|
28
|
+
x = stave.getX() - this.width - 24;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
x = stave.getX() + stave.getWidth() + 24;
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case StaveModifierPosition.ABOVE:
|
|
35
|
+
case StaveModifierPosition.BELOW:
|
|
36
|
+
x = stave.getX();
|
|
37
|
+
if (this.justification === TextJustification.CENTER) {
|
|
38
|
+
x += stave.getWidth() / 2 - this.width / 2;
|
|
39
|
+
}
|
|
40
|
+
else if (this.justification === TextJustification.RIGHT) {
|
|
41
|
+
x += stave.getWidth() - this.width;
|
|
42
|
+
}
|
|
43
|
+
if (this.position === StaveModifierPosition.ABOVE) {
|
|
44
|
+
y = stave.getYForTopText(2);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
y = stave.getYForBottomText(2);
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
throw new RuntimeError('InvalidPosition', 'Value Must be in Modifier.Position.');
|
|
52
|
+
}
|
|
53
|
+
this.renderText(ctx, x, y + 4);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { RuntimeError } from './util.js';
|
|
3
|
+
export class StaveTie extends Element {
|
|
4
|
+
static get CATEGORY() {
|
|
5
|
+
return "StaveTie";
|
|
6
|
+
}
|
|
7
|
+
constructor(notes, text = '') {
|
|
8
|
+
super();
|
|
9
|
+
this.setNotes(notes);
|
|
10
|
+
this.text = text;
|
|
11
|
+
this.renderOptions = {
|
|
12
|
+
cp1: 8,
|
|
13
|
+
cp2: 12,
|
|
14
|
+
shortTieCutoff: 10,
|
|
15
|
+
cp1Short: 2,
|
|
16
|
+
cp2Short: 8,
|
|
17
|
+
textShiftX: 0,
|
|
18
|
+
firstXShift: 0,
|
|
19
|
+
lastXShift: 0,
|
|
20
|
+
yShift: 7,
|
|
21
|
+
tieSpacing: 0,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
getDirection() {
|
|
25
|
+
if (this.direction !== undefined && this.direction !== null) {
|
|
26
|
+
return this.direction;
|
|
27
|
+
}
|
|
28
|
+
else if (this.notes.lastNote) {
|
|
29
|
+
return this.notes.lastNote.getStemDirection();
|
|
30
|
+
}
|
|
31
|
+
else if (this.notes.firstNote) {
|
|
32
|
+
return this.notes.firstNote.getStemDirection();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
setDirection(direction) {
|
|
39
|
+
this.direction = direction;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
setNotes(notes) {
|
|
43
|
+
if (!notes.firstNote && !notes.lastNote) {
|
|
44
|
+
throw new RuntimeError('BadArguments', 'Tie needs to have either firstNote or lastNote set.');
|
|
45
|
+
}
|
|
46
|
+
if (!notes.firstIndexes) {
|
|
47
|
+
notes.firstIndexes = [0];
|
|
48
|
+
}
|
|
49
|
+
if (!notes.lastIndexes) {
|
|
50
|
+
notes.lastIndexes = [0];
|
|
51
|
+
}
|
|
52
|
+
if (notes.firstIndexes.length !== notes.lastIndexes.length) {
|
|
53
|
+
throw new RuntimeError('BadArguments', 'Tied notes must have same number of indexes.');
|
|
54
|
+
}
|
|
55
|
+
this.notes = notes;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
isPartial() {
|
|
59
|
+
return !this.notes.firstNote || !this.notes.lastNote;
|
|
60
|
+
}
|
|
61
|
+
renderTie(params) {
|
|
62
|
+
if (params.firstYs.length === 0 || params.lastYs.length === 0) {
|
|
63
|
+
throw new RuntimeError('BadArguments', 'No Y-values to render');
|
|
64
|
+
}
|
|
65
|
+
const ctx = this.checkContext();
|
|
66
|
+
let cp1 = this.renderOptions.cp1;
|
|
67
|
+
let cp2 = this.renderOptions.cp2;
|
|
68
|
+
if (Math.abs(params.lastX - params.firstX) < this.renderOptions.shortTieCutoff) {
|
|
69
|
+
cp1 = this.renderOptions.cp1Short;
|
|
70
|
+
cp2 = this.renderOptions.cp2Short;
|
|
71
|
+
}
|
|
72
|
+
const firstXShift = this.renderOptions.firstXShift;
|
|
73
|
+
const lastXShift = this.renderOptions.lastXShift;
|
|
74
|
+
const yShift = this.renderOptions.yShift * params.direction;
|
|
75
|
+
const firstIndexes = this.notes.firstIndexes;
|
|
76
|
+
const lastIndexes = this.notes.lastIndexes;
|
|
77
|
+
const clsAttribute = this.getAttribute('class');
|
|
78
|
+
ctx.openGroup('stavetie' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
79
|
+
for (let i = 0; i < firstIndexes.length; ++i) {
|
|
80
|
+
const cpX = (params.lastX + lastXShift + (params.firstX + firstXShift)) / 2;
|
|
81
|
+
const firstY = params.firstYs[firstIndexes[i]] + yShift;
|
|
82
|
+
const lastY = params.lastYs[lastIndexes[i]] + yShift;
|
|
83
|
+
if (isNaN(firstY) || isNaN(lastY)) {
|
|
84
|
+
throw new RuntimeError('BadArguments', 'Bad indexes for tie rendering.');
|
|
85
|
+
}
|
|
86
|
+
const topControlPointY = (firstY + lastY) / 2 + cp1 * params.direction;
|
|
87
|
+
const bottomControlPointY = (firstY + lastY) / 2 + cp2 * params.direction;
|
|
88
|
+
ctx.beginPath();
|
|
89
|
+
ctx.moveTo(params.firstX + firstXShift, firstY);
|
|
90
|
+
ctx.quadraticCurveTo(cpX, topControlPointY, params.lastX + lastXShift, lastY);
|
|
91
|
+
ctx.quadraticCurveTo(cpX, bottomControlPointY, params.firstX + firstXShift, firstY);
|
|
92
|
+
ctx.closePath();
|
|
93
|
+
ctx.fill();
|
|
94
|
+
}
|
|
95
|
+
this.drawPointerRect();
|
|
96
|
+
ctx.closeGroup();
|
|
97
|
+
}
|
|
98
|
+
renderTieText(firstX, lastX) {
|
|
99
|
+
var _a, _b, _c;
|
|
100
|
+
const ctx = this.checkContext();
|
|
101
|
+
let centerX = (firstX + lastX) / 2;
|
|
102
|
+
centerX -= ctx.measureText(this.text).width / 2;
|
|
103
|
+
const stave = (_b = (_a = this.notes.firstNote) === null || _a === void 0 ? void 0 : _a.checkStave()) !== null && _b !== void 0 ? _b : (_c = this.notes.lastNote) === null || _c === void 0 ? void 0 : _c.checkStave();
|
|
104
|
+
if (stave) {
|
|
105
|
+
ctx.setFont(this.fontInfo);
|
|
106
|
+
ctx.fillText(this.text, centerX + this.renderOptions.textShiftX, stave.getYForTopText() - 1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
getNotes() {
|
|
110
|
+
return this.notes;
|
|
111
|
+
}
|
|
112
|
+
getFirstX() {
|
|
113
|
+
if (this.notes.firstNote) {
|
|
114
|
+
return this.notes.firstNote.getTieRightX() + this.renderOptions.tieSpacing;
|
|
115
|
+
}
|
|
116
|
+
else if (this.notes.lastNote) {
|
|
117
|
+
return this.notes.lastNote.checkStave().getTieStartX();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
getLastX() {
|
|
124
|
+
if (this.notes.lastNote) {
|
|
125
|
+
return this.notes.lastNote.getTieLeftX() + this.renderOptions.tieSpacing;
|
|
126
|
+
}
|
|
127
|
+
else if (this.notes.firstNote) {
|
|
128
|
+
return this.notes.firstNote.checkStave().getTieEndX();
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
getFirstYs() {
|
|
135
|
+
if (this.notes.firstNote) {
|
|
136
|
+
return this.notes.firstNote.getYs();
|
|
137
|
+
}
|
|
138
|
+
else if (this.notes.lastNote) {
|
|
139
|
+
return this.notes.lastNote.getYs();
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
return [0];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
getLastYs() {
|
|
146
|
+
if (this.notes.lastNote) {
|
|
147
|
+
return this.notes.lastNote.getYs();
|
|
148
|
+
}
|
|
149
|
+
else if (this.notes.firstNote) {
|
|
150
|
+
return this.notes.firstNote.getYs();
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
return [0];
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
synchronizeIndexes() {
|
|
157
|
+
if (this.notes.firstNote && this.notes.lastNote) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
else if (!this.notes.firstNote && !this.notes.lastNote) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
else if (this.notes.firstNote) {
|
|
164
|
+
this.notes.lastIndexes = this.notes.firstIndexes;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.notes.firstIndexes = this.notes.lastIndexes;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
draw() {
|
|
171
|
+
this.checkContext();
|
|
172
|
+
this.setRendered();
|
|
173
|
+
this.synchronizeIndexes();
|
|
174
|
+
const firstX = this.getFirstX();
|
|
175
|
+
const lastX = this.getLastX();
|
|
176
|
+
this.renderTie({
|
|
177
|
+
firstX,
|
|
178
|
+
lastX,
|
|
179
|
+
firstYs: this.getFirstYs(),
|
|
180
|
+
lastYs: this.getLastYs(),
|
|
181
|
+
direction: this.getDirection(),
|
|
182
|
+
});
|
|
183
|
+
this.renderTieText(firstX, lastX);
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { StaveModifier } from './stavemodifier.js';
|
|
2
|
+
export var VoltaType;
|
|
3
|
+
(function (VoltaType) {
|
|
4
|
+
VoltaType[VoltaType["NONE"] = 1] = "NONE";
|
|
5
|
+
VoltaType[VoltaType["BEGIN"] = 2] = "BEGIN";
|
|
6
|
+
VoltaType[VoltaType["MID"] = 3] = "MID";
|
|
7
|
+
VoltaType[VoltaType["END"] = 4] = "END";
|
|
8
|
+
VoltaType[VoltaType["BEGIN_END"] = 5] = "BEGIN_END";
|
|
9
|
+
})(VoltaType || (VoltaType = {}));
|
|
10
|
+
export class Volta extends StaveModifier {
|
|
11
|
+
static get CATEGORY() {
|
|
12
|
+
return "Volta";
|
|
13
|
+
}
|
|
14
|
+
static get type() {
|
|
15
|
+
return VoltaType;
|
|
16
|
+
}
|
|
17
|
+
constructor(type, label, x, yShift) {
|
|
18
|
+
super();
|
|
19
|
+
this.type = type;
|
|
20
|
+
this.x = x;
|
|
21
|
+
this.yShift = yShift;
|
|
22
|
+
this.text = label;
|
|
23
|
+
}
|
|
24
|
+
draw() {
|
|
25
|
+
const stave = this.checkStave();
|
|
26
|
+
const x = stave.getModifierXShift(this.getPosition());
|
|
27
|
+
const ctx = stave.checkContext();
|
|
28
|
+
this.setRendered();
|
|
29
|
+
let width = stave.getWidth() - x;
|
|
30
|
+
const topY = stave.getYForTopText(stave.getNumLines()) + this.yShift;
|
|
31
|
+
const vertHeight = 1.5 * stave.getSpacingBetweenLines();
|
|
32
|
+
switch (this.type) {
|
|
33
|
+
case VoltaType.BEGIN:
|
|
34
|
+
ctx.fillRect(this.x + x, topY, 1, vertHeight);
|
|
35
|
+
break;
|
|
36
|
+
case VoltaType.END:
|
|
37
|
+
width -= 5;
|
|
38
|
+
ctx.fillRect(this.x + x + width, topY, 1, vertHeight);
|
|
39
|
+
break;
|
|
40
|
+
case VoltaType.BEGIN_END:
|
|
41
|
+
width -= 3;
|
|
42
|
+
ctx.fillRect(this.x + x, topY, 1, vertHeight);
|
|
43
|
+
ctx.fillRect(this.x + x + width, topY, 1, vertHeight);
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
if (this.type === VoltaType.BEGIN || this.type === VoltaType.BEGIN_END) {
|
|
49
|
+
this.renderText(ctx, x + 5, topY - this.yShift + 15);
|
|
50
|
+
}
|
|
51
|
+
ctx.fillRect(this.x + x, topY, width, 1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Metrics } from './metrics.js';
|
|
3
|
+
import { Tables } from './tables.js';
|
|
4
|
+
import { log, RuntimeError } from './util.js';
|
|
5
|
+
function L(...args) {
|
|
6
|
+
if (Stem.DEBUG)
|
|
7
|
+
log('VexFlow.Stem', args);
|
|
8
|
+
}
|
|
9
|
+
export class Stem extends Element {
|
|
10
|
+
static get CATEGORY() {
|
|
11
|
+
return "Stem";
|
|
12
|
+
}
|
|
13
|
+
static get UP() {
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
static get DOWN() {
|
|
17
|
+
return -1;
|
|
18
|
+
}
|
|
19
|
+
static get WIDTH() {
|
|
20
|
+
return Tables.STEM_WIDTH;
|
|
21
|
+
}
|
|
22
|
+
static get HEIGHT() {
|
|
23
|
+
return Tables.STEM_HEIGHT;
|
|
24
|
+
}
|
|
25
|
+
constructor(options) {
|
|
26
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
27
|
+
super();
|
|
28
|
+
this.stemUpYOffset = 0;
|
|
29
|
+
this.stemDownYOffset = 0;
|
|
30
|
+
this.stemUpYBaseOffset = 0;
|
|
31
|
+
this.stemDownYBaseOffset = 0;
|
|
32
|
+
this.xBegin = (_a = options === null || options === void 0 ? void 0 : options.xBegin) !== null && _a !== void 0 ? _a : 0;
|
|
33
|
+
this.xEnd = (_b = options === null || options === void 0 ? void 0 : options.xEnd) !== null && _b !== void 0 ? _b : 0;
|
|
34
|
+
this.yTop = (_c = options === null || options === void 0 ? void 0 : options.yTop) !== null && _c !== void 0 ? _c : 0;
|
|
35
|
+
this.yBottom = (_d = options === null || options === void 0 ? void 0 : options.yBottom) !== null && _d !== void 0 ? _d : 0;
|
|
36
|
+
this.stemExtension = (_e = options === null || options === void 0 ? void 0 : options.stemExtension) !== null && _e !== void 0 ? _e : 0;
|
|
37
|
+
this.stemDirection = (_f = options === null || options === void 0 ? void 0 : options.stemDirection) !== null && _f !== void 0 ? _f : 0;
|
|
38
|
+
this.hide = (options === null || options === void 0 ? void 0 : options.hide) || false;
|
|
39
|
+
this.isStemlet = (options === null || options === void 0 ? void 0 : options.isStemlet) || false;
|
|
40
|
+
this.stemletHeight = (_g = options === null || options === void 0 ? void 0 : options.stemletHeight) !== null && _g !== void 0 ? _g : 0;
|
|
41
|
+
this.renderHeightAdjustment = 0;
|
|
42
|
+
this.setOptions(options);
|
|
43
|
+
}
|
|
44
|
+
setOptions(options) {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
this.stemUpYOffset = (_a = options === null || options === void 0 ? void 0 : options.stemUpYOffset) !== null && _a !== void 0 ? _a : 0;
|
|
47
|
+
this.stemDownYOffset = (_b = options === null || options === void 0 ? void 0 : options.stemDownYOffset) !== null && _b !== void 0 ? _b : 0;
|
|
48
|
+
this.stemUpYBaseOffset = (_c = options === null || options === void 0 ? void 0 : options.stemUpYBaseOffset) !== null && _c !== void 0 ? _c : 0;
|
|
49
|
+
this.stemDownYBaseOffset = (_d = options === null || options === void 0 ? void 0 : options.stemDownYBaseOffset) !== null && _d !== void 0 ? _d : 0;
|
|
50
|
+
}
|
|
51
|
+
setNoteHeadXBounds(xBegin, xEnd) {
|
|
52
|
+
this.xBegin = xBegin;
|
|
53
|
+
this.xEnd = xEnd;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
setDirection(direction) {
|
|
57
|
+
this.stemDirection = direction;
|
|
58
|
+
}
|
|
59
|
+
setExtension(ext) {
|
|
60
|
+
this.stemExtension = ext;
|
|
61
|
+
}
|
|
62
|
+
getExtension() {
|
|
63
|
+
return this.stemExtension;
|
|
64
|
+
}
|
|
65
|
+
setYBounds(yTop, yBottom) {
|
|
66
|
+
this.yTop = yTop;
|
|
67
|
+
this.yBottom = yBottom;
|
|
68
|
+
}
|
|
69
|
+
getHeight() {
|
|
70
|
+
const yOffset = this.stemDirection === Stem.UP ? this.stemUpYOffset : this.stemDownYOffset;
|
|
71
|
+
const unsignedHeight = this.yBottom - this.yTop + (Stem.HEIGHT - yOffset + this.stemExtension);
|
|
72
|
+
return unsignedHeight * this.stemDirection;
|
|
73
|
+
}
|
|
74
|
+
getBoundingBox() {
|
|
75
|
+
throw new RuntimeError('NotImplemented', 'getBoundingBox() not implemented.');
|
|
76
|
+
}
|
|
77
|
+
getExtents() {
|
|
78
|
+
const isStemUp = this.stemDirection === Stem.UP;
|
|
79
|
+
const ys = [this.yTop, this.yBottom];
|
|
80
|
+
const stemHeight = Stem.HEIGHT + this.stemExtension;
|
|
81
|
+
const innerMostNoteheadY = (isStemUp ? Math.min : Math.max)(...ys);
|
|
82
|
+
const outerMostNoteheadY = (isStemUp ? Math.max : Math.min)(...ys);
|
|
83
|
+
const stemTipY = innerMostNoteheadY + stemHeight * -this.stemDirection;
|
|
84
|
+
return { topY: stemTipY, baseY: outerMostNoteheadY };
|
|
85
|
+
}
|
|
86
|
+
setVisibility(isVisible) {
|
|
87
|
+
this.hide = !isVisible;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
setStemlet(isStemlet, stemletHeight) {
|
|
91
|
+
this.isStemlet = isStemlet;
|
|
92
|
+
this.stemletHeight = stemletHeight;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
adjustHeightForFlag() {
|
|
96
|
+
this.renderHeightAdjustment = Metrics.get('Stem.heightAdjustmentForFlag', -3);
|
|
97
|
+
}
|
|
98
|
+
adjustHeightForBeam() {
|
|
99
|
+
this.renderHeightAdjustment = -Stem.WIDTH / 2;
|
|
100
|
+
}
|
|
101
|
+
draw() {
|
|
102
|
+
this.setRendered();
|
|
103
|
+
if (this.hide)
|
|
104
|
+
return;
|
|
105
|
+
const ctx = this.checkContext();
|
|
106
|
+
let stemX;
|
|
107
|
+
let stemY;
|
|
108
|
+
const stemDirection = this.stemDirection;
|
|
109
|
+
let yBaseOffset = 0;
|
|
110
|
+
if (stemDirection === Stem.DOWN) {
|
|
111
|
+
stemX = this.xBegin;
|
|
112
|
+
stemY = this.yTop + this.stemDownYOffset;
|
|
113
|
+
yBaseOffset = this.stemDownYBaseOffset;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
stemX = this.xEnd;
|
|
117
|
+
stemY = this.yBottom - this.stemUpYOffset;
|
|
118
|
+
yBaseOffset = this.stemUpYBaseOffset;
|
|
119
|
+
}
|
|
120
|
+
const stemHeight = this.getHeight();
|
|
121
|
+
L('Rendering stem - ', 'Top Y: ', this.yTop, 'Bottom Y: ', this.yBottom);
|
|
122
|
+
const stemletYOffset = this.isStemlet ? stemHeight - this.stemletHeight * this.stemDirection : 0;
|
|
123
|
+
const clsAttribute = this.getAttribute('class');
|
|
124
|
+
ctx.openGroup('stem' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
125
|
+
ctx.beginPath();
|
|
126
|
+
ctx.setLineWidth(Stem.WIDTH);
|
|
127
|
+
ctx.moveTo(stemX, stemY - stemletYOffset + yBaseOffset);
|
|
128
|
+
ctx.lineTo(stemX, stemY - stemHeight - this.renderHeightAdjustment * stemDirection);
|
|
129
|
+
ctx.stroke();
|
|
130
|
+
ctx.closeGroup();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
Stem.DEBUG = false;
|