vexflow 4.0.1-beta.1 → 4.0.1-beta.2
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/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 +92 -24
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +38 -16
- 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 +11 -0
- package/build/esm/entry/vexflow-core.js +54 -0
- package/build/esm/entry/vexflow-debug-with-tests.js +4 -0
- package/build/esm/entry/vexflow-debug.js +3 -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 +11 -0
- package/build/esm/entry/vexflow-petaluma.js +11 -0
- package/build/esm/entry/vexflow.js +9 -0
- package/build/esm/src/accidental.js +348 -0
- package/build/esm/src/annotation.js +232 -0
- package/build/esm/src/articulation.js +267 -0
- package/build/esm/src/barnote.js +58 -0
- package/build/esm/src/beam.js +632 -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 +440 -0
- package/build/esm/src/flow.js +275 -0
- package/build/esm/src/font.js +264 -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 +568 -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 +331 -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 +91 -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 +218 -0
- package/build/esm/src/stavemodifier.js +77 -0
- package/build/esm/src/stavenote.js +855 -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 +116 -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 +176 -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 +377 -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 +595 -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 +459 -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 +669 -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 +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-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 +3 -0
- package/build/types/entry/vexflow-petaluma.d.ts +3 -0
- package/build/types/entry/vexflow.d.ts +3 -0
- package/build/types/src/accidental.d.ts +66 -0
- package/build/types/src/annotation.d.ts +60 -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 +124 -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 +148 -0
- package/build/types/src/element.d.ts +202 -0
- package/build/types/src/factory.d.ts +271 -0
- package/build/types/src/flow.d.ts +245 -0
- package/build/types/src/font.d.ts +181 -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 +139 -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 +91 -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 +231 -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 +57 -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/package.json +1 -1
- package/src/annotation.ts +27 -6
- package/src/articulation.ts +8 -2
- package/src/fonts/gonville_glyphs.ts +4 -4
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
import { BoundingBox } from './boundingbox.js';
|
|
2
|
+
import { Modifier } from './modifier.js';
|
|
3
|
+
import { NoteHead } from './notehead.js';
|
|
4
|
+
import { Stem } from './stem.js';
|
|
5
|
+
import { StemmableNote } from './stemmablenote.js';
|
|
6
|
+
import { Tables } from './tables.js';
|
|
7
|
+
import { defined, log, midLine, RuntimeError, warn } from './util.js';
|
|
8
|
+
function showDeprecationWarningForNoteHeads() {
|
|
9
|
+
console.warn('StaveNote.note_heads is deprecated. Use StaveNote.noteHeads instead.', 'This accessor will be removed in VexFlow 5.0.');
|
|
10
|
+
}
|
|
11
|
+
function L(...args) {
|
|
12
|
+
if (StaveNote.DEBUG)
|
|
13
|
+
log('Vex.Flow.StaveNote', args);
|
|
14
|
+
}
|
|
15
|
+
const isInnerNoteIndex = (note, index) => index === (note.getStemDirection() === Stem.UP ? note.keyProps.length - 1 : 0);
|
|
16
|
+
function shiftRestVertical(rest, note, dir) {
|
|
17
|
+
const delta = dir;
|
|
18
|
+
rest.line += delta;
|
|
19
|
+
rest.maxLine += delta;
|
|
20
|
+
rest.minLine += delta;
|
|
21
|
+
rest.note.setKeyLine(0, rest.note.getKeyLine(0) + delta);
|
|
22
|
+
}
|
|
23
|
+
function centerRest(rest, noteU, noteL) {
|
|
24
|
+
const delta = rest.line - midLine(noteU.minLine, noteL.maxLine);
|
|
25
|
+
rest.note.setKeyLine(0, rest.note.getKeyLine(0) - delta);
|
|
26
|
+
rest.line -= delta;
|
|
27
|
+
rest.maxLine -= delta;
|
|
28
|
+
rest.minLine -= delta;
|
|
29
|
+
}
|
|
30
|
+
export class StaveNote extends StemmableNote {
|
|
31
|
+
constructor(noteStruct) {
|
|
32
|
+
var _a, _b, _c;
|
|
33
|
+
super(noteStruct);
|
|
34
|
+
this.minLine = 0;
|
|
35
|
+
this.maxLine = 0;
|
|
36
|
+
this.ledgerLineStyle = {};
|
|
37
|
+
this.clef = (_a = noteStruct.clef) !== null && _a !== void 0 ? _a : 'treble';
|
|
38
|
+
this.octave_shift = (_b = noteStruct.octave_shift) !== null && _b !== void 0 ? _b : 0;
|
|
39
|
+
this.glyph = Tables.getGlyphProps(this.duration, this.noteType);
|
|
40
|
+
defined(this.glyph, 'BadArguments', `No glyph found for duration '${this.duration}' and type '${this.noteType}'`);
|
|
41
|
+
this.displaced = false;
|
|
42
|
+
this.dot_shiftY = 0;
|
|
43
|
+
this.use_default_head_x = false;
|
|
44
|
+
this._noteHeads = [];
|
|
45
|
+
this.modifiers = [];
|
|
46
|
+
this.render_options = Object.assign(Object.assign({}, this.render_options), { glyph_font_scale: noteStruct.glyph_font_scale || Tables.NOTATION_FONT_SCALE, stroke_px: noteStruct.stroke_px || StaveNote.LEDGER_LINE_OFFSET });
|
|
47
|
+
this.calculateKeyProps();
|
|
48
|
+
this.buildStem();
|
|
49
|
+
if (noteStruct.auto_stem) {
|
|
50
|
+
this.autoStem();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.setStemDirection((_c = noteStruct.stem_direction) !== null && _c !== void 0 ? _c : Stem.UP);
|
|
54
|
+
}
|
|
55
|
+
this.reset();
|
|
56
|
+
this.buildFlag();
|
|
57
|
+
}
|
|
58
|
+
static get CATEGORY() {
|
|
59
|
+
return "StaveNote";
|
|
60
|
+
}
|
|
61
|
+
static get STEM_UP() {
|
|
62
|
+
return Stem.UP;
|
|
63
|
+
}
|
|
64
|
+
static get STEM_DOWN() {
|
|
65
|
+
return Stem.DOWN;
|
|
66
|
+
}
|
|
67
|
+
static get LEDGER_LINE_OFFSET() {
|
|
68
|
+
return 3;
|
|
69
|
+
}
|
|
70
|
+
static get minNoteheadPadding() {
|
|
71
|
+
const musicFont = Tables.currentMusicFont();
|
|
72
|
+
return musicFont.lookupMetric('glyphs.noteHead.minPadding');
|
|
73
|
+
}
|
|
74
|
+
static format(notes, state) {
|
|
75
|
+
if (!notes || notes.length < 2)
|
|
76
|
+
return false;
|
|
77
|
+
const notesList = [];
|
|
78
|
+
for (let i = 0; i < notes.length; i++) {
|
|
79
|
+
const props = notes[i].getKeyProps();
|
|
80
|
+
const line = props[0].line;
|
|
81
|
+
let minL = props[props.length - 1].line;
|
|
82
|
+
const stemDirection = notes[i].getStemDirection();
|
|
83
|
+
const stemMax = notes[i].getStemLength() / 10;
|
|
84
|
+
const stemMin = notes[i].getStemMinimumLength() / 10;
|
|
85
|
+
let maxL;
|
|
86
|
+
if (notes[i].isRest()) {
|
|
87
|
+
maxL = line + notes[i].glyph.line_above;
|
|
88
|
+
minL = line - notes[i].glyph.line_below;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
maxL = stemDirection === 1 ? props[props.length - 1].line + stemMax : props[props.length - 1].line;
|
|
92
|
+
minL = stemDirection === 1 ? props[0].line : props[0].line - stemMax;
|
|
93
|
+
}
|
|
94
|
+
notesList.push({
|
|
95
|
+
line: props[0].line,
|
|
96
|
+
maxLine: maxL,
|
|
97
|
+
minLine: minL,
|
|
98
|
+
isrest: notes[i].isRest(),
|
|
99
|
+
stemDirection: stemDirection,
|
|
100
|
+
stemMax,
|
|
101
|
+
stemMin,
|
|
102
|
+
voice_shift: notes[i].getVoiceShiftWidth(),
|
|
103
|
+
is_displaced: notes[i].isDisplaced(),
|
|
104
|
+
note: notes[i],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const voices = notesList.length;
|
|
108
|
+
let noteU = notesList[0];
|
|
109
|
+
const noteM = voices > 2 ? notesList[1] : undefined;
|
|
110
|
+
let noteL = voices > 2 ? notesList[2] : notesList[1];
|
|
111
|
+
if (voices === 2 && noteU.stemDirection === -1 && noteL.stemDirection === 1) {
|
|
112
|
+
noteU = notesList[1];
|
|
113
|
+
noteL = notesList[0];
|
|
114
|
+
}
|
|
115
|
+
const voiceXShift = Math.max(noteU.voice_shift, noteL.voice_shift);
|
|
116
|
+
let xShift = 0;
|
|
117
|
+
if (voices === 2) {
|
|
118
|
+
const lineSpacing = noteU.note.hasStem() && noteL.note.hasStem() && noteU.stemDirection === noteL.stemDirection ? 0.0 : 0.5;
|
|
119
|
+
if (noteU.minLine <= noteL.maxLine + lineSpacing) {
|
|
120
|
+
if (noteU.isrest) {
|
|
121
|
+
shiftRestVertical(noteU, noteL, 1);
|
|
122
|
+
}
|
|
123
|
+
else if (noteL.isrest) {
|
|
124
|
+
shiftRestVertical(noteL, noteU, -1);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const lineDiff = Math.abs(noteU.line - noteL.line);
|
|
128
|
+
if (noteU.note.hasStem() && noteL.note.hasStem()) {
|
|
129
|
+
let whiteNoteHeadCount = 0;
|
|
130
|
+
let blackNoteHeadCount = 0;
|
|
131
|
+
if (Tables.durationToNumber(noteU.note.duration) === 2) {
|
|
132
|
+
whiteNoteHeadCount++;
|
|
133
|
+
}
|
|
134
|
+
else if (Tables.durationToNumber(noteU.note.duration) > 2) {
|
|
135
|
+
blackNoteHeadCount++;
|
|
136
|
+
}
|
|
137
|
+
if (Tables.durationToNumber(noteL.note.duration) === 2) {
|
|
138
|
+
whiteNoteHeadCount++;
|
|
139
|
+
}
|
|
140
|
+
else if (Tables.durationToNumber(noteL.note.duration) > 2) {
|
|
141
|
+
blackNoteHeadCount++;
|
|
142
|
+
}
|
|
143
|
+
if ((whiteNoteHeadCount !== 2 && blackNoteHeadCount !== 2) ||
|
|
144
|
+
noteU.note.getModifiersByType("Dot").length !== noteL.note.getModifiersByType("Dot").length) {
|
|
145
|
+
xShift = voiceXShift + 2;
|
|
146
|
+
if (noteU.stemDirection === noteL.stemDirection) {
|
|
147
|
+
noteU.note.setXShift(xShift);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
noteL.note.setXShift(xShift);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (lineDiff < 1 && lineDiff > 0) {
|
|
154
|
+
xShift = voiceXShift + 2;
|
|
155
|
+
if (noteU.stemDirection === noteL.stemDirection) {
|
|
156
|
+
noteU.note.setXShift(xShift);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
noteL.note.setXShift(xShift);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (noteU.note.voice !== noteL.note.voice) {
|
|
163
|
+
if (noteU.stemDirection === noteL.stemDirection) {
|
|
164
|
+
if (noteU.line != noteL.line) {
|
|
165
|
+
xShift = voiceXShift + 2;
|
|
166
|
+
noteU.note.setXShift(xShift);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
if (noteL.stemDirection === 1) {
|
|
170
|
+
noteL.stemDirection = -1;
|
|
171
|
+
noteL.note.setStemDirection(-1);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
xShift = voiceXShift + 2;
|
|
179
|
+
if (noteU.stemDirection === noteL.stemDirection) {
|
|
180
|
+
noteU.note.setXShift(xShift);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
noteL.note.setXShift(xShift);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
state.right_shift += xShift;
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
if (!noteM)
|
|
192
|
+
throw new RuntimeError('InvalidState', 'noteM not defined.');
|
|
193
|
+
if (noteM.isrest && !noteU.isrest && !noteL.isrest) {
|
|
194
|
+
if (noteU.minLine <= noteM.maxLine || noteM.minLine <= noteL.maxLine) {
|
|
195
|
+
const restHeight = noteM.maxLine - noteM.minLine;
|
|
196
|
+
const space = noteU.minLine - noteL.maxLine;
|
|
197
|
+
if (restHeight < space) {
|
|
198
|
+
centerRest(noteM, noteU, noteL);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
xShift = voiceXShift + 2;
|
|
202
|
+
noteM.note.setXShift(xShift);
|
|
203
|
+
if (noteL.note.hasBeam() === false) {
|
|
204
|
+
noteL.stemDirection = -1;
|
|
205
|
+
noteL.note.setStemDirection(-1);
|
|
206
|
+
}
|
|
207
|
+
if (noteU.minLine <= noteL.maxLine && noteU.note.hasBeam() === false) {
|
|
208
|
+
noteU.stemDirection = 1;
|
|
209
|
+
noteU.note.setStemDirection(1);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
state.right_shift += xShift;
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (noteU.isrest && noteM.isrest && noteL.isrest) {
|
|
217
|
+
shiftRestVertical(noteU, noteM, 1);
|
|
218
|
+
shiftRestVertical(noteL, noteM, -1);
|
|
219
|
+
state.right_shift += xShift;
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
if (noteM.isrest && noteU.isrest && noteM.minLine <= noteL.maxLine) {
|
|
223
|
+
shiftRestVertical(noteM, noteL, 1);
|
|
224
|
+
}
|
|
225
|
+
if (noteM.isrest && noteL.isrest && noteU.minLine <= noteM.maxLine) {
|
|
226
|
+
shiftRestVertical(noteM, noteU, -1);
|
|
227
|
+
}
|
|
228
|
+
if (noteU.isrest && noteU.minLine <= noteM.maxLine) {
|
|
229
|
+
shiftRestVertical(noteU, noteM, 1);
|
|
230
|
+
}
|
|
231
|
+
if (noteL.isrest && noteM.minLine <= noteL.maxLine) {
|
|
232
|
+
shiftRestVertical(noteL, noteM, -1);
|
|
233
|
+
}
|
|
234
|
+
if (noteU.minLine <= noteM.maxLine + 0.5 || noteM.minLine <= noteL.maxLine) {
|
|
235
|
+
xShift = voiceXShift + 2;
|
|
236
|
+
noteM.note.setXShift(xShift);
|
|
237
|
+
if (noteL.note.hasBeam() === false) {
|
|
238
|
+
noteL.stemDirection = -1;
|
|
239
|
+
noteL.note.setStemDirection(-1);
|
|
240
|
+
}
|
|
241
|
+
if (noteU.minLine <= noteL.maxLine && noteU.note.hasBeam() === false) {
|
|
242
|
+
noteU.stemDirection = 1;
|
|
243
|
+
noteU.note.setStemDirection(1);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
state.right_shift += xShift;
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
static postFormat(notes) {
|
|
250
|
+
if (!notes)
|
|
251
|
+
return false;
|
|
252
|
+
notes.forEach((note) => note.postFormat());
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
reset() {
|
|
256
|
+
super.reset();
|
|
257
|
+
const noteHeadStyles = this._noteHeads.map((noteHead) => noteHead.getStyle());
|
|
258
|
+
this.buildNoteHeads();
|
|
259
|
+
this._noteHeads.forEach((noteHead, index) => {
|
|
260
|
+
const noteHeadStyle = noteHeadStyles[index];
|
|
261
|
+
if (noteHeadStyle)
|
|
262
|
+
noteHead.setStyle(noteHeadStyle);
|
|
263
|
+
});
|
|
264
|
+
const stave = this.stave;
|
|
265
|
+
if (stave) {
|
|
266
|
+
this._noteHeads.forEach((head) => head.setStave(stave));
|
|
267
|
+
}
|
|
268
|
+
this.calcNoteDisplacements();
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
setBeam(beam) {
|
|
272
|
+
this.beam = beam;
|
|
273
|
+
this.calcNoteDisplacements();
|
|
274
|
+
if (this.stem) {
|
|
275
|
+
this.stem.setExtension(this.getStemExtension());
|
|
276
|
+
}
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
buildStem() {
|
|
280
|
+
this.setStem(new Stem({ hide: !!this.isRest() }));
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
buildNoteHeads() {
|
|
284
|
+
this._noteHeads = [];
|
|
285
|
+
const stemDirection = this.getStemDirection();
|
|
286
|
+
const keys = this.getKeys();
|
|
287
|
+
let lastLine = undefined;
|
|
288
|
+
let lineDiff = undefined;
|
|
289
|
+
let displaced = false;
|
|
290
|
+
let start;
|
|
291
|
+
let end;
|
|
292
|
+
let step;
|
|
293
|
+
if (stemDirection === Stem.UP) {
|
|
294
|
+
start = 0;
|
|
295
|
+
end = keys.length;
|
|
296
|
+
step = 1;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
start = keys.length - 1;
|
|
300
|
+
end = -1;
|
|
301
|
+
step = -1;
|
|
302
|
+
}
|
|
303
|
+
for (let i = start; i !== end; i += step) {
|
|
304
|
+
const noteProps = this.keyProps[i];
|
|
305
|
+
const line = noteProps.line;
|
|
306
|
+
if (lastLine === undefined) {
|
|
307
|
+
lastLine = line;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
lineDiff = Math.abs(lastLine - line);
|
|
311
|
+
if (lineDiff === 0 || lineDiff === 0.5) {
|
|
312
|
+
displaced = !displaced;
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
displaced = false;
|
|
316
|
+
this.use_default_head_x = true;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
lastLine = line;
|
|
320
|
+
const notehead = new NoteHead({
|
|
321
|
+
duration: this.duration,
|
|
322
|
+
note_type: this.noteType,
|
|
323
|
+
displaced,
|
|
324
|
+
stem_direction: stemDirection,
|
|
325
|
+
custom_glyph_code: noteProps.code,
|
|
326
|
+
glyph_font_scale: this.render_options.glyph_font_scale,
|
|
327
|
+
x_shift: noteProps.shift_right,
|
|
328
|
+
stem_up_x_offset: noteProps.stem_up_x_offset,
|
|
329
|
+
stem_down_x_offset: noteProps.stem_down_x_offset,
|
|
330
|
+
line: noteProps.line,
|
|
331
|
+
});
|
|
332
|
+
this._noteHeads[i] = notehead;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
autoStem() {
|
|
336
|
+
this.setStemDirection(this.calculateOptimalStemDirection());
|
|
337
|
+
}
|
|
338
|
+
calculateOptimalStemDirection() {
|
|
339
|
+
this.minLine = this.keyProps[0].line;
|
|
340
|
+
this.maxLine = this.keyProps[this.keyProps.length - 1].line;
|
|
341
|
+
const MIDDLE_LINE = 3;
|
|
342
|
+
const decider = (this.minLine + this.maxLine) / 2;
|
|
343
|
+
const stemDirection = decider < MIDDLE_LINE ? Stem.UP : Stem.DOWN;
|
|
344
|
+
return stemDirection;
|
|
345
|
+
}
|
|
346
|
+
calculateKeyProps() {
|
|
347
|
+
let lastLine;
|
|
348
|
+
for (let i = 0; i < this.keys.length; ++i) {
|
|
349
|
+
const key = this.keys[i];
|
|
350
|
+
if (this.glyph.rest)
|
|
351
|
+
this.glyph.position = key;
|
|
352
|
+
const options = { octave_shift: this.octave_shift || 0 };
|
|
353
|
+
const props = Tables.keyProperties(key, this.clef, options);
|
|
354
|
+
if (!props) {
|
|
355
|
+
throw new RuntimeError('BadArguments', `Invalid key for note properties: ${key}`);
|
|
356
|
+
}
|
|
357
|
+
if (props.key === 'R') {
|
|
358
|
+
if (this.duration === '1' || this.duration === 'w') {
|
|
359
|
+
props.line = 4;
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
props.line = 3;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const line = props.line;
|
|
366
|
+
if (lastLine == undefined) {
|
|
367
|
+
lastLine = line;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
if (Math.abs(lastLine - line) === 0.5) {
|
|
371
|
+
this.displaced = true;
|
|
372
|
+
props.displaced = true;
|
|
373
|
+
if (this.keyProps.length > 0) {
|
|
374
|
+
this.keyProps[i - 1].displaced = true;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
lastLine = line;
|
|
379
|
+
this.keyProps.push(props);
|
|
380
|
+
}
|
|
381
|
+
lastLine = undefined;
|
|
382
|
+
this.keyProps.forEach((key) => {
|
|
383
|
+
if (lastLine && key.line < lastLine) {
|
|
384
|
+
warn('Unsorted keys in note will be sorted. ' + 'See https://github.com/0xfe/vexflow/issues/104 for details.');
|
|
385
|
+
}
|
|
386
|
+
lastLine = key.line;
|
|
387
|
+
});
|
|
388
|
+
this.keyProps.sort((a, b) => a.line - b.line);
|
|
389
|
+
}
|
|
390
|
+
getBoundingBox() {
|
|
391
|
+
var _a, _b;
|
|
392
|
+
if (!this.preFormatted) {
|
|
393
|
+
throw new RuntimeError('UnformattedNote', "Can't call getBoundingBox on an unformatted note.");
|
|
394
|
+
}
|
|
395
|
+
const { width: w, modLeftPx, leftDisplacedHeadPx } = this.getMetrics();
|
|
396
|
+
const x = this.getAbsoluteX() - modLeftPx - leftDisplacedHeadPx;
|
|
397
|
+
let minY = 0;
|
|
398
|
+
let maxY = 0;
|
|
399
|
+
const halfLineSpacing = ((_b = (_a = this.getStave()) === null || _a === void 0 ? void 0 : _a.getSpacingBetweenLines()) !== null && _b !== void 0 ? _b : 0) / 2;
|
|
400
|
+
const lineSpacing = halfLineSpacing * 2;
|
|
401
|
+
if (this.isRest()) {
|
|
402
|
+
const y = this.ys[0];
|
|
403
|
+
const frac = Tables.durationToFraction(this.duration);
|
|
404
|
+
if (frac.equals(1) || frac.equals(2)) {
|
|
405
|
+
minY = y - halfLineSpacing;
|
|
406
|
+
maxY = y + halfLineSpacing;
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
minY = y - this.glyph.line_above * lineSpacing;
|
|
410
|
+
maxY = y + this.glyph.line_below * lineSpacing;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
else if (this.glyph.stem) {
|
|
414
|
+
const ys = this.getStemExtents();
|
|
415
|
+
ys.baseY += halfLineSpacing * this.getStemDirection();
|
|
416
|
+
minY = Math.min(ys.topY, ys.baseY);
|
|
417
|
+
maxY = Math.max(ys.topY, ys.baseY);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
minY = 0;
|
|
421
|
+
maxY = 0;
|
|
422
|
+
for (let i = 0; i < this.ys.length; ++i) {
|
|
423
|
+
const yy = this.ys[i];
|
|
424
|
+
if (i === 0) {
|
|
425
|
+
minY = yy;
|
|
426
|
+
maxY = yy;
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
minY = Math.min(yy, minY);
|
|
430
|
+
maxY = Math.max(yy, maxY);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
minY -= halfLineSpacing;
|
|
434
|
+
maxY += halfLineSpacing;
|
|
435
|
+
}
|
|
436
|
+
return new BoundingBox(x, minY, w, maxY - minY);
|
|
437
|
+
}
|
|
438
|
+
getLineNumber(isTopNote) {
|
|
439
|
+
if (!this.keyProps.length) {
|
|
440
|
+
throw new RuntimeError('NoKeyProps', "Can't get bottom note line, because note is not initialized properly.");
|
|
441
|
+
}
|
|
442
|
+
let resultLine = this.keyProps[0].line;
|
|
443
|
+
for (let i = 0; i < this.keyProps.length; i++) {
|
|
444
|
+
const thisLine = this.keyProps[i].line;
|
|
445
|
+
if (isTopNote) {
|
|
446
|
+
if (thisLine > resultLine)
|
|
447
|
+
resultLine = thisLine;
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
if (thisLine < resultLine)
|
|
451
|
+
resultLine = thisLine;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return resultLine;
|
|
455
|
+
}
|
|
456
|
+
isRest() {
|
|
457
|
+
return this.glyph.rest;
|
|
458
|
+
}
|
|
459
|
+
isChord() {
|
|
460
|
+
return !this.isRest() && this.keys.length > 1;
|
|
461
|
+
}
|
|
462
|
+
hasStem() {
|
|
463
|
+
return this.glyph.stem;
|
|
464
|
+
}
|
|
465
|
+
hasFlag() {
|
|
466
|
+
return super.hasFlag() && !this.isRest();
|
|
467
|
+
}
|
|
468
|
+
getStemX() {
|
|
469
|
+
if (this.noteType === 'r') {
|
|
470
|
+
return this.getCenterGlyphX();
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
return super.getStemX() + (this.stem_direction ? Stem.WIDTH / (2 * -this.stem_direction) : 0);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
getYForTopText(textLine) {
|
|
477
|
+
const extents = this.getStemExtents();
|
|
478
|
+
return Math.min(this.checkStave().getYForTopText(textLine), extents.topY - this.render_options.annotation_spacing * (textLine + 1));
|
|
479
|
+
}
|
|
480
|
+
getYForBottomText(textLine) {
|
|
481
|
+
const extents = this.getStemExtents();
|
|
482
|
+
return Math.max(this.checkStave().getYForTopText(textLine), extents.baseY + this.render_options.annotation_spacing * textLine);
|
|
483
|
+
}
|
|
484
|
+
setStave(stave) {
|
|
485
|
+
super.setStave(stave);
|
|
486
|
+
const ys = this._noteHeads.map((notehead) => {
|
|
487
|
+
notehead.setStave(stave);
|
|
488
|
+
return notehead.getY();
|
|
489
|
+
});
|
|
490
|
+
this.setYs(ys);
|
|
491
|
+
if (this.stem) {
|
|
492
|
+
const { y_top, y_bottom } = this.getNoteHeadBounds();
|
|
493
|
+
this.stem.setYBounds(y_top, y_bottom);
|
|
494
|
+
}
|
|
495
|
+
return this;
|
|
496
|
+
}
|
|
497
|
+
isDisplaced() {
|
|
498
|
+
return this.displaced;
|
|
499
|
+
}
|
|
500
|
+
setNoteDisplaced(displaced) {
|
|
501
|
+
this.displaced = displaced;
|
|
502
|
+
return this;
|
|
503
|
+
}
|
|
504
|
+
getTieRightX() {
|
|
505
|
+
let tieStartX = this.getAbsoluteX();
|
|
506
|
+
tieStartX += this.getGlyphWidth() + this.x_shift + this.rightDisplacedHeadPx;
|
|
507
|
+
if (this.modifierContext)
|
|
508
|
+
tieStartX += this.modifierContext.getRightShift();
|
|
509
|
+
return tieStartX;
|
|
510
|
+
}
|
|
511
|
+
getTieLeftX() {
|
|
512
|
+
let tieEndX = this.getAbsoluteX();
|
|
513
|
+
tieEndX += this.x_shift - this.leftDisplacedHeadPx;
|
|
514
|
+
return tieEndX;
|
|
515
|
+
}
|
|
516
|
+
getLineForRest() {
|
|
517
|
+
let restLine = this.keyProps[0].line;
|
|
518
|
+
if (this.keyProps.length > 1) {
|
|
519
|
+
const lastLine = this.keyProps[this.keyProps.length - 1].line;
|
|
520
|
+
const top = Math.max(restLine, lastLine);
|
|
521
|
+
const bot = Math.min(restLine, lastLine);
|
|
522
|
+
restLine = midLine(top, bot);
|
|
523
|
+
}
|
|
524
|
+
return restLine;
|
|
525
|
+
}
|
|
526
|
+
getModifierStartXY(position, index, options = {}) {
|
|
527
|
+
var _a, _b;
|
|
528
|
+
if (!this.preFormatted) {
|
|
529
|
+
throw new RuntimeError('UnformattedNote', "Can't call GetModifierStartXY on an unformatted note");
|
|
530
|
+
}
|
|
531
|
+
if (this.ys.length === 0) {
|
|
532
|
+
throw new RuntimeError('NoYValues', 'No Y-Values calculated for this note.');
|
|
533
|
+
}
|
|
534
|
+
const { ABOVE, BELOW, LEFT, RIGHT } = Modifier.Position;
|
|
535
|
+
let x = 0;
|
|
536
|
+
if (position === LEFT) {
|
|
537
|
+
x = -1 * 2;
|
|
538
|
+
}
|
|
539
|
+
else if (position === RIGHT) {
|
|
540
|
+
x = this.getGlyphWidth() + this.x_shift + 2;
|
|
541
|
+
if (this.stem_direction === Stem.UP &&
|
|
542
|
+
this.hasFlag() &&
|
|
543
|
+
(options.forceFlagRight || isInnerNoteIndex(this, index))) {
|
|
544
|
+
x += (_b = (_a = this === null || this === void 0 ? void 0 : this.flag) === null || _a === void 0 ? void 0 : _a.getMetrics().width) !== null && _b !== void 0 ? _b : 0;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
else if (position === BELOW || position === ABOVE) {
|
|
548
|
+
x = this.getGlyphWidth() / 2;
|
|
549
|
+
}
|
|
550
|
+
return {
|
|
551
|
+
x: this.getAbsoluteX() + x,
|
|
552
|
+
y: this.ys[index],
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
setStyle(style) {
|
|
556
|
+
super.setStyle(style);
|
|
557
|
+
this._noteHeads.forEach((notehead) => notehead.setStyle(style));
|
|
558
|
+
if (this.stem)
|
|
559
|
+
this.stem.setStyle(style);
|
|
560
|
+
return this;
|
|
561
|
+
}
|
|
562
|
+
setStemStyle(style) {
|
|
563
|
+
const stem = this.getStem();
|
|
564
|
+
if (stem)
|
|
565
|
+
stem.setStyle(style);
|
|
566
|
+
return this;
|
|
567
|
+
}
|
|
568
|
+
getStemStyle() {
|
|
569
|
+
var _a;
|
|
570
|
+
return (_a = this.stem) === null || _a === void 0 ? void 0 : _a.getStyle();
|
|
571
|
+
}
|
|
572
|
+
setLedgerLineStyle(style) {
|
|
573
|
+
this.ledgerLineStyle = style;
|
|
574
|
+
}
|
|
575
|
+
getLedgerLineStyle() {
|
|
576
|
+
return this.ledgerLineStyle;
|
|
577
|
+
}
|
|
578
|
+
setFlagStyle(style) {
|
|
579
|
+
this.flagStyle = style;
|
|
580
|
+
}
|
|
581
|
+
getFlagStyle() {
|
|
582
|
+
return this.flagStyle;
|
|
583
|
+
}
|
|
584
|
+
setKeyStyle(index, style) {
|
|
585
|
+
this._noteHeads[index].setStyle(style);
|
|
586
|
+
return this;
|
|
587
|
+
}
|
|
588
|
+
setKeyLine(index, line) {
|
|
589
|
+
this.keyProps[index].line = line;
|
|
590
|
+
this.reset();
|
|
591
|
+
return this;
|
|
592
|
+
}
|
|
593
|
+
getKeyLine(index) {
|
|
594
|
+
return this.keyProps[index].line;
|
|
595
|
+
}
|
|
596
|
+
getVoiceShiftWidth() {
|
|
597
|
+
return this.getGlyphWidth() * (this.displaced ? 2 : 1);
|
|
598
|
+
}
|
|
599
|
+
calcNoteDisplacements() {
|
|
600
|
+
this.setLeftDisplacedHeadPx(this.displaced && this.stem_direction === Stem.DOWN ? this.getGlyphWidth() : 0);
|
|
601
|
+
this.setRightDisplacedHeadPx(!this.hasFlag() && this.displaced && this.stem_direction === Stem.UP ? this.getGlyphWidth() : 0);
|
|
602
|
+
}
|
|
603
|
+
preFormat() {
|
|
604
|
+
if (this.preFormatted)
|
|
605
|
+
return;
|
|
606
|
+
let noteHeadPadding = 0;
|
|
607
|
+
if (this.modifierContext) {
|
|
608
|
+
this.modifierContext.preFormat();
|
|
609
|
+
if (this.modifierContext.getWidth() === 0) {
|
|
610
|
+
noteHeadPadding = StaveNote.minNoteheadPadding;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
let width = this.getGlyphWidth() + this.leftDisplacedHeadPx + this.rightDisplacedHeadPx + noteHeadPadding;
|
|
614
|
+
if (this.shouldDrawFlag() && this.stem_direction === Stem.UP) {
|
|
615
|
+
width += this.getGlyphWidth();
|
|
616
|
+
}
|
|
617
|
+
this.setWidth(width);
|
|
618
|
+
this.preFormatted = true;
|
|
619
|
+
}
|
|
620
|
+
getNoteHeadBounds() {
|
|
621
|
+
let yTop = +Infinity;
|
|
622
|
+
let yBottom = -Infinity;
|
|
623
|
+
let nonDisplacedX;
|
|
624
|
+
let displacedX;
|
|
625
|
+
let highestLine = this.checkStave().getNumLines();
|
|
626
|
+
let lowestLine = 1;
|
|
627
|
+
let highestDisplacedLine;
|
|
628
|
+
let lowestDisplacedLine;
|
|
629
|
+
let highestNonDisplacedLine = highestLine;
|
|
630
|
+
let lowestNonDisplacedLine = lowestLine;
|
|
631
|
+
this._noteHeads.forEach((notehead) => {
|
|
632
|
+
const line = notehead.getLine();
|
|
633
|
+
const y = notehead.getY();
|
|
634
|
+
yTop = Math.min(y, yTop);
|
|
635
|
+
yBottom = Math.max(y, yBottom);
|
|
636
|
+
if (displacedX === undefined && notehead.isDisplaced()) {
|
|
637
|
+
displacedX = notehead.getAbsoluteX();
|
|
638
|
+
}
|
|
639
|
+
if (nonDisplacedX === undefined && !notehead.isDisplaced()) {
|
|
640
|
+
nonDisplacedX = notehead.getAbsoluteX();
|
|
641
|
+
}
|
|
642
|
+
highestLine = Math.max(line, highestLine);
|
|
643
|
+
lowestLine = Math.min(line, lowestLine);
|
|
644
|
+
if (notehead.isDisplaced()) {
|
|
645
|
+
highestDisplacedLine = highestDisplacedLine === undefined ? line : Math.max(line, highestDisplacedLine);
|
|
646
|
+
lowestDisplacedLine = lowestDisplacedLine === undefined ? line : Math.min(line, lowestDisplacedLine);
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
highestNonDisplacedLine = Math.max(line, highestNonDisplacedLine);
|
|
650
|
+
lowestNonDisplacedLine = Math.min(line, lowestNonDisplacedLine);
|
|
651
|
+
}
|
|
652
|
+
}, this);
|
|
653
|
+
return {
|
|
654
|
+
y_top: yTop,
|
|
655
|
+
y_bottom: yBottom,
|
|
656
|
+
displaced_x: displacedX,
|
|
657
|
+
non_displaced_x: nonDisplacedX,
|
|
658
|
+
highest_line: highestLine,
|
|
659
|
+
lowest_line: lowestLine,
|
|
660
|
+
highest_displaced_line: highestDisplacedLine,
|
|
661
|
+
lowest_displaced_line: lowestDisplacedLine,
|
|
662
|
+
highest_non_displaced_line: highestNonDisplacedLine,
|
|
663
|
+
lowest_non_displaced_line: lowestNonDisplacedLine,
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
getNoteHeadBeginX() {
|
|
667
|
+
return this.getAbsoluteX() + this.x_shift;
|
|
668
|
+
}
|
|
669
|
+
getNoteHeadEndX() {
|
|
670
|
+
const xBegin = this.getNoteHeadBeginX();
|
|
671
|
+
return xBegin + this.getGlyphWidth();
|
|
672
|
+
}
|
|
673
|
+
get noteHeads() {
|
|
674
|
+
return this._noteHeads.slice();
|
|
675
|
+
}
|
|
676
|
+
get note_heads() {
|
|
677
|
+
showDeprecationWarningForNoteHeads();
|
|
678
|
+
return this.noteHeads;
|
|
679
|
+
}
|
|
680
|
+
drawLedgerLines() {
|
|
681
|
+
const stave = this.checkStave();
|
|
682
|
+
const { glyph, render_options: { stroke_px }, } = this;
|
|
683
|
+
const ctx = this.checkContext();
|
|
684
|
+
const width = glyph.getWidth() + stroke_px * 2;
|
|
685
|
+
const doubleWidth = 2 * (glyph.getWidth() + stroke_px) - Stem.WIDTH / 2;
|
|
686
|
+
if (this.isRest())
|
|
687
|
+
return;
|
|
688
|
+
if (!ctx) {
|
|
689
|
+
throw new RuntimeError('NoCanvasContext', "Can't draw without a canvas context.");
|
|
690
|
+
}
|
|
691
|
+
const { highest_line, lowest_line, highest_displaced_line, highest_non_displaced_line, lowest_displaced_line, lowest_non_displaced_line, displaced_x, non_displaced_x, } = this.getNoteHeadBounds();
|
|
692
|
+
if (highest_line < 6 && lowest_line > 0)
|
|
693
|
+
return;
|
|
694
|
+
const min_x = Math.min(displaced_x !== null && displaced_x !== void 0 ? displaced_x : 0, non_displaced_x !== null && non_displaced_x !== void 0 ? non_displaced_x : 0);
|
|
695
|
+
const drawLedgerLine = (y, normal, displaced) => {
|
|
696
|
+
let x;
|
|
697
|
+
if (displaced && normal)
|
|
698
|
+
x = min_x - stroke_px;
|
|
699
|
+
else if (normal)
|
|
700
|
+
x = (non_displaced_x !== null && non_displaced_x !== void 0 ? non_displaced_x : 0) - stroke_px;
|
|
701
|
+
else
|
|
702
|
+
x = (displaced_x !== null && displaced_x !== void 0 ? displaced_x : 0) - stroke_px;
|
|
703
|
+
const ledgerWidth = normal && displaced ? doubleWidth : width;
|
|
704
|
+
ctx.beginPath();
|
|
705
|
+
ctx.moveTo(x, y);
|
|
706
|
+
ctx.lineTo(x + ledgerWidth, y);
|
|
707
|
+
ctx.stroke();
|
|
708
|
+
};
|
|
709
|
+
const style = Object.assign(Object.assign({}, stave.getDefaultLedgerLineStyle()), this.getLedgerLineStyle());
|
|
710
|
+
this.applyStyle(ctx, style);
|
|
711
|
+
for (let line = 6; line <= highest_line; ++line) {
|
|
712
|
+
const normal = non_displaced_x !== undefined && line <= highest_non_displaced_line;
|
|
713
|
+
const displaced = highest_displaced_line !== undefined && line <= highest_displaced_line;
|
|
714
|
+
drawLedgerLine(stave.getYForNote(line), normal, displaced);
|
|
715
|
+
}
|
|
716
|
+
for (let line = 0; line >= lowest_line; --line) {
|
|
717
|
+
const normal = non_displaced_x !== undefined && line >= lowest_non_displaced_line;
|
|
718
|
+
const displaced = lowest_displaced_line !== undefined && line >= lowest_displaced_line;
|
|
719
|
+
drawLedgerLine(stave.getYForNote(line), normal, displaced);
|
|
720
|
+
}
|
|
721
|
+
this.restoreStyle(ctx, style);
|
|
722
|
+
}
|
|
723
|
+
drawModifiers() {
|
|
724
|
+
const ctx = this.checkContext();
|
|
725
|
+
ctx.openGroup('modifiers');
|
|
726
|
+
for (let i = 0; i < this.modifiers.length; i++) {
|
|
727
|
+
const modifier = this.modifiers[i];
|
|
728
|
+
const index = modifier.checkIndex();
|
|
729
|
+
const notehead = this._noteHeads[index];
|
|
730
|
+
const noteheadStyle = notehead.getStyle();
|
|
731
|
+
notehead.applyStyle(ctx, noteheadStyle);
|
|
732
|
+
modifier.setContext(ctx);
|
|
733
|
+
modifier.drawWithStyle();
|
|
734
|
+
notehead.restoreStyle(ctx, noteheadStyle);
|
|
735
|
+
}
|
|
736
|
+
ctx.closeGroup();
|
|
737
|
+
}
|
|
738
|
+
shouldDrawFlag() {
|
|
739
|
+
const hasStem = this.stem !== undefined;
|
|
740
|
+
const hasFlag = this.glyph.flag;
|
|
741
|
+
const hasNoBeam = this.beam === undefined;
|
|
742
|
+
return hasStem && hasFlag && hasNoBeam;
|
|
743
|
+
}
|
|
744
|
+
drawFlag() {
|
|
745
|
+
var _a, _b, _c, _d, _e;
|
|
746
|
+
const ctx = this.checkContext();
|
|
747
|
+
if (!ctx) {
|
|
748
|
+
throw new RuntimeError('NoCanvasContext', "Can't draw without a canvas context.");
|
|
749
|
+
}
|
|
750
|
+
if (this.shouldDrawFlag()) {
|
|
751
|
+
const { y_top, y_bottom } = this.getNoteHeadBounds();
|
|
752
|
+
const noteStemHeight = this.stem.getHeight();
|
|
753
|
+
const flagX = this.getStemX();
|
|
754
|
+
const flagY = this.getStemDirection() === Stem.DOWN
|
|
755
|
+
?
|
|
756
|
+
y_top -
|
|
757
|
+
noteStemHeight +
|
|
758
|
+
2 -
|
|
759
|
+
(this.glyph ? this.glyph.stem_down_extension : 0) * this.getStaveNoteScale() -
|
|
760
|
+
((_b = (_a = this.flag) === null || _a === void 0 ? void 0 : _a.getMetrics().y_shift) !== null && _b !== void 0 ? _b : 0) * (1 - this.getStaveNoteScale())
|
|
761
|
+
:
|
|
762
|
+
y_bottom -
|
|
763
|
+
noteStemHeight -
|
|
764
|
+
2 +
|
|
765
|
+
(this.glyph ? this.glyph.stem_up_extension : 0) * this.getStaveNoteScale() -
|
|
766
|
+
((_d = (_c = this.flag) === null || _c === void 0 ? void 0 : _c.getMetrics().y_shift) !== null && _d !== void 0 ? _d : 0) * (1 - this.getStaveNoteScale());
|
|
767
|
+
ctx.openGroup('flag', undefined, { pointerBBox: true });
|
|
768
|
+
this.applyStyle(ctx, this.getFlagStyle());
|
|
769
|
+
(_e = this.flag) === null || _e === void 0 ? void 0 : _e.render(ctx, flagX, flagY);
|
|
770
|
+
this.restoreStyle(ctx, this.getFlagStyle());
|
|
771
|
+
ctx.closeGroup();
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
drawNoteHeads() {
|
|
775
|
+
const ctx = this.checkContext();
|
|
776
|
+
this._noteHeads.forEach((notehead) => {
|
|
777
|
+
ctx.openGroup('notehead', undefined, { pointerBBox: true });
|
|
778
|
+
notehead.setContext(ctx).draw();
|
|
779
|
+
ctx.closeGroup();
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
drawStem(stemOptions) {
|
|
783
|
+
const ctx = this.checkContext();
|
|
784
|
+
if (stemOptions) {
|
|
785
|
+
this.setStem(new Stem(stemOptions));
|
|
786
|
+
}
|
|
787
|
+
if (this.shouldDrawFlag() && this.stem) {
|
|
788
|
+
this.stem.adjustHeightForFlag();
|
|
789
|
+
}
|
|
790
|
+
if (this.stem) {
|
|
791
|
+
ctx.openGroup('stem', undefined, { pointerBBox: true });
|
|
792
|
+
this.stem.setContext(ctx).draw();
|
|
793
|
+
ctx.closeGroup();
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
getStaveNoteScale() {
|
|
797
|
+
return 1.0;
|
|
798
|
+
}
|
|
799
|
+
getStemExtension() {
|
|
800
|
+
const super_stem_extension = super.getStemExtension();
|
|
801
|
+
if (!this.glyph.stem) {
|
|
802
|
+
return super_stem_extension;
|
|
803
|
+
}
|
|
804
|
+
const stem_direction = this.getStemDirection();
|
|
805
|
+
if (stem_direction !== this.calculateOptimalStemDirection()) {
|
|
806
|
+
return super_stem_extension;
|
|
807
|
+
}
|
|
808
|
+
let mid_line_distance;
|
|
809
|
+
const MIDDLE_LINE = 3;
|
|
810
|
+
if (stem_direction === Stem.UP) {
|
|
811
|
+
mid_line_distance = MIDDLE_LINE - this.maxLine;
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
mid_line_distance = this.minLine - MIDDLE_LINE;
|
|
815
|
+
}
|
|
816
|
+
const lines_over_octave_from_mid_line = mid_line_distance - 3.5;
|
|
817
|
+
if (lines_over_octave_from_mid_line <= 0) {
|
|
818
|
+
return super_stem_extension;
|
|
819
|
+
}
|
|
820
|
+
const stave = this.getStave();
|
|
821
|
+
let spacing_between_lines = 10;
|
|
822
|
+
if (stave != undefined) {
|
|
823
|
+
spacing_between_lines = stave.getSpacingBetweenLines();
|
|
824
|
+
}
|
|
825
|
+
return super_stem_extension + lines_over_octave_from_mid_line * spacing_between_lines;
|
|
826
|
+
}
|
|
827
|
+
draw() {
|
|
828
|
+
if (this.ys.length === 0) {
|
|
829
|
+
throw new RuntimeError('NoYValues', "Can't draw note without Y values.");
|
|
830
|
+
}
|
|
831
|
+
const ctx = this.checkContext();
|
|
832
|
+
const xBegin = this.getNoteHeadBeginX();
|
|
833
|
+
const shouldRenderStem = this.hasStem() && !this.beam;
|
|
834
|
+
this._noteHeads.forEach((notehead) => notehead.setX(xBegin));
|
|
835
|
+
if (this.stem) {
|
|
836
|
+
const stemX = this.getStemX();
|
|
837
|
+
this.stem.setNoteHeadXBounds(stemX, stemX);
|
|
838
|
+
}
|
|
839
|
+
L('Rendering ', this.isChord() ? 'chord :' : 'note :', this.keys);
|
|
840
|
+
this.applyStyle();
|
|
841
|
+
this.setAttribute('el', ctx.openGroup('stavenote', this.getAttribute('id')));
|
|
842
|
+
this.drawLedgerLines();
|
|
843
|
+
ctx.openGroup('note', undefined, { pointerBBox: true });
|
|
844
|
+
if (shouldRenderStem)
|
|
845
|
+
this.drawStem();
|
|
846
|
+
this.drawNoteHeads();
|
|
847
|
+
this.drawFlag();
|
|
848
|
+
ctx.closeGroup();
|
|
849
|
+
this.drawModifiers();
|
|
850
|
+
ctx.closeGroup();
|
|
851
|
+
this.restoreStyle();
|
|
852
|
+
this.setRendered();
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
StaveNote.DEBUG = false;
|