File save/load

This commit is contained in:
Skyler Lehmkuhl
2025-12-01 09:18:49 -05:00
parent 5379e3bc8c
commit ba9a4ee812
19 changed files with 1339 additions and 73 deletions
@@ -1126,8 +1126,9 @@ impl AssetLibraryPane {
if asset_category == AssetCategory::Audio && !self.thumbnail_cache.has(&asset_id) {
if let Some(clip) = document.audio_clips.get(&asset_id) {
if let AudioClipType::Sampled { audio_pool_index } = &clip.clip_type {
if let Some(audio_controller) = shared.audio_controller.as_mut() {
audio_controller.get_pool_waveform(*audio_pool_index, THUMBNAIL_SIZE as usize)
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.get_pool_waveform(*audio_pool_index, THUMBNAIL_SIZE as usize)
.ok()
.map(|peaks| peaks.iter().map(|p| (p.min, p.max)).collect())
} else {
@@ -1397,8 +1398,9 @@ impl AssetLibraryPane {
if asset_category == AssetCategory::Audio && !self.thumbnail_cache.has(&asset_id) {
if let Some(clip) = document.audio_clips.get(&asset_id) {
if let AudioClipType::Sampled { audio_pool_index } = &clip.clip_type {
if let Some(audio_controller) = shared.audio_controller.as_mut() {
audio_controller.get_pool_waveform(*audio_pool_index, THUMBNAIL_SIZE as usize)
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.get_pool_waveform(*audio_pool_index, THUMBNAIL_SIZE as usize)
.ok()
.map(|peaks| peaks.iter().map(|p| (p.min, p.max)).collect())
} else {
@@ -107,8 +107,8 @@ pub struct SharedPaneState<'a> {
pub draw_simplify_mode: &'a mut lightningbeam_core::tool::SimplifyMode,
pub rdp_tolerance: &'a mut f64,
pub schneider_max_error: &'a mut f64,
/// Audio engine controller for playback control
pub audio_controller: Option<&'a mut daw_backend::EngineController>,
/// Audio engine controller for playback control (wrapped in Arc<Mutex<>> for thread safety)
pub audio_controller: Option<&'a std::sync::Arc<std::sync::Mutex<daw_backend::EngineController>>>,
/// Mapping from Document layer UUIDs to daw-backend TrackIds
pub layer_to_track_map: &'a std::collections::HashMap<Uuid, daw_backend::TrackId>,
/// Global playback state
@@ -975,7 +975,7 @@ impl TimelinePane {
pending_actions: &mut Vec<Box<dyn lightningbeam_core::action::Action>>,
playback_time: &mut f64,
is_playing: &mut bool,
audio_controller: Option<&mut daw_backend::EngineController>,
audio_controller: Option<&std::sync::Arc<std::sync::Mutex<daw_backend::EngineController>>>,
) {
// Don't allocate the header area for input - let widgets handle it directly
// Only allocate content area (ruler + layers) with click and drag
@@ -1382,7 +1382,8 @@ impl TimelinePane {
else if !response.dragged() && self.is_scrubbing {
self.is_scrubbing = false;
// Seek the audio engine to the new position
if let Some(controller) = audio_controller {
if let Some(controller_arc) = audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.seek(*playback_time);
}
}
@@ -1492,7 +1493,8 @@ impl PaneRenderer for TimelinePane {
// Go to start
if ui.add_sized(button_size, egui::Button::new("|◀")).clicked() {
*shared.playback_time = 0.0;
if let Some(controller) = shared.audio_controller.as_mut() {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.seek(0.0);
}
}
@@ -1500,7 +1502,8 @@ impl PaneRenderer for TimelinePane {
// Rewind (step backward)
if ui.add_sized(button_size, egui::Button::new("◀◀")).clicked() {
*shared.playback_time = (*shared.playback_time - 0.1).max(0.0);
if let Some(controller) = shared.audio_controller.as_mut() {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.seek(*shared.playback_time);
}
}
@@ -1512,7 +1515,8 @@ impl PaneRenderer for TimelinePane {
println!("🔘 Play/Pause button clicked! is_playing = {}", *shared.is_playing);
// Send play/pause command to audio engine
if let Some(controller) = shared.audio_controller.as_mut() {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
if *shared.is_playing {
controller.play();
println!("▶ Started playback");
@@ -1528,7 +1532,8 @@ impl PaneRenderer for TimelinePane {
// Fast forward (step forward)
if ui.add_sized(button_size, egui::Button::new("▶▶")).clicked() {
*shared.playback_time = (*shared.playback_time + 0.1).min(self.duration);
if let Some(controller) = shared.audio_controller.as_mut() {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.seek(*shared.playback_time);
}
}
@@ -1536,7 +1541,8 @@ impl PaneRenderer for TimelinePane {
// Go to end
if ui.add_sized(button_size, egui::Button::new("▶|")).clicked() {
*shared.playback_time = self.duration;
if let Some(controller) = shared.audio_controller.as_mut() {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.seek(self.duration);
}
}
@@ -1690,7 +1696,7 @@ impl PaneRenderer for TimelinePane {
shared.pending_actions,
shared.playback_time,
shared.is_playing,
shared.audio_controller.as_mut().map(|c| &mut **c),
shared.audio_controller,
);
// Handle asset drag-and-drop from Asset Library
@@ -358,7 +358,8 @@ impl VirtualPianoPane {
if let Some(active_layer_id) = *shared.active_layer_id {
// Look up daw-backend track ID from layer ID
if let Some(&track_id) = shared.layer_to_track_map.get(&active_layer_id) {
if let Some(ref mut controller) = shared.audio_controller {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.send_midi_note_on(track_id, note, velocity);
}
}
@@ -380,7 +381,8 @@ impl VirtualPianoPane {
if let Some(active_layer_id) = *shared.active_layer_id {
if let Some(&track_id) = shared.layer_to_track_map.get(&active_layer_id) {
if let Some(ref mut controller) = shared.audio_controller {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.send_midi_note_off(track_id, note);
}
}
@@ -560,7 +562,8 @@ impl VirtualPianoPane {
self.pressed_notes.remove(&note);
if let Some(active_layer_id) = *shared.active_layer_id {
if let Some(&track_id) = shared.layer_to_track_map.get(&active_layer_id) {
if let Some(ref mut controller) = shared.audio_controller {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.send_midi_note_off(track_id, note);
}
}
@@ -573,7 +576,8 @@ impl VirtualPianoPane {
self.pressed_notes.remove(note);
if let Some(active_layer_id) = *shared.active_layer_id {
if let Some(&track_id) = shared.layer_to_track_map.get(&active_layer_id) {
if let Some(ref mut controller) = shared.audio_controller {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.send_midi_note_off(track_id, *note);
}
}