-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathTabBeatContainerGlyph.ts
More file actions
163 lines (158 loc) · 6.48 KB
/
TabBeatContainerGlyph.ts
File metadata and controls
163 lines (158 loc) · 6.48 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import type { Beat } from '@coderline/alphatab/model/Beat';
import type { Note } from '@coderline/alphatab/model/Note';
import { SlideInType } from '@coderline/alphatab/model/SlideInType';
import { SlideOutType } from '@coderline/alphatab/model/SlideOutType';
import { BeatContainerGlyph } from '@coderline/alphatab/rendering/glyphs/BeatContainerGlyph';
import { TabBeatGlyph } from '@coderline/alphatab/rendering/glyphs/TabBeatGlyph';
import { TabBeatPreNotesGlyph } from '@coderline/alphatab/rendering/glyphs/TabBeatPreNotesGlyph';
import { TabBendGlyph } from '@coderline/alphatab/rendering/glyphs/TabBendGlyph';
import { TabSlideLineGlyph } from '@coderline/alphatab/rendering/glyphs/TabSlideLineGlyph';
import { TabSlurGlyph } from '@coderline/alphatab/rendering/glyphs/TabSlurGlyph';
import { TabTieGlyph } from '@coderline/alphatab/rendering/glyphs/TabTieGlyph';
import type { TabBarRenderer } from '@coderline/alphatab/rendering/TabBarRenderer';
import type { BeamingHelper } from '@coderline/alphatab/rendering/utils/BeamingHelper';
/**
* @internal
*/
export class TabBeatContainerGlyph extends BeatContainerGlyph {
private _bend: TabBendGlyph | null = null;
private _effectSlurs: TabSlurGlyph[] = [];
public constructor(beat: Beat) {
super(beat);
this.preNotes = new TabBeatPreNotesGlyph();
this.onNotes = new TabBeatGlyph();
}
protected override drawBeamHelperAsFlags(helper: BeamingHelper): boolean {
return helper.hasFlag((this.renderer as TabBarRenderer).drawBeamHelperAsFlags(helper), this.beat);
}
public override doLayout(): void {
this._effectSlurs = [];
super.doLayout();
if (this._bend) {
this._bend.renderer = this.renderer;
this._bend.doLayout();
this.updateWidth();
}
}
protected override createTies(n: Note): void {
if (!n.isVisible) {
return;
}
const renderer: TabBarRenderer = this.renderer as TabBarRenderer;
if (n.isTieOrigin && renderer.showTiedNotes && n.tieDestination!.isVisible) {
const tie: TabTieGlyph = new TabTieGlyph(`tab.tie.${n.id}`, n, n.tieDestination!, false);
this.addTie(tie);
}
if (n.isTieDestination && renderer.showTiedNotes) {
const tie: TabTieGlyph = new TabTieGlyph(`tab.tie.${n.tieOrigin!.id}`, n.tieOrigin!, n, true);
this.addTie(tie);
}
if (n.isLeftHandTapped && !n.isHammerPullDestination) {
const tapSlur: TabTieGlyph = new TabTieGlyph(`tab.tie.leftHandTap.${n.id}`, n, n, false);
this.addTie(tapSlur);
}
// H/P arc start-side: create individual arc per hammer-pull pair
if (n.isHammerPullOrigin && n.hammerPullDestination) {
const dest = n.hammerPullDestination;
const slurText = dest.fret >= n.fret ? 'H' : 'P';
let expanded: boolean = false;
for (const slur of this._effectSlurs) {
if (slur.tryExpand(n, dest, false, false, slurText)) {
expanded = true;
break;
}
}
if (!expanded) {
const effectSlur: TabSlurGlyph = new TabSlurGlyph(
`tab.slur.effect.${n.id}`,
n,
dest,
false,
false,
slurText
);
this._effectSlurs.push(effectSlur);
this.addTie(effectSlur);
}
}
// H/P arc end-side: for cross-bar rendering
if (n.isHammerPullDestination && n.hammerPullOrigin) {
const origin = n.hammerPullOrigin;
const slurText = n.fret >= origin.fret ? 'H' : 'P';
let expanded: boolean = false;
for (const slur of this._effectSlurs) {
if (slur.tryExpand(origin, n, false, true, slurText)) {
expanded = true;
break;
}
}
if (!expanded) {
const effectSlur: TabSlurGlyph = new TabSlurGlyph(
`tab.slur.effect.${origin.id}`,
origin,
n,
false,
true,
slurText
);
this._effectSlurs.push(effectSlur);
this.addTie(effectSlur);
}
}
// start non-H/P effect slur (e.g. legato slide)
if (n.isEffectSlurOrigin && n.effectSlurDestination && !n.isHammerPullOrigin) {
let expanded: boolean = false;
for (const slur of this._effectSlurs) {
if (slur.tryExpand(n, n.effectSlurDestination, false, false)) {
expanded = true;
break;
}
}
if (!expanded) {
const effectSlur: TabSlurGlyph = new TabSlurGlyph(
`tab.slur.effect.${n.id}`,
n,
n.effectSlurDestination,
false,
false
);
this._effectSlurs.push(effectSlur);
this.addTie(effectSlur);
}
}
// end non-H/P effect slur
if (n.isEffectSlurDestination && n.effectSlurOrigin && !n.isHammerPullDestination) {
let expanded: boolean = false;
for (const slur of this._effectSlurs) {
if (slur.tryExpand(n.effectSlurOrigin, n, false, true)) {
expanded = true;
break;
}
}
if (!expanded) {
const effectSlur: TabSlurGlyph = new TabSlurGlyph(
`tab.slur.effect.${n.effectSlurOrigin.id}`,
n.effectSlurOrigin,
n,
false,
true
);
this._effectSlurs.push(effectSlur);
this.addTie(effectSlur);
}
}
if (n.slideInType !== SlideInType.None || n.slideOutType !== SlideOutType.None) {
const l: TabSlideLineGlyph = new TabSlideLineGlyph(n.slideInType, n.slideOutType, n, this);
this.addTie(l);
}
if (n.hasBend) {
if (!this._bend) {
const bend = new TabBendGlyph();
this._bend = bend;
bend.renderer = this.renderer;
this.addTie(bend);
}
this._bend.addBends(n);
}
}
}