adicionando instrumentos no editor de patterns
Deploy / Deploy (push) Successful in 1m57s
Details
Deploy / Deploy (push) Successful in 1m57s
Details
This commit is contained in:
parent
6fb1bd425e
commit
96a7bd3f3c
|
|
@ -202,27 +202,58 @@ export async function loadAudioForTrack(track) {
|
||||||
|
|
||||||
export function addTrackToState() {
|
export function addTrackToState() {
|
||||||
const totalSteps = getTotalSteps();
|
const totalSteps = getTotalSteps();
|
||||||
const referenceTrack = appState.pattern.tracks[0];
|
|
||||||
|
// ✅ define o "pai" correto pra UI conseguir renderizar
|
||||||
|
const focusedId = appState.pattern.focusedBasslineId || null;
|
||||||
|
|
||||||
|
let parentBasslineId = null;
|
||||||
|
if (focusedId) {
|
||||||
|
const basslineTrack = appState.pattern.tracks.find(
|
||||||
|
(t) => t.type === "bassline" && t.id === focusedId
|
||||||
|
);
|
||||||
|
// mesmo critério do pattern_ui: srcId = instrumentSourceId || focusedId
|
||||||
|
parentBasslineId = basslineTrack?.instrumentSourceId || focusedId;
|
||||||
|
} else {
|
||||||
|
parentBasslineId = null; // IMPORTANTÍSSIMO: não deixar undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ pega referência do mesmo pai (pra clonar patterns compatíveis)
|
||||||
|
const referenceTrack =
|
||||||
|
appState.pattern.tracks.find(
|
||||||
|
(t) =>
|
||||||
|
t.type !== "bassline" &&
|
||||||
|
(t.parentBasslineId ?? null) === parentBasslineId &&
|
||||||
|
Array.isArray(t.patterns) &&
|
||||||
|
t.patterns.length > 0
|
||||||
|
) ||
|
||||||
|
appState.pattern.tracks.find(
|
||||||
|
(t) => t.type !== "bassline" && Array.isArray(t.patterns) && t.patterns.length > 0
|
||||||
|
) ||
|
||||||
|
null;
|
||||||
|
|
||||||
const newId = Date.now() + Math.random();
|
const newId = Date.now() + Math.random();
|
||||||
|
|
||||||
const newTrack = {
|
const newTrack = {
|
||||||
id: newId,
|
id: newId,
|
||||||
name: `Novo Instrumento ${appState.pattern.tracks.length + 1}`,
|
name: `Novo Instrumento ${appState.pattern.tracks.filter(t => t.type !== "bassline").length + 1}`,
|
||||||
samplePath: null,
|
samplePath: null,
|
||||||
type: 'plugin',
|
type: "plugin",
|
||||||
|
|
||||||
|
// ✅ AQUI a chave: agora a track entra no lugar certo (rack ou root)
|
||||||
|
parentBasslineId,
|
||||||
|
|
||||||
// 🔥 CORREÇÃO: Definir instrumento padrão (Kicker) e XML
|
|
||||||
instrumentName: "kicker",
|
instrumentName: "kicker",
|
||||||
instrumentXml: DEFAULT_KICKER_XML,
|
instrumentXml: DEFAULT_KICKER_XML,
|
||||||
|
|
||||||
player: null,
|
player: null,
|
||||||
buffer: null,
|
buffer: null,
|
||||||
|
|
||||||
patterns: referenceTrack
|
patterns: referenceTrack
|
||||||
? referenceTrack.patterns.map(p => ({
|
? referenceTrack.patterns.map((p) => ({
|
||||||
name: p.name,
|
name: p.name,
|
||||||
steps: new Array(p.steps.length).fill(false),
|
steps: new Array((p.steps?.length || totalSteps)).fill(false),
|
||||||
notes: [],
|
notes: [],
|
||||||
pos: p.pos
|
pos: p.pos,
|
||||||
}))
|
}))
|
||||||
: [{ name: "Pattern 1", steps: new Array(totalSteps).fill(false), notes: [], pos: 0 }],
|
: [{ name: "Pattern 1", steps: new Array(totalSteps).fill(false), notes: [], pos: 0 }],
|
||||||
|
|
||||||
|
|
@ -236,7 +267,6 @@ export function addTrackToState() {
|
||||||
newTrack.volumeNode.connect(newTrack.pannerNode);
|
newTrack.volumeNode.connect(newTrack.pannerNode);
|
||||||
newTrack.pannerNode.connect(getMainGainNode());
|
newTrack.pannerNode.connect(getMainGainNode());
|
||||||
|
|
||||||
// Carrega o áudio (vai cair no case "kicker" do loadAudioForTrack)
|
|
||||||
loadAudioForTrack(newTrack);
|
loadAudioForTrack(newTrack);
|
||||||
|
|
||||||
appState.pattern.tracks.push(newTrack);
|
appState.pattern.tracks.push(newTrack);
|
||||||
|
|
@ -245,6 +275,7 @@ export function addTrackToState() {
|
||||||
console.log("Faixa adicionada ao estado com Kicker padrão.");
|
console.log("Faixa adicionada ao estado com Kicker padrão.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function removeTrackById(trackId) {
|
export function removeTrackById(trackId) {
|
||||||
const index = appState.pattern.tracks.findIndex(t => t.id === trackId);
|
const index = appState.pattern.tracks.findIndex(t => t.id === trackId);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue