reformula buscas
Deploy / Deploy (push) Successful in 1m33s Details

This commit is contained in:
JotaChina 2025-12-16 20:13:34 -03:00
parent 007a40cdb2
commit cf83d63ad4
1 changed files with 393 additions and 219 deletions

View File

@ -12,25 +12,14 @@ permalink: /projetos/
{% assign list_automation = "" %}
{% for p in site.data.all %}
{% if p.bpm %}
{% assign list_bpm = list_bpm | append: p.bpm | append: "|||" %}
{% endif %}
{% if p.bpm %}{% assign list_bpm = list_bpm | append: p.bpm | append: "|||" %}{% endif %}
{% for item in p.tags.plugin %}{% if item != "" %}{% assign list_plugins = list_plugins | append: item | append: "|||" %}{% endif %}{% endfor %}
{% if p.tags.bassline %}{% for item in p.tags.bassline %}{% if item != "" %}{% assign list_bassline = list_bassline | append: item | append: "|||" %}{% endif %}{% endfor %}{% endif %}
{% if p.tags.automation %}{% for item in p.tags.automation %}{% if item != "" %}{% assign list_automation = list_automation | append: item | append: "|||" %}{% endif %}{% endfor %}{% endif %}
{% for track in p.tracks %}
{% if track.instruments %}
{% for inst in track.instruments %}
{% if inst.instrument_name and inst.instrument_name != "" %}
{% assign list_instruments = list_instruments | append: inst.instrument_name | append: "|||" %}
{% endif %}
{% endfor %}
{% elsif track.instrument_name and track.instrument_name != "" %}
{% assign list_instruments = list_instruments | append: track.instrument_name | append: "|||" %}
{% endif %}
{% if track.instruments %}{% for inst in track.instruments %}{% if inst.instrument_name %}{% assign list_instruments = list_instruments | append: inst.instrument_name | append: "|||" %}{% endif %}{% endfor %}
{% elsif track.instrument_name %}{% assign list_instruments = list_instruments | append: track.instrument_name | append: "|||" %}{% endif %}
{% if track.sample %}{% for smp in track.sample %}{% assign list_samples = list_samples | append: smp.sample_name | append: "|||" %}{% endfor %}
{% elsif track.sample_name %}{% assign list_samples = list_samples | append: track.sample_name | append: "|||" %}{% endif %}
{% endfor %}
@ -59,33 +48,112 @@ permalink: /projetos/
{% include sidebar.html %}
</div>
<div class="columns is-vcentered mb-5">
<div class="columns is-vcentered mb-4">
<div class="column">
<h1 class="title is-3 has-text-grey-dark">📁 Projetos Disponíveis</h1>
<p class="subtitle is-6 has-text-grey">
Busca avançada: Use o slicer de BPM ou filtros de tag para encontrar o projeto ideal.
Use os filtros laterais ou a barra de IA abaixo para explorar.
</p>
</div>
<div class="column is-narrow">
<button id="reset-all-filters" class="button is-danger is-light is-small">
<span class="icon"><i class="fa-solid fa-rotate-left"></i></span>
<span>Limpar Filtros</span>
<span>Limpar Tudo</span>
</button>
</div>
</div>
<div class="box has-background-white-ter mb-5 p-0" style="border: 1px solid #dbdbdb; overflow: hidden;">
<div class="p-3 is-clickable" id="filter-toggle-btn" style="cursor: pointer; display: flex; align-items: center; justify-content: space-between; background-color: #f5f5f5;">
<div class="icon-text has-text-weight-bold has-text-grey-dark">
<span class="icon"><i class="fa-solid fa-sliders"></i></span>
<span>Filtros IA, Gêneros & Ordenação</span>
</div>
<span class="icon transition-icon"><i class="fa-solid fa-chevron-down" id="filter-chevron"></i></span>
</div>
<div id="filter-content" style="display: none; border-top: 1px solid #e8e8e8;">
<div class="p-4">
<div class="columns is-vcentered is-multiline">
<div class="column">
<span class="is-size-7 has-text-grey has-text-weight-bold mb-2 is-block">GÊNEROS (IA):</span>
<div class="buttons" id="genre-filters">
<button class="button is-small is-rounded is-active is-info" data-genre="all">Todos</button>
</div>
</div>
<div class="column is-narrow">
<div class="field has-addons" style="flex-wrap: wrap; gap: 5px;">
<div class="control has-icons-left">
<div class="select is-small is-rounded">
<select id="star-filter">
<option value="all">Todas Dificuldades</option>
<option value="5">🔥 Expert (Nível 5)</option>
<option value="4">⚡ Avançado (Nível 4)</option>
<option value="3">🔷 Intermediário (Nível 3)</option>
<option value="2">🟢 Básico (Nível 2)</option>
</select>
</div>
<div class="icon is-small is-left has-text-warning"><i class="fa-solid fa-star"></i></div>
</div>
<div class="control has-icons-left">
<div class="select is-small is-rounded">
<select id="sort-select">
<option value="default">Ordem Padrão</option>
<option value="stars_desc">⭐ Mais Complexos</option>
<option value="stars_asc">⭐ Mais Simples</option>
<option value="intensity_desc">🔥 Mais Intensos</option>
<option value="intensity_asc">❄️ Mais Calmos</option>
<option value="bpm_desc">⚡ BPM (Rápido)</option>
</select>
</div>
<div class="icon is-small is-left"><i class="fa-solid fa-sort"></i></div>
</div>
<div class="control has-icons-left">
<div class="select is-small is-rounded">
<select id="key-filter">
<option value="all">🎹 Todos os Tons</option>
<option value="C">C (Dó Maior)</option>
<option value="Db">Db (Réb Maior)</option>
<option value="D">D (Ré Maior)</option>
<option value="Eb">Eb (Mib Maior)</option>
<option value="E">E (Mi Maior)</option>
<option value="F">F (Fá Maior)</option>
<option value="Gb">Gb (Solb Maior)</option>
<option value="G">G (Sol Maior)</option>
<option value="Ab">Ab (Láb Maior)</option>
<option value="A">A (Lá Maior)</option>
<option value="Bb">Bb (Sib Maior)</option>
<option value="B">B (Si Maior)</option>
<option value="Cm">Cm (Dó Menor)</option>
<option value="C#m">C#m (Dó# Menor)</option>
<option value="Dm">Dm (Ré Menor)</option>
</select>
</div>
<div class="icon is-small is-left has-text-info"><i class="fa-solid fa-music"></i></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="columns">
<div class="column is-3">
<div class="box p-3" style="background: #fcfcfc; border: 1px solid #eee;">
<div class="field mb-5">
<label class="label is-small has-text-grey">Busca Inteligente (IA)</label>
<label class="label is-small has-text-grey">Busca Textual</label>
<div class="control has-icons-left">
<input class="input is-small" type="text" id="search-input" placeholder="Nome, plugin, instrumento...">
<span class="icon is-small is-left">
<i class="fa-solid fa-magnifying-glass"></i>
</span>
<span class="icon is-small is-left"><i class="fa-solid fa-magnifying-glass"></i></span>
</div>
</div>
<hr class="my-3">
@ -102,7 +170,6 @@ permalink: /projetos/
<input class="input is-small" type="number" id="bpm-max" value="{{ max_bpm_val }}" min="0" max="999">
</div>
</div>
<p class="help has-text-centered is-size-7" style="margin-top: -5px;">Projetos entre esses valores.</p>
</div>
<hr class="my-3">
@ -130,38 +197,21 @@ permalink: /projetos/
</details>
<hr class="my-3">
<details>
<summary class="menu-label has-text-weight-bold mb-2 clickable-summary">Bassline</summary>
<details><summary class="menu-label has-text-weight-bold mb-2 clickable-summary">Bassline</summary>
<div class="filter-content" style="max-height: 200px; overflow-y: auto;">
{% for item in unique_bassline %}{% if item != "" %}
<label class="checkbox is-block mb-1 is-size-7">
<input type="checkbox" class="filter-checkbox" data-category="bassline" value="{{ item }}"> {{ item }}
</label>
{% endif %}{% endfor %}
{% for item in unique_bassline %}{% if item != "" %}<label class="checkbox is-block mb-1 is-size-7"><input type="checkbox" class="filter-checkbox" data-category="bassline" value="{{ item }}"> {{ item }}</label>{% endif %}{% endfor %}
</div>
</details>
<hr class="my-3">
<details>
<summary class="menu-label has-text-weight-bold mb-2 clickable-summary">Automação</summary>
<details><summary class="menu-label has-text-weight-bold mb-2 clickable-summary">Automação</summary>
<div class="filter-content" style="max-height: 200px; overflow-y: auto;">
{% for item in unique_automation %}{% if item != "" %}
<label class="checkbox is-block mb-1 is-size-7">
<input type="checkbox" class="filter-checkbox" data-category="automation" value="{{ item }}"> {{ item }}
</label>
{% endif %}{% endfor %}
{% for item in unique_automation %}{% if item != "" %}<label class="checkbox is-block mb-1 is-size-7"><input type="checkbox" class="filter-checkbox" data-category="automation" value="{{ item }}"> {{ item }}</label>{% endif %}{% endfor %}
</div>
</details>
<hr class="my-3">
<details>
<summary class="menu-label has-text-weight-bold mb-2 clickable-summary">Samples</summary>
<details><summary class="menu-label has-text-weight-bold mb-2 clickable-summary">Samples</summary>
<div class="filter-content" style="max-height: 200px; overflow-y: auto;">
{% for item in unique_samples %}{% if item != "" %}
<label class="checkbox is-block mb-1 is-size-7">
<input type="checkbox" class="filter-checkbox" data-category="samples" value="{{ item }}"> {{ item | truncate: 25 }}
</label>
{% endif %}{% endfor %}
{% for item in unique_samples %}{% if item != "" %}<label class="checkbox is-block mb-1 is-size-7"><input type="checkbox" class="filter-checkbox" data-category="samples" value="{{ item }}"> {{ item | truncate: 25 }}</label>{% endif %}{% endfor %}
</div>
</details>
@ -181,29 +231,20 @@ permalink: /projetos/
{% assign p_insts_array = "" | split: "," %}
{% for track in page.tracks %}
{% if track.instruments %}
{% for inst in track.instruments %}
{% if inst.instrument_name %}
{% assign p_insts_array = p_insts_array | push: inst.instrument_name %}
{% endif %}
{% endfor %}
{% elsif track.instrument_name %}
{% assign p_insts_array = p_insts_array | push: track.instrument_name %}
{% endif %}
{% if track.instruments %}{% for inst in track.instruments %}{% if inst.instrument_name %}{% assign p_insts_array = p_insts_array | push: inst.instrument_name %}{% endif %}{% endfor %}
{% elsif track.instrument_name %}{% assign p_insts_array = p_insts_array | push: track.instrument_name %}{% endif %}
{% endfor %}
{% assign p_instruments_str = p_insts_array | uniq | join: ',' %}
{% assign p_bpm = page.bpm | default: 0 %}
{% assign p_plugins = page.tags.plugin | join: ',' %}
{% assign p_bassline = page.tags.bassline | join: ',' %}
{% assign p_automation = page.tags.automation | join: ',' %}
{% assign p_samples = page.tags.sample | join: ',' %}
{% assign p_name = page.title | default: page.name | downcase %}
<div class="column is-12-mobile is-6-tablet is-4-desktop is-4-widescreen project-item"
data-name="{{ p_name }}"
data-title="{{ page.title | escape }}"
data-bpm="{{ p_bpm }}"
data-plugins="{{ p_plugins }}"
data-bassline="{{ p_bassline }}"
@ -212,30 +253,27 @@ permalink: /projetos/
data-samples="{{ p_samples }}">
<div class="card project-card"
data-title="{{ page.title | escape }}"
style="height: 100%; background-color: #f0f8ff; border: 1px solid #cfe8fc; border-radius: 12px; display: flex; flex-direction: column; position: relative;">
<a href="{{ page.url | relative_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-music fa-lg"></i>
</span>
<span class="icon" style="color: #3273dc;"><i class="fa-solid fa-music 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;">
{{ page.title | default: page.name | replace: '.html', '' }}
</p>
{% if page.bpm %}
<div class="mb-3">
<div class="bpm-container mb-3" style="min-height: 25px;">
{% if page.bpm %}
<span class="tag is-dark is-rounded is-light" style="font-size: 0.7rem; font-weight: bold; border: 1px solid #ccc;">
🎵 {{ page.bpm }} BPM
</span>
</div>
{% else %}
<div class="mb-3" style="height: 24px;"></div>
{% endif %}
{% endif %}
</div>
<div style="flex: 1;"></div>
@ -249,11 +287,9 @@ permalink: /projetos/
<span class="icon is-small chevron"><i class="fa-solid fa-chevron-down"></i></span>
</summary>
<div class="tags is-centered mt-1 mb-2 px-1" style="gap: 3px;">
{% for tag in unique_insts_page %}
{% if tag != "" %}
<a href="{{ '/instruments/?instrument=' | append: tag | relative_url }}" class="tag is-light is-info clickable-tag">{{ tag | truncate: 18 }}</a>
{% endif %}
{% endfor %}
{% for tag in unique_insts_page %}{% if tag != "" %}
<a href="{{ '/instruments/?instrument=' | append: tag | relative_url }}" class="tag is-light is-info clickable-tag">{{ tag | truncate: 18 }}</a>
{% endif %}{% endfor %}
</div>
</details>
{% endif %}
@ -285,35 +321,6 @@ permalink: /projetos/
</div>
</details>
{% endif %}
{% if page.tags.automation and page.tags.automation.size > 0 %}
<details class="category-reveal mb-1" style="width: 100%;">
<summary class="tag is-white summary-btn">
<div class="tag-label"><span>🎚️</span> <span class="tag-text">AUTOMATION</span></div>
<span class="icon is-small chevron"><i class="fa-solid fa-chevron-down"></i></span>
</summary>
<div class="tags is-centered mt-1 mb-2 px-1" style="gap: 3px;">
{% for tag in page.tags.automation %}{% if tag != "" %}
<a href="{{ '/automation/?automation=' | append: tag | relative_url }}" class="tag is-light is-info clickable-tag">{{ tag | truncate: 18 }}</a>
{% endif %}{% endfor %}
</div>
</details>
{% endif %}
{% if page.tags.sample and page.tags.sample.size > 0 %}
<details class="category-reveal mb-1" style="width: 100%;">
<summary class="tag is-white summary-btn">
<div class="tag-label"><span>🎤</span> <span class="tag-text">SAMPLES</span></div>
<span class="icon is-small chevron"><i class="fa-solid fa-chevron-down"></i></span>
</summary>
<div class="tags is-centered mt-1 mb-2 px-1" style="gap: 3px;">
{% for tag in page.tags.sample %}{% if tag != "" %}
<a href="{{ '/sample/?sample=' | append: tag | relative_url }}" class="tag is-light is-info clickable-tag">{{ tag | truncate: 18 }}</a>
{% endif %}{% endfor %}
</div>
</details>
{% endif %}
</div>
</div>
</a>
@ -324,19 +331,17 @@ permalink: /projetos/
data-modal-title="Detalhes: {{ page.file }}"
data-full-btn-text="Ir para Página"
data-full-btn-link="{{ page.url | relative_url }}"
style="color: #5b7da3; font-size: 0.8rem; font-weight: 600; border-right: 1px solid #eee; transition: background 0.2s;">
style="color: #5b7da3; font-size: 0.8rem; font-weight: 600; border-right: 1px solid #eee;">
Ver
</a>
{% assign creation_url = '/mmpSearch/creation.html?project=' | append: page.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: {{ page.file }}"
data-full-btn-text="Abrir Editor"
data-full-btn-link="{{ creation_url }}"
style="color: #3273dc; font-size: 0.8rem; font-weight: 600; transition: background 0.2s;">
style="color: #3273dc; font-size: 0.8rem; font-weight: 600;">
Editar
</a>
</footer>
@ -349,7 +354,7 @@ permalink: /projetos/
<div id="no-results" class="has-text-centered is-hidden mt-6">
<span class="icon is-large has-text-grey-light"><i class="fa-solid fa-face-frown fa-3x"></i></span>
<p class="subtitle mt-3 has-text-grey">Nenhum projeto encontrado com essa combinação.</p>
<p class="subtitle mt-3 has-text-grey">Nenhum projeto encontrado.</p>
<button class="button is-small is-info mt-2" onclick="document.getElementById('reset-all-filters').click()">Limpar Filtros</button>
</div>
@ -361,7 +366,7 @@ permalink: /projetos/
{% include preview-modal.html %}
<style>
/* Estilos do Filtro Lateral */
/* Estilos Gerais */
.clickable-summary { cursor: pointer; user-select: none; }
.clickable-summary:hover { color: #3273dc; }
.tag.is-checked { background-color: #3273dc !important; color: #fff !important; border-color: #3273dc !important; }
@ -370,18 +375,13 @@ permalink: /projetos/
.filter-content::-webkit-scrollbar-track { background: #f1f1f1; }
.filter-content::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
/* Estilos do Card */
.project-card:hover { transform: translateY(-5px); box-shadow: 0 8px 20px rgba(50, 115, 220, 0.15); border-color: #3273dc !important; }
/* Tags nos Cards */
.category-reveal summary { list-style: none; transition: all 0.2s ease; }
.category-reveal summary::-webkit-details-marker { display: none; }
.summary-btn {
width: 100%; justify-content: space-between; cursor: pointer;
border: 1px solid #deeaf6; color: #5b7da3; padding: 2px 8px;
min-height: 22px; margin-bottom: 2px; display: flex !important;
}
.summary-btn { width: 100%; justify-content: space-between; cursor: pointer; border: 1px solid #deeaf6; color: #5b7da3; padding: 2px 8px; min-height: 22px; margin-bottom: 2px; display: flex !important; }
.tag-label { display: flex; align-items: center; gap: 6px; }
.tag-text { font-weight: 700; font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.5px; }
.chevron { font-size: 0.6rem; opacity: 0.7; transition: transform 0.2s ease; }
@ -390,128 +390,314 @@ permalink: /projetos/
.category-reveal[open] summary { background-color: #eef6fc !important; border-color: #3273dc !important; color: #3273dc !important; }
.category-reveal[open] summary .chevron { transform: rotate(180deg); }
.clickable-tag {
font-size: 0.6rem; height: 1.5em; border: 1px solid #cfe8fc;
text-decoration: none; padding: 0 6px; transition: all 0.2s ease;
}
.clickable-tag:hover {
background-color: #3273dc !important; color: #fff !important;
border-color: #3273dc !important; transform: translateY(-1px);
}
.clickable-tag { font-size: 0.6rem; height: 1.5em; border: 1px solid #cfe8fc; text-decoration: none; padding: 0 6px; transition: all 0.2s ease; }
.clickable-tag:hover { background-color: #3273dc !important; color: #fff !important; border-color: #3273dc !important; transform: translateY(-1px); }
/* Estilos Novos (Filtro Superior) */
.transition-icon i { transition: transform 0.3s ease; }
.border-tag { border: 1px solid #dbdbdb; color: #555; }
#genre-filters .button { margin-bottom: 0.5rem; transition: all 0.2s; }
#genre-filters .button:not(.is-active) { background-color: white; border-color: #dbdbdb; color: #363636; }
#genre-filters .button.is-active { box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
// --- 1. ELEMENTOS DOM ---
const checkboxes = document.querySelectorAll('.filter-checkbox');
const searchInput = document.getElementById('search-input');
// Inputs de BPM
const bpmMinInput = document.getElementById('bpm-min');
const bpmMaxInput = document.getElementById('bpm-max');
const projects = document.querySelectorAll('.project-item');
const resetBtn = document.getElementById('reset-all-filters');
const countBar = document.getElementById('results-count-bar');
const countSpan = document.getElementById('visible-count');
const noResults = document.getElementById('no-results');
// Filtros Superiores (Novos)
const genreContainer = document.getElementById('genre-filters');
const starFilterSelect = document.getElementById('star-filter');
const keyFilterSelect = document.getElementById('key-filter');
const sortSelect = document.getElementById('sort-select');
const projectsContainer = document.getElementById('project-list');
const filterBtn = document.getElementById('filter-toggle-btn');
const filterContent = document.getElementById('filter-content');
const filterChevron = document.getElementById('filter-chevron');
// Estado do Filtro
let activeFilters = { instruments: [], plugins: [], samples: [], bassline: [], automation: [] };
// Estado Global
let activeSidebar = { instruments: [], plugins: [], samples: [], bassline: [], automation: [] };
let activeGenres = [];
let currentMinStars = 'all';
let currentKey = 'all';
let searchText = "";
// Valores Iniciais de BPM
let initialMinBpm = parseInt(bpmMinInput.value) || 0;
let initialMaxBpm = parseInt(bpmMaxInput.value) || 999;
// JSON de Análise
const JSON_URL = '/mmpSearch/src_mmpSearch/saida_analises/db_final_completo.json';
function updateState() {
// Reseta Arrays (menos BPM que é tratado separado)
activeFilters = { instruments: [], plugins: [], samples: [], bassline: [], automation: [] };
// Lê Checkboxes
checkboxes.forEach(cb => {
if (cb.checked) {
const category = cb.getAttribute('data-category');
// BPM não usa checkbox mais, mas mantive a segurança
if (activeFilters[category]) activeFilters[category].push(cb.value);
if(cb.parentElement.classList.contains('tag')) cb.parentElement.classList.add('is-checked');
} else {
if(cb.parentElement.classList.contains('tag')) cb.parentElement.classList.remove('is-checked');
}
});
// --- 2. LÓGICA DE INTERFACE (Toggle Menu) ---
let isFilterOpen = window.innerWidth > 1024;
function updateFilterState() {
if(isFilterOpen) {
filterContent.style.display = 'block';
filterChevron.style.transform = 'rotate(180deg)';
} else {
filterContent.style.display = 'none';
filterChevron.style.transform = 'rotate(0deg)';
}
}
if(filterBtn) filterBtn.addEventListener('click', () => { isFilterOpen = !isFilterOpen; updateFilterState(); });
updateFilterState();
// Lê Campo de Texto (IA Filter)
searchText = searchInput.value.toLowerCase().trim();
// --- 3. FETCH E ENRIQUECIMENTO DOS CARDS ---
fetch(JSON_URL)
.then(r => r.ok ? r.json() : [])
.then(data => {
enrichCards(data);
createGenreButtons(data);
applyGlobalFilters(); // Reaplica filtros após carregar dados
})
.catch(console.warn);
applyFilters();
function normalizarChaveJS(str) {
if (!str) return "";
return str.toString().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]/g, "");
}
function applyFilters() {
function renderizarDificuldade(num) {
const n = Math.round(num) || 1;
let label = "Básico", icon = "fa-leaf", color = "is-success";
if (n >= 4.5) { label = "Expert"; icon = "fa-fire"; color = "is-danger"; }
else if (n >= 3.5) { label = "Avançado"; icon = "fa-bolt"; color = "is-warning"; }
else if (n >= 2.5) { label = "Médio"; icon = "fa-layer-group"; color = "is-info"; }
return `<span class="tag ${color} is-light is-rounded" title="Complexidade: ${n}/5" style="border: 1px solid rgba(0,0,0,0.1);"><i class="fa-solid ${icon} mr-1"></i> ${label}</span>`;
}
function enrichCards(data) {
const mapDados = {};
data.forEach(item => {
if(item.arquivo) mapDados[normalizarChaveJS(item.arquivo.replace('.wav','').replace('.mp3',''))] = item;
if(item.dados_projeto?.titulo) mapDados[normalizarChaveJS(item.dados_projeto.titulo)] = item;
});
document.querySelectorAll('.project-item').forEach(item => {
const card = item.querySelector('.project-card');
const titleKey = normalizarChaveJS(item.getAttribute('data-title'));
const info = mapDados[titleKey];
// Padrões
let genero = "Unknown", subgeneros = [], estrelas = 0, intensidade = -100, bpm = 0, tomHtml = "", tomRaw = "all", subTagsHTML = "";
if (info) {
// Dados IA
if (info.analise_ia) {
genero = info.analise_ia.genero_macro || "Unknown";
if (Array.isArray(info.analise_ia.nuvem_tags)) {
info.analise_ia.nuvem_tags.forEach(t => { if(t.tag) subgeneros.push(t.tag); });
info.analise_ia.nuvem_tags.slice(0, 2).forEach(t => {
subTagsHTML += `<span class="tag is-white is-rounded border-tag" title="IA: ${Math.round(t.score*100)}%" style="font-size: 0.65rem; color: #666; margin-right: 2px;">#${t.tag}</span>`;
});
}
}
// Dados Técnicos
if (info.analise_tecnica) {
intensidade = parseFloat(info.analise_tecnica.intensidade_db || -100);
bpm = parseFloat(info.analise_tecnica.bpm || 0);
estrelas = Math.round(info.analise_tecnica.complexidade?.estrelas || 0);
if (info.analise_tecnica.tom) {
const t = info.analise_tecnica.tom;
const e = info.analise_tecnica.escala === 'minor' ? 'm' : '';
tomRaw = t + e;
tomHtml = `<span class="tag is-white is-rounded border-tag" title="Tom">🎹 ${tomRaw}</span>`;
}
}
}
// Injeta dados no elemento para filtragem
item.setAttribute('data-genre', genero);
item.setAttribute('data-subgenres', subgeneros.join(',').toLowerCase());
item.setAttribute('data-stars', estrelas);
item.setAttribute('data-intensity', intensidade);
item.setAttribute('data-key', tomRaw);
if(bpm > 0) item.setAttribute('data-bpm-real', bpm); // BPM Real do áudio se disponível
// Atualiza Visual do Card (BPM Container)
const bpmContainer = card.querySelector('.bpm-container');
if(bpmContainer) {
const existingBpm = bpmContainer.innerHTML;
let newHtml = `<div class="mt-2" style="display:flex; flex-direction:column; align-items:center; gap:4px;">`;
newHtml += `<div>${renderizarDificuldade(estrelas)}</div>`;
newHtml += `<div class="tags is-centered mb-0" style="gap:4px;">`;
if(genero !== "Unknown") {
let c = 'is-primary';
if(genero === 'Electronic') c = 'is-info';
if(genero === 'Hip Hop') c = 'is-warning';
if(genero === 'Rock') c = 'is-danger';
newHtml += `<span class="tag ${c} is-light is-rounded" style="font-size: 0.7rem;">🤖 ${genero}</span>`;
}
newHtml += tomHtml;
newHtml += `</div>`;
if(subTagsHTML) newHtml += `<div style="display:flex; flex-wrap:wrap; justify-content:center; gap:2px;">${subTagsHTML}</div>`;
newHtml += `</div>`;
bpmContainer.innerHTML = existingBpm + newHtml;
}
});
}
function createGenreButtons(data) {
const genres = new Set();
data.forEach(i => {
if(i.analise_ia?.genero_macro && i.analise_ia.genero_macro !== "Unknown") genres.add(i.analise_ia.genero_macro);
if(Array.isArray(i.analise_ia?.nuvem_tags)) i.analise_ia.nuvem_tags.forEach(t => genres.add(t.tag));
});
Array.from(genres).sort().forEach(g => {
const btn = document.createElement('button');
btn.className = 'button is-small is-rounded is-white';
btn.textContent = g;
btn.onclick = () => {
const allBtn = document.querySelector('[data-genre="all"]');
if(allBtn) { allBtn.classList.remove('is-active', 'is-info'); allBtn.classList.add('is-white'); }
if(activeGenres.includes(g)) {
activeGenres = activeGenres.filter(x => x !== g);
btn.classList.remove('is-active', 'is-info'); btn.classList.add('is-white');
} else {
activeGenres.push(g);
btn.classList.remove('is-white'); btn.classList.add('is-active', 'is-info');
}
if(activeGenres.length === 0) document.querySelector('[data-genre="all"]').click();
else applyGlobalFilters();
};
genreContainer.appendChild(btn);
});
const allBtn = document.querySelector('[data-genre="all"]');
allBtn.onclick = () => {
activeGenres = [];
document.querySelectorAll('#genre-filters .button').forEach(b => {
b.classList.remove('is-active', 'is-info'); b.classList.add('is-white');
});
allBtn.classList.remove('is-white'); allBtn.classList.add('is-active', 'is-info');
applyGlobalFilters();
}
}
// --- 4. FILTRAGEM UNIFICADA (A Mágica acontece aqui) ---
function applyGlobalFilters() {
let visibleCount = 0;
// Lê valores atuais do Slicer de BPM
const currentMinBpm = parseInt(bpmMinInput.value) || 0;
const currentMaxBpm = parseInt(bpmMaxInput.value) || 999;
// Valores Sidebar
const minBpm = parseInt(bpmMinInput.value) || 0;
const maxBpm = parseInt(bpmMaxInput.value) || 999;
document.querySelectorAll('.project-item').forEach(item => {
// Leitura de Dados (Unificada)
const pName = item.getAttribute('data-name') || "";
const pBpm = parseInt(item.getAttribute('data-bpm')) || 0;
const pInsts = (item.getAttribute('data-instruments') || "").split(',');
const pPlugins = (item.getAttribute('data-plugins') || "").split(',');
const pSamples = (item.getAttribute('data-samples') || "").split(',');
const pBassline = (item.getAttribute('data-bassline') || "").split(',');
const pAutomation = (item.getAttribute('data-automation') || "").split(',');
projects.forEach(project => {
// Lê dados do elemento
const pName = project.getAttribute('data-name') || "";
const pBpm = parseInt(project.getAttribute('data-bpm')) || 0;
const pInsts = (project.getAttribute('data-instruments') || "").split(',');
const pPlugins = (project.getAttribute('data-plugins') || "").split(',');
const pSamples = (project.getAttribute('data-samples') || "").split(',');
const pBassline = (project.getAttribute('data-bassline') || "").split(',');
const pAutomation = (project.getAttribute('data-automation') || "").split(',');
// Dados Novos (IA)
const pGenre = (item.getAttribute('data-genre') || "").toLowerCase();
const pSubs = (item.getAttribute('data-subgenres') || "").toLowerCase();
const pTagsIA = pGenre + "," + pSubs;
const pStars = parseInt(item.getAttribute('data-stars') || 0);
const pKey = item.getAttribute('data-key') || 'all';
// 1. Checa SLICER DE BPM (Lógica de Intervalo)
const matchBpm = (pBpm >= currentMinBpm && pBpm <= currentMaxBpm);
// 2. Checa Filtros de Categoria (Checkbox)
const matchInst = activeFilters.instruments.length === 0 || activeFilters.instruments.some(f => pInsts.includes(f));
const matchPlugin = activeFilters.plugins.length === 0 || activeFilters.plugins.some(f => pPlugins.includes(f));
const matchSample = activeFilters.samples.length === 0 || activeFilters.samples.some(f => pSamples.includes(f));
const matchBassline = activeFilters.bassline.length === 0 || activeFilters.bassline.some(f => pBassline.includes(f));
const matchAutomation = activeFilters.automation.length === 0 || activeFilters.automation.some(f => pAutomation.includes(f));
// 3. Checa Busca de Texto (IA Filter)
const fullMeta = [pName, pBpm.toString(), pInsts.join(' '), pPlugins.join(' '), pSamples.join(' '), pBassline.join(' '), pAutomation.join(' ')].join(' ').toLowerCase();
// --- CHECAGEM ---
// 1. Sidebar (Checkboxes)
const matchInst = activeSidebar.instruments.length === 0 || activeSidebar.instruments.some(f => pInsts.includes(f));
const matchPlugin = activeSidebar.plugins.length === 0 || activeSidebar.plugins.some(f => pPlugins.includes(f));
const matchSample = activeSidebar.samples.length === 0 || activeSidebar.samples.some(f => pSamples.includes(f));
const matchBassline = activeSidebar.bassline.length === 0 || activeSidebar.bassline.some(f => pBassline.includes(f));
const matchAuto = activeSidebar.automation.length === 0 || activeSidebar.automation.some(f => pAutomation.includes(f));
// 2. Sidebar (BPM Slicer)
const matchBpm = (pBpm >= minBpm && pBpm <= maxBpm);
// 3. Texto
const fullMeta = [pName, pBpm, pInsts, pPlugins, pTagsIA].join(' ').toLowerCase();
const matchText = searchText === "" || fullMeta.includes(searchText);
if (matchBpm && matchInst && matchPlugin && matchSample && matchBassline && matchAutomation && matchText) {
project.style.display = 'block';
// 4. Novos Filtros (IA)
let matchGenre = true;
if(activeGenres.length > 0) {
matchGenre = activeGenres.some(g => pTagsIA.includes(g.toLowerCase()));
}
const matchStars = (currentMinStars === 'all' || pStars === parseInt(currentMinStars));
const matchKey = (currentKey === 'all' || pKey === currentKey);
// RESULTADO FINAL
if (matchInst && matchPlugin && matchSample && matchBassline && matchAuto && matchBpm && matchText && matchGenre && matchStars && matchKey) {
item.style.display = 'block';
visibleCount++;
} else {
project.style.display = 'none';
item.style.display = 'none';
}
});
countSpan.textContent = visibleCount;
countBar.classList.toggle('is-hidden', visibleCount >= projects.length);
countBar.classList.toggle('is-hidden', visibleCount >= document.querySelectorAll('.project-item').length);
noResults.classList.toggle('is-hidden', visibleCount > 0);
}
// Eventos
checkboxes.forEach(cb => cb.addEventListener('change', updateState));
searchInput.addEventListener('input', updateState);
bpmMinInput.addEventListener('input', updateState);
bpmMaxInput.addEventListener('input', updateState);
// Suporte para parâmetros de URL (q=...)
const urlParams = new URLSearchParams(window.location.search);
const qParam = urlParams.get('q');
if(qParam) {
searchInput.value = qParam;
updateState();
}
resetBtn.addEventListener('click', () => {
checkboxes.forEach(cb => {
cb.checked = false;
if(cb.parentElement.classList.contains('tag')) cb.parentElement.classList.remove('is-checked');
// --- 5. EVENT LISTENERS ---
// Sidebar Listeners
checkboxes.forEach(cb => cb.addEventListener('change', () => {
// Atualiza objeto activeSidebar
activeSidebar = { instruments: [], plugins: [], samples: [], bassline: [], automation: [] };
checkboxes.forEach(bx => {
if(bx.checked) {
activeSidebar[bx.dataset.category].push(bx.value);
if(bx.parentElement.classList.contains('tag')) bx.parentElement.classList.add('is-checked');
} else {
if(bx.parentElement.classList.contains('tag')) bx.parentElement.classList.remove('is-checked');
}
});
searchInput.value = "";
// Reseta BPM para os valores iniciais da página
bpmMinInput.value = initialMinBpm;
bpmMaxInput.value = initialMaxBpm;
updateState();
applyGlobalFilters();
}));
searchInput.addEventListener('input', (e) => { searchText = e.target.value.toLowerCase().trim(); applyGlobalFilters(); });
bpmMinInput.addEventListener('input', applyGlobalFilters);
bpmMaxInput.addEventListener('input', applyGlobalFilters);
// Top Bar Listeners
if(starFilterSelect) starFilterSelect.addEventListener('change', (e) => { currentMinStars = e.target.value; applyGlobalFilters(); });
if(keyFilterSelect) keyFilterSelect.addEventListener('change', (e) => { currentKey = e.target.value; applyGlobalFilters(); });
// Ordenação
if(sortSelect) sortSelect.addEventListener('change', (e) => {
const crit = e.target.value;
const cols = Array.from(projectsContainer.children);
cols.sort((a, b) => {
const getVal = (el, k) => parseFloat(el.getAttribute(k) || 0);
if(crit === 'stars_desc') return getVal(b, 'data-stars') - getVal(a, 'data-stars');
if(crit === 'stars_asc') return getVal(a, 'data-stars') - getVal(b, 'data-stars');
if(crit === 'bpm_desc') return getVal(b, 'data-bpm-real') - getVal(a, 'data-bpm-real');
if(crit === 'intensity_desc') return getVal(b, 'data-intensity') - getVal(a, 'data-intensity');
if(crit === 'intensity_asc') return getVal(a, 'data-intensity') - getVal(b, 'data-intensity');
return a.getAttribute('data-title').localeCompare(b.getAttribute('data-title'));
});
cols.forEach(c => projectsContainer.appendChild(c));
});
// Reset Total
resetBtn.addEventListener('click', () => {
checkboxes.forEach(cb => { cb.checked = false; cb.parentElement.classList.remove('is-checked'); });
activeSidebar = { instruments: [], plugins: [], samples: [], bassline: [], automation: [] };
searchInput.value = ""; searchText = "";
bpmMinInput.value = 0; bpmMaxInput.value = 300;
document.querySelector('[data-genre="all"]').click();
starFilterSelect.value = 'all'; currentMinStars = 'all';
keyFilterSelect.value = 'all'; currentKey = 'all';
applyGlobalFilters();
});
// --- Modal Logic (Preview) ---
@ -520,35 +706,23 @@ document.addEventListener('DOMContentLoaded', function () {
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');
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 = "";
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);
});
btn.addEventListener('click', (e) => { e.preventDefault(); openModal(btn.dataset.targetUrl, btn.dataset.modalTitle, btn.dataset.fullBtnText, btn.dataset.fullBtnLink); });
});
if(iframe) {
iframe.addEventListener('load', () => { try {
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
const style = iframeDoc.createElement('style');
style.textContent = `.tabs, .navbar, .sidebar-wrapper, .main-header { display: none !important; } .publication { padding-top: 0 !important; } body { background-color: #fff !important; }`;
iframeDoc.head.appendChild(style);
} catch(e){} });
if(iframe) { iframe.addEventListener('load', () => { try {
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
const style = iframeDoc.createElement('style');
style.textContent = `.tabs, .navbar, .sidebar-wrapper, .main-header { display: none !important; } .publication { padding-top: 0 !important; } body { background-color: #fff !important; }`;
iframeDoc.head.appendChild(style); } catch(e){} });
}
closeButtons.forEach(el => el.addEventListener('click', closeModal));
document.addEventListener('keydown', (e) => { if (e.key === "Escape") closeModal(); });