fix: missing count-in when recording with loop mode on

This commit is contained in:
Xiaohan-Tian
2026-05-01 14:17:29 -07:00
parent adb2345693
commit 043e90b1d7
5 changed files with 85 additions and 13 deletions
@@ -97,4 +97,19 @@ describe('KGAudioInterface preroll playback', () => {
expect(MockTransport.stop).toHaveBeenCalledTimes(1)
expect(audio.getTransportPosition()).toBe(0)
})
it('allows a first-pass start before the loop start when explicitly requested', () => {
const project = createMockProject({
bpm: 120,
timeSignature: { numerator: 4, denominator: 4 },
tracks: [],
})
project.setIsLooping(true)
project.setLoopingRange([4, 7])
const audio = KGAudioInterface.instance()
audio.preparePlayback(project, 12, { allowStartBeforeLoopStart: true })
expect(MockTransport.position).toBe(6)
})
})
+6 -2
View File
@@ -12,6 +12,10 @@ import { KGCore } from '../KGCore';
import { ConfigManager } from '../config/ConfigManager';
import { KGMetronome } from './KGMetronome';
interface PreparePlaybackOptions {
allowStartBeforeLoopStart?: boolean;
}
/**
* KGAudioInterface - Audio engine interface for the DAW
* Implements the singleton pattern for global audio management
@@ -391,7 +395,7 @@ export class KGAudioInterface {
/**
* Prepare playback by scheduling all MIDI events
*/
public preparePlayback(project: KGProject, startPosition: number): void {
public preparePlayback(project: KGProject, startPosition: number, options?: PreparePlaybackOptions): void {
// Clear any existing scheduled events
this.clearScheduledEvents();
this.clearDelayedTransportStart();
@@ -437,7 +441,7 @@ export class KGAudioInterface {
console.log(`Loop mode enabled: bars [${startBar}, ${endBar}], beats [${scheduleStartBeat}, ${scheduleEndBeat}]`);
// Adjust start position to loop start if before loop range
if (startPosition < scheduleStartBeat) {
if (startPosition < scheduleStartBeat && !options?.allowStartBeforeLoopStart) {
startPosition = scheduleStartBeat;
}
} else {