718 lines
32 KiB
Markdown
Executable File
718 lines
32 KiB
Markdown
Executable File
---
|
|
layout: default
|
|
title: MMPSearch - Samples Disponíveis
|
|
permalink: /samples/
|
|
---
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<main class="main-content">
|
|
<div class="publication">
|
|
|
|
<div class="container">
|
|
<br />
|
|
|
|
<div class="tabs is-centered is-boxed is-medium mb-6">
|
|
{% include sidebar.html %}
|
|
</div>
|
|
|
|
<div class="has-text-centered mb-5">
|
|
<h1 class="title is-3 has-text-grey-dark">🎤 Biblioteca de Samples</h1>
|
|
<p class="subtitle is-6 has-text-grey">Navegue pelas pastas para ouvir e filtrar projetos.</p>
|
|
<div style="width: 60px; height: 4px; background-color: #3273dc; margin: 1rem auto; border-radius: 2px;"></div>
|
|
</div>
|
|
|
|
<div class="box p-0 mb-6" style="border: 1px solid #cfe8fc; overflow: hidden; background-color: #fff; min-height: 400px; display: flex; flex-direction: column; box-shadow: 0 4px 10px rgba(0,0,0,0.05);">
|
|
|
|
<div class="p-3 has-background-white-ter" style="border-bottom: 1px solid #cfe8fc; display: flex; align-items: center;">
|
|
<button id="btn-home" class="button is-small is-info is-light mr-3" title="Voltar ao início">
|
|
<i class="fa-solid fa-house"></i>
|
|
</button>
|
|
|
|
<button id="btn-open-upload" class="button is-small is-success is-light mr-3" title="Enviar novo Sample" style="display: inline-flex; align-items: center;">
|
|
<span class="icon"><i class="fa-solid fa-upload"></i></span>
|
|
<span>Enviar Sample</span>
|
|
</button>
|
|
|
|
<nav class="breadcrumb is-small mb-0" aria-label="breadcrumbs">
|
|
<ul id="breadcrumb-list">
|
|
<li class="is-active"><a href="#">Raiz</a></li>
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
|
|
<div id="browser-view" class="p-4" style="flex: 1;">
|
|
<p class="has-text-centered has-text-grey-light mt-6">Carregando biblioteca...</p>
|
|
</div>
|
|
|
|
<div id="preview-bar" class="p-3 has-background-info-light is-hidden" style="border-top: 1px solid #cfe8fc; display: flex; align-items: center; justify-content: space-between;">
|
|
<div style="display: flex; align-items: center; gap: 10px; overflow: hidden;">
|
|
<span class="icon has-text-info"><i class="fa-solid fa-music"></i></span>
|
|
<div>
|
|
<strong id="preview-filename" style="display:block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; line-height: 1;">Nome do Arquivo</strong>
|
|
<span class="is-size-7 has-text-grey">Filtrando projetos abaixo...</span>
|
|
</div>
|
|
</div>
|
|
<audio id="browser-audio-player" controls style="height: 30px; max-width: 300px;"></audio>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="columns is-mobile is-vcentered mb-5">
|
|
<div class="column is-auto">
|
|
<h2 class="title is-4 has-text-grey-dark">
|
|
<span class="icon has-text-info mr-2"><i class="fa-solid fa-filter"></i></span>
|
|
Filtro: <code id="filter-display-name" style="color: #d63384;">(nenhum selecionado)</code>
|
|
</h2>
|
|
</div>
|
|
<div class="column is-narrow">
|
|
<button id="clearFilterButton" class="button is-small is-danger is-light">
|
|
<span class="icon is-small"><i class="fa-solid fa-xmark"></i></span>
|
|
<span>Limpar Filtro</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="project-list" class="columns is-multiline">
|
|
{% for projeto in site.data.all %}
|
|
|
|
{% assign project_samples_list = "" %}
|
|
{% for track in projeto.tracks %}
|
|
{% if track.sample %}
|
|
{% for inst in track.sample %}
|
|
{% if inst.sample_name %}
|
|
{% assign project_samples_list = project_samples_list | append: inst.sample_name | append: "," %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% elsif track.sample_name %}
|
|
{% assign project_samples_list = project_samples_list | append: track.sample_name | append: "," %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
{% if project_samples_list != "" %}
|
|
|
|
<div class="column is-12-mobile is-6-tablet is-4-desktop is-3-widescreen project-item"
|
|
data-samples="{{ project_samples_list }}">
|
|
|
|
<div class="card project-card" style="height: 100%; background-color: #f0f8ff; border: 1px solid #cfe8fc; border-radius: 12px; display: flex; flex-direction: column; position: relative;">
|
|
|
|
{% assign file_url = projeto.file | downcase | replace: ' ', '-' | replace: 'ç', 'c' | replace: 'ã', 'a' | replace: 'á', 'a' | replace: 'â', 'a' | replace: 'é', 'e' | replace: 'ê', 'e' | replace: 'í', 'i' | replace: 'ó', 'o' | replace: 'ô', 'o' | replace: 'õ', 'o' | replace: 'ú', 'u' %}
|
|
{% assign page_url = '../projetos/' | append: file_url | append: '.html' %}
|
|
|
|
<a href="{{ page_url }}" style="text-decoration: none; flex: 1; display: flex; flex-direction: column;">
|
|
<div class="card-content has-text-centered p-4" style="flex: 1; display: flex; flex-direction: column;">
|
|
|
|
<div style="width: 50px; height: 50px; background-color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 0.5rem auto; box-shadow: 0 2px 5px rgba(0,0,0,0.05);">
|
|
<span class="icon" style="color: #3273dc;"><i class="fa-solid fa-microphone-lines fa-lg"></i></span>
|
|
</div>
|
|
|
|
<p class="title is-6 mb-2" style="color: #205081; word-break: break-word; font-weight: 700; line-height: 1.2;">
|
|
{{ projeto.file }}
|
|
</p>
|
|
|
|
{% if projeto.bpm %}
|
|
<div class="mb-3">
|
|
<span class="tag is-dark is-rounded is-light" style="font-size: 0.7rem; font-weight: bold; border: 1px solid #ccc;">
|
|
🎵 {{ projeto.bpm }} BPM
|
|
</span>
|
|
</div>
|
|
{% else %}
|
|
<div class="mb-3" style="height: 24px;"></div>
|
|
{% endif %}
|
|
|
|
<div style="flex: 1;"></div>
|
|
|
|
<div class="tags is-centered is-gapless mb-0 mt-2" style="gap: 4px; justify-content: center;">
|
|
{% assign unique_list = project_samples_list | split: "," | uniq %}
|
|
{% for item in unique_list %}
|
|
{% if item != "" %}
|
|
{% assign item_display = item | split: '/' | last | split: '\\' | last %}
|
|
<span class="tag is-white sample-tag-item clickable-tag" data-value="{{ item }}"
|
|
style="font-size: 0.65rem; border: 1px solid #deeaf6; color: #5b7da3; padding: 0 6px; height: 1.5em; text-decoration: none; cursor: pointer;">
|
|
{{ item_display | truncate: 15 }}
|
|
</span>
|
|
{% endif %}
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
</a>
|
|
|
|
<footer class="card-footer" style="border-top: 1px solid #cfe8fc; background-color: #fff; border-radius: 0 0 12px 12px; overflow: hidden;">
|
|
<a href="#" class="card-footer-item js-open-modal" data-target-url="{{ page_url }}" data-modal-title="Detalhes: {{ projeto.file }}" data-full-btn-text="Ir para Página" data-full-btn-link="{{ page_url }}" style="color: #5b7da3; font-size: 0.8rem; font-weight: 600; border-right: 1px solid #eee; transition: background 0.2s;">Ver</a>
|
|
{% assign creation_url = '/mmpSearch/creation.html?project=' | append: projeto.file %}
|
|
{% assign embed_url = creation_url | append: '&embed=true' %}
|
|
<a href="#" class="card-footer-item js-open-modal" data-target-url="{{ embed_url }}" data-modal-title="Editor: {{ projeto.file }}" data-full-btn-text="Abrir Editor" data-full-btn-link="{{ creation_url }}" style="color: #3273dc; font-size: 0.8rem; font-weight: 600;">Editar</a>
|
|
</footer>
|
|
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
{% endfor %}
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<div id="preview-modal" class="modal">
|
|
<div class="modal-background"></div>
|
|
<div class="modal-card" style="width: 90%; max-width: 800px;">
|
|
<header class="modal-card-head" style="background-color: #f0f8ff; border-bottom: 1px solid #cfe8fc;">
|
|
<p class="modal-card-title" id="modal-title" style="color: #205081; font-weight: bold;">Preview</p>
|
|
<button class="delete" aria-label="close"></button>
|
|
</header>
|
|
<section class="modal-card-body p-0" style="height: 500px; background-color: #fff;">
|
|
<iframe id="preview-iframe" src="" style="width: 100%; height: 100%; border: none;"></iframe>
|
|
</section>
|
|
<footer class="modal-card-foot" style="justify-content: flex-end; background-color: #fff; border-top: 1px solid #cfe8fc;">
|
|
<button class="button" id="close-modal-btn">Fechar</button>
|
|
<a href="#" id="full-edit-btn" target="_blank" class="button is-info">Abrir</a>
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="upload-sample-modal" class="modal">
|
|
<div class="modal-background"></div>
|
|
<div class="modal-card">
|
|
<header class="modal-card-head">
|
|
<p class="modal-card-title">Enviar Sample</p>
|
|
<button class="delete" aria-label="close" id="close-upload-modal"></button>
|
|
</header>
|
|
<section class="modal-card-body">
|
|
|
|
<div class="tabs is-toggle is-fullwidth is-small mb-4">
|
|
<ul>
|
|
<li class="is-active" id="tab-file-trigger">
|
|
<a>
|
|
<span class="icon is-small"><i class="fa-solid fa-file-arrow-up"></i></span>
|
|
<span>Arquivo</span>
|
|
</a>
|
|
</li>
|
|
<li id="tab-mic-trigger">
|
|
<a>
|
|
<span class="icon is-small"><i class="fa-solid fa-microphone"></i></span>
|
|
<span>Microfone</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<form id="sample-upload-form">
|
|
|
|
<div id="section-file-upload">
|
|
<div class="field">
|
|
<label class="label">Arquivo de Áudio</label>
|
|
<div class="control">
|
|
<div class="file has-name is-fullwidth">
|
|
<label class="file-label">
|
|
<input class="file-input" type="file" name="sample_file" accept=".wav,.mp3,.ogg,.flac" id="file-input-real">
|
|
<span class="file-cta">
|
|
<span class="file-icon"><i class="fa-solid fa-upload"></i></span>
|
|
<span class="file-label">Escolher arquivo...</span>
|
|
</span>
|
|
<span class="file-name" id="upload-filename-display">Nenhum selecionado</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="section-mic-record" class="is-hidden has-text-centered mb-4 p-4" style="background-color: #f5f5f5; border-radius: 8px;">
|
|
<p class="mb-3 is-size-7 has-text-grey">Clique para começar a gravar</p>
|
|
|
|
<button type="button" id="record-btn" class="button is-rounded is-large mb-3" style="width: 80px; height: 80px; border: 4px solid #ddd; transition: all 0.2s;">
|
|
<span class="icon is-large has-text-danger"><i class="fa-solid fa-microphone"></i></span>
|
|
</button>
|
|
|
|
<div id="recording-indicator" class="is-hidden">
|
|
<span class="tag is-danger is-light mb-2 pulse-animation">🔴 Gravando...</span>
|
|
</div>
|
|
|
|
<audio id="record-preview" controls class="is-hidden mt-3" style="width: 100%;"></audio>
|
|
|
|
<div class="field mt-3">
|
|
<label class="label is-small has-text-left">Nome da Gravação</label>
|
|
<div class="control">
|
|
<input class="input is-small" type="text" id="record-filename" placeholder="Ex: minha_voz_01">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="field mt-4">
|
|
<label class="label">Salvar na Pasta</label>
|
|
<div class="control has-icons-left">
|
|
<input class="input" type="text" name="subfolder" placeholder="Ex: Drums/Kicks (Vazio = Raiz)" id="upload-subfolder">
|
|
<span class="icon is-small is-left"><i class="fa-solid fa-folder-open"></i></span>
|
|
</div>
|
|
<p class="help">Você pode criar pastas usando barras, ex: <code>Percussion/Hats</code></p>
|
|
</div>
|
|
|
|
<progress id="upload-progress" class="progress is-small is-primary is-hidden" max="100"></progress>
|
|
<p id="upload-status" class="help is-hidden"></p>
|
|
|
|
</form>
|
|
</section>
|
|
<footer class="modal-card-foot" style="justify-content: flex-end;">
|
|
<button class="button" id="cancel-upload">Cancelar</button>
|
|
<button class="button is-success" id="confirm-upload-btn">
|
|
<span class="icon"><i class="fa-solid fa-check"></i></span>
|
|
<span>Enviar</span>
|
|
</button>
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.browser-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 15px; }
|
|
.browser-item { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 15px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; transition: all 0.2s; }
|
|
.browser-item:hover { background-color: #f0f8ff; border-color: #cfe8fc; transform: translateY(-2px); }
|
|
.browser-icon { font-size: 2.5rem; margin-bottom: 10px; color: #888; }
|
|
.browser-item.is-folder .browser-icon { color: #fce96a; text-shadow: 0 2px 2px rgba(0,0,0,0.1); }
|
|
.browser-item.is-file .browser-icon { color: #3273dc; }
|
|
.browser-item.is-unsupported .browser-icon { color: #ccc; }
|
|
.browser-name { font-size: 0.85rem; word-break: break-word; line-height: 1.3; color: #4a4a4a; }
|
|
|
|
.project-card:hover { transform: translateY(-5px); box-shadow: 0 8px 20px rgba(50, 115, 220, 0.15); border-color: #3273dc !important; background-color: #fff !important; }
|
|
.clickable-tag:hover { background-color: #e3effd !important; color: #3273dc !important; border-color: #3273dc !important; transform: scale(1.05); }
|
|
.tag.is-active-filter { background-color: #3273dc !important; color: #fff !important; border-color: #3273dc !important; font-weight: bold; box-shadow: 0 2px 5px rgba(50, 115, 220, 0.3); }
|
|
|
|
/* Animação para Gravação */
|
|
@keyframes pulse-red {
|
|
0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 56, 96, 0.7); }
|
|
70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(255, 56, 96, 0); }
|
|
100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 56, 96, 0); }
|
|
}
|
|
.pulse-animation { animation: pulse-red 1.5s infinite; }
|
|
.is-recording { border-color: #ff3860 !important; background-color: #ffe0e6 !important; animation: pulse-red 1.5s infinite; }
|
|
</style>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// === DADOS E CONFIGURAÇÃO ===
|
|
const manifestData = {{ site.data['samples-manifest'] | jsonify }};
|
|
const BASE_ASSETS_URL = "{{ '/src_mmpSearch/samples/' | relative_url }}";
|
|
|
|
// === ELEMENTOS DO DOM ===
|
|
const browserView = document.getElementById('browser-view');
|
|
const breadcrumbList = document.getElementById('breadcrumb-list');
|
|
const btnHome = document.getElementById('btn-home');
|
|
const previewBar = document.getElementById('preview-bar');
|
|
const audioPlayer = document.getElementById('browser-audio-player');
|
|
const previewLabel = document.getElementById('preview-filename');
|
|
|
|
const projects = document.querySelectorAll('.project-item');
|
|
const filterDisplayName = document.getElementById('filter-display-name');
|
|
const clearFilterButton = document.getElementById('clearFilterButton');
|
|
|
|
let currentPathStack = [];
|
|
let currentFolderObj = manifestData;
|
|
|
|
// === FUNÇÕES DE UTILIDADE ===
|
|
function removeExtension(filename) {
|
|
return filename.replace(/\.[^/.]+$/, "");
|
|
}
|
|
|
|
// === LÓGICA DO NAVEGADOR DE ARQUIVOS ===
|
|
function getFolderByPath(pathArray) {
|
|
let folder = manifestData;
|
|
for (const dir of pathArray) {
|
|
if (folder[dir]) folder = folder[dir];
|
|
}
|
|
return folder;
|
|
}
|
|
|
|
function isAudioFile(filename) {
|
|
const ext = filename.split('.').pop().toLowerCase();
|
|
return ['wav', 'ogg', 'mp3', 'flac'].includes(ext);
|
|
}
|
|
|
|
function renderBreadcrumbs() {
|
|
breadcrumbList.innerHTML = '';
|
|
const liRoot = document.createElement('li');
|
|
if (currentPathStack.length === 0) liRoot.classList.add('is-active');
|
|
liRoot.innerHTML = `<a href="#">Raiz</a>`;
|
|
liRoot.onclick = (e) => { e.preventDefault(); navigateTo([]); };
|
|
breadcrumbList.appendChild(liRoot);
|
|
|
|
let accumulatedPath = [];
|
|
currentPathStack.forEach((folderName, index) => {
|
|
accumulatedPath.push(folderName);
|
|
const isLast = index === currentPathStack.length - 1;
|
|
const li = document.createElement('li');
|
|
if (isLast) li.classList.add('is-active');
|
|
const pathForClick = [...accumulatedPath];
|
|
li.innerHTML = `<a href="#">${folderName}</a>`;
|
|
if (!isLast) li.onclick = (e) => { e.preventDefault(); navigateTo(pathForClick); };
|
|
breadcrumbList.appendChild(li);
|
|
});
|
|
}
|
|
|
|
function renderBrowser() {
|
|
browserView.innerHTML = '';
|
|
const grid = document.createElement('div');
|
|
grid.className = 'browser-grid';
|
|
|
|
const folders = [];
|
|
const files = [];
|
|
|
|
Object.keys(currentFolderObj).forEach(key => {
|
|
if (key === '_isFile') return;
|
|
const item = currentFolderObj[key];
|
|
if (item._isFile) files.push(key);
|
|
else folders.push(key);
|
|
});
|
|
|
|
folders.sort();
|
|
files.sort();
|
|
|
|
folders.forEach(folderName => {
|
|
const el = document.createElement('div');
|
|
el.className = 'browser-item is-folder';
|
|
el.innerHTML = `<i class="fa-solid fa-folder browser-icon"></i><span class="browser-name">${folderName}</span>`;
|
|
el.onclick = () => navigateTo([...currentPathStack, folderName]);
|
|
grid.appendChild(el);
|
|
});
|
|
|
|
files.forEach(fileName => {
|
|
const isAudio = isAudioFile(fileName);
|
|
const el = document.createElement('div');
|
|
el.className = `browser-item ${isAudio ? 'is-file' : 'is-unsupported'}`;
|
|
let iconClass = isAudio ? 'fa-file-audio' : (fileName.endsWith('.ds') ? 'fa-sliders' : 'fa-file');
|
|
el.innerHTML = `<i class="fa-solid ${iconClass} browser-icon"></i><span class="browser-name">${fileName}</span>`;
|
|
|
|
if (isAudio) {
|
|
el.onclick = () => {
|
|
playFile(fileName);
|
|
filterBySample(fileName);
|
|
};
|
|
} else {
|
|
el.onclick = () => alert('Este arquivo não é um áudio reproduzível (preset/binário).');
|
|
}
|
|
grid.appendChild(el);
|
|
});
|
|
|
|
if (folders.length === 0 && files.length === 0) {
|
|
browserView.innerHTML = `<div class="has-text-centered has-text-grey p-5">Esta pasta está vazia.</div>`;
|
|
} else {
|
|
browserView.appendChild(grid);
|
|
}
|
|
}
|
|
|
|
function navigateTo(newPathArray) {
|
|
currentPathStack = newPathArray;
|
|
currentFolderObj = getFolderByPath(currentPathStack);
|
|
renderBreadcrumbs();
|
|
renderBrowser();
|
|
}
|
|
|
|
function playFile(fileName) {
|
|
const fullPath = BASE_ASSETS_URL + currentPathStack.join('/') + '/' + fileName;
|
|
previewBar.classList.remove('is-hidden');
|
|
previewLabel.textContent = fileName;
|
|
audioPlayer.src = fullPath;
|
|
audioPlayer.play().catch(e => console.log('Erro ao tocar:', e));
|
|
}
|
|
|
|
// === LÓGICA DE FILTRAGEM (ROBUSTA) ===
|
|
function filterBySample(sampleName) {
|
|
if (!sampleName) {
|
|
filterDisplayName.textContent = "(todos)";
|
|
projects.forEach(p => p.style.display = 'block');
|
|
document.querySelectorAll('.sample-tag-item').forEach(tag => tag.classList.remove('is-active-filter'));
|
|
return;
|
|
}
|
|
|
|
filterDisplayName.textContent = sampleName;
|
|
const targetClean = sampleName.trim().toLowerCase();
|
|
const targetBase = removeExtension(targetClean);
|
|
|
|
let foundCount = 0;
|
|
|
|
projects.forEach(project => {
|
|
const projectSamplesStr = project.getAttribute('data-samples');
|
|
if (!projectSamplesStr) { project.style.display = 'none'; return; }
|
|
const projectSamples = projectSamplesStr.split(',');
|
|
|
|
const hasMatch = projectSamples.some(s => {
|
|
const samplePathClean = s.trim().toLowerCase();
|
|
const sampleFileName = samplePathClean.split(/[/\\]/).pop();
|
|
const sampleBaseName = removeExtension(sampleFileName);
|
|
|
|
if (sampleFileName === targetClean) return true;
|
|
if (sampleBaseName === targetBase && sampleBaseName !== "") return true;
|
|
return false;
|
|
});
|
|
|
|
if (hasMatch) {
|
|
project.style.display = 'block';
|
|
foundCount++;
|
|
const tags = project.querySelectorAll('.sample-tag-item');
|
|
tags.forEach(tag => {
|
|
const tagValClean = tag.dataset.value.trim().toLowerCase().split(/[/\\]/).pop();
|
|
const tagBase = removeExtension(tagValClean);
|
|
if(tagBase === targetBase) tag.classList.add('is-active-filter');
|
|
else tag.classList.remove('is-active-filter');
|
|
});
|
|
} else {
|
|
project.style.display = 'none';
|
|
}
|
|
});
|
|
|
|
if(foundCount > 0) document.getElementById('project-list').scrollIntoView({ behavior: 'smooth' });
|
|
}
|
|
|
|
btnHome.onclick = () => navigateTo([]);
|
|
renderBreadcrumbs();
|
|
renderBrowser();
|
|
|
|
document.querySelectorAll('.sample-tag-item').forEach(tag => {
|
|
tag.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
const val = this.dataset.value.split(/[/\\]/).pop();
|
|
filterBySample(val);
|
|
});
|
|
});
|
|
|
|
if(clearFilterButton) clearFilterButton.addEventListener('click', () => filterBySample(null));
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const sampleParam = urlParams.get('sample');
|
|
if (sampleParam) filterBySample(sampleParam);
|
|
|
|
// Modal Preview
|
|
const modal = document.getElementById('preview-modal');
|
|
const iframe = document.getElementById('preview-iframe');
|
|
const modalTitle = document.getElementById('modal-title');
|
|
const fullEditBtn = document.getElementById('full-edit-btn');
|
|
const closeButtons = document.querySelectorAll('.modal-background, .modal-card-head .delete, #close-modal-btn');
|
|
|
|
function openModal(url, title, btnText, btnLink) {
|
|
if(!modal) return;
|
|
modalTitle.textContent = title;
|
|
iframe.src = url;
|
|
fullEditBtn.textContent = btnText;
|
|
fullEditBtn.href = btnLink;
|
|
modal.classList.add('is-active');
|
|
document.documentElement.classList.add('is-clipped');
|
|
}
|
|
function closeModal() {
|
|
if(!modal) return;
|
|
modal.classList.remove('is-active');
|
|
document.documentElement.classList.remove('is-clipped');
|
|
iframe.src = "";
|
|
}
|
|
document.querySelectorAll('.js-open-modal').forEach(btn => {
|
|
btn.addEventListener('click', (e) => {
|
|
e.preventDefault();
|
|
openModal(btn.dataset.targetUrl, btn.dataset.modalTitle, btn.dataset.fullBtnText, btn.dataset.fullBtnLink);
|
|
});
|
|
});
|
|
closeButtons.forEach(el => el.addEventListener('click', closeModal));
|
|
document.addEventListener('keydown', (e) => { if (e.key === "Escape") closeModal(); });
|
|
|
|
// ==========================================================
|
|
// === LÓGICA DE UPLOAD & GRAVAÇÃO (CORRIGIDA) ===
|
|
// ==========================================================
|
|
const uploadModal = document.getElementById('upload-sample-modal');
|
|
const btnOpenUpload = document.getElementById('btn-open-upload');
|
|
const btnCloseUpload = document.getElementById('close-upload-modal');
|
|
const btnCancelUpload = document.getElementById('cancel-upload');
|
|
const fileInput = document.getElementById('file-input-real');
|
|
const fileNameDisplay = document.getElementById('upload-filename-display');
|
|
const subfolderInput = document.getElementById('upload-subfolder');
|
|
const confirmUploadBtn = document.getElementById('confirm-upload-btn');
|
|
const uploadProgress = document.getElementById('upload-progress');
|
|
const uploadStatus = document.getElementById('upload-status');
|
|
|
|
// Elementos das Abas
|
|
const tabFile = document.getElementById('tab-file-trigger');
|
|
const tabMic = document.getElementById('tab-mic-trigger');
|
|
const sectionFile = document.getElementById('section-file-upload');
|
|
const sectionMic = document.getElementById('section-mic-record');
|
|
|
|
// Elementos de Gravação
|
|
const recordBtn = document.getElementById('record-btn');
|
|
const recordIndicator = document.getElementById('recording-indicator');
|
|
const recordPreview = document.getElementById('record-preview');
|
|
const recordNameInput = document.getElementById('record-filename');
|
|
|
|
let isRecording = false;
|
|
let mediaRecorder = null;
|
|
let audioChunks = [];
|
|
let audioBlob = null;
|
|
let activeTab = 'file';
|
|
|
|
// Alternância de Abas
|
|
function switchTab(mode) {
|
|
activeTab = mode;
|
|
if(mode === 'file') {
|
|
tabFile.classList.add('is-active');
|
|
tabMic.classList.remove('is-active');
|
|
sectionFile.classList.remove('is-hidden');
|
|
sectionMic.classList.add('is-hidden');
|
|
stopRecordingLogic();
|
|
} else {
|
|
tabMic.classList.add('is-active');
|
|
tabFile.classList.remove('is-active');
|
|
sectionMic.classList.remove('is-hidden');
|
|
sectionFile.classList.add('is-hidden');
|
|
if(!recordNameInput.value) recordNameInput.value = "gravacao_" + new Date().toLocaleTimeString().replace(/:/g, '-');
|
|
}
|
|
}
|
|
|
|
tabFile.onclick = () => switchTab('file');
|
|
tabMic.onclick = () => switchTab('mic');
|
|
|
|
// Lógica do Microfone
|
|
recordBtn.onclick = async () => {
|
|
if (!isRecording) {
|
|
// INICIAR GRAVAÇÃO
|
|
try {
|
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
mediaRecorder = new MediaRecorder(stream);
|
|
audioChunks = [];
|
|
|
|
mediaRecorder.start();
|
|
isRecording = true;
|
|
|
|
// UI Updates
|
|
recordBtn.classList.add('is-recording');
|
|
recordIndicator.classList.remove('is-hidden');
|
|
recordPreview.classList.add('is-hidden');
|
|
uploadStatus.textContent = "Gravando... Clique no microfone para parar.";
|
|
uploadStatus.className = "help has-text-danger";
|
|
uploadStatus.classList.remove('is-hidden');
|
|
|
|
mediaRecorder.ondataavailable = event => {
|
|
audioChunks.push(event.data);
|
|
};
|
|
|
|
mediaRecorder.onstop = () => {
|
|
// CORREÇÃO 1: Forçamos o tipo para OGG para o servidor aceitar
|
|
audioBlob = new Blob(audioChunks, { type: 'audio/ogg' });
|
|
|
|
const audioUrl = URL.createObjectURL(audioBlob);
|
|
recordPreview.src = audioUrl;
|
|
recordPreview.classList.remove('is-hidden');
|
|
|
|
stream.getTracks().forEach(track => track.stop());
|
|
};
|
|
|
|
} catch (err) {
|
|
alert("Erro ao acessar microfone: " + err.message);
|
|
console.error(err);
|
|
}
|
|
} else {
|
|
// PARAR GRAVAÇÃO
|
|
stopRecordingLogic();
|
|
}
|
|
};
|
|
|
|
function stopRecordingLogic() {
|
|
if(mediaRecorder && mediaRecorder.state !== 'inactive') {
|
|
mediaRecorder.stop();
|
|
}
|
|
isRecording = false;
|
|
recordBtn.classList.remove('is-recording');
|
|
recordIndicator.classList.add('is-hidden');
|
|
uploadStatus.textContent = "Gravação finalizada. Pode enviar.";
|
|
uploadStatus.className = "help has-text-success";
|
|
}
|
|
|
|
// Modal Open/Close
|
|
function toggleUploadModal(show) {
|
|
if(show) {
|
|
uploadModal.classList.add('is-active');
|
|
subfolderInput.value = currentPathStack.join('/');
|
|
switchTab('file');
|
|
} else {
|
|
uploadModal.classList.remove('is-active');
|
|
uploadStatus.classList.add('is-hidden');
|
|
uploadProgress.classList.add('is-hidden');
|
|
stopRecordingLogic();
|
|
audioBlob = null;
|
|
recordPreview.src = "";
|
|
fileInput.value = "";
|
|
fileNameDisplay.textContent = "Nenhum selecionado";
|
|
}
|
|
}
|
|
|
|
if(btnOpenUpload) btnOpenUpload.onclick = () => toggleUploadModal(true);
|
|
if(btnCloseUpload) btnCloseUpload.onclick = () => toggleUploadModal(false);
|
|
if(btnCancelUpload) btnCancelUpload.onclick = () => toggleUploadModal(false);
|
|
|
|
fileInput.onchange = () => {
|
|
if (fileInput.files.length > 0) fileNameDisplay.textContent = fileInput.files[0].name;
|
|
};
|
|
|
|
// ENVIO (Upload)
|
|
confirmUploadBtn.onclick = async (e) => {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData();
|
|
formData.append('subfolder', subfolderInput.value);
|
|
|
|
if (activeTab === 'file') {
|
|
if (fileInput.files.length === 0) {
|
|
alert("Selecione um arquivo primeiro.");
|
|
return;
|
|
}
|
|
formData.append('sample_file', fileInput.files[0]);
|
|
} else {
|
|
// ABA MICROFONE
|
|
if (!audioBlob) {
|
|
alert("Grave algo antes de enviar.");
|
|
return;
|
|
}
|
|
|
|
let filename = recordNameInput.value.trim() || "gravacao";
|
|
|
|
// CORREÇÃO 2: Removemos a extensão antiga se houver e forçamos .ogg
|
|
// Isso engana a validação simples do servidor
|
|
filename = filename.replace(/\.(webm|wav|mp3|flac)$/i, "");
|
|
filename += ".ogg";
|
|
|
|
console.log("Enviando arquivo como:", filename); // Debug
|
|
|
|
formData.append('sample_file', audioBlob, filename);
|
|
}
|
|
|
|
const API_URL = 'https://alice.ufsj.edu.br:33002/api/upload/sample';
|
|
|
|
// UI Loading
|
|
confirmUploadBtn.classList.add('is-loading');
|
|
uploadProgress.classList.remove('is-hidden');
|
|
uploadStatus.classList.remove('is-hidden');
|
|
uploadStatus.textContent = "Enviando dados...";
|
|
uploadStatus.className = "help has-text-info";
|
|
|
|
console.log("Enviando para:", API_URL);
|
|
|
|
try {
|
|
const response = await fetch(API_URL, {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
console.log("Status:", response.status);
|
|
const result = await response.json();
|
|
|
|
if (response.ok) {
|
|
uploadStatus.textContent = "Sucesso! Recarregando...";
|
|
uploadStatus.className = "help has-text-success";
|
|
setTimeout(() => window.location.reload(), 2000);
|
|
} else {
|
|
throw new Error(result.error || "Erro no servidor (" + response.status + ")");
|
|
}
|
|
} catch (error) {
|
|
console.error("Erro Upload:", error);
|
|
let msg = "Erro: " + error.message;
|
|
if (error.message.includes("Failed to fetch")) {
|
|
msg = "Erro de Conexão (Verifique VPN/Firewall - Porta 33002).";
|
|
}
|
|
uploadStatus.textContent = msg;
|
|
uploadStatus.className = "help has-text-danger";
|
|
confirmUploadBtn.classList.remove('is-loading');
|
|
}
|
|
};
|
|
});
|
|
</script> |