The preview gets a pulse and export results get the front
Browse files at this commit- fix
- the preview gets a pulse and export results get the front
4 changed files +70 -5
- crates/app/src/notices.rs +19 -4
- crates/app/src/render.rs +1 -1
- crates/app/src/tests/layout.rs +26 -0
- crates/app/src/tests/media.rs +24 -0
crates/app/src/notices.rsmodified+19 -4
| @@ -19,9 +19,9 @@ pub(crate) const NOTICES_MAX: usize = 8; | |||
| 19 | pub(crate) const NOTICE_MIN_W: f32 = 180.; | 19 | pub(crate) const NOTICE_MIN_W: f32 = 180.; |
| 20 | 20 | ||
| 21 | /// The whole of the queue's policy, where it can be read at once and tested | 21 | /// The whole of the queue's policy, where it can be read at once and tested |
| 22 | -/// without a window: dedupe against the back, a ceiling, oldest out first. | 22 | +/// without a window: dedupe against the back, a ceiling, oldest out first -- |
| 23 | -/// [`Player::notify_user`] is the door every message comes through; this is what | 23 | +/// except an export's own outcome, which jumps to the front. [`Player::notify_user`] |
| 24 | -/// the door does. | 24 | +/// is the door every message comes through; this is what the door does. |
| 25 | pub(crate) fn push_notice(notices: &mut std::collections::VecDeque<SharedString>, message: SharedString) { | 25 | pub(crate) fn push_notice(notices: &mut std::collections::VecDeque<SharedString>, message: SharedString) { |
| 26 | // A repeat of what is already at the back is dropped -- holding a key that | 26 | // A repeat of what is already at the back is dropped -- holding a key that |
| 27 | // refuses would otherwise fill the queue with one sentence, and the count on | 27 | // refuses would otherwise fill the queue with one sentence, and the count on |
| @@ -32,7 +32,22 @@ pub(crate) fn push_notice(notices: &mut std::collections::VecDeque<SharedString> | |||
| 32 | if notices.len() >= NOTICES_MAX { | 32 | if notices.len() >= NOTICES_MAX { |
| 33 | notices.pop_front(); | 33 | notices.pop_front(); |
| 34 | } | 34 | } |
| 35 | - notices.push_back(message); | 35 | + // Minutes of an export land here the moment it ends, and behind two or |
| 36 | + // three progress lines (a proxy, a caption) queued while it ran, its own | ||
| 37 | + // result would sit unseen several dismissals deep. It is the one thing a | ||
| 38 | + // person started the export to read, so it goes to the front -- the | ||
| 39 | + // notice showing now -- rather than the back of the line. | ||
| 40 | + match is_completion(&message) { | ||
| 41 | + true => notices.push_front(message), | ||
| 42 | + false => notices.push_back(message), | ||
| 43 | + } | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +/// An export's own outcome: the one class of notice that outranks whatever | ||
| 47 | +/// is already queued ([`push_notice`]). Named by the same prefixes | ||
| 48 | +/// [`crate::player::export`] writes them with. | ||
| 49 | +fn is_completion(message: &str) -> bool { | ||
| 50 | + message.starts_with(EXPORT_DONE) || message.starts_with("EXPORT FAILED") | ||
| 36 | } | 51 | } |
| 37 | 52 | ||
| 38 | /// The tail an open/load notice grows when the file has sound the engine cannot | 53 | /// The tail an open/load notice grows when the file has sound the engine cannot |
crates/app/src/render.rsmodified+1 -1
| @@ -8,7 +8,7 @@ impl Render for Player { | |||
| 8 | // A file that has just been opened sits on its first frame with the | 8 | // A file that has just been opened sits on its first frame with the |
| 9 | // clock stopped: opening is not playing, whichever way the file | 9 | // clock stopped: opening is not playing, whichever way the file |
| 10 | // arrived. The play binding and the transport button start it. | 10 | // arrived. The play binding and the transport button start it. |
| 11 | - if let Some(session) = &mut self.session { | 11 | + if let Some(session) = self.active_session_mut() { |
| 12 | session.tick(); | 12 | session.tick(); |
| 13 | } | 13 | } |
| 14 | self.pump(window); | 14 | self.pump(window); |
crates/app/src/tests/layout.rsmodified+26 -0
| @@ -153,6 +153,32 @@ fn a_second_message_queues_behind_the_first_instead_of_erasing_it() { | |||
| 153 | assert_ne!(front, q.front().cloned()); | 153 | assert_ne!(front, q.front().cloned()); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | +/// An export's own outcome is what a person started it to read, so it must | ||
| 157 | +/// never sit behind two progress lines queued while it ran: it jumps to the | ||
| 158 | +/// front and is the one showing the moment it arrives. | ||
| 159 | +#[test] | ||
| 160 | +fn an_export_outcome_jumps_the_queue() { | ||
| 161 | + let mut q = std::collections::VecDeque::new(); | ||
| 162 | + push_notice(&mut q, "PROXY READY for a.mp4 — Proxies on cuts on it".into()); | ||
| 163 | + push_notice(&mut q, "SUBTITLES b.srt — 1 track(s) in the palette".into()); | ||
| 164 | + push_notice(&mut q, format!("{EXPORT_DONE}out.mp4").into()); | ||
| 165 | + assert_eq!(q.len(), 3); | ||
| 166 | + assert_eq!( | ||
| 167 | + q.front().map(|n: &gpui::SharedString| n.as_ref()), | ||
| 168 | + Some(format!("{EXPORT_DONE}out.mp4")).as_deref(), | ||
| 169 | + "the export's result must be the notice showing, not third in line" | ||
| 170 | + ); | ||
| 171 | + | ||
| 172 | + // A failed export is the same class: the outcome, whichever it was. | ||
| 173 | + let mut q = std::collections::VecDeque::new(); | ||
| 174 | + push_notice(&mut q, "PROXY READY for a.mp4 — Proxies on cuts on it".into()); | ||
| 175 | + push_notice(&mut q, "EXPORT FAILED: disk full".into()); | ||
| 176 | + assert_eq!( | ||
| 177 | + q.front().map(|n: &gpui::SharedString| n.as_ref()), | ||
| 178 | + Some("EXPORT FAILED: disk full") | ||
| 179 | + ); | ||
| 180 | +} | ||
| 181 | + | ||
| 156 | /// The bar colours itself off the words the message already opens with, so | 182 | /// The bar colours itself off the words the message already opens with, so |
| 157 | /// the tone cannot disagree with the sentence it labels. | 183 | /// the tone cannot disagree with the sentence it labels. |
| 158 | #[test] | 184 | #[test] |
crates/app/src/tests/media.rsmodified+24 -0
| @@ -1279,6 +1279,30 @@ fn a_second_session_playing_never_moves_the_first() { | |||
| 1279 | ); | 1279 | ); |
| 1280 | } | 1280 | } |
| 1281 | 1281 | ||
| 1282 | +/// The frozen-preview regression: `render` used to call `tick` on | ||
| 1283 | +/// `self.session` unconditionally, so a preview session's clock -- the one | ||
| 1284 | +/// [`Player::pump`] actually reads while previewing -- was never advanced | ||
| 1285 | +/// and the picture sat on frame 0 forever. The fix routes `tick` through | ||
| 1286 | +/// [`Player::active_session_mut`], the same preview-first precedence | ||
| 1287 | +/// `pump`/`transport` already use. This proves `tick` is what a session | ||
| 1288 | +/// needs to keep its own clock honest, and that ticking one session leaves | ||
| 1289 | +/// an untouched sibling exactly where it was -- so routing it through | ||
| 1290 | +/// whichever session is active cannot disturb the other one. | ||
| 1291 | +#[test] | ||
| 1292 | +fn ticking_the_preview_session_never_moves_the_timeline() { | ||
| 1293 | + let mut timeline = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 1294 | + timeline.seek(0.5); | ||
| 1295 | + let before = timeline.now(); | ||
| 1296 | + | ||
| 1297 | + let mut preview = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 1298 | + preview.play(); | ||
| 1299 | + // Stands in for what `render` now does every frame while a preview is | ||
| 1300 | + // showing: only the active session -- the preview -- gets ticked. | ||
| 1301 | + preview.tick(); | ||
| 1302 | + | ||
| 1303 | + assert_eq!(timeline.now(), before, "ticking the preview moved the timeline's clock"); | ||
| 1304 | +} | ||
| 1305 | + | ||
| 1282 | /// [`bgra_to_rgba`] and [`save_screenshot`]'s own PNG write, round-tripped: a | 1306 | /// [`bgra_to_rgba`] and [`save_screenshot`]'s own PNG write, round-tripped: a |
| 1283 | /// synthetic 2x2 frame -- one pixel per corner, alpha and channel order all | 1307 | /// synthetic 2x2 frame -- one pixel per corner, alpha and channel order all |
| 1284 | /// distinct -- decodes back to the same pixels a viewer would see, in RGBA. | 1308 | /// distinct -- decodes back to the same pixels a viewer would see, in RGBA. |