renderizando projetos no mmpCreator utilizando o lmms
Deploy / Deploy (push) Successful in 2m5s
Details
Deploy / Deploy (push) Successful in 2m5s
Details
This commit is contained in:
parent
897a5b54b5
commit
4d047b7ac7
|
|
@ -27,9 +27,10 @@ window.ROOM_NAME = ROOM_NAME;
|
|||
|
||||
const PROJECT_NAME = new URLSearchParams(window.location.search).get("project");
|
||||
|
||||
const chosenFormat = allowed.has(fmt) ? fmt : "wav";
|
||||
const body = {
|
||||
roomName: ROOM_NAME || null,
|
||||
format,
|
||||
chosenFormat,
|
||||
name:
|
||||
appState.global?.currentBeatBasslineName ||
|
||||
appState.global?.projectName ||
|
||||
|
|
@ -148,76 +149,68 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
const renderAudioBtn = document.getElementById("render-audio-btn");
|
||||
|
||||
renderAudioBtn?.addEventListener("click", async () => {
|
||||
const fmt = (prompt("Formato: wav / mp3 / ogg / flac", "wav") || "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
const fmt = (prompt("Formato: wav / mp3 / ogg / flac", "wav") || "").trim().toLowerCase();
|
||||
if (!fmt) return;
|
||||
|
||||
if (!fmt) return;
|
||||
const allowed = new Set(["wav", "mp3", "ogg", "flac"]);
|
||||
const chosenFormat = allowed.has(fmt) ? fmt : "wav"; // ✅
|
||||
|
||||
const allowed = new Set(["wav", "mp3", "ogg", "flac"]);
|
||||
const format = allowed.has(fmt) ? fmt : "wav";
|
||||
const icon = renderAudioBtn.querySelector("i");
|
||||
const oldIconClass = icon?.className;
|
||||
if (icon) icon.className = "fa-solid fa-spinner fa-spin";
|
||||
renderAudioBtn.style.pointerEvents = "none";
|
||||
|
||||
const originalIcon = renderAudioBtn.className;
|
||||
renderAudioBtn.className = "fa-solid fa-spinner fa-spin";
|
||||
renderAudioBtn.style.pointerEvents = "none";
|
||||
try {
|
||||
showToast("🎛️ Renderizando no LMMS (servidor)...", "info", 4000);
|
||||
|
||||
try {
|
||||
showToast("🎛️ Renderizando no LMMS (servidor)...", "info", 4000);
|
||||
const roomName = new URLSearchParams(window.location.search).get("room");
|
||||
const baseUrl = `https://${window.location.hostname}:33001`;
|
||||
|
||||
// mesma lógica do socket: room vem da URL
|
||||
const roomName = new URLSearchParams(window.location.search).get("room");
|
||||
const body = {
|
||||
roomName: roomName || null,
|
||||
format: chosenFormat, // ✅ sem shorthand
|
||||
name: appState.global?.currentBeatBasslineName || appState.global?.projectName || "projeto",
|
||||
};
|
||||
|
||||
// usa a mesma porta do socket (o socket.js usa PORT_SOCK) :contentReference[oaicite:7]{index=7}
|
||||
// se você não quiser mexer em imports, dá pra trocar por ':33001' direto.
|
||||
const baseUrl = `https://${window.location.hostname}:33001`;
|
||||
// ✅ Modo Local: manda XML direto (senão dá missing_xml_or_room)
|
||||
if (!roomName) {
|
||||
body.xml = generateXmlFromStateExported();
|
||||
}
|
||||
|
||||
const body = {
|
||||
roomName: roomName || null,
|
||||
format,
|
||||
name:
|
||||
appState.global?.currentBeatBasslineName ||
|
||||
appState.global?.projectName ||
|
||||
"projeto",
|
||||
};
|
||||
const resp = await fetch(`${baseUrl}/render`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const resp = await fetch(`${baseUrl}/render`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!resp.ok) throw new Error(await resp.text());
|
||||
|
||||
if (!resp.ok) {
|
||||
const txt = await resp.text();
|
||||
throw new Error(txt || `HTTP ${resp.status}`);
|
||||
const blob = await resp.blob();
|
||||
|
||||
let filename = `projeto.${chosenFormat}`;
|
||||
const cd = resp.headers.get("Content-Disposition");
|
||||
const m = cd && /filename="?([^"]+)"?/i.exec(cd);
|
||||
if (m?.[1]) filename = m[1];
|
||||
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1500);
|
||||
|
||||
showToast("✅ Render concluído!", "success", 3000);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
showToast("❌ Falha ao renderizar no LMMS.", "error", 6000);
|
||||
alert("Falha ao renderizar no LMMS. Veja o console para detalhes.");
|
||||
} finally {
|
||||
if (icon && oldIconClass) icon.className = oldIconClass;
|
||||
renderAudioBtn.style.pointerEvents = "auto";
|
||||
}
|
||||
|
||||
const blob = await resp.blob();
|
||||
|
||||
// tenta usar filename vindo do Content-Disposition
|
||||
let filename = `projeto.${format}`;
|
||||
const cd = resp.headers.get("Content-Disposition");
|
||||
const m = cd && /filename="?([^"]+)"?/i.exec(cd);
|
||||
if (m?.[1]) filename = m[1];
|
||||
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1500);
|
||||
|
||||
showToast("✅ Render concluído!", "success", 3000);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
showToast("❌ Falha ao renderizar no LMMS.", "error", 6000);
|
||||
alert("Falha ao renderizar no LMMS. Veja o console para detalhes.");
|
||||
} finally {
|
||||
renderAudioBtn.className = originalIcon;
|
||||
renderAudioBtn.style.pointerEvents = "auto";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Download projeto
|
||||
downloadPackageBtn?.addEventListener("click", generateMmpFile);
|
||||
|
|
|
|||
Loading…
Reference in New Issue