From dc9a2c2312026326f1c54975ed5346fb22ce51c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 19 Aug 2026 21:02:01 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(app):=20resolution=20and=20rat?= =?UTF-8?q?e=20are=20choosable=20before=20any=20file=20opens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A pick made on an empty player waits in pending_settings and lands on the next session the moment it is built, the same way a saved project's own numbers do. The inspector rows and the Resolution keystroke work with nothing open; a .edith's saved settings still win over a stale pre-import pick. Engine test proves a later import never touches an explicit resolution or rate. --- crates/app/src/export_ui.rs | 37 +++++++++++++++++++ crates/app/src/main.rs | 10 +++++ crates/app/src/player/cards.rs | 63 ++++++++++++++++++++++++-------- crates/app/src/player/library.rs | 17 +++++++++ crates/app/src/tests/cards.rs | 27 ++++++++++++++ crates/app/src/tests/mod.rs | 2 +- crates/app/src/ui/inspector.rs | 12 ++++-- crates/engine/src/playback.rs | 42 +++++++++++++++++++++ 8 files changed, 190 insertions(+), 20 deletions(-) diff --git a/crates/app/src/export_ui.rs b/crates/app/src/export_ui.rs index bc8f03b..d2174a0 100644 --- a/crates/app/src/export_ui.rs +++ b/crates/app/src/export_ui.rs @@ -484,6 +484,43 @@ pub(crate) fn resolution_choices(current: (u32, u32), native: (u32, u32)) -> Vec .collect() } +/// The resolution list's rows before any file is open: [`RESOLUTIONS`] plain, +/// with nothing marked unless a pick is already held +/// ([`Player::pending_settings`]) -- there is no media size to cycle in +/// beside them yet ([`resolution_choices`]'s `native`). +pub(crate) fn pending_resolution_choices(pending: Option<(u32, u32)>) -> Vec { + RESOLUTIONS + .into_iter() + .map(|(w, h)| { + ( + Choice::Size(w, h), + format!("{h}p").into(), + format!("{w}x{h}").into(), + Some((w, h)) == pending, + ) + }) + .collect() +} + +/// [`pending_resolution_choices`]'s sibling for the rate list. +pub(crate) fn pending_fps_choices(pending: Option) -> Vec { + FRAME_RATES + .into_iter() + .map(|fps| { + ( + Choice::Fps(fps), + format!("{} fps", fps_label(fps)).into(), + match (fps - fps.round()).abs() < 0.001 { + true => String::new(), + false => "NTSC".to_string(), + } + .into(), + Some(fps) == pending, + ) + }) + .collect() +} + /// Every project frame rate on offer, slowest first: [`FRAME_RATES`] with the /// media's own cycled in at its place by speed, so a project already cut at a /// listed rate does not see it twice and the media's own rate -- the one a diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index c82d272..11a4f44 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -73,6 +73,15 @@ struct Player { /// waits: the first media import or project load is what fills it, and /// until then every action that needs a timeline says so instead of acting. session: Option, + /// A resolution and/or frame rate picked before any file exists to derive + /// them from -- what [`Player::cycle_resolution`] and its fps sibling edit + /// instead of refusing, with nothing open yet. Applied as the explicit + /// override [`engine::PlaybackSession::set_resolution`]/`set_frame_rate` + /// already are for a `.edith`'s own saved values ([`Player::install_media`]) + /// the moment the first session exists, and cleared there: consumed once, + /// the way a project's own saved settings are read once at + /// [`engine::PlaybackSession::open_project`]. + pending_settings: (Option<(u32, u32)>, Option), /// A library row's own file, opened and playing in place of the /// timeline's picture, and never written to `session` or its undo stack: /// a preview is watched, not edited. `Some` is what [`Player::pump`] and @@ -680,6 +689,7 @@ fn main() { seek_since: None, resynced: None, session: None, + pending_settings: (None, None), preview_session: None, preview_playing: false, // Full and unmuted, which is what the session it was just diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 8d858d1..018ed7f 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -14,8 +14,16 @@ impl Player { return; } let Some(session) = &mut self.session else { - self.notify_user("no timeline to resize — open a file first".into()); - cx.notify(); + // No media yet to derive a "native" size from: cycle the plain + // list and hold the pick until the first file opens + // ([`Player::install_media`]), the same way a size picked from + // the list does ([`apply_resolution`](Self::apply_resolution)). + let at = self + .pending_settings + .0 + .and_then(|c| RESOLUTIONS.iter().position(|&s| s == c)); + let (w, h) = RESOLUTIONS[at.map_or(0, |at| (at + 1) % RESOLUTIONS.len())]; + self.apply_resolution(w, h, cx); return; }; let (width, height) = next_resolution(session.resolution(), session.native_resolution()); @@ -23,13 +31,21 @@ impl Player { } /// The project resized, whichever asked: the stroke that steps to the next - /// size and the list that names one outright come through here. + /// size and the list that names one outright come through here. With no + /// timeline yet the size is held as [`Player::pending_settings`] instead of + /// being written anywhere -- there is no session to write it onto -- and + /// applied the moment the first one exists. pub(crate) fn apply_resolution(&mut self, width: u32, height: u32, cx: &mut Context) { - if let Some(session) = &mut self.session - && session.set_resolution(width, height) - { - self.notify_user(format!("PROJECT: {width}x{height}").into()); - self.reset_after_reseek(); + if let Some(session) = &mut self.session { + if session.set_resolution(width, height) { + self.notify_user(format!("PROJECT: {width}x{height}").into()); + self.reset_after_reseek(); + } + } else { + self.pending_settings.0 = Some((width, height)); + self.notify_user( + format!("PROJECT: {width}x{height} — takes effect on the next file opened").into(), + ); } cx.notify(); } @@ -41,12 +57,21 @@ impl Player { /// and the rate the app itself counts frames in follows, since every /// timecode, ruler mark and step key here is measured in it. pub(crate) fn apply_frame_rate(&mut self, fps: f64, cx: &mut Context) { - if let Some(session) = &mut self.session - && session.set_frame_rate(fps) - { - self.fps = session.meta().frame_rate; - self.notify_user(format!("PROJECT: {} fps", fps_label(fps)).into()); - self.reset_after_reseek(); + if let Some(session) = &mut self.session { + if session.set_frame_rate(fps) { + self.fps = session.meta().frame_rate; + self.notify_user(format!("PROJECT: {} fps", fps_label(fps)).into()); + self.reset_after_reseek(); + } + } else if fps.is_finite() && fps > 0.0 { + // Held the same way a resolution picked before any file is + // ([`apply_resolution`](Self::apply_resolution)): there is no + // timeline yet to cut at it. + self.pending_settings.1 = Some(fps); + self.notify_user( + format!("PROJECT: {} fps — takes effect on the next file opened", fps_label(fps)) + .into(), + ); } cx.notify(); } @@ -143,7 +168,15 @@ impl Player { .collect(); } let Some(session) = &self.session else { - return Vec::new(); + // Resolution and rate are reachable before any file is open -- + // they hold as `pending_settings` until one is ([`apply_resolution`], + // [`apply_frame_rate`]) -- every other row still needs a session to + // have anything to offer. + return match of { + Pick::Resolution => pending_resolution_choices(self.pending_settings.0), + Pick::Fps => pending_fps_choices(self.pending_settings.1), + _ => Vec::new(), + }; }; match of { Pick::Resolution => { diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 14a138a..66bde0e 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -933,6 +933,19 @@ impl Player { ) -> String { match opened { Ok((mut session, subs)) => { + // A size and/or a rate picked before this file existed + // ([`Player::apply_resolution`], [`Player::apply_frame_rate`]) + // are the project's from its very first frame -- the same + // precedence a `.edith`'s own saved settings already have over + // the scaffold ([`engine::PlaybackSession::open_project`]). + // Consumed once: a later file replacing this session finds + // nothing left pending. + if let Some((w, h)) = self.pending_settings.0.take() { + session.set_resolution(w, h); + } + if let Some(fps) = self.pending_settings.1.take() { + session.set_frame_rate(fps); + } self.fps = session.meta().frame_rate; // This window *is* the real-time viewer: a picture already past // the clock is one `pump` takes off the channel and throws away, @@ -1212,6 +1225,10 @@ impl Player { } let text = match opened { Ok(mut session) => { + // A `.edith` carries its own saved size and rate, read at + // [`engine::PlaybackSession::open_project`] -- a pick made + // before this project loaded is not this project's. + self.pending_settings = (None, None); self.fps = session.meta().frame_rate; // As at the file door above: the window watches in real time. session.drop_late_pictures(true); diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 5e5a197..ae6407c 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -1250,6 +1250,33 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() { ); } +/// The two settings a resolution/rate pick reaches with no file open yet: +/// the plain list, since there is no media size to cycle in beside it, with +/// nothing marked until a pending pick exists and exactly that row marked +/// once it does -- the same shape [`resolution_choices`]/[`fps_choices`] +/// have once a session exists, minus the media's own rung. +#[test] +fn the_resolution_and_rate_lists_work_before_any_file_is_open() { + let none = pending_resolution_choices(None); + assert_eq!(none.len(), RESOLUTIONS.len()); + assert!(none.iter().all(|(.., picked)| !picked), "nothing picked yet"); + for ((choice, label, detail, _), size) in none.iter().zip(RESOLUTIONS) { + assert_eq!(*choice, Choice::Size(size.0, size.1)); + assert_eq!(label.as_ref(), format!("{}p", size.1)); + assert_eq!(detail.as_ref(), format!("{}x{}", size.0, size.1)); + } + let picked = pending_resolution_choices(Some(RESOLUTIONS[2])); + assert_eq!(picked.iter().filter(|(.., picked)| *picked).count(), 1); + assert!(picked[2].3); + + let none = pending_fps_choices(None); + assert_eq!(none.len(), FRAME_RATES.len()); + assert!(none.iter().all(|(.., picked)| !picked)); + let picked = pending_fps_choices(Some(FRAME_RATES[3])); + assert_eq!(picked.iter().filter(|(.., picked)| *picked).count(), 1); + assert!(picked[3].3); +} + #[test] fn the_export_card_fits_the_smallest_window() { // Same 640x360 floor the keybindings card is measured against: the diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 53ee26c..b074cfb 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -49,7 +49,7 @@ use super::{ IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanKey, ScanPlan, SilenceScan, import_line, Landing, arrival, launch_queue, full_scan_key, silence_cached, slice_whole_levels, read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write, - repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label, + repeats, resolution_choices, resolution_ladder, pending_resolution_choices, pending_fps_choices, span_label, tone_choices, tone_label, clip_width, frames_of_us, trimmed_clip, trimmed_sub, trims, unscannable, unusable, visible_slice, }; diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index 2e88167..f088e44 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -282,7 +282,10 @@ impl Player { ZOOM_SLOT_W, BG_RAISED(), None, - resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")), + match resolution.or(self.pending_settings.0) { + Some((_, h)) => format!("{h}p"), + None => "Size".to_string(), + }, "the canvas every clip is composed onto, and the size the export comes out at", ActionId::Resolution, cx.listener(|this, event: &ClickEvent, _, cx| { @@ -294,9 +297,10 @@ impl Player { ZOOM_SLOT_W, BG_RAISED(), None, - match self.session.is_some() { - true => format!("{} fps", fps_label(self.fps)), - false => "Rate".to_string(), + match (self.session.is_some(), self.pending_settings.1) { + (true, _) => format!("{} fps", fps_label(self.fps)), + (false, Some(fps)) => format!("{} fps", fps_label(fps)), + (false, None) => "Rate".to_string(), }, "the rate the whole timeline is cut and written at", ActionId::Resolution, diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 7ad2531..cd17f6e 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -3778,6 +3778,48 @@ mod tests { assert!(audio_source_of(&[]).is_none(), "and no file at all"); } + /// What a front end's "resolution/rate picked before any file is open" + /// setting costs the engine: nothing new. `open` then `set_resolution`/ + /// `set_frame_rate` right after construction -- the app's technique for + /// applying a pre-import pick to the session it just made, mirroring + /// [`PlaybackSession::open_project`]'s own `doc.resolution`/`doc.fps` + /// override -- lands exactly where either setter lands it whenever it is + /// called, and a later `import` of another file leaves both untouched: an + /// import registers a source and its length, and never writes `meta.width`, + /// `meta.height` or `meta.frame_rate`. + #[test] + fn a_pre_import_setting_survives_construction_and_a_later_import() { + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); + let native = session.native_resolution(); + let native_fps = session.native_frame_rate(); + // The explicit picks a pre-import setting would apply, distinct from + // the fixture's own so a no-op would be caught. + let (picked_w, picked_h) = (1920, 1080); + assert_ne!((picked_w, picked_h), native, "the test needs a real change"); + let picked_fps = 24.0; + assert_ne!(picked_fps, native_fps, "the test needs a real change"); + assert!(session.set_resolution(picked_w, picked_h)); + assert!(session.set_frame_rate(picked_fps)); + assert_eq!(session.resolution(), (picked_w, picked_h)); + assert_eq!(session.meta().frame_rate, picked_fps); + + // A second file joining the timeline is exactly the case the front end + // worried a later import could silently override the explicit pick -- + // it cannot, because `import` never touches the canvas. + session + .import(&asset("test_av2.mp4")) + .expect("av2 matches the timeline it was set to"); + assert_eq!( + session.resolution(), + (picked_w, picked_h), + "an import must not move the project's own canvas size" + ); + assert_eq!( + session.meta().frame_rate, picked_fps, + "an import must not move the project's own rate" + ); + } + /// The seam between the two lists a source index reaches: dropping a file /// from the library shortens `sources`, and `counts` -- the frame length /// per source, which is what a trim is walled by -- has to lose the same