adicionando instrumentos no editor de patterns
Deploy / Deploy (push) Successful in 1m56s Details

This commit is contained in:
JotaChina 2025-12-27 20:47:04 -03:00
parent 14c2a3b658
commit 68101fab2e
2 changed files with 43 additions and 40 deletions

View File

@ -660,7 +660,7 @@ export async function parseMmpContent(xmlString) {
const firstInst = newTracks.find((t) => t.type !== "bassline");
appState.pattern.activeTrackId = firstInst ? firstInst.id : null;
appState.pattern.activePatternIndex = 0;
appState.pattern.activePatternIndex = null;
loadStateFromSession();

View File

@ -308,49 +308,52 @@ export function updateStepUI(trackIndex, patternIndex, stepIndex, isActive) {
// Atualiza o dropdown de patterns na toolbar
export function updateGlobalPatternSelector() {
const globalPatternSelector = document.getElementById('global-pattern-selector');
if (!globalPatternSelector) return;
const sel = document.getElementById("global-pattern-selector");
if (!sel) return;
const activeTrackId = appState.pattern.activeTrackId;
const activeTrack = appState.pattern.tracks.find(t => t.id === activeTrackId);
const isFocused = !!appState.pattern.focusedBasslineId;
// Tenta pegar a track ativa ou a primeira visível como referência de patterns
const isFocused = !!appState.pattern.focusedBasslineId;
const referenceTrack = isFocused
? appState.pattern.tracks.find(t => t.type !== "bassline" && t.parentBasslineId !== null)
: (activeTrack || appState.pattern.tracks.find(t => !t.isMuted && t.type !== "bassline"));
// track de referência que tenha patterns
const referenceTrack = (appState.pattern.tracks || []).find(
(t) => t.type !== "bassline" && Array.isArray(t.patterns) && t.patterns.length > 0
);
globalPatternSelector.innerHTML = '';
sel.innerHTML = "";
if (referenceTrack && referenceTrack.patterns && referenceTrack.patterns.length > 0) {
const isFocused = !!appState.pattern.focusedBasslineId;
const hasSelection = Number.isInteger(appState.pattern.activePatternIndex);
if (!referenceTrack) {
const opt = document.createElement("option");
opt.textContent = "Sem patterns";
sel.appendChild(opt);
sel.disabled = true;
return;
}
globalPatternSelector.innerHTML = '';
const hasSelection = Number.isInteger(appState.pattern.activePatternIndex);
if (!isFocused && !hasSelection) {
const ph = document.createElement('option');
ph.value = '';
ph.textContent = 'Selecione uma pattern…';
ph.disabled = true;
ph.selected = true;
globalPatternSelector.appendChild(ph);
}
// ✅ 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);
}
referenceTrack.patterns.forEach((pattern, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = pattern.name;
globalPatternSelector.appendChild(option);
});
referenceTrack.patterns.forEach((p, idx) => {
const opt = document.createElement("option");
opt.value = String(idx);
opt.textContent = p.name || `Pattern ${idx + 1}`;
sel.appendChild(opt);
});
// ✅ em vez de forçar 0
globalPatternSelector.value = hasSelection ? String(appState.pattern.activePatternIndex) : '';
globalPatternSelector.disabled = false;
} else {
const option = document.createElement('option');
option.textContent = 'Sem patterns';
globalPatternSelector.appendChild(option);
globalPatternSelector.disabled = true;
}
if (isFocused) {
// em foco: se não tiver índice ainda, cai pra 0
sel.value = String(appState.pattern.activePatternIndex ?? 0);
} else {
// fora de foco: só seta valor se realmente existir seleção
sel.value = hasSelection ? String(appState.pattern.activePatternIndex) : "";
}
sel.disabled = false;
}