melhorando a leitura de projetos no mmpCreator
Deploy / Deploy (push) Successful in 2m16s Details

This commit is contained in:
JotaChina 2025-12-25 16:45:09 -03:00
parent 73a61a96f4
commit f9ae0d92a8
1 changed files with 43 additions and 13 deletions

View File

@ -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);
try {
track.instrument.triggerAttackRelease(noteName, durSec, t2, vel);
} catch {
try {
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]) {
// 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) {
try {
track.instrument.triggerAttackRelease("C5", "16n", time);
} catch {}
}
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");