From d619e533aae8f65f4bdc6feba521682a5d9eff45 Mon Sep 17 00:00:00 2001 From: JotaChina Date: Thu, 25 Dec 2025 12:26:01 -0300 Subject: [PATCH] melhorando a leitura de projetos no mmpCreator --- assets/js/creations/file.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/assets/js/creations/file.js b/assets/js/creations/file.js index 4d5590ed..4feb0957 100755 --- a/assets/js/creations/file.js +++ b/assets/js/creations/file.js @@ -45,12 +45,12 @@ function resolveSamplePath(sampleName, pathMap) { return null; } -// helper: LMMS ticks -> seconds (1 beat = 192 ticks) -function ticksToSeconds(ticks, bpm) { - seconds = (ticks / 12) * getSecondsPerStep() +function ticksToSeconds(ticks) { + const seconds = (ticks / TICKS_PER_STEP) * getSecondsPerStep(); return seconds; } + export async function parseBeatIndexJson(data) { resetProjectState(); initializeAudioContext(); @@ -263,9 +263,9 @@ function parseInstrumentNode( const patternSteps = parseInt(patternNode.getAttribute("steps"), 10) || 16; const steps = new Array(patternSteps).fill(false); const notes = []; - - // Constante de conversão LMMS (192 ticks = 1 beat, 48 ticks = 1 step) - const ticksPerStep = 48; + // No XML base: 1 compasso (bar) = 192 ticks em 4/4, + // então 1 beat = 48 ticks e 1 step (1/16) = 12 ticks. + const ticksPerStep = 12; patternNode.querySelectorAll("note").forEach((noteNode) => { const pos = parseInt(noteNode.getAttribute("pos"), 10); @@ -277,14 +277,9 @@ function parseInstrumentNode( notes.push({ pos, len, key, vol, pan }); // Calcula qual step acender - // Nota: B/B Editor no LMMS geralmente usa notas de len=48. - // Se a nota for longa, isso marca apenas o step de início. - const stepIndex = Math.round(pos / ticksPerStep); - - if (stepIndex >= 0 && stepIndex < patternSteps) { - steps[stepIndex] = true; - } - }); + const stepIndex = Math.floor(pos / ticksPerStep); + if (stepIndex < patternSteps) steps[stepIndex] = true; + }); return { name: patternName, @@ -608,7 +603,7 @@ export function syncPatternStateToServer() { function createTrackXml(track) { if (!track.patterns || track.patterns.length === 0) return ""; - const ticksPerStep = 48; // Sincronizado com o parsing + const ticksPerStep = 12; // 1 step (1/16) no LMMS = 12 ticks (com bar=192 em 4/4) const lmmsVolume = Math.round(track.volume * 100); const lmmsPan = Math.round(track.pan * 100);