Type the rest of the audio-controller boundary (no more bare-f64 wrapping)
Push Beats/Seconds through the remaining controller methods that took a bare f64 and let the audio thread wrap it in a newtype, so the caller's domain is now compiler-checked (the seam that hid the recording bug): - seek -> Seconds - set_trim_start/set_trim_end -> Seconds / Option<Seconds> (metatrack, always seconds) - add_midi_note, add_loaded_midi_clip, update_midi_clip_notes -> Beats - add_automation_point, remove_automation_point, automation_add_keyframe, automation_remove_keyframe -> Beats Command enums stay raw f64 transport; only the public signatures + call sites change. No behavior change — every caller already passed the right domain, this just makes it enforced. Two deliberate exceptions, documented in place: - trim_clip stays f64: the TrimClip handler interprets it as Seconds for a sampled-audio clip but Beats for a MIDI clip, so no single newtype fits; callers pass the clip's own trim value, which matches its content domain. - The piano-roll MIDI note model stays f64 internally (a beats-only subsystem with no seconds anywhere); it's converted to Beats at the update_midi_clip_notes boundary in UpdateMidiNotesAction, same as trim_start f64 -> Seconds at add_audio_clip.
This commit is contained in:
@@ -211,8 +211,8 @@ impl Action for MoveClipInstancesAction {
|
||||
// Check if this clip has a metatrack
|
||||
if let Some(&metatrack_id) = backend.layer_to_track_map.get(&instance.clip_id) {
|
||||
controller.set_offset(metatrack_id, document.tempo_map().beats_to_seconds(*new_start));
|
||||
controller.set_trim_start(metatrack_id, instance.trim_start);
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end);
|
||||
controller.set_trim_start(metatrack_id, daw_backend::Seconds(instance.trim_start));
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end.map(daw_backend::Seconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,8 +295,8 @@ impl Action for MoveClipInstancesAction {
|
||||
if let Some(instance) = vl.clip_instances.iter().find(|ci| ci.id == *instance_id) {
|
||||
if let Some(&metatrack_id) = backend.layer_to_track_map.get(&instance.clip_id) {
|
||||
controller.set_offset(metatrack_id, document.tempo_map().beats_to_seconds(*old_start));
|
||||
controller.set_trim_start(metatrack_id, instance.trim_start);
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end);
|
||||
controller.set_trim_start(metatrack_id, daw_backend::Seconds(instance.trim_start));
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end.map(daw_backend::Seconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,8 +387,8 @@ impl Action for TrimClipInstancesAction {
|
||||
if let Some(&metatrack_id) = backend.layer_to_track_map.get(&instance.clip_id) {
|
||||
// Instance already has new values after execute()
|
||||
controller.set_offset(metatrack_id, document.tempo_map().beats_to_seconds(instance.timeline_start));
|
||||
controller.set_trim_start(metatrack_id, instance.trim_start);
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end);
|
||||
controller.set_trim_start(metatrack_id, daw_backend::Seconds(instance.trim_start));
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end.map(daw_backend::Seconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,8 +477,8 @@ impl Action for TrimClipInstancesAction {
|
||||
if let Some(&metatrack_id) = backend.layer_to_track_map.get(&instance.clip_id) {
|
||||
// Instance already has old values after rollback()
|
||||
controller.set_offset(metatrack_id, document.tempo_map().beats_to_seconds(instance.timeline_start));
|
||||
controller.set_trim_start(metatrack_id, instance.trim_start);
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end);
|
||||
controller.set_trim_start(metatrack_id, daw_backend::Seconds(instance.trim_start));
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end.map(daw_backend::Seconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
use crate::action::Action;
|
||||
use crate::document::Document;
|
||||
use daw_backend::Beats;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Convert editor-side beats-domain note tuples to the typed backend form.
|
||||
fn notes_to_beats(notes: &[(f64, u8, u8, f64)]) -> Vec<(Beats, u8, u8, Beats)> {
|
||||
notes.iter().map(|&(t, n, v, d)| (Beats(t), n, v, Beats(d))).collect()
|
||||
}
|
||||
|
||||
/// 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,
|
||||
@@ -49,7 +55,8 @@ impl Action for UpdateMidiNotesAction {
|
||||
.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());
|
||||
// Note times/durations are beats (MIDI content domain); assert that at the typed boundary.
|
||||
controller.update_midi_clip_notes(*track_id, self.midi_clip_id, notes_to_beats(&self.new_notes));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -68,7 +75,7 @@ impl Action for UpdateMidiNotesAction {
|
||||
.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());
|
||||
controller.update_midi_clip_notes(*track_id, self.midi_clip_id, notes_to_beats(&self.old_notes));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user