@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,325 @@
|
|
|
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 { Modifier } from './modifier.js';
|
|
6
|
+
import { Tables } from './tables.js';
|
|
7
|
+
import { isStemmableNote } from './typeguard.js';
|
|
8
|
+
import { log } from './util.js';
|
|
9
|
+
function L(...args) {
|
|
10
|
+
if (ChordSymbol.DEBUG)
|
|
11
|
+
log('VexFlow.ChordSymbol', args);
|
|
12
|
+
}
|
|
13
|
+
export class ChordSymbolBlock extends Element {
|
|
14
|
+
constructor(text, symbolModifier, xShift, yShift, vAlign) {
|
|
15
|
+
super();
|
|
16
|
+
this.text = text;
|
|
17
|
+
this.symbolModifier = symbolModifier;
|
|
18
|
+
this.xShift = xShift;
|
|
19
|
+
this.yShift = yShift;
|
|
20
|
+
this.vAlign = vAlign;
|
|
21
|
+
}
|
|
22
|
+
isSuperscript() {
|
|
23
|
+
return this.symbolModifier === SymbolModifiers.SUPERSCRIPT;
|
|
24
|
+
}
|
|
25
|
+
isSubscript() {
|
|
26
|
+
return this.symbolModifier === SymbolModifiers.SUBSCRIPT;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export var ChordSymbolHorizontalJustify;
|
|
30
|
+
(function (ChordSymbolHorizontalJustify) {
|
|
31
|
+
ChordSymbolHorizontalJustify[ChordSymbolHorizontalJustify["LEFT"] = 1] = "LEFT";
|
|
32
|
+
ChordSymbolHorizontalJustify[ChordSymbolHorizontalJustify["CENTER"] = 2] = "CENTER";
|
|
33
|
+
ChordSymbolHorizontalJustify[ChordSymbolHorizontalJustify["RIGHT"] = 3] = "RIGHT";
|
|
34
|
+
ChordSymbolHorizontalJustify[ChordSymbolHorizontalJustify["CENTER_STEM"] = 4] = "CENTER_STEM";
|
|
35
|
+
})(ChordSymbolHorizontalJustify || (ChordSymbolHorizontalJustify = {}));
|
|
36
|
+
export var ChordSymbolVerticalJustify;
|
|
37
|
+
(function (ChordSymbolVerticalJustify) {
|
|
38
|
+
ChordSymbolVerticalJustify[ChordSymbolVerticalJustify["TOP"] = 1] = "TOP";
|
|
39
|
+
ChordSymbolVerticalJustify[ChordSymbolVerticalJustify["BOTTOM"] = 2] = "BOTTOM";
|
|
40
|
+
})(ChordSymbolVerticalJustify || (ChordSymbolVerticalJustify = {}));
|
|
41
|
+
export var SymbolModifiers;
|
|
42
|
+
(function (SymbolModifiers) {
|
|
43
|
+
SymbolModifiers[SymbolModifiers["NONE"] = 1] = "NONE";
|
|
44
|
+
SymbolModifiers[SymbolModifiers["SUBSCRIPT"] = 2] = "SUBSCRIPT";
|
|
45
|
+
SymbolModifiers[SymbolModifiers["SUPERSCRIPT"] = 3] = "SUPERSCRIPT";
|
|
46
|
+
})(SymbolModifiers || (SymbolModifiers = {}));
|
|
47
|
+
export class ChordSymbol extends Modifier {
|
|
48
|
+
static get CATEGORY() {
|
|
49
|
+
return "ChordSymbol";
|
|
50
|
+
}
|
|
51
|
+
static get superSubRatio() {
|
|
52
|
+
return Metrics.get('ChordSymbol.superSubRatio');
|
|
53
|
+
}
|
|
54
|
+
static get spacingBetweenBlocks() {
|
|
55
|
+
return Metrics.get('ChordSymbol.spacing');
|
|
56
|
+
}
|
|
57
|
+
static get superscriptOffset() {
|
|
58
|
+
return Metrics.get('ChordSymbol.superscriptOffset');
|
|
59
|
+
}
|
|
60
|
+
static get subscriptOffset() {
|
|
61
|
+
return Metrics.get('ChordSymbol.subscriptOffset');
|
|
62
|
+
}
|
|
63
|
+
static get minPadding() {
|
|
64
|
+
return Metrics.get('NoteHead.minPadding');
|
|
65
|
+
}
|
|
66
|
+
static format(symbols, state) {
|
|
67
|
+
if (!symbols || symbols.length === 0)
|
|
68
|
+
return false;
|
|
69
|
+
let width = 0;
|
|
70
|
+
let leftWidth = 0;
|
|
71
|
+
let rightWidth = 0;
|
|
72
|
+
let maxLeftGlyphWidth = 0;
|
|
73
|
+
let maxRightGlyphWidth = 0;
|
|
74
|
+
for (const symbol of symbols) {
|
|
75
|
+
const note = symbol.checkAttachedNote();
|
|
76
|
+
let lineSpaces = 1;
|
|
77
|
+
for (let j = 0; j < symbol.symbolBlocks.length; ++j) {
|
|
78
|
+
const block = symbol.symbolBlocks[j];
|
|
79
|
+
const sup = block.isSuperscript();
|
|
80
|
+
const sub = block.isSubscript();
|
|
81
|
+
block.setXShift(width);
|
|
82
|
+
if (sup || sub) {
|
|
83
|
+
lineSpaces = 2;
|
|
84
|
+
}
|
|
85
|
+
if (sub && j > 0) {
|
|
86
|
+
const prev = symbol.symbolBlocks[j - 1];
|
|
87
|
+
if (prev.isSuperscript()) {
|
|
88
|
+
block.setXShift(width - prev.getWidth() - ChordSymbol.minPadding);
|
|
89
|
+
block.vAlign = true;
|
|
90
|
+
width +=
|
|
91
|
+
-prev.getWidth() -
|
|
92
|
+
ChordSymbol.minPadding +
|
|
93
|
+
(prev.getWidth() > block.getWidth() ? prev.getWidth() - block.getWidth() : 0);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
width += block.getWidth() + ChordSymbol.minPadding;
|
|
97
|
+
}
|
|
98
|
+
if (symbol.getVertical() === ChordSymbolVerticalJustify.TOP) {
|
|
99
|
+
symbol.setTextLine(state.topTextLine);
|
|
100
|
+
state.topTextLine += lineSpaces;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
symbol.setTextLine(state.textLine + 1);
|
|
104
|
+
state.textLine += lineSpaces + 1;
|
|
105
|
+
}
|
|
106
|
+
if (symbol.getReportWidth()) {
|
|
107
|
+
if (isStemmableNote(note)) {
|
|
108
|
+
const glyphWidth = note.getGlyphWidth();
|
|
109
|
+
if (symbol.getHorizontal() === ChordSymbolHorizontalJustify.RIGHT) {
|
|
110
|
+
maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
|
|
111
|
+
leftWidth = Math.max(leftWidth, width) + ChordSymbol.minPadding;
|
|
112
|
+
}
|
|
113
|
+
else if (symbol.getHorizontal() === ChordSymbolHorizontalJustify.LEFT) {
|
|
114
|
+
maxRightGlyphWidth = Math.max(glyphWidth, maxRightGlyphWidth);
|
|
115
|
+
rightWidth = Math.max(rightWidth, width);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
leftWidth = Math.max(leftWidth, width / 2) + ChordSymbol.minPadding;
|
|
119
|
+
rightWidth = Math.max(rightWidth, width / 2);
|
|
120
|
+
maxLeftGlyphWidth = Math.max(glyphWidth / 2, maxLeftGlyphWidth);
|
|
121
|
+
maxRightGlyphWidth = Math.max(glyphWidth / 2, maxRightGlyphWidth);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
symbol.width = width;
|
|
125
|
+
}
|
|
126
|
+
width = 0;
|
|
127
|
+
}
|
|
128
|
+
const rightOverlap = Math.min(Math.max(rightWidth - maxRightGlyphWidth, 0), Math.max(rightWidth - state.rightShift, 0));
|
|
129
|
+
const leftOverlap = Math.min(Math.max(leftWidth - maxLeftGlyphWidth, 0), Math.max(leftWidth - state.leftShift, 0));
|
|
130
|
+
state.leftShift += leftOverlap;
|
|
131
|
+
state.rightShift += rightOverlap;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
constructor() {
|
|
135
|
+
super();
|
|
136
|
+
this.symbolBlocks = [];
|
|
137
|
+
this.horizontal = ChordSymbolHorizontalJustify.LEFT;
|
|
138
|
+
this.vertical = ChordSymbolVerticalJustify.TOP;
|
|
139
|
+
this.reportWidth = true;
|
|
140
|
+
}
|
|
141
|
+
get superscriptOffset() {
|
|
142
|
+
return ChordSymbol.superscriptOffset * Font.convertSizeToPixelValue(this.fontInfo.size);
|
|
143
|
+
}
|
|
144
|
+
get subscriptOffset() {
|
|
145
|
+
return ChordSymbol.subscriptOffset * Font.convertSizeToPixelValue(this.fontInfo.size);
|
|
146
|
+
}
|
|
147
|
+
setReportWidth(value) {
|
|
148
|
+
this.reportWidth = value;
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
getReportWidth() {
|
|
152
|
+
return this.reportWidth;
|
|
153
|
+
}
|
|
154
|
+
getSymbolBlock(params = {}) {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
const symbolBlock = new ChordSymbolBlock((_a = params.text) !== null && _a !== void 0 ? _a : '', (_b = params.symbolModifier) !== null && _b !== void 0 ? _b : SymbolModifiers.NONE, 0, 0, false);
|
|
157
|
+
if (symbolBlock.isSubscript()) {
|
|
158
|
+
symbolBlock.setYShift(this.subscriptOffset);
|
|
159
|
+
}
|
|
160
|
+
if (symbolBlock.isSuperscript()) {
|
|
161
|
+
symbolBlock.setYShift(this.superscriptOffset);
|
|
162
|
+
}
|
|
163
|
+
if (symbolBlock.isSubscript() || symbolBlock.isSuperscript()) {
|
|
164
|
+
const { family, size, weight, style } = this.fontInfo;
|
|
165
|
+
const smallerFontSize = Font.scaleSize(size, ChordSymbol.superSubRatio);
|
|
166
|
+
symbolBlock.setFont(family, smallerFontSize, weight, style);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
symbolBlock.setFont(this.fontInfo);
|
|
170
|
+
}
|
|
171
|
+
return symbolBlock;
|
|
172
|
+
}
|
|
173
|
+
addSymbolBlock(parameters) {
|
|
174
|
+
this.symbolBlocks.push(this.getSymbolBlock(parameters));
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
addText(text, parameters = {}) {
|
|
178
|
+
return this.addSymbolBlock(Object.assign(Object.assign({}, parameters), { text }));
|
|
179
|
+
}
|
|
180
|
+
addTextSuperscript(text) {
|
|
181
|
+
const symbolModifier = SymbolModifiers.SUPERSCRIPT;
|
|
182
|
+
return this.addSymbolBlock({ text, symbolModifier });
|
|
183
|
+
}
|
|
184
|
+
addTextSubscript(text) {
|
|
185
|
+
const symbolModifier = SymbolModifiers.SUBSCRIPT;
|
|
186
|
+
return this.addSymbolBlock({ text, symbolModifier });
|
|
187
|
+
}
|
|
188
|
+
addGlyphSuperscript(glyph) {
|
|
189
|
+
return this.addTextSuperscript(ChordSymbol.glyphs[glyph]);
|
|
190
|
+
}
|
|
191
|
+
addGlyph(glyph, params = {}) {
|
|
192
|
+
return this.addText(ChordSymbol.glyphs[glyph], params);
|
|
193
|
+
}
|
|
194
|
+
addGlyphOrText(text, params = {}) {
|
|
195
|
+
let str = '';
|
|
196
|
+
for (let i = 0; i < text.length; ++i) {
|
|
197
|
+
const char = text[i];
|
|
198
|
+
const glyph = ChordSymbol.glyphs[char];
|
|
199
|
+
if (glyph) {
|
|
200
|
+
str += glyph;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
str += char;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (str.length > 0) {
|
|
207
|
+
this.addText(str, params);
|
|
208
|
+
}
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
addLine(params = {}) {
|
|
212
|
+
return this.addText('\ue874\ue874', params);
|
|
213
|
+
}
|
|
214
|
+
setVertical(vj) {
|
|
215
|
+
this.vertical = typeof vj === 'string' ? ChordSymbol.VerticalJustifyString[vj] : vj;
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
getVertical() {
|
|
219
|
+
return this.vertical;
|
|
220
|
+
}
|
|
221
|
+
setHorizontal(hj) {
|
|
222
|
+
this.horizontal = typeof hj === 'string' ? ChordSymbol.HorizontalJustifyString[hj] : hj;
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
getHorizontal() {
|
|
226
|
+
return this.horizontal;
|
|
227
|
+
}
|
|
228
|
+
draw() {
|
|
229
|
+
const ctx = this.checkContext();
|
|
230
|
+
const note = this.checkAttachedNote();
|
|
231
|
+
this.setRendered();
|
|
232
|
+
const clsAttribute = this.getAttribute('class');
|
|
233
|
+
ctx.openGroup('chordsymbol' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
234
|
+
const start = note.getModifierStartXY(Modifier.Position.ABOVE, this.index);
|
|
235
|
+
ctx.setFont(this.fontInfo);
|
|
236
|
+
let y;
|
|
237
|
+
const hasStem = note.hasStem();
|
|
238
|
+
const stave = note.checkStave();
|
|
239
|
+
if (this.vertical === ChordSymbolVerticalJustify.BOTTOM) {
|
|
240
|
+
y = stave.getYForBottomText(this.textLine + Tables.TEXT_HEIGHT_OFFSET_HACK);
|
|
241
|
+
if (hasStem) {
|
|
242
|
+
const stemExt = note.checkStem().getExtents();
|
|
243
|
+
const spacing = stave.getSpacingBetweenLines();
|
|
244
|
+
const stemBase = note.getStemDirection() === 1 ? stemExt.baseY : stemExt.topY;
|
|
245
|
+
y = Math.max(y, stemBase + spacing * (this.textLine + 2));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
const topY = Math.min(...note.getYs());
|
|
250
|
+
y = Math.min(stave.getYForTopText(this.textLine), topY - 10);
|
|
251
|
+
if (hasStem) {
|
|
252
|
+
const stemExt = note.checkStem().getExtents();
|
|
253
|
+
const spacing = stave.getSpacingBetweenLines();
|
|
254
|
+
y = Math.min(y, stemExt.topY - 5 - spacing * this.textLine);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
let x = start.x;
|
|
258
|
+
if (this.horizontal === ChordSymbolHorizontalJustify.LEFT) {
|
|
259
|
+
x = start.x;
|
|
260
|
+
}
|
|
261
|
+
else if (this.horizontal === ChordSymbolHorizontalJustify.RIGHT) {
|
|
262
|
+
x = start.x + this.getWidth();
|
|
263
|
+
}
|
|
264
|
+
else if (this.horizontal === ChordSymbolHorizontalJustify.CENTER) {
|
|
265
|
+
x = start.x - this.getWidth() / 2;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
x = note.getStemX() - this.getWidth() / 2;
|
|
269
|
+
}
|
|
270
|
+
L('Rendering ChordSymbol: ', x, y);
|
|
271
|
+
this.symbolBlocks.forEach((symbol) => {
|
|
272
|
+
L('Rendering Text: ', symbol.getText(), x + symbol.getXShift(), y + symbol.getYShift());
|
|
273
|
+
symbol.setX(x);
|
|
274
|
+
symbol.setY(y);
|
|
275
|
+
symbol.renderText(ctx, 0, 0);
|
|
276
|
+
});
|
|
277
|
+
this.drawPointerRect();
|
|
278
|
+
ctx.closeGroup();
|
|
279
|
+
}
|
|
280
|
+
getBoundingBox() {
|
|
281
|
+
const boundingBox = this.symbolBlocks[0].getBoundingBox();
|
|
282
|
+
for (let i = 1; i < this.symbolBlocks.length; i++) {
|
|
283
|
+
boundingBox.mergeWith(this.symbolBlocks[i].getBoundingBox());
|
|
284
|
+
}
|
|
285
|
+
return boundingBox;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
ChordSymbol.DEBUG = false;
|
|
289
|
+
ChordSymbol.HorizontalJustify = ChordSymbolHorizontalJustify;
|
|
290
|
+
ChordSymbol.HorizontalJustifyString = {
|
|
291
|
+
left: ChordSymbolHorizontalJustify.LEFT,
|
|
292
|
+
right: ChordSymbolHorizontalJustify.RIGHT,
|
|
293
|
+
center: ChordSymbolHorizontalJustify.CENTER,
|
|
294
|
+
centerStem: ChordSymbolHorizontalJustify.CENTER_STEM,
|
|
295
|
+
};
|
|
296
|
+
ChordSymbol.VerticalJustify = ChordSymbolVerticalJustify;
|
|
297
|
+
ChordSymbol.VerticalJustifyString = {
|
|
298
|
+
top: ChordSymbolVerticalJustify.TOP,
|
|
299
|
+
above: ChordSymbolVerticalJustify.TOP,
|
|
300
|
+
below: ChordSymbolVerticalJustify.BOTTOM,
|
|
301
|
+
bottom: ChordSymbolVerticalJustify.BOTTOM,
|
|
302
|
+
};
|
|
303
|
+
ChordSymbol.glyphs = {
|
|
304
|
+
diminished: Glyphs.csymDiminished,
|
|
305
|
+
dim: Glyphs.csymDiminished,
|
|
306
|
+
halfDiminished: Glyphs.csymHalfDiminished,
|
|
307
|
+
'+': Glyphs.csymAugmented,
|
|
308
|
+
augmented: Glyphs.csymAugmented,
|
|
309
|
+
majorSeventh: Glyphs.csymMajorSeventh,
|
|
310
|
+
minor: Glyphs.csymMinor,
|
|
311
|
+
'-': Glyphs.csymMinor,
|
|
312
|
+
'(': '(',
|
|
313
|
+
leftParen: '(',
|
|
314
|
+
')': ')',
|
|
315
|
+
rightParen: ')',
|
|
316
|
+
leftBracket: Glyphs.csymBracketLeftTall,
|
|
317
|
+
rightBracket: Glyphs.csymBracketRightTall,
|
|
318
|
+
leftParenTall: '(',
|
|
319
|
+
rightParenTall: ')',
|
|
320
|
+
'/': Glyphs.csymDiagonalArrangementSlash,
|
|
321
|
+
over: Glyphs.csymDiagonalArrangementSlash,
|
|
322
|
+
'#': Glyphs.csymAccidentalSharp,
|
|
323
|
+
b: Glyphs.csymAccidentalFlat,
|
|
324
|
+
};
|
|
325
|
+
ChordSymbol.symbolModifiers = SymbolModifiers;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Glyphs } from './glyphs.js';
|
|
2
|
+
import { Metrics } from './metrics.js';
|
|
3
|
+
import { StaveModifier, StaveModifierPosition } from './stavemodifier.js';
|
|
4
|
+
import { log } from './util.js';
|
|
5
|
+
function L(...args) {
|
|
6
|
+
if (Clef.DEBUG)
|
|
7
|
+
log('VexFlow.Clef', args);
|
|
8
|
+
}
|
|
9
|
+
export class Clef extends StaveModifier {
|
|
10
|
+
static get CATEGORY() {
|
|
11
|
+
return "Clef";
|
|
12
|
+
}
|
|
13
|
+
static get types() {
|
|
14
|
+
const { gClef, fClef, cClef, unpitchedPercussionClef1, sixStringTabClef } = Glyphs;
|
|
15
|
+
return {
|
|
16
|
+
treble: {
|
|
17
|
+
code: gClef,
|
|
18
|
+
line: 3,
|
|
19
|
+
},
|
|
20
|
+
bass: {
|
|
21
|
+
code: fClef,
|
|
22
|
+
line: 1,
|
|
23
|
+
},
|
|
24
|
+
alto: {
|
|
25
|
+
code: cClef,
|
|
26
|
+
line: 2,
|
|
27
|
+
},
|
|
28
|
+
tenor: {
|
|
29
|
+
code: cClef,
|
|
30
|
+
line: 1,
|
|
31
|
+
},
|
|
32
|
+
percussion: {
|
|
33
|
+
code: unpitchedPercussionClef1,
|
|
34
|
+
line: 2,
|
|
35
|
+
},
|
|
36
|
+
soprano: {
|
|
37
|
+
code: cClef,
|
|
38
|
+
line: 4,
|
|
39
|
+
},
|
|
40
|
+
'mezzo-soprano': {
|
|
41
|
+
code: cClef,
|
|
42
|
+
line: 3,
|
|
43
|
+
},
|
|
44
|
+
'baritone-c': {
|
|
45
|
+
code: cClef,
|
|
46
|
+
line: 0,
|
|
47
|
+
},
|
|
48
|
+
'baritone-f': {
|
|
49
|
+
code: fClef,
|
|
50
|
+
line: 2,
|
|
51
|
+
},
|
|
52
|
+
subbass: {
|
|
53
|
+
code: fClef,
|
|
54
|
+
line: 0,
|
|
55
|
+
},
|
|
56
|
+
french: {
|
|
57
|
+
code: gClef,
|
|
58
|
+
line: 4,
|
|
59
|
+
},
|
|
60
|
+
tab: {
|
|
61
|
+
code: sixStringTabClef,
|
|
62
|
+
line: 2.5,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
constructor(type, size, annotation) {
|
|
67
|
+
super();
|
|
68
|
+
this.code = Clef.types['treble'].code;
|
|
69
|
+
this.line = Clef.types['treble'].line;
|
|
70
|
+
this.size = 'default';
|
|
71
|
+
this.type = 'treble';
|
|
72
|
+
this.setPosition(StaveModifierPosition.BEGIN);
|
|
73
|
+
this.setType(type, size, annotation);
|
|
74
|
+
L('Creating clef:', type);
|
|
75
|
+
}
|
|
76
|
+
setType(type, size = 'default', annotation) {
|
|
77
|
+
this.type = type;
|
|
78
|
+
this.code = Clef.types[type].code;
|
|
79
|
+
this.line = Clef.types[type].line;
|
|
80
|
+
this.size = size !== null && size !== void 0 ? size : 'default';
|
|
81
|
+
if (annotation === '8va') {
|
|
82
|
+
if (this.code === Glyphs.gClef) {
|
|
83
|
+
this.code = Glyphs.gClef8va;
|
|
84
|
+
}
|
|
85
|
+
if (this.code === Glyphs.fClef) {
|
|
86
|
+
this.code = Glyphs.fClef8va;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (annotation === '8vb') {
|
|
90
|
+
if (this.code === Glyphs.gClef) {
|
|
91
|
+
this.code = Glyphs.gClef8vb;
|
|
92
|
+
}
|
|
93
|
+
if (this.code === Glyphs.fClef) {
|
|
94
|
+
this.code = Glyphs.fClef8vb;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
this.text = this.code;
|
|
98
|
+
this.fontInfo.size = Math.floor(Clef.getPoint(this.size));
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
static getPoint(size) {
|
|
102
|
+
return size === 'default' ? Metrics.get('fontSize') : (Metrics.get('fontSize') * 2) / 3;
|
|
103
|
+
}
|
|
104
|
+
setStave(stave) {
|
|
105
|
+
this.stave = stave;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
draw() {
|
|
109
|
+
const stave = this.checkStave();
|
|
110
|
+
const ctx = stave.checkContext();
|
|
111
|
+
this.setRendered();
|
|
112
|
+
const clsAttribute = this.getAttribute('class');
|
|
113
|
+
ctx.openGroup('clef' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
114
|
+
this.y = stave.getYForLine(this.line);
|
|
115
|
+
this.renderText(ctx, 0, 0);
|
|
116
|
+
this.drawPointerRect();
|
|
117
|
+
ctx.closeGroup();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
Clef.DEBUG = false;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Clef } from './clef.js';
|
|
2
|
+
import { Note } from './note.js';
|
|
3
|
+
export class ClefNote extends Note {
|
|
4
|
+
static get CATEGORY() {
|
|
5
|
+
return "ClefNote";
|
|
6
|
+
}
|
|
7
|
+
constructor(type, size = 'default', annotation) {
|
|
8
|
+
super({ duration: 'b' });
|
|
9
|
+
this.setType(type, size, annotation);
|
|
10
|
+
this.ignoreTicks = true;
|
|
11
|
+
}
|
|
12
|
+
setType(type, size, annotation) {
|
|
13
|
+
this.clef = new Clef(type, size, annotation);
|
|
14
|
+
this.setWidth(this.clef.getWidth());
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
getClef() {
|
|
18
|
+
return this.clef;
|
|
19
|
+
}
|
|
20
|
+
preFormat() {
|
|
21
|
+
this.preFormatted = true;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
draw() {
|
|
25
|
+
const stave = this.checkStave();
|
|
26
|
+
const ctx = this.checkContext();
|
|
27
|
+
this.setRendered();
|
|
28
|
+
this.clef.setX(this.getAbsoluteX());
|
|
29
|
+
this.clef.setY(stave.getYForLine(this.clef.line));
|
|
30
|
+
this.clef.renderText(ctx, 0, 0);
|
|
31
|
+
}
|
|
32
|
+
getBoundingBox() {
|
|
33
|
+
return this.clef.getBoundingBox();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Note } from './note.js';
|
|
2
|
+
import { TickContext } from './tickcontext.js';
|
|
3
|
+
import { log } from './util.js';
|
|
4
|
+
function L(...args) {
|
|
5
|
+
if (Crescendo.DEBUG)
|
|
6
|
+
log('VexFlow.Crescendo', args);
|
|
7
|
+
}
|
|
8
|
+
function renderHairpin(ctx, params) {
|
|
9
|
+
const beginX = params.beginX;
|
|
10
|
+
const endX = params.endX;
|
|
11
|
+
const y = params.y;
|
|
12
|
+
const halfHeight = params.height / 2;
|
|
13
|
+
ctx.beginPath();
|
|
14
|
+
if (params.reverse) {
|
|
15
|
+
ctx.moveTo(beginX, y - halfHeight);
|
|
16
|
+
ctx.lineTo(endX, y);
|
|
17
|
+
ctx.lineTo(beginX, y + halfHeight);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
ctx.moveTo(endX, y - halfHeight);
|
|
21
|
+
ctx.lineTo(beginX, y);
|
|
22
|
+
ctx.lineTo(endX, y + halfHeight);
|
|
23
|
+
}
|
|
24
|
+
ctx.stroke();
|
|
25
|
+
ctx.closePath();
|
|
26
|
+
}
|
|
27
|
+
export class Crescendo extends Note {
|
|
28
|
+
static get CATEGORY() {
|
|
29
|
+
return "Crescendo";
|
|
30
|
+
}
|
|
31
|
+
constructor(noteStruct) {
|
|
32
|
+
var _a;
|
|
33
|
+
super(noteStruct);
|
|
34
|
+
this.options = {
|
|
35
|
+
extendLeft: 0,
|
|
36
|
+
extendRight: 0,
|
|
37
|
+
yShift: 0,
|
|
38
|
+
};
|
|
39
|
+
this.decrescendo = false;
|
|
40
|
+
this.line = (_a = noteStruct.line) !== null && _a !== void 0 ? _a : 0;
|
|
41
|
+
this.height = 15;
|
|
42
|
+
}
|
|
43
|
+
setLine(line) {
|
|
44
|
+
this.line = line;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
setHeight(height) {
|
|
48
|
+
this.height = height;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
setDecrescendo(decresc) {
|
|
52
|
+
this.decrescendo = decresc;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
preFormat() {
|
|
56
|
+
this.preFormatted = true;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
draw() {
|
|
60
|
+
const ctx = this.checkContext();
|
|
61
|
+
const stave = this.checkStave();
|
|
62
|
+
this.setRendered();
|
|
63
|
+
const tickContext = this.getTickContext();
|
|
64
|
+
const nextContext = TickContext.getNextContext(tickContext);
|
|
65
|
+
const beginX = this.getAbsoluteX();
|
|
66
|
+
const endX = nextContext ? nextContext.getX() : stave.getX() + stave.getWidth();
|
|
67
|
+
const y = stave.getYForLine(this.line + -3) + 1;
|
|
68
|
+
L('Drawing ', this.decrescendo ? 'decrescendo ' : 'crescendo ', this.height, 'x', beginX - endX);
|
|
69
|
+
renderHairpin(ctx, {
|
|
70
|
+
beginX: beginX - this.options.extendLeft,
|
|
71
|
+
endX: endX + this.options.extendRight,
|
|
72
|
+
y: y + this.options.yShift,
|
|
73
|
+
height: this.height,
|
|
74
|
+
reverse: this.decrescendo,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
Crescendo.DEBUG = false;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { RuntimeError } from './util.js';
|
|
3
|
+
export var CurvePosition;
|
|
4
|
+
(function (CurvePosition) {
|
|
5
|
+
CurvePosition[CurvePosition["NEAR_HEAD"] = 1] = "NEAR_HEAD";
|
|
6
|
+
CurvePosition[CurvePosition["NEAR_TOP"] = 2] = "NEAR_TOP";
|
|
7
|
+
})(CurvePosition || (CurvePosition = {}));
|
|
8
|
+
export class Curve extends Element {
|
|
9
|
+
static get CATEGORY() {
|
|
10
|
+
return "Curve";
|
|
11
|
+
}
|
|
12
|
+
static get Position() {
|
|
13
|
+
return CurvePosition;
|
|
14
|
+
}
|
|
15
|
+
static get PositionString() {
|
|
16
|
+
return {
|
|
17
|
+
nearHead: CurvePosition.NEAR_HEAD,
|
|
18
|
+
nearTop: CurvePosition.NEAR_TOP,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
constructor(from, to, options) {
|
|
22
|
+
super();
|
|
23
|
+
this.renderOptions = Object.assign({ thickness: 2, xShift: 0, yShift: 10, position: CurvePosition.NEAR_HEAD, positionEnd: CurvePosition.NEAR_HEAD, invert: false, cps: [
|
|
24
|
+
{ x: 0, y: 10 },
|
|
25
|
+
{ x: 0, y: 10 },
|
|
26
|
+
], openingDirection: 'auto' }, options);
|
|
27
|
+
this.setNotes(from, to);
|
|
28
|
+
}
|
|
29
|
+
setNotes(from, to) {
|
|
30
|
+
if (!from && !to) {
|
|
31
|
+
throw new RuntimeError('BadArguments', 'Curve needs to have either `from` or `to` set.');
|
|
32
|
+
}
|
|
33
|
+
this.from = from;
|
|
34
|
+
this.to = to;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
isPartial() {
|
|
38
|
+
return !this.from || !this.to;
|
|
39
|
+
}
|
|
40
|
+
renderCurve(params) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const ctx = this.checkContext();
|
|
43
|
+
const xShift = this.renderOptions.xShift;
|
|
44
|
+
const yShift = this.renderOptions.yShift * params.direction;
|
|
45
|
+
const firstX = params.firstX + xShift;
|
|
46
|
+
const firstY = params.firstY + yShift;
|
|
47
|
+
const lastX = params.lastX - xShift;
|
|
48
|
+
const lastY = params.lastY + yShift;
|
|
49
|
+
const thickness = this.renderOptions.thickness;
|
|
50
|
+
const cps = this.renderOptions.cps;
|
|
51
|
+
const { x: cp0x, y: cp0y } = cps[0];
|
|
52
|
+
const { x: cp1x, y: cp1y } = cps[1];
|
|
53
|
+
const controlPointSpacing = (lastX - firstX) / (cps.length + 2);
|
|
54
|
+
ctx.beginPath();
|
|
55
|
+
ctx.moveTo(firstX, firstY);
|
|
56
|
+
ctx.bezierCurveTo(firstX + controlPointSpacing + cp0x, firstY + cp0y * params.direction, lastX - controlPointSpacing + cp1x, lastY + cp1y * params.direction, lastX, lastY);
|
|
57
|
+
if (!((_a = this.style) === null || _a === void 0 ? void 0 : _a.lineDash))
|
|
58
|
+
ctx.bezierCurveTo(lastX - controlPointSpacing + cp1x, lastY + (cp1y + thickness) * params.direction, firstX + controlPointSpacing + cp0x, firstY + (cp0y + thickness) * params.direction, firstX, firstY);
|
|
59
|
+
ctx.stroke();
|
|
60
|
+
ctx.closePath();
|
|
61
|
+
if (!((_b = this.style) === null || _b === void 0 ? void 0 : _b.lineDash))
|
|
62
|
+
ctx.fill();
|
|
63
|
+
}
|
|
64
|
+
draw() {
|
|
65
|
+
this.checkContext();
|
|
66
|
+
this.setRendered();
|
|
67
|
+
const firstNote = this.from;
|
|
68
|
+
const lastNote = this.to;
|
|
69
|
+
let firstX;
|
|
70
|
+
let lastX;
|
|
71
|
+
let firstY;
|
|
72
|
+
let lastY;
|
|
73
|
+
let stemDirection = 0;
|
|
74
|
+
let metric = 'baseY';
|
|
75
|
+
let endMetric = 'baseY';
|
|
76
|
+
function getPosition(position) {
|
|
77
|
+
return typeof position === 'string' ? Curve.PositionString[position] : position;
|
|
78
|
+
}
|
|
79
|
+
const position = getPosition(this.renderOptions.position);
|
|
80
|
+
const positionEnd = getPosition(this.renderOptions.positionEnd);
|
|
81
|
+
if (position === CurvePosition.NEAR_TOP) {
|
|
82
|
+
metric = 'topY';
|
|
83
|
+
endMetric = 'topY';
|
|
84
|
+
}
|
|
85
|
+
if (positionEnd === CurvePosition.NEAR_HEAD) {
|
|
86
|
+
endMetric = 'baseY';
|
|
87
|
+
}
|
|
88
|
+
else if (positionEnd === CurvePosition.NEAR_TOP) {
|
|
89
|
+
endMetric = 'topY';
|
|
90
|
+
}
|
|
91
|
+
if (firstNote) {
|
|
92
|
+
firstX = firstNote.getTieRightX();
|
|
93
|
+
stemDirection = firstNote.getStemDirection();
|
|
94
|
+
firstY = firstNote.getStemExtents()[metric];
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const stave = lastNote.checkStave();
|
|
98
|
+
firstX = stave.getTieStartX();
|
|
99
|
+
firstY = lastNote.getStemExtents()[metric];
|
|
100
|
+
}
|
|
101
|
+
if (lastNote) {
|
|
102
|
+
lastX = lastNote.getTieLeftX();
|
|
103
|
+
stemDirection = lastNote.getStemDirection();
|
|
104
|
+
lastY = lastNote.getStemExtents()[endMetric];
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const stave = firstNote.checkStave();
|
|
108
|
+
lastX = stave.getTieEndX();
|
|
109
|
+
lastY = firstNote.getStemExtents()[endMetric];
|
|
110
|
+
}
|
|
111
|
+
if (this.renderOptions.openingDirection === 'up') {
|
|
112
|
+
stemDirection = 1;
|
|
113
|
+
}
|
|
114
|
+
if (this.renderOptions.openingDirection === 'down') {
|
|
115
|
+
stemDirection = -1;
|
|
116
|
+
}
|
|
117
|
+
this.renderCurve({
|
|
118
|
+
firstX,
|
|
119
|
+
lastX,
|
|
120
|
+
firstY,
|
|
121
|
+
lastY,
|
|
122
|
+
direction: stemDirection * (this.renderOptions.invert === true ? -1 : 1),
|
|
123
|
+
});
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
}
|