vexflow 4.0.1-beta.1 → 4.0.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/README.md +48 -65
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +724 -697
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +550 -610
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow-font-gonville.js +1 -1
- package/build/cjs/vexflow-font-gonville.js.map +1 -1
- package/build/cjs/vexflow-gonville.js +2 -2
- package/build/cjs/vexflow-gonville.js.map +1 -1
- package/build/cjs/vexflow-petaluma.js +2 -2
- package/build/cjs/vexflow-petaluma.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/entry/vexflow-bravura.js +10 -0
- package/build/esm/entry/vexflow-core.js +53 -0
- package/build/esm/entry/vexflow-debug-with-tests.js +11 -0
- package/build/esm/entry/vexflow-debug.js +8 -0
- package/build/esm/entry/vexflow-font-bravura.js +7 -0
- package/build/esm/entry/vexflow-font-custom.js +7 -0
- package/build/esm/entry/vexflow-font-gonville.js +7 -0
- package/build/esm/entry/vexflow-font-petaluma.js +7 -0
- package/build/esm/entry/vexflow-gonville.js +10 -0
- package/build/esm/entry/vexflow-petaluma.js +10 -0
- package/build/esm/entry/vexflow.js +8 -0
- package/build/esm/src/accidental.js +348 -0
- package/build/esm/src/annotation.js +238 -0
- package/build/esm/src/articulation.js +267 -0
- package/build/esm/src/barnote.js +58 -0
- package/build/esm/src/beam.js +644 -0
- package/build/esm/src/bend.js +202 -0
- package/build/esm/src/boundingbox.js +59 -0
- package/build/esm/src/boundingboxcomputation.js +107 -0
- package/build/esm/src/canvascontext.js +202 -0
- package/build/esm/src/chordsymbol.js +578 -0
- package/build/esm/src/clef.js +153 -0
- package/build/esm/src/clefnote.js +65 -0
- package/build/esm/src/crescendo.js +77 -0
- package/build/esm/src/curve.js +118 -0
- package/build/esm/src/dot.js +137 -0
- package/build/esm/src/easyscore.js +374 -0
- package/build/esm/src/element.js +216 -0
- package/build/esm/src/factory.js +445 -0
- package/build/esm/src/flow.js +288 -0
- package/build/esm/src/font.js +262 -0
- package/build/esm/src/fonts/bravura_glyphs.js +3239 -0
- package/build/esm/src/fonts/bravura_metrics.js +507 -0
- package/build/esm/src/fonts/custom_glyphs.js +78 -0
- package/build/esm/src/fonts/custom_metrics.js +5 -0
- package/build/esm/src/fonts/gonville_glyphs.js +828 -0
- package/build/esm/src/fonts/gonville_metrics.js +421 -0
- package/build/esm/src/fonts/load_all.js +10 -0
- package/build/esm/src/fonts/load_bravura.js +6 -0
- package/build/esm/src/fonts/load_custom.js +6 -0
- package/build/esm/src/fonts/load_gonville.js +6 -0
- package/build/esm/src/fonts/load_petaluma.js +6 -0
- package/build/esm/src/fonts/petaluma_glyphs.js +1335 -0
- package/build/esm/src/fonts/petaluma_metrics.js +536 -0
- package/build/esm/src/fonts/petalumascript_glyphs.js +863 -0
- package/build/esm/src/fonts/robotoslab_glyphs.js +863 -0
- package/build/esm/src/fonts/textfonts.js +44 -0
- package/build/esm/src/formatter.js +585 -0
- package/build/esm/src/fraction.js +171 -0
- package/build/esm/src/frethandfinger.js +156 -0
- package/build/esm/src/ghostnote.js +50 -0
- package/build/esm/src/glyph.js +337 -0
- package/build/esm/src/glyphnote.js +55 -0
- package/build/esm/src/gracenote.js +133 -0
- package/build/esm/src/gracenotegroup.js +128 -0
- package/build/esm/src/gracetabnote.js +12 -0
- package/build/esm/src/index.js +89 -0
- package/build/esm/src/keymanager.js +99 -0
- package/build/esm/src/keysignature.js +250 -0
- package/build/esm/src/keysignote.js +28 -0
- package/build/esm/src/modifier.js +128 -0
- package/build/esm/src/modifiercontext.js +110 -0
- package/build/esm/src/multimeasurerest.js +173 -0
- package/build/esm/src/music.js +322 -0
- package/build/esm/src/note.js +371 -0
- package/build/esm/src/notehead.js +169 -0
- package/build/esm/src/notesubgroup.js +59 -0
- package/build/esm/src/ornament.js +206 -0
- package/build/esm/src/parenthesis.js +76 -0
- package/build/esm/src/parser.js +164 -0
- package/build/esm/src/pedalmarking.js +192 -0
- package/build/esm/src/registry.js +81 -0
- package/build/esm/src/rendercontext.js +24 -0
- package/build/esm/src/renderer.js +112 -0
- package/build/esm/src/repeatnote.js +22 -0
- package/build/esm/src/stave.js +547 -0
- package/build/esm/src/stavebarline.js +182 -0
- package/build/esm/src/staveconnector.js +196 -0
- package/build/esm/src/stavehairpin.js +120 -0
- package/build/esm/src/staveline.js +215 -0
- package/build/esm/src/stavemodifier.js +77 -0
- package/build/esm/src/stavenote.js +860 -0
- package/build/esm/src/staverepetition.js +155 -0
- package/build/esm/src/stavesection.js +58 -0
- package/build/esm/src/stavetempo.js +91 -0
- package/build/esm/src/stavetext.js +82 -0
- package/build/esm/src/stavetie.js +141 -0
- package/build/esm/src/stavevolta.js +67 -0
- package/build/esm/src/stem.js +131 -0
- package/build/esm/src/stemmablenote.js +193 -0
- package/build/esm/src/stringnumber.js +231 -0
- package/build/esm/src/strokes.js +200 -0
- package/build/esm/src/svgcontext.js +414 -0
- package/build/esm/src/system.js +109 -0
- package/build/esm/src/tables.js +1102 -0
- package/build/esm/src/tabnote.js +299 -0
- package/build/esm/src/tabslide.js +76 -0
- package/build/esm/src/tabstave.js +17 -0
- package/build/esm/src/tabtie.js +19 -0
- package/build/esm/src/textbracket.js +144 -0
- package/build/esm/src/textdynamics.js +81 -0
- package/build/esm/src/textformatter.js +177 -0
- package/build/esm/src/textnote.js +174 -0
- package/build/esm/src/tickable.js +214 -0
- package/build/esm/src/tickcontext.js +170 -0
- package/build/esm/src/timesigglyph.js +85 -0
- package/build/esm/src/timesignature.js +89 -0
- package/build/esm/src/timesignote.js +32 -0
- package/build/esm/src/tremolo.js +47 -0
- package/build/esm/src/tuning.js +54 -0
- package/build/esm/src/tuplet.js +240 -0
- package/build/esm/src/typeguard.js +30 -0
- package/build/esm/src/util.js +58 -0
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vex.js +51 -0
- package/build/esm/src/vibrato.js +100 -0
- package/build/esm/src/vibratobracket.js +50 -0
- package/build/esm/src/voice.js +187 -0
- package/build/esm/src/web.js +15 -0
- package/build/esm/tests/accidental_tests.js +974 -0
- package/build/esm/tests/annotation_tests.js +390 -0
- package/build/esm/tests/articulation_tests.js +365 -0
- package/build/esm/tests/auto_beam_formatting_tests.js +548 -0
- package/build/esm/tests/bach_tests.js +335 -0
- package/build/esm/tests/barline_tests.js +52 -0
- package/build/esm/tests/beam_tests.js +614 -0
- package/build/esm/tests/bend_tests.js +215 -0
- package/build/esm/tests/boundingbox_tests.js +53 -0
- package/build/esm/tests/boundingboxcomputation_tests.js +183 -0
- package/build/esm/tests/chordsymbol_tests.js +320 -0
- package/build/esm/tests/clef_tests.js +131 -0
- package/build/esm/tests/curve_tests.js +118 -0
- package/build/esm/tests/dot_tests.js +123 -0
- package/build/esm/tests/easyscore_tests.js +462 -0
- package/build/esm/tests/factory_tests.js +44 -0
- package/build/esm/tests/font_tests.js +135 -0
- package/build/esm/tests/formatter/framestack.js +61 -0
- package/build/esm/tests/formatter/tests.js +203 -0
- package/build/esm/tests/formatter_tests.js +670 -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 +113 -0
- package/build/esm/tests/gracenote_tests.js +413 -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 +103 -0
- package/build/esm/tests/keymanager_tests.js +68 -0
- package/build/esm/tests/keysignature_tests.js +308 -0
- package/build/esm/tests/mocks.js +71 -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/notehead_tests.js +137 -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 +298 -0
- package/build/esm/tests/parser_tests.js +122 -0
- package/build/esm/tests/pedalmarking_tests.js +64 -0
- package/build/esm/tests/percussion_tests.js +180 -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 +248 -0
- package/build/esm/tests/rhythm_tests.js +357 -0
- package/build/esm/tests/stave_tests.js +560 -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 +122 -0
- package/build/esm/tests/stavemodifier_tests.js +51 -0
- package/build/esm/tests/stavenote_tests.js +867 -0
- package/build/esm/tests/stavetie_tests.js +108 -0
- package/build/esm/tests/stringnumber_tests.js +259 -0
- package/build/esm/tests/strokes_tests.js +275 -0
- package/build/esm/tests/style_tests.js +98 -0
- package/build/esm/tests/support/qunit.js +2765 -0
- package/build/esm/tests/tabnote_tests.js +474 -0
- package/build/esm/tests/tabslide_tests.js +135 -0
- package/build/esm/tests/tabstave_tests.js +23 -0
- package/build/esm/tests/tabtie_tests.js +173 -0
- package/build/esm/tests/textbracket_tests.js +100 -0
- package/build/esm/tests/textformatter_tests.js +24 -0
- package/build/esm/tests/textnote_tests.js +215 -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 +134 -0
- package/build/esm/tests/tremolo_tests.js +75 -0
- package/build/esm/tests/tuning_tests.js +56 -0
- package/build/esm/tests/tuplet_tests.js +450 -0
- package/build/esm/tests/typeguard_tests.js +82 -0
- package/build/esm/tests/vexflow_test_helpers.js +266 -0
- package/build/esm/tests/vf_prefix_tests.js +115 -0
- package/build/esm/tests/vibrato_tests.js +92 -0
- package/build/esm/tests/vibratobracket_tests.js +45 -0
- package/build/esm/tests/voice_tests.js +69 -0
- package/build/types/entry/vexflow-bravura.d.ts +2 -0
- package/build/types/entry/vexflow-core.d.ts +2 -0
- package/build/types/entry/vexflow-debug.d.ts +2 -0
- package/build/types/entry/vexflow-font-bravura.d.ts +3771 -0
- package/build/types/entry/vexflow-font-custom.d.ts +86 -0
- package/build/types/entry/vexflow-font-gonville.d.ts +1267 -0
- package/build/types/entry/vexflow-font-petaluma.d.ts +1896 -0
- package/build/types/entry/vexflow-gonville.d.ts +2 -0
- package/build/types/entry/vexflow-petaluma.d.ts +2 -0
- package/build/types/entry/vexflow.d.ts +2 -0
- package/build/types/src/accidental.d.ts +66 -0
- package/build/types/src/annotation.d.ts +61 -0
- package/build/types/src/articulation.d.ts +62 -0
- package/build/types/src/barnote.d.ts +29 -0
- package/build/types/src/beam.d.ts +153 -0
- package/build/types/src/bend.d.ts +73 -0
- package/build/types/src/boundingbox.d.ts +42 -0
- package/build/types/src/boundingboxcomputation.d.ts +33 -0
- package/build/types/src/canvascontext.d.ts +89 -0
- package/build/types/src/chordsymbol.d.ts +149 -0
- package/build/types/src/clef.d.ts +48 -0
- package/build/types/src/clefnote.d.ts +25 -0
- package/build/types/src/crescendo.d.ts +27 -0
- package/build/types/src/curve.d.ts +41 -0
- package/build/types/src/dot.d.ts +20 -0
- package/build/types/src/easyscore.d.ts +152 -0
- package/build/types/src/element.d.ts +202 -0
- package/build/types/src/factory.d.ts +274 -0
- package/build/types/src/flow.d.ts +260 -0
- package/build/types/src/font.d.ts +180 -0
- package/build/types/src/fonts/bravura_glyphs.d.ts +3239 -0
- package/build/types/src/fonts/bravura_metrics.d.ts +533 -0
- package/build/types/src/fonts/custom_glyphs.d.ts +78 -0
- package/build/types/src/fonts/custom_metrics.d.ts +5 -0
- package/build/types/src/fonts/gonville_glyphs.d.ts +828 -0
- package/build/types/src/fonts/gonville_metrics.d.ts +440 -0
- package/build/types/src/fonts/load_all.d.ts +1 -0
- package/build/types/src/fonts/load_bravura.d.ts +1 -0
- package/build/types/src/fonts/load_custom.d.ts +1 -0
- package/build/types/src/fonts/load_gonville.d.ts +1 -0
- package/build/types/src/fonts/load_petaluma.d.ts +1 -0
- package/build/types/src/fonts/petaluma_glyphs.d.ts +1335 -0
- package/build/types/src/fonts/petaluma_metrics.d.ts +562 -0
- package/build/types/src/fonts/petalumascript_glyphs.d.ts +863 -0
- package/build/types/src/fonts/robotoslab_glyphs.d.ts +863 -0
- package/build/types/src/fonts/textfonts.d.ts +1 -0
- package/build/types/src/formatter.d.ts +203 -0
- package/build/types/src/fraction.d.ts +62 -0
- package/build/types/src/frethandfinger.d.ts +22 -0
- package/build/types/src/ghostnote.d.ts +16 -0
- package/build/types/src/glyph.d.ts +141 -0
- package/build/types/src/glyphnote.d.ts +17 -0
- package/build/types/src/gracenote.d.ts +19 -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 +89 -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/modifier.d.ts +97 -0
- package/build/types/src/modifiercontext.d.ts +45 -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 +70 -0
- package/build/types/src/notesubgroup.d.ts +18 -0
- package/build/types/src/ornament.d.ts +76 -0
- package/build/types/src/parenthesis.d.ts +22 -0
- package/build/types/src/parser.d.ts +45 -0
- package/build/types/src/pedalmarking.d.ts +69 -0
- package/build/types/src/registry.d.ts +40 -0
- package/build/types/src/rendercontext.d.ts +64 -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 +186 -0
- package/build/types/src/stavebarline.d.ts +28 -0
- package/build/types/src/staveconnector.d.ts +67 -0
- package/build/types/src/stavehairpin.d.ts +56 -0
- package/build/types/src/staveline.d.ts +54 -0
- package/build/types/src/stavemodifier.d.ts +44 -0
- package/build/types/src/stavenote.d.ts +154 -0
- package/build/types/src/staverepetition.d.ts +32 -0
- package/build/types/src/stavesection.d.ts +15 -0
- package/build/types/src/stavetempo.d.ts +25 -0
- package/build/types/src/stavetext.d.ts +25 -0
- package/build/types/src/stavetie.d.ts +59 -0
- package/build/types/src/stavevolta.d.ts +21 -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 +27 -0
- package/build/types/src/strokes.d.ts +33 -0
- package/build/types/src/svgcontext.d.ts +131 -0
- package/build/types/src/system.d.ts +92 -0
- package/build/types/src/tables.d.ts +96 -0
- package/build/types/src/tabnote.d.ts +44 -0
- package/build/types/src/tabslide.d.ts +34 -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 +55 -0
- package/build/types/src/textdynamics.d.ts +39 -0
- package/build/types/src/textformatter.d.ts +109 -0
- package/build/types/src/textnote.d.ts +49 -0
- package/build/types/src/tickable.d.ts +140 -0
- package/build/types/src/tickcontext.d.ts +82 -0
- package/build/types/src/timesigglyph.d.ts +14 -0
- package/build/types/src/timesignature.d.ts +26 -0
- package/build/types/src/timesignote.d.ts +11 -0
- package/build/types/src/tremolo.d.ts +17 -0
- package/build/types/src/tuning.d.ts +23 -0
- package/build/types/src/tuplet.d.ts +105 -0
- package/build/types/src/typeguard.d.ts +99 -0
- package/build/types/src/util.d.ts +27 -0
- package/build/types/src/version.d.ts +3 -0
- package/build/types/src/vex.d.ts +18 -0
- package/build/types/src/vibrato.d.ts +29 -0
- package/build/types/src/vibratobracket.d.ts +33 -0
- package/build/types/src/voice.d.ts +108 -0
- package/build/types/src/web.d.ts +2 -0
- package/entry/vexflow-bravura.ts +3 -3
- package/entry/vexflow-core.ts +3 -3
- package/entry/vexflow-debug-with-tests.ts +16 -2
- package/entry/vexflow-debug.ts +11 -3
- package/entry/vexflow-gonville.ts +3 -3
- package/entry/vexflow-petaluma.ts +3 -3
- package/entry/vexflow.ts +3 -3
- package/package.json +1 -1
- package/src/annotation.ts +38 -6
- package/src/articulation.ts +8 -2
- package/src/beam.ts +53 -6
- package/src/easyscore.ts +11 -1
- package/src/factory.ts +16 -2
- package/src/flow.ts +35 -20
- package/src/font.ts +0 -4
- package/src/fonts/gonville_glyphs.ts +4 -4
- package/src/formatter.ts +24 -8
- package/src/glyph.ts +8 -0
- package/src/index.ts +2 -7
- package/src/note.ts +2 -1
- package/src/staveline.ts +2 -5
- package/src/stavenote.ts +13 -9
- package/src/stavetext.ts +3 -3
- package/src/system.ts +1 -7
- package/src/textnote.ts +9 -11
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { RuntimeError } from './util.js';
|
|
2
|
+
export class Fraction {
|
|
3
|
+
constructor(numerator, denominator) {
|
|
4
|
+
this.numerator = 1;
|
|
5
|
+
this.denominator = 1;
|
|
6
|
+
this.set(numerator, denominator);
|
|
7
|
+
}
|
|
8
|
+
static get CATEGORY() {
|
|
9
|
+
return "Fraction";
|
|
10
|
+
}
|
|
11
|
+
static GCD(a, b) {
|
|
12
|
+
if (typeof a !== 'number' || Number.isNaN(a) || typeof b !== 'number' || Number.isNaN(b)) {
|
|
13
|
+
throw new RuntimeError('BadArgument', `Invalid numbers: ${a}, ${b}`);
|
|
14
|
+
}
|
|
15
|
+
let t;
|
|
16
|
+
while (b !== 0) {
|
|
17
|
+
t = b;
|
|
18
|
+
b = a % b;
|
|
19
|
+
a = t;
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
}
|
|
23
|
+
static LCM(a, b) {
|
|
24
|
+
return (a * b) / Fraction.GCD(a, b);
|
|
25
|
+
}
|
|
26
|
+
static LCMM(args) {
|
|
27
|
+
if (args.length === 0) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
else if (args.length === 1) {
|
|
31
|
+
return args[0];
|
|
32
|
+
}
|
|
33
|
+
else if (args.length === 2) {
|
|
34
|
+
return Fraction.LCM(args[0], args[1]);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return Fraction.LCM(args.shift(), Fraction.LCMM(args));
|
|
38
|
+
}
|
|
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.__staticFractionA.copy(compare).simplify();
|
|
86
|
+
const b = Fraction.__staticFractionB.copy(this).simplify();
|
|
87
|
+
return a.numerator === b.numerator && a.denominator === b.denominator;
|
|
88
|
+
}
|
|
89
|
+
greaterThan(compare) {
|
|
90
|
+
const a = Fraction.__staticFractionB.copy(this);
|
|
91
|
+
a.subtract(compare);
|
|
92
|
+
return a.numerator > 0;
|
|
93
|
+
}
|
|
94
|
+
greaterThanEquals(compare) {
|
|
95
|
+
const a = Fraction.__staticFractionB.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, 1);
|
|
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.__staticFractionTmp.copy(this).simplify().toString();
|
|
132
|
+
}
|
|
133
|
+
toMixedString() {
|
|
134
|
+
let s = '';
|
|
135
|
+
const q = this.quotient();
|
|
136
|
+
const f = Fraction.__staticFractionTmp.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.__staticFractionA = new Fraction();
|
|
162
|
+
Fraction.__staticFractionB = new Fraction();
|
|
163
|
+
Fraction.__staticFractionTmp = new Fraction();
|
|
164
|
+
function getNumeratorAndDenominator(n, d = 1) {
|
|
165
|
+
if (typeof n === 'number') {
|
|
166
|
+
return [n, d];
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return [n.numerator, n.denominator];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Font, FontStyle, FontWeight } from './font.js';
|
|
2
|
+
import { Modifier, ModifierPosition } from './modifier.js';
|
|
3
|
+
import { Tables } from './tables.js';
|
|
4
|
+
import { TextFormatter } from './textformatter.js';
|
|
5
|
+
import { RuntimeError } from './util.js';
|
|
6
|
+
export class FretHandFinger extends Modifier {
|
|
7
|
+
constructor(finger) {
|
|
8
|
+
super();
|
|
9
|
+
this.finger = finger;
|
|
10
|
+
this.width = 7;
|
|
11
|
+
this.position = Modifier.Position.LEFT;
|
|
12
|
+
this.x_shift = 0;
|
|
13
|
+
this.y_shift = 0;
|
|
14
|
+
this.x_offset = 0;
|
|
15
|
+
this.y_offset = 0;
|
|
16
|
+
this.resetFont();
|
|
17
|
+
}
|
|
18
|
+
static get CATEGORY() {
|
|
19
|
+
return "FretHandFinger";
|
|
20
|
+
}
|
|
21
|
+
static format(nums, state) {
|
|
22
|
+
const { left_shift, right_shift } = state;
|
|
23
|
+
const num_spacing = 1;
|
|
24
|
+
if (!nums || nums.length === 0)
|
|
25
|
+
return false;
|
|
26
|
+
const nums_list = [];
|
|
27
|
+
let prev_note = null;
|
|
28
|
+
let shiftLeft = 0;
|
|
29
|
+
let shiftRight = 0;
|
|
30
|
+
for (let i = 0; i < nums.length; ++i) {
|
|
31
|
+
const num = nums[i];
|
|
32
|
+
const note = num.getNote();
|
|
33
|
+
const pos = num.getPosition();
|
|
34
|
+
const index = num.checkIndex();
|
|
35
|
+
const props = note.getKeyProps()[index];
|
|
36
|
+
const textFormatter = TextFormatter.create(num.textFont);
|
|
37
|
+
const textHeight = textFormatter.maxHeight;
|
|
38
|
+
if (num.position === ModifierPosition.ABOVE) {
|
|
39
|
+
state.top_text_line += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
|
|
40
|
+
}
|
|
41
|
+
if (num.position === ModifierPosition.BELOW) {
|
|
42
|
+
state.text_line += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
|
|
43
|
+
}
|
|
44
|
+
if (note !== prev_note) {
|
|
45
|
+
for (let n = 0; n < note.keys.length; ++n) {
|
|
46
|
+
if (left_shift === 0) {
|
|
47
|
+
shiftLeft = Math.max(note.getLeftDisplacedHeadPx(), shiftLeft);
|
|
48
|
+
}
|
|
49
|
+
if (right_shift === 0) {
|
|
50
|
+
shiftRight = Math.max(note.getRightDisplacedHeadPx(), shiftRight);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
prev_note = note;
|
|
54
|
+
}
|
|
55
|
+
nums_list.push({
|
|
56
|
+
note,
|
|
57
|
+
num,
|
|
58
|
+
pos,
|
|
59
|
+
line: props.line,
|
|
60
|
+
shiftL: shiftLeft,
|
|
61
|
+
shiftR: shiftRight,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
nums_list.sort((a, b) => b.line - a.line);
|
|
65
|
+
let numShiftL = 0;
|
|
66
|
+
let numShiftR = 0;
|
|
67
|
+
let xWidthL = 0;
|
|
68
|
+
let xWidthR = 0;
|
|
69
|
+
let lastLine = null;
|
|
70
|
+
let lastNote = null;
|
|
71
|
+
for (let i = 0; i < nums_list.length; ++i) {
|
|
72
|
+
let num_shift = 0;
|
|
73
|
+
const { note, pos, num, line, shiftL, shiftR } = nums_list[i];
|
|
74
|
+
if (line !== lastLine || note !== lastNote) {
|
|
75
|
+
numShiftL = left_shift + shiftL;
|
|
76
|
+
numShiftR = right_shift + shiftR;
|
|
77
|
+
}
|
|
78
|
+
const numWidth = num.getWidth() + num_spacing;
|
|
79
|
+
if (pos === Modifier.Position.LEFT) {
|
|
80
|
+
num.setXShift(left_shift + numShiftL);
|
|
81
|
+
num_shift = left_shift + numWidth;
|
|
82
|
+
xWidthL = num_shift > xWidthL ? num_shift : xWidthL;
|
|
83
|
+
}
|
|
84
|
+
else if (pos === Modifier.Position.RIGHT) {
|
|
85
|
+
num.setXShift(numShiftR);
|
|
86
|
+
num_shift = shiftRight + numWidth;
|
|
87
|
+
xWidthR = num_shift > xWidthR ? num_shift : xWidthR;
|
|
88
|
+
}
|
|
89
|
+
lastLine = line;
|
|
90
|
+
lastNote = note;
|
|
91
|
+
}
|
|
92
|
+
state.left_shift += xWidthL;
|
|
93
|
+
state.right_shift += xWidthR;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
static easyScoreHook({ fingerings } = {}, note, builder) {
|
|
97
|
+
fingerings === null || fingerings === void 0 ? void 0 : fingerings.split(',').map((fingeringString) => {
|
|
98
|
+
const split = fingeringString.trim().split('.');
|
|
99
|
+
const params = { number: split[0] };
|
|
100
|
+
if (split[1])
|
|
101
|
+
params.position = split[1];
|
|
102
|
+
return builder.getFactory().Fingering(params);
|
|
103
|
+
}).map((fingering, index) => note.addModifier(fingering, index));
|
|
104
|
+
}
|
|
105
|
+
setFretHandFinger(finger) {
|
|
106
|
+
this.finger = finger;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
getFretHandFinger() {
|
|
110
|
+
return this.finger;
|
|
111
|
+
}
|
|
112
|
+
setOffsetX(x) {
|
|
113
|
+
this.x_offset = x;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
setOffsetY(y) {
|
|
117
|
+
this.y_offset = y;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
draw() {
|
|
121
|
+
const ctx = this.checkContext();
|
|
122
|
+
const note = this.checkAttachedNote();
|
|
123
|
+
this.setRendered();
|
|
124
|
+
const start = note.getModifierStartXY(this.position, this.index);
|
|
125
|
+
let dot_x = start.x + this.x_shift + this.x_offset;
|
|
126
|
+
let dot_y = start.y + this.y_shift + this.y_offset + 5;
|
|
127
|
+
switch (this.position) {
|
|
128
|
+
case Modifier.Position.ABOVE:
|
|
129
|
+
dot_x -= 4;
|
|
130
|
+
dot_y -= 12;
|
|
131
|
+
break;
|
|
132
|
+
case Modifier.Position.BELOW:
|
|
133
|
+
dot_x -= 2;
|
|
134
|
+
dot_y += 10;
|
|
135
|
+
break;
|
|
136
|
+
case Modifier.Position.LEFT:
|
|
137
|
+
dot_x -= this.width;
|
|
138
|
+
break;
|
|
139
|
+
case Modifier.Position.RIGHT:
|
|
140
|
+
dot_x += 1;
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
throw new RuntimeError('InvalidPosition', `The position ${this.position} does not exist`);
|
|
144
|
+
}
|
|
145
|
+
ctx.save();
|
|
146
|
+
ctx.setFont(this.textFont);
|
|
147
|
+
ctx.fillText('' + this.finger, dot_x, dot_y);
|
|
148
|
+
ctx.restore();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
FretHandFinger.TEXT_FONT = {
|
|
152
|
+
family: Font.SANS_SERIF,
|
|
153
|
+
size: 9,
|
|
154
|
+
weight: FontWeight.BOLD,
|
|
155
|
+
style: FontStyle.NORMAL,
|
|
156
|
+
};
|
|
@@ -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
|
+
}
|