From cca6100b96ae0d179decbc461e3451733c9156f8 Mon Sep 17 00:00:00 2001 From: JotaChina Date: Sat, 27 Dec 2025 09:15:21 -0300 Subject: [PATCH] corrigindo loop interno ao esticar patterns na playlist --- assets/js/creations/pattern/pattern_audio.js | 26 ++++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/assets/js/creations/pattern/pattern_audio.js b/assets/js/creations/pattern/pattern_audio.js index 0f2a4f97..f64abbd3 100755 --- a/assets/js/creations/pattern/pattern_audio.js +++ b/assets/js/creations/pattern/pattern_audio.js @@ -641,34 +641,44 @@ export function startSongPatternPlaybackOnTransport() { 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 ( track.type === "sampler" && track.buffer && Array.isArray(patt.notes) && 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; for (const n of patt.notes) { 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 lenTicks = Math.max(1, Number(n.len) || LMMS_TICKS_PER_STEP); 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 antiga de STEP (sampler / plugin sem notes) + // ✅ 2) LĂłgica de STEP (sampler / plugin sem notes) if (!patt.steps) continue; if (patt.steps[stepInPattern]) {