From 7ec18a5f02d7c756cc999e4400bebb86c42c0ba2 Mon Sep 17 00:00:00 2001 From: JotaChina Date: Thu, 25 Dec 2025 17:31:36 -0300 Subject: [PATCH] playlist importando sample track --- assets/js/creations/audio/audio_state.js | 12 ++++++------ assets/js/creations/ui.js | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/assets/js/creations/audio/audio_state.js b/assets/js/creations/audio/audio_state.js index e6627534..6d54ab61 100755 --- a/assets/js/creations/audio/audio_state.js +++ b/assets/js/creations/audio/audio_state.js @@ -122,8 +122,7 @@ export function initializeAudioState() { }); } -export async function loadAudioForClip(clip) { - // --- ADIÇÃO --- +export async function loadAudioForClip(clip) { // Se já temos um buffer (do bounce ou colagem), não faz fetch if (clip.buffer) { // Garante que as durações estão corretas @@ -132,8 +131,7 @@ export async function loadAudioForClip(clip) { if (clip.durationInSeconds === 0) clip.durationInSeconds = clip.buffer.duration; return clip; - } - // --- FIM DA ADIÇÃO --- + } if (!clip.sourcePath || clip.sourcePath.startsWith("blob:")) { // Se não há caminho ou se é um blob, não há nada para buscar. @@ -147,7 +145,9 @@ export async function loadAudioForClip(clip) { } try { - const response = await fetch(clip.sourcePath); + const safeUrl = encodeURI(url).replace(/#/g, "%23"); + const response = await fetch(safeUrl); + if (!response.ok) throw new Error(`Falha ao buscar áudio: ${clip.sourcePath}`); const arrayBuffer = await response.arrayBuffer(); @@ -155,7 +155,7 @@ export async function loadAudioForClip(clip) { clip.buffer = audioBuffer; - // --- CORREÇÃO: Salva a duração original --- + // --- Salva a duração original --- if (clip.durationInSeconds === 0) { clip.durationInSeconds = audioBuffer.duration; } diff --git a/assets/js/creations/ui.js b/assets/js/creations/ui.js index 4a230948..18c86324 100755 --- a/assets/js/creations/ui.js +++ b/assets/js/creations/ui.js @@ -27,7 +27,8 @@ function buildSamplePathMap(tree, currentPath) { for (const key in tree) { if (key === "_isFile") continue; const node = tree[key]; - const newPath = `${currentPath}/${key}`; + const encodedKey = encodeURIComponent(key); + const newPath = `${currentPath}/${encodedKey}`; if (node._isFile) { samplePathMap[key] = newPath; } else { @@ -72,7 +73,8 @@ function renderFileTree(tree, parentElement, currentPath) { const node = tree[key]; const li = document.createElement("li"); - const newPath = `${currentPath}/${key}`; + const encodedKey = encodeURIComponent(key); + const newPath = `${currentPath}/${encodedKey}`; if (node._isFile) { // --- LÓGICA PARA ARQUIVOS ---