Add spectrogram

This commit is contained in:
Skyler Lehmkuhl
2026-02-12 18:37:34 -05:00
parent ad81cce0c6
commit c11dab928c
10 changed files with 2203 additions and 33 deletions
@@ -24,6 +24,7 @@ pub mod create_folder;
pub mod rename_folder;
pub mod delete_folder;
pub mod move_asset_to_folder;
pub mod update_midi_notes;
pub use add_clip_instance::AddClipInstanceAction;
pub use add_effect::AddEffectAction;
@@ -46,3 +47,4 @@ pub use create_folder::CreateFolderAction;
pub use rename_folder::RenameFolderAction;
pub use delete_folder::{DeleteFolderAction, DeleteStrategy};
pub use move_asset_to_folder::MoveAssetToFolderAction;
pub use update_midi_notes::UpdateMidiNotesAction;
@@ -0,0 +1,74 @@
use crate::action::Action;
use crate::document::Document;
use uuid::Uuid;
/// Action to update MIDI notes in a clip (supports undo/redo)
///
/// Stores the before and after note states. MIDI note data lives in the backend,
/// so execute/rollback are no-ops on the document — all changes go through
/// execute_backend/rollback_backend.
pub struct UpdateMidiNotesAction {
/// Layer containing the MIDI clip
pub layer_id: Uuid,
/// Backend MIDI clip ID
pub midi_clip_id: u32,
/// Notes before the edit: (start_time, note, velocity, duration)
pub old_notes: Vec<(f64, u8, u8, f64)>,
/// Notes after the edit: (start_time, note, velocity, duration)
pub new_notes: Vec<(f64, u8, u8, f64)>,
/// Human-readable description
pub description_text: String,
}
impl Action for UpdateMidiNotesAction {
fn execute(&mut self, _document: &mut Document) -> Result<(), String> {
// MIDI note data lives in the backend, not the document
Ok(())
}
fn rollback(&mut self, _document: &mut Document) -> Result<(), String> {
Ok(())
}
fn description(&self) -> String {
self.description_text.clone()
}
fn execute_backend(
&mut self,
backend: &mut crate::action::BackendContext,
_document: &Document,
) -> Result<(), String> {
let controller = match backend.audio_controller.as_mut() {
Some(c) => c,
None => return Ok(()),
};
let track_id = backend
.layer_to_track_map
.get(&self.layer_id)
.ok_or_else(|| format!("Layer {} not mapped to backend track", self.layer_id))?;
controller.update_midi_clip_notes(*track_id, self.midi_clip_id, self.new_notes.clone());
Ok(())
}
fn rollback_backend(
&mut self,
backend: &mut crate::action::BackendContext,
_document: &Document,
) -> Result<(), String> {
let controller = match backend.audio_controller.as_mut() {
Some(c) => c,
None => return Ok(()),
};
let track_id = backend
.layer_to_track_map
.get(&self.layer_id)
.ok_or_else(|| format!("Layer {} not mapped to backend track", self.layer_id))?;
controller.update_midi_clip_notes(*track_id, self.midi_clip_id, self.old_notes.clone());
Ok(())
}
}