Add presets and make graph follow selected layer/track
This commit is contained in:
+2
-2
@@ -72,7 +72,7 @@ export const defaultLayouts = {
|
||||
|
||||
audioDaw: {
|
||||
name: "Audio/DAW",
|
||||
description: "Audio tracks prominent with mixer and node editor",
|
||||
description: "Audio tracks prominent with mixer, node editor, and preset browser",
|
||||
layout: {
|
||||
type: "horizontal-grid",
|
||||
percent: 75,
|
||||
@@ -85,7 +85,7 @@ export const defaultLayouts = {
|
||||
{ type: "pane", name: "nodeEditor"}
|
||||
]
|
||||
},
|
||||
{ type: "pane", name: "infopanel" }
|
||||
{ type: "pane", name: "presetBrowser" }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
+524
-66
@@ -6042,6 +6042,18 @@ async function renderMenu() {
|
||||
}
|
||||
updateMenu();
|
||||
|
||||
// Helper function to get the current MIDI track
|
||||
function getCurrentMidiTrack() {
|
||||
const activeLayer = context.activeObject?.activeLayer;
|
||||
if (!activeLayer || !(activeLayer instanceof AudioTrack) || activeLayer.type !== 'midi') {
|
||||
return null;
|
||||
}
|
||||
if (activeLayer.audioTrackId === null) {
|
||||
return null;
|
||||
}
|
||||
return activeLayer.audioTrackId;
|
||||
}
|
||||
|
||||
function nodeEditor() {
|
||||
// Create container for the node editor
|
||||
const container = document.createElement("div");
|
||||
@@ -6291,17 +6303,25 @@ function nodeEditor() {
|
||||
|
||||
// Send command to backend
|
||||
// If parent node exists, add to VoiceAllocator template; otherwise add to main graph
|
||||
const trackId = getCurrentMidiTrack();
|
||||
if (trackId === null) {
|
||||
console.error('No MIDI track selected');
|
||||
showNodeEditorError(container, 'Please select a MIDI track first');
|
||||
editor.removeNodeId(`node-${drawflowNodeId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const commandName = parentNodeId ? "graph_add_node_to_template" : "graph_add_node";
|
||||
const commandArgs = parentNodeId
|
||||
? {
|
||||
trackId: 0,
|
||||
trackId: trackId,
|
||||
voiceAllocatorId: editor.getNodeFromId(parentNodeId).data.backendId,
|
||||
nodeType: nodeType,
|
||||
x: x,
|
||||
y: y
|
||||
}
|
||||
: {
|
||||
trackId: 0,
|
||||
trackId: trackId,
|
||||
nodeType: nodeType,
|
||||
x: x,
|
||||
y: y
|
||||
@@ -6318,14 +6338,17 @@ function nodeEditor() {
|
||||
// If this is an AudioOutput node, automatically set it as the graph output
|
||||
if (nodeType === "AudioOutput") {
|
||||
console.log(`Setting node ${backendNodeId} as graph output`);
|
||||
invoke("graph_set_output_node", {
|
||||
trackId: 0,
|
||||
nodeId: backendNodeId
|
||||
}).then(() => {
|
||||
console.log("Output node set successfully");
|
||||
}).catch(err => {
|
||||
console.error("Failed to set output node:", err);
|
||||
});
|
||||
const currentTrackId = getCurrentMidiTrack();
|
||||
if (currentTrackId !== null) {
|
||||
invoke("graph_set_output_node", {
|
||||
trackId: currentTrackId,
|
||||
nodeId: backendNodeId
|
||||
}).then(() => {
|
||||
console.log("Output node set successfully");
|
||||
}).catch(err => {
|
||||
console.error("Failed to set output node:", err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// If this is a VoiceAllocator, automatically create template I/O nodes inside it
|
||||
@@ -6477,14 +6500,17 @@ function nodeEditor() {
|
||||
|
||||
// Send to backend
|
||||
if (nodeData.data.backendId !== null) {
|
||||
invoke("graph_set_parameter", {
|
||||
trackId: 0,
|
||||
nodeId: nodeData.data.backendId,
|
||||
paramId: paramId,
|
||||
value: value
|
||||
}).catch(err => {
|
||||
console.error("Failed to set parameter:", err);
|
||||
});
|
||||
const currentTrackId = getCurrentMidiTrack();
|
||||
if (currentTrackId !== null) {
|
||||
invoke("graph_set_parameter", {
|
||||
trackId: currentTrackId,
|
||||
nodeId: nodeData.data.backendId,
|
||||
paramId: paramId,
|
||||
value: value
|
||||
}).catch(err => {
|
||||
console.error("Failed to set parameter:", err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -6632,48 +6658,54 @@ function nodeEditor() {
|
||||
// Both nodes are inside the same VoiceAllocator - connect in template
|
||||
const parentNode = editor.getNodeFromId(outputParent);
|
||||
console.log(`Connecting in VoiceAllocator template ${parentNode.data.backendId}: node ${outputNode.data.backendId} port ${outputPort} -> node ${inputNode.data.backendId} port ${inputPort}`);
|
||||
invoke("graph_connect_in_template", {
|
||||
trackId: 0,
|
||||
voiceAllocatorId: parentNode.data.backendId,
|
||||
fromNode: outputNode.data.backendId,
|
||||
fromPort: outputPort,
|
||||
toNode: inputNode.data.backendId,
|
||||
toPort: inputPort
|
||||
}).then(() => {
|
||||
console.log("Template connection successful");
|
||||
}).catch(err => {
|
||||
console.error("Failed to connect nodes in template:", err);
|
||||
showError("Template connection failed: " + err);
|
||||
// Remove the connection
|
||||
editor.removeSingleConnection(
|
||||
connection.output_id,
|
||||
connection.input_id,
|
||||
connection.output_class,
|
||||
connection.input_class
|
||||
);
|
||||
});
|
||||
const currentTrackId = getCurrentMidiTrack();
|
||||
if (currentTrackId !== null) {
|
||||
invoke("graph_connect_in_template", {
|
||||
trackId: currentTrackId,
|
||||
voiceAllocatorId: parentNode.data.backendId,
|
||||
fromNode: outputNode.data.backendId,
|
||||
fromPort: outputPort,
|
||||
toNode: inputNode.data.backendId,
|
||||
toPort: inputPort
|
||||
}).then(() => {
|
||||
console.log("Template connection successful");
|
||||
}).catch(err => {
|
||||
console.error("Failed to connect nodes in template:", err);
|
||||
showError("Template connection failed: " + err);
|
||||
// Remove the connection
|
||||
editor.removeSingleConnection(
|
||||
connection.output_id,
|
||||
connection.input_id,
|
||||
connection.output_class,
|
||||
connection.input_class
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Normal connection in main graph
|
||||
console.log(`Connecting: node ${outputNode.data.backendId} port ${outputPort} -> node ${inputNode.data.backendId} port ${inputPort}`);
|
||||
invoke("graph_connect", {
|
||||
trackId: 0,
|
||||
fromNode: outputNode.data.backendId,
|
||||
fromPort: outputPort,
|
||||
toNode: inputNode.data.backendId,
|
||||
toPort: inputPort
|
||||
}).then(() => {
|
||||
console.log("Connection successful");
|
||||
}).catch(err => {
|
||||
console.error("Failed to connect nodes:", err);
|
||||
showError("Connection failed: " + err);
|
||||
// Remove the connection
|
||||
editor.removeSingleConnection(
|
||||
connection.output_id,
|
||||
connection.input_id,
|
||||
connection.output_class,
|
||||
connection.input_class
|
||||
);
|
||||
});
|
||||
const currentTrackId = getCurrentMidiTrack();
|
||||
if (currentTrackId !== null) {
|
||||
invoke("graph_connect", {
|
||||
trackId: currentTrackId,
|
||||
fromNode: outputNode.data.backendId,
|
||||
fromPort: outputPort,
|
||||
toNode: inputNode.data.backendId,
|
||||
toPort: inputPort
|
||||
}).then(() => {
|
||||
console.log("Connection successful");
|
||||
}).catch(err => {
|
||||
console.error("Failed to connect nodes:", err);
|
||||
showError("Connection failed: " + err);
|
||||
// Remove the connection
|
||||
editor.removeSingleConnection(
|
||||
connection.output_id,
|
||||
connection.input_id,
|
||||
connection.output_class,
|
||||
connection.input_class
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6695,15 +6727,18 @@ function nodeEditor() {
|
||||
|
||||
// Send to backend
|
||||
if (outputNode.data.backendId !== null && inputNode.data.backendId !== null) {
|
||||
invoke("graph_disconnect", {
|
||||
trackId: 0,
|
||||
fromNode: outputNode.data.backendId,
|
||||
fromPort: outputPort,
|
||||
toNode: inputNode.data.backendId,
|
||||
toPort: inputPort
|
||||
}).catch(err => {
|
||||
console.error("Failed to disconnect nodes:", err);
|
||||
});
|
||||
const currentTrackId = getCurrentMidiTrack();
|
||||
if (currentTrackId !== null) {
|
||||
invoke("graph_disconnect", {
|
||||
trackId: currentTrackId,
|
||||
fromNode: outputNode.data.backendId,
|
||||
fromPort: outputPort,
|
||||
toNode: inputNode.data.backendId,
|
||||
toPort: inputPort
|
||||
}).catch(err => {
|
||||
console.error("Failed to disconnect nodes:", err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6719,6 +6754,132 @@ function nodeEditor() {
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// Function to reload graph from backend
|
||||
async function reloadGraph() {
|
||||
if (!editor) return;
|
||||
|
||||
const trackId = getCurrentMidiTrack();
|
||||
|
||||
// Clear editor first
|
||||
editor.clearModuleSelected();
|
||||
editor.clear();
|
||||
|
||||
// If no MIDI track selected, just leave it cleared
|
||||
if (trackId === null) {
|
||||
console.log('No MIDI track selected, editor cleared');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const graphJson = await invoke('graph_get_state', { trackId });
|
||||
const preset = JSON.parse(graphJson);
|
||||
|
||||
// If graph is empty (no nodes), just leave cleared
|
||||
if (!preset.nodes || preset.nodes.length === 0) {
|
||||
console.log('Graph is empty, editor cleared');
|
||||
return;
|
||||
}
|
||||
|
||||
// Rebuild from preset
|
||||
const nodeMap = new Map(); // Maps backend node ID to Drawflow node ID
|
||||
|
||||
// Add all nodes
|
||||
for (const serializedNode of preset.nodes) {
|
||||
const nodeType = serializedNode.node_type;
|
||||
const nodeDef = nodeTypes[nodeType];
|
||||
if (!nodeDef) continue;
|
||||
|
||||
// Create node HTML
|
||||
let html = `<div class="node-content"><div class="node-title">${nodeDef.name}</div>`;
|
||||
for (const param of nodeDef.parameters) {
|
||||
const value = serializedNode.parameters[param.id] || param.default;
|
||||
html += `<div class="node-parameter">
|
||||
<label>${param.name}</label>
|
||||
<input type="range" data-param-id="${param.id}" min="${param.min}" max="${param.max}" step="${param.step || 0.01}" value="${value}" />
|
||||
<span class="param-value">${value.toFixed(2)}</span>
|
||||
</div>`;
|
||||
}
|
||||
html += `</div>`;
|
||||
|
||||
// Add node to Drawflow
|
||||
const drawflowId = editor.addNode(
|
||||
nodeType,
|
||||
nodeDef.inputs.length,
|
||||
nodeDef.outputs.length,
|
||||
serializedNode.position[0],
|
||||
serializedNode.position[1],
|
||||
nodeType,
|
||||
{ nodeType, backendId: serializedNode.id, parentNodeId: null },
|
||||
html,
|
||||
false
|
||||
);
|
||||
|
||||
nodeMap.set(serializedNode.id, drawflowId);
|
||||
|
||||
// Style ports
|
||||
setTimeout(() => styleNodePorts(drawflowId, nodeDef), 10);
|
||||
|
||||
// Wire up parameter controls
|
||||
setTimeout(() => {
|
||||
const nodeElement = container.querySelector(`#node-${drawflowId}`);
|
||||
if (!nodeElement) return;
|
||||
|
||||
nodeElement.querySelectorAll('input[type="range"]').forEach(slider => {
|
||||
const paramId = parseInt(slider.dataset.paramId);
|
||||
const displaySpan = slider.nextElementSibling;
|
||||
|
||||
slider.addEventListener('input', (e) => {
|
||||
const value = parseFloat(e.target.value);
|
||||
if (displaySpan) {
|
||||
const param = nodeDef.parameters.find(p => p.id === paramId);
|
||||
displaySpan.textContent = value.toFixed(param?.unit === 'Hz' ? 0 : 2);
|
||||
}
|
||||
|
||||
const currentTrackId = getCurrentMidiTrack();
|
||||
if (currentTrackId !== null) {
|
||||
invoke("graph_set_parameter", {
|
||||
trackId: currentTrackId,
|
||||
nodeId: serializedNode.id,
|
||||
paramId: paramId,
|
||||
value: value
|
||||
}).catch(err => {
|
||||
console.error("Failed to set parameter:", err);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// Add all connections
|
||||
for (const conn of preset.connections) {
|
||||
const outputDrawflowId = nodeMap.get(conn.from_node);
|
||||
const inputDrawflowId = nodeMap.get(conn.to_node);
|
||||
|
||||
if (outputDrawflowId && inputDrawflowId) {
|
||||
// Drawflow uses 1-based port indexing
|
||||
editor.addConnection(
|
||||
outputDrawflowId,
|
||||
inputDrawflowId,
|
||||
`output_${conn.from_port + 1}`,
|
||||
`input_${conn.to_port + 1}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Graph reloaded from backend');
|
||||
} catch (error) {
|
||||
console.error('Failed to reload graph:', error);
|
||||
showError(`Failed to reload graph: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Store reload function in context so it can be called from preset browser
|
||||
context.reloadNodeEditor = reloadGraph;
|
||||
|
||||
// Initial load of graph
|
||||
setTimeout(() => reloadGraph(), 200);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
@@ -6882,6 +7043,296 @@ function pianoRoll() {
|
||||
return canvas;
|
||||
}
|
||||
|
||||
function presetBrowser() {
|
||||
const container = document.createElement("div");
|
||||
container.className = "preset-browser-pane";
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="preset-browser-header">
|
||||
<h3>Instrument Presets</h3>
|
||||
<button class="preset-btn preset-save-btn" title="Save current graph as preset">
|
||||
<span>💾</span> Save Preset
|
||||
</button>
|
||||
</div>
|
||||
<div class="preset-filter">
|
||||
<input type="text" id="preset-search" placeholder="Search presets..." />
|
||||
<select id="preset-tag-filter">
|
||||
<option value="">All Tags</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="preset-categories">
|
||||
<div class="preset-category">
|
||||
<h4>Factory Presets</h4>
|
||||
<div class="preset-list" id="factory-preset-list">
|
||||
<div class="preset-loading">Loading...</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="preset-category">
|
||||
<h4>User Presets</h4>
|
||||
<div class="preset-list" id="user-preset-list">
|
||||
<div class="preset-empty">No user presets yet</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Load presets after DOM insertion
|
||||
setTimeout(async () => {
|
||||
await loadPresetList(container);
|
||||
|
||||
// Set up save button handler
|
||||
const saveBtn = container.querySelector('.preset-save-btn');
|
||||
if (saveBtn) {
|
||||
saveBtn.addEventListener('click', () => showSavePresetDialog(container));
|
||||
}
|
||||
|
||||
// Set up search and filter
|
||||
const searchInput = container.querySelector('#preset-search');
|
||||
const tagFilter = container.querySelector('#preset-tag-filter');
|
||||
|
||||
if (searchInput) {
|
||||
searchInput.addEventListener('input', () => filterPresets(container));
|
||||
}
|
||||
if (tagFilter) {
|
||||
tagFilter.addEventListener('change', () => filterPresets(container));
|
||||
}
|
||||
}, 0);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
async function loadPresetList(container) {
|
||||
try {
|
||||
const presets = await invoke('graph_list_presets');
|
||||
|
||||
const factoryList = container.querySelector('#factory-preset-list');
|
||||
const userList = container.querySelector('#user-preset-list');
|
||||
const tagFilter = container.querySelector('#preset-tag-filter');
|
||||
|
||||
// Collect all unique tags
|
||||
const allTags = new Set();
|
||||
presets.forEach(preset => {
|
||||
preset.tags.forEach(tag => allTags.add(tag));
|
||||
});
|
||||
|
||||
// Populate tag filter
|
||||
if (tagFilter) {
|
||||
allTags.forEach(tag => {
|
||||
const option = document.createElement('option');
|
||||
option.value = tag;
|
||||
option.textContent = tag.charAt(0).toUpperCase() + tag.slice(1);
|
||||
tagFilter.appendChild(option);
|
||||
});
|
||||
}
|
||||
|
||||
// Separate factory and user presets
|
||||
const factoryPresets = presets.filter(p => p.is_factory);
|
||||
const userPresets = presets.filter(p => !p.is_factory);
|
||||
|
||||
// Render factory presets
|
||||
if (factoryList) {
|
||||
if (factoryPresets.length === 0) {
|
||||
factoryList.innerHTML = '<div class="preset-empty">No factory presets found</div>';
|
||||
} else {
|
||||
factoryList.innerHTML = factoryPresets.map(preset => createPresetItem(preset)).join('');
|
||||
addPresetItemHandlers(factoryList);
|
||||
}
|
||||
}
|
||||
|
||||
// Render user presets
|
||||
if (userList) {
|
||||
if (userPresets.length === 0) {
|
||||
userList.innerHTML = '<div class="preset-empty">No user presets yet</div>';
|
||||
} else {
|
||||
userList.innerHTML = userPresets.map(preset => createPresetItem(preset)).join('');
|
||||
addPresetItemHandlers(userList);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load presets:', error);
|
||||
const factoryList = container.querySelector('#factory-preset-list');
|
||||
const userList = container.querySelector('#user-preset-list');
|
||||
if (factoryList) factoryList.innerHTML = '<div class="preset-error">Failed to load presets</div>';
|
||||
if (userList) userList.innerHTML = '';
|
||||
}
|
||||
}
|
||||
|
||||
function createPresetItem(preset) {
|
||||
const tags = preset.tags.map(tag => `<span class="preset-tag">${tag}</span>`).join('');
|
||||
const deleteBtn = preset.is_factory ? '' : '<button class="preset-delete-btn" title="Delete preset">🗑️</button>';
|
||||
|
||||
return `
|
||||
<div class="preset-item" data-preset-path="${preset.path}" data-preset-tags="${preset.tags.join(',')}">
|
||||
<div class="preset-item-header">
|
||||
<span class="preset-name">${preset.name}</span>
|
||||
${deleteBtn}
|
||||
</div>
|
||||
<div class="preset-description">${preset.description || 'No description'}</div>
|
||||
<div class="preset-tags">${tags}</div>
|
||||
<div class="preset-author">by ${preset.author || 'Unknown'}</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function addPresetItemHandlers(listElement) {
|
||||
// Load preset on click
|
||||
listElement.querySelectorAll('.preset-item').forEach(item => {
|
||||
item.addEventListener('click', async (e) => {
|
||||
// Don't trigger if clicking delete button
|
||||
if (e.target.classList.contains('preset-delete-btn')) return;
|
||||
|
||||
const presetPath = item.dataset.presetPath;
|
||||
await loadPreset(presetPath);
|
||||
});
|
||||
});
|
||||
|
||||
// Delete preset on delete button click
|
||||
listElement.querySelectorAll('.preset-delete-btn').forEach(btn => {
|
||||
btn.addEventListener('click', async (e) => {
|
||||
e.stopPropagation();
|
||||
const item = btn.closest('.preset-item');
|
||||
const presetPath = item.dataset.presetPath;
|
||||
const presetName = item.querySelector('.preset-name').textContent;
|
||||
|
||||
if (confirm(`Delete preset "${presetName}"?`)) {
|
||||
try {
|
||||
await invoke('graph_delete_preset', { presetPath });
|
||||
// Reload preset list
|
||||
const container = btn.closest('.preset-browser-pane');
|
||||
await loadPresetList(container);
|
||||
} catch (error) {
|
||||
alert(`Failed to delete preset: ${error}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function loadPreset(presetPath) {
|
||||
const trackId = getCurrentMidiTrack();
|
||||
if (trackId === null) {
|
||||
alert('Please select a MIDI track first');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await invoke('graph_load_preset', {
|
||||
trackId: trackId,
|
||||
presetPath
|
||||
});
|
||||
|
||||
// Refresh the node editor to show the loaded preset
|
||||
await context.reloadNodeEditor?.();
|
||||
|
||||
console.log('Preset loaded successfully');
|
||||
} catch (error) {
|
||||
alert(`Failed to load preset: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
function showSavePresetDialog(container) {
|
||||
const currentTrackId = getCurrentMidiTrack();
|
||||
if (currentTrackId === null) {
|
||||
alert('Please select a MIDI track first');
|
||||
return;
|
||||
}
|
||||
|
||||
// Create modal dialog
|
||||
const dialog = document.createElement('div');
|
||||
dialog.className = 'modal-overlay';
|
||||
dialog.innerHTML = `
|
||||
<div class="modal-dialog">
|
||||
<h3>Save Preset</h3>
|
||||
<form id="save-preset-form">
|
||||
<div class="form-group">
|
||||
<label>Preset Name</label>
|
||||
<input type="text" id="preset-name" required placeholder="My Awesome Synth" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<textarea id="preset-description" placeholder="Describe the sound..." rows="3"></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Tags (comma-separated)</label>
|
||||
<input type="text" id="preset-tags" placeholder="bass, lead, pad" />
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="button" class="btn-cancel">Cancel</button>
|
||||
<button type="submit" class="btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.body.appendChild(dialog);
|
||||
|
||||
// Focus name input
|
||||
setTimeout(() => dialog.querySelector('#preset-name')?.focus(), 100);
|
||||
|
||||
// Handle cancel
|
||||
dialog.querySelector('.btn-cancel').addEventListener('click', () => {
|
||||
dialog.remove();
|
||||
});
|
||||
|
||||
// Handle save
|
||||
dialog.querySelector('#save-preset-form').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const name = dialog.querySelector('#preset-name').value.trim();
|
||||
const description = dialog.querySelector('#preset-description').value.trim();
|
||||
const tagsInput = dialog.querySelector('#preset-tags').value.trim();
|
||||
const tags = tagsInput ? tagsInput.split(',').map(t => t.trim()).filter(t => t) : [];
|
||||
|
||||
if (!name) {
|
||||
alert('Please enter a preset name');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await invoke('graph_save_preset', {
|
||||
trackId: currentTrackId,
|
||||
presetName: name,
|
||||
description,
|
||||
tags
|
||||
});
|
||||
|
||||
dialog.remove();
|
||||
|
||||
// Reload preset list
|
||||
await loadPresetList(container);
|
||||
|
||||
alert(`Preset "${name}" saved successfully!`);
|
||||
} catch (error) {
|
||||
alert(`Failed to save preset: ${error}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Close on background click
|
||||
dialog.addEventListener('click', (e) => {
|
||||
if (e.target === dialog) {
|
||||
dialog.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function filterPresets(container) {
|
||||
const searchTerm = container.querySelector('#preset-search')?.value.toLowerCase() || '';
|
||||
const selectedTag = container.querySelector('#preset-tag-filter')?.value || '';
|
||||
|
||||
const allItems = container.querySelectorAll('.preset-item');
|
||||
|
||||
allItems.forEach(item => {
|
||||
const name = item.querySelector('.preset-name').textContent.toLowerCase();
|
||||
const description = item.querySelector('.preset-description').textContent.toLowerCase();
|
||||
const tags = item.dataset.presetTags.split(',');
|
||||
|
||||
const matchesSearch = !searchTerm || name.includes(searchTerm) || description.includes(searchTerm);
|
||||
const matchesTag = !selectedTag || tags.includes(selectedTag);
|
||||
|
||||
item.style.display = (matchesSearch && matchesTag) ? 'block' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
const panes = {
|
||||
stage: {
|
||||
name: "stage",
|
||||
@@ -6919,6 +7370,10 @@ const panes = {
|
||||
name: "node-editor",
|
||||
func: nodeEditor,
|
||||
},
|
||||
presetBrowser: {
|
||||
name: "preset-browser",
|
||||
func: presetBrowser,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -7179,6 +7634,9 @@ async function addEmptyMIDITrack() {
|
||||
context.timelineWidget.requestRedraw();
|
||||
}
|
||||
|
||||
// Refresh node editor to show empty graph
|
||||
setTimeout(() => context.reloadNodeEditor?.(), 100);
|
||||
|
||||
console.log('Empty MIDI track created:', trackName, 'with ID:', newMIDITrack.audioTrackId);
|
||||
} catch (error) {
|
||||
console.error('Failed to create empty MIDI track:', error);
|
||||
|
||||
+284
@@ -1307,3 +1307,287 @@ button {
|
||||
0%, 70% { opacity: 1; }
|
||||
100% { opacity: 0; }
|
||||
}
|
||||
|
||||
/* Preset Browser Pane Styling */
|
||||
.preset-browser-pane {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background: #1e1e1e;
|
||||
color: #ddd;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.preset-browser-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 12px 16px;
|
||||
background: #252525;
|
||||
border-bottom: 1px solid #3d3d3d;
|
||||
}
|
||||
|
||||
.preset-browser-header h3 {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.preset-btn {
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 6px 12px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.preset-btn:hover {
|
||||
background: #45a049;
|
||||
}
|
||||
|
||||
.preset-btn span {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.preset-filter {
|
||||
padding: 12px 16px;
|
||||
background: #252525;
|
||||
border-bottom: 1px solid #3d3d3d;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.preset-filter input,
|
||||
.preset-filter select {
|
||||
flex: 1;
|
||||
background: #1e1e1e;
|
||||
color: #ddd;
|
||||
border: 1px solid #3d3d3d;
|
||||
padding: 6px 10px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.preset-filter input:focus,
|
||||
.preset-filter select:focus {
|
||||
outline: none;
|
||||
border-color: #4CAF50;
|
||||
}
|
||||
|
||||
.preset-categories {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.preset-category {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.preset-category h4 {
|
||||
margin: 0 0 12px 0;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #999;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.preset-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.preset-item {
|
||||
background: #252525;
|
||||
border: 1px solid #3d3d3d;
|
||||
border-radius: 4px;
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.preset-item:hover {
|
||||
background: #2d2d2d;
|
||||
border-color: #4CAF50;
|
||||
}
|
||||
|
||||
.preset-item-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.preset-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.preset-delete-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: #f44336;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.preset-delete-btn:hover {
|
||||
background: rgba(244, 67, 54, 0.2);
|
||||
}
|
||||
|
||||
.preset-description {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-bottom: 6px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.preset-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.preset-tag {
|
||||
background: #3d3d3d;
|
||||
color: #aaa;
|
||||
font-size: 10px;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.preset-author {
|
||||
font-size: 11px;
|
||||
color: #777;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.preset-loading,
|
||||
.preset-empty,
|
||||
.preset-error {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
color: #777;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.preset-error {
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
/* Modal Dialog for Save Preset */
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 10000;
|
||||
}
|
||||
|
||||
.modal-dialog {
|
||||
background: #252525;
|
||||
border: 1px solid #3d3d3d;
|
||||
border-radius: 6px;
|
||||
padding: 24px;
|
||||
min-width: 400px;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.modal-dialog h3 {
|
||||
margin: 0 0 20px 0;
|
||||
font-size: 18px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-size: 13px;
|
||||
color: #aaa;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
background: #1e1e1e;
|
||||
color: #ddd;
|
||||
border: 1px solid #3d3d3d;
|
||||
padding: 8px 10px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: #4CAF50;
|
||||
}
|
||||
|
||||
.form-group textarea {
|
||||
resize: vertical;
|
||||
min-height: 60px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.btn-cancel,
|
||||
.btn-primary {
|
||||
padding: 8px 16px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
font-weight: 500;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
background: #3d3d3d;
|
||||
color: #ddd;
|
||||
}
|
||||
|
||||
.btn-cancel:hover {
|
||||
background: #4d4d4d;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #45a049;
|
||||
}
|
||||
|
||||
@@ -2839,6 +2839,9 @@ class TimelineWindowV2 extends Widget {
|
||||
// Clear selections when selecting layer
|
||||
this.context.selection = []
|
||||
this.context.shapeselection = []
|
||||
|
||||
// Clear node editor when selecting a non-audio layer
|
||||
setTimeout(() => this.context.reloadNodeEditor?.(), 50);
|
||||
} else if (track.type === 'shape') {
|
||||
// Find the layer this shape belongs to and select it
|
||||
for (let i = 0; i < this.context.activeObject.allLayers.length; i++) {
|
||||
@@ -2862,6 +2865,11 @@ class TimelineWindowV2 extends Widget {
|
||||
this.context.activeObject.activeLayer = track.object
|
||||
this.context.selection = []
|
||||
this.context.shapeselection = []
|
||||
|
||||
// If this is a MIDI track, reload the node editor
|
||||
if (track.object.type === 'midi') {
|
||||
setTimeout(() => this.context.reloadNodeEditor?.(), 50);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the stage UI to reflect selection changes
|
||||
|
||||
Reference in New Issue
Block a user