melhorando a leitura de projetos no mmpCreator
Deploy / Deploy (push) Successful in 2m3s Details

This commit is contained in:
JotaChina 2025-12-22 18:52:21 -03:00
parent f7781827b8
commit 9cf3c585fe
1 changed files with 22 additions and 20 deletions

View File

@ -643,32 +643,34 @@
return; return;
} }
// --- CORREÇÃO: Usar o índice global ativo para manter a sincronia ---
// Se não houver índice definido no estado, usa 0 (primeiro pattern)
const currentPatternIndex = appState.pattern.activePatternIndex || 0;
instruments.forEach((inst) => { instruments.forEach((inst) => {
// --- A. Nome do Instrumento --- // --- A. Nome do Instrumento ---
const nameRow = document.createElement("div"); const nameRow = document.createElement("div");
nameRow.className = "instrument-row"; nameRow.className = "instrument-row";
// Exibe o nome do pattern também para debug (opcional)
const displayLabel =
inst.instrument_name || inst.plugin_name || "Sem Nome";
const label = document.createElement("span"); const label = document.createElement("span");
label.innerText = displayLabel; label.innerText =
inst.instrument_name || inst.plugin_name || "Sem Nome";
nameRow.appendChild(label); nameRow.appendChild(label);
nameContainer.appendChild(nameRow); nameContainer.appendChild(nameRow);
// --- B. Steps (Lógica Corrigida) --- // --- B. Steps (Correção Aqui) ---
let stepData = []; let stepData = [];
// Verifica se o instrumento tem patterns e se o índice atual existe if (inst.patterns && inst.patterns.length > 0) {
if (inst.patterns && inst.patterns[currentPatternIndex]) { // Tenta encontrar um pattern que tenha pelo menos uma nota 'true'
stepData = inst.patterns[currentPatternIndex].steps; const activePattern = inst.patterns.find((p) =>
p.steps.some((s) => s === true)
);
if (activePattern) {
// Se achou um com notas, usa ele
stepData = activePattern.steps;
} else {
// Se todos estão vazios, usa o primeiro mesmo
stepData = inst.patterns[0].steps;
}
} else { } else {
// Se não existir pattern para este índice neste instrumento, cria vazio
stepData = Array(16).fill(false); stepData = Array(16).fill(false);
} }
@ -685,12 +687,11 @@
if (newState) stepBtn.classList.add("active"); if (newState) stepBtn.classList.add("active");
else stepBtn.classList.remove("active"); else stepBtn.classList.remove("active");
// Atualiza o estado na memória no índice CORRETO // Atualiza na memória (atenção: idealmente atualize todos os patterns desse inst)
if (inst.patterns && inst.patterns[currentPatternIndex]) { if (inst.patterns && inst.patterns.length > 0) {
inst.patterns[currentPatternIndex].steps[index] = newState; inst.patterns.forEach((p) => {
} else if (inst.patterns) { if (p.steps[index] !== undefined) p.steps[index] = newState;
// Caso extremo: o pattern ainda não existe, teríamos que criar (não implementado aqui para brevidade) });
console.warn("Pattern index não existe para este instrumento");
} }
}); });
@ -700,6 +701,7 @@
stepsContainer.appendChild(stepsRow); stepsContainer.appendChild(stepsRow);
}); });
}; };
// --- FUNÇÃO GLOBAL PARA ABRIR O PIANO ROLL (JÁ EXISTENTE) --- // --- FUNÇÃO GLOBAL PARA ABRIR O PIANO ROLL (JÁ EXISTENTE) ---
window.openPianoRoll = function (trackId) { window.openPianoRoll = function (trackId) {
const track = appState.pattern.tracks.find((t) => t.id === trackId); const track = appState.pattern.tracks.find((t) => t.id === trackId);