criação de novas patterns de composição, com indice correto, nos projetos

This commit is contained in:
JotaChina committed 2025-12-27 19:34:55 -03:00
1 parent 0383274a50
commit 86f64918a2
2 files changed
+40 -15

No files matched your search

+23 -1
View File
@@ -729,7 +729,29 @@ async function handleActionBroadcast(action) {
const nonBass = (appState.pattern.tracks || []).filter(t => t.type !== "bassline");
const currentCount = nonBass.reduce((m, t) => Math.max(m, t.patterns?.length ?? 0), 0);
const idx = desiredIndex != null ? desiredIndex : currentCount;
// Próximo índice livre (fim da lista)
const maxFromNonBass = nonBass.reduce(
(m, t) => Math.max(m, (t.patterns?.length || 0) - 1),
-1
);
const maxFromBass = (appState.pattern.tracks || [])
.filter(t => t.type === "bassline" && Number.isFinite(Number(t.patternIndex)))
.reduce((m, t) => Math.max(m, Number(t.patternIndex)), -1);
const nextFree = Math.max(maxFromNonBass, maxFromBass) + 1;
// tenta usar o índice pedido, mas só se ele ainda não existe
let idx = desiredIndex != null ? desiredIndex : nextFree;
const idxAlreadyExists =
idx <= maxFromNonBass ||
(appState.pattern.tracks || []).some(
t => t.type === "bassline" && Number(t.patternIndex) === idx
);
if (idxAlreadyExists) idx = nextFree;
const finalName = String(action.name || `Pattern ${idx + 1}`).trim();
// 1) cria patterns vazios em TODAS as tracks (respeita bars-input)