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

Method finish

packages/alphatab/src/model/Voice.ts:171–288  ·  view source on GitHub ↗
(settings: Settings, sharedDataBag: Map<string, unknown> | null = null)

Source from the content-addressed store, hash-verified

169 }
170
171 public finish(settings: Settings, sharedDataBag: Map<string, unknown> | null = null): void {
172 this._isEmpty = true;
173 this._isRestOnly = true;
174 this._beatLookup = new Map<number, Beat>();
175 let currentGraceGroup: GraceGroup | null = null;
176 for (let index: number = 0; index < this.beats.length; index++) {
177 const beat: Beat = this.beats[index];
178 beat.index = index;
179 this._chain(beat, sharedDataBag);
180 if (beat.graceType === GraceType.None) {
181 beat.graceGroup = currentGraceGroup;
182 if (currentGraceGroup) {
183 currentGraceGroup.isComplete = true;
184 }
185 currentGraceGroup = null;
186 } else {
187 if (!currentGraceGroup) {
188 currentGraceGroup = new GraceGroup();
189 }
190 currentGraceGroup.addBeat(beat);
191 }
192 if (!beat.isEmpty) {
193 this._isEmpty = false;
194 }
195 if (!beat.isRest) {
196 this._isRestOnly = false;
197 }
198 }
199
200 let currentDisplayTick: number = 0;
201 let currentPlaybackTick: number = 0;
202 this.shortestDuration = Duration.DoubleWhole;
203 for (let i: number = 0; i < this.beats.length; i++) {
204 const beat: Beat = this.beats[i];
205 beat.index = i;
206 beat.finish(settings, sharedDataBag);
207
208 // if this beat is a non-grace but has grace notes
209 // we need to first steal the duration from the right beat
210 // and place the grace beats correctly
211 if (beat.graceType === GraceType.None) {
212 if (beat.duration > this.shortestDuration) {
213 this.shortestDuration = beat.duration;
214 }
215
216 if (beat.graceGroup) {
217 const firstGraceBeat = beat.graceGroup!.beats[0];
218 const lastGraceBeat = beat.graceGroup!.beats[beat.graceGroup!.beats.length - 1];
219 if (firstGraceBeat.graceType !== GraceType.BendGrace) {
220 // find out the stolen duration first
221 const stolenDuration: number =
222 lastGraceBeat.playbackStart + lastGraceBeat.playbackDuration - firstGraceBeat.playbackStart;
223
224 switch (firstGraceBeat.graceType) {
225 case GraceType.BeforeBeat:
226 // steal duration from previous beat and then place grace beats newly
227 if (firstGraceBeat.previousBeat) {
228 firstGraceBeat.previousBeat.playbackDuration -= stolenDuration;

Callers

nothing calls this directly

Calls 7

_chainMethod · 0.95
addFermataMethod · 0.80
getFermataMethod · 0.80
finishTupletMethod · 0.80
addBeatMethod · 0.45
deleteMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected