@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,170 @@
|
|
|
1
|
+
import { RuntimeError } from './util.js';
|
|
2
|
+
export class Fraction {
|
|
3
|
+
static get CATEGORY() {
|
|
4
|
+
return "Fraction";
|
|
5
|
+
}
|
|
6
|
+
static GCD(a, b) {
|
|
7
|
+
if (typeof a !== 'number' || Number.isNaN(a) || typeof b !== 'number' || Number.isNaN(b)) {
|
|
8
|
+
throw new RuntimeError('BadArgument', `Invalid numbers: ${a}, ${b}`);
|
|
9
|
+
}
|
|
10
|
+
let t;
|
|
11
|
+
while (b !== 0) {
|
|
12
|
+
t = b;
|
|
13
|
+
b = a % b;
|
|
14
|
+
a = t;
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
}
|
|
18
|
+
static LCM(a, b) {
|
|
19
|
+
return (a * b) / Fraction.GCD(a, b);
|
|
20
|
+
}
|
|
21
|
+
static LCMM(args) {
|
|
22
|
+
if (args.length === 0) {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
else if (args.length === 1) {
|
|
26
|
+
return args[0];
|
|
27
|
+
}
|
|
28
|
+
else if (args.length === 2) {
|
|
29
|
+
return Fraction.LCM(args[0], args[1]);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return Fraction.LCM(args.shift(), Fraction.LCMM(args));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
constructor(numerator, denominator) {
|
|
36
|
+
this.numerator = 1;
|
|
37
|
+
this.denominator = 1;
|
|
38
|
+
this.set(numerator, denominator);
|
|
39
|
+
}
|
|
40
|
+
set(numerator = 1, denominator = 1) {
|
|
41
|
+
this.numerator = numerator;
|
|
42
|
+
this.denominator = denominator;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
value() {
|
|
46
|
+
return this.numerator / this.denominator;
|
|
47
|
+
}
|
|
48
|
+
simplify() {
|
|
49
|
+
let u = this.numerator;
|
|
50
|
+
let d = this.denominator;
|
|
51
|
+
const gcd = Fraction.GCD(u, d);
|
|
52
|
+
u /= gcd;
|
|
53
|
+
d /= gcd;
|
|
54
|
+
if (d < 0) {
|
|
55
|
+
d = -d;
|
|
56
|
+
u = -u;
|
|
57
|
+
}
|
|
58
|
+
return this.set(u, d);
|
|
59
|
+
}
|
|
60
|
+
add(param1 = 0, param2 = 1) {
|
|
61
|
+
const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
|
|
62
|
+
const lcm = Fraction.LCM(this.denominator, otherDenominator);
|
|
63
|
+
const a = lcm / this.denominator;
|
|
64
|
+
const b = lcm / otherDenominator;
|
|
65
|
+
const u = this.numerator * a + otherNumerator * b;
|
|
66
|
+
return this.set(u, lcm);
|
|
67
|
+
}
|
|
68
|
+
subtract(param1 = 0, param2 = 1) {
|
|
69
|
+
const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
|
|
70
|
+
const lcm = Fraction.LCM(this.denominator, otherDenominator);
|
|
71
|
+
const a = lcm / this.denominator;
|
|
72
|
+
const b = lcm / otherDenominator;
|
|
73
|
+
const u = this.numerator * a - otherNumerator * b;
|
|
74
|
+
return this.set(u, lcm);
|
|
75
|
+
}
|
|
76
|
+
multiply(param1 = 1, param2 = 1) {
|
|
77
|
+
const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
|
|
78
|
+
return this.set(this.numerator * otherNumerator, this.denominator * otherDenominator);
|
|
79
|
+
}
|
|
80
|
+
divide(param1 = 1, param2 = 1) {
|
|
81
|
+
const [otherNumerator, otherDenominator] = getNumeratorAndDenominator(param1, param2);
|
|
82
|
+
return this.set(this.numerator * otherDenominator, this.denominator * otherNumerator);
|
|
83
|
+
}
|
|
84
|
+
equals(compare) {
|
|
85
|
+
const a = Fraction.fractionA.copy(compare).simplify();
|
|
86
|
+
const b = Fraction.fractionB.copy(this).simplify();
|
|
87
|
+
return a.numerator === b.numerator && a.denominator === b.denominator;
|
|
88
|
+
}
|
|
89
|
+
greaterThan(compare) {
|
|
90
|
+
const a = Fraction.fractionA.copy(this);
|
|
91
|
+
a.subtract(compare);
|
|
92
|
+
return a.numerator > 0;
|
|
93
|
+
}
|
|
94
|
+
greaterThanEquals(compare) {
|
|
95
|
+
const a = Fraction.fractionA.copy(this);
|
|
96
|
+
a.subtract(compare);
|
|
97
|
+
return a.numerator >= 0;
|
|
98
|
+
}
|
|
99
|
+
lessThan(compare) {
|
|
100
|
+
return !this.greaterThanEquals(compare);
|
|
101
|
+
}
|
|
102
|
+
lessThanEquals(compare) {
|
|
103
|
+
return !this.greaterThan(compare);
|
|
104
|
+
}
|
|
105
|
+
clone() {
|
|
106
|
+
return new Fraction(this.numerator, this.denominator);
|
|
107
|
+
}
|
|
108
|
+
copy(other) {
|
|
109
|
+
if (typeof other === 'number') {
|
|
110
|
+
return this.set(other);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
return this.set(other.numerator, other.denominator);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
quotient() {
|
|
117
|
+
return Math.floor(this.numerator / this.denominator);
|
|
118
|
+
}
|
|
119
|
+
remainder() {
|
|
120
|
+
return this.numerator % this.denominator;
|
|
121
|
+
}
|
|
122
|
+
makeAbs() {
|
|
123
|
+
this.denominator = Math.abs(this.denominator);
|
|
124
|
+
this.numerator = Math.abs(this.numerator);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
toString() {
|
|
128
|
+
return `${this.numerator}/${this.denominator}`;
|
|
129
|
+
}
|
|
130
|
+
toSimplifiedString() {
|
|
131
|
+
return Fraction.fractionA.copy(this).simplify().toString();
|
|
132
|
+
}
|
|
133
|
+
toMixedString() {
|
|
134
|
+
let s = '';
|
|
135
|
+
const q = this.quotient();
|
|
136
|
+
const f = Fraction.fractionA.copy(this);
|
|
137
|
+
if (q < 0) {
|
|
138
|
+
f.makeAbs();
|
|
139
|
+
}
|
|
140
|
+
if (q !== 0) {
|
|
141
|
+
s += q;
|
|
142
|
+
if (f.numerator !== 0) {
|
|
143
|
+
s += ` ${f.toSimplifiedString()}`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else if (f.numerator === 0) {
|
|
147
|
+
s = '0';
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
s = f.toSimplifiedString();
|
|
151
|
+
}
|
|
152
|
+
return s;
|
|
153
|
+
}
|
|
154
|
+
parse(str) {
|
|
155
|
+
const i = str.split('/');
|
|
156
|
+
const n = parseInt(i[0], 10);
|
|
157
|
+
const d = i[1] ? parseInt(i[1], 10) : 1;
|
|
158
|
+
return this.set(n, d);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
Fraction.fractionA = new Fraction();
|
|
162
|
+
Fraction.fractionB = new Fraction();
|
|
163
|
+
function getNumeratorAndDenominator(n, d = 1) {
|
|
164
|
+
if (typeof n === 'number') {
|
|
165
|
+
return [n, d];
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return [n.numerator, n.denominator];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Metrics } from './metrics.js';
|
|
2
|
+
import { Modifier, ModifierPosition } from './modifier.js';
|
|
3
|
+
import { Tables } from './tables.js';
|
|
4
|
+
import { RuntimeError } from './util.js';
|
|
5
|
+
export class FretHandFinger extends Modifier {
|
|
6
|
+
static get CATEGORY() {
|
|
7
|
+
return "FretHandFinger";
|
|
8
|
+
}
|
|
9
|
+
static format(nums, state) {
|
|
10
|
+
const { leftShift, rightShift } = state;
|
|
11
|
+
const numSpacing = 1;
|
|
12
|
+
if (!nums || nums.length === 0)
|
|
13
|
+
return false;
|
|
14
|
+
const numsList = [];
|
|
15
|
+
let prevNote = null;
|
|
16
|
+
let shiftLeft = 0;
|
|
17
|
+
let shiftRight = 0;
|
|
18
|
+
for (let i = 0; i < nums.length; ++i) {
|
|
19
|
+
const num = nums[i];
|
|
20
|
+
const note = num.getNote();
|
|
21
|
+
const pos = num.getPosition();
|
|
22
|
+
const index = num.checkIndex();
|
|
23
|
+
const props = note.getKeyProps()[index];
|
|
24
|
+
const textHeight = Metrics.get('FretHandFinger.fontSize');
|
|
25
|
+
if (num.position === ModifierPosition.ABOVE) {
|
|
26
|
+
state.topTextLine += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
|
|
27
|
+
}
|
|
28
|
+
if (num.position === ModifierPosition.BELOW) {
|
|
29
|
+
state.textLine += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
|
|
30
|
+
}
|
|
31
|
+
if (note !== prevNote) {
|
|
32
|
+
for (let n = 0; n < note.keys.length; ++n) {
|
|
33
|
+
if (leftShift === 0) {
|
|
34
|
+
shiftLeft = Math.max(note.getLeftDisplacedHeadPx(), shiftLeft);
|
|
35
|
+
}
|
|
36
|
+
if (rightShift === 0) {
|
|
37
|
+
shiftRight = Math.max(note.getRightDisplacedHeadPx(), shiftRight);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
prevNote = note;
|
|
41
|
+
}
|
|
42
|
+
numsList.push({
|
|
43
|
+
note,
|
|
44
|
+
num,
|
|
45
|
+
pos,
|
|
46
|
+
line: props.line,
|
|
47
|
+
shiftL: shiftLeft,
|
|
48
|
+
shiftR: shiftRight,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
numsList.sort((a, b) => b.line - a.line);
|
|
52
|
+
let numShiftL = 0;
|
|
53
|
+
let numShiftR = 0;
|
|
54
|
+
let xWidthL = 0;
|
|
55
|
+
let xWidthR = 0;
|
|
56
|
+
let lastLine = null;
|
|
57
|
+
let lastNote = null;
|
|
58
|
+
for (let i = 0; i < numsList.length; ++i) {
|
|
59
|
+
let numShift = 0;
|
|
60
|
+
const { note, pos, num, line, shiftL, shiftR } = numsList[i];
|
|
61
|
+
if (line !== lastLine || note !== lastNote) {
|
|
62
|
+
numShiftL = leftShift + shiftL;
|
|
63
|
+
numShiftR = rightShift + shiftR;
|
|
64
|
+
}
|
|
65
|
+
const numWidth = num.getWidth() + numSpacing;
|
|
66
|
+
if (pos === Modifier.Position.LEFT) {
|
|
67
|
+
num.setXShift(leftShift + numShiftL);
|
|
68
|
+
numShift = leftShift + numWidth;
|
|
69
|
+
xWidthL = numShift > xWidthL ? numShift : xWidthL;
|
|
70
|
+
}
|
|
71
|
+
else if (pos === Modifier.Position.RIGHT) {
|
|
72
|
+
num.setXShift(numShiftR);
|
|
73
|
+
numShift = shiftRight + numWidth;
|
|
74
|
+
xWidthR = numShift > xWidthR ? numShift : xWidthR;
|
|
75
|
+
}
|
|
76
|
+
lastLine = line;
|
|
77
|
+
lastNote = note;
|
|
78
|
+
}
|
|
79
|
+
state.leftShift += xWidthL;
|
|
80
|
+
state.rightShift += xWidthR;
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
static easyScoreHook({ fingerings } = {}, note, builder) {
|
|
84
|
+
fingerings === null || fingerings === void 0 ? void 0 : fingerings.split(',').map((fingeringString) => {
|
|
85
|
+
const split = fingeringString.trim().split('.');
|
|
86
|
+
const params = { number: split[0] };
|
|
87
|
+
if (split[1])
|
|
88
|
+
params.position = split[1];
|
|
89
|
+
return builder.getFactory().Fingering(params);
|
|
90
|
+
}).map((fingering, index) => note.addModifier(fingering, index));
|
|
91
|
+
}
|
|
92
|
+
constructor(finger) {
|
|
93
|
+
super();
|
|
94
|
+
this.setFretHandFinger(finger);
|
|
95
|
+
this.position = Modifier.Position.LEFT;
|
|
96
|
+
this.xOffset = 0;
|
|
97
|
+
this.yOffset = 0;
|
|
98
|
+
}
|
|
99
|
+
setFretHandFinger(finger) {
|
|
100
|
+
this.text = finger;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
getFretHandFinger() {
|
|
104
|
+
return this.text;
|
|
105
|
+
}
|
|
106
|
+
setOffsetX(x) {
|
|
107
|
+
this.xOffset = x;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
setOffsetY(y) {
|
|
111
|
+
this.yOffset = y;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
draw() {
|
|
115
|
+
const ctx = this.checkContext();
|
|
116
|
+
const note = this.checkAttachedNote();
|
|
117
|
+
this.setRendered();
|
|
118
|
+
const start = note.getModifierStartXY(this.position, this.index);
|
|
119
|
+
let dotX = start.x + this.xOffset;
|
|
120
|
+
let dotY = start.y + this.yOffset + 5;
|
|
121
|
+
switch (this.position) {
|
|
122
|
+
case Modifier.Position.ABOVE:
|
|
123
|
+
dotX -= 4;
|
|
124
|
+
dotY -= 12;
|
|
125
|
+
break;
|
|
126
|
+
case Modifier.Position.BELOW:
|
|
127
|
+
dotX -= 2;
|
|
128
|
+
dotY += 10;
|
|
129
|
+
break;
|
|
130
|
+
case Modifier.Position.LEFT:
|
|
131
|
+
dotX -= this.width;
|
|
132
|
+
break;
|
|
133
|
+
case Modifier.Position.RIGHT:
|
|
134
|
+
dotX += 1;
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
throw new RuntimeError('InvalidPosition', `The position ${this.position} does not exist`);
|
|
138
|
+
}
|
|
139
|
+
this.renderText(ctx, dotX, dotY);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { StemmableNote } from './stemmablenote.js';
|
|
2
|
+
import { isAnnotation } from './typeguard.js';
|
|
3
|
+
import { RuntimeError } from './util.js';
|
|
4
|
+
const ERROR_MSG = 'Ghost note must have valid initialization data to identify duration.';
|
|
5
|
+
export class GhostNote extends StemmableNote {
|
|
6
|
+
static get CATEGORY() {
|
|
7
|
+
return "GhostNote";
|
|
8
|
+
}
|
|
9
|
+
constructor(parameter) {
|
|
10
|
+
if (!parameter) {
|
|
11
|
+
throw new RuntimeError('BadArguments', ERROR_MSG);
|
|
12
|
+
}
|
|
13
|
+
let noteStruct;
|
|
14
|
+
if (typeof parameter === 'string') {
|
|
15
|
+
noteStruct = { duration: parameter };
|
|
16
|
+
}
|
|
17
|
+
else if (typeof parameter === 'object') {
|
|
18
|
+
noteStruct = parameter;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
throw new RuntimeError('BadArguments', ERROR_MSG);
|
|
22
|
+
}
|
|
23
|
+
super(noteStruct);
|
|
24
|
+
this.setWidth(0);
|
|
25
|
+
}
|
|
26
|
+
isRest() {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
setStave(stave) {
|
|
30
|
+
super.setStave(stave);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
addToModifierContext(mc) {
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
preFormat() {
|
|
37
|
+
this.preFormatted = true;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
draw() {
|
|
41
|
+
this.setRendered();
|
|
42
|
+
for (let i = 0; i < this.modifiers.length; ++i) {
|
|
43
|
+
const modifier = this.modifiers[i];
|
|
44
|
+
if (isAnnotation(modifier)) {
|
|
45
|
+
modifier.setContext(this.getContext());
|
|
46
|
+
modifier.drawWithStyle();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Note } from './note.js';
|
|
2
|
+
export class GlyphNote extends Note {
|
|
3
|
+
static get CATEGORY() {
|
|
4
|
+
return "GlyphNote";
|
|
5
|
+
}
|
|
6
|
+
constructor(glyph, noteStruct, options) {
|
|
7
|
+
super(noteStruct);
|
|
8
|
+
this.options = Object.assign({ ignoreTicks: false, line: 2 }, options);
|
|
9
|
+
this.ignoreTicks = this.options.ignoreTicks;
|
|
10
|
+
this.setGlyph(glyph);
|
|
11
|
+
}
|
|
12
|
+
setGlyph(glyph) {
|
|
13
|
+
this.text = glyph;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
preFormat() {
|
|
17
|
+
if (!this.preFormatted && this.modifierContext) {
|
|
18
|
+
this.modifierContext.preFormat();
|
|
19
|
+
}
|
|
20
|
+
this.preFormatted = true;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
drawModifiers() {
|
|
24
|
+
const ctx = this.checkContext();
|
|
25
|
+
for (let i = 0; i < this.modifiers.length; i++) {
|
|
26
|
+
const modifier = this.modifiers[i];
|
|
27
|
+
modifier.setContext(ctx);
|
|
28
|
+
modifier.drawWithStyle();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
draw() {
|
|
32
|
+
const stave = this.checkStave();
|
|
33
|
+
const ctx = stave.checkContext();
|
|
34
|
+
this.setRendered();
|
|
35
|
+
const clsAttribute = this.getAttribute('class');
|
|
36
|
+
ctx.openGroup('glyphNote' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
37
|
+
this.x = this.isCenterAligned() ? this.getAbsoluteX() - this.getWidth() / 2 : this.getAbsoluteX();
|
|
38
|
+
this.y = stave.getYForLine(this.options.line);
|
|
39
|
+
this.renderText(ctx, 0, 0);
|
|
40
|
+
this.drawModifiers();
|
|
41
|
+
this.drawPointerRect();
|
|
42
|
+
ctx.closeGroup();
|
|
43
|
+
}
|
|
44
|
+
}
|