sync mode on

This commit is contained in:
JotaChina committed 2025-10-26 16:43:01 -03:00
1 parent 1818932244
commit 1174b328e5
415 files changed
+44294 -1182

No files matched your search

+35 -8
View File
@@ -4,6 +4,10 @@ import { loadAudioForTrack } from "./pattern/pattern_state.js";
import { renderAll, getSamplePathMap } from "./ui.js";
import { DEFAULT_PAN, DEFAULT_VOLUME, NOTE_LENGTH } from "./config.js";
import { initializeAudioContext, getAudioContext, getMainGainNode } from "./audio.js";
import * as Tone from "https://esm.sh/tone";
// --- NOVA IMPORTAÇÃO ---
import { sendAction } from "./socket.js";
export async function handleFileLoad(file) {
let xmlContent = "";
@@ -20,7 +24,12 @@ export async function handleFileLoad(file) {
} else {
xmlContent = await file.text();
}
await parseMmpContent(xmlContent);
// ANTES: await parseMmpContent(xmlContent);
// DEPOIS:
// Envia o XML para o servidor, que o transmitirá para todos (incluindo nós)
sendAction({ type: 'LOAD_PROJECT', xml: xmlContent });
} catch (error) {
console.error("Erro ao carregar o projeto:", error);
alert(`Erro ao carregar projeto: ${error.message}`);
@@ -34,8 +43,16 @@ export async function loadProjectFromServer(fileName) {
throw new Error(`Não foi possível carregar o arquivo ${fileName}`);
const xmlContent = await response.text();
await parseMmpContent(xmlContent);
return true;
// ANTES:
// await parseMmpContent(xmlContent);
// return true;
// DEPOIS:
// Envia o XML para o servidor
sendAction({ type: 'LOAD_PROJECT', xml: xmlContent });
return true; // Retorna true para que o modal de UI feche
} catch (error) {
console.error("Erro ao carregar projeto do servidor:", error);
console.error(error);
@@ -44,6 +61,10 @@ export async function loadProjectFromServer(fileName) {
}
}
// --- NENHUMA MUDANÇA DAQUI PARA BAIXO ---
// 'parseMmpContent' agora é chamado pelo 'socket.js'
// quando ele recebe a ação 'LOAD_PROJECT' ou 'load_project_state'.
export async function parseMmpContent(xmlString) {
resetProjectState();
initializeAudioContext();
@@ -175,12 +196,12 @@ export async function parseMmpContent(xmlString) {
let isFirstTrackWithNotes = true;
newTracks.forEach(track => {
// --- INÍCIO DA CORREÇÃO ---
// Cria os nós de áudio usando os construtores do Tone.js
track.gainNode = new Tone.Gain(Tone.gainToDb(track.volume));
// Agora usando Volume em dB (Opção B)
track.volumeNode = new Tone.Volume(Tone.gainToDb(track.volume));
track.pannerNode = new Tone.Panner(track.pan);
// Conecta a cadeia de áudio: Gain -> Panner -> Saída Principal (Destination)
track.gainNode.connect(track.pannerNode);
// Cadeia de áudio: Volume(dB) -> Panner -> Saída Principal
track.volumeNode.connect(track.pannerNode);
track.pannerNode.connect(getMainGainNode());
// --- FIM DA CORREÇÃO ---
@@ -206,7 +227,13 @@ export async function parseMmpContent(xmlString) {
appState.pattern.tracks = newTracks;
appState.pattern.activeTrackId = appState.pattern.tracks[0]?.id || null;
// força atualização total da UI e dos editores de pattern
await Promise.resolve(); // garante que os tracks estejam no estado
renderAll();
console.log('[UI] Projeto renderizado após parseMmpContent');
}
export function generateMmpFile() {
@@ -314,4 +341,4 @@ function downloadFile(content, fileName) {
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
}