patterns funcionais, alguns nomes estão ao contrário. mas o conteúdo agora está correto e fidedigno ao projeto.

This commit is contained in:
JotaChina committed 2025-10-03 18:02:36 -03:00
1 parent 1174d71518
commit 6212750429
5 files changed
+365 -214

No files matched your search

+31 -15
View File
@@ -22,7 +22,6 @@ export function initializeAudioContext() {
mainGainNode = audioContext.createGain();
masterPannerNode = audioContext.createStereoPanner();
// Roteamento: Gain Master -> Panner Master -> Saída
mainGainNode.connect(masterPannerNode);
masterPannerNode.connect(audioContext.destination);
}
@@ -75,17 +74,13 @@ export function playSample(filePath, trackId) {
const track = trackId ? appState.tracks.find((t) => t.id == trackId) : null;
if (!track) {
if (!track || !track.audioBuffer) {
// Se não houver buffer (ex: preview do sample browser), toca como um áudio simples
const audio = new Audio(filePath);
audio.play();
return;
}
if (!track.audioBuffer) {
console.warn(`Buffer para a trilha ${track.name} ainda não carregado.`);
return;
}
const source = audioContext.createBufferSource();
source.buffer = track.audioBuffer;
@@ -124,11 +119,20 @@ function tick() {
}
}
// --- INÍCIO DA CORREÇÃO ---
appState.tracks.forEach((track) => {
if (track.steps[appState.currentStep] && track.samplePath) {
// 1. Verifica se a faixa tem patterns
if (!track.patterns || track.patterns.length === 0) return;
// 2. Pega o pattern que está ativo para esta faixa
const activePattern = track.patterns[track.activePatternIndex];
// 3. Verifica se o pattern existe e se o step atual está ativo NELE
if (activePattern && activePattern.steps[appState.currentStep] && track.samplePath) {
playSample(track.samplePath, track.id);
}
});
// --- FIM DA CORREÇÃO ---
highlightStep(appState.currentStep, true);
appState.currentStep = (appState.currentStep + 1) % totalSteps;
@@ -151,31 +155,43 @@ export function startPlayback() {
}
export function stopPlayback() {
clearInterval(appState.playbackIntervalId);
if(appState.playbackIntervalId) {
clearInterval(appState.playbackIntervalId);
}
appState.playbackIntervalId = null;
appState.isPlaying = false;
highlightStep(appState.currentStep - 1, false);
highlightStep(appState.currentStep, false); // Garante que o último step "playing" seja limpo
appState.currentStep = 0;
if (timerDisplay) timerDisplay.textContent = '00:00:00';
document.getElementById("play-btn").classList.remove("fa-pause");
document.getElementById("play-btn").classList.add("fa-play");
const playBtn = document.getElementById("play-btn");
if (playBtn) {
playBtn.classList.remove("fa-pause");
playBtn.classList.add("fa-play");
}
}
export function rewindPlayback() {
const previousStep = appState.currentStep;
appState.currentStep = 0;
if (!appState.isPlaying) {
if (timerDisplay) timerDisplay.textContent = '00:00:00';
document
.querySelectorAll(".step.playing")
.forEach((s) => s.classList.remove("playing"));
highlightStep(previousStep - 1, false);
highlightStep(previousStep, false);
}
}
export function togglePlayback() {
initializeAudioContext(); // Garante que o contexto de áudio foi iniciado por um gesto do usuário
if (appState.isPlaying) {
stopPlayback();
// Pausa a reprodução, mas não reseta
clearInterval(appState.playbackIntervalId);
appState.playbackIntervalId = null;
appState.isPlaying = false;
document.getElementById("play-btn").classList.remove("fa-pause");
document.getElementById("play-btn").classList.add("fa-play");
} else {
startPlayback();
}