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

Method _addMasterBarToRepeatGroups

packages/alphatab/src/model/Score.ts:380–423  ·  view source on GitHub ↗

* Adds the given bar correctly into the current repeat group setup. * @param bar

(bar: MasterBar)

Source from the content-addressed store, hash-verified

378 * @param bar
379 */
380 private _addMasterBarToRepeatGroups(bar: MasterBar) {
381 // handling the repeats is quite tricky due to many invalid combinations a user might define
382 // there are also some complexities due to nested repeats and repeats with multiple endings but only one opening.
383 // all scenarios are handled below.
384
385 // NOTE: In all paths we need to ensure that the bar is added to some repeat group
386
387 // start a new repeat group if really a repeat is started
388 // or we don't have a group.
389 if (bar.isRepeatStart) {
390 // if the current group was already closed (this opening doesn't cause nesting)
391 // we consider the group as completed
392 if (this._currentRepeatGroup?.isClosed) {
393 this._openedRepeatGroups.pop();
394 this._properlyOpenedRepeatGroups--;
395 }
396 this._currentRepeatGroup = new RepeatGroup();
397 this._openedRepeatGroups.push(this._currentRepeatGroup);
398 this._properlyOpenedRepeatGroups++;
399 } else if (!this._currentRepeatGroup) {
400 this._currentRepeatGroup = new RepeatGroup();
401 this._openedRepeatGroups.push(this._currentRepeatGroup);
402 }
403
404 // close current group if there was one started
405 this._currentRepeatGroup.addMasterBar(bar);
406
407 // handle repeat ends
408 if (bar.isRepeatEnd) {
409 // if we have nested repeat groups a repeat end
410 // will treat the group as completed
411 if (this._properlyOpenedRepeatGroups > 1) {
412 this._openedRepeatGroups.pop();
413 this._properlyOpenedRepeatGroups--;
414 // restore outer group in cases like "open open close close"
415 this._currentRepeatGroup =
416 this._openedRepeatGroups.length > 0
417 ? this._openedRepeatGroups[this._openedRepeatGroups.length - 1]
418 : null;
419 }
420 // else: if only one group is opened, this group stays active for
421 // scenarios like open close bar close
422 }
423 }
424
425 public addTrack(track: Track): void {
426 track.score = this;

Callers 2

rebuildRepeatGroupsMethod · 0.95
addMasterBarMethod · 0.95

Calls 3

popMethod · 0.80
pushMethod · 0.45
addMasterBarMethod · 0.45

Tested by

no test coverage detected