diff --git a/creation.html b/creation.html
index e0fb209b..c7280a46 100755
--- a/creation.html
+++ b/creation.html
@@ -643,34 +643,32 @@
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) => {
// --- A. Nome do Instrumento ---
const nameRow = document.createElement("div");
nameRow.className = "instrument-row";
- const label = document.createElement("span");
- label.innerText =
+ // 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");
+ label.innerText = displayLabel;
nameRow.appendChild(label);
nameContainer.appendChild(nameRow);
- // --- B. Steps (Correção Aqui) ---
+ // --- B. Steps (Lógica Corrigida) ---
let stepData = [];
- if (inst.patterns && inst.patterns.length > 0) {
- // Tenta encontrar um pattern que tenha pelo menos uma nota 'true'
- 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;
- }
+ // Verifica se o instrumento tem patterns e se o índice atual existe
+ if (inst.patterns && inst.patterns[currentPatternIndex]) {
+ stepData = inst.patterns[currentPatternIndex].steps;
} else {
+ // Se não existir pattern para este índice neste instrumento, cria vazio
stepData = Array(16).fill(false);
}
@@ -687,11 +685,12 @@
if (newState) stepBtn.classList.add("active");
else stepBtn.classList.remove("active");
- // Atualiza na memória (atenção: idealmente atualize todos os patterns desse inst)
- if (inst.patterns && inst.patterns.length > 0) {
- inst.patterns.forEach((p) => {
- if (p.steps[index] !== undefined) p.steps[index] = newState;
- });
+ // Atualiza o estado na memória no índice CORRETO
+ if (inst.patterns && inst.patterns[currentPatternIndex]) {
+ inst.patterns[currentPatternIndex].steps[index] = newState;
+ } else if (inst.patterns) {
+ // 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");
}
});
@@ -701,7 +700,6 @@
stepsContainer.appendChild(stepsRow);
});
};
-
// --- FUNÇÃO GLOBAL PARA ABRIR O PIANO ROLL (JÁ EXISTENTE) ---
window.openPianoRoll = function (trackId) {
const track = appState.pattern.tracks.find((t) => t.id === trackId);