diff --git a/session_state.db b/session_state.db index 90ad56b..313cf09 100644 Binary files a/session_state.db and b/session_state.db differ diff --git a/src/audio/Engine.ts b/src/audio/Engine.ts index af0d885..86d0a5b 100644 --- a/src/audio/Engine.ts +++ b/src/audio/Engine.ts @@ -218,6 +218,7 @@ export class AudioEngine { const freq = NOTE_FREQ_MAP[note]; if (!freq) return; + this.stopBassNote(note, time); const osc = this.audioContext.createOscillator(); const gain = this.audioContext.createGain(); osc.type = 'sine'; diff --git a/src/hooks/useDrumMachine.ts b/src/hooks/useDrumMachine.ts index 9c35889..eb72f44 100644 --- a/src/hooks/useDrumMachine.ts +++ b/src/hooks/useDrumMachine.ts @@ -12,6 +12,7 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) => } = useStore(); const timerRef = useRef(null); + const wasPlayingRef = useRef(false); const lookahead = 25.0; const scheduleAheadTime = 0.1; const nextNoteTimeRef = useRef(0.0); @@ -161,8 +162,8 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) => const triggerBassNote = async (note: string) => { await audioEngine.init(); audioEngine.startBassNote(note, audioEngine.getCurrentTime()); - // Stop after 1s for preview - setTimeout(() => audioEngine.stopBassNote(note, audioEngine.getCurrentTime()), 1000); + // Stop after 500ms for preview + setTimeout(() => audioEngine.stopBassNote(note, audioEngine.getCurrentTime()), 500); }; const exportBeat = () => { @@ -199,9 +200,13 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) => scheduler(); } else { if (timerRef.current) clearTimeout(timerRef.current); - audioEngine.stopAllBassNotes(); + // Only stop all notes if we just switched from playing to stopped + if (wasPlayingRef.current) { + audioEngine.stopAllBassNotes(); + } setCurrentStep(null); } + wasPlayingRef.current = isPlaying; return () => { if (timerRef.current) clearTimeout(timerRef.current); };