From f9ae0d92a83348f785936f2f8756ed184616d034 Mon Sep 17 00:00:00 2001 From: JotaChina Date: Thu, 25 Dec 2025 16:45:09 -0300 Subject: [PATCH] melhorando a leitura de projetos no mmpCreator --- assets/js/creations/pattern/pattern_audio.js | 56 +++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/assets/js/creations/pattern/pattern_audio.js b/assets/js/creations/pattern/pattern_audio.js index 03515757..fab1c3bf 100755 --- a/assets/js/creations/pattern/pattern_audio.js +++ b/assets/js/creations/pattern/pattern_audio.js @@ -586,26 +586,56 @@ export function startSongPatternPlaybackOnTransport() { for (const hit of activePatternHits) { const patt = track.patterns?.[hit.patternIndex]; - if (!patt?.steps) continue; + if (!patt) continue; + + // ✅ 1) PLUGIN com piano roll (notes) + if ( + track.type === "plugin" && + track.instrument && + Array.isArray(patt.notes) && + patt.notes.length > 0 + ) { + const stepStartTick = hit.localStep * LMMS_TICKS_PER_STEP; + 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; + 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)); + + const vel = Math.max(0, Math.min(1, (Number(n.vol) || 100) / 100)); + const noteName = midiToNoteName(n.key); - if (patt.steps[hit.localStep]) { - // SAMPLER - if (track.type === "sampler" && track.player) { - track.player.restart = true; // baterias precisam retrigger try { - track.player.start(time); - } catch {} - } - // PLUGIN (step sem piano roll) - else if (track.type === "plugin" && track.instrument) { - const hasNotes = patt.notes && patt.notes.length > 0; - if (!hasNotes) { + track.instrument.triggerAttackRelease(noteName, durSec, t2, vel); + } catch { try { - track.instrument.triggerAttackRelease("C5", "16n", time); + track.instrument.triggerAttackRelease(noteName, durSec, t2); } catch {} } } + + continue; // 👈 importante: não cair na lógica de steps abaixo } + + // ✅ 2) Lógica antiga de STEP (sampler / plugin sem notes) + if (!patt.steps) continue; + + if (patt.steps[hit.localStep]) { + if (track.type === "sampler" && track.player) { + track.player.restart = true; + try { track.player.start(time); } catch {} + } else if (track.type === "plugin" && track.instrument) { + // plugin sem piano roll + try { track.instrument.triggerAttackRelease("C5", "16n", time); } catch {} + } + } + } } }, "16n");