Repository navigation
fix(player): skip count-in in backing track and external media modes instead of freezing #2932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leocaseiro
wants to merge
6
commits into
CoderLine:develop
Choose a base branch
from
leocaseiro:fix/count-in-freeze-media-modes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−4
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7b39d5
fix(player): skip count-in in backing track and external media modes …
leocaseiro 1084229
test(player): cover count-in on the synthesizer player
leocaseiro dc26aea
test(player): check playback starts when count-in is skipped in media…
leocaseiro 9f3aba9
test(player): fail instead of hanging when the sequencer fill loop st…
leocaseiro 8d81bf8
test(player): trim the count-in tests to the core assertions
leocaseiro 5680d15
chore(player): drop the doc comment on supportsCountIn
leocaseiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { MidiFile } from '@coderline/alphatab/midi/MidiFile'; | |
| import { MidiFileGenerator } from '@coderline/alphatab/midi/MidiFileGenerator'; | ||
| import type { BackingTrack } from '@coderline/alphatab/model/BackingTrack'; | ||
| import { Settings } from '@coderline/alphatab/Settings'; | ||
| import { AlphaSynth } from '@coderline/alphatab/synth/AlphaSynth'; | ||
| import { BackingTrackPlayer, type IBackingTrackSynthOutput } from '@coderline/alphatab/synth/BackingTrackPlayer'; | ||
| import { | ||
| ExternalMediaPlayer, | ||
|
|
@@ -19,6 +20,7 @@ import type { PositionChangedEventArgs } from '@coderline/alphatab/synth/Positio | |
| import type { Hydra } from '@coderline/alphatab/synth/soundfont/Hydra'; | ||
| import type { SynthEvent } from '@coderline/alphatab/synth/synthesis/SynthEvent'; | ||
| import { FlatMidiEventGenerator } from 'test/audio/FlatMidiEventGenerator'; | ||
| import { TestOutput } from 'test/audio/TestOutput'; | ||
| import { TestPlatform } from 'test/TestPlatform'; | ||
|
|
||
| describe('SyncPointTests', () => { | ||
|
|
@@ -356,6 +358,89 @@ describe('SyncPointTests', () => { | |
| expect(events.map(e => `${e.currentTime},${e.originalTempo},${e.modifiedTempo}`)).toMatchSnapshot(); | ||
| expect(testOutput.seekTimes).toMatchSnapshot(); | ||
| }); | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Danielku15, I noticed you simplified my latest tests, so I tried to keep it simple this time. Let me know if this provides good coverage or if you would prefer a different testing approach. |
||
| /** | ||
| * See #2397: starting the playback with count-in must not rewind the media to the song start. | ||
| */ | ||
| it('count-in-keeps-position-backing-track', async () => { | ||
| const player = await prepareBackingTrackPlayer(); | ||
| const testOutput = player.output as TestBackingTrackOutput; | ||
| player.timePosition = 30000; | ||
| player.countInVolume = 1; | ||
| const seekCount = testOutput.seekTimes.length; | ||
|
|
||
| player.play(); | ||
|
|
||
| // no seek back to the song start, the next media update continues from 30s | ||
| testOutput.simulateSeek(testOutput.seekTimes[seekCount - 1] + 100); | ||
| expect(testOutput.seekTimes.length).toBe(seekCount); | ||
| expect(player.timePosition).toBeGreaterThan(30000); | ||
| }); | ||
|
|
||
| it('count-in-keeps-position-external-media', async () => { | ||
| const player = await prepareExternalMediaPlayer(); | ||
| const testOutput = (player.output as IExternalMediaSynthOutput).handler as TestExternalMediaHandler; | ||
| player.timePosition = 30000; | ||
| player.countInVolume = 1; | ||
| const seekCount = testOutput.seekTimes.length; | ||
|
|
||
| player.play(); | ||
|
|
||
| // no seek back to the song start, the next media update continues from 30s | ||
| testOutput.simulateSeek(testOutput.seekTimes[seekCount - 1] + 100); | ||
| expect(testOutput.seekTimes.length).toBe(seekCount); | ||
| expect(player.timePosition).toBeGreaterThan(30000); | ||
| }); | ||
|
|
||
| /** | ||
| * See #2397: filling the queue up to a time position must advance the active | ||
| * (count-in) state, otherwise the loop never ends. | ||
| */ | ||
| it('fill-to-end-time-during-count-in', () => { | ||
| const score = ScoreLoader.loadAlphaTex(` | ||
| . | ||
| C4 * 4 | ||
| `); | ||
|
|
||
| const midi = new MidiFile(); | ||
| const handler = new AlphaSynthMidiFileHandler(midi); | ||
| const generator = new MidiFileGenerator(score, new Settings(), handler); | ||
| generator.generate(); | ||
|
|
||
| const sequencer = new MidiFileSequencer(new EmptyAudioSynthesizer()); | ||
| sequencer.loadMidi(midi); | ||
| sequencer.startCountIn(); | ||
|
|
||
| sequencer.fillMidiEventQueueToEndTime(1000); | ||
|
|
||
| expect(sequencer.isPlayingCountIn).toBe(true); | ||
| expect(sequencer.currentTime).toBe(1000); | ||
| }); | ||
|
|
||
| /** | ||
| * See #2397: the synthesizer player still plays the count-in. | ||
| */ | ||
| it('count-in-playback-synthesizer', () => { | ||
| const score = ScoreLoader.loadAlphaTex(` | ||
| . | ||
| C4 * 4 | ||
| `); | ||
|
|
||
| const midi = new MidiFile(); | ||
| const handler = new AlphaSynthMidiFileHandler(midi); | ||
| const generator = new MidiFileGenerator(score, new Settings(), handler); | ||
| generator.generate(); | ||
|
|
||
| const synth = new AlphaSynth(new TestOutput(), 500); | ||
| synth.loadMidiFile(midi); | ||
| synth.timePosition = 1000; | ||
| synth.countInVolume = 1; | ||
|
|
||
| expect(synth.play()).toBe(true); | ||
|
|
||
| // the count-in plays from its own start, the song continues at 1000ms after it | ||
| expect(synth.timePosition).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| /** | ||
|
|
@@ -450,7 +535,15 @@ class TestExternalMediaHandler implements IExternalMediaHandler { | |
| class EmptyAudioSynthesizer implements IAudioSampleSynthesizer { | ||
| public masterVolume: number = 0; | ||
| public metronomeVolume: number = 0; | ||
| public outSampleRate: number = 44100; | ||
| private _sampleRateReads: number = 0; | ||
| public get outSampleRate(): number { | ||
| // the sequencer reads this once per fill iteration: fail instead of hanging if it stops making progress | ||
| this._sampleRateReads++; | ||
| if (this._sampleRateReads > 100000) { | ||
| throw new Error('Sequencer is not making progress'); | ||
| } | ||
| return 44100; | ||
| } | ||
| public currentTempo: number = 120; | ||
| public timeSignatureNumerator: number = 4; | ||
| public timeSignatureDenominator: number = 4; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sets the current clock, instead of the main one, to match
fillMidiEventQueueToEndTime.