diff --git a/creation.html b/creation.html
index c7280a46..e0fb209b 100755
--- a/creation.html
+++ b/creation.html
@@ -643,32 +643,34 @@
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";
- // 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;
+ label.innerText =
+ inst.instrument_name || inst.plugin_name || "Sem Nome";
nameRow.appendChild(label);
nameContainer.appendChild(nameRow);
- // --- B. Steps (Lógica Corrigida) ---
+ // --- B. Steps (Correção Aqui) ---
let stepData = [];
- // Verifica se o instrumento tem patterns e se o índice atual existe
- if (inst.patterns && inst.patterns[currentPatternIndex]) {
- stepData = inst.patterns[currentPatternIndex].steps;
+ 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;
+ }
} else {
- // Se não existir pattern para este índice neste instrumento, cria vazio
stepData = Array(16).fill(false);
}
@@ -685,12 +687,11 @@
if (newState) stepBtn.classList.add("active");
else stepBtn.classList.remove("active");
- // 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");
+ // 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;
+ });
}
});
@@ -700,6 +701,7 @@
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);