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 PROJECT_NAME = new URLSearchParams(window.location.search).get("project");
|
||||||
|
|
||||||
|
const chosenFormat = allowed.has(fmt) ? fmt : "wav";
|
||||||
const body = {
|
const body = {
|
||||||
roomName: ROOM_NAME || null,
|
roomName: ROOM_NAME || null,
|
||||||
format,
|
chosenFormat,
|
||||||
name:
|
name:
|
||||||
appState.global?.currentBeatBasslineName ||
|
appState.global?.currentBeatBasslineName ||
|
||||||
appState.global?.projectName ||
|
appState.global?.projectName ||
|
||||||
|
|
@ -148,53 +149,45 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
const renderAudioBtn = document.getElementById("render-audio-btn");
|
const renderAudioBtn = document.getElementById("render-audio-btn");
|
||||||
|
|
||||||
renderAudioBtn?.addEventListener("click", async () => {
|
renderAudioBtn?.addEventListener("click", async () => {
|
||||||
const fmt = (prompt("Formato: wav / mp3 / ogg / flac", "wav") || "")
|
const fmt = (prompt("Formato: wav / mp3 / ogg / flac", "wav") || "").trim().toLowerCase();
|
||||||
.trim()
|
|
||||||
.toLowerCase();
|
|
||||||
|
|
||||||
if (!fmt) return;
|
if (!fmt) return;
|
||||||
|
|
||||||
const allowed = new Set(["wav", "mp3", "ogg", "flac"]);
|
const allowed = new Set(["wav", "mp3", "ogg", "flac"]);
|
||||||
const format = allowed.has(fmt) ? fmt : "wav";
|
const chosenFormat = allowed.has(fmt) ? fmt : "wav"; // ✅
|
||||||
|
|
||||||
const originalIcon = renderAudioBtn.className;
|
const icon = renderAudioBtn.querySelector("i");
|
||||||
renderAudioBtn.className = "fa-solid fa-spinner fa-spin";
|
const oldIconClass = icon?.className;
|
||||||
|
if (icon) icon.className = "fa-solid fa-spinner fa-spin";
|
||||||
renderAudioBtn.style.pointerEvents = "none";
|
renderAudioBtn.style.pointerEvents = "none";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
showToast("🎛️ Renderizando no LMMS (servidor)...", "info", 4000);
|
showToast("🎛️ Renderizando no LMMS (servidor)...", "info", 4000);
|
||||||
|
|
||||||
// mesma lógica do socket: room vem da URL
|
|
||||||
const roomName = new URLSearchParams(window.location.search).get("room");
|
const roomName = new URLSearchParams(window.location.search).get("room");
|
||||||
|
|
||||||
// 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`;
|
const baseUrl = `https://${window.location.hostname}:33001`;
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
roomName: roomName || null,
|
roomName: roomName || null,
|
||||||
format,
|
format: chosenFormat, // ✅ sem shorthand
|
||||||
name:
|
name: appState.global?.currentBeatBasslineName || appState.global?.projectName || "projeto",
|
||||||
appState.global?.currentBeatBasslineName ||
|
|
||||||
appState.global?.projectName ||
|
|
||||||
"projeto",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ✅ Modo Local: manda XML direto (senão dá missing_xml_or_room)
|
||||||
|
if (!roomName) {
|
||||||
|
body.xml = generateXmlFromStateExported();
|
||||||
|
}
|
||||||
|
|
||||||
const resp = await fetch(`${baseUrl}/render`, {
|
const resp = await fetch(`${baseUrl}/render`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!resp.ok) {
|
if (!resp.ok) throw new Error(await resp.text());
|
||||||
const txt = await resp.text();
|
|
||||||
throw new Error(txt || `HTTP ${resp.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const blob = await resp.blob();
|
const blob = await resp.blob();
|
||||||
|
|
||||||
// tenta usar filename vindo do Content-Disposition
|
let filename = `projeto.${chosenFormat}`;
|
||||||
let filename = `projeto.${format}`;
|
|
||||||
const cd = resp.headers.get("Content-Disposition");
|
const cd = resp.headers.get("Content-Disposition");
|
||||||
const m = cd && /filename="?([^"]+)"?/i.exec(cd);
|
const m = cd && /filename="?([^"]+)"?/i.exec(cd);
|
||||||
if (m?.[1]) filename = m[1];
|
if (m?.[1]) filename = m[1];
|
||||||
|
|
@ -214,10 +207,10 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
showToast("❌ Falha ao renderizar no LMMS.", "error", 6000);
|
showToast("❌ Falha ao renderizar no LMMS.", "error", 6000);
|
||||||
alert("Falha ao renderizar no LMMS. Veja o console para detalhes.");
|
alert("Falha ao renderizar no LMMS. Veja o console para detalhes.");
|
||||||
} finally {
|
} finally {
|
||||||
renderAudioBtn.className = originalIcon;
|
if (icon && oldIconClass) icon.className = oldIconClass;
|
||||||
renderAudioBtn.style.pointerEvents = "auto";
|
renderAudioBtn.style.pointerEvents = "auto";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Download projeto
|
// Download projeto
|
||||||
downloadPackageBtn?.addEventListener("click", generateMmpFile);
|
downloadPackageBtn?.addEventListener("click", generateMmpFile);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue