forge
Explore
Log in

Don't you dare go Hollow

Loop honors the i/o range (range > trim > whole timeline)

Browse files at this commit

7867c90f8ed0e515e3f9466de8f166cc9c2484b7Ahmet Kaan GümüşParent: 9e3e5bc0d4b12a
  • feat
    • loop honors the i/o range (range > trim > whole timeline)
Show full message
✨ feat(transport): loop honors the i/o range (range > trim > whole timeline)
crates/app/src/player/transport.rsmodified+50 -17
@@ -46,14 +46,17 @@ impl Player {
46 let Some(session) = self.preview_session.as_mut().or(self.session.as_mut()) else {46 let Some(session) = self.preview_session.as_mut().or(self.session.as_mut()) else {
47 return;47 return;
48 };48 };
49- // Loop-trim (DESIGN.md §6): the transport is kept inside the subject49+ // Loop-trim and the i/o range (DESIGN.md §6): the transport is kept
50- // cut's own span while the mode is on, so a trim can be heard and50+ // inside the active window while one is armed, so a trim or a marked
51- // seen without a manual replay after every nudge. Checked off the51+ // range can be heard and seen without a manual replay after every
52- // engine's own clock, not a frame counter this pump keeps -- the52+ // nudge. The range wins over the trim when both are set
53- // same `now()` [`Player::step`] reads.53+ // ([`active_loop_window`]). Checked off the engine's own clock, not
54- if session.is_playing() && should_loop_restart(frame_at(session.now(), fps), self.loop_trim)54+ // a frame counter this pump keeps -- the same `now()`
55+ // [`Player::step`] reads.
56+ let loop_window = active_loop_window(self.loop_on, self.range, self.loop_trim);
57+ if session.is_playing() && should_loop_restart(frame_at(session.now(), fps), loop_window)
55 {58 {
56- let start = self.loop_trim.map_or(0, |(lo, _)| lo);59+ let start = loop_window.map_or(0, |(lo, _)| lo);
57 session.seek(f64::from(start) / fps);60 session.seek(f64::from(start) / fps);
58 }61 }
59 // Whether the span now decoding has yet to hand over a picture, read62 // Whether the span now decoding has yet to hand over a picture, read
@@ -172,6 +175,10 @@ impl Player {
172 // whole-timeline loop already used, so that race has nothing175 // whole-timeline loop already used, so that race has nothing
173 // left to win: reaching the end while *either* loop is armed176 // left to win: reaching the end while *either* loop is armed
174 // restarts rather than halts, regardless of which one owns it.177 // restarts rather than halts, regardless of which one owns it.
178+ // A bare i/o range never arms this crossing on its own -- it is
179+ // an export mark first ([`active_loop_window`]) -- so `range`
180+ // only ever widens `armed` through the `loop_on`/`loop_trim`
181+ // terms already here, never past them.
175 let armed = self.loop_on || self.loop_trim.is_some();182 let armed = self.loop_on || self.loop_trim.is_some();
176 if crosses_into_loop(was, Transport::Ended, armed) {183 if crosses_into_loop(was, Transport::Ended, armed) {
177 // The same door the restart button and key use184 // The same door the restart button and key use
@@ -179,7 +186,8 @@ impl Player {
179 // spends only on a repaint -- the pump is already inside one.186 // spends only on a repaint -- the pump is already inside one.
180 // One seam of a one-frame seam: the restart is a fresh seek187 // One seam of a one-frame seam: the restart is a fresh seek
181 // and its reopen, not a gapless splice.188 // and its reopen, not a gapless splice.
182- let start = loop_restart_frame(self.loop_on, self.loop_trim).unwrap_or(0);189+ let start =
190+ loop_restart_frame(self.loop_on, self.range, self.loop_trim).unwrap_or(0);
183 if let Some(session) = self.active_session_mut() {191 if let Some(session) = self.active_session_mut() {
184 session.seek(f64::from(start) / fps);192 session.seek(f64::from(start) / fps);
185 }193 }
@@ -474,20 +482,45 @@ mod tests {
474 }482 }
475 483
476 /// `loop_restart_frame` picks the seek target the crossing above plays484 /// `loop_restart_frame` picks the seek target the crossing above plays
477- /// from: the trim window's near edge when one is armed (it wins over the485+ /// from: the i/o range's near edge when one is armed and set (it wins
478- /// whole-timeline loop when both happen to be set), the top of the486+ /// over both the trim window and the whole-timeline loop), the trim
479- /// timeline for the whole-timeline loop alone, and no restart at all487+ /// window's near edge next, the top of the timeline for the
480- /// with neither armed.488+ /// whole-timeline loop alone, and no restart at all with nothing armed.
481 #[test]489 #[test]
482 fn loop_restart_frame_prefers_the_trim_window_then_the_whole_timeline_then_nothing() {490 fn loop_restart_frame_prefers_the_trim_window_then_the_whole_timeline_then_nothing() {
483- assert_eq!(loop_restart_frame(false, Some((30, 60))), Some(30));491+ assert_eq!(loop_restart_frame(false, None, Some((30, 60))), Some(30));
484 assert_eq!(492 assert_eq!(
485- loop_restart_frame(true, Some((30, 60))),493+ loop_restart_frame(true, None, Some((30, 60))),
486 Some(30),494 Some(30),
487 "the trim window wins over the whole-timeline loop"495 "the trim window wins over the whole-timeline loop"
488 );496 );
489- assert_eq!(loop_restart_frame(true, None), Some(0));497+ assert_eq!(loop_restart_frame(true, None, None), Some(0));
490- assert_eq!(loop_restart_frame(false, None), None);498+ assert_eq!(loop_restart_frame(false, None, None), None);
499+ // The i/o range beats the trim window when both are set...
500+ assert_eq!(
501+ loop_restart_frame(true, Some((10, 20)), Some((30, 60))),
502+ Some(10),
503+ "the marked range wins over the subject-cut trim"
504+ );
505+ // ...and a range alone, with loop off and no trim, never arms a
506+ // restart at all -- it is an export mark first.
507+ assert_eq!(
508+ loop_restart_frame(false, Some((10, 20)), None),
509+ None,
510+ "a bare i/o range must not start looping un-looped playback"
511+ );
512+ // Clearing the range falls back to the trim window, then to the
513+ // whole timeline.
514+ assert_eq!(
515+ loop_restart_frame(true, None, Some((30, 60))),
516+ Some(30),
517+ "clearing the range falls back to the trim window"
518+ );
519+ assert_eq!(
520+ loop_restart_frame(true, None, None),
521+ Some(0),
522+ "clearing both the range and the trim falls back to the whole timeline"
523+ );
491 }524 }
492 525
493 /// The bug this session fixed: a loop-trim window whose far edge (60)526 /// The bug this session fixed: a loop-trim window whose far edge (60)
@@ -509,7 +542,7 @@ mod tests {
509 Transport::Ended,542 Transport::Ended,
510 armed543 armed
511 ));544 ));
512- assert_eq!(loop_restart_frame(loop_on, loop_trim), Some(30));545+ assert_eq!(loop_restart_frame(loop_on, None, loop_trim), Some(30));
513 }546 }
514 547
515 /// A loop window sitting entirely before the film's end never reaches548 /// A loop window sitting entirely before the film's end never reaches
crates/app/src/timeline_math.rsmodified+30 -8
@@ -362,15 +362,37 @@ pub(crate) fn should_loop_restart(frame: u32, window: Option<(u32, u32)>) -> boo
362 window.is_some_and(|(_, hi)| frame >= hi)362 window.is_some_and(|(_, hi)| frame >= hi)
363 }363 }
364 364
365+/// Which window is actually looping, in priority order: the i/o range
366+/// ([`Player::range`]) beats the subject-cut trim ([`Player::loop_trim`])
367+/// beats the whole timeline -- but only once *something* is already armed
368+/// (`loop_on` or `loop_trim`). A bare in/out mark with neither on is an
369+/// export mark first, not a loop request, so it answers `None` here and
370+/// never restarts anything on its own.
371+pub(crate) fn active_loop_window(
372+ loop_on: bool,
373+ range: Option<(u32, u32)>,
374+ loop_trim: Option<(u32, u32)>,
375+) -> Option<(u32, u32)> {
376+ if !loop_on && loop_trim.is_none() {
377+ return None;
378+ }
379+ range.or(loop_trim)
380+}
381+
365 /// Where a play resumes from on crossing into [`Transport::Ended`]382 /// Where a play resumes from on crossing into [`Transport::Ended`]
366-/// (`Player::pump`): the loop-trim window's own near edge when one is armed,383+/// (`Player::pump`): the active window's own near edge
367-/// *even when its far edge is the film's own last frame* -- half of all cuts384+/// ([`active_loop_window`]) when one is armed, *even when its far edge is
368-/// in a two-clip film sit on the final clip (DESIGN.md §6), so that coincidence385+/// the film's own last frame* -- half of all cuts in a two-clip film sit on
369-/// is not an edge case and must not read as "reached the end, stop". Falls386+/// the final clip (DESIGN.md §6), so that coincidence is not an edge case
370-/// back to the whole-timeline loop's top, and `None` -- neither armed --387+/// and must not read as "reached the end, stop". Falls back to the
371-/// restarts nothing, which is the halt this crossing otherwise means.388+/// whole-timeline loop's top, and `None` -- nothing armed -- restarts
372-pub(crate) fn loop_restart_frame(loop_on: bool, loop_trim: Option<(u32, u32)>) -> Option<u32> {389+/// nothing, which is the halt this crossing otherwise means.
373- match loop_trim {390+pub(crate) fn loop_restart_frame(
391+ loop_on: bool,
392+ range: Option<(u32, u32)>,
393+ loop_trim: Option<(u32, u32)>,
394+) -> Option<u32> {
395+ match active_loop_window(loop_on, range, loop_trim) {
374 Some((lo, _)) => Some(lo),396 Some((lo, _)) => Some(lo),
375 None => loop_on.then_some(0),397 None => loop_on.then_some(0),
376 }398 }
crates/app/src/ui/toolbar.rsmodified+13 -1
@@ -170,6 +170,18 @@ impl Player {
170 - 2. * SPLIT_W;170 - 2. * SPLIT_W;
171 let clock_w = TIME_W.min(room - 140.).max(96.);171 let clock_w = TIME_W.min(room - 140.).max(96.);
172 let slider = room >= TRANSPORT_ROOMY;172 let slider = room >= TRANSPORT_ROOMY;
173+ // Which window the loop button actually restarts, in the same
174+ // priority [`active_loop_window`] picks it in: the marked i/o range
175+ // once something is armed, the subject-cut trim next, the whole
176+ // timeline last.
177+ let armed = self.loop_on || self.loop_trim.is_some();
178+ let loop_hint = if armed && self.range.is_some() {
179+ "restarts from the marked in point on reaching the marked out point, instead of stopping"
180+ } else if self.loop_trim.is_some() {
181+ "restarts from the subject cut's own start on reaching its end, instead of stopping"
182+ } else {
183+ "restarts from the top on reaching the end, instead of stopping"
184+ };
173 div()185 div()
174 .flex_none()186 .flex_none()
175 .h(px(TRANSPORT_H))187 .h(px(TRANSPORT_H))
@@ -213,7 +225,7 @@ impl Player {
213 },225 },
214 None,226 None,
215 "Loop",227 "Loop",
216- "restarts from the top on reaching the end, instead of stopping",228+ loop_hint,
217 ActionId::Loop,229 ActionId::Loop,
218 cx.listener(|this, _: &ClickEvent, window, cx| {230 cx.listener(|this, _: &ClickEvent, window, cx| {
219 this.act(ActionId::Loop, window, cx)231 this.act(ActionId::Loop, window, cx)