Bass line Note Trigger Sound fixed
This commit is contained in:
BIN
session_state.db
BIN
session_state.db
Binary file not shown.
@@ -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';
|
||||
|
||||
@@ -12,6 +12,7 @@ export const useDrumMachine = (_lastMessage: any, sendMessage: (message: any) =>
|
||||
} = useStore();
|
||||
|
||||
const timerRef = useRef<number | null>(null);
|
||||
const wasPlayingRef = useRef<boolean>(false);
|
||||
const lookahead = 25.0;
|
||||
const scheduleAheadTime = 0.1;
|
||||
const nextNoteTimeRef = useRef<number>(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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user