MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / check

Method check

packages/alphatab/src/model/TupletGroup.ts:57–105  ·  view source on GitHub ↗
(beat: Beat)

Source from the content-addressed store, hash-verified

55 }
56
57 public check(beat: Beat): boolean {
58 if (this.beats.length === 0) {
59 // accept first beat
60 this.beats.push(beat);
61 this.totalDuration += beat.playbackDuration;
62 return true;
63 }
64 if (beat.graceType !== GraceType.None) {
65 // grace notes do not break tuplet group, but also do not contribute to them.
66 return true;
67 }
68 if (
69 beat.voice !== this.voice ||
70 this.isFull ||
71 beat.tupletNumerator !== this.beats[0].tupletNumerator ||
72 beat.tupletDenominator !== this.beats[0].tupletDenominator
73 ) {
74 // only same tuplets are potentially accepted
75 return false;
76 }
77 // TBH: I do not really know how the 100% tuplet grouping of Guitar Pro might work
78 // it sometimes has really strange rules where notes filling 3 quarters, are considered a full 3:2 tuplet
79 // in alphaTab we have now 2 rules where we consider a tuplet full:
80 // 1. if all beats have the same length, the tuplet must contain N notes of an N:M tuplet
81 // 2. if we have mixed beats, we check if the current set of beats, matches a N:M tuplet
82 // by checking all potential note durations.
83 // this logic is very likely not 100% correct but for most cases the tuplets
84 // appeared correct.
85
86 if (beat.displayDuration !== this.beats[0].displayDuration) {
87 this._isEqualLengthTuplet = false;
88 }
89 this.beats.push(beat);
90 this.totalDuration += beat.displayDuration;
91 if (this._isEqualLengthTuplet) {
92 if (this.beats.length === this.beats[0].tupletNumerator) {
93 this.isFull = true;
94 }
95 } else {
96 const factor: number = (this.beats[0].tupletNumerator / this.beats[0].tupletDenominator) | 0;
97 for (const potentialMatch of TupletGroup._allTicks) {
98 if (this.totalDuration === potentialMatch * factor) {
99 this.isFull = true;
100 break;
101 }
102 }
103 }
104 return true;
105 }
106}

Callers 2

finishTupletMethod · 0.80
_isFontAvailableMethod · 0.80

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected