tirando pattern padrão quando não estamos editando alguma
Deploy / Deploy (push) Successful in 1m55s
Details
Deploy / Deploy (push) Successful in 1m55s
Details
This commit is contained in:
parent
f883ebfccf
commit
338d13d801
|
|
@ -238,23 +238,27 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
|
||||
// Adiciona o novo "ouvinte" de evento para o seletor de pattern
|
||||
globalPatternSelector?.addEventListener("change", () => {
|
||||
// Pega o novo índice (ex: 0, 1, 2...) do seletor
|
||||
const newPatternIndex = parseInt(globalPatternSelector.value, 10);
|
||||
const raw = globalPatternSelector.value;
|
||||
|
||||
// --- CORREÇÃO DE LÓGICA (não precisamos mais do activeTrackId) ---
|
||||
// A ação agora é global e afeta TODAS as tracks.
|
||||
if (isNaN(newPatternIndex)) {
|
||||
// ✅ limpar seleção
|
||||
if (raw === "") {
|
||||
sendAction({ type: "SET_ACTIVE_PATTERN", patternIndex: null });
|
||||
return;
|
||||
}
|
||||
|
||||
const newPatternIndex = parseInt(raw, 10);
|
||||
if (Number.isNaN(newPatternIndex)) {
|
||||
console.warn("Não é possível trocar pattern: índice inválido.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Envia a ação para todos (incluindo você)
|
||||
sendAction({
|
||||
type: "SET_ACTIVE_PATTERN",
|
||||
patternIndex: newPatternIndex,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// =================================================================
|
||||
// 👇 INÍCIO DA CORREÇÃO (Botão de Sincronia - Agora envia Ação)
|
||||
// =================================================================
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ export function updateGlobalPatternSelector() {
|
|||
|
||||
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(
|
||||
(t) => t.type !== "bassline" && Array.isArray(t.patterns) && t.patterns.length > 0
|
||||
);
|
||||
|
|
@ -363,16 +363,12 @@ export function updateGlobalPatternSelector() {
|
|||
return;
|
||||
}
|
||||
|
||||
const hasSelection = Number.isInteger(appState.pattern.activePatternIndex);
|
||||
|
||||
// ✅ placeholder só quando NÃO está focado e NÃO tem seleção
|
||||
if (!isFocused && !hasSelection) {
|
||||
const ph = document.createElement("option");
|
||||
ph.value = "";
|
||||
ph.textContent = "Selecione uma pattern";
|
||||
ph.disabled = true;
|
||||
ph.selected = true;
|
||||
sel.appendChild(ph);
|
||||
// ✅ fora do foco: permite "limpar seleção"
|
||||
if (!isFocused) {
|
||||
const noneOpt = document.createElement("option");
|
||||
noneOpt.value = "";
|
||||
noneOpt.textContent = "Selecione uma pattern";
|
||||
sel.appendChild(noneOpt);
|
||||
}
|
||||
|
||||
referenceTrack.patterns.forEach((p, idx) => {
|
||||
|
|
@ -382,13 +378,14 @@ export function updateGlobalPatternSelector() {
|
|||
sel.appendChild(opt);
|
||||
});
|
||||
|
||||
// Define seleção atual
|
||||
const idx = appState.pattern.activePatternIndex;
|
||||
if (isFocused) {
|
||||
// em foco: se não tiver índice ainda, cai pra 0
|
||||
sel.value = String(appState.pattern.activePatternIndex ?? 0);
|
||||
sel.value = String(Number.isInteger(idx) ? idx : 0);
|
||||
} else {
|
||||
// fora de foco: só seta valor se realmente existir seleção
|
||||
sel.value = hasSelection ? String(appState.pattern.activePatternIndex) : "";
|
||||
sel.value = Number.isInteger(idx) ? String(idx) : "";
|
||||
}
|
||||
|
||||
sel.disabled = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1356,6 +1356,15 @@ async function handleActionBroadcast(action) {
|
|||
// índice que veio do seletor global
|
||||
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)
|
||||
appState.pattern.activePatternIndex = patternIndex;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue