melhorando a leitura de projetos no mmpCreator
Deploy / Deploy (push) Successful in 1m58s
Details
Deploy / Deploy (push) Successful in 1m58s
Details
This commit is contained in:
parent
8d2380c704
commit
942793f267
|
|
@ -268,16 +268,24 @@ function parseInstrumentNode(
|
||||||
const ticksPerStep = 12;
|
const ticksPerStep = 12;
|
||||||
|
|
||||||
patternNode.querySelectorAll("note").forEach((noteNode) => {
|
patternNode.querySelectorAll("note").forEach((noteNode) => {
|
||||||
const pos = parseInt(noteNode.getAttribute("pos"), 10);
|
const pos = parseInt(noteNode.getAttribute("pos"), 10) || 0;
|
||||||
const len = parseInt(noteNode.getAttribute("len"), 10);
|
|
||||||
const vol = parseInt(noteNode.getAttribute("vol"), 10);
|
|
||||||
const pan = parseInt(noteNode.getAttribute("pan"), 10);
|
|
||||||
const key = parseInt(noteNode.getAttribute("key"), 10);
|
|
||||||
|
|
||||||
notes.push({ pos, len, key, vol, pan });
|
const rawLen = parseInt(noteNode.getAttribute("len"), 10) || 0;
|
||||||
|
|
||||||
// Calcula qual step acender
|
// ✅ LMMS costuma salvar one-shots com len negativo (ex: -192).
|
||||||
const stepIndex = Math.floor(pos / ticksPerStep);
|
// Na nossa DAW, tratamos isso como 1 step (1/16) = 12 ticks.
|
||||||
|
const len = rawLen < 0 ? TICKS_PER_STEP : rawLen;
|
||||||
|
|
||||||
|
notes.push({
|
||||||
|
pos,
|
||||||
|
len,
|
||||||
|
key: parseInt(noteNode.getAttribute("key"), 10),
|
||||||
|
vol: parseInt(noteNode.getAttribute("vol"), 10),
|
||||||
|
pan: parseInt(noteNode.getAttribute("pan"), 10),
|
||||||
|
});
|
||||||
|
|
||||||
|
// stepIndex também deve usar 12 (você já corrigiu isso antes)
|
||||||
|
const stepIndex = Math.floor(pos / TICKS_PER_STEP);
|
||||||
if (stepIndex < patternSteps) steps[stepIndex] = true;
|
if (stepIndex < patternSteps) steps[stepIndex] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -275,24 +275,25 @@ function schedulePianoRoll() {
|
||||||
track.instrument
|
track.instrument
|
||||||
) {
|
) {
|
||||||
// Converte notas para eventos Tone.js
|
// Converte notas para eventos Tone.js
|
||||||
const events = pattern.notes.map((note) => {
|
const bpm = parseInt(document.getElementById("bpm-input")?.value, 10) || 120;
|
||||||
// --- CORREÇÃO DE TEMPO (PPQ) ---
|
const stepSec = 60 / (bpm * 4); // 1/16
|
||||||
// LMMS usa 192 ticks por batida. Tone.js também usa 192 por padrão.
|
|
||||||
// Precisamos converter o 'pos' (ticks absolutos) para tempo musical
|
|
||||||
|
|
||||||
// 1 Beat = 192 ticks
|
const events = pattern.notes.map((note) => {
|
||||||
// Tone.Time("0:0:0").toTicks()
|
const posSteps = (note.pos || 0) / TICKS_PER_STEP;
|
||||||
|
|
||||||
|
const rawLen = note.len || 0;
|
||||||
|
const lenTicks = rawLen < 0 ? TICKS_PER_STEP : rawLen; // defesa extra
|
||||||
|
const lenSteps = Math.max(1, lenTicks / TICKS_PER_STEP);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// Passamos 'ticks' diretamente. O Tone converte baseado no BPM.
|
time: posSteps * stepSec, // segundos
|
||||||
time:
|
|
||||||
0 + (note.pos * (Tone.Transport.PPQ / 192)) / Tone.Transport.PPQ,
|
|
||||||
midi: note.key,
|
midi: note.key,
|
||||||
duration: note.len / 192 + "n", // Converte duração baseada em semínimas (192)
|
duration: lenSteps * stepSec, // segundos
|
||||||
velocity: (note.vol || 100) / 100,
|
velocity: (note.vol || 100) / 100,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const part = new Tone.Part((time, value) => {
|
const part = new Tone.Part((time, value) => {
|
||||||
if (track.muted) return;
|
if (track.muted) return;
|
||||||
const freq = Tone.Frequency(value.midi, "midi");
|
const freq = Tone.Frequency(value.midi, "midi");
|
||||||
|
|
|
||||||
|
|
@ -809,7 +809,9 @@
|
||||||
CONSTANTS.TOTAL_KEYS - 1 - (note.key - CONSTANTS.START_NOTE);
|
CONSTANTS.TOTAL_KEYS - 1 - (note.key - CONSTANTS.START_NOTE);
|
||||||
const y = keyIndex * CONSTANTS.NOTE_HEIGHT;
|
const y = keyIndex * CONSTANTS.NOTE_HEIGHT;
|
||||||
const x = note.pos / CONSTANTS.TICKS_PER_PIXEL;
|
const x = note.pos / CONSTANTS.TICKS_PER_PIXEL;
|
||||||
const width = note.len / CONSTANTS.TICKS_PER_PIXEL;
|
const lenTicks = note.len < 0 ? 12 : note.len;
|
||||||
|
const width = lenTicks / CONSTANTS.TICKS_PER_PIXEL;
|
||||||
|
|
||||||
|
|
||||||
gridCtx.fillRect(x + 1, y + 1, width - 2, CONSTANTS.NOTE_HEIGHT - 2);
|
gridCtx.fillRect(x + 1, y + 1, width - 2, CONSTANTS.NOTE_HEIGHT - 2);
|
||||||
gridCtx.strokeRect(
|
gridCtx.strokeRect(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue