@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,224 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Fraction } from './fraction.js';
|
|
3
|
+
import { Tables } from './tables.js';
|
|
4
|
+
import { defined, RuntimeError } from './util.js';
|
|
5
|
+
export class Tickable extends Element {
|
|
6
|
+
static get CATEGORY() {
|
|
7
|
+
return "Tickable";
|
|
8
|
+
}
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this._preFormatted = false;
|
|
12
|
+
this._postFormatted = false;
|
|
13
|
+
this.ticks = new Fraction(0, 1);
|
|
14
|
+
this.intrinsicTicks = 0;
|
|
15
|
+
this.tickMultiplier = new Fraction(1, 1);
|
|
16
|
+
this.modifiers = [];
|
|
17
|
+
this.tupletStack = [];
|
|
18
|
+
this.alignCenter = false;
|
|
19
|
+
this.centerXShift = 0;
|
|
20
|
+
this.ignoreTicks = false;
|
|
21
|
+
this.formatterMetrics = {
|
|
22
|
+
freedom: { left: 0, right: 0 },
|
|
23
|
+
duration: '',
|
|
24
|
+
iterations: 0,
|
|
25
|
+
space: {
|
|
26
|
+
used: 0,
|
|
27
|
+
mean: 0,
|
|
28
|
+
deviation: 0,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
reset() {
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
getTicks() {
|
|
36
|
+
return this.ticks;
|
|
37
|
+
}
|
|
38
|
+
shouldIgnoreTicks() {
|
|
39
|
+
return this.ignoreTicks;
|
|
40
|
+
}
|
|
41
|
+
setIgnoreTicks(flag) {
|
|
42
|
+
this.ignoreTicks = flag;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
getWidth() {
|
|
46
|
+
if (!this._preFormatted) {
|
|
47
|
+
throw new RuntimeError('UnformattedNote', "Can't call GetWidth on an unformatted note.");
|
|
48
|
+
}
|
|
49
|
+
return this.width + (this.modifierContext ? this.modifierContext.getWidth() : 0);
|
|
50
|
+
}
|
|
51
|
+
getX() {
|
|
52
|
+
const tickContext = this.checkTickContext(`Can't getX() without a TickContext.`);
|
|
53
|
+
return tickContext.getX() + this.xShift;
|
|
54
|
+
}
|
|
55
|
+
getFormatterMetrics() {
|
|
56
|
+
return this.formatterMetrics;
|
|
57
|
+
}
|
|
58
|
+
getCenterXShift() {
|
|
59
|
+
if (this.isCenterAligned()) {
|
|
60
|
+
return this.centerXShift;
|
|
61
|
+
}
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
setCenterXShift(centerXShift) {
|
|
65
|
+
this.centerXShift = centerXShift;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
isCenterAligned() {
|
|
69
|
+
return this.alignCenter;
|
|
70
|
+
}
|
|
71
|
+
setCenterAlignment(alignCenter) {
|
|
72
|
+
this.alignCenter = alignCenter;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
getVoice() {
|
|
76
|
+
return defined(this.voice, 'NoVoice', 'Tickable has no voice.');
|
|
77
|
+
}
|
|
78
|
+
setVoice(voice) {
|
|
79
|
+
this.voice = voice;
|
|
80
|
+
}
|
|
81
|
+
getTuplet() {
|
|
82
|
+
return this.tupletStack.at(-1);
|
|
83
|
+
}
|
|
84
|
+
getTupletStack() {
|
|
85
|
+
return this.tupletStack;
|
|
86
|
+
}
|
|
87
|
+
removeTuplet(tuplet) {
|
|
88
|
+
const i = this.tupletStack.indexOf(tuplet);
|
|
89
|
+
if (i === -1) {
|
|
90
|
+
throw new RuntimeError('BadArguments', 'Tuplet is not found in this tickable');
|
|
91
|
+
}
|
|
92
|
+
this.tupletStack.splice(i, 1);
|
|
93
|
+
const noteCount = tuplet.getNoteCount();
|
|
94
|
+
const notesOccupied = tuplet.getNotesOccupied();
|
|
95
|
+
this.applyTickMultiplier(noteCount, notesOccupied);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
clearTuplets() {
|
|
99
|
+
if (!this.tupletStack.length) {
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
this.tupletStack = [];
|
|
103
|
+
this.tickMultiplier = new Fraction(1, 1);
|
|
104
|
+
this.ticks = new Fraction(this.intrinsicTicks, 1);
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
resetTuplet(tuplet) {
|
|
108
|
+
if (tuplet) {
|
|
109
|
+
try {
|
|
110
|
+
this.removeTuplet(tuplet);
|
|
111
|
+
}
|
|
112
|
+
catch (_a) {
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.clearTuplets();
|
|
117
|
+
}
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
setTuplet(tuplet) {
|
|
121
|
+
if (this.tupletStack.length) {
|
|
122
|
+
this.clearTuplets();
|
|
123
|
+
}
|
|
124
|
+
return this.addTuplet(tuplet);
|
|
125
|
+
}
|
|
126
|
+
addTuplet(tuplet) {
|
|
127
|
+
this.tupletStack.push(tuplet);
|
|
128
|
+
const noteCount = tuplet.getNoteCount();
|
|
129
|
+
const notesOccupied = tuplet.getNotesOccupied();
|
|
130
|
+
this.applyTickMultiplier(notesOccupied, noteCount);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
setTupletStack(tupletStack) {
|
|
134
|
+
this.clearTuplets();
|
|
135
|
+
for (const tup of tupletStack) {
|
|
136
|
+
this.addTuplet(tup);
|
|
137
|
+
}
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
addToModifierContext(mc) {
|
|
141
|
+
this.modifierContext = mc;
|
|
142
|
+
for (let i = 0; i < this.modifiers.length; ++i) {
|
|
143
|
+
this.modifierContext.addMember(this.modifiers[i]);
|
|
144
|
+
}
|
|
145
|
+
this.modifierContext.addMember(this);
|
|
146
|
+
this._preFormatted = false;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
addModifier(modifier, index = 0) {
|
|
150
|
+
this.modifiers.push(modifier);
|
|
151
|
+
this._preFormatted = false;
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
getModifiers() {
|
|
155
|
+
return this.modifiers;
|
|
156
|
+
}
|
|
157
|
+
setTickContext(tc) {
|
|
158
|
+
this.tickContext = tc;
|
|
159
|
+
this._preFormatted = false;
|
|
160
|
+
}
|
|
161
|
+
checkTickContext(message = 'Tickable has no tick context.') {
|
|
162
|
+
return defined(this.tickContext, 'NoTickContext', message);
|
|
163
|
+
}
|
|
164
|
+
preFormat() {
|
|
165
|
+
if (this._preFormatted)
|
|
166
|
+
return;
|
|
167
|
+
this.width = 0;
|
|
168
|
+
if (this.modifierContext) {
|
|
169
|
+
this.modifierContext.preFormat();
|
|
170
|
+
this.width += this.modifierContext.getWidth();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
set preFormatted(value) {
|
|
174
|
+
this._preFormatted = value;
|
|
175
|
+
}
|
|
176
|
+
get preFormatted() {
|
|
177
|
+
return this._preFormatted;
|
|
178
|
+
}
|
|
179
|
+
postFormat() {
|
|
180
|
+
if (this._postFormatted)
|
|
181
|
+
return this;
|
|
182
|
+
this._postFormatted = true;
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
set postFormatted(value) {
|
|
186
|
+
this._postFormatted = value;
|
|
187
|
+
}
|
|
188
|
+
get postFormatted() {
|
|
189
|
+
return this._postFormatted;
|
|
190
|
+
}
|
|
191
|
+
getIntrinsicTicks() {
|
|
192
|
+
return this.intrinsicTicks;
|
|
193
|
+
}
|
|
194
|
+
setIntrinsicTicks(intrinsicTicks) {
|
|
195
|
+
this.intrinsicTicks = intrinsicTicks;
|
|
196
|
+
this.ticks = this.tickMultiplier.clone().multiply(this.intrinsicTicks);
|
|
197
|
+
}
|
|
198
|
+
getTickMultiplier() {
|
|
199
|
+
return this.tickMultiplier;
|
|
200
|
+
}
|
|
201
|
+
applyTickMultiplier(numerator, denominator) {
|
|
202
|
+
this.tickMultiplier.multiply(numerator, denominator);
|
|
203
|
+
this.ticks = this.tickMultiplier.clone().multiply(this.intrinsicTicks);
|
|
204
|
+
}
|
|
205
|
+
setDuration(duration) {
|
|
206
|
+
const ticks = duration.numerator * (Tables.RESOLUTION / duration.denominator);
|
|
207
|
+
this.ticks = this.tickMultiplier.clone().multiply(ticks);
|
|
208
|
+
this.intrinsicTicks = this.ticks.value();
|
|
209
|
+
}
|
|
210
|
+
getAbsoluteX() {
|
|
211
|
+
const tickContext = this.checkTickContext(`Can't getAbsoluteX() without a TickContext.`);
|
|
212
|
+
return tickContext.getX();
|
|
213
|
+
}
|
|
214
|
+
setModifierContext(mc) {
|
|
215
|
+
this.modifierContext = mc;
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
getModifierContext() {
|
|
219
|
+
return this.modifierContext;
|
|
220
|
+
}
|
|
221
|
+
checkModifierContext() {
|
|
222
|
+
return defined(this.modifierContext, 'NoModifierContext', 'No modifier context attached to this tickable.');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { Fraction } from './fraction.js';
|
|
2
|
+
import { RuntimeError, sumArray } from './util.js';
|
|
3
|
+
export class TickContext {
|
|
4
|
+
static getNextContext(tContext) {
|
|
5
|
+
const contexts = tContext.tContexts;
|
|
6
|
+
const index = contexts.indexOf(tContext);
|
|
7
|
+
if (index + 1 < contexts.length)
|
|
8
|
+
return contexts[index + 1];
|
|
9
|
+
}
|
|
10
|
+
constructor(options) {
|
|
11
|
+
var _a;
|
|
12
|
+
this.preFormatted = false;
|
|
13
|
+
this.postFormatted = false;
|
|
14
|
+
this.tickID = (_a = options === null || options === void 0 ? void 0 : options.tickID) !== null && _a !== void 0 ? _a : 0;
|
|
15
|
+
this.currentTick = new Fraction(0, 1);
|
|
16
|
+
this.maxTicks = new Fraction(0, 1);
|
|
17
|
+
this.maxTickable = undefined;
|
|
18
|
+
this.minTicks = undefined;
|
|
19
|
+
this.minTickable = undefined;
|
|
20
|
+
this.padding = 1;
|
|
21
|
+
this.x = 0;
|
|
22
|
+
this.xBase = 0;
|
|
23
|
+
this.xOffset = 0;
|
|
24
|
+
this.tickables = [];
|
|
25
|
+
this.tickablesByVoice = {};
|
|
26
|
+
this.notePx = 0;
|
|
27
|
+
this.glyphPx = 0;
|
|
28
|
+
this.leftDisplacedHeadPx = 0;
|
|
29
|
+
this.rightDisplacedHeadPx = 0;
|
|
30
|
+
this.modLeftPx = 0;
|
|
31
|
+
this.modRightPx = 0;
|
|
32
|
+
this.totalLeftPx = 0;
|
|
33
|
+
this.totalRightPx = 0;
|
|
34
|
+
this.tContexts = [];
|
|
35
|
+
this.width = 0;
|
|
36
|
+
this.formatterMetrics = {
|
|
37
|
+
freedom: { left: 0, right: 0 },
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
getTickID() {
|
|
41
|
+
return this.tickID;
|
|
42
|
+
}
|
|
43
|
+
getX() {
|
|
44
|
+
return this.x;
|
|
45
|
+
}
|
|
46
|
+
setX(x) {
|
|
47
|
+
this.x = x;
|
|
48
|
+
this.xBase = x;
|
|
49
|
+
this.xOffset = 0;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
getXBase() {
|
|
53
|
+
return this.xBase;
|
|
54
|
+
}
|
|
55
|
+
setXBase(xBase) {
|
|
56
|
+
this.xBase = xBase;
|
|
57
|
+
this.x = xBase + this.xOffset;
|
|
58
|
+
}
|
|
59
|
+
getXOffset() {
|
|
60
|
+
return this.xOffset;
|
|
61
|
+
}
|
|
62
|
+
setXOffset(xOffset) {
|
|
63
|
+
this.xOffset = xOffset;
|
|
64
|
+
this.x = this.xBase + xOffset;
|
|
65
|
+
}
|
|
66
|
+
getWidth() {
|
|
67
|
+
return this.width + this.padding * 2;
|
|
68
|
+
}
|
|
69
|
+
setPadding(padding) {
|
|
70
|
+
this.padding = padding;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
getMaxTicks() {
|
|
74
|
+
return this.maxTicks;
|
|
75
|
+
}
|
|
76
|
+
getMinTicks() {
|
|
77
|
+
return this.minTicks;
|
|
78
|
+
}
|
|
79
|
+
getMaxTickable() {
|
|
80
|
+
return this.maxTickable;
|
|
81
|
+
}
|
|
82
|
+
getMinTickable() {
|
|
83
|
+
return this.minTickable;
|
|
84
|
+
}
|
|
85
|
+
getTickables() {
|
|
86
|
+
return this.tickables;
|
|
87
|
+
}
|
|
88
|
+
getTickableForVoice(voiceIndex) {
|
|
89
|
+
return this.tickablesByVoice[voiceIndex];
|
|
90
|
+
}
|
|
91
|
+
getTickablesByVoice() {
|
|
92
|
+
return this.tickablesByVoice;
|
|
93
|
+
}
|
|
94
|
+
getCenterAlignedTickables() {
|
|
95
|
+
return this.tickables.filter((tickable) => tickable.isCenterAligned());
|
|
96
|
+
}
|
|
97
|
+
getMetrics() {
|
|
98
|
+
const { width, glyphPx, notePx, leftDisplacedHeadPx, rightDisplacedHeadPx, modLeftPx, modRightPx, totalLeftPx, totalRightPx, } = this;
|
|
99
|
+
return {
|
|
100
|
+
width,
|
|
101
|
+
glyphPx,
|
|
102
|
+
notePx,
|
|
103
|
+
leftDisplacedHeadPx,
|
|
104
|
+
rightDisplacedHeadPx,
|
|
105
|
+
modLeftPx,
|
|
106
|
+
modRightPx,
|
|
107
|
+
totalLeftPx,
|
|
108
|
+
totalRightPx,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
getCurrentTick() {
|
|
112
|
+
return this.currentTick;
|
|
113
|
+
}
|
|
114
|
+
setCurrentTick(tick) {
|
|
115
|
+
this.currentTick = tick;
|
|
116
|
+
this.preFormatted = false;
|
|
117
|
+
}
|
|
118
|
+
addTickable(tickable, voiceIndex) {
|
|
119
|
+
if (!tickable) {
|
|
120
|
+
throw new RuntimeError('BadArgument', 'Invalid tickable added.');
|
|
121
|
+
}
|
|
122
|
+
if (!tickable.shouldIgnoreTicks()) {
|
|
123
|
+
const ticks = tickable.getTicks();
|
|
124
|
+
if (ticks.greaterThan(this.maxTicks)) {
|
|
125
|
+
this.maxTicks = ticks.clone();
|
|
126
|
+
this.maxTickable = tickable;
|
|
127
|
+
}
|
|
128
|
+
if (this.minTicks === undefined) {
|
|
129
|
+
this.minTicks = ticks.clone();
|
|
130
|
+
this.minTickable = tickable;
|
|
131
|
+
}
|
|
132
|
+
else if (ticks.lessThan(this.minTicks)) {
|
|
133
|
+
this.minTicks = ticks.clone();
|
|
134
|
+
this.minTickable = tickable;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
tickable.setTickContext(this);
|
|
138
|
+
this.tickables.push(tickable);
|
|
139
|
+
this.tickablesByVoice[voiceIndex !== null && voiceIndex !== void 0 ? voiceIndex : 0] = tickable;
|
|
140
|
+
this.preFormatted = false;
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
preFormat() {
|
|
144
|
+
var _a;
|
|
145
|
+
if (this.preFormatted)
|
|
146
|
+
return this;
|
|
147
|
+
for (let i = 0; i < this.tickables.length; ++i) {
|
|
148
|
+
const tickable = this.tickables[i];
|
|
149
|
+
tickable.preFormat();
|
|
150
|
+
const metrics = tickable.getMetrics();
|
|
151
|
+
this.leftDisplacedHeadPx = Math.max(this.leftDisplacedHeadPx, metrics.leftDisplacedHeadPx);
|
|
152
|
+
this.rightDisplacedHeadPx = Math.max(this.rightDisplacedHeadPx, metrics.rightDisplacedHeadPx);
|
|
153
|
+
this.notePx = Math.max(this.notePx, metrics.notePx);
|
|
154
|
+
this.glyphPx = Math.max(this.glyphPx, (_a = metrics.glyphWidth) !== null && _a !== void 0 ? _a : 0);
|
|
155
|
+
this.modLeftPx = Math.max(this.modLeftPx, metrics.modLeftPx);
|
|
156
|
+
this.modRightPx = Math.max(this.modRightPx, metrics.modRightPx);
|
|
157
|
+
this.totalLeftPx = Math.max(this.totalLeftPx, metrics.modLeftPx + metrics.leftDisplacedHeadPx);
|
|
158
|
+
this.totalRightPx = Math.max(this.totalRightPx, metrics.modRightPx + metrics.rightDisplacedHeadPx);
|
|
159
|
+
this.width = this.notePx + this.totalLeftPx + this.totalRightPx;
|
|
160
|
+
}
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
postFormat() {
|
|
164
|
+
if (this.postFormatted)
|
|
165
|
+
return this;
|
|
166
|
+
this.postFormatted = true;
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
getFormatterMetrics() {
|
|
170
|
+
return this.formatterMetrics;
|
|
171
|
+
}
|
|
172
|
+
move(shift, prev, next) {
|
|
173
|
+
this.setX(this.getX() + shift);
|
|
174
|
+
this.getFormatterMetrics().freedom.left += shift;
|
|
175
|
+
this.getFormatterMetrics().freedom.right -= shift;
|
|
176
|
+
if (prev)
|
|
177
|
+
prev.getFormatterMetrics().freedom.right += shift;
|
|
178
|
+
if (next)
|
|
179
|
+
next.getFormatterMetrics().freedom.left -= shift;
|
|
180
|
+
}
|
|
181
|
+
getDeviationCost() {
|
|
182
|
+
return sumArray(this.tickables.map((t) => t.getFormatterMetrics().space.deviation));
|
|
183
|
+
}
|
|
184
|
+
getAverageDeviationCost() {
|
|
185
|
+
if (!this.tickables.length)
|
|
186
|
+
return 0;
|
|
187
|
+
return this.getDeviationCost() / this.tickables.length;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Glyphs } from './glyphs.js';
|
|
3
|
+
import { StaveModifier, StaveModifierPosition } from './stavemodifier.js';
|
|
4
|
+
import { RuntimeError } from './util.js';
|
|
5
|
+
const assertIsValidTimeSig = (timeSpec) => {
|
|
6
|
+
const numbers = timeSpec.split('/');
|
|
7
|
+
numbers.forEach((number) => {
|
|
8
|
+
if (/^[0-9+\-()]+$/.test(number) === false) {
|
|
9
|
+
throw new RuntimeError('BadTimeSignature', `Invalid time spec: ${timeSpec}. Must contain valid signatures.`);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export class TimeSignature extends StaveModifier {
|
|
14
|
+
static get CATEGORY() {
|
|
15
|
+
return "TimeSignature";
|
|
16
|
+
}
|
|
17
|
+
constructor(timeSpec = '4/4', customPadding = 15, validateArgs = true) {
|
|
18
|
+
super();
|
|
19
|
+
this.topRenderY = 0;
|
|
20
|
+
this.botRenderY = 0;
|
|
21
|
+
this.timeSpec = '4/4';
|
|
22
|
+
this.line = 0;
|
|
23
|
+
this.isNumeric = true;
|
|
24
|
+
this.topStartX = 0;
|
|
25
|
+
this.botStartX = 0;
|
|
26
|
+
this.lineShift = 0;
|
|
27
|
+
this.topText = new Element();
|
|
28
|
+
this.botText = new Element();
|
|
29
|
+
this.validateArgs = validateArgs;
|
|
30
|
+
const padding = customPadding;
|
|
31
|
+
this.topLine = 1;
|
|
32
|
+
this.bottomLine = 3;
|
|
33
|
+
this.setPosition(StaveModifierPosition.BEGIN);
|
|
34
|
+
this.setTimeSig(timeSpec);
|
|
35
|
+
this.setPadding(padding);
|
|
36
|
+
}
|
|
37
|
+
static getTimeSigCode(key, smallSig = false) {
|
|
38
|
+
let code = Glyphs.null;
|
|
39
|
+
switch (key) {
|
|
40
|
+
case 'C':
|
|
41
|
+
code = Glyphs.timeSigCommon;
|
|
42
|
+
break;
|
|
43
|
+
case 'C|':
|
|
44
|
+
code = Glyphs.timeSigCutCommon;
|
|
45
|
+
break;
|
|
46
|
+
case '+':
|
|
47
|
+
code = smallSig ? Glyphs.timeSigPlusSmall : Glyphs.timeSigPlus;
|
|
48
|
+
break;
|
|
49
|
+
case '-':
|
|
50
|
+
code = Glyphs.timeSigMinus;
|
|
51
|
+
break;
|
|
52
|
+
case '(':
|
|
53
|
+
code = smallSig ? Glyphs.timeSigParensLeftSmall : Glyphs.timeSigParensLeft;
|
|
54
|
+
break;
|
|
55
|
+
case ')':
|
|
56
|
+
code = smallSig ? Glyphs.timeSigParensRightSmall : Glyphs.timeSigParensRight;
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
code = String.fromCodePoint(0xe080 + Number(key[0]));
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
return code;
|
|
63
|
+
}
|
|
64
|
+
makeTimeSignatureGlyph(topDigits, botDigits) {
|
|
65
|
+
let txt = '';
|
|
66
|
+
let topWidth = 0;
|
|
67
|
+
let height = 0;
|
|
68
|
+
for (let i = 0; i < topDigits.length; ++i) {
|
|
69
|
+
const code = TimeSignature.getTimeSigCode(topDigits[i], botDigits.length > 0);
|
|
70
|
+
txt += code;
|
|
71
|
+
}
|
|
72
|
+
this.topText.setText(txt);
|
|
73
|
+
topWidth = this.topText.getWidth();
|
|
74
|
+
height = this.topText.getHeight();
|
|
75
|
+
let botWidth = 0;
|
|
76
|
+
txt = '';
|
|
77
|
+
for (let i = 0; i < botDigits.length; ++i) {
|
|
78
|
+
const code = TimeSignature.getTimeSigCode(botDigits[i], true);
|
|
79
|
+
txt += code;
|
|
80
|
+
}
|
|
81
|
+
this.botText.setText(txt);
|
|
82
|
+
botWidth = this.botText.getWidth();
|
|
83
|
+
height = Math.max(height, this.botText.getHeight());
|
|
84
|
+
this.lineShift = height > 30 ? 0.5 : 0;
|
|
85
|
+
this.width = Math.max(topWidth, botWidth);
|
|
86
|
+
this.topStartX = (this.width - topWidth) / 2.0;
|
|
87
|
+
this.botStartX = (this.width - botWidth) / 2.0;
|
|
88
|
+
}
|
|
89
|
+
setTimeSig(timeSpec) {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
this.timeSpec = timeSpec;
|
|
92
|
+
if (timeSpec === 'C' || timeSpec === 'C|') {
|
|
93
|
+
const code = TimeSignature.getTimeSigCode(timeSpec);
|
|
94
|
+
this.line = 2;
|
|
95
|
+
this.text = code;
|
|
96
|
+
this.isNumeric = false;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
if (this.validateArgs) {
|
|
100
|
+
assertIsValidTimeSig(timeSpec);
|
|
101
|
+
}
|
|
102
|
+
const parts = timeSpec.split('/');
|
|
103
|
+
this.line = 0;
|
|
104
|
+
this.isNumeric = true;
|
|
105
|
+
this.makeTimeSignatureGlyph((_a = parts[0]) !== null && _a !== void 0 ? _a : '', (_b = parts[1]) !== null && _b !== void 0 ? _b : '');
|
|
106
|
+
}
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
getTimeSpec() {
|
|
110
|
+
return this.timeSpec;
|
|
111
|
+
}
|
|
112
|
+
getLine() {
|
|
113
|
+
return this.line;
|
|
114
|
+
}
|
|
115
|
+
setLine(line) {
|
|
116
|
+
this.line = line;
|
|
117
|
+
}
|
|
118
|
+
getIsNumeric() {
|
|
119
|
+
return this.isNumeric;
|
|
120
|
+
}
|
|
121
|
+
setIsNumeric(isNumeric) {
|
|
122
|
+
this.isNumeric = isNumeric;
|
|
123
|
+
}
|
|
124
|
+
draw() {
|
|
125
|
+
const stave = this.checkStave();
|
|
126
|
+
const ctx = stave.checkContext();
|
|
127
|
+
this.setRendered();
|
|
128
|
+
const clsAttribute = this.getAttribute('class');
|
|
129
|
+
ctx.openGroup('timesignature' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
130
|
+
this.drawAt(ctx, stave, this.x);
|
|
131
|
+
this.drawPointerRect();
|
|
132
|
+
ctx.closeGroup();
|
|
133
|
+
}
|
|
134
|
+
drawAt(ctx, stave, x) {
|
|
135
|
+
this.setRendered();
|
|
136
|
+
if (this.isNumeric) {
|
|
137
|
+
let startX = x + this.topStartX;
|
|
138
|
+
if (this.botText.getText().length > 0) {
|
|
139
|
+
this.topRenderY = stave.getYForLine(this.topLine - this.lineShift);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.topRenderY = (stave.getYForLine(this.topLine) + stave.getYForLine(this.bottomLine)) / 2;
|
|
143
|
+
}
|
|
144
|
+
this.topText.renderText(ctx, startX, this.topRenderY);
|
|
145
|
+
startX = x + this.botStartX;
|
|
146
|
+
this.botRenderY = stave.getYForLine(this.bottomLine + this.lineShift);
|
|
147
|
+
this.botText.renderText(ctx, startX, this.botRenderY);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
this.renderText(ctx, x - this.x, stave.getYForLine(this.line));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
getBoundingBox() {
|
|
154
|
+
if (this.isNumeric) {
|
|
155
|
+
const topBoundingBox = this.topText.getBoundingBox();
|
|
156
|
+
const botBoundingBox = this.botText.getBoundingBox();
|
|
157
|
+
topBoundingBox.move(this.x + this.topStartX, this.topRenderY);
|
|
158
|
+
botBoundingBox.move(this.x + this.botStartX, this.botRenderY);
|
|
159
|
+
const mergedBox = topBoundingBox.mergeWith(botBoundingBox);
|
|
160
|
+
return mergedBox;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const stave = this.checkStave();
|
|
164
|
+
const textBoundingBox = super.getBoundingBox();
|
|
165
|
+
textBoundingBox.move(0, stave.getYForLine(this.line));
|
|
166
|
+
return textBoundingBox;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Note } from './note.js';
|
|
2
|
+
import { TimeSignature } from './timesignature.js';
|
|
3
|
+
export class TimeSigNote extends Note {
|
|
4
|
+
static get CATEGORY() {
|
|
5
|
+
return "TimeSigNote";
|
|
6
|
+
}
|
|
7
|
+
constructor(timeSpec, customPadding) {
|
|
8
|
+
super({ duration: 'b' });
|
|
9
|
+
this.timeSig = new TimeSignature(timeSpec, customPadding);
|
|
10
|
+
this.setWidth(this.timeSig.getWidth());
|
|
11
|
+
this.ignoreTicks = true;
|
|
12
|
+
}
|
|
13
|
+
addToModifierContext(mc) {
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
preFormat() {
|
|
17
|
+
this.preFormatted = true;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
draw() {
|
|
21
|
+
const stave = this.checkStave();
|
|
22
|
+
const ctx = this.checkContext();
|
|
23
|
+
this.setRendered();
|
|
24
|
+
const clsAttribute = this.getAttribute('class');
|
|
25
|
+
ctx.openGroup('timesignote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
26
|
+
this.timeSig.drawAt(ctx, stave, this.getAbsoluteX());
|
|
27
|
+
this.drawPointerRect();
|
|
28
|
+
ctx.closeGroup();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Glyphs } from './glyphs.js';
|
|
2
|
+
import { Metrics } from './metrics.js';
|
|
3
|
+
import { Modifier } from './modifier.js';
|
|
4
|
+
import { Stem } from './stem.js';
|
|
5
|
+
export class Tremolo extends Modifier {
|
|
6
|
+
static get CATEGORY() {
|
|
7
|
+
return "Tremolo";
|
|
8
|
+
}
|
|
9
|
+
constructor(num) {
|
|
10
|
+
super();
|
|
11
|
+
this.num = num;
|
|
12
|
+
this.position = Modifier.Position.CENTER;
|
|
13
|
+
this.text = Glyphs.tremolo1;
|
|
14
|
+
}
|
|
15
|
+
draw() {
|
|
16
|
+
const ctx = this.checkContext();
|
|
17
|
+
const note = this.checkAttachedNote();
|
|
18
|
+
this.setRendered();
|
|
19
|
+
const stemDirection = note.getStemDirection();
|
|
20
|
+
const scale = note.getFontScale();
|
|
21
|
+
const ySpacing = Metrics.get(`Tremolo.spacing`) * stemDirection * scale;
|
|
22
|
+
const x = note.getAbsoluteX() + (stemDirection === Stem.UP ? note.getGlyphWidth() - Stem.WIDTH / 2 : Stem.WIDTH / 2);
|
|
23
|
+
let y = note.getStemExtents().topY + (this.num <= 3 ? ySpacing : 0);
|
|
24
|
+
this.fontInfo.size = Metrics.get(`Tremolo.fontSize`) * scale;
|
|
25
|
+
for (let i = 0; i < this.num; ++i) {
|
|
26
|
+
this.renderText(ctx, x, y);
|
|
27
|
+
y += ySpacing;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Tables } from './tables.js';
|
|
2
|
+
import { RuntimeError } from './util.js';
|
|
3
|
+
export class Tuning {
|
|
4
|
+
static get names() {
|
|
5
|
+
return {
|
|
6
|
+
standard: 'E/5,B/4,G/4,D/4,A/3,E/3',
|
|
7
|
+
dagdad: 'D/5,A/4,G/4,D/4,A/3,D/3',
|
|
8
|
+
dropd: 'E/5,B/4,G/4,D/4,A/3,D/3',
|
|
9
|
+
eb: 'Eb/5,Bb/4,Gb/4,Db/4,Ab/3,Db/3',
|
|
10
|
+
standardBanjo: 'D/5,B/4,G/4,D/4,G/5',
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
constructor(tuningString = 'E/5,B/4,G/4,D/4,A/3,E/3,B/2,E/2') {
|
|
14
|
+
this.tuningValues = [];
|
|
15
|
+
this.setTuning(tuningString);
|
|
16
|
+
}
|
|
17
|
+
noteToInteger(noteString) {
|
|
18
|
+
var _a;
|
|
19
|
+
return (_a = Tables.keyProperties(noteString).intValue) !== null && _a !== void 0 ? _a : -1;
|
|
20
|
+
}
|
|
21
|
+
setTuning(tuningString) {
|
|
22
|
+
if (Tuning.names[tuningString]) {
|
|
23
|
+
tuningString = Tuning.names[tuningString];
|
|
24
|
+
}
|
|
25
|
+
this.tuningValues = [];
|
|
26
|
+
const keys = tuningString.split(/\s*,\s*/);
|
|
27
|
+
if (keys.length === 0) {
|
|
28
|
+
throw new RuntimeError('BadArguments', `Invalid tuning string: ${tuningString}`);
|
|
29
|
+
}
|
|
30
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
31
|
+
this.tuningValues[i] = this.noteToInteger(keys[i]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
getValueForString(stringNum) {
|
|
35
|
+
const s = Number(stringNum);
|
|
36
|
+
if (s < 1 || s > this.tuningValues.length) {
|
|
37
|
+
throw new RuntimeError('BadArguments', `String number must be between 1 and ${this.tuningValues.length}:${stringNum}`);
|
|
38
|
+
}
|
|
39
|
+
return this.tuningValues[s - 1];
|
|
40
|
+
}
|
|
41
|
+
getValueForFret(fretNum, stringNum) {
|
|
42
|
+
const stringValue = this.getValueForString(stringNum);
|
|
43
|
+
const f = Number(fretNum);
|
|
44
|
+
if (f < 0) {
|
|
45
|
+
throw new RuntimeError('BadArguments', `Fret number must be 0 or higher: ${fretNum}`);
|
|
46
|
+
}
|
|
47
|
+
return stringValue + f;
|
|
48
|
+
}
|
|
49
|
+
getNoteForFret(fretNum, stringNum) {
|
|
50
|
+
const noteValue = this.getValueForFret(fretNum, stringNum);
|
|
51
|
+
const octave = Math.floor(noteValue / 12);
|
|
52
|
+
const value = noteValue % 12;
|
|
53
|
+
return `${Tables.integerToNote(value)}/${octave}`;
|
|
54
|
+
}
|
|
55
|
+
}
|