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

Method checkForFinish

packages/alphatab/src/synth/AlphaSynth.ts:524–578  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

522 }
523
524 protected checkForFinish() {
525 let startTick = 0;
526 let endTick = 0;
527
528 if (this.playbackRange && this.sequencer.isPlayingMain) {
529 startTick = this.playbackRange.startTick;
530 endTick = this.playbackRange.endTick;
531 } else {
532 endTick = this.sequencer.currentEndTick;
533 }
534
535 if (this._tickPosition >= endTick) {
536 // fully done with playback of remaining samples?
537 if (this._notPlayedSamples <= 0) {
538 this._notPlayedSamples = 0;
539 if (this.sequencer.isPlayingCountIn) {
540 Logger.debug('AlphaSynth', 'Finished playback (count-in)');
541 this.sequencer.resetCountIn();
542 this.timePosition = this.sequencer.currentTime;
543 this._playInternal();
544 this.output.resetSamples();
545 } else if (this.sequencer.isPlayingOneTimeMidi) {
546 Logger.debug('AlphaSynth', 'Finished playback (one time)');
547 this.output.resetSamples();
548 this.state = PlayerState.Paused;
549 this._stopOneTimeMidi();
550 } else if (this.isLooping) {
551 Logger.debug('AlphaSynth', 'Finished playback (main looping)');
552 (this.finished as EventEmitter).trigger();
553 this.tickPosition = startTick;
554 this._synthStopping = false;
555 } else if (this.synthesizer.activeVoiceCount > 0) {
556 // smooth stop
557 if (!this._synthStopping) {
558 Logger.debug('AlphaSynth', 'Signaling synth to stop all voices (all samples played)');
559 this.synthesizer.noteOffAll(true);
560 this._synthStopping = true;
561 }
562 } else {
563 this._synthStopping = false;
564 Logger.debug('AlphaSynth', 'Finished playback (main)');
565 (this.finished as EventEmitter).trigger();
566 this.stop();
567 }
568 } else {
569 // the output still has to play some samples, signal the synth to stop
570 // to eventually bring the voices down to 0 and stop playing
571 if (!this._synthStopping) {
572 Logger.debug('AlphaSynth', 'Signaling synth to stop all voices (not all samples played)');
573 this.synthesizer.noteOffAll(true);
574 this._synthStopping = true;
575 }
576 }
577 }
578 }
579
580 private _stopOneTimeMidi() {
581 this.output.pause();

Callers 2

_onSamplesPlayedMethod · 0.95
constructorMethod · 0.80

Calls 8

_playInternalMethod · 0.95
_stopOneTimeMidiMethod · 0.95
stopMethod · 0.95
resetCountInMethod · 0.80
debugMethod · 0.65
resetSamplesMethod · 0.65
noteOffAllMethod · 0.65
triggerMethod · 0.45

Tested by

no test coverage detected