add clear node graph button

This commit is contained in:
Skyler Lehmkuhl
2025-11-12 11:23:46 -05:00
parent 30aa639460
commit 5d84522a74
7 changed files with 647 additions and 9 deletions
+43
View File
@@ -959,6 +959,49 @@ pub async fn graph_load_preset(
}
}
#[tauri::command]
pub async fn graph_load_preset_from_json(
state: tauri::State<'_, Arc<Mutex<AudioState>>>,
track_id: u32,
preset_json: String,
) -> Result<(), String> {
use daw_backend::GraphPreset;
use std::io::Write;
let mut audio_state = state.lock().unwrap();
// Parse the preset JSON to count nodes
let preset = GraphPreset::from_json(&preset_json)
.map_err(|e| format!("Failed to parse preset: {}", e))?;
// Update the node ID counter to account for nodes in the preset
let node_count = preset.nodes.len() as u32;
audio_state.next_graph_node_id = node_count;
if let Some(controller) = &mut audio_state.controller {
// Write JSON to a temporary file
let temp_path = std::env::temp_dir().join(format!("lb_temp_preset_{}.json", track_id));
let mut file = std::fs::File::create(&temp_path)
.map_err(|e| format!("Failed to create temp file: {}", e))?;
file.write_all(preset_json.as_bytes())
.map_err(|e| format!("Failed to write temp file: {}", e))?;
drop(file);
// Load from the temp file
controller.graph_load_preset(track_id, temp_path.to_string_lossy().to_string());
// Clean up temp file (after a delay to allow loading)
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(500));
let _ = std::fs::remove_file(temp_path);
});
Ok(())
} else {
Err("Audio not initialized".to_string())
}
}
#[derive(serde::Serialize)]
pub struct PresetInfo {
pub name: String,
+44
View File
@@ -43,6 +43,47 @@ fn error(msg: String) {
error!("{}",msg);
}
#[tauri::command]
async fn open_folder_dialog(app: AppHandle, title: String) -> Result<Option<String>, String> {
use tauri_plugin_dialog::DialogExt;
let folder = app.dialog()
.file()
.set_title(&title)
.blocking_pick_folder();
Ok(folder.map(|path| path.to_string()))
}
#[tauri::command]
async fn read_folder_files(path: String) -> Result<Vec<String>, String> {
use std::fs;
let entries = fs::read_dir(&path)
.map_err(|e| format!("Failed to read directory: {}", e))?;
let audio_extensions = vec!["wav", "aif", "aiff", "flac", "mp3", "ogg"];
let mut files = Vec::new();
for entry in entries {
let entry = entry.map_err(|e| format!("Failed to read entry: {}", e))?;
let path = entry.path();
if path.is_file() {
if let Some(ext) = path.extension() {
let ext_str = ext.to_string_lossy().to_lowercase();
if audio_extensions.contains(&ext_str.as_str()) {
if let Some(filename) = path.file_name() {
files.push(filename.to_string_lossy().to_string());
}
}
}
}
}
Ok(files)
}
use tauri::PhysicalSize;
#[tauri::command]
@@ -241,6 +282,7 @@ pub fn run() {
audio::graph_set_output_node,
audio::graph_save_preset,
audio::graph_load_preset,
audio::graph_load_preset_from_json,
audio::graph_list_presets,
audio::graph_delete_preset,
audio::graph_get_state,
@@ -265,6 +307,8 @@ pub fn run() {
video::video_get_frame,
video::video_get_frames_batch,
video::video_set_cache_size,
open_folder_dialog,
read_folder_files,
video::video_get_pool_info,
video::video_ipc_benchmark,
video::video_get_transcode_status,