@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,68 @@
|
|
|
1
|
+
import { Bend } from './bend.js';
|
|
2
|
+
import { Modifier } from './modifier.js';
|
|
3
|
+
import { Tables } from './tables.js';
|
|
4
|
+
import { RuntimeError } from './util.js';
|
|
5
|
+
export class Vibrato extends Modifier {
|
|
6
|
+
static get CATEGORY() {
|
|
7
|
+
return "Vibrato";
|
|
8
|
+
}
|
|
9
|
+
static format(vibratos, state, context) {
|
|
10
|
+
if (!vibratos || vibratos.length === 0)
|
|
11
|
+
return false;
|
|
12
|
+
let textLine = state.topTextLine;
|
|
13
|
+
let width = 0;
|
|
14
|
+
let shift = state.rightShift - 7;
|
|
15
|
+
const bends = context.getMembers(Bend.CATEGORY);
|
|
16
|
+
if (bends && bends.length > 0) {
|
|
17
|
+
const bendHeight = bends.map((bb) => bb.getTextHeight()).reduce((a, b) => (a > b ? a : b)) / Tables.STAVE_LINE_DISTANCE;
|
|
18
|
+
textLine = textLine - (bendHeight + 1);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
state.topTextLine += 1;
|
|
22
|
+
}
|
|
23
|
+
for (let i = 0; i < vibratos.length; ++i) {
|
|
24
|
+
const vibrato = vibratos[i];
|
|
25
|
+
vibrato.setXShift(shift);
|
|
26
|
+
vibrato.setTextLine(textLine);
|
|
27
|
+
width += vibrato.getWidth();
|
|
28
|
+
shift += width;
|
|
29
|
+
}
|
|
30
|
+
state.rightShift += width;
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
constructor() {
|
|
34
|
+
super();
|
|
35
|
+
this.position = Modifier.Position.RIGHT;
|
|
36
|
+
this.renderOptions = {
|
|
37
|
+
code: 0xeab0,
|
|
38
|
+
width: 20,
|
|
39
|
+
};
|
|
40
|
+
this.setVibratoWidth(this.renderOptions.width);
|
|
41
|
+
}
|
|
42
|
+
setVibratoWidth(width) {
|
|
43
|
+
this.renderOptions.width = width;
|
|
44
|
+
this.text = String.fromCodePoint(this.renderOptions.code);
|
|
45
|
+
const myWidth = this.getWidth();
|
|
46
|
+
if (!myWidth) {
|
|
47
|
+
throw new RuntimeError('Cannot set vibrato width if width is 0');
|
|
48
|
+
}
|
|
49
|
+
const items = Math.round(this.renderOptions.width / myWidth);
|
|
50
|
+
for (let i = 1; i < items; i++) {
|
|
51
|
+
this.text += String.fromCodePoint(this.renderOptions.code);
|
|
52
|
+
}
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
setVibratoCode(code) {
|
|
56
|
+
this.renderOptions.code = code;
|
|
57
|
+
return this.setVibratoWidth(this.renderOptions.width);
|
|
58
|
+
}
|
|
59
|
+
draw() {
|
|
60
|
+
const ctx = this.checkContext();
|
|
61
|
+
const note = this.checkAttachedNote();
|
|
62
|
+
this.setRendered();
|
|
63
|
+
const start = note.getModifierStartXY(Modifier.Position.RIGHT, this.index);
|
|
64
|
+
const vx = start.x;
|
|
65
|
+
const vy = note.getYForTopText(this.textLine) + 5;
|
|
66
|
+
this.renderText(ctx, vx, vy);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { log } from './util.js';
|
|
3
|
+
import { Vibrato } from './vibrato.js';
|
|
4
|
+
function L(...args) {
|
|
5
|
+
if (VibratoBracket.DEBUG)
|
|
6
|
+
log('VexFlow.VibratoBracket', args);
|
|
7
|
+
}
|
|
8
|
+
export class VibratoBracket extends Element {
|
|
9
|
+
static get CATEGORY() {
|
|
10
|
+
return "VibratoBracket";
|
|
11
|
+
}
|
|
12
|
+
constructor(bracketData) {
|
|
13
|
+
super();
|
|
14
|
+
this.vibrato = new Vibrato();
|
|
15
|
+
if (bracketData.start)
|
|
16
|
+
this.start = bracketData.start;
|
|
17
|
+
if (bracketData.stop)
|
|
18
|
+
this.stop = bracketData.stop;
|
|
19
|
+
this.line = 1;
|
|
20
|
+
}
|
|
21
|
+
setLine(line) {
|
|
22
|
+
this.line = line;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
setVibratoCode(code) {
|
|
26
|
+
this.vibrato.setVibratoCode(code);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
draw() {
|
|
30
|
+
const ctx = this.checkContext();
|
|
31
|
+
this.setRendered();
|
|
32
|
+
const y = (this.start && this.start.checkStave().getYForTopText(this.line)) ||
|
|
33
|
+
(this.stop && this.stop.checkStave().getYForTopText(this.line)) ||
|
|
34
|
+
0;
|
|
35
|
+
const startX = (this.start && this.start.getAbsoluteX()) || (this.stop && this.stop.checkStave().getTieStartX()) || 0;
|
|
36
|
+
const stopX = (this.stop && this.stop.getAbsoluteX() - this.stop.getWidth() - 5) ||
|
|
37
|
+
(this.start && this.start.checkStave().getTieEndX() - 10) ||
|
|
38
|
+
0;
|
|
39
|
+
this.vibrato.setVibratoWidth(stopX - startX);
|
|
40
|
+
L('Rendering VibratoBracket: startX:', startX, 'stopX:', stopX, 'y:', y);
|
|
41
|
+
this.vibrato.renderText(ctx, startX, y);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
VibratoBracket.DEBUG = false;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Fraction } from './fraction.js';
|
|
3
|
+
import { Tables } from './tables.js';
|
|
4
|
+
import { defined, RuntimeError, sumArray } from './util.js';
|
|
5
|
+
export var VoiceMode;
|
|
6
|
+
(function (VoiceMode) {
|
|
7
|
+
VoiceMode[VoiceMode["STRICT"] = 1] = "STRICT";
|
|
8
|
+
VoiceMode[VoiceMode["SOFT"] = 2] = "SOFT";
|
|
9
|
+
VoiceMode[VoiceMode["FULL"] = 3] = "FULL";
|
|
10
|
+
})(VoiceMode || (VoiceMode = {}));
|
|
11
|
+
export class Voice extends Element {
|
|
12
|
+
static get CATEGORY() {
|
|
13
|
+
return "Voice";
|
|
14
|
+
}
|
|
15
|
+
static get Mode() {
|
|
16
|
+
return VoiceMode;
|
|
17
|
+
}
|
|
18
|
+
constructor(time) {
|
|
19
|
+
super();
|
|
20
|
+
this.resolutionMultiplier = 1;
|
|
21
|
+
this.mode = VoiceMode.STRICT;
|
|
22
|
+
this.preFormatted = false;
|
|
23
|
+
this.ticksUsed = new Fraction(0, 1);
|
|
24
|
+
this.largestTickWidth = 0;
|
|
25
|
+
this.tickables = [];
|
|
26
|
+
this.options = {
|
|
27
|
+
softmaxFactor: Tables.SOFTMAX_FACTOR,
|
|
28
|
+
};
|
|
29
|
+
let voiceTime;
|
|
30
|
+
if (typeof time === 'string') {
|
|
31
|
+
const match = time.match(/(\d+)\/(\d+)/);
|
|
32
|
+
if (match) {
|
|
33
|
+
voiceTime = {
|
|
34
|
+
numBeats: parseInt(match[1]),
|
|
35
|
+
beatValue: parseInt(match[2]),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
voiceTime = time;
|
|
41
|
+
}
|
|
42
|
+
this.time = Object.assign({ numBeats: 4, beatValue: 4, resolution: Tables.RESOLUTION }, voiceTime);
|
|
43
|
+
this.totalTicks = new Fraction(this.time.numBeats * (this.time.resolution / this.time.beatValue), 1);
|
|
44
|
+
this.smallestTickCount = this.totalTicks.clone();
|
|
45
|
+
}
|
|
46
|
+
getTotalTicks() {
|
|
47
|
+
return this.totalTicks;
|
|
48
|
+
}
|
|
49
|
+
getTicksUsed() {
|
|
50
|
+
return this.ticksUsed;
|
|
51
|
+
}
|
|
52
|
+
getLargestTickWidth() {
|
|
53
|
+
return this.largestTickWidth;
|
|
54
|
+
}
|
|
55
|
+
getSmallestTickCount() {
|
|
56
|
+
return this.smallestTickCount;
|
|
57
|
+
}
|
|
58
|
+
getTickables() {
|
|
59
|
+
return this.tickables;
|
|
60
|
+
}
|
|
61
|
+
getMode() {
|
|
62
|
+
return this.mode;
|
|
63
|
+
}
|
|
64
|
+
setMode(mode) {
|
|
65
|
+
this.mode = mode;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
getResolutionMultiplier() {
|
|
69
|
+
return this.resolutionMultiplier;
|
|
70
|
+
}
|
|
71
|
+
getActualResolution() {
|
|
72
|
+
return this.resolutionMultiplier * this.time.resolution;
|
|
73
|
+
}
|
|
74
|
+
setStave(stave) {
|
|
75
|
+
this.stave = stave;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
getStave() {
|
|
79
|
+
return this.stave;
|
|
80
|
+
}
|
|
81
|
+
getBoundingBox() {
|
|
82
|
+
const boundingBox = this.tickables[0].getBoundingBox();
|
|
83
|
+
for (let i = 1; i < this.tickables.length; ++i) {
|
|
84
|
+
const tickable = this.tickables[i];
|
|
85
|
+
if (!tickable.getStave() && this.stave)
|
|
86
|
+
tickable.setStave(this.stave);
|
|
87
|
+
const bb = tickable.getBoundingBox();
|
|
88
|
+
boundingBox.mergeWith(bb);
|
|
89
|
+
}
|
|
90
|
+
return boundingBox;
|
|
91
|
+
}
|
|
92
|
+
setStrict(strict) {
|
|
93
|
+
this.mode = strict ? VoiceMode.STRICT : VoiceMode.SOFT;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
isComplete() {
|
|
97
|
+
if (this.mode === VoiceMode.STRICT || this.mode === VoiceMode.FULL) {
|
|
98
|
+
return this.ticksUsed.equals(this.totalTicks);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
setSoftmaxFactor(factor) {
|
|
105
|
+
this.options.softmaxFactor = factor;
|
|
106
|
+
this.expTicksUsed = 0;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
reCalculateExpTicksUsed() {
|
|
110
|
+
const totalTicks = this.ticksUsed.value();
|
|
111
|
+
const exp = (tickable) => Math.pow(this.options.softmaxFactor, tickable.getTicks().value() / totalTicks);
|
|
112
|
+
this.expTicksUsed = sumArray(this.tickables.map(exp));
|
|
113
|
+
return this.expTicksUsed;
|
|
114
|
+
}
|
|
115
|
+
softmax(tickValue) {
|
|
116
|
+
if (!this.expTicksUsed) {
|
|
117
|
+
this.expTicksUsed = this.reCalculateExpTicksUsed();
|
|
118
|
+
}
|
|
119
|
+
const totalTicks = this.ticksUsed.value();
|
|
120
|
+
const exp = (v) => Math.pow(this.options.softmaxFactor, v / totalTicks);
|
|
121
|
+
const sm = exp(tickValue) / this.expTicksUsed;
|
|
122
|
+
return sm;
|
|
123
|
+
}
|
|
124
|
+
addTickable(tickable) {
|
|
125
|
+
if (!tickable.shouldIgnoreTicks()) {
|
|
126
|
+
const ticks = tickable.getTicks();
|
|
127
|
+
this.ticksUsed.add(ticks);
|
|
128
|
+
this.expTicksUsed = 0;
|
|
129
|
+
if ((this.mode === VoiceMode.STRICT || this.mode === VoiceMode.FULL) &&
|
|
130
|
+
this.ticksUsed.greaterThan(this.totalTicks)) {
|
|
131
|
+
this.ticksUsed.subtract(ticks);
|
|
132
|
+
throw new RuntimeError('BadArgument', 'Too many ticks.');
|
|
133
|
+
}
|
|
134
|
+
if (ticks.lessThan(this.smallestTickCount)) {
|
|
135
|
+
this.smallestTickCount = ticks.clone();
|
|
136
|
+
}
|
|
137
|
+
this.resolutionMultiplier = this.ticksUsed.denominator;
|
|
138
|
+
this.totalTicks.add(0, this.ticksUsed.denominator);
|
|
139
|
+
}
|
|
140
|
+
this.tickables.push(tickable);
|
|
141
|
+
tickable.setVoice(this);
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
addTickables(tickables) {
|
|
145
|
+
for (let i = 0; i < tickables.length; ++i) {
|
|
146
|
+
this.addTickable(tickables[i]);
|
|
147
|
+
}
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
preFormat() {
|
|
151
|
+
if (this.preFormatted)
|
|
152
|
+
return this;
|
|
153
|
+
const stave = this.checkStave();
|
|
154
|
+
this.tickables.forEach((tickable) => {
|
|
155
|
+
if (!tickable.getStave()) {
|
|
156
|
+
tickable.setStave(stave);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
this.preFormatted = true;
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
checkStave() {
|
|
163
|
+
return defined(this.stave, 'NoStave', 'No stave attached to instance.');
|
|
164
|
+
}
|
|
165
|
+
draw(context = this.checkContext(), stave) {
|
|
166
|
+
stave = stave !== null && stave !== void 0 ? stave : this.stave;
|
|
167
|
+
this.setRendered();
|
|
168
|
+
for (let i = 0; i < this.tickables.length; ++i) {
|
|
169
|
+
const tickable = this.tickables[i];
|
|
170
|
+
if (stave) {
|
|
171
|
+
tickable.setStave(stave);
|
|
172
|
+
}
|
|
173
|
+
defined(tickable.getStave(), 'MissingStave', 'The voice cannot draw tickables without staves.');
|
|
174
|
+
tickable.setContext(context);
|
|
175
|
+
tickable.drawWithStyle();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { globalObject } from './util.js';
|
|
2
|
+
export function isHTMLCanvas(element) {
|
|
3
|
+
if (!element)
|
|
4
|
+
return false;
|
|
5
|
+
const global = globalObject();
|
|
6
|
+
return ((typeof global.HTMLCanvasElement === 'function' && element instanceof global.HTMLCanvasElement) ||
|
|
7
|
+
(typeof element.getContext === 'function' && typeof element.toDataURL === 'function'));
|
|
8
|
+
}
|
|
9
|
+
export function isHTMLDiv(element) {
|
|
10
|
+
if (!element)
|
|
11
|
+
return false;
|
|
12
|
+
const global = globalObject();
|
|
13
|
+
return ((typeof global.HTMLDivElement === 'function' && element instanceof global.HTMLDivElement) ||
|
|
14
|
+
(typeof element.appendChild === 'function' && typeof element.style === 'object'));
|
|
15
|
+
}
|