From b7d3bc529afbf1daee40fd0305d1b9991235f500 Mon Sep 17 00:00:00 2001 From: JotaChina Date: Fri, 26 Dec 2025 20:30:06 -0300 Subject: [PATCH] tentando resolver conflitos do tone no mmpCreator --- assets/js/creations/pattern/pattern_audio.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/assets/js/creations/pattern/pattern_audio.js b/assets/js/creations/pattern/pattern_audio.js index 119612af..12904b50 100755 --- a/assets/js/creations/pattern/pattern_audio.js +++ b/assets/js/creations/pattern/pattern_audio.js @@ -12,6 +12,9 @@ import { SuperSaw } from "../../audio/plugins/SuperSaw.js"; import { Lb302 } from "../../audio/plugins/Lb302.js"; import { Kicker } from "../../audio/plugins/Kicker.js"; +const TICKS_PER_STEP = 12; // LMMS: 12 ticks por 1/16 +const STEPS_PER_BAR = 16; // 4/4 em 1/16 + // Mapa para facilitar a criação dinâmica const PLUGIN_CLASSES = { tripleoscillator: TripleOscillator, @@ -310,9 +313,21 @@ function schedulePianoRoll() { } }, events).start(0); - const bars = parseInt(document.getElementById("bars-input")?.value || 1); + // calcula até onde vai a última nota do pianoroll + let maxEndTick = 0; + for (const n of pattern.notes) { + const pos = Number(n.pos) || 0; + const rawLen = Number(n.len) || 0; + const len = rawLen < 0 ? TICKS_PER_STEP : rawLen; + maxEndTick = Math.max(maxEndTick, pos + Math.max(len, TICKS_PER_STEP)); + } + + const totalStepsNeeded = Math.max(1, Math.ceil(maxEndTick / TICKS_PER_STEP)); + const barsNeeded = Math.max(1, Math.ceil(totalStepsNeeded / STEPS_PER_BAR)); + part.loop = true; - part.loopEnd = bars + "m"; + part.loopEnd = `${barsNeeded}m`; + activeParts.push(part); }