vexflow 5.0.0-alpha.2 → 5.0.0-alpha.4
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 +528 -492
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +460 -452
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/accidental.js +22 -28
- package/build/esm/src/beam.js +24 -42
- package/build/esm/src/clefnote.js +6 -1
- package/build/esm/src/element.js +83 -101
- package/build/esm/src/fonts/gonville.js +1 -1
- package/build/esm/src/formatter.js +9 -17
- package/build/esm/src/fraction.js +15 -22
- package/build/esm/src/glyphnote.js +3 -2
- package/build/esm/src/metrics.js +3 -0
- package/build/esm/src/modifier.js +6 -21
- package/build/esm/src/multimeasurerest.js +16 -25
- package/build/esm/src/note.js +7 -0
- package/build/esm/src/registry.js +5 -19
- package/build/esm/src/stave.js +4 -6
- package/build/esm/src/stavenote.js +26 -40
- package/build/esm/src/stavetempo.js +4 -11
- package/build/esm/src/stavetie.js +82 -36
- package/build/esm/src/svgcontext.js +5 -12
- package/build/esm/src/tickable.js +13 -26
- package/build/esm/src/tickcontext.js +20 -2
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vibrato.js +6 -1
- package/build/esm/tests/clef_tests.js +5 -1
- package/build/esm/tests/glyphnote_tests.js +6 -0
- package/build/esm/tests/stavetie_tests.js +29 -0
- package/build/esm/tests/tabstave_tests.js +1 -0
- package/build/esm/tests/vexflow_test_helpers.js +25 -39
- package/build/types/src/accidental.d.ts +19 -1
- package/build/types/src/annotation.d.ts +1 -1
- package/build/types/src/beam.d.ts +12 -1
- package/build/types/src/clefnote.d.ts +2 -0
- package/build/types/src/element.d.ts +13 -3
- package/build/types/src/fonts/gonville.d.ts +1 -1
- package/build/types/src/formatter.d.ts +5 -3
- package/build/types/src/fraction.d.ts +12 -7
- package/build/types/src/modifier.d.ts +2 -1
- package/build/types/src/multimeasurerest.d.ts +4 -1
- package/build/types/src/note.d.ts +2 -0
- package/build/types/src/registry.d.ts +1 -1
- package/build/types/src/stavenote.d.ts +2 -1
- package/build/types/src/stavetempo.d.ts +3 -3
- package/build/types/src/stavetie.d.ts +39 -2
- package/build/types/src/svgcontext.d.ts +1 -1
- package/build/types/src/tickable.d.ts +2 -1
- package/build/types/src/tickcontext.d.ts +30 -0
- package/package.json +2 -4
- package/tests/flow.html +2 -2
- package/entry/vexflow-bravura.ts +0 -25
- package/entry/vexflow-core.ts +0 -16
- package/entry/vexflow-debug-with-tests.ts +0 -64
- package/entry/vexflow-debug.ts +0 -54
- package/entry/vexflow.ts +0 -47
- package/src/accidental.ts +0 -570
- package/src/annotation.ts +0 -294
- package/src/articulation.ts +0 -383
- package/src/barnote.ts +0 -95
- package/src/beam.ts +0 -999
- package/src/bend.ts +0 -268
- package/src/boundingbox.ts +0 -108
- package/src/canvascontext.ts +0 -348
- package/src/chordsymbol.ts +0 -473
- package/src/clef.ts +0 -164
- package/src/clefnote.ts +0 -50
- package/src/crescendo.ts +0 -132
- package/src/curve.ts +0 -195
- package/src/dot.ts +0 -171
- package/src/easyscore.ts +0 -538
- package/src/element.ts +0 -692
- package/src/factory.ts +0 -694
- package/src/font.ts +0 -343
- package/src/fonts/academico.ts +0 -2
- package/src/fonts/academicobold.ts +0 -2
- package/src/fonts/bravura.ts +0 -2
- package/src/fonts/gonville.ts +0 -2
- package/src/fonts/petaluma.ts +0 -2
- package/src/fonts/petalumascript.ts +0 -2
- package/src/formatter.ts +0 -1107
- package/src/fraction.ts +0 -245
- package/src/frethandfinger.ts +0 -180
- package/src/ghostnote.ts +0 -75
- package/src/glyphnote.ts +0 -68
- package/src/glyphs.ts +0 -5880
- package/src/gracenote.ts +0 -146
- package/src/gracenotegroup.ts +0 -194
- package/src/gracetabnote.ts +0 -30
- package/src/index.ts +0 -90
- package/src/keymanager.ts +0 -153
- package/src/keysignature.ts +0 -272
- package/src/keysignote.ts +0 -46
- package/src/metrics.ts +0 -222
- package/src/modifier.ts +0 -216
- package/src/modifiercontext.ts +0 -177
- package/src/multimeasurerest.ts +0 -229
- package/src/music.ts +0 -443
- package/src/note.ts +0 -690
- package/src/notehead.ts +0 -158
- package/src/notesubgroup.ts +0 -88
- package/src/ornament.ts +0 -301
- package/src/parenthesis.ts +0 -89
- package/src/parser.ts +0 -263
- package/src/pedalmarking.ts +0 -273
- package/src/registry.ts +0 -146
- package/src/rendercontext.ts +0 -98
- package/src/renderer.ts +0 -166
- package/src/repeatnote.ts +0 -25
- package/src/stave.ts +0 -885
- package/src/stavebarline.ts +0 -231
- package/src/staveconnector.ts +0 -281
- package/src/stavehairpin.ts +0 -209
- package/src/staveline.ts +0 -343
- package/src/stavemodifier.ts +0 -93
- package/src/stavenote.ts +0 -1230
- package/src/staverepetition.ts +0 -148
- package/src/stavesection.ts +0 -54
- package/src/stavetempo.ts +0 -162
- package/src/stavetext.ts +0 -69
- package/src/stavetie.ts +0 -235
- package/src/stavevolta.ts +0 -66
- package/src/stem.ts +0 -225
- package/src/stemmablenote.ts +0 -248
- package/src/stringnumber.ts +0 -286
- package/src/strokes.ts +0 -214
- package/src/svgcontext.ts +0 -639
- package/src/system.ts +0 -327
- package/src/tables.ts +0 -796
- package/src/tabnote.ts +0 -449
- package/src/tabslide.ts +0 -115
- package/src/tabstave.ts +0 -31
- package/src/tabtie.ts +0 -44
- package/src/textbracket.ts +0 -231
- package/src/textdynamics.ts +0 -101
- package/src/textnote.ts +0 -175
- package/src/tickable.ts +0 -374
- package/src/tickcontext.ts +0 -280
- package/src/timesignature.ts +0 -229
- package/src/timesignote.ts +0 -45
- package/src/tremolo.ts +0 -51
- package/src/tuning.ts +0 -90
- package/src/tuplet.ts +0 -349
- package/src/typeguard.ts +0 -136
- package/src/util.ts +0 -169
- package/src/version.ts +0 -4
- package/src/vexflow.ts +0 -378
- package/src/vibrato.ts +0 -99
- package/src/vibratobracket.ts +0 -81
- package/src/voice.ts +0 -302
- package/src/web.ts +0 -35
package/src/crescendo.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// This file implements the `Crescendo` object which draws crescendos and
|
|
4
|
-
// decrescendo dynamics markings. A `Crescendo` is initialized with a
|
|
5
|
-
// duration and formatted as part of a `Voice` like any other `Note`
|
|
6
|
-
// type in VexFlow. This object would most likely be formatted in a Voice
|
|
7
|
-
// with `TextNotes` - which are used to represent other dynamics markings.
|
|
8
|
-
|
|
9
|
-
import { Note, NoteStruct } from './note';
|
|
10
|
-
import { RenderContext } from './rendercontext';
|
|
11
|
-
import { TickContext } from './tickcontext';
|
|
12
|
-
import { Category } from './typeguard';
|
|
13
|
-
import { log } from './util';
|
|
14
|
-
|
|
15
|
-
export interface CrescendoParams {
|
|
16
|
-
reverse: boolean;
|
|
17
|
-
height: number;
|
|
18
|
-
y: number;
|
|
19
|
-
beginX: number;
|
|
20
|
-
endX: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// To enable logging for this class. Set `VexFlow.Crescendo.DEBUG` to `true`.
|
|
24
|
-
// eslint-disable-next-line
|
|
25
|
-
function L(...args: any[]) {
|
|
26
|
-
if (Crescendo.DEBUG) log('VexFlow.Crescendo', args);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Helper to draw the hairpin.
|
|
30
|
-
function renderHairpin(ctx: RenderContext, params: CrescendoParams) {
|
|
31
|
-
const beginX = params.beginX;
|
|
32
|
-
const endX = params.endX;
|
|
33
|
-
const y = params.y;
|
|
34
|
-
const halfHeight = params.height / 2;
|
|
35
|
-
|
|
36
|
-
ctx.beginPath();
|
|
37
|
-
|
|
38
|
-
if (params.reverse) {
|
|
39
|
-
ctx.moveTo(beginX, y - halfHeight);
|
|
40
|
-
ctx.lineTo(endX, y);
|
|
41
|
-
ctx.lineTo(beginX, y + halfHeight);
|
|
42
|
-
} else {
|
|
43
|
-
ctx.moveTo(endX, y - halfHeight);
|
|
44
|
-
ctx.lineTo(beginX, y);
|
|
45
|
-
ctx.lineTo(endX, y + halfHeight);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
ctx.stroke();
|
|
49
|
-
ctx.closePath();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class Crescendo extends Note {
|
|
53
|
-
static DEBUG: boolean = false;
|
|
54
|
-
|
|
55
|
-
/** Crescendo category string. */
|
|
56
|
-
static get CATEGORY(): string {
|
|
57
|
-
return Category.Crescendo;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
protected decrescendo: boolean;
|
|
61
|
-
protected line: number;
|
|
62
|
-
protected options = {
|
|
63
|
-
// Extensions to the length of the crescendo on either side
|
|
64
|
-
extendLeft: 0,
|
|
65
|
-
extendRight: 0,
|
|
66
|
-
// Vertical shift
|
|
67
|
-
yShift: 0,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Initialize the crescendo's properties
|
|
71
|
-
constructor(noteStruct: NoteStruct) {
|
|
72
|
-
super(noteStruct);
|
|
73
|
-
|
|
74
|
-
// Whether the object is a decrescendo
|
|
75
|
-
this.decrescendo = false;
|
|
76
|
-
|
|
77
|
-
// The staff line to be placed on
|
|
78
|
-
this.line = noteStruct.line ?? 0;
|
|
79
|
-
|
|
80
|
-
// The height at the open end of the cresc/decresc
|
|
81
|
-
this.height = 15;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Set the line to center the element on
|
|
85
|
-
setLine(line: number): this {
|
|
86
|
-
this.line = line;
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Set the full height at the open end
|
|
91
|
-
setHeight(height: number): this {
|
|
92
|
-
this.height = height;
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Set whether the sign should be a descresendo by passing a bool
|
|
97
|
-
// to `decresc`
|
|
98
|
-
setDecrescendo(decresc: boolean): this {
|
|
99
|
-
this.decrescendo = decresc;
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Preformat the note
|
|
104
|
-
preFormat(): this {
|
|
105
|
-
this.preFormatted = true;
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Render the Crescendo object onto the canvas
|
|
110
|
-
draw(): void {
|
|
111
|
-
const ctx = this.checkContext();
|
|
112
|
-
const stave = this.checkStave();
|
|
113
|
-
this.setRendered();
|
|
114
|
-
|
|
115
|
-
const tickContext = this.getTickContext();
|
|
116
|
-
const nextContext = TickContext.getNextContext(tickContext);
|
|
117
|
-
|
|
118
|
-
const beginX = this.getAbsoluteX();
|
|
119
|
-
const endX = nextContext ? nextContext.getX() : stave.getX() + stave.getWidth();
|
|
120
|
-
const y = stave.getYForLine(this.line + -3) + 1;
|
|
121
|
-
|
|
122
|
-
L('Drawing ', this.decrescendo ? 'decrescendo ' : 'crescendo ', this.height, 'x', beginX - endX);
|
|
123
|
-
|
|
124
|
-
renderHairpin(ctx, {
|
|
125
|
-
beginX: beginX - this.options.extendLeft,
|
|
126
|
-
endX: endX + this.options.extendRight,
|
|
127
|
-
y: y + this.options.yShift,
|
|
128
|
-
height: this.height,
|
|
129
|
-
reverse: this.decrescendo,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
package/src/curve.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// This class implements curves (for slurs)
|
|
4
|
-
|
|
5
|
-
import { Element } from './element';
|
|
6
|
-
import { Note } from './note';
|
|
7
|
-
import { Category } from './typeguard';
|
|
8
|
-
import { RuntimeError } from './util';
|
|
9
|
-
|
|
10
|
-
export interface CurveOptions {
|
|
11
|
-
/** Two control points for the bezier curves. */
|
|
12
|
-
cps?: { x: number; y: number }[];
|
|
13
|
-
thickness?: number;
|
|
14
|
-
xShift?: number;
|
|
15
|
-
yShift?: number;
|
|
16
|
-
position?: string | number;
|
|
17
|
-
positionEnd?: string | number;
|
|
18
|
-
invert?: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export enum CurvePosition {
|
|
22
|
-
NEAR_HEAD = 1,
|
|
23
|
-
NEAR_TOP = 2,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class Curve extends Element {
|
|
27
|
-
static get CATEGORY(): string {
|
|
28
|
-
return Category.Curve;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public renderOptions: Required<CurveOptions>;
|
|
32
|
-
protected from: Note;
|
|
33
|
-
protected to: Note;
|
|
34
|
-
|
|
35
|
-
static get Position(): typeof CurvePosition {
|
|
36
|
-
return CurvePosition;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static get PositionString(): Record<string, number> {
|
|
40
|
-
return {
|
|
41
|
-
nearHead: CurvePosition.NEAR_HEAD,
|
|
42
|
-
nearTop: CurvePosition.NEAR_TOP,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// from: Start note
|
|
47
|
-
// to: End note
|
|
48
|
-
// options:
|
|
49
|
-
// cps: List of control points
|
|
50
|
-
// xShift: pixels to shift
|
|
51
|
-
// yShift: pixels to shift
|
|
52
|
-
constructor(from: Note, to: Note, options: CurveOptions) {
|
|
53
|
-
super();
|
|
54
|
-
|
|
55
|
-
this.renderOptions = {
|
|
56
|
-
thickness: 2,
|
|
57
|
-
xShift: 0,
|
|
58
|
-
yShift: 10,
|
|
59
|
-
position: CurvePosition.NEAR_HEAD,
|
|
60
|
-
positionEnd: CurvePosition.NEAR_HEAD,
|
|
61
|
-
invert: false,
|
|
62
|
-
cps: [
|
|
63
|
-
{ x: 0, y: 10 },
|
|
64
|
-
{ x: 0, y: 10 },
|
|
65
|
-
],
|
|
66
|
-
...options,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
this.from = from;
|
|
70
|
-
this.to = to;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
setNotes(from: Note, to: Note): this {
|
|
74
|
-
if (!from && !to) {
|
|
75
|
-
throw new RuntimeError('BadArguments', 'Curve needs to have either `from` or `to` set.');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.from = from;
|
|
79
|
-
this.to = to;
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @return {boolean} Returns true if this is a partial bar.
|
|
85
|
-
*/
|
|
86
|
-
isPartial(): boolean {
|
|
87
|
-
return !this.from || !this.to;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
renderCurve(params: { lastY: number; lastX: number; firstY: number; firstX: number; direction: number }): void {
|
|
91
|
-
const ctx = this.checkContext();
|
|
92
|
-
this.applyStyle();
|
|
93
|
-
|
|
94
|
-
const xShift = this.renderOptions.xShift;
|
|
95
|
-
const yShift = this.renderOptions.yShift * params.direction;
|
|
96
|
-
|
|
97
|
-
const firstX = params.firstX + xShift;
|
|
98
|
-
const firstY = params.firstY + yShift;
|
|
99
|
-
const lastX = params.lastX - xShift;
|
|
100
|
-
const lastY = params.lastY + yShift;
|
|
101
|
-
const thickness = this.renderOptions.thickness;
|
|
102
|
-
|
|
103
|
-
const cps = this.renderOptions.cps;
|
|
104
|
-
const { x: cp0x, y: cp0y } = cps[0];
|
|
105
|
-
const { x: cp1x, y: cp1y } = cps[1];
|
|
106
|
-
|
|
107
|
-
const controlPointSpacing = (lastX - firstX) / (cps.length + 2);
|
|
108
|
-
|
|
109
|
-
ctx.beginPath();
|
|
110
|
-
ctx.moveTo(firstX, firstY);
|
|
111
|
-
ctx.bezierCurveTo(
|
|
112
|
-
firstX + controlPointSpacing + cp0x,
|
|
113
|
-
firstY + cp0y * params.direction,
|
|
114
|
-
lastX - controlPointSpacing + cp1x,
|
|
115
|
-
lastY + cp1y * params.direction,
|
|
116
|
-
lastX,
|
|
117
|
-
lastY
|
|
118
|
-
);
|
|
119
|
-
if (!this.style?.lineDash)
|
|
120
|
-
ctx.bezierCurveTo(
|
|
121
|
-
lastX - controlPointSpacing + cp1x,
|
|
122
|
-
lastY + (cp1y + thickness) * params.direction,
|
|
123
|
-
firstX + controlPointSpacing + cp0x,
|
|
124
|
-
firstY + (cp0y + thickness) * params.direction,
|
|
125
|
-
firstX,
|
|
126
|
-
firstY
|
|
127
|
-
);
|
|
128
|
-
ctx.stroke();
|
|
129
|
-
ctx.closePath();
|
|
130
|
-
if (!this.style?.lineDash) ctx.fill();
|
|
131
|
-
this.restoreStyle();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
draw(): boolean {
|
|
135
|
-
this.checkContext();
|
|
136
|
-
this.setRendered();
|
|
137
|
-
|
|
138
|
-
const firstNote = this.from;
|
|
139
|
-
const lastNote = this.to;
|
|
140
|
-
let firstX;
|
|
141
|
-
let lastX;
|
|
142
|
-
let firstY;
|
|
143
|
-
let lastY;
|
|
144
|
-
let stemDirection = 0;
|
|
145
|
-
|
|
146
|
-
let metric = 'baseY';
|
|
147
|
-
let endMetric = 'baseY';
|
|
148
|
-
|
|
149
|
-
function getPosition(position: string | number) {
|
|
150
|
-
return typeof position === 'string' ? Curve.PositionString[position] : position;
|
|
151
|
-
}
|
|
152
|
-
const position = getPosition(this.renderOptions.position);
|
|
153
|
-
const positionEnd = getPosition(this.renderOptions.positionEnd);
|
|
154
|
-
|
|
155
|
-
if (position === CurvePosition.NEAR_TOP) {
|
|
156
|
-
metric = 'topY';
|
|
157
|
-
endMetric = 'topY';
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (positionEnd === CurvePosition.NEAR_HEAD) {
|
|
161
|
-
endMetric = 'baseY';
|
|
162
|
-
} else if (positionEnd === CurvePosition.NEAR_TOP) {
|
|
163
|
-
endMetric = 'topY';
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (firstNote) {
|
|
167
|
-
firstX = firstNote.getTieRightX();
|
|
168
|
-
stemDirection = firstNote.getStemDirection();
|
|
169
|
-
firstY = firstNote.getStemExtents()[metric];
|
|
170
|
-
} else {
|
|
171
|
-
const stave = lastNote.checkStave();
|
|
172
|
-
firstX = stave.getTieStartX();
|
|
173
|
-
firstY = lastNote.getStemExtents()[metric];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (lastNote) {
|
|
177
|
-
lastX = lastNote.getTieLeftX();
|
|
178
|
-
stemDirection = lastNote.getStemDirection();
|
|
179
|
-
lastY = lastNote.getStemExtents()[endMetric];
|
|
180
|
-
} else {
|
|
181
|
-
const stave = firstNote.checkStave();
|
|
182
|
-
lastX = stave.getTieEndX();
|
|
183
|
-
lastY = firstNote.getStemExtents()[endMetric];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
this.renderCurve({
|
|
187
|
-
firstX,
|
|
188
|
-
lastX,
|
|
189
|
-
firstY,
|
|
190
|
-
lastY,
|
|
191
|
-
direction: stemDirection * (this.renderOptions.invert === true ? -1 : 1),
|
|
192
|
-
});
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
}
|
package/src/dot.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
2
|
-
//
|
|
3
|
-
// This class implements dot modifiers for notes.
|
|
4
|
-
|
|
5
|
-
import { Glyphs } from './glyphs';
|
|
6
|
-
import { Modifier } from './modifier';
|
|
7
|
-
import { ModifierContextState } from './modifiercontext';
|
|
8
|
-
import { Note } from './note';
|
|
9
|
-
import { Category, isStaveNote, isTabNote } from './typeguard';
|
|
10
|
-
import { RuntimeError } from './util';
|
|
11
|
-
|
|
12
|
-
export class Dot extends Modifier {
|
|
13
|
-
static get CATEGORY(): string {
|
|
14
|
-
return Category.Dot;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
protected dotShiftY: number;
|
|
18
|
-
|
|
19
|
-
/** Returns the dots associated to a Note. */
|
|
20
|
-
static getDots(note: Note): Dot[] {
|
|
21
|
-
return note.getModifiersByType(Dot.CATEGORY) as Dot[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Add a dot on the specified keys to the notes. */
|
|
25
|
-
static buildAndAttach(notes: Note[], options?: { index?: number; all?: boolean }): void {
|
|
26
|
-
for (const note of notes) {
|
|
27
|
-
if (options?.all) {
|
|
28
|
-
for (let i = 0; i < note.keys.length; i++) {
|
|
29
|
-
const dot = new Dot();
|
|
30
|
-
note.addModifier(dot, i);
|
|
31
|
-
}
|
|
32
|
-
} else if (options?.index !== undefined) {
|
|
33
|
-
const dot = new Dot();
|
|
34
|
-
note.addModifier(dot, options?.index);
|
|
35
|
-
} else {
|
|
36
|
-
const dot = new Dot();
|
|
37
|
-
note.addModifier(dot, 0);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Arrange dots inside a ModifierContext.
|
|
43
|
-
static format(dots: Dot[], state: ModifierContextState): boolean {
|
|
44
|
-
const rightShift = state.rightShift;
|
|
45
|
-
const dotSpacing = 1;
|
|
46
|
-
|
|
47
|
-
if (!dots || dots.length === 0) return false;
|
|
48
|
-
|
|
49
|
-
const dotList = [];
|
|
50
|
-
const maxShiftMap: Record<string, number> = {};
|
|
51
|
-
for (let i = 0; i < dots.length; ++i) {
|
|
52
|
-
const dot = dots[i];
|
|
53
|
-
const note = dot.getNote();
|
|
54
|
-
|
|
55
|
-
let props;
|
|
56
|
-
let shift;
|
|
57
|
-
|
|
58
|
-
if (isStaveNote(note)) {
|
|
59
|
-
const index = dot.checkIndex();
|
|
60
|
-
props = note.getKeyProps()[index];
|
|
61
|
-
// consider right displaced head with no previous modifier
|
|
62
|
-
shift = note.getFirstDotPx();
|
|
63
|
-
} else if (isTabNote(note)) {
|
|
64
|
-
props = { line: 0.5 }; // Shim key props for dot placement
|
|
65
|
-
shift = rightShift;
|
|
66
|
-
} else {
|
|
67
|
-
// note object is not StaveNote or TabNote.
|
|
68
|
-
throw new RuntimeError('Internal', 'Unexpected instance.');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const noteId = note.getAttribute('id');
|
|
72
|
-
dotList.push({ line: props.line, note, noteId, dot });
|
|
73
|
-
maxShiftMap[noteId] = Math.max(maxShiftMap[noteId] || shift, shift);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Sort dots by line number.
|
|
77
|
-
dotList.sort((a, b) => b.line - a.line);
|
|
78
|
-
|
|
79
|
-
let dotShift = rightShift;
|
|
80
|
-
let xWidth = 0;
|
|
81
|
-
let lastLine = null;
|
|
82
|
-
let lastNote = null;
|
|
83
|
-
let prevDottedSpace = null;
|
|
84
|
-
let halfShiftY = 0;
|
|
85
|
-
|
|
86
|
-
for (let i = 0; i < dotList.length; ++i) {
|
|
87
|
-
const { dot, note, noteId, line } = dotList[i];
|
|
88
|
-
|
|
89
|
-
// Reset the position of the dot every line.
|
|
90
|
-
if (line !== lastLine || note !== lastNote) {
|
|
91
|
-
dotShift = maxShiftMap[noteId];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!note.isRest() && line !== lastLine) {
|
|
95
|
-
if (Math.abs(line % 1) === 0.5) {
|
|
96
|
-
// note is on a space, so no dot shift
|
|
97
|
-
halfShiftY = 0;
|
|
98
|
-
} else {
|
|
99
|
-
// note is on a line, so shift dot to space above the line
|
|
100
|
-
halfShiftY = 0.5;
|
|
101
|
-
if (lastNote !== null && !lastNote.isRest() && lastLine !== null && lastLine - line === 0.5) {
|
|
102
|
-
// previous note on a space, so shift dot to space below the line
|
|
103
|
-
halfShiftY = -0.5;
|
|
104
|
-
} else if (line + halfShiftY === prevDottedSpace) {
|
|
105
|
-
// previous space is dotted, so shift dot to space below the line
|
|
106
|
-
halfShiftY = -0.5;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Convert halfShiftY to a multiplier for dots.draw().
|
|
112
|
-
if (note.isRest()) {
|
|
113
|
-
dot.dotShiftY += -halfShiftY;
|
|
114
|
-
} else {
|
|
115
|
-
dot.dotShiftY = -halfShiftY;
|
|
116
|
-
}
|
|
117
|
-
prevDottedSpace = line + halfShiftY;
|
|
118
|
-
|
|
119
|
-
dot.setXShift(dotShift);
|
|
120
|
-
dotShift += dot.getWidth() + dotSpacing; // spacing
|
|
121
|
-
xWidth = dotShift > xWidth ? dotShift : xWidth;
|
|
122
|
-
lastLine = line;
|
|
123
|
-
lastNote = note;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Update state.
|
|
127
|
-
state.rightShift += xWidth;
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
constructor() {
|
|
132
|
-
super();
|
|
133
|
-
|
|
134
|
-
this.position = Modifier.Position.RIGHT;
|
|
135
|
-
|
|
136
|
-
this.setText(Glyphs.augmentationDot);
|
|
137
|
-
this.dotShiftY = 0;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
setNote(note: Note): this {
|
|
141
|
-
this.note = note;
|
|
142
|
-
this.font = note.font;
|
|
143
|
-
return this;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
setDotShiftY(y: number): this {
|
|
147
|
-
this.dotShiftY = y;
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
draw(): void {
|
|
152
|
-
const ctx = this.checkContext();
|
|
153
|
-
const note = this.checkAttachedNote();
|
|
154
|
-
this.setRendered();
|
|
155
|
-
|
|
156
|
-
const stave = note.checkStave();
|
|
157
|
-
const lineSpace = stave.getSpacingBetweenLines();
|
|
158
|
-
|
|
159
|
-
const start = note.getModifierStartXY(this.position, this.index, { forceFlagRight: true });
|
|
160
|
-
|
|
161
|
-
// Set the starting y coordinate to the base of the stem for TabNotes.
|
|
162
|
-
if (isTabNote(note)) {
|
|
163
|
-
start.y = note.getStemExtents().baseY;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
this.x = start.x;
|
|
167
|
-
this.y = start.y + this.dotShiftY * lineSpace;
|
|
168
|
-
|
|
169
|
-
this.renderText(ctx, 0, 0);
|
|
170
|
-
}
|
|
171
|
-
}
|