Bass line Note Trigger Sound fixed

This commit is contained in:
AG
2025-12-20 20:48:15 +02:00
parent 26cedfca61
commit 13029f4277
3 changed files with 9 additions and 3 deletions

Binary file not shown.

View File

@@ -218,6 +218,7 @@ export class AudioEngine {
const freq = NOTE_FREQ_MAP[note]; const freq = NOTE_FREQ_MAP[note];
if (!freq) return; if (!freq) return;
this.stopBassNote(note, time);
const osc = this.audioContext.createOscillator(); const osc = this.audioContext.createOscillator();
const gain = this.audioContext.createGain(); const gain = this.audioContext.createGain();
osc.type = 'sine'; osc.type = 'sine';

View File

@@ -12,6 +12,7 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) =>
} = useStore(); } = useStore();
const timerRef = useRef<number | null>(null); const timerRef = useRef<number | null>(null);
const wasPlayingRef = useRef<boolean>(false);
const lookahead = 25.0; const lookahead = 25.0;
const scheduleAheadTime = 0.1; const scheduleAheadTime = 0.1;
const nextNoteTimeRef = useRef<number>(0.0); const nextNoteTimeRef = useRef<number>(0.0);
@@ -161,8 +162,8 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) =>
const triggerBassNote = async (note: string) => { const triggerBassNote = async (note: string) => {
await audioEngine.init(); await audioEngine.init();
audioEngine.startBassNote(note, audioEngine.getCurrentTime()); audioEngine.startBassNote(note, audioEngine.getCurrentTime());
// Stop after 1s for preview // Stop after 500ms for preview
setTimeout(() => audioEngine.stopBassNote(note, audioEngine.getCurrentTime()), 1000); setTimeout(() => audioEngine.stopBassNote(note, audioEngine.getCurrentTime()), 500);
}; };
const exportBeat = () => { const exportBeat = () => {
@@ -199,9 +200,13 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) =>
scheduler(); scheduler();
} else { } else {
if (timerRef.current) clearTimeout(timerRef.current); if (timerRef.current) clearTimeout(timerRef.current);
// Only stop all notes if we just switched from playing to stopped
if (wasPlayingRef.current) {
audioEngine.stopAllBassNotes(); audioEngine.stopAllBassNotes();
}
setCurrentStep(null); setCurrentStep(null);
} }
wasPlayingRef.current = isPlaying;
return () => { return () => {
if (timerRef.current) clearTimeout(timerRef.current); if (timerRef.current) clearTimeout(timerRef.current);
}; };