forge
Explore
Log in

Don't you dare go Hollow

Merge the interaction lane into main

Browse files at this commit

a78d43d6329123e20524f31578824aebc4eabf00Ahmet Kaan GümüşParent: 4d39c1856924e8
  • fix
    • merge the interaction lane into main
Show full message
🐛 fix(app,audio): merge the interaction lane into main

A card no longer swallows undo, redo, save or the clipboard, a refused
split keeps the clip in hand, every edit door arms the flag only when it
wrote, the cue picture cache is keyed by the cue, and a device that dies
under an open file says so and unsays it. Lane: lane-bughunt-inter.

The one hand resolution: `Player::undo` and `Player::redo` carry both
lanes' work in one body -- the interaction lane's bool ("was there a step
to take") and its conditional selection clear, plus the app lane's
write-back of the cached rate, the two proxy switches, the palette's pick
and the plate over the picture. All of that now hangs off
`Player::step_history`, whose own answer is the gate, and the selection
still only goes when a step was taken.
crates/app/src/keymap.rsmodified+6 -3
@@ -949,9 +949,12 @@ impl Keymap {
949949 // Seeking without a pointer, on the keys every player already
950950 // seeks with (gpui names them "left"/"right"/"home"/"end",
951951 // platform.rs:872-877). The colour card reads the same arrows
952- // for its sliders, but a card answers the stroke and returns
953- // before the keymap is consulted at all -- so these move the
954- // playhead only while no card is open.
952+ // for its sliders, and a card answers its own strokes before the
953+ // keymap is consulted -- the arrows among them -- so these move
954+ // the playhead only while no card is open. The document chords
955+ // are the exception and are not these: `Undo`, `Redo`, `Save`,
956+ // `Copy` and `Paste` reach the keymap whatever is up
957+ // (`ui::stance::card_safe_action`).
955958 b(ActionId::StepBack, "left", false),
956959 b(ActionId::StepForward, "right", false),
957960 b(ActionId::JumpBack, "left", true),
crates/app/src/main.rsmodified+20 -2
@@ -138,8 +138,11 @@ struct Player {
138138 /// The *lane* is half the key because the four PGS tracks of a remux are
139139 /// one film's subtitles in four languages: placed one over the other they
140140 /// start at the same microsecond, and a lane whose eye was shut would leave
141- /// the one before it on screen.
142- sub_image: Option<((Lane, i64), Arc<RenderImage>)>,
141+ /// the one before it on screen. The other half is the cue itself
142+ /// ([`crate::ui::preview::SubImageKey`]): two different cues can share a
143+ /// lane and a start too, and a key of those two alone served one caption's
144+ /// picture for another's.
145+ sub_image: Option<(crate::ui::preview::SubImageKey, Arc<RenderImage>)>,
143146 /// A frame that arrived before its time; shown on the tick it comes due.
144147 /// The pump's buffer, not transport state -- but a frame waiting here is
145148 /// what keeps a finished decoder from reading as [`Transport::Ended`] one
@@ -787,6 +790,17 @@ struct Player {
787790 /// The active session's identity, for the above: bumped by every door that
788791 /// swaps `session` or `preview_session`.
789792 session_gen: u64,
793+ /// The engine's own word on the sound device, as the last pump saw it: the
794+ /// cache [`Player::watch_audio`] compares each frame against so a reason is
795+ /// announced once when it *changes* and taken back when it clears. `None`
796+ /// while the sound is up, and seeded by `Player::seed_audio_watch` at every
797+ /// open, whose own line already carries the same fact.
798+ audio_reason: Option<String>,
799+ /// Which session generation (`session_gen`) the cached reason above describes:
800+ /// the watch is keyed to the session it is a statement about, so a preview
801+ /// opening or closing seeds the cache instead of announcing the *other*
802+ /// session's device.
803+ audio_watch_gen: u64,
790804 /// Which of the clip's two inks the look section's wheel and colour field
791805 /// act on ([`VizSlot`]): the clip's own colour, or the ring's dual half.
792806 /// The pick stays picked across clips, the way the dock tab's does.
@@ -1116,6 +1130,10 @@ fn main() {
11161130 picture_box: Rc::default(),
11171131 shot_pending: None,
11181132 session_gen: 0,
1133+ // Nothing heard yet: the first pump seeds it off the session
1134+ // it serves.
1135+ audio_reason: None,
1136+ audio_watch_gen: 0,
11191137 viz_slot: VizSlot::Main,
11201138 viz_hex_edit: None,
11211139 pending_viz: None,
crates/app/src/notices.rsmodified+96 -5
@@ -46,9 +46,98 @@ fn is_completion(message: &str) -> bool {
4646 /// decode: it plays perfectly, in silence, and that is the one thing the window
4747 /// would otherwise never say (the engine's own word for it, verbatim).
4848 pub(crate) fn audio_notice(session: &PlaybackSession) -> Option<String> {
49- session
50- .audio_disabled_reason()
51- .map(|reason| format!(" — NO AUDIO: {reason}"))
49+ session.audio_disabled_reason().map(audio_tail)
50+}
51+
52+/// [`audio_notice`]'s own tail, for a reason already read -- the one place the
53+/// engine's word is spelled into a line, so the open path and the mid-session
54+/// one cannot drift apart.
55+pub(crate) fn audio_tail(reason: &str) -> String {
56+ format!(" — NO AUDIO: {reason}")
57+}
58+
59+/// The same fact said on its own, for a device that dies *after* a file was
60+/// opened: [`audio_notice`] is a tail to append to "OPENED x", and a death
61+/// mid-session has no line to hang off -- so it leads with the state word the
62+/// strip reads first, and the tail is the same one.
63+pub(crate) fn audio_lost_line(reason: &str) -> String {
64+ format!("AUDIO LOST{}", audio_tail(reason))
65+}
66+
67+/// What a frame of the sound watch decides, as a pure value: the cache's own
68+/// session generation against the frame's says whether the two are even talking
69+/// about the same session, and only then what the reason did.
70+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
71+pub(crate) enum AudioStep {
72+ /// The cache describes the session *before* this one
73+ /// (`Player::session_swapped`): it is seeded and nothing is announced -- a
74+ /// preview that opens or closes is not a device that came back.
75+ Seed,
76+ /// The same session's reason arrived, or changed to a new one.
77+ Push,
78+ /// ...and the same session's reason is gone: the line it earned is retracted.
79+ Clear,
80+ /// The ordinary frame.
81+ Nothing,
82+}
83+
84+/// [`Player::watch_audio`]'s whole decision, pure: `cached_gen` is the session
85+/// generation the cache describes, `session_gen` the one the frame is serving, and
86+/// two reasons are what the engine says the sound is (`None` for sound that is
87+/// up).
88+///
89+/// The generation is what keeps another session's reason out of this session's
90+/// cache: `pump` serves the preview while one is up and the timeline otherwise,
91+/// so a flip reads a reason that was never about the cached session at all -- a
92+/// live device on one side and a dead one on the other is not a change, it is
93+/// two different questions.
94+pub(crate) fn audio_step(
95+ cached_gen: u64,
96+ session_gen: u64,
97+ was: Option<&str>,
98+ now: Option<&str>,
99+) -> AudioStep {
100+ if cached_gen != session_gen {
101+ return AudioStep::Seed;
102+ }
103+ match (was, now) {
104+ (Some(was), Some(now)) if was == now => AudioStep::Nothing,
105+ (_, Some(_)) => AudioStep::Push,
106+ (Some(_), None) => AudioStep::Clear,
107+ (None, None) => AudioStep::Nothing,
108+ }
109+}
110+
111+/// What a *change* in the engine's sound reason does to the notice queue, as a
112+/// pure step: the line pushed when a reason arrives, the same line taken back
113+/// when the reason clears. [`Player::watch_audio`] is the only caller and owns
114+/// the caching; this owns the queue, so a test can drive both directions without
115+/// a window and without a device that dies on cue.
116+///
117+/// The reason is the engine's to write, and the engine's writer is the wave
118+/// branch's: `tick`'s dead branch sets the lost-device reason and `rearm_audio`
119+/// clears it (its own test observes both). This side is the reader and never
120+/// spells the engine's words, so the end-to-end flip is asserted on the merged
121+/// tree while this lane drives the same step through the seam below -- on this
122+/// lane's base engine no path flips the reason at all.
123+pub(crate) fn audio_change_notice(
124+ notices: &mut std::collections::VecDeque<SharedString>,
125+ was: Option<&str>,
126+ now: Option<&str>,
127+) {
128+ match (was, now) {
129+ (_, Some(reason)) if was != Some(reason) => {
130+ push_notice(notices, audio_lost_line(reason).into());
131+ }
132+ // The sound is back: the line goes with it, or the strip keeps saying NO
133+ // AUDIO over a film that plays. Only that line -- whatever else is
134+ // queued is none of this step's business.
135+ (Some(was), None) => {
136+ let line = audio_lost_line(was);
137+ notices.retain(|notice| notice.as_ref() != line.as_str());
138+ }
139+ _ => {}
140+ }
52141 }
53142
54143 /// The strip's own width is finite and its message is one line: what a
@@ -121,12 +210,14 @@ mod tests {
121210 #[test]
122211 fn a_long_name_loses_its_middle_rather_than_the_state_word() {
123212 assert_eq!(ledger_line("SNAP OFF"), "SNAP OFF");
124- let long = ledger_line("OPENED he_is_not_the_only_one_at_all_here.mp4 · 1 subtitle track(s)");
213+ let long =
214+ ledger_line("OPENED he_is_not_the_only_one_at_all_here.mp4 · 1 subtitle track(s)");
125215 assert!(long.starts_with("OPENED "), "{long}");
126216 assert!(long.ends_with(" · 1 subtitle track(s)"), "{long}");
127217 assert!(long.contains('…'), "{long}");
128218 assert!(
129- long.split(' ').all(|w| w.chars().count() <= LEDGER_WORD_MAX),
219+ long.split(' ')
220+ .all(|w| w.chars().count() <= LEDGER_WORD_MAX),
130221 "{long}"
131222 );
132223 }
crates/app/src/player/actions.rsmodified+56 -14
@@ -36,6 +36,12 @@ impl Player {
3636 // costs nothing a real edit would not have earned anyway, and one list
3737 // here is the whole answer instead of fifteen scattered calls.
3838 //
39+ // The two exceptions are the history pair, whose doors answer "there was
40+ // a step to take" and are gated in their own arms below: `^z` with
41+ // nothing to undo is not a stroke that earned an autosave, and the
42+ // save-on-close question over a project nobody has touched is exactly
43+ // what the card doors' own gate exists to prevent.
44+ //
3945 // This list is the *action* doors only, and that is the class to mind
4046 // when adding an edit: a control that reaches the session from a
4147 // *click* -- the Clip tab's look chips and wheel, the settings rows,
@@ -54,8 +60,6 @@ impl Player {
5460 | ActionId::Group
5561 | ActionId::Delete
5662 | ActionId::Lift
57- | ActionId::Undo
58- | ActionId::Redo
5963 | ActionId::AddVideoLane
6064 | ActionId::RemoveVideoLane
6165 | ActionId::AddAudioLane
@@ -130,8 +134,16 @@ impl Player {
130134 ActionId::ZoomIn => self.zoom(ZOOM_STEP, None, cx),
131135 ActionId::ZoomOut => self.zoom(1. / ZOOM_STEP, None, cx),
132136 ActionId::ZoomFit => self.zoom_fit(cx),
133- ActionId::Undo => self.undo(cx),
134- ActionId::Redo => self.redo(cx),
137+ ActionId::Undo => {
138+ if self.undo(cx) {
139+ self.mark_dirty();
140+ }
141+ }
142+ ActionId::Redo => {
143+ if self.redo(cx) {
144+ self.mark_dirty();
145+ }
146+ }
135147 ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx),
136148 ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx),
137149 // The last track of that kind: the one the add key put there, so the
@@ -611,12 +623,17 @@ impl Player {
611623 return;
612624 };
613625 let to = nudge_edge(current, dir, lo, hi);
614- self.mark_dirty();
615626 let trimmed = self
616627 .session
617628 .as_mut()
618629 .is_some_and(|s| s.trim_clip(lane, idx, edge, to));
619630 if trimmed {
631+ // The arm rides the door's own answer: `trim_clip` is `false` for an
632+ // edge already where it was asked to go -- the `[`/`]` pressed
633+ // against the wall the edge is already on -- so the flag, the
634+ // autosave sidecar and the save-on-close question stay off a
635+ // project nobody has changed.
636+ self.mark_dirty();
620637 self.reset_after_reseek();
621638 // Loop-trim follows the edge it is trimming: the whole point of
622639 // the mode is hearing the cut as it moves.
@@ -643,12 +660,15 @@ impl Player {
643660 return;
644661 };
645662 let to = frame_at(session.now(), self.fps);
646- self.mark_dirty();
647663 let trimmed = self
648664 .session
649665 .as_mut()
650666 .is_some_and(|s| s.trim_clip(lane, idx, edge, to));
651667 if trimmed {
668+ // The door's own answer again: an edge the playhead is already on is
669+ // `false`, no undo step, and nothing for the unsaved ghost to be
670+ // about.
671+ self.mark_dirty();
652672 self.reset_after_reseek();
653673 // Loop-trim follows the edge it is trimming, same as the nudge
654674 // pair above.
@@ -684,16 +704,33 @@ impl Player {
684704 cx.notify();
685705 }
686706
687- pub(crate) fn undo(&mut self, cx: &mut Context<Self>) {
688- self.step_history(PlaybackSession::undo);
689- self.selected.clear();
707+ /// Whether there was a step to take, for the reason the action table arms
708+ /// nothing on its own: a `^z` with an empty history is not an edit, and it
709+ /// may not raise the save-on-close question over a project nobody has
710+ /// touched. The selection goes with the step for the same reason it used to
711+ /// go every time: a step back puts the indices on different clips, while a
712+ /// refused one leaves them naming exactly what they named.
713+ ///
714+ /// The step itself goes through [`Player::step_history`], which is what
715+ /// takes the window's own copy of the rate, the two proxy switches, the
716+ /// palette's pick and the plate over the picture back up with it.
717+ pub(crate) fn undo(&mut self, cx: &mut Context<Self>) -> bool {
718+ let stepped = self.step_history(PlaybackSession::undo);
719+ if stepped {
720+ self.selected.clear();
721+ }
690722 cx.notify();
723+ stepped
691724 }
692725
693- pub(crate) fn redo(&mut self, cx: &mut Context<Self>) {
694- self.step_history(PlaybackSession::redo);
695- self.selected.clear();
726+ /// [`Player::undo`]'s twin, the same answer and the same gate.
727+ pub(crate) fn redo(&mut self, cx: &mut Context<Self>) -> bool {
728+ let stepped = self.step_history(PlaybackSession::redo);
729+ if stepped {
730+ self.selected.clear();
731+ }
696732 cx.notify();
733+ stepped
697734 }
698735
699736 /// One step of the session's own history through the door both `^z` and
@@ -705,7 +742,11 @@ impl Player {
705742 /// the frame owed to the screen is cleared
706743 /// ([`Player::reset_after_reseek`]): an undo reseeks inside the engine, and
707744 /// a picture left where it was is the frame before the step.
708- fn step_history(&mut self, step: fn(&mut PlaybackSession) -> bool) {
745+ ///
746+ /// `false` where there was nothing to step: no session at all, or a history
747+ /// step that refused ([`PlaybackSession::undo`]'s own answer), in which case
748+ /// nothing in the window moves either.
749+ fn step_history(&mut self, step: fn(&mut PlaybackSession) -> bool) -> bool {
709750 let mut caches = SessionCaches {
710751 fps: self.fps,
711752 proxies_on: self.proxies_on,
@@ -720,7 +761,7 @@ impl Player {
720761 .as_mut()
721762 .and_then(|session| history_step(&before, &mut caches, session, step))
722763 else {
723- return;
764+ return false;
724765 };
725766 self.fps = caches.fps;
726767 self.proxies_on = caches.proxies_on;
@@ -732,6 +773,7 @@ impl Player {
732773 self.sub_image = None;
733774 }
734775 self.reset_after_reseek();
776+ true
735777 }
736778 }
737779
crates/app/src/player/library.rsmodified+5 -0
@@ -716,6 +716,11 @@ impl Player {
716716 cx.notify();
717717 }
718718 }
719+ // The picture swaps back to the timeline's, so everything keyed to a
720+ // session hears it (`Player::session_swapped`) -- the sound watch among
721+ // them, or the timeline's own unchanged reason would read as a device
722+ // that came back the moment the preview closed.
723+ self.session_swapped();
719724 self.preview_playing = false;
720725 }
721726
crates/app/src/player/timeline_edit.rsmodified+125 -55
@@ -50,12 +50,21 @@ impl Player {
5050 // not that.
5151 let cut = session.cut_at(f64::from(at) / self.fps);
5252 if cut {
53+ // Only a split that happened drops the selection: a refusal is
54+ // "NOTHING TO SPLIT", and the clip in hand is still the clip the
55+ // next Delete, `x` or menu acts on -- clearing it there left the
56+ // user with nothing picked and told them nothing about it. A
57+ // real split is the other way round: the cut it leaves makes the
58+ // picked index name a different clip, so the mark has to go.
59+ // [`Player::regroup`] below has always cleared inside its own
60+ // success branch; this is the same rule on the other half of the
61+ // pair.
62+ self.selected.clear();
5363 self.notify_user("SPLIT".into());
5464 } else {
5565 self.notify_user("NOTHING TO SPLIT — the playhead is already on a cut".into());
5666 }
5767 }
58- self.selected.clear();
5968 cx.notify();
6069 }
6170
@@ -72,10 +81,7 @@ impl Player {
7281 if session.regroup_at(session.now()) {
7382 self.selected.clear();
7483 } else {
75- self.notify_user(
76- "NOTHING TO REGROUP — no cut under the playhead"
77- .into(),
78- );
84+ self.notify_user("NOTHING TO REGROUP — no cut under the playhead".into());
7985 }
8086 }
8187 cx.notify();
@@ -97,9 +103,7 @@ impl Player {
97103 );
98104 }
99105 }
100- (Some(_), None) => {
101- self.notify_user("NOTHING DETACHED — nothing selected".into())
102- }
106+ (Some(_), None) => self.notify_user("NOTHING DETACHED — nothing selected".into()),
103107 (None, _) => {}
104108 }
105109 cx.notify();
@@ -126,9 +130,7 @@ impl Player {
126130 // index (a stroke nobody saw) is not a thing to group.
127131 let picks = self.marks().0;
128132 match (&mut self.session, self.selected.anchor(), picks.len()) {
129- (_, None, _) => {
130- self.notify_user("NOTHING GROUPED — nothing selected".into())
131- }
133+ (_, None, _) => self.notify_user("NOTHING GROUPED — nothing selected".into()),
132134 // The hand's group: every pick, one id.
133135 (Some(session), _, 2..) => {
134136 if let Err(e) = session.group_all(&picks) {
@@ -146,10 +148,9 @@ impl Player {
146148 self.notify_user(format!("NOT GROUPED — {e}").into());
147149 }
148150 }
149- None => self.notify_user(
150- "NOTHING TO GROUP WITH — no clip covers these frames"
151- .into(),
152- ),
151+ None => {
152+ self.notify_user("NOTHING TO GROUP WITH — no clip covers these frames".into())
153+ }
153154 },
154155 (None, ..) => {}
155156 }
@@ -237,9 +238,7 @@ impl Player {
237238 self.notify_user("NOTHING LIFTED — that half is no longer there".into());
238239 }
239240 }
240- (Some(_), None) => {
241- self.notify_user("NOTHING LIFTED — nothing selected".into())
242- }
241+ (Some(_), None) => self.notify_user("NOTHING LIFTED — nothing selected".into()),
243242 (None, _) => {}
244243 }
245244 cx.notify();
@@ -351,7 +350,6 @@ impl Player {
351350 if self.exporting().is_some() {
352351 return;
353352 }
354- self.mark_dirty();
355353 let (Some((start, _)), Some(was)) = (
356354 self.drop_frame(from, idx, x),
357355 self.session
@@ -386,6 +384,14 @@ impl Player {
386384 };
387385 match moved {
388386 true => {
387+ // The arm rides the door's own answer: `move_clip_to` /
388+ // `move_selection_to` answer `false` for a clip let go where it
389+ // was picked up (`Project::move_selection` refuses before its
390+ // snapshot) and for a lane of the wrong kind, and the arms below
391+ // say both in words. Armed before the call it dirtied a project
392+ // nobody had touched -- the ledger's `unsaved` ghost and the
393+ // save-on-close question over an unchanged file.
394+ self.mark_dirty();
389395 // Every pick named a `(lane, ...)` by index into that lane's
390396 // clips, sorted by start -- exactly what an insert or a lane
391397 // change reorders. Re-read by the frame each pick's clip now
@@ -409,11 +415,7 @@ impl Player {
409415 // Everything else that could refuse (a clip that is not there)
410416 // cannot be dragged.
411417 false if from.kind != to.kind => self.notify_user(
412- format!(
413- "NOT ON {} — a {kind} clip takes a {lanes} lane",
414- to.label()
415- )
416- .into(),
418+ format!("NOT ON {} — a {kind} clip takes a {lanes} lane", to.label()).into(),
417419 ),
418420 // Picked up and put back down where it was: a click, and a click
419421 // says nothing.
@@ -517,7 +519,6 @@ impl Player {
517519 if self.exporting().is_some() {
518520 return;
519521 }
520- self.mark_dirty();
521522 self.snap_cue = None;
522523 self.ghost.clear();
523524 let at = self.place_frame(x).0;
@@ -535,12 +536,18 @@ impl Player {
535536 },
536537 // The row is greyed and says why in the list; here it says why at
537538 // the moment somebody tried to use it anyway.
538- (None, Some(_)) => Some(
539- "NOT PLACED — that subtitle track has no cues"
540- .to_string(),
541- ),
539+ (None, Some(_)) => Some("NOT PLACED — that subtitle track has no cues".to_string()),
542540 (_, None) => Some("NOT PLACED — no file open".to_string()),
543541 };
542+ // The arm rides the door's own answer: `text` is `None` exactly when
543+ // `Project::place_sub` took the track, and every refusal -- an overlap,
544+ // a lane that is not a subtitle lane, "no file open", "no cues" --
545+ // leaves the project byte-for-byte what it was. Armed ahead of the
546+ // answer it wrote an autosave sidecar, the ledger's `unsaved` ghost and
547+ // the save-on-close question over a project nobody had changed.
548+ if text.is_none() {
549+ self.mark_dirty();
550+ }
544551 match (text, marked) {
545552 (Some(text), _) => self.notify_user(text.into()),
546553 // It went down, and a lane holds its captions in start order
@@ -605,12 +612,19 @@ impl Player {
605612 if self.exporting().is_some() {
606613 return;
607614 }
608- self.mark_dirty();
609615 self.snap_cue = None;
610616 self.ghost.clear();
611617 let Some(idx) = self.dragged_sub(drag) else {
612618 return;
613619 };
620+ // Where the caption stands *now*, so the arm below can tell a move from
621+ // a drag let go where it began: `Project::move_sub` answers `Ok` for a
622+ // pick-up-put-back too ("`Ok`, and no undo step, because nothing
623+ // changed"), so its own answer is not a change report.
624+ let was = self
625+ .session
626+ .as_ref()
627+ .and_then(|session| session.sub_lane(drag.lane).get(idx).map(|sub| sub.start));
614628 // Asked before the edit, on the indices the press captured: the
615629 // engine's own grouped-with-clips answer, which is exactly when its
616630 // move reseeks -- a caption grouped only with other captions moves no
@@ -648,6 +662,20 @@ impl Player {
648662 .as_ref()
649663 .and_then(|session| sub_mark(session.sub_lane(to), start))
650664 .map(|i| (to, i));
665+ // The arm rides the caption's own place having moved -- the
666+ // engine's `Ok` covers the put-back that takes no undo step at
667+ // all (`Project::move_sub`), and a project nobody has touched
668+ // must not light the `unsaved` ghost.
669+ let landed = mark.and_then(|(lane, i)| {
670+ self.session
671+ .as_ref()?
672+ .sub_lane(lane)
673+ .get(i)
674+ .map(|sub| (lane, sub.start))
675+ });
676+ if landed != was.map(|start| (drag.lane, start)) {
677+ self.mark_dirty();
678+ }
651679 self.selected = match mark {
652680 Some(mark) => {
653681 let mut sel = Selection::new();
@@ -678,7 +706,6 @@ impl Player {
678706 if self.exporting().is_some() {
679707 return;
680708 }
681- self.mark_dirty();
682709 let lifted = self
683710 .session
684711 .as_mut()
@@ -691,6 +718,11 @@ impl Player {
691718 false => "NOTHING LIFTED — that caption is not there any more".to_string(),
692719 };
693720 if lifted {
721+ // The arm rides the door's own answer: `false` is "NOTHING LIFTED —
722+ // that caption is not there any more", and the project is exactly
723+ // what it was, so the flag, the autosave sidecar and the
724+ // save-on-close question must stay off it.
725+ self.mark_dirty();
694726 // Everything after it on that lane slid down one ([`Vec::remove`]),
695727 // so a mark or an open menu left at or past it names a *different*
696728 // caption now -- and the next Delete would take that one. Both go
@@ -1293,12 +1325,7 @@ impl Player {
12931325 /// a project can gain, and the one remove that applies to this lane's kind
12941326 /// ([`oracle::lane_items`]). Nothing is selected -- a head owns no clip --
12951327 /// which is [`Player::open_gap_menu`]'s rule on the other empty target.
1296- pub(crate) fn open_head_menu(
1297- &mut self,
1298- lane: Lane,
1299- at: Point<Pixels>,
1300- cx: &mut Context<Self>,
1301- ) {
1328+ pub(crate) fn open_head_menu(&mut self, lane: Lane, at: Point<Pixels>, cx: &mut Context<Self>) {
13021329 if self.modal() || self.session.is_none() {
13031330 return;
13041331 }
@@ -1550,7 +1577,11 @@ impl Player {
15501577 let Some(trim) = self.trim.take() else {
15511578 return;
15521579 };
1553- self.mark_dirty();
1580+ // The arm rides each door's own answer or the caption's own edges --
1581+ // never the call: a trim released where the edge already stood is
1582+ // `Ok`/`true` with no undo step, and it must not leave the project
1583+ // looking edited to autosave, the `unsaved` ghost or the close
1584+ // question.
15541585 // A caption's edge reaches the engine through its own door, at this
15551586 // timeline's rate. An `Ok` is *not* "something changed" -- an edge that
15561587 // stopped at a wall it already stood against is `Ok` with no undo step
@@ -1565,14 +1596,33 @@ impl Player {
15651596 .session
15661597 .as_ref()
15671598 .is_some_and(|session| session.caption_grouped_with_clips(trim.lane, trim.idx));
1599+ // The caption's own window, before and after: the only reading that
1600+ // can tell a trim from an edge released against the wall it already
1601+ // stood on.
1602+ let edges = |player: &Self| {
1603+ player.session.as_ref().and_then(|session| {
1604+ session
1605+ .sub_lane(trim.lane)
1606+ .get(trim.idx)
1607+ .map(|sub| (sub.start, sub.frames, sub.in_us, sub.out_us))
1608+ })
1609+ };
1610+ let before = edges(self);
15681611 let trimmed = self
15691612 .session
15701613 .as_mut()
15711614 .map(|session| session.trim_sub(trim.lane, trim.idx, trim.edge, trim.to));
15721615 match trimmed {
15731616 Some(Err(e)) => self.notify_user(format!("NOT TRIMMED — {e}").into()),
1574- Some(Ok(())) if grouped => self.reset_after_reseek(),
1575- _ => {}
1617+ Some(Ok(())) => {
1618+ if edges(self) != before {
1619+ self.mark_dirty();
1620+ }
1621+ if grouped {
1622+ self.reset_after_reseek();
1623+ }
1624+ }
1625+ None => {}
15761626 }
15771627 cx.notify();
15781628 return;
@@ -1582,6 +1632,10 @@ impl Player {
15821632 .as_mut()
15831633 .is_some_and(|session| session.trim_clip(trim.lane, trim.idx, trim.edge, trim.to));
15841634 if trimmed {
1635+ // The arm rides the door's own answer: `trim_clip` is `false` for an
1636+ // edge already where it was asked to go, which is no undo step and
1637+ // no edit.
1638+ self.mark_dirty();
15851639 self.reset_after_reseek();
15861640 }
15871641 cx.notify();
@@ -1656,7 +1710,20 @@ impl Player {
16561710 let Some(fade) = self.fade_drag.take() else {
16571711 return;
16581712 };
1659- self.mark_dirty();
1713+ // The ramp the clip is carrying *now*, so the arm below can tell a drag
1714+ // from a press-and-release that left the handle where it was: `set_fade_in`
1715+ // / `set_fade_out` answer `true` for any index that exists and take an
1716+ // undo step either way, so their own answer is not a change report.
1717+ let was = match fade.is_in {
1718+ true => self
1719+ .session
1720+ .as_ref()
1721+ .map(|session| session.fade_in_of(fade.lane, fade.idx)),
1722+ false => self
1723+ .session
1724+ .as_ref()
1725+ .map(|session| session.fade_out_of(fade.lane, fade.idx)),
1726+ };
16601727 let set = self
16611728 .session
16621729 .as_mut()
@@ -1665,6 +1732,19 @@ impl Player {
16651732 false => session.set_fade_out(fade.lane, fade.idx, fade.to),
16661733 });
16671734 if set {
1735+ let now = match fade.is_in {
1736+ true => self
1737+ .session
1738+ .as_ref()
1739+ .map(|session| session.fade_in_of(fade.lane, fade.idx)),
1740+ false => self
1741+ .session
1742+ .as_ref()
1743+ .map(|session| session.fade_out_of(fade.lane, fade.idx)),
1744+ };
1745+ if now != was {
1746+ self.mark_dirty();
1747+ }
16681748 cx.notify();
16691749 }
16701750 }
@@ -1698,19 +1778,14 @@ impl Player {
16981778 [a, b] if a.0 == b.0 && a.1.abs_diff(b.1) == 1 => Some((a.0, a.1.min(b.1))),
16991779 _ => self.selected.anchor(),
17001780 }) else {
1701- self.notify_user(
1702- "NOTHING TO CROSSFADE — no audio clip selected".into(),
1703- );
1781+ self.notify_user("NOTHING TO CROSSFADE — no audio clip selected".into());
17041782 cx.notify();
17051783 return;
17061784 };
17071785 let frames = self.fps.round().max(1.) as u32;
17081786 if let Some(session) = &mut self.session {
17091787 if !session.crossfade(lane, idx, frames) {
1710- self.notify_user(
1711- "NOTHING TO CROSSFADE — no neighbour end to end"
1712- .into(),
1713- );
1788+ self.notify_user("NOTHING TO CROSSFADE — no neighbour end to end".into());
17141789 }
17151790 }
17161791 cx.notify();
@@ -1730,9 +1805,7 @@ impl Player {
17301805 [a, b] if a.0 == b.0 && a.1.abs_diff(b.1) == 1 => Some((a.0, a.1.min(b.1))),
17311806 _ => self.selected.anchor(),
17321807 }) else {
1733- self.notify_user(
1734- "NOTHING TO DISSOLVE — no video clip selected".into(),
1735- );
1808+ self.notify_user("NOTHING TO DISSOLVE — no video clip selected".into());
17361809 cx.notify();
17371810 return;
17381811 };
@@ -1747,10 +1820,7 @@ impl Player {
17471820 self.fps.round().max(1.) as u32
17481821 };
17491822 if !session.set_transition_out(lane, idx, frames) {
1750- self.notify_user(
1751- "NOTHING TO DISSOLVE — no neighbour end to end"
1752- .into(),
1753- );
1823+ self.notify_user("NOTHING TO DISSOLVE — no neighbour end to end".into());
17541824 } else if removing {
17551825 self.notify_user("DISSOLVE REMOVED — the clips cut again".into());
17561826 }
crates/app/src/player/transport.rsmodified+61 -0
@@ -25,12 +25,73 @@ impl Player {
2525 .map_or(self.fps, |s| s.meta().frame_rate)
2626 }
2727
28+ /// The engine's own word on the sound device, for the session the pump
29+ /// serves ([`Player::active_session`]).
30+ fn sound_reason(&self) -> Option<&str> {
31+ self.active_session()
32+ .and_then(PlaybackSession::audio_disabled_reason)
33+ }
34+
35+ /// The engine's word on the sound device, watched rather than asked once.
36+ /// A file that *opens* silent says so in its own open line
37+ /// ([`audio_notice`], `library.rs`); what used to reach no consumer at all is
38+ /// a reason that changes *under* a session that is already up. This is the
39+ /// reader of that state: the writer is the engine's (the wave branch's
40+ /// `tick` dead branch sets the lost-device reason, `rearm_audio` clears it),
41+ /// and this lane spells none of its words.
42+ ///
43+ /// Called from [`Player::pump`] because that is the one place every frame
44+ /// passes through, and written to cost an ordinary frame nothing: one read of
45+ /// an `Option<&str>` and one compare, with the strings built only on the step
46+ /// the pure [`audio_step`] names.
47+ ///
48+ /// Keyed by session ([`Player::audio_watch_gen`] against `session_gen`):
49+ /// `pump` serves the preview while one is up and the timeline otherwise, so
50+ /// without the key a preview opening or closing would read the *other*
51+ /// session's reason and announce a device loss that never happened.
52+ pub(crate) fn watch_audio(&mut self) {
53+ let step = audio_step(
54+ self.audio_watch_gen,
55+ self.session_gen,
56+ self.audio_reason.as_deref(),
57+ self.sound_reason(),
58+ );
59+ if step == AudioStep::Nothing {
60+ return;
61+ }
62+ let was = self.audio_reason.take();
63+ self.audio_reason = self.sound_reason().map(str::to_owned);
64+ self.audio_watch_gen = self.session_gen;
65+ if step == AudioStep::Seed {
66+ // A session swap is not a change: the new session's own open line
67+ // carries its reason, so only a line left over from the session
68+ // before is taken back -- and only when this one's sound is up.
69+ if self.audio_reason.is_none() {
70+ if let Some(was) = was {
71+ let line = audio_lost_line(&was);
72+ self.notices
73+ .retain(|notice| notice.as_ref() != line.as_str());
74+ }
75+ }
76+ return;
77+ }
78+ audio_change_notice(
79+ &mut self.notices,
80+ was.as_deref(),
81+ self.audio_reason.as_deref(),
82+ );
83+ }
84+
2885 /// Catches the display up to the clock: everything already due is taken off
2986 /// the channel and only the last of them is shown, which *is* the
3087 /// drop-when-behind policy. A frame that is not due yet waits in `held`, and
3188 /// while the clock is paused *nothing* is due -- a repaint re-presents the
3289 /// frame already on screen, whatever asked for the repaint.
3390 pub(crate) fn pump(&mut self, window: &mut Window) {
91+ // Before the drain, on the one read that does not need the session
92+ // mutably: the sound can die at any point in a frame, and the notice it
93+ // earns is owed to the frame it died in.
94+ self.watch_audio();
3495 // Where the transport was before this drain, so the crossing into
3596 // `Ended` can be recognised as the one transition it is.
3697 let was = self.transport();
crates/app/src/tests/cards.rsmodified+82 -0
@@ -1628,6 +1628,88 @@ fn every_click_door_that_writes_the_project_arms_autosave() {
16281628 "{name} arms outside its gate, so a no-op pick would dirty the project"
16291629 );
16301630 }
1631+ // The drag-and-drop family on the timeline: the same class, and the same
1632+ // rule. Every one of these doors can answer "nothing happened" -- a clip let
1633+ // go where it was picked up, a caption dragged back to the frame it started
1634+ // on, a trim, a fade or a `[`/`]` nudge released against the wall the edge
1635+ // already stood on, a subtitle row dropped on an overlap ("NOT PLACED") or a
1636+ // caption that is not there any more ("NOTHING LIFTED") -- and each one used
1637+ // to arm the flag *before* the door was asked, so the ledger's `unsaved`
1638+ // ghost, the autosave sidecar and the save-on-close question described a
1639+ // project whose content was byte-for-byte what it was.
1640+ //
1641+ // Each arm now rides its own door's answer, or the one reading the door's
1642+ // answer cannot give: a caption's own window before and after the trim
1643+ // (`Project::trim_sub` answers `Ok` for an edge released at a wall it already
1644+ // stood against) and the ramp's own value before and after the fade
1645+ // (`set_fade_*` answer `true` for any index that exists).
1646+ for (name, gate) in [
1647+ ("move_clip", "match moved {"),
1648+ (
1649+ "place_sub",
1650+ "let text = match (self.sub_of_track(track), &mut self.session) {",
1651+ ),
1652+ ("move_sub", "Some(Ok(())) => {"),
1653+ ("lift_sub", "if lifted {"),
1654+ ("commit_trim", "if trim.lane.kind == LaneKind::Subtitle {"),
1655+ ("commit_fade", "if set {"),
1656+ ("nudge_cut", "let to = nudge_edge(current, dir, lo, hi);"),
1657+ (
1658+ "trim_cut_to_playhead",
1659+ "let to = frame_at(session.now(), self.fps);",
1660+ ),
1661+ ] {
1662+ let body = fn_body(name);
1663+ let (before, after) = body
1664+ .split_once(gate)
1665+ .unwrap_or_else(|| panic!("{name} lost the gate its arm rides"));
1666+ assert!(
1667+ after.contains("mark_dirty()"),
1668+ "{name} arms outside its gate, so a stroke that changed nothing \
1669+ would dirty the project"
1670+ );
1671+ assert!(
1672+ !before.contains("mark_dirty()"),
1673+ "{name} still arms ahead of its gate, so a refusal -- or a drag let \
1674+ go where it started -- leaves the project looking edited"
1675+ );
1676+ }
1677+ // The history pair is the one place the action table does not arm early:
1678+ // the door's own answer ("there was a step to take") is the gate, so `^z`
1679+ // with an empty history leaves the flag -- and the close question -- clear.
1680+ let act = fn_body("act");
1681+ for (gate, next) in [
1682+ ("if self.undo(cx) {", "ActionId::Redo =>"),
1683+ ("if self.redo(cx) {", "ActionId::AddVideoLane =>"),
1684+ ] {
1685+ let arm = act
1686+ .split_once(gate)
1687+ .unwrap_or_else(|| panic!("{gate} is gone from the action table"))
1688+ .1;
1689+ // Cut at the arm *after* this one: "everything from here on" is
1690+ // satisfied by the sibling's arm, so deleting Undo's own would ship
1691+ // green.
1692+ let arm = arm.split_once(next).map_or(arm, |(arm, _)| arm);
1693+ assert!(
1694+ arm.contains("mark_dirty()"),
1695+ "the arm behind `{gate}` arms nothing, so a real step back is \
1696+ invisible to autosave, the unsaved ghost and the close question"
1697+ );
1698+ }
1699+ // ...and the answer the arm reads is the door's own: the session's bool, not
1700+ // a bare call that would arm for an undo with nothing to undo.
1701+ for name in ["undo", "redo"] {
1702+ let body = fn_body(name);
1703+ assert!(
1704+ body.contains("PlaybackSession::") && body.contains("stepped"),
1705+ "Player::{name} no longer answers whether there was a step to take"
1706+ );
1707+ assert!(
1708+ !body.contains("mark_dirty"),
1709+ "Player::{name} arms its own flag, so the arm in `act` is a second \
1710+ one for the same step"
1711+ );
1712+ }
16311713 }
16321714
16331715 /// [`crate::ui::dock_stance::transition_of`]: the dock's duration row
crates/app/src/tests/editing.rsmodified+57 -0
@@ -613,6 +613,20 @@ fn the_playhead_actions_still_work_with_a_caption_marked() {
613613 let clips = session.lane_clips(Lane::V1).len();
614614 assert!(session.cut_at(2.0), "the playhead splits the clip under it");
615615 assert_eq!(session.lane_clips(Lane::V1).len(), clips + 1);
616+ // The refusal is a real state and not a defence against nothing: the
617+ // playhead is standing on the seam the split just left, which is exactly the
618+ // stroke `Player::cut` words as "NOTHING TO SPLIT — the playhead is already
619+ // on a cut".
620+ assert!(
621+ !session.cut_at(2.0),
622+ "a second split on the seam is refused, which is the state the door's \
623+ selection gate is about"
624+ );
625+ assert_eq!(
626+ session.lane_clips(Lane::V1).len(),
627+ clips + 1,
628+ "and adds none"
629+ );
616630 assert!(session.regroup_at(2.0), "and the seam rejoins");
617631 assert_eq!(session.lane_clips(Lane::V1).len(), clips);
618632 assert_eq!(session.sub_lane(lane).len(), 1, "the caption is untouched");
@@ -2914,6 +2928,49 @@ fn escape_closes_a_card_before_it_can_ever_reach_deselect() {
29142928 }
29152929 }
29162930
2931+/// A refused split is not an edit, so it may not drop the clip in hand: the
2932+/// refused stroke is worded ("NOTHING TO SPLIT — the playhead is already on a
2933+/// cut") and the pick is still what the next `x`, `delete` or clip-menu row acts
2934+/// on. The clear rides the door's own answer, the way [`Player::regroup`]'s
2935+/// always has -- a split that happened is the other way round: the seam it
2936+/// leaves renumbers the lane, so a pick kept across it names the wrong clip.
2937+///
2938+/// A scan and not a drive: `self.selected` lives on `Player`, which needs a gpui
2939+/// `Context` this binary has no harness for. The state itself is driven in
2940+/// `the_playhead_actions_still_work_with_a_caption_marked`, which holds the real
2941+/// `cut_at` refusal this gate is about.
2942+#[test]
2943+fn a_refused_split_keeps_the_clip_in_hand() {
2944+ let body = fn_body("cut");
2945+ let (before, after) = body
2946+ .split_once("if cut {")
2947+ .expect("the split door no longer gates anything on its own answer");
2948+ // The door's own branch, cut apart at its `else`: "runs after `if cut {`" is
2949+ // satisfied by the shape this fix replaced as well, because the clear sat
2950+ // below the whole if/else and so inside everything that followed the gate --
2951+ // a revert of the fix would have shipped green. What the arm has to be is
2952+ // inside the then-branch, and nothing that follows the branch may hold one.
2953+ let then = after
2954+ .split_once("} else {")
2955+ .expect("the split door no longer branches on what the cut answered")
2956+ .0;
2957+ // One arm's worth of clear, counted with `matches`: `split(..).count()`
2958+ // counts the pieces *between* matches, so a single occurrence reads as two
2959+ // there and the guard fails on the fix it is guarding.
2960+ let extra_clear = after.matches("self.selected.clear()").count() > 1;
2961+ assert!(
2962+ !before.contains("self.selected.clear()"),
2963+ "the split drops the selection before it knows the cut happened, so a \
2964+ refused split leaves the user with nothing picked and nothing told"
2965+ );
2966+ assert!(
2967+ then.contains("self.selected.clear()") && !extra_clear,
2968+ "the clear does not ride the split's own success branch: a split that \
2969+ happened leaves the mark naming a different clip across the seam, and a \
2970+ refused one must leave it naming the clip it named"
2971+ );
2972+}
2973+
29172974 /// The other half: with nothing on screen to claim the key, bare escape falls
29182975 /// all the way through to `Player::act`, whose `ActionId::Deselect` arm is
29192976 /// the one place `self.selected` is emptied by a bare stroke rather than by
crates/app/src/tests/media.rsmodified+120 -0
@@ -11,6 +11,126 @@ use crate::subs::{
1111 };
1212 use crate::ui::preview::{bgra_to_rgba, screenshot_path};
1313
14+/// The notice queue's own half of the sound watch, and the three words it is
15+/// spelled with -- reached by name because the app's own glob does not carry
16+/// them (`notices` is a private module re-exported for the window).
17+use crate::notices::{audio_change_notice, audio_lost_line, audio_tail};
18+
19+/// A reason that changes under a session that is already open says so, and stops
20+/// saying so when it clears. This side is the *reader*: the writer of a reason is
21+/// the engine's own `audio_disabled_reason`, and the app's two call sites were
22+/// the *open* paths -- so a reason that arrived mid-session reached no consumer
23+/// at all and the window played on in silence with nothing said. The engine's
24+/// writer is the wave branch's, so the flip is driven through the seam here and
25+/// asserted end to end on the merged tree; nothing below depends on when the
26+/// engine's `tick` sets it.
27+///
28+/// Driven through the queue step itself -- [`audio_change_notice`] is the whole
29+/// of what a reason change does to the strip -- because a test cannot make a
30+/// sound card fail on cue; the caching around it is the same comparison plus the
31+/// source guard below.
32+#[test]
33+fn a_device_that_dies_under_an_open_file_says_so_and_unsays_it() {
34+ let mut notices: std::collections::VecDeque<gpui::SharedString> =
35+ ["OPENED take.mp4".into()].into_iter().collect();
36+ let lost = audio_lost_line("AUDIO_LOST");
37+ // The file was fine, and then the sound is gone: the reason arrives between
38+ // two frames.
39+ audio_change_notice(&mut notices, None, Some("AUDIO_LOST"));
40+ assert_eq!(
41+ notices.back().map(|notice| &***notice),
42+ Some(lost.as_str()),
43+ "a reason that arrives mid-session is never pushed"
44+ );
45+ assert!(
46+ lost.starts_with("AUDIO LOST") && lost.ends_with(&audio_tail("AUDIO_LOST")),
47+ "the standing line lost its state word, or stopped sharing \
48+ `audio_notice`'s own tail"
49+ );
50+ // The same reason read again on the next frame is not news.
51+ audio_change_notice(&mut notices, Some("AUDIO_LOST"), Some("AUDIO_LOST"));
52+ assert_eq!(notices.len(), 2, "one death was announced twice");
53+ // The re-arm takes: the line goes with it, and nothing else does.
54+ audio_change_notice(&mut notices, Some("AUDIO_LOST"), None);
55+ assert_eq!(
56+ notices.iter().map(|notice| &***notice).collect::<Vec<_>>(),
57+ vec!["OPENED take.mp4"],
58+ "the NO AUDIO line is still on the strip over a film that plays"
59+ );
60+ // A second death later says so again.
61+ audio_change_notice(&mut notices, None, Some("AUDIO_LOST"));
62+ assert_eq!(notices.back().map(|notice| &***notice), Some(lost.as_str()));
63+ // The wiring: the pump is the one place every frame passes through, and a
64+ // watcher nothing calls is a message nobody reads.
65+ assert!(
66+ fn_body("pump").contains("self.watch_audio();"),
67+ "the pump stopped watching the engine's sound reason, so a device that \
68+ dies mid-session is silent again"
69+ );
70+ // ...and the watch keys its cache to the session it is a statement about:
71+ // the two generations are what the *step call* is asked, so a preview flip
72+ // cannot be answered as if it were the cached session's own change.
73+ let watch = fn_body("watch_audio");
74+ let args = watch
75+ .split_once("audio_step(")
76+ .expect(
77+ "the watch decides for itself instead of through the pure step the flip test drives",
78+ )
79+ .1;
80+ let args = args.split_once(')').map_or(args, |(args, _)| args);
81+ assert!(
82+ args.contains("self.audio_watch_gen") && args.contains("self.session_gen"),
83+ "the watch asks the step about something other than the session it serves, \
84+ so a preview opening or closing announces the other session's device"
85+ );
86+ assert!(
87+ fn_body("sound_reason").contains("self.active_session()"),
88+ "the watch reads a reason off a session the pump is not serving, so its \
89+ cache and the frame disagree the moment a preview is up"
90+ );
91+ // ...and every door that installs or drops a session says so, the preview's
92+ // two among them (the one the flip was missed on).
93+ for door in ["close_session", "open_preview", "close_preview"] {
94+ assert!(
95+ fn_body(door).contains("self.session_swapped();"),
96+ "{door} installs or drops a session without telling anything keyed to \
97+ one, so a flip reads as news"
98+ );
99+ }
100+}
101+
102+/// The flip logic itself, pure: a preview opening or closing is a *different*
103+/// session, so the reason it reports is not news about the cached one -- the
104+/// phantom device loss the verifier caught, and the reason the cache carries a
105+/// generation at all. A change on the session the cache describes is the one that
106+/// speaks.
107+#[test]
108+fn a_preview_flip_is_not_a_device_that_came_back() {
109+ use crate::notices::{audio_step, AudioStep};
110+ // A swap, every way round: seeded, never announced.
111+ assert_eq!(audio_step(7, 8, None, Some("AUDIO_LOST")), AudioStep::Seed);
112+ assert_eq!(audio_step(7, 8, Some("AUDIO_LOST"), None), AudioStep::Seed);
113+ assert_eq!(
114+ audio_step(7, 8, Some("AUDIO_LOST"), Some("AUDIO_LOST")),
115+ AudioStep::Seed,
116+ "a flip whose reason reads the same on both sides is still a flip"
117+ );
118+ // The same session, the reason arriving, changing, and going.
119+ assert_eq!(audio_step(7, 7, None, Some("AUDIO_LOST")), AudioStep::Push);
120+ assert_eq!(
121+ audio_step(7, 7, Some("AUDIO_LOST"), Some("device gone")),
122+ AudioStep::Push
123+ );
124+ assert_eq!(audio_step(7, 7, Some("AUDIO_LOST"), None), AudioStep::Clear);
125+ assert_eq!(
126+ audio_step(7, 7, Some("AUDIO_LOST"), Some("AUDIO_LOST")),
127+ AudioStep::Nothing,
128+ "the same reason read again on the next frame is not news"
129+ );
130+ assert_eq!(audio_step(7, 7, None, None), AudioStep::Nothing);
131+ assert_eq!(audio_step(0, 0, None, None), AudioStep::Nothing);
132+}
133+
14134 /// The toast tail an audio import earns: rate, channel count and rounded
15135 /// length, in the words the IMPORTED line appends them in
16136 /// ([`Player::take_import`], [`Player::install_media`]). A film gets none of
crates/app/src/tests/view.rsmodified+159 -0
@@ -3,6 +3,63 @@
33
44 use super::*;
55
6+/// The preview's one cached cue picture is keyed by the *cue* and not only by
7+/// where it happens to sit: a lane and a start microsecond are not an identity --
8+/// lift a bitmap caption off a lane, drop another track's caption at the same
9+/// frame, and a key of those two matched the cache, painting the picture of the
10+/// cue that is gone over the one that is up. The picture's own allocation is the
11+/// rest of the key, and an identical repeat still hits, which is the whole cache.
12+#[test]
13+fn a_cached_cue_picture_is_keyed_by_the_cue_not_only_its_moment() {
14+ use crate::ui::preview::sub_image_key;
15+ let (lane, other) = (Lane::S1, Lane::A1);
16+ // Two cues that share the lane and the start, and nothing else: one lifted,
17+ // one placed at the same frame.
18+ let a = sub_image_key(lane, 1_000_000, 3_000_000, 0x1000);
19+ let b = sub_image_key(lane, 1_000_000, 3_000_000, 0x2000);
20+ assert_ne!(
21+ a, b,
22+ "two different cues at one moment on one lane are one cache key again, so \
23+ the second paints the first's picture"
24+ );
25+ // The same cue repainted: still a hit.
26+ assert_eq!(
27+ a,
28+ sub_image_key(lane, 1_000_000, 3_000_000, 0x1000),
29+ "the cache misses on every repaint of the same cue, so it decodes an 8 MB \
30+ display set per frame"
31+ );
32+ // The same picture recut over the same start is a different cue.
33+ assert_ne!(
34+ a,
35+ sub_image_key(lane, 1_000_000, 2_500_000, 0x1000),
36+ "a cue's own end is no part of the key, so a recut cue serves the old window"
37+ );
38+ // And the other half of the old key still holds: the four PGS tracks of a
39+ // remux start at the same microsecond, so the lane separates them.
40+ assert_ne!(
41+ a,
42+ sub_image_key(other, 1_000_000, 3_000_000, 0x1000),
43+ "the lane is no longer part of the key, so a lane's eye shut leaves the \
44+ other lane's caption on screen"
45+ );
46+ // And the door builds its key this way, out of the cue's own picture: the
47+ // cache is only keyed by the cue while the lookup goes through this
48+ // constructor, and a test of the constructor alone would pass with the door
49+ // still keying on `(lane, start_us)`.
50+ let preview_rs = src_text("ui/preview.rs");
51+ assert!(
52+ preview_rs.contains(
53+ "let key = sub_image_key(lane, start_us, end_us, Arc::as_ptr(image) as usize);"
54+ ),
55+ "the cue picture is cached under a key that is not the cue's own"
56+ );
57+ assert!(
58+ preview_rs.contains("*up == key"),
59+ "the cache no longer compares the key it built"
60+ );
61+}
62+
663 /// What a drop reads: the frame under the pointer, through the same scale
764 /// the boxes are drawn through. Zoomed in, the same pixel is a different
865 /// frame -- which is the whole reason `Player::frame_under` goes through
@@ -976,3 +1033,105 @@ fn focus_panels_is_bound_and_lands_on_the_dock() {
9761033 // have stolen it.
9771034 assert_eq!(k.lookup("tab", false), Some(ActionId::Select));
9781035 }
1036+
1037+/// A card is not a key-eating black box: the room-wide chords that act on the
1038+/// document -- the edit history, the project file, the clipboard -- must reach
1039+/// `Player::act` while any card is open. `param_card_key` answers `true` for
1040+/// *every* stroke once one of the seven is up, so the dispatch has to stand in
1041+/// front of it, not only in front of the blanket modal guard under it; and the
1042+/// blanket guard's own `card_open()` has to read after that dispatch too, or a
1043+/// chord that got past `param_card_key` (a menu dismiss comes to mind) would
1044+/// still never reach the keymap.
1045+///
1046+/// A scan of the handler's own source, for the reason every handler scan here
1047+/// gives: this binary has no window harness to press `ctrl+z` through.
1048+#[test]
1049+fn an_open_card_does_not_swallow_the_document_chords() {
1050+ use crate::ui::stance::card_safe_action;
1051+ use keymap::ActionId;
1052+ // The five the room answers through a card, and the reason each is on the
1053+ // list: history, file, clipboard.
1054+ for action in [
1055+ ActionId::Undo,
1056+ ActionId::Redo,
1057+ ActionId::Save,
1058+ ActionId::Copy,
1059+ ActionId::Paste,
1060+ ] {
1061+ assert!(
1062+ card_safe_action(action),
1063+ "{action:?} is a document chord and a card must not eat it"
1064+ );
1065+ }
1066+ // ...and the strokes the cards' own branch list claims stay theirs:
1067+ // escape is every card's way out, `s` is the equalizer's spectrum, `x` its
1068+ // band removal, `m` every card's maximize, and the digits pick a band.
1069+ for action in [
1070+ ActionId::Deselect,
1071+ ActionId::Cut,
1072+ ActionId::Delete,
1073+ ActionId::ToggleMute,
1074+ ActionId::Equalizer,
1075+ ActionId::Color,
1076+ ActionId::Loop,
1077+ ActionId::TrimIn,
1078+ ] {
1079+ assert!(
1080+ !card_safe_action(action),
1081+ "{action:?} is a card's own stroke and the card must keep it"
1082+ );
1083+ }
1084+ // The chords are real bindings, not a list of actions nothing reaches.
1085+ let keys = keymap::Keymap::defaults();
1086+ for (key, ctrl, action) in [
1087+ ("z", true, ActionId::Undo),
1088+ ("y", true, ActionId::Redo),
1089+ ("s", true, ActionId::Save),
1090+ ("c", true, ActionId::Copy),
1091+ ("v", true, ActionId::Paste),
1092+ ] {
1093+ assert_eq!(
1094+ keys.lookup(key, ctrl),
1095+ Some(action),
1096+ "the keymap no longer binds {action:?}"
1097+ );
1098+ }
1099+ // And the dispatch stands where it has to: inside the root handler, ahead
1100+ // of the cards' own branches and ahead of the blanket modal guard.
1101+ let stance_rs = src_text("ui/stance.rs");
1102+ let dispatch = stance_rs.find("card_safe_action(action)").expect(
1103+ "the root key handler no longer asks which chords a card does not take -- an open card \
1104+ eats every stroke again",
1105+ );
1106+ assert!(
1107+ stance_rs[..dispatch].contains("this.keymap.lookup(key, ctrl)"),
1108+ "the dispatch no longer goes through the keymap, so a rebind would leave it behind"
1109+ );
1110+ // The *statement* that dispatches, not just some `keymap.lookup` before it:
1111+ // the hold gate at the top of the handler resolves the same pair, so a needle
1112+ // that only asks for the lookup is satisfied by a dispatch resolving the
1113+ // action some other way entirely.
1114+ let resolve = stance_rs
1115+ .find("if let Some(action) = this.keymap.lookup(key, ctrl)")
1116+ .expect("the dispatch no longer resolves an action through the keymap");
1117+ let stmt = &stance_rs[resolve..];
1118+ let stmt = &stmt[..stmt.find('{').expect("the dispatch statement has no block")];
1119+ assert!(
1120+ stmt.contains("card_safe_action("),
1121+ "the dispatch resolves an action and never asks whether a card may take \
1122+ it, so an open card eats the document chords again"
1123+ );
1124+ for (guard, label) in [
1125+ ("if this.param_card_key(", "the cards' own key branches"),
1126+ ("if this.card_open()", "the blanket modal guard"),
1127+ ] {
1128+ let at = stance_rs
1129+ .find(guard)
1130+ .unwrap_or_else(|| panic!("{label} moved or was renamed"));
1131+ assert!(
1132+ dispatch < at,
1133+ "{label} reads before the document dispatch -- an open card would \
1134+ swallow undo, redo, save and the clipboard pair again"
1135+ );
1136+ }
1137+}
crates/app/src/ui/preview.rsmodified+49 -8
@@ -5,6 +5,44 @@ use crate::ui::type_scale::{self, Typeset};
55 use crate::*;
66 use std::path::{Path, PathBuf};
77
8+/// What the preview's one cached cue picture is *of*: the lane, the moment,
9+/// the cue's own end, and the picture itself.
10+///
11+/// The lane and the start microsecond alone are not a cue. Two bitmap cues can
12+/// share both -- lift a caption off a lane and drop another track's caption at
13+/// the same frame -- and with those two as the whole key the cache's `up == key`
14+/// test matched, painting the picture of the cue that is gone over the one that
15+/// is up.
16+///
17+/// The picture's own allocation ([`Arc::as_ptr`]) is the identity: the cue list
18+/// a repaint is handed holds the same `Arc` for as long as that cue is in it, so
19+/// two repaints of one cue compare equal -- which is the whole cache hit -- while
20+/// two different cues never do. The bytes are never compared: a display set is
21+/// tens of kilobytes and this test runs on every frame.
22+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
23+pub(crate) struct SubImageKey {
24+ pub(crate) lane: Lane,
25+ pub(crate) start_us: i64,
26+ /// The cue's own end, so the same picture recut over the same start reads as
27+ /// a different cue here too.
28+ pub(crate) end_us: i64,
29+ /// Where that picture lives -- [`Arc::as_ptr`] of the cue's image.
30+ pub(crate) picture: usize,
31+}
32+
33+/// [`SubImageKey`] for one cue's picture: the one place the key is built, so the
34+/// lookup that trusts a hit and the test that pins what a hit means cannot drift
35+/// apart. `picture` is where the cue's image lives -- the caller passes
36+/// `Arc::as_ptr` of it, and nothing about the bytes is ever read here.
37+pub(crate) fn sub_image_key(lane: Lane, start_us: i64, end_us: i64, picture: usize) -> SubImageKey {
38+ SubImageKey {
39+ lane,
40+ start_us,
41+ end_us,
42+ picture,
43+ }
44+}
45+
846 impl Player {
947 /// The darkroom's own preview indicator (MOCK-SPEC.md): a plate
1048 /// (canvas-on-panel, §4), mono for what the film says, and a ghost
@@ -314,8 +352,10 @@ impl Player {
314352 // lane is all there is here.
315353 let picture = cues
316354 .iter()
317- .find_map(|cue| Some((cue.start_us, cue.image.as_ref()?)))
318- .and_then(|(start_us, image)| self.sub_picture(lane, start_us, image, window));
355+ .find_map(|cue| Some((cue.start_us, cue.end_us, cue.image.as_ref()?)))
356+ .and_then(|(start_us, end_us, image)| {
357+ self.sub_picture(lane, start_us, end_us, image, window)
358+ });
319359 // A picture is fitted onto the whole region and a plate hangs off the
320360 // bottom of it, and a track is one or the other -- so they are two
321361 // shapes and not one with the parts switched off.
@@ -386,10 +426,10 @@ impl Player {
386426 )
387427 }
388428
389- /// The cue `lane` starts at `start_us` as a drawable picture, decoded on the
390- /// first repaint it is up for and kept until another cue takes its place
391- /// ([`Player::sub_image`]). `None` for a display set the decoder refuses,
392- /// which draws nothing rather than failing the frame.
429+ /// The cue `lane` plays from `start_us` to `end_us` as a drawable picture,
430+ /// decoded on the first repaint it is up for and kept until another cue
431+ /// takes its place ([`Player::sub_image`]). `None` for a display set the
432+ /// decoder refuses, which draws nothing rather than failing the frame.
393433 ///
394434 /// Its atlas tile is released as the video's is: every [`RenderImage`] gets
395435 /// a fresh id and its own tile, so a film's worth of cues would grow the
@@ -398,10 +438,11 @@ impl Player {
398438 &mut self,
399439 lane: Lane,
400440 start_us: i64,
401- image: &engine::subtitle::CueImage,
441+ end_us: i64,
442+ image: &Arc<engine::subtitle::CueImage>,
402443 window: &mut Window,
403444 ) -> Option<Arc<RenderImage>> {
404- let key = (lane, start_us);
445+ let key = sub_image_key(lane, start_us, end_us, Arc::as_ptr(image) as usize);
405446 if let Some((up, ready)) = &self.sub_image
406447 && *up == key
407448 {
crates/app/src/ui/stance.rsmodified+74 -0
@@ -68,6 +68,55 @@ pub(crate) fn is_focus_exit_key(key: &str) -> bool {
6868 key == "escape"
6969 }
7070
71+/// The room-wide chords an open card does not take.
72+///
73+/// A card owns the keyboard for its own *values* -- the arrows on a slider, `r`
74+/// for reset, `m` for maximize, the digits on the equalizer, `enter` to apply
75+/// ([`Player::param_card_key`]'s branch list) -- and every one of those is a
76+/// *bare* stroke its own branch claims. These five are not: each acts on the
77+/// document rather than on the card the hand is looking at, and while a card is
78+/// open the room must still answer them. It is the equalizer card's own comment
79+/// that says so from the inside: "Nothing to undo: every change is already at
80+/// the clip, and undo is undo's own key".
81+///
82+/// - `Undo`/`Redo`: the edit history. The one chord a hand reaches for *while*
83+/// looking at what it just changed, which is exactly when a card is open.
84+/// - `Save`: the project file. Its chord is `ctrl+s`, and no card's branch
85+/// answers a ctrl chord on purpose (`param_card_key` is handed the shift
86+/// modifier alone).
87+/// - `Copy`/`Paste`: the clip clipboard, the pair beside the history keys.
88+///
89+/// Asked against the [`keymap::ActionId`] the stroke resolved to, never against
90+/// a key literal: a rebind moves the chord and this list follows it.
91+///
92+/// Deliberately *not* here, in three kinds:
93+///
94+/// 1. The strokes a card's own branch list claims, which the card must keep:
95+/// escape (every card's way out, and `Deselect`'s own stroke), the arrows
96+/// (`StepBack`/`StepForward`/`JumpBack`/`JumpForward` -- the branch reads
97+/// them with or without ctrl), `m` (`ToggleMute`) and the digits, plus the
98+/// bare letters the cards' verbs sit on -- `r` (`Loop`, `Resolution`), `f`
99+/// (`Mix`, `Crossfade`), `a` (`AddAudioLane`, `SelectAll`), `s`
100+/// (`Cut` -- the EQ card's spectrum), `x` (`Delete`, `Dissolve` -- the
101+/// band's removal), `k` (`Color`), `j`, `u`, `y` (`SubtitleStyle`), `enter`
102+/// (the silence card's apply).
103+/// 2. The chords that open a card: `Export`/`Settings`/`Color`/`Transform`/
104+/// `Speed`/`Silence`/`Mix`/`Equalizer`/`SubtitleStyle`. They own the very
105+/// modal slot the open card is sitting in, and swapping the surface under a
106+/// hand mid-stroke is not a chord this fix is for.
107+/// 3. Everything else the keymap binds (the odometer, the trims, the zoom, the
108+/// lane add/remove pair, the theme, the screenshot...). They are left to the
109+/// card on purpose, the way [`Player::param_card_key`] left them before this:
110+/// the defect is a card swallowing the *history* while the user edits through
111+/// it, and each of these is one press away again the moment the card closes.
112+pub(crate) fn card_safe_action(action: crate::keymap::ActionId) -> bool {
113+ use crate::keymap::ActionId;
114+ matches!(
115+ action,
116+ ActionId::Undo | ActionId::Redo | ActionId::Save | ActionId::Copy | ActionId::Paste
117+ )
118+}
119+
71120 /// The dock mounts only one of its two tabs at a time
72121 /// (`dock_stance::render`'s `match src_active`), so `focus_dock` only has a
73122 /// tree node under Sources and `focus_inspector` only under Clip -- focusing
@@ -1068,6 +1117,25 @@ pub(crate) fn render(
10681117 cx.notify();
10691118 return;
10701119 }
1120+ // A card is not a key-eating black box. The room-wide chords that
1121+ // act on the document rather than on the card -- the edit history,
1122+ // the project file, the clipboard ([`card_safe_action`]) -- run
1123+ // here, ahead of the cards' own key branches below and ahead of the
1124+ // blanket modal guard under them, so an open card cannot swallow
1125+ // the stroke a hand reaches for while looking at what it changed.
1126+ // `param_card_key` answers `true` for every stroke once a card is
1127+ // open, so this has to stand in front of *it*, not only in front of
1128+ // the guard: `ctrl+z` never reached `keymap.lookup` at all, and the
1129+ // card's own comment says undo was always meant to be undo's key.
1130+ //
1131+ // Asked through the keymap rather than as a table of key literals:
1132+ // a rebind moves the chord and this follows.
1133+ if let Some(action) = this.keymap.lookup(key, ctrl)
1134+ && card_safe_action(action)
1135+ {
1136+ this.act(action, window, cx);
1137+ return;
1138+ }
10711139 // The param cards' own key branches (arrows nudge the focused
10721140 // slider, digits pick an EQ band, `r` resets, card verbs) --
10731141 // `Player::param_card_key` (`player/cards.rs`), the same
@@ -1125,6 +1193,12 @@ pub(crate) fn render(
11251193 // clip_menu/row_menu/list chain follows (`render.rs`): this is
11261194 // the fix for "no state may make the room modal without
11271195 // showing anything", not only the source-dot's menu.
1196+ //
1197+ // Except the document chords, which were answered *above* and
1198+ // left the menu standing: a menu is a visible surface with
1199+ // escape and any other key still shutting it, and losing an
1200+ // undo to a square of the screen a right-click left open would
1201+ // be the black box this handler no longer is.
11281202 this.context_menu = None;
11291203 this.library_menu = None;
11301204 this.picker = None;