-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathTabSlurGlyph.ts
More file actions
71 lines (66 loc) · 2.55 KB
/
TabSlurGlyph.ts
File metadata and controls
71 lines (66 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type { Note } from '@coderline/alphatab/model/Note';
import { TabTieGlyph } from '@coderline/alphatab/rendering/glyphs/TabTieGlyph';
import { BeamDirection } from '@coderline/alphatab/rendering/utils/BeamDirection';
/**
* @internal
*/
export class TabSlurGlyph extends TabTieGlyph {
private _forSlide: boolean;
private readonly _slurText?: string;
public constructor(slurEffectId: string, startNote: Note, endNote: Note, forSlide: boolean, forEnd:boolean, slurText?: string) {
super(slurEffectId, startNote, endNote, forEnd);
this._forSlide = forSlide;
this._slurText = slurText;
}
public override getTieHeight(startX: number, _startY: number, endX: number, _endY: number): number {
return (Math.log(endX - startX + 1) * this.renderer.settings.notation.slurHeight) / 2;
}
protected override getSlurText(): string | undefined {
return this._slurText;
}
public tryExpand(startNote: Note, endNote: Note, forSlide: boolean, forEnd: boolean, slurText?: string): boolean {
// same label required (when provided)
if (slurText !== undefined && this._slurText !== slurText) {
return false;
}
// same type required
if (this._forSlide !== forSlide) {
return false;
}
// same start and endbeat
if (this.startNote.beat.id !== startNote.beat.id) {
return false;
}
if (this.endNote.beat.id !== endNote.beat.id) {
return false;
}
const isForEnd = this.renderer === this.lookupEndBeatRenderer();
if (isForEnd !== forEnd) {
return false;
}
// same draw direction
if (this.tieDirection !== TabTieGlyph.getBeamDirectionForNote(startNote)) {
return false;
}
// if we can expand, expand in correct direction
switch (this.tieDirection) {
case BeamDirection.Up:
if (startNote.realValue > this.startNote.realValue) {
this.startNote = startNote;
}
if (endNote.realValue > this.endNote.realValue) {
this.endNote = endNote;
}
break;
case BeamDirection.Down:
if (startNote.realValue < this.startNote.realValue) {
this.startNote = startNote;
}
if (endNote.realValue < this.endNote.realValue) {
this.endNote = endNote;
}
break;
}
return true;
}
}