@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,278 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Glyphs } from './glyphs.js';
|
|
3
|
+
import { Modifier } from './modifier.js';
|
|
4
|
+
import { Note } from './note.js';
|
|
5
|
+
import { Stem } from './stem.js';
|
|
6
|
+
import { StemmableNote } from './stemmablenote.js';
|
|
7
|
+
import { isDot } from './typeguard.js';
|
|
8
|
+
import { defined, RuntimeError } from './util.js';
|
|
9
|
+
function getUnusedStringGroups(numLines, stringsUsed) {
|
|
10
|
+
const stemThrough = [];
|
|
11
|
+
let group = [];
|
|
12
|
+
for (let string = 1; string <= numLines; string++) {
|
|
13
|
+
const isUsed = stringsUsed.indexOf(string) > -1;
|
|
14
|
+
if (!isUsed) {
|
|
15
|
+
group.push(string);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
stemThrough.push(group);
|
|
19
|
+
group = [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (group.length > 0)
|
|
23
|
+
stemThrough.push(group);
|
|
24
|
+
return stemThrough;
|
|
25
|
+
}
|
|
26
|
+
function getPartialStemLines(stemY, unusedStrings, stave, stemDirection) {
|
|
27
|
+
const upStem = stemDirection !== 1;
|
|
28
|
+
const downStem = stemDirection !== -1;
|
|
29
|
+
const lineSpacing = stave.getSpacingBetweenLines();
|
|
30
|
+
const totalLines = stave.getNumLines();
|
|
31
|
+
const stemLines = [];
|
|
32
|
+
unusedStrings.forEach((strings) => {
|
|
33
|
+
const containsLastString = strings.indexOf(totalLines) > -1;
|
|
34
|
+
const containsFirstString = strings.indexOf(1) > -1;
|
|
35
|
+
if ((upStem && containsFirstString) || (downStem && containsLastString)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (strings.length === 1) {
|
|
39
|
+
strings.push(strings[0]);
|
|
40
|
+
}
|
|
41
|
+
const lineYs = [];
|
|
42
|
+
strings.forEach((string, index, strings) => {
|
|
43
|
+
const isTopBound = string === 1;
|
|
44
|
+
const isBottomBound = string === totalLines;
|
|
45
|
+
let y = stave.getYForLine(string - 1);
|
|
46
|
+
if (index === 0 && !isTopBound) {
|
|
47
|
+
y -= lineSpacing / 2 - 1;
|
|
48
|
+
}
|
|
49
|
+
else if (index === strings.length - 1 && !isBottomBound) {
|
|
50
|
+
y += lineSpacing / 2 - 1;
|
|
51
|
+
}
|
|
52
|
+
lineYs.push(y);
|
|
53
|
+
if (stemDirection === 1 && isTopBound) {
|
|
54
|
+
lineYs.push(stemY - 2);
|
|
55
|
+
}
|
|
56
|
+
else if (stemDirection === -1 && isBottomBound) {
|
|
57
|
+
lineYs.push(stemY + 2);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
stemLines.push(lineYs.sort((a, b) => a - b));
|
|
61
|
+
});
|
|
62
|
+
return stemLines;
|
|
63
|
+
}
|
|
64
|
+
export class TabNote extends StemmableNote {
|
|
65
|
+
static get CATEGORY() {
|
|
66
|
+
return "TabNote";
|
|
67
|
+
}
|
|
68
|
+
constructor(noteStruct, drawStem = false) {
|
|
69
|
+
super(noteStruct);
|
|
70
|
+
this.fretElement = [];
|
|
71
|
+
this.greatestString = () => {
|
|
72
|
+
return this.positions.map((x) => x.str).reduce((a, b) => (a > b ? a : b));
|
|
73
|
+
};
|
|
74
|
+
this.leastString = () => {
|
|
75
|
+
return this.positions.map((x) => x.str).reduce((a, b) => (a < b ? a : b));
|
|
76
|
+
};
|
|
77
|
+
this.ghost = false;
|
|
78
|
+
this.positions = noteStruct.positions || [];
|
|
79
|
+
this.renderOptions = Object.assign(Object.assign({}, this.renderOptions), { drawStem, drawDots: drawStem, drawStemThroughStave: false, yShift: 0 });
|
|
80
|
+
this.glyphProps = Note.getGlyphProps(this.duration, this.noteType);
|
|
81
|
+
defined(this.glyphProps, 'BadArguments', `No glyph found for duration '${this.duration}' and type '${this.noteType}'`);
|
|
82
|
+
this.buildStem();
|
|
83
|
+
if (noteStruct.stemDirection) {
|
|
84
|
+
this.setStemDirection(noteStruct.stemDirection);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.setStemDirection(Stem.UP);
|
|
88
|
+
}
|
|
89
|
+
this.ghost = false;
|
|
90
|
+
this.updateWidth();
|
|
91
|
+
}
|
|
92
|
+
reset() {
|
|
93
|
+
super.reset();
|
|
94
|
+
if (this.stave)
|
|
95
|
+
this.setStave(this.stave);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
setGhost(ghost) {
|
|
99
|
+
this.ghost = ghost;
|
|
100
|
+
this.updateWidth();
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
hasStem() {
|
|
104
|
+
if (this.renderOptions.drawStem)
|
|
105
|
+
return true;
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
getStemExtension() {
|
|
109
|
+
if (this.stemExtensionOverride !== undefined) {
|
|
110
|
+
return this.stemExtensionOverride;
|
|
111
|
+
}
|
|
112
|
+
return this.flag.getHeight() > Stem.HEIGHT ? this.flag.getHeight() - Stem.HEIGHT : 0;
|
|
113
|
+
}
|
|
114
|
+
static tabToElement(fret) {
|
|
115
|
+
let el;
|
|
116
|
+
if (fret.toUpperCase() === 'X') {
|
|
117
|
+
el = new Element('TabNote');
|
|
118
|
+
el.setText(Glyphs.accidentalDoubleSharp);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
el = new Element('TabNote.text');
|
|
122
|
+
el.setText(fret);
|
|
123
|
+
el.setYShift(el.getHeight() / 2);
|
|
124
|
+
}
|
|
125
|
+
return el;
|
|
126
|
+
}
|
|
127
|
+
updateWidth() {
|
|
128
|
+
this.fretElement = [];
|
|
129
|
+
this.width = 0;
|
|
130
|
+
for (let i = 0; i < this.positions.length; ++i) {
|
|
131
|
+
let fret = this.positions[i].fret;
|
|
132
|
+
if (this.ghost)
|
|
133
|
+
fret = '(' + fret + ')';
|
|
134
|
+
const el = TabNote.tabToElement(fret.toString());
|
|
135
|
+
this.fretElement.push(el);
|
|
136
|
+
this.width = Math.max(el.getWidth(), this.width);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
setStave(stave) {
|
|
140
|
+
super.setStave(stave);
|
|
141
|
+
const ctx = stave.getContext();
|
|
142
|
+
this.setContext(ctx);
|
|
143
|
+
const ys = this.positions.map(({ str: line }) => stave.getYForLine(Number(line) - 1));
|
|
144
|
+
this.setYs(ys);
|
|
145
|
+
if (this.stem) {
|
|
146
|
+
this.stem.setYBounds(this.getStemY(), this.getStemY());
|
|
147
|
+
}
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
getPositions() {
|
|
151
|
+
return this.positions;
|
|
152
|
+
}
|
|
153
|
+
getModifierStartXY(position, index) {
|
|
154
|
+
if (!this.preFormatted) {
|
|
155
|
+
throw new RuntimeError('UnformattedNote', "Can't call GetModifierStartXY on an unformatted note");
|
|
156
|
+
}
|
|
157
|
+
if (this.ys.length === 0) {
|
|
158
|
+
throw new RuntimeError('NoYValues', 'No Y-Values calculated for this note.');
|
|
159
|
+
}
|
|
160
|
+
let x = 0;
|
|
161
|
+
if (position === Modifier.Position.LEFT) {
|
|
162
|
+
x = -1 * 2;
|
|
163
|
+
}
|
|
164
|
+
else if (position === Modifier.Position.RIGHT) {
|
|
165
|
+
x = this.width + 2;
|
|
166
|
+
}
|
|
167
|
+
else if (position === Modifier.Position.BELOW || position === Modifier.Position.ABOVE) {
|
|
168
|
+
const noteGlyphWidth = this.width;
|
|
169
|
+
x = noteGlyphWidth / 2;
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
x: this.getAbsoluteX() + x,
|
|
173
|
+
y: this.ys[index],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
getLineForRest() {
|
|
177
|
+
return Number(this.positions[0].str);
|
|
178
|
+
}
|
|
179
|
+
preFormat() {
|
|
180
|
+
if (this.preFormatted)
|
|
181
|
+
return;
|
|
182
|
+
if (this.modifierContext)
|
|
183
|
+
this.modifierContext.preFormat();
|
|
184
|
+
this.preFormatted = true;
|
|
185
|
+
}
|
|
186
|
+
getStemX() {
|
|
187
|
+
return this.getCenterGlyphX();
|
|
188
|
+
}
|
|
189
|
+
getStemY() {
|
|
190
|
+
const numLines = this.checkStave().getNumLines();
|
|
191
|
+
const stemUpLine = -0.5;
|
|
192
|
+
const stemDownLine = numLines - 0.5;
|
|
193
|
+
const stemStartLine = Stem.UP === this.stemDirection ? stemUpLine : stemDownLine;
|
|
194
|
+
return this.checkStave().getYForLine(stemStartLine);
|
|
195
|
+
}
|
|
196
|
+
getStemExtents() {
|
|
197
|
+
return this.checkStem().getExtents();
|
|
198
|
+
}
|
|
199
|
+
drawFlag() {
|
|
200
|
+
const { beam, glyphProps, renderOptions: { drawStem }, } = this;
|
|
201
|
+
const context = this.checkContext();
|
|
202
|
+
const shouldDrawFlag = beam === undefined && drawStem;
|
|
203
|
+
if (glyphProps.codeFlagUp && shouldDrawFlag) {
|
|
204
|
+
const flagX = this.getStemX();
|
|
205
|
+
const flagY = this.getStemDirection() === Stem.DOWN
|
|
206
|
+
?
|
|
207
|
+
this.getStemY() - this.checkStem().getHeight() - this.getStemExtension()
|
|
208
|
+
:
|
|
209
|
+
this.getStemY() - this.checkStem().getHeight() + this.getStemExtension();
|
|
210
|
+
this.flag.setContext(context).setX(flagX).setY(flagY).drawWithStyle();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
drawModifiers() {
|
|
214
|
+
this.modifiers.forEach((modifier) => {
|
|
215
|
+
if (isDot(modifier) && !this.renderOptions.drawDots) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
modifier.setContext(this.getContext());
|
|
219
|
+
modifier.drawWithStyle();
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
drawStemThrough() {
|
|
223
|
+
const stemX = this.getStemX();
|
|
224
|
+
const stemY = this.getStemY();
|
|
225
|
+
const ctx = this.checkContext();
|
|
226
|
+
const drawStem = this.renderOptions.drawStem;
|
|
227
|
+
const stemThrough = this.renderOptions.drawStemThroughStave;
|
|
228
|
+
if (drawStem && stemThrough) {
|
|
229
|
+
const numLines = this.checkStave().getNumLines();
|
|
230
|
+
const stringsUsed = this.positions.map((position) => Number(position.str));
|
|
231
|
+
const unusedStrings = getUnusedStringGroups(numLines, stringsUsed);
|
|
232
|
+
const stemLines = getPartialStemLines(stemY, unusedStrings, this.checkStave(), this.getStemDirection());
|
|
233
|
+
ctx.setLineWidth(Stem.WIDTH);
|
|
234
|
+
stemLines.forEach((bounds) => {
|
|
235
|
+
if (bounds.length === 0)
|
|
236
|
+
return;
|
|
237
|
+
ctx.beginPath();
|
|
238
|
+
ctx.moveTo(stemX, bounds[0]);
|
|
239
|
+
ctx.lineTo(stemX, bounds[bounds.length - 1]);
|
|
240
|
+
ctx.stroke();
|
|
241
|
+
ctx.closePath();
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
drawPositions() {
|
|
246
|
+
const ctx = this.checkContext();
|
|
247
|
+
const x = this.getAbsoluteX();
|
|
248
|
+
const ys = this.ys;
|
|
249
|
+
for (let i = 0; i < this.positions.length; ++i) {
|
|
250
|
+
const y = ys[i] + this.renderOptions.yShift;
|
|
251
|
+
const el = this.fretElement[i];
|
|
252
|
+
const tabX = x - el.getWidth() / 2;
|
|
253
|
+
ctx.clearRect(tabX - 2, y - 3, el.getWidth() + 4, 6);
|
|
254
|
+
el.renderText(ctx, tabX, y);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
draw() {
|
|
258
|
+
const ctx = this.checkContext();
|
|
259
|
+
if (this.ys.length === 0) {
|
|
260
|
+
throw new RuntimeError('NoYValues', "Can't draw note without Y values.");
|
|
261
|
+
}
|
|
262
|
+
this.setRendered();
|
|
263
|
+
const renderStem = this.beam === undefined && this.renderOptions.drawStem;
|
|
264
|
+
const clsAttribute = this.getAttribute('class');
|
|
265
|
+
ctx.openGroup('tabnote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
266
|
+
this.drawPositions();
|
|
267
|
+
this.drawStemThrough();
|
|
268
|
+
if (this.stem && renderStem) {
|
|
269
|
+
const stemX = this.getStemX();
|
|
270
|
+
this.stem.setNoteHeadXBounds(stemX, stemX);
|
|
271
|
+
this.stem.setContext(ctx).drawWithStyle();
|
|
272
|
+
}
|
|
273
|
+
this.drawFlag();
|
|
274
|
+
this.drawModifiers();
|
|
275
|
+
this.drawPointerRect();
|
|
276
|
+
ctx.closeGroup();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { TabTie } from './tabtie.js';
|
|
2
|
+
import { RuntimeError } from './util.js';
|
|
3
|
+
export class TabSlide extends TabTie {
|
|
4
|
+
static get CATEGORY() {
|
|
5
|
+
return "TabSlide";
|
|
6
|
+
}
|
|
7
|
+
static get SLIDE_UP() {
|
|
8
|
+
return 1;
|
|
9
|
+
}
|
|
10
|
+
static get SLIDE_DOWN() {
|
|
11
|
+
return -1;
|
|
12
|
+
}
|
|
13
|
+
static createSlideUp(notes) {
|
|
14
|
+
return new TabSlide(notes, TabSlide.SLIDE_UP);
|
|
15
|
+
}
|
|
16
|
+
static createSlideDown(notes) {
|
|
17
|
+
return new TabSlide(notes, TabSlide.SLIDE_DOWN);
|
|
18
|
+
}
|
|
19
|
+
constructor(notes, direction) {
|
|
20
|
+
super(notes, 'sl.');
|
|
21
|
+
if (!direction) {
|
|
22
|
+
let firstFret = notes.firstNote.getPositions()[0].fret;
|
|
23
|
+
if (typeof firstFret === 'string') {
|
|
24
|
+
firstFret = parseInt(firstFret, 10);
|
|
25
|
+
}
|
|
26
|
+
let lastFret = notes.lastNote.getPositions()[0].fret;
|
|
27
|
+
if (typeof lastFret === 'string') {
|
|
28
|
+
lastFret = parseInt(lastFret, 10);
|
|
29
|
+
}
|
|
30
|
+
if (isNaN(firstFret) || isNaN(lastFret)) {
|
|
31
|
+
direction = TabSlide.SLIDE_UP;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
direction = firstFret > lastFret ? TabSlide.SLIDE_DOWN : TabSlide.SLIDE_UP;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.direction = direction;
|
|
38
|
+
this.renderOptions.cp1 = 11;
|
|
39
|
+
this.renderOptions.cp2 = 14;
|
|
40
|
+
this.renderOptions.yShift = 0.5;
|
|
41
|
+
}
|
|
42
|
+
renderTie(params) {
|
|
43
|
+
if (params.firstYs.length === 0 || params.lastYs.length === 0) {
|
|
44
|
+
throw new RuntimeError('BadArguments', 'No Y-values to render');
|
|
45
|
+
}
|
|
46
|
+
const ctx = this.checkContext();
|
|
47
|
+
const firstX = params.firstX;
|
|
48
|
+
const firstYs = params.firstYs;
|
|
49
|
+
const lastX = params.lastX;
|
|
50
|
+
const direction = params.direction;
|
|
51
|
+
if (direction !== TabSlide.SLIDE_UP && direction !== TabSlide.SLIDE_DOWN) {
|
|
52
|
+
throw new RuntimeError('BadSlide', 'Invalid slide direction');
|
|
53
|
+
}
|
|
54
|
+
const firstIndexes = this.notes.firstIndexes;
|
|
55
|
+
for (let i = 0; i < firstIndexes.length; ++i) {
|
|
56
|
+
const slideY = firstYs[firstIndexes[i]] + this.renderOptions.yShift;
|
|
57
|
+
if (isNaN(slideY)) {
|
|
58
|
+
throw new RuntimeError('BadArguments', 'Bad indexes for slide rendering.');
|
|
59
|
+
}
|
|
60
|
+
ctx.beginPath();
|
|
61
|
+
ctx.moveTo(firstX, slideY + 3 * direction);
|
|
62
|
+
ctx.lineTo(lastX, slideY - 3 * direction);
|
|
63
|
+
ctx.closePath();
|
|
64
|
+
ctx.stroke();
|
|
65
|
+
}
|
|
66
|
+
this.setRendered();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Stave } from './stave.js';
|
|
2
|
+
export class TabStave extends Stave {
|
|
3
|
+
static get CATEGORY() {
|
|
4
|
+
return "TabStave";
|
|
5
|
+
}
|
|
6
|
+
constructor(x, y, width, options) {
|
|
7
|
+
const tabOptions = Object.assign({ spacingBetweenLinesPx: 13, numLines: 6, topTextPosition: 1 }, options);
|
|
8
|
+
super(x, y, width, tabOptions);
|
|
9
|
+
}
|
|
10
|
+
getYForGlyphs() {
|
|
11
|
+
return this.getYForLine(2.5);
|
|
12
|
+
}
|
|
13
|
+
addTabGlyph() {
|
|
14
|
+
this.addClef('tab');
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StaveTie } from './stavetie.js';
|
|
2
|
+
export class TabTie extends StaveTie {
|
|
3
|
+
static get CATEGORY() {
|
|
4
|
+
return "TabTie";
|
|
5
|
+
}
|
|
6
|
+
static createHammeron(notes) {
|
|
7
|
+
return new TabTie(notes, 'H');
|
|
8
|
+
}
|
|
9
|
+
static createPulloff(notes) {
|
|
10
|
+
return new TabTie(notes, 'P');
|
|
11
|
+
}
|
|
12
|
+
constructor(notes, text) {
|
|
13
|
+
super(notes, text);
|
|
14
|
+
this.renderOptions.cp1 = 9;
|
|
15
|
+
this.renderOptions.cp2 = 11;
|
|
16
|
+
this.renderOptions.yShift = 3;
|
|
17
|
+
this.direction = -1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Font } from './font.js';
|
|
3
|
+
import { Renderer } from './renderer.js';
|
|
4
|
+
import { Tables } from './tables.js';
|
|
5
|
+
import { log, RuntimeError } from './util.js';
|
|
6
|
+
function L(...args) {
|
|
7
|
+
if (TextBracket.DEBUG)
|
|
8
|
+
log('VexFlow.TextBracket', args);
|
|
9
|
+
}
|
|
10
|
+
export var TextBracketPosition;
|
|
11
|
+
(function (TextBracketPosition) {
|
|
12
|
+
TextBracketPosition[TextBracketPosition["TOP"] = 1] = "TOP";
|
|
13
|
+
TextBracketPosition[TextBracketPosition["BOTTOM"] = -1] = "BOTTOM";
|
|
14
|
+
})(TextBracketPosition || (TextBracketPosition = {}));
|
|
15
|
+
export class TextBracket extends Element {
|
|
16
|
+
static get CATEGORY() {
|
|
17
|
+
return "TextBracket";
|
|
18
|
+
}
|
|
19
|
+
static get Position() {
|
|
20
|
+
return TextBracketPosition;
|
|
21
|
+
}
|
|
22
|
+
static get PositionString() {
|
|
23
|
+
return {
|
|
24
|
+
top: TextBracketPosition.TOP,
|
|
25
|
+
bottom: TextBracketPosition.BOTTOM,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
constructor({ start, stop, text = '', superscript = '', position = TextBracketPosition.TOP }) {
|
|
29
|
+
super();
|
|
30
|
+
this.start = start;
|
|
31
|
+
this.stop = stop;
|
|
32
|
+
this.textElement = new Element('TextBracket');
|
|
33
|
+
this.textElement.setText(text);
|
|
34
|
+
this.superscriptElement = new Element('TextBracket');
|
|
35
|
+
this.superscriptElement.setText(superscript);
|
|
36
|
+
const smallerFontSize = Font.scaleSize(this.fontInfo.size, 0.714286);
|
|
37
|
+
this.superscriptElement.setFontSize(smallerFontSize);
|
|
38
|
+
this.position = typeof position === 'string' ? TextBracket.PositionString[position] : position;
|
|
39
|
+
this.line = 1;
|
|
40
|
+
this.renderOptions = {
|
|
41
|
+
dashed: true,
|
|
42
|
+
dash: [5],
|
|
43
|
+
color: 'black',
|
|
44
|
+
lineWidth: 1,
|
|
45
|
+
showBracket: true,
|
|
46
|
+
bracketHeight: 8,
|
|
47
|
+
underlineSuperscript: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
applyStyle(ctx) {
|
|
51
|
+
this.textElement.setFont(this.fontInfo);
|
|
52
|
+
const { family, size, weight, style } = this.fontInfo;
|
|
53
|
+
const smallerFontSize = Font.scaleSize(size, 0.714286);
|
|
54
|
+
this.superscriptElement.setFont(family, smallerFontSize, weight, style);
|
|
55
|
+
const options = this.renderOptions;
|
|
56
|
+
ctx.setStrokeStyle(options.color);
|
|
57
|
+
ctx.setFillStyle(options.color);
|
|
58
|
+
ctx.setLineWidth(options.lineWidth);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
setDashed(dashed, dash) {
|
|
62
|
+
this.renderOptions.dashed = dashed;
|
|
63
|
+
if (dash)
|
|
64
|
+
this.renderOptions.dash = dash;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
setLine(line) {
|
|
68
|
+
this.line = line;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
draw() {
|
|
72
|
+
const ctx = this.checkContext();
|
|
73
|
+
this.setRendered();
|
|
74
|
+
let y = 0;
|
|
75
|
+
switch (this.position) {
|
|
76
|
+
case TextBracketPosition.TOP:
|
|
77
|
+
y = this.start.checkStave().getYForTopText(this.line);
|
|
78
|
+
break;
|
|
79
|
+
case TextBracketPosition.BOTTOM:
|
|
80
|
+
y = this.start.checkStave().getYForBottomText(this.line + Tables.TEXT_HEIGHT_OFFSET_HACK);
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
throw new RuntimeError('InvalidPosition', `The position ${this.position} is invalid.`);
|
|
84
|
+
}
|
|
85
|
+
const start = { x: this.start.getAbsoluteX(), y };
|
|
86
|
+
const stop = { x: this.stop.getAbsoluteX(), y };
|
|
87
|
+
L('Rendering TextBracket: start:', start, 'stop:', stop, 'y:', y);
|
|
88
|
+
const bracketHeight = this.renderOptions.bracketHeight * this.position;
|
|
89
|
+
this.textElement.renderText(ctx, start.x, start.y);
|
|
90
|
+
const mainWidth = this.textElement.getWidth();
|
|
91
|
+
const mainHeight = this.textElement.getHeight();
|
|
92
|
+
const superY = start.y - mainHeight / 2.5;
|
|
93
|
+
this.superscriptElement.renderText(ctx, start.x + mainWidth + 1, superY);
|
|
94
|
+
const superWidth = this.superscriptElement.getWidth();
|
|
95
|
+
const superHeight = this.superscriptElement.getHeight();
|
|
96
|
+
let startX = start.x;
|
|
97
|
+
let lineY = superY;
|
|
98
|
+
const endX = stop.x + this.stop.getGlyphWidth();
|
|
99
|
+
if (this.position === TextBracketPosition.TOP) {
|
|
100
|
+
startX += mainWidth + superWidth + 5;
|
|
101
|
+
lineY -= superHeight / 2.7;
|
|
102
|
+
}
|
|
103
|
+
else if (this.position === TextBracketPosition.BOTTOM) {
|
|
104
|
+
lineY += superHeight / 2.7;
|
|
105
|
+
startX += mainWidth + 2;
|
|
106
|
+
if (!this.renderOptions.underlineSuperscript) {
|
|
107
|
+
startX += superWidth;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (this.renderOptions.dashed) {
|
|
111
|
+
Renderer.drawDashedLine(ctx, startX, lineY, endX, lineY, this.renderOptions.dash);
|
|
112
|
+
if (this.renderOptions.showBracket) {
|
|
113
|
+
Renderer.drawDashedLine(ctx, endX, lineY + 1 * this.position, endX, lineY + bracketHeight, this.renderOptions.dash);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
ctx.beginPath();
|
|
118
|
+
ctx.moveTo(startX, lineY);
|
|
119
|
+
ctx.lineTo(endX, lineY);
|
|
120
|
+
if (this.renderOptions.showBracket) {
|
|
121
|
+
ctx.lineTo(endX, lineY + bracketHeight);
|
|
122
|
+
}
|
|
123
|
+
ctx.stroke();
|
|
124
|
+
ctx.closePath();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
TextBracket.DEBUG = false;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Glyphs } from './glyphs.js';
|
|
2
|
+
import { Note } from './note.js';
|
|
3
|
+
import { log, RuntimeError } from './util.js';
|
|
4
|
+
function L(...args) {
|
|
5
|
+
if (TextDynamics.DEBUG)
|
|
6
|
+
log('VexFlow.TextDynamics', args);
|
|
7
|
+
}
|
|
8
|
+
export class TextDynamics extends Note {
|
|
9
|
+
static get CATEGORY() {
|
|
10
|
+
return "TextDynamics";
|
|
11
|
+
}
|
|
12
|
+
static get GLYPHS() {
|
|
13
|
+
return {
|
|
14
|
+
f: Glyphs.dynamicForte,
|
|
15
|
+
p: Glyphs.dynamicPiano,
|
|
16
|
+
m: Glyphs.dynamicMezzo,
|
|
17
|
+
s: Glyphs.dynamicSforzando,
|
|
18
|
+
z: Glyphs.dynamicZ,
|
|
19
|
+
r: Glyphs.dynamicRinforzando,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
constructor(noteStruct) {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
super(noteStruct);
|
|
25
|
+
this.sequence = ((_a = noteStruct.text) !== null && _a !== void 0 ? _a : '').toLowerCase();
|
|
26
|
+
this.line = (_b = noteStruct.line) !== null && _b !== void 0 ? _b : 0;
|
|
27
|
+
this.text = '';
|
|
28
|
+
L('New Dynamics Text: ', this.sequence);
|
|
29
|
+
}
|
|
30
|
+
setLine(line) {
|
|
31
|
+
this.line = line;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
preFormat() {
|
|
35
|
+
this.text = '';
|
|
36
|
+
this.sequence.split('').forEach((letter) => {
|
|
37
|
+
const glyph = TextDynamics.GLYPHS[letter];
|
|
38
|
+
if (!glyph)
|
|
39
|
+
throw new RuntimeError('Invalid dynamics character: ' + letter);
|
|
40
|
+
this.text += glyph;
|
|
41
|
+
});
|
|
42
|
+
this.preFormatted = true;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
draw() {
|
|
46
|
+
this.setRendered();
|
|
47
|
+
const x = this.getAbsoluteX();
|
|
48
|
+
const y = this.checkStave().getYForLine(this.line + -3);
|
|
49
|
+
L('Rendering Dynamics: ', this.sequence);
|
|
50
|
+
this.renderText(this.checkContext(), x, y);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
TextDynamics.DEBUG = false;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Font } from './font.js';
|
|
3
|
+
import { Glyphs } from './glyphs.js';
|
|
4
|
+
import { Metrics } from './metrics.js';
|
|
5
|
+
import { Note } from './note.js';
|
|
6
|
+
export var TextJustification;
|
|
7
|
+
(function (TextJustification) {
|
|
8
|
+
TextJustification[TextJustification["LEFT"] = 1] = "LEFT";
|
|
9
|
+
TextJustification[TextJustification["CENTER"] = 2] = "CENTER";
|
|
10
|
+
TextJustification[TextJustification["RIGHT"] = 3] = "RIGHT";
|
|
11
|
+
})(TextJustification || (TextJustification = {}));
|
|
12
|
+
export class TextNote extends Note {
|
|
13
|
+
static get CATEGORY() {
|
|
14
|
+
return "TextNote";
|
|
15
|
+
}
|
|
16
|
+
static get GLYPHS() {
|
|
17
|
+
return {
|
|
18
|
+
segno: Glyphs.segno,
|
|
19
|
+
tr: Glyphs.ornamentTrill,
|
|
20
|
+
mordent: Glyphs.ornamentMordent,
|
|
21
|
+
mordentUpper: Glyphs.ornamentShortTrill,
|
|
22
|
+
mordentLower: Glyphs.ornamentMordent,
|
|
23
|
+
f: Glyphs.dynamicForte,
|
|
24
|
+
p: Glyphs.dynamicPiano,
|
|
25
|
+
m: Glyphs.dynamicMezzo,
|
|
26
|
+
s: Glyphs.dynamicSforzando,
|
|
27
|
+
z: Glyphs.dynamicZ,
|
|
28
|
+
coda: Glyphs.coda,
|
|
29
|
+
pedalOpen: Glyphs.keyboardPedalPed,
|
|
30
|
+
pedalClose: Glyphs.keyboardPedalUp,
|
|
31
|
+
caesuraStraight: Glyphs.caesura,
|
|
32
|
+
caesuraCurved: Glyphs.caesuraCurved,
|
|
33
|
+
breath: Glyphs.breathMarkComma,
|
|
34
|
+
tick: Glyphs.breathMarkTick,
|
|
35
|
+
turn: Glyphs.ornamentTurn,
|
|
36
|
+
turnInverted: Glyphs.ornamentTurnSlash,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
constructor(noteStruct) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
super(noteStruct);
|
|
42
|
+
this.text = (_a = noteStruct.text) !== null && _a !== void 0 ? _a : '';
|
|
43
|
+
if (noteStruct.glyph) {
|
|
44
|
+
this.text += TextNote.GLYPHS[noteStruct.glyph] || noteStruct.glyph;
|
|
45
|
+
}
|
|
46
|
+
if (noteStruct.font) {
|
|
47
|
+
this.setFont(noteStruct.font);
|
|
48
|
+
}
|
|
49
|
+
else if (noteStruct.glyph === undefined) {
|
|
50
|
+
this.setFont(Metrics.getFontInfo('TextNote.text.fontSize'));
|
|
51
|
+
}
|
|
52
|
+
const smallerFontSize = Font.convertSizeToPointValue(this.fontInfo.size) * 0.769231;
|
|
53
|
+
if (noteStruct.superscript) {
|
|
54
|
+
this.superscript = new Element('TexNote.subSuper');
|
|
55
|
+
this.superscript.setText(noteStruct.superscript);
|
|
56
|
+
this.superscript.setFontSize(smallerFontSize);
|
|
57
|
+
}
|
|
58
|
+
if (noteStruct.subscript) {
|
|
59
|
+
this.subscript = new Element('TexNote.subSuper');
|
|
60
|
+
this.subscript.setText(noteStruct.subscript);
|
|
61
|
+
this.subscript.setFontSize(smallerFontSize);
|
|
62
|
+
}
|
|
63
|
+
this.line = (_b = noteStruct.line) !== null && _b !== void 0 ? _b : 0;
|
|
64
|
+
this.smooth = noteStruct.smooth || false;
|
|
65
|
+
this.ignoreTicks = noteStruct.ignoreTicks || false;
|
|
66
|
+
this.justification = TextJustification.LEFT;
|
|
67
|
+
}
|
|
68
|
+
setJustification(just) {
|
|
69
|
+
this.justification = just;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
setLine(line) {
|
|
73
|
+
this.line = line;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
getLine() {
|
|
77
|
+
return this.line;
|
|
78
|
+
}
|
|
79
|
+
preFormat() {
|
|
80
|
+
if (this.preFormatted)
|
|
81
|
+
return;
|
|
82
|
+
const tickContext = this.checkTickContext(`Can't preformat without a TickContext.`);
|
|
83
|
+
if (this.justification === TextJustification.CENTER) {
|
|
84
|
+
this.leftDisplacedHeadPx = this.width / 2;
|
|
85
|
+
}
|
|
86
|
+
else if (this.justification === TextJustification.RIGHT) {
|
|
87
|
+
this.leftDisplacedHeadPx = this.width;
|
|
88
|
+
}
|
|
89
|
+
this.rightDisplacedHeadPx = tickContext.getMetrics().glyphPx / 2;
|
|
90
|
+
this.preFormatted = true;
|
|
91
|
+
}
|
|
92
|
+
draw() {
|
|
93
|
+
const ctx = this.checkContext();
|
|
94
|
+
const stave = this.checkStave();
|
|
95
|
+
const tickContext = this.checkTickContext(`Can't draw without a TickContext.`);
|
|
96
|
+
this.setRendered();
|
|
97
|
+
let x = this.getAbsoluteX() + tickContext.getMetrics().glyphPx / 2;
|
|
98
|
+
const width = this.getWidth();
|
|
99
|
+
if (this.justification === TextJustification.CENTER) {
|
|
100
|
+
x -= width / 2;
|
|
101
|
+
}
|
|
102
|
+
else if (this.justification === TextJustification.RIGHT) {
|
|
103
|
+
x -= width;
|
|
104
|
+
}
|
|
105
|
+
const y = stave.getYForLine(this.line + -3);
|
|
106
|
+
this.renderText(ctx, x, y);
|
|
107
|
+
const height = this.getHeight();
|
|
108
|
+
if (this.superscript) {
|
|
109
|
+
this.superscript.renderText(ctx, x + this.width + 2, y - height / 2.2);
|
|
110
|
+
}
|
|
111
|
+
if (this.subscript) {
|
|
112
|
+
this.subscript.renderText(ctx, x + this.width + 2, y + height / 2.2 - 1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
TextNote.Justification = TextJustification;
|