Add presets and make graph follow selected layer/track
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "Basic Sine",
|
||||
"description": "Simple sine wave synthesizer with ADSR envelope. Great for learning the basics of subtractive synthesis.",
|
||||
"author": "Lightningbeam",
|
||||
"version": 1,
|
||||
"tags": ["basic", "lead", "mono"]
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"id": 0,
|
||||
"node_type": "MidiInput",
|
||||
"parameters": {},
|
||||
"position": [100.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"node_type": "MidiToCV",
|
||||
"parameters": {},
|
||||
"position": [300.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"node_type": "Oscillator",
|
||||
"parameters": {
|
||||
"0": 440.0,
|
||||
"1": 0.7,
|
||||
"2": 0.0
|
||||
},
|
||||
"position": [500.0, 150.0]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"node_type": "ADSR",
|
||||
"parameters": {
|
||||
"0": 0.01,
|
||||
"1": 0.1,
|
||||
"2": 0.7,
|
||||
"3": 0.3
|
||||
},
|
||||
"position": [500.0, 300.0]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"node_type": "Gain",
|
||||
"parameters": {
|
||||
"0": 1.0
|
||||
},
|
||||
"position": [700.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"node_type": "AudioOutput",
|
||||
"parameters": {},
|
||||
"position": [900.0, 200.0]
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"from_node": 0,
|
||||
"from_port": 0,
|
||||
"to_node": 1,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 0,
|
||||
"to_node": 2,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 1,
|
||||
"to_node": 3,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 2,
|
||||
"from_port": 0,
|
||||
"to_node": 4,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 3,
|
||||
"from_port": 0,
|
||||
"to_node": 4,
|
||||
"to_port": 1
|
||||
},
|
||||
{
|
||||
"from_node": 4,
|
||||
"from_port": 0,
|
||||
"to_node": 5,
|
||||
"to_port": 0
|
||||
}
|
||||
],
|
||||
"midi_targets": [0],
|
||||
"output_node": 5
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "Pluck",
|
||||
"description": "Percussive pluck sound with fast attack and decay. Great for arpeggios, melodies, and rhythmic patterns.",
|
||||
"author": "Lightningbeam",
|
||||
"version": 1,
|
||||
"tags": ["pluck", "lead", "percussive", "arpeggio"]
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"id": 0,
|
||||
"node_type": "MidiInput",
|
||||
"parameters": {},
|
||||
"position": [100.0, 250.0]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"node_type": "MidiToCV",
|
||||
"parameters": {},
|
||||
"position": [300.0, 250.0]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"node_type": "Oscillator",
|
||||
"parameters": {
|
||||
"0": 440.0,
|
||||
"1": 0.6,
|
||||
"2": 2.0
|
||||
},
|
||||
"position": [500.0, 150.0]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"node_type": "Filter",
|
||||
"parameters": {
|
||||
"0": 2000.0,
|
||||
"1": 0.8,
|
||||
"2": 0.0
|
||||
},
|
||||
"position": [700.0, 150.0]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"node_type": "ADSR",
|
||||
"parameters": {
|
||||
"0": 0.001,
|
||||
"1": 0.3,
|
||||
"2": 0.0,
|
||||
"3": 0.05
|
||||
},
|
||||
"position": [500.0, 350.0]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"node_type": "ADSR",
|
||||
"parameters": {
|
||||
"0": 0.001,
|
||||
"1": 0.4,
|
||||
"2": 0.0,
|
||||
"3": 0.1
|
||||
},
|
||||
"position": [700.0, 350.0]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"node_type": "Gain",
|
||||
"parameters": {
|
||||
"0": 1.0
|
||||
},
|
||||
"position": [900.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"node_type": "AudioOutput",
|
||||
"parameters": {},
|
||||
"position": [1100.0, 200.0]
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"from_node": 0,
|
||||
"from_port": 0,
|
||||
"to_node": 1,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 0,
|
||||
"to_node": 2,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 1,
|
||||
"to_node": 4,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 1,
|
||||
"to_node": 5,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 2,
|
||||
"from_port": 0,
|
||||
"to_node": 3,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 4,
|
||||
"from_port": 0,
|
||||
"to_node": 3,
|
||||
"to_port": 1
|
||||
},
|
||||
{
|
||||
"from_node": 3,
|
||||
"from_port": 0,
|
||||
"to_node": 6,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 5,
|
||||
"from_port": 0,
|
||||
"to_node": 6,
|
||||
"to_port": 1
|
||||
},
|
||||
{
|
||||
"from_node": 6,
|
||||
"from_port": 0,
|
||||
"to_node": 7,
|
||||
"to_port": 0
|
||||
}
|
||||
],
|
||||
"midi_targets": [0],
|
||||
"output_node": 7
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "Poly Synth",
|
||||
"description": "8-voice polyphonic synthesizer with sawtooth oscillator and ADSR envelope. Perfect for chords and complex harmonies.",
|
||||
"author": "Lightningbeam",
|
||||
"version": 1,
|
||||
"tags": ["poly", "polyphonic", "synth", "chords"]
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"id": 0,
|
||||
"node_type": "MidiInput",
|
||||
"parameters": {},
|
||||
"position": [100.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"node_type": "VoiceAllocator",
|
||||
"parameters": {
|
||||
"0": 8.0
|
||||
},
|
||||
"position": [400.0, 200.0],
|
||||
"template_graph": {
|
||||
"metadata": {
|
||||
"name": "template",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"version": 1,
|
||||
"tags": []
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"id": 0,
|
||||
"node_type": "TemplateInput",
|
||||
"parameters": {},
|
||||
"position": [100.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"node_type": "MidiToCV",
|
||||
"parameters": {},
|
||||
"position": [300.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"node_type": "Oscillator",
|
||||
"parameters": {
|
||||
"0": 440.0,
|
||||
"1": 0.7,
|
||||
"2": 1.0
|
||||
},
|
||||
"position": [500.0, 150.0]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"node_type": "ADSR",
|
||||
"parameters": {
|
||||
"0": 0.01,
|
||||
"1": 0.2,
|
||||
"2": 0.6,
|
||||
"3": 0.3
|
||||
},
|
||||
"position": [500.0, 300.0]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"node_type": "Gain",
|
||||
"parameters": {
|
||||
"0": 1.0
|
||||
},
|
||||
"position": [700.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"node_type": "TemplateOutput",
|
||||
"parameters": {},
|
||||
"position": [900.0, 200.0]
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"from_node": 0,
|
||||
"from_port": 0,
|
||||
"to_node": 1,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 0,
|
||||
"to_node": 2,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 1,
|
||||
"to_node": 3,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 2,
|
||||
"from_port": 0,
|
||||
"to_node": 4,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 3,
|
||||
"from_port": 0,
|
||||
"to_node": 4,
|
||||
"to_port": 1
|
||||
},
|
||||
{
|
||||
"from_node": 4,
|
||||
"from_port": 0,
|
||||
"to_node": 5,
|
||||
"to_port": 0
|
||||
}
|
||||
],
|
||||
"midi_targets": [],
|
||||
"output_node": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"node_type": "AudioOutput",
|
||||
"parameters": {},
|
||||
"position": [700.0, 200.0]
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"from_node": 0,
|
||||
"from_port": 0,
|
||||
"to_node": 1,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 0,
|
||||
"to_node": 2,
|
||||
"to_port": 0
|
||||
}
|
||||
],
|
||||
"midi_targets": [0],
|
||||
"output_node": 2
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "Sawtooth Bass",
|
||||
"description": "Classic analog-style bass synth with sawtooth oscillator and resonant lowpass filter. Perfect for electronic music basslines.",
|
||||
"author": "Lightningbeam",
|
||||
"version": 1,
|
||||
"tags": ["bass", "analog", "electronic", "mono"]
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"id": 0,
|
||||
"node_type": "MidiInput",
|
||||
"parameters": {},
|
||||
"position": [100.0, 250.0]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"node_type": "MidiToCV",
|
||||
"parameters": {},
|
||||
"position": [300.0, 250.0]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"node_type": "Oscillator",
|
||||
"parameters": {
|
||||
"0": 110.0,
|
||||
"1": 0.8,
|
||||
"2": 1.0
|
||||
},
|
||||
"position": [500.0, 150.0]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"node_type": "Filter",
|
||||
"parameters": {
|
||||
"0": 800.0,
|
||||
"1": 2.5,
|
||||
"2": 0.0
|
||||
},
|
||||
"position": [700.0, 150.0]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"node_type": "ADSR",
|
||||
"parameters": {
|
||||
"0": 0.005,
|
||||
"1": 0.2,
|
||||
"2": 0.3,
|
||||
"3": 0.1
|
||||
},
|
||||
"position": [500.0, 300.0]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"node_type": "ADSR",
|
||||
"parameters": {
|
||||
"0": 0.005,
|
||||
"1": 0.15,
|
||||
"2": 0.6,
|
||||
"3": 0.2
|
||||
},
|
||||
"position": [700.0, 350.0]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"node_type": "Gain",
|
||||
"parameters": {
|
||||
"0": 1.2
|
||||
},
|
||||
"position": [900.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"node_type": "AudioOutput",
|
||||
"parameters": {},
|
||||
"position": [1100.0, 200.0]
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"from_node": 0,
|
||||
"from_port": 0,
|
||||
"to_node": 1,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 0,
|
||||
"to_node": 2,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 1,
|
||||
"to_node": 4,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 1,
|
||||
"to_node": 5,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 2,
|
||||
"from_port": 0,
|
||||
"to_node": 3,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 4,
|
||||
"from_port": 0,
|
||||
"to_node": 3,
|
||||
"to_port": 1
|
||||
},
|
||||
{
|
||||
"from_node": 3,
|
||||
"from_port": 0,
|
||||
"to_node": 6,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 5,
|
||||
"from_port": 0,
|
||||
"to_node": 6,
|
||||
"to_port": 1
|
||||
},
|
||||
{
|
||||
"from_node": 6,
|
||||
"from_port": 0,
|
||||
"to_node": 7,
|
||||
"to_port": 0
|
||||
}
|
||||
],
|
||||
"midi_targets": [0],
|
||||
"output_node": 7
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "Warm Pad",
|
||||
"description": "Lush pad sound combining sawtooth and triangle waves with slow filter sweep and gentle attack. Ideal for ambient and cinematic music.",
|
||||
"author": "Lightningbeam",
|
||||
"version": 1,
|
||||
"tags": ["pad", "ambient", "warm", "cinematic"]
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"id": 0,
|
||||
"node_type": "MidiInput",
|
||||
"parameters": {},
|
||||
"position": [100.0, 300.0]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"node_type": "MidiToCV",
|
||||
"parameters": {},
|
||||
"position": [300.0, 300.0]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"node_type": "Oscillator",
|
||||
"parameters": {
|
||||
"0": 440.0,
|
||||
"1": 0.5,
|
||||
"2": 1.0
|
||||
},
|
||||
"position": [500.0, 150.0]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"node_type": "Oscillator",
|
||||
"parameters": {
|
||||
"0": 440.0,
|
||||
"1": 0.4,
|
||||
"2": 3.0
|
||||
},
|
||||
"position": [500.0, 250.0]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"node_type": "Mixer",
|
||||
"parameters": {
|
||||
"0": 0.5,
|
||||
"1": 0.5,
|
||||
"2": 0.0,
|
||||
"3": 0.0
|
||||
},
|
||||
"position": [700.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"node_type": "Filter",
|
||||
"parameters": {
|
||||
"0": 1200.0,
|
||||
"1": 1.0,
|
||||
"2": 0.0
|
||||
},
|
||||
"position": [900.0, 200.0]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"node_type": "ADSR",
|
||||
"parameters": {
|
||||
"0": 0.8,
|
||||
"1": 1.0,
|
||||
"2": 0.6,
|
||||
"3": 1.5
|
||||
},
|
||||
"position": [700.0, 400.0]
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"node_type": "ADSR",
|
||||
"parameters": {
|
||||
"0": 0.5,
|
||||
"1": 0.5,
|
||||
"2": 0.8,
|
||||
"3": 1.0
|
||||
},
|
||||
"position": [900.0, 400.0]
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"node_type": "Gain",
|
||||
"parameters": {
|
||||
"0": 0.8
|
||||
},
|
||||
"position": [1100.0, 250.0]
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"node_type": "AudioOutput",
|
||||
"parameters": {},
|
||||
"position": [1300.0, 250.0]
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"from_node": 0,
|
||||
"from_port": 0,
|
||||
"to_node": 1,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 0,
|
||||
"to_node": 2,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 0,
|
||||
"to_node": 3,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 1,
|
||||
"to_node": 6,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 1,
|
||||
"from_port": 1,
|
||||
"to_node": 7,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 2,
|
||||
"from_port": 0,
|
||||
"to_node": 4,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 3,
|
||||
"from_port": 0,
|
||||
"to_node": 4,
|
||||
"to_port": 1
|
||||
},
|
||||
{
|
||||
"from_node": 4,
|
||||
"from_port": 0,
|
||||
"to_node": 5,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 6,
|
||||
"from_port": 0,
|
||||
"to_node": 5,
|
||||
"to_port": 1
|
||||
},
|
||||
{
|
||||
"from_node": 5,
|
||||
"from_port": 0,
|
||||
"to_node": 8,
|
||||
"to_port": 0
|
||||
},
|
||||
{
|
||||
"from_node": 7,
|
||||
"from_port": 0,
|
||||
"to_node": 8,
|
||||
"to_port": 1
|
||||
},
|
||||
{
|
||||
"from_node": 8,
|
||||
"from_port": 0,
|
||||
"to_node": 9,
|
||||
"to_port": 0
|
||||
}
|
||||
],
|
||||
"midi_targets": [0],
|
||||
"output_node": 9
|
||||
}
|
||||
+199
-1
@@ -1,7 +1,7 @@
|
||||
use daw_backend::{AudioEvent, AudioSystem, EngineController, EventEmitter, WaveformPeak};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::collections::HashMap;
|
||||
use tauri::{Emitter};
|
||||
use tauri::{Emitter, Manager};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct AudioFileMetadata {
|
||||
@@ -693,6 +693,204 @@ pub async fn graph_set_output_node(
|
||||
}
|
||||
}
|
||||
|
||||
// Preset management commands
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn graph_save_preset(
|
||||
app_handle: tauri::AppHandle,
|
||||
state: tauri::State<'_, Arc<Mutex<AudioState>>>,
|
||||
track_id: u32,
|
||||
preset_name: String,
|
||||
description: String,
|
||||
tags: Vec<String>,
|
||||
) -> Result<String, String> {
|
||||
use std::fs;
|
||||
|
||||
let mut audio_state = state.lock().unwrap();
|
||||
if let Some(controller) = &mut audio_state.controller {
|
||||
// Get user presets directory
|
||||
let app_data_dir = app_handle.path().app_data_dir()
|
||||
.map_err(|e| format!("Failed to get app data directory: {}", e))?;
|
||||
let presets_dir = app_data_dir.join("presets");
|
||||
|
||||
// Create presets directory if it doesn't exist
|
||||
fs::create_dir_all(&presets_dir)
|
||||
.map_err(|e| format!("Failed to create presets directory: {}", e))?;
|
||||
|
||||
// Create preset path
|
||||
let filename = format!("{}.json", preset_name.replace(" ", "_"));
|
||||
let preset_path = presets_dir.join(&filename);
|
||||
let preset_path_str = preset_path.to_string_lossy().to_string();
|
||||
|
||||
// Send command to save preset
|
||||
controller.graph_save_preset(
|
||||
track_id,
|
||||
preset_path_str.clone(),
|
||||
preset_name,
|
||||
description,
|
||||
tags
|
||||
);
|
||||
|
||||
Ok(preset_path_str)
|
||||
} else {
|
||||
Err("Audio not initialized".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn graph_load_preset(
|
||||
state: tauri::State<'_, Arc<Mutex<AudioState>>>,
|
||||
track_id: u32,
|
||||
preset_path: String,
|
||||
) -> Result<(), String> {
|
||||
let mut audio_state = state.lock().unwrap();
|
||||
if let Some(controller) = &mut audio_state.controller {
|
||||
// Send command to load preset
|
||||
controller.graph_load_preset(track_id, preset_path);
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Audio not initialized".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct PresetInfo {
|
||||
pub name: String,
|
||||
pub path: String,
|
||||
pub description: String,
|
||||
pub author: String,
|
||||
pub tags: Vec<String>,
|
||||
pub is_factory: bool,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn graph_list_presets(
|
||||
app_handle: tauri::AppHandle,
|
||||
) -> Result<Vec<PresetInfo>, String> {
|
||||
use daw_backend::GraphPreset;
|
||||
use std::fs;
|
||||
|
||||
let mut presets = Vec::new();
|
||||
|
||||
// Load factory presets from bundled assets
|
||||
let factory_presets = [
|
||||
"Basic_Sine.json",
|
||||
"Sawtooth_Bass.json",
|
||||
"Warm_Pad.json",
|
||||
"Pluck.json",
|
||||
"Poly_Synth.json",
|
||||
];
|
||||
|
||||
for preset_file in &factory_presets {
|
||||
// Try to load from resource directory
|
||||
if let Ok(resource_dir) = app_handle.path().resource_dir() {
|
||||
let factory_path = resource_dir.join("assets/factory_presets").join(preset_file);
|
||||
if let Ok(json) = fs::read_to_string(&factory_path) {
|
||||
if let Ok(preset) = GraphPreset::from_json(&json) {
|
||||
presets.push(PresetInfo {
|
||||
name: preset.metadata.name,
|
||||
path: factory_path.to_string_lossy().to_string(),
|
||||
description: preset.metadata.description,
|
||||
author: preset.metadata.author,
|
||||
tags: preset.metadata.tags,
|
||||
is_factory: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load user presets
|
||||
if let Ok(app_data_dir) = app_handle.path().app_data_dir() {
|
||||
let user_presets_dir = app_data_dir.join("presets");
|
||||
if user_presets_dir.exists() {
|
||||
if let Ok(entries) = fs::read_dir(user_presets_dir) {
|
||||
for entry in entries.flatten() {
|
||||
if let Ok(path) = entry.path().canonicalize() {
|
||||
if path.extension().and_then(|s| s.to_str()) == Some("json") {
|
||||
if let Ok(json) = fs::read_to_string(&path) {
|
||||
if let Ok(preset) = GraphPreset::from_json(&json) {
|
||||
presets.push(PresetInfo {
|
||||
name: preset.metadata.name,
|
||||
path: path.to_string_lossy().to_string(),
|
||||
description: preset.metadata.description,
|
||||
author: preset.metadata.author,
|
||||
tags: preset.metadata.tags,
|
||||
is_factory: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(presets)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn graph_delete_preset(
|
||||
preset_path: String,
|
||||
) -> Result<(), String> {
|
||||
use std::fs;
|
||||
|
||||
// Only allow deleting user presets (not factory presets)
|
||||
if preset_path.contains("factory") || preset_path.contains("assets") {
|
||||
return Err("Cannot delete factory presets".to_string());
|
||||
}
|
||||
|
||||
fs::remove_file(&preset_path)
|
||||
.map_err(|e| format!("Failed to delete preset: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn graph_get_state(
|
||||
state: tauri::State<'_, Arc<Mutex<AudioState>>>,
|
||||
track_id: u32,
|
||||
) -> Result<String, String> {
|
||||
use daw_backend::GraphPreset;
|
||||
|
||||
let mut audio_state = state.lock().unwrap();
|
||||
if let Some(controller) = &mut audio_state.controller {
|
||||
// Send a command to get the graph state
|
||||
// For now, we'll use the preset serialization to get the graph
|
||||
let temp_path = std::env::temp_dir().join(format!("temp_graph_state_{}.json", track_id));
|
||||
let temp_path_str = temp_path.to_string_lossy().to_string();
|
||||
|
||||
controller.graph_save_preset(
|
||||
track_id,
|
||||
temp_path_str.clone(),
|
||||
"temp".to_string(),
|
||||
"".to_string(),
|
||||
vec![]
|
||||
);
|
||||
|
||||
// Give the audio thread time to process
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
|
||||
// Read the temp file
|
||||
let json = match std::fs::read_to_string(&temp_path) {
|
||||
Ok(json) => json,
|
||||
Err(_) => {
|
||||
// If file doesn't exist, graph is likely empty - return empty preset
|
||||
let empty_preset = GraphPreset::new("empty");
|
||||
empty_preset.to_json().unwrap_or_else(|_| "{}".to_string())
|
||||
}
|
||||
};
|
||||
|
||||
// Clean up temp file
|
||||
let _ = std::fs::remove_file(&temp_path);
|
||||
|
||||
Ok(json)
|
||||
} else {
|
||||
Err("Audio not initialized".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Clone)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum SerializedAudioEvent {
|
||||
|
||||
@@ -222,6 +222,11 @@ pub fn run() {
|
||||
audio::graph_disconnect,
|
||||
audio::graph_set_parameter,
|
||||
audio::graph_set_output_node,
|
||||
audio::graph_save_preset,
|
||||
audio::graph_load_preset,
|
||||
audio::graph_list_presets,
|
||||
audio::graph_delete_preset,
|
||||
audio::graph_get_state,
|
||||
])
|
||||
// .manage(window_counter)
|
||||
.build(tauri::generate_context!())
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"resources": [
|
||||
"assets/factory_presets/*"
|
||||
],
|
||||
"linux": {
|
||||
"appimage": {
|
||||
"bundleMediaFramework": true,
|
||||
|
||||
Reference in New Issue
Block a user