Timeline types stage 2: fix editor seconds↔beats at every clip boundary
Thread Beats/Seconds through the editor now that lightningbeam-core is typed. The timeline UI is seconds-domain (pixels_per_second, viewport_start_time, playback_time, drag_offset), while ClipInstance.timeline_start/duration/ loop_before are beats — the compiler flagged every place the two were mixed. Fixes the reported bugs and the whole class behind them: - Recording placement (audio + MIDI + webcam): the new clip's timeline_start was written from playback_time (seconds) into a beats field, so a second recording landed at the wrong time. Now converted via the tempo map. - Drag/move: introduce snapped_move_offset -> Beats (snap in the seconds/pixel domain, express the anchor's movement in beats) and moved_start(); the group clamp, live preview, and commit all use one uniform beats offset instead of adding a seconds delta to a beats position. - Trim/loop drag preview + commit: overlap limits come from the timeline (beats) but trims are content seconds — converted at the boundary. - Drop (asset drag, stage + timeline), paste, duplicate, split-at-playhead: all convert the seconds drop/playhead position to beats before placing. - Stage playback gates + clip-local time remap: compared seconds playback_time against beats timeline_start; now both in seconds. - Piano roll / infopanel / effect export: clip_dur is Seconds; effect and waveform data converted at use. Core API refinement (motivated by the above): find_max_trim_extend_left/right now return Seconds (the content-seconds gap) instead of raw Beats, since every trim caller wants seconds; loop-extend callers convert to beats. Added a beats_to_x() timeline helper. Whole workspace compiles; 299 core tests pass.
This commit is contained in:
@@ -1186,19 +1186,21 @@ impl Document {
|
||||
///
|
||||
/// Returns the distance to the nearest clip to the left, or the distance to
|
||||
/// timeline start (0.0) if no clips exist to the left.
|
||||
/// Returns the max leftward trim extension as a content-seconds span (the wall-clock
|
||||
/// length of the timeline gap to the previous clip); the trim domain is seconds.
|
||||
pub fn find_max_trim_extend_left(
|
||||
&self,
|
||||
layer_id: &Uuid,
|
||||
instance_id: &Uuid,
|
||||
current_timeline_start: Beats,
|
||||
) -> Beats {
|
||||
) -> Seconds {
|
||||
let Some(layer) = self.get_layer(layer_id) else {
|
||||
return current_timeline_start; // No limit if layer not found
|
||||
return self.tempo_map().beats_to_seconds(current_timeline_start); // No limit if layer not found
|
||||
};
|
||||
|
||||
// Only check audio, video, and effect layers
|
||||
if matches!(layer, AnyLayer::Vector(_) | AnyLayer::Group(_)) {
|
||||
return current_timeline_start; // No limit for vector/group layers
|
||||
return self.tempo_map().beats_to_seconds(current_timeline_start); // No limit for vector/group layers
|
||||
};
|
||||
|
||||
// Find the nearest clip to the left
|
||||
@@ -1231,27 +1233,27 @@ impl Document {
|
||||
}
|
||||
}
|
||||
|
||||
current_timeline_start - nearest_end
|
||||
self.tempo_map().beats_to_seconds(current_timeline_start) - self.tempo_map().beats_to_seconds(nearest_end)
|
||||
}
|
||||
|
||||
/// Find the maximum amount we can extend a clip to the right without overlapping
|
||||
/// Find the maximum amount we can extend a clip to the right without overlapping.
|
||||
///
|
||||
/// Returns the distance to the nearest clip to the right, or f64::MAX if no
|
||||
/// clips exist to the right.
|
||||
/// Returns the content-seconds span of the timeline gap to the nearest clip on the
|
||||
/// right, or Seconds(f64::MAX) if none. `current_effective_duration` is beats (timeline).
|
||||
pub fn find_max_trim_extend_right(
|
||||
&self,
|
||||
layer_id: &Uuid,
|
||||
instance_id: &Uuid,
|
||||
current_timeline_start: Beats,
|
||||
current_effective_duration: Beats,
|
||||
) -> Beats {
|
||||
) -> Seconds {
|
||||
let Some(layer) = self.get_layer(layer_id) else {
|
||||
return Beats(f64::MAX); // No limit if layer not found
|
||||
return Seconds(f64::MAX); // No limit if layer not found
|
||||
};
|
||||
|
||||
// Only check audio, video, and effect layers
|
||||
if matches!(layer, AnyLayer::Vector(_) | AnyLayer::Group(_)) {
|
||||
return Beats(f64::MAX); // No limit for vector/group layers
|
||||
return Seconds(f64::MAX); // No limit for vector/group layers
|
||||
}
|
||||
|
||||
let instances: &[ClipInstance] = match layer {
|
||||
@@ -1280,9 +1282,10 @@ impl Document {
|
||||
}
|
||||
|
||||
if nearest_start == Beats(f64::MAX) {
|
||||
Beats(f64::MAX) // No clip to the right, can extend freely
|
||||
Seconds(f64::MAX) // No clip to the right, can extend freely
|
||||
} else {
|
||||
(nearest_start - current_end).max(Beats::ZERO) // Gap between our end and next clip's start
|
||||
// Gap between our end and next clip's start, as content seconds.
|
||||
(self.tempo_map().beats_to_seconds(nearest_start) - self.tempo_map().beats_to_seconds(current_end)).max(Seconds::ZERO)
|
||||
}
|
||||
}
|
||||
/// Find the maximum amount we can extend loop_before to the left without overlapping.
|
||||
|
||||
Reference in New Issue
Block a user