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:
Skyler Lehmkuhl
2026-07-11 14:33:22 -04:00
parent b5766672ee
commit 64bf9bb431
8 changed files with 64 additions and 51 deletions
+28 -23
View File
@@ -3348,8 +3348,8 @@ impl EngineController {
}
/// Seek to a specific position in seconds
pub fn seek(&mut self, seconds: f64) {
let _ = self.command_tx.push(Command::Seek(seconds));
pub fn seek(&mut self, seconds: Seconds) {
let _ = self.command_tx.push(Command::Seek(seconds.seconds_to_f64()));
}
/// Set track volume (0.0 = silence, 1.0 = unity gain)
@@ -3386,6 +3386,10 @@ impl EngineController {
/// Trim a clip's internal boundaries (changes which portion of source content is used)
/// This also resets external_duration to match internal duration (disables looping)
/// Trim a clip's internal content bounds. The units are content-domain and depend on the
/// track type: SECONDS for a sampled-audio clip, BEATS for a MIDI clip (see the TrimClip
/// handler). Left as raw f64 because a single newtype can't express both; callers pass the
/// clip's own `trim_start`/`trim_end`, which already match its content domain.
pub fn trim_clip(&mut self, track_id: TrackId, clip_id: ClipId, new_internal_start: f64, new_internal_end: f64) {
let _ = self.command_tx.push(Command::TrimClip(track_id, clip_id, new_internal_start, new_internal_end));
}
@@ -3450,13 +3454,13 @@ impl EngineController {
}
/// Set metatrack trim start in seconds
pub fn set_trim_start(&mut self, track_id: TrackId, trim_start: f64) {
let _ = self.command_tx.push(Command::SetTrimStart(track_id, trim_start));
pub fn set_trim_start(&mut self, track_id: TrackId, trim_start: Seconds) {
let _ = self.command_tx.push(Command::SetTrimStart(track_id, trim_start.seconds_to_f64()));
}
/// Set metatrack trim end in seconds (None = no end trim)
pub fn set_trim_end(&mut self, track_id: TrackId, trim_end: Option<f64>) {
let _ = self.command_tx.push(Command::SetTrimEnd(track_id, trim_end));
pub fn set_trim_end(&mut self, track_id: TrackId, trim_end: Option<Seconds>) {
let _ = self.command_tx.push(Command::SetTrimEnd(track_id, trim_end.map(|s| s.seconds_to_f64())));
}
/// Create a new audio track
@@ -3615,17 +3619,18 @@ impl EngineController {
}
/// Add a MIDI note to a clip
pub fn add_midi_note(&mut self, track_id: TrackId, clip_id: MidiClipId, time_offset: f64, note: u8, velocity: u8, duration: f64) {
let _ = self.command_tx.push(Command::AddMidiNote(track_id, clip_id, time_offset, note, velocity, duration));
pub fn add_midi_note(&mut self, track_id: TrackId, clip_id: MidiClipId, time_offset: Beats, note: u8, velocity: u8, duration: Beats) {
let _ = self.command_tx.push(Command::AddMidiNote(track_id, clip_id, time_offset.beats_to_f64(), note, velocity, duration.beats_to_f64()));
}
/// Add a pre-loaded MIDI clip to a track at the given timeline position
pub fn add_loaded_midi_clip(&mut self, track_id: TrackId, clip: MidiClip, start_time: f64) {
let _ = self.command_tx.push(Command::AddLoadedMidiClip(track_id, clip, start_time));
/// Add a pre-loaded MIDI clip to a track at the given timeline position (beats)
pub fn add_loaded_midi_clip(&mut self, track_id: TrackId, clip: MidiClip, start_time: Beats) {
let _ = self.command_tx.push(Command::AddLoadedMidiClip(track_id, clip, start_time.beats_to_f64()));
}
/// Update all notes in a MIDI clip
pub fn update_midi_clip_notes(&mut self, track_id: TrackId, clip_id: MidiClipId, notes: Vec<(f64, u8, u8, f64)>) {
/// Update all notes in a MIDI clip. Note tuples are (start [beats], note, velocity, duration [beats]).
pub fn update_midi_clip_notes(&mut self, track_id: TrackId, clip_id: MidiClipId, notes: Vec<(Beats, u8, u8, Beats)>) {
let notes = notes.into_iter().map(|(t, n, v, d)| (t.beats_to_f64(), n, v, d.beats_to_f64())).collect();
let _ = self.command_tx.push(Command::UpdateMidiClipNotes(track_id, clip_id, notes));
}
@@ -3661,25 +3666,25 @@ impl EngineController {
&mut self,
track_id: TrackId,
lane_id: crate::audio::AutomationLaneId,
time: f64,
time: Beats,
value: f32,
curve: crate::audio::CurveType,
) {
let _ = self.command_tx.push(Command::AddAutomationPoint(
track_id, lane_id, time, value, curve,
track_id, lane_id, time.beats_to_f64(), value, curve,
));
}
/// Remove an automation point at a specific time
/// Remove an automation point at a specific time (beats); tolerance is a beats delta
pub fn remove_automation_point(
&mut self,
track_id: TrackId,
lane_id: crate::audio::AutomationLaneId,
time: f64,
tolerance: f64,
time: Beats,
tolerance: Beats,
) {
let _ = self.command_tx.push(Command::RemoveAutomationPoint(
track_id, lane_id, time, tolerance,
track_id, lane_id, time.beats_to_f64(), tolerance.beats_to_f64(),
));
}
@@ -3715,16 +3720,16 @@ impl EngineController {
/// Add a keyframe to an AutomationInput node
pub fn automation_add_keyframe(&mut self, track_id: TrackId, node_id: u32,
time: f64, value: f32, interpolation: String,
time: Beats, value: f32, interpolation: String,
ease_out: (f32, f32), ease_in: (f32, f32)) {
let _ = self.command_tx.push(Command::AutomationAddKeyframe(
track_id, node_id, time, value, interpolation, ease_out, ease_in));
track_id, node_id, time.beats_to_f64(), value, interpolation, ease_out, ease_in));
}
/// Remove a keyframe from an AutomationInput node
pub fn automation_remove_keyframe(&mut self, track_id: TrackId, node_id: u32, time: f64) {
pub fn automation_remove_keyframe(&mut self, track_id: TrackId, node_id: u32, time: Beats) {
let _ = self.command_tx.push(Command::AutomationRemoveKeyframe(
track_id, node_id, time));
track_id, node_id, time.beats_to_f64()));
}
/// Set the display name of an AutomationInput node
+2 -2
View File
@@ -790,7 +790,7 @@ fn execute_command(
return Err("Usage: seek <seconds>".to_string());
}
let pos: f64 = parts[1].parse().map_err(|_| "Invalid position")?;
controller.seek(pos);
controller.seek(crate::Seconds(pos));
app.set_status(format!("Seeked to {:.2}s", pos));
}
"track" => {
@@ -882,7 +882,7 @@ fn execute_command(
app.next_clip_id += 1;
// Send to audio engine with the start_time (clip content is separate from timeline position)
controller.add_loaded_midi_clip(track_id, midi_clip, start_time);
controller.add_loaded_midi_clip(track_id, midi_clip, crate::Beats(start_time));
app.set_status(format!("Loaded {} ({} events, {:.2}s) to track {} at {:.2}s",
file_path, event_count, duration, track_id, start_time));