tirando pattern padrão quando não estamos editando alguma
Deploy / Deploy (push) Successful in 1m55s Details

This commit is contained in:
JotaChina 2025-12-27 21:14:05 -03:00
parent f883ebfccf
commit 338d13d801
3 changed files with 38 additions and 28 deletions

View File

@ -238,22 +238,26 @@ document.addEventListener("DOMContentLoaded", () => {
// Adiciona o novo "ouvinte" de evento para o seletor de pattern // Adiciona o novo "ouvinte" de evento para o seletor de pattern
globalPatternSelector?.addEventListener("change", () => { globalPatternSelector?.addEventListener("change", () => {
// Pega o novo índice (ex: 0, 1, 2...) do seletor const raw = globalPatternSelector.value;
const newPatternIndex = parseInt(globalPatternSelector.value, 10);
// --- CORREÇÃO DE LÓGICA (não precisamos mais do activeTrackId) --- // ✅ limpar seleção
// A ação agora é global e afeta TODAS as tracks. if (raw === "") {
if (isNaN(newPatternIndex)) { sendAction({ type: "SET_ACTIVE_PATTERN", patternIndex: null });
console.warn("Não é possível trocar pattern: índice inválido."); return;
return; }
}
// Envia a ação para todos (incluindo você) const newPatternIndex = parseInt(raw, 10);
sendAction({ if (Number.isNaN(newPatternIndex)) {
type: "SET_ACTIVE_PATTERN", console.warn("Não é possível trocar pattern: índice inválido.");
patternIndex: newPatternIndex, return;
}); }
sendAction({
type: "SET_ACTIVE_PATTERN",
patternIndex: newPatternIndex,
}); });
});
// ================================================================= // =================================================================
// 👇 INÍCIO DA CORREÇÃO (Botão de Sincronia - Agora envia Ação) // 👇 INÍCIO DA CORREÇÃO (Botão de Sincronia - Agora envia Ação)

View File

@ -348,7 +348,7 @@ export function updateGlobalPatternSelector() {
const isFocused = !!appState.pattern.focusedBasslineId; const isFocused = !!appState.pattern.focusedBasslineId;
// track de referência que tenha patterns // qualquer instrumento serve como referência de nomes/quantidade de patterns
const referenceTrack = (appState.pattern.tracks || []).find( const referenceTrack = (appState.pattern.tracks || []).find(
(t) => t.type !== "bassline" && Array.isArray(t.patterns) && t.patterns.length > 0 (t) => t.type !== "bassline" && Array.isArray(t.patterns) && t.patterns.length > 0
); );
@ -363,16 +363,12 @@ export function updateGlobalPatternSelector() {
return; return;
} }
const hasSelection = Number.isInteger(appState.pattern.activePatternIndex); // ✅ fora do foco: permite "limpar seleção"
if (!isFocused) {
// ✅ placeholder só quando NÃO está focado e NÃO tem seleção const noneOpt = document.createElement("option");
if (!isFocused && !hasSelection) { noneOpt.value = "";
const ph = document.createElement("option"); noneOpt.textContent = "Selecione uma pattern";
ph.value = ""; sel.appendChild(noneOpt);
ph.textContent = "Selecione uma pattern";
ph.disabled = true;
ph.selected = true;
sel.appendChild(ph);
} }
referenceTrack.patterns.forEach((p, idx) => { referenceTrack.patterns.forEach((p, idx) => {
@ -382,13 +378,14 @@ export function updateGlobalPatternSelector() {
sel.appendChild(opt); sel.appendChild(opt);
}); });
// Define seleção atual
const idx = appState.pattern.activePatternIndex;
if (isFocused) { if (isFocused) {
// em foco: se não tiver índice ainda, cai pra 0 sel.value = String(Number.isInteger(idx) ? idx : 0);
sel.value = String(appState.pattern.activePatternIndex ?? 0);
} else { } else {
// fora de foco: só seta valor se realmente existir seleção sel.value = Number.isInteger(idx) ? String(idx) : "";
sel.value = hasSelection ? String(appState.pattern.activePatternIndex) : "";
} }
sel.disabled = false; sel.disabled = false;
} }

View File

@ -1356,6 +1356,15 @@ async function handleActionBroadcast(action) {
// índice que veio do seletor global // índice que veio do seletor global
const { patternIndex } = action; const { patternIndex } = action;
// ✅ limpar seleção
if (!Number.isInteger(patternIndex)) {
appState.pattern.activePatternIndex = null;
appState.pattern.tracks.forEach((t) => (t.activePatternIndex = null));
renderAll();
saveStateToSession();
break;
}
// fonte de verdade global (muitos pontos da UI usam isso) // fonte de verdade global (muitos pontos da UI usam isso)
appState.pattern.activePatternIndex = patternIndex; appState.pattern.activePatternIndex = patternIndex;