Arrumando botões de volume e pan, criação de novos compassos.
This commit is contained in:
1 parent
e776a830c8
commit
e10621da17
8 files changed
+411
-291
No files matched your search
@@ -42,44 +42,41 @@ export function playMetronomeSound(isDownbeat) {
|
||||
oscillator.stop(audioContext.currentTime + 0.05);
|
||||
}
|
||||
|
||||
// (ALTERADO) Função reescrita para usar AudioBuffers pré-carregados
|
||||
// Função otimizada para usar AudioBuffers
|
||||
export function playSample(filePath, trackId) {
|
||||
initializeAudioContext();
|
||||
if (!filePath) return;
|
||||
|
||||
const track = trackId ? appState.tracks.find((t) => t.id == trackId) : null;
|
||||
|
||||
// Se a função for chamada sem um ID de track (ex: clique no browser de samples),
|
||||
// usa o método antigo como fallback para uma prévia rápida.
|
||||
// Se for uma prévia (sem trilha), usa o método antigo e rápido
|
||||
if (!track) {
|
||||
const audio = new Audio(filePath);
|
||||
audio.play();
|
||||
return;
|
||||
}
|
||||
|
||||
// Se a track não tiver o buffer de áudio pronto, avisa no console e não toca.
|
||||
|
||||
// Se a trilha não tiver o buffer carregado, não toca
|
||||
if (!track.audioBuffer) {
|
||||
console.warn(`Buffer para a track ${track.name} ainda não carregado.`);
|
||||
console.warn(`Buffer para a trilha ${track.name} ainda não carregado.`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Cria uma fonte de áudio leve (BufferSource)
|
||||
// Cria uma fonte de áudio leve a partir do buffer
|
||||
const source = audioContext.createBufferSource();
|
||||
// 2. Conecta o buffer de áudio já decodificado
|
||||
source.buffer = track.audioBuffer;
|
||||
|
||||
// 3. Conecta na cadeia de áudio da track (respeitando volume e pan)
|
||||
// Conecta na cadeia de áudio da trilha (respeitando volume e pan)
|
||||
if (track.gainNode) {
|
||||
source.connect(track.gainNode);
|
||||
} else {
|
||||
source.connect(mainGainNode); // Fallback
|
||||
}
|
||||
|
||||
// 4. Toca o som imediatamente
|
||||
// Toca o som imediatamente
|
||||
source.start(0);
|
||||
}
|
||||
|
||||
|
||||
function tick() {
|
||||
const totalSteps = getTotalSteps();
|
||||
if (totalSteps === 0) {
|
||||
|
||||
Reference in new issue
Block a user