Files
jhonny-editor/code/cep-plugin/abas/projeto/projeto.js
T
João Henrique 5644b42722 feat: carregamento automático da análise do Scanner ao abrir a aba
- carregamento automático da análise do Scanner ao abrir a aba Refinar
- simplificada a aba Editar vídeo para exibir análises disponíveis sem carregamento manual
- movida a visualização do tipo de vídeo para a guia Projeto com leitura do banco

Resumo:
- 10 arquivos alterados
- 2 novos
- 8 modificados
- 0 removidos

 8 files changed, 114 insertions(+), 11 deletions(-)

Arquivos:
  - .jhonny/analises.db
  - code/cep-plugin/abas/projeto/projeto.js
  - code/cep-plugin/index.html
  - code/cep-plugin/main.js
  - code/engine/integracoes/audio/__init__.py
  - code/engine/integracoes/audio/modelos_de_analise_musical.py
  - code/engine/integracoes/audio/provider_de_analise_musical_essentia.py
  - code/engine/testes/test_analisador_de_musica_essentia.py
  - code/engine/consultar_edicao_concluida.py
  - code/engine/integracoes/audio/classificador_de_musica_essentia.py
2026-09-10 13:30:10 -04:00

143 lines
8.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
// A guia Projeto mantém a seleção da sequência, faixas e clipes fora das
// regras específicas de edição. O estado definitivo será persistido pelo
// repositório SQLite na próxima etapa da integração.
var projetoSequencias = [];
var projetoAtual = null;
function projetoListarSequencias() {
var botao = document.getElementById("btnProjetoCarregar");
if (botao) botao.disabled = true;
var select = document.getElementById("projetoSequenciaSelect");
var info = document.getElementById("projetoInfo");
info.textContent = "Lendo sequências, faixas e clipes do Premiere…";
cs.evalScript(
"(function(){try{" +
"if(!app.project)return JSON.stringify({ok:false,error:'Nenhum projeto aberto.'});" +
"var saida=[];" +
"for(var i=0;i<app.project.sequences.numSequences;i++){" +
"var s=app.project.sequences[i], faixas=[];" +
"for(var v=0;v<s.videoTracks.numTracks;v++){var tv=s.videoTracks[v],cv=[];for(var j=0;j<tv.clips.numItems;j++){var x=tv.clips[j];cv.push({id:String(x.nodeId),nome:String(x.name||''),inicio:Number(x.start.seconds),fim:Number(x.end.seconds)});}faixas.push({id:'video_'+v,nome:'Vídeo '+(v+1),tipo:'video',indice:v,clipes:cv});}" +
"for(var a=0;a<s.audioTracks.numTracks;a++){var ta=s.audioTracks[a],ca=[];for(var k=0;k<ta.clips.numItems;k++){var y=ta.clips[k];ca.push({id:String(y.nodeId),nome:String(y.name||''),inicio:Number(y.start.seconds),fim:Number(y.end.seconds)});}faixas.push({id:'audio_'+a,nome:'Áudio '+(a+1),tipo:'audio',indice:a,clipes:ca});}" +
"saida.push({id:String(s.sequenceID),nome:String(s.name||''),duracao:Number(s.end.seconds||0),largura:Number(s.frameSizeHorizontal||0),altura:Number(s.frameSizeVertical||0),ativa:!!(app.project.activeSequence&&s.sequenceID===app.project.activeSequence.sequenceID),faixas:faixas});" +
"}return JSON.stringify({ok:true,sequences:saida});}catch(e){return JSON.stringify({ok:false,error:String(e)});}}())",
function (raw) {
if (botao) botao.disabled = false;
var resposta;
try { resposta = JSON.parse(raw); } catch (erro) { resposta = {ok: false, error: "Resposta inválida do Premiere."}; }
if (!resposta.ok) { info.textContent = resposta.error; return; }
projetoSequencias = resposta.sequences || [];
select.innerHTML = "";
projetoSequencias.forEach(function (sequencia) {
var opcao = document.createElement("option");
opcao.value = sequencia.id;
opcao.textContent = sequencia.nome + (sequencia.ativa ? " · ativa" : "");
select.appendChild(opcao);
});
select.disabled = projetoSequencias.length === 0;
if (projetoSequencias.length) {
var ativa = projetoSequencias.findIndex(function (item) { return item.ativa; });
select.selectedIndex = ativa >= 0 ? ativa : 0;
projetoSelecionarSequencia();
} else {
info.textContent = "Nenhuma sequência encontrada no projeto do Premiere.";
}
}
);
}
function projetoSelecionarSequencia() {
var select = document.getElementById("projetoSequenciaSelect");
projetoAtual = projetoSequencias.find(function (item) { return item.id === select.value; }) || null;
if (!projetoAtual) return;
document.getElementById("projetoTimelineCard").hidden = false;
document.getElementById("projetoStatus").textContent = "Sequência selecionada";
document.getElementById("projetoTimelineStatus").textContent = projetoAtual.nome;
document.getElementById("projetoDuracao").textContent = formatSequenceDuration(projetoAtual.duracao);
document.getElementById("projetoResolucao").textContent = projetoAtual.largura && projetoAtual.altura ? projetoAtual.largura + " × " + projetoAtual.altura : "Não informada";
document.getElementById("projetoTotalFaixas").textContent = projetoAtual.faixas.length;
document.getElementById("projetoTotalClipes").textContent = projetoAtual.faixas.reduce(function (total, faixa) { return total + faixa.clipes.length; }, 0);
var container = document.getElementById("projetoFaixas");
container.innerHTML = "";
projetoAtual.faixas.forEach(function (faixa) {
var bloco = document.createElement("div");
bloco.className = "scanner-subsection";
bloco.innerHTML = '<label class="checkbox-field"><input type="checkbox" checked data-projeto-faixa="' + faixa.id + '"><span>' + faixa.nome + " · " + faixa.clipes.length + " clipe(s)</span></label>";
faixa.clipes.forEach(function (clipe) {
bloco.innerHTML += '<label class="checkbox-field" style="padding-left:24px"><input type="checkbox" checked data-projeto-clipe="' + clipe.id + '"><span>' + clipe.nome + " · " + formatSequenceDuration(clipe.fim - clipe.inicio) + "</span></label>";
});
container.appendChild(bloco);
});
document.getElementById("btnProjetoContinuar").disabled = false;
document.getElementById("btnProjetoSalvar").disabled = false;
projetoCarregarTipoDeVideo();
document.getElementById("projetoInfo").textContent = "A sequência foi carregada. Selecione as faixas e clipes que participarão do plano.";
}
function projetoCarregarTipoDeVideo() {
var select = document.getElementById("projetoTipoVideoSelect");
var info = document.getElementById("projetoTipoVideoInfo");
select.disabled = true;
runStreamed(SCANNER_PYTHON_BIN, [CONSULTAR_EDICAO_SCRIPT, projetoAtual.id, "--banco", ANALISES_DB_PATH],
function () {},
function (codigo, ultimoErro, ultimaSaida) {
if (codigo !== 0) { info.textContent = ultimoErro || "Nenhum tipo de vídeo salvo para esta sequência."; return; }
try {
var edicao = JSON.parse(ultimaSaida).edicao;
var tipos = tiposVideoLer().filter(function (item) { return item.ativo !== false; });
var tipo = tipos.filter(function (item) { return item.id === edicao.tipo_de_video; })[0];
select.innerHTML = "";
tipos.forEach(function (item) {
var opcao = document.createElement("option");
opcao.value = item.id;
opcao.textContent = item.nome;
select.appendChild(opcao);
});
if (!tipo) {
var tipoDesconhecido = document.createElement("option");
tipoDesconhecido.value = edicao.tipo_de_video;
tipoDesconhecido.textContent = edicao.tipo_de_video;
select.appendChild(tipoDesconhecido);
}
select.value = edicao.tipo_de_video;
select.disabled = false;
silenceState.tipoVideoId = edicao.tipo_de_video;
silenceState.tipoVideo = tipo || null;
info.textContent = "Tipo carregado da edição concluída mais recente.";
} catch (erro) { info.textContent = "Não foi possível interpretar o tipo salvo: " + erro.message; }
});
}
function projetoSelecionarTipoVideo() {
var tipo = tiposVideoLer().filter(function (item) { return item.id === document.getElementById("projetoTipoVideoSelect").value; })[0] || null;
silenceState.tipoVideoId = tipo ? tipo.id : null;
silenceState.tipoVideo = tipo;
document.getElementById("projetoTipoVideoInfo").textContent = tipo ? tipo.nome + " · disponível para a edição." : "Nenhum tipo selecionado.";
}
function projetoSalvar() {
if (!projetoAtual) return;
var faixas = Array.prototype.slice.call(document.querySelectorAll("[data-projeto-faixa]:checked")).map(function (item) { return item.getAttribute("data-projeto-faixa"); });
var clipes = Array.prototype.slice.call(document.querySelectorAll("[data-projeto-clipe]:checked")).map(function (item) { return item.getAttribute("data-projeto-clipe"); });
var pedido = path.join(os.tmpdir(), "pedido-projeto-edicao-" + Date.now() + ".json");
fs.writeFileSync(pedido, JSON.stringify({
nome: projetoAtual.nome, video_id: projetoAtual.id, faixas: faixas, clipes: clipes,
}, null, 2), "utf-8");
setBusy("btnProjetoSalvar", true);
runStreamed(SCANNER_PYTHON_BIN, [REGISTRAR_PROJETO_SCRIPT, pedido, "--banco", ANALISES_DB_PATH],
function (linha) { silenceLog(linha); },
function (codigo, ultimoErro) {
setBusy("btnProjetoSalvar", false);
if (codigo !== 0) { showToast("err", ultimoErro || "Não foi possível salvar o projeto."); return; }
document.getElementById("projetoStatus").textContent = "Projeto salvo no banco";
showToast("ok", "Projeto salvo com " + faixas.length + " faixa(s) e " + clipes.length + " clipe(s).");
});
}
function projetoContinuarEdicao() {
if (!projetoAtual) return;
switchTab("silence");
silenceListSequences();
}