Add pitch bend support

This commit is contained in:
Skyler Lehmkuhl
2026-03-18 23:11:24 -04:00
parent 4f3da810d0
commit 6b6ae230a1
14 changed files with 891 additions and 199 deletions
@@ -109,6 +109,17 @@ pub trait Action: Send {
fn midi_notes_after_rollback(&self) -> Option<(u32, &[(f64, u8, u8, f64)])> {
None
}
/// Return full MIDI event data (CC, pitch bend, etc.) reflecting the state after execute/redo.
/// Used to keep the frontend MIDI event cache in sync after undo/redo.
fn midi_events_after_execute(&self) -> Option<(u32, &[daw_backend::audio::midi::MidiEvent])> {
None
}
/// Return full MIDI event data reflecting the state after rollback/undo.
fn midi_events_after_rollback(&self) -> Option<(u32, &[daw_backend::audio::midi::MidiEvent])> {
None
}
}
/// Action executor that wraps the document and manages undo/redo
@@ -280,6 +291,16 @@ impl ActionExecutor {
self.redo_stack.last().and_then(|a| a.midi_notes_after_rollback())
}
/// Get full MIDI event data from the last action on the undo stack (after redo).
pub fn last_undo_midi_events(&self) -> Option<(u32, &[daw_backend::audio::midi::MidiEvent])> {
self.undo_stack.last().and_then(|a| a.midi_events_after_execute())
}
/// Get full MIDI event data from the last action on the redo stack (after undo).
pub fn last_redo_midi_events(&self) -> Option<(u32, &[daw_backend::audio::midi::MidiEvent])> {
self.redo_stack.last().and_then(|a| a.midi_events_after_rollback())
}
/// Get the description of the next action to redo
pub fn redo_description(&self) -> Option<String> {
self.redo_stack.last().map(|a| a.description())
@@ -23,6 +23,7 @@ pub mod rename_folder;
pub mod delete_folder;
pub mod move_asset_to_folder;
pub mod update_midi_notes;
pub mod update_midi_events;
pub mod loop_clip_instances;
pub mod remove_clip_instances;
pub mod set_keyframe;
@@ -56,6 +57,7 @@ pub use rename_folder::RenameFolderAction;
pub use delete_folder::{DeleteFolderAction, DeleteStrategy};
pub use move_asset_to_folder::MoveAssetToFolderAction;
pub use update_midi_notes::UpdateMidiNotesAction;
pub use update_midi_events::UpdateMidiEventsAction;
pub use loop_clip_instances::LoopClipInstancesAction;
pub use remove_clip_instances::RemoveClipInstancesAction;
pub use set_keyframe::SetKeyframeAction;
@@ -0,0 +1,76 @@
use crate::action::Action;
use crate::document::Document;
use uuid::Uuid;
/// Action to replace all MIDI events in a clip (CC, pitch bend, notes, etc.) with undo/redo.
///
/// Used when editing per-note CC or pitch bend from the piano roll. Stores full
/// `MidiEvent` lists rather than the simplified note-tuple format of `UpdateMidiNotesAction`.
pub struct UpdateMidiEventsAction {
/// Layer containing the MIDI clip
pub layer_id: Uuid,
/// Backend MIDI clip ID
pub midi_clip_id: u32,
/// Full event list before the edit
pub old_events: Vec<daw_backend::audio::midi::MidiEvent>,
/// Full event list after the edit
pub new_events: Vec<daw_backend::audio::midi::MidiEvent>,
/// Human-readable description
pub description_text: String,
}
impl Action for UpdateMidiEventsAction {
fn execute(&mut self, _document: &mut Document) -> Result<(), String> {
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_events(*track_id, self.midi_clip_id, self.new_events.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_events(*track_id, self.midi_clip_id, self.old_events.clone());
Ok(())
}
fn midi_events_after_execute(&self) -> Option<(u32, &[daw_backend::audio::midi::MidiEvent])> {
Some((self.midi_clip_id, &self.new_events))
}
fn midi_events_after_rollback(&self) -> Option<(u32, &[daw_backend::audio::midi::MidiEvent])> {
Some((self.midi_clip_id, &self.old_events))
}
}