corrigindo loop interno ao esticar patterns na playlist
Deploy / Deploy (push) Successful in 2m25s Details

This commit is contained in:
JotaChina 2025-12-27 09:15:21 -03:00
parent bf1c0e02a0
commit cca6100b96
1 changed files with 18 additions and 8 deletions

View File

@ -641,34 +641,44 @@ export function startSongPatternPlaybackOnTransport() {
continue; // 👈 importante: não cair na lógica abaixo continue; // 👈 importante: não cair na lógica abaixo
} }
// ✅ 1b) SAMPLER com piano roll (notes) — respeita oitava/pitch via playbackRate // ✅ 1b) SAMPLER com piano roll (notes) — loop interno ao esticar o clip
if ( if (
track.type === "sampler" && track.type === "sampler" &&
track.buffer && track.buffer &&
Array.isArray(patt.notes) && Array.isArray(patt.notes) &&
patt.notes.length > 0 patt.notes.length > 0
) { ) {
const stepStartTick = hit.localStep * LMMS_TICKS_PER_STEP; // 👇 chave do loop interno: usa tickInPattern (já calculado acima)
const stepStartTick = tickInPattern;
const stepEndTick = stepStartTick + LMMS_TICKS_PER_STEP; const stepEndTick = stepStartTick + LMMS_TICKS_PER_STEP;
for (const n of patt.notes) { for (const n of patt.notes) {
const nPos = Number(n.pos) || 0; const nPos = Number(n.pos) || 0;
if (nPos < stepStartTick || nPos >= stepEndTick) continue;
const offsetTicks = nPos - stepStartTick; // janela do step, tratando “wrap” no fim do pattern
const wraps = stepEndTick > pattLenTicks;
const inWindow = wraps
? (nPos >= stepStartTick || nPos < (stepEndTick - pattLenTicks))
: (nPos >= stepStartTick && nPos < stepEndTick);
if (!inWindow) continue;
const offsetTicks = wraps && nPos < stepStartTick
? (pattLenTicks - stepStartTick) + nPos
: nPos - stepStartTick;
const t2 = time + ticksToSec(offsetTicks, stepIntervalSec); const t2 = time + ticksToSec(offsetTicks, stepIntervalSec);
const lenTicks = Math.max(1, Number(n.len) || LMMS_TICKS_PER_STEP); const lenTicks = Math.max(1, Number(n.len) || LMMS_TICKS_PER_STEP);
const durSec = Math.max(0.01, ticksToSec(lenTicks, stepIntervalSec)); const durSec = Math.max(0.01, ticksToSec(lenTicks, stepIntervalSec));
playSamplerNoteAtTime(track, n.key, t2, durSec); playSamplerNoteAtTime(track, Number(n.key) || 0, t2, durSec);
} }
continue; // 👈 importante: não cair na lógica de steps continue; // mantém: não cair na lógica de steps
} }
// ✅ 2) Lógica de STEP (sampler / plugin sem notes)
// ✅ 2) Lógica antiga de STEP (sampler / plugin sem notes)
if (!patt.steps) continue; if (!patt.steps) continue;
if (patt.steps[stepInPattern]) { if (patt.steps[stepInPattern]) {