forge
Explore
Log in

Don't you dare go Hollow

Project settings live before the first import

Browse files at this commit

79d189bc5c53f9e617790fe4bfd18f5c822ed975Ahmet Kaan GümüşParent: 803b8e6dc9a2c2
  • feat
    • project settings live before the first import
Show full message
✨ feat(app): project settings live before the first import

Resolution and frame rate no longer wait for a first file to exist.
crates/app/src/export_ui.rsmodified+37 -0
@@ -484,6 +484,43 @@ pub(crate) fn resolution_choices(current: (u32, u32), native: (u32, u32)) -> Vec
484 .collect()484 .collect()
485 }485 }
486 486
487+/// The resolution list's rows before any file is open: [`RESOLUTIONS`] plain,
488+/// with nothing marked unless a pick is already held
489+/// ([`Player::pending_settings`]) -- there is no media size to cycle in
490+/// beside them yet ([`resolution_choices`]'s `native`).
491+pub(crate) fn pending_resolution_choices(pending: Option<(u32, u32)>) -> Vec<ChoiceRow> {
492+ RESOLUTIONS
493+ .into_iter()
494+ .map(|(w, h)| {
495+ (
496+ Choice::Size(w, h),
497+ format!("{h}p").into(),
498+ format!("{w}x{h}").into(),
499+ Some((w, h)) == pending,
500+ )
501+ })
502+ .collect()
503+}
504+
505+/// [`pending_resolution_choices`]'s sibling for the rate list.
506+pub(crate) fn pending_fps_choices(pending: Option<f64>) -> Vec<ChoiceRow> {
507+ FRAME_RATES
508+ .into_iter()
509+ .map(|fps| {
510+ (
511+ Choice::Fps(fps),
512+ format!("{} fps", fps_label(fps)).into(),
513+ match (fps - fps.round()).abs() < 0.001 {
514+ true => String::new(),
515+ false => "NTSC".to_string(),
516+ }
517+ .into(),
518+ Some(fps) == pending,
519+ )
520+ })
521+ .collect()
522+}
523+
487 /// Every project frame rate on offer, slowest first: [`FRAME_RATES`] with the524 /// Every project frame rate on offer, slowest first: [`FRAME_RATES`] with the
488 /// media's own cycled in at its place by speed, so a project already cut at a525 /// media's own cycled in at its place by speed, so a project already cut at a
489 /// listed rate does not see it twice and the media's own rate -- the one a526 /// listed rate does not see it twice and the media's own rate -- the one a
crates/app/src/main.rsmodified+10 -0
@@ -73,6 +73,15 @@ struct Player {
73 /// waits: the first media import or project load is what fills it, and73 /// waits: the first media import or project load is what fills it, and
74 /// until then every action that needs a timeline says so instead of acting.74 /// until then every action that needs a timeline says so instead of acting.
75 session: Option<PlaybackSession>,75 session: Option<PlaybackSession>,
76+ /// A resolution and/or frame rate picked before any file exists to derive
77+ /// them from -- what [`Player::cycle_resolution`] and its fps sibling edit
78+ /// instead of refusing, with nothing open yet. Applied as the explicit
79+ /// override [`engine::PlaybackSession::set_resolution`]/`set_frame_rate`
80+ /// already are for a `.edith`'s own saved values ([`Player::install_media`])
81+ /// the moment the first session exists, and cleared there: consumed once,
82+ /// the way a project's own saved settings are read once at
83+ /// [`engine::PlaybackSession::open_project`].
84+ pending_settings: (Option<(u32, u32)>, Option<f64>),
76 /// A library row's own file, opened and playing in place of the85 /// A library row's own file, opened and playing in place of the
77 /// timeline's picture, and never written to `session` or its undo stack:86 /// timeline's picture, and never written to `session` or its undo stack:
78 /// a preview is watched, not edited. `Some` is what [`Player::pump`] and87 /// a preview is watched, not edited. `Some` is what [`Player::pump`] and
@@ -680,6 +689,7 @@ fn main() {
680 seek_since: None,689 seek_since: None,
681 resynced: None,690 resynced: None,
682 session: None,691 session: None,
692+ pending_settings: (None, None),
683 preview_session: None,693 preview_session: None,
684 preview_playing: false,694 preview_playing: false,
685 // Full and unmuted, which is what the session it was just695 // Full and unmuted, which is what the session it was just
crates/app/src/player/cards.rsmodified+48 -15
@@ -14,8 +14,16 @@ impl Player {
14 return;14 return;
15 }15 }
16 let Some(session) = &mut self.session else {16 let Some(session) = &mut self.session else {
17- self.notify_user("no timeline to resize — open a file first".into());17+ // No media yet to derive a "native" size from: cycle the plain
18- cx.notify();18+ // list and hold the pick until the first file opens
19+ // ([`Player::install_media`]), the same way a size picked from
20+ // the list does ([`apply_resolution`](Self::apply_resolution)).
21+ let at = self
22+ .pending_settings
23+ .0
24+ .and_then(|c| RESOLUTIONS.iter().position(|&s| s == c));
25+ let (w, h) = RESOLUTIONS[at.map_or(0, |at| (at + 1) % RESOLUTIONS.len())];
26+ self.apply_resolution(w, h, cx);
19 return;27 return;
20 };28 };
21 let (width, height) = next_resolution(session.resolution(), session.native_resolution());29 let (width, height) = next_resolution(session.resolution(), session.native_resolution());
@@ -23,13 +31,21 @@ impl Player {
23 }31 }
24 32
25 /// The project resized, whichever asked: the stroke that steps to the next33 /// The project resized, whichever asked: the stroke that steps to the next
26- /// size and the list that names one outright come through here.34+ /// size and the list that names one outright come through here. With no
35+ /// timeline yet the size is held as [`Player::pending_settings`] instead of
36+ /// being written anywhere -- there is no session to write it onto -- and
37+ /// applied the moment the first one exists.
27 pub(crate) fn apply_resolution(&mut self, width: u32, height: u32, cx: &mut Context<Self>) {38 pub(crate) fn apply_resolution(&mut self, width: u32, height: u32, cx: &mut Context<Self>) {
28- if let Some(session) = &mut self.session39+ if let Some(session) = &mut self.session {
29- && session.set_resolution(width, height)40+ if session.set_resolution(width, height) {
30- {41+ self.notify_user(format!("PROJECT: {width}x{height}").into());
31- self.notify_user(format!("PROJECT: {width}x{height}").into());42+ self.reset_after_reseek();
32- self.reset_after_reseek();43+ }
44+ } else {
45+ self.pending_settings.0 = Some((width, height));
46+ self.notify_user(
47+ format!("PROJECT: {width}x{height} — takes effect on the next file opened").into(),
48+ );
33 }49 }
34 cx.notify();50 cx.notify();
35 }51 }
@@ -41,12 +57,21 @@ impl Player {
41 /// and the rate the app itself counts frames in follows, since every57 /// and the rate the app itself counts frames in follows, since every
42 /// timecode, ruler mark and step key here is measured in it.58 /// timecode, ruler mark and step key here is measured in it.
43 pub(crate) fn apply_frame_rate(&mut self, fps: f64, cx: &mut Context<Self>) {59 pub(crate) fn apply_frame_rate(&mut self, fps: f64, cx: &mut Context<Self>) {
44- if let Some(session) = &mut self.session60+ if let Some(session) = &mut self.session {
45- && session.set_frame_rate(fps)61+ if session.set_frame_rate(fps) {
46- {62+ self.fps = session.meta().frame_rate;
47- self.fps = session.meta().frame_rate;63+ self.notify_user(format!("PROJECT: {} fps", fps_label(fps)).into());
48- self.notify_user(format!("PROJECT: {} fps", fps_label(fps)).into());64+ self.reset_after_reseek();
49- self.reset_after_reseek();65+ }
66+ } else if fps.is_finite() && fps > 0.0 {
67+ // Held the same way a resolution picked before any file is
68+ // ([`apply_resolution`](Self::apply_resolution)): there is no
69+ // timeline yet to cut at it.
70+ self.pending_settings.1 = Some(fps);
71+ self.notify_user(
72+ format!("PROJECT: {} fps — takes effect on the next file opened", fps_label(fps))
73+ .into(),
74+ );
50 }75 }
51 cx.notify();76 cx.notify();
52 }77 }
@@ -143,7 +168,15 @@ impl Player {
143 .collect();168 .collect();
144 }169 }
145 let Some(session) = &self.session else {170 let Some(session) = &self.session else {
146- return Vec::new();171+ // Resolution and rate are reachable before any file is open --
172+ // they hold as `pending_settings` until one is ([`apply_resolution`],
173+ // [`apply_frame_rate`]) -- every other row still needs a session to
174+ // have anything to offer.
175+ return match of {
176+ Pick::Resolution => pending_resolution_choices(self.pending_settings.0),
177+ Pick::Fps => pending_fps_choices(self.pending_settings.1),
178+ _ => Vec::new(),
179+ };
147 };180 };
148 match of {181 match of {
149 Pick::Resolution => {182 Pick::Resolution => {
crates/app/src/player/library.rsmodified+17 -0
@@ -933,6 +933,19 @@ impl Player {
933 ) -> String {933 ) -> String {
934 match opened {934 match opened {
935 Ok((mut session, subs)) => {935 Ok((mut session, subs)) => {
936+ // A size and/or a rate picked before this file existed
937+ // ([`Player::apply_resolution`], [`Player::apply_frame_rate`])
938+ // are the project's from its very first frame -- the same
939+ // precedence a `.edith`'s own saved settings already have over
940+ // the scaffold ([`engine::PlaybackSession::open_project`]).
941+ // Consumed once: a later file replacing this session finds
942+ // nothing left pending.
943+ if let Some((w, h)) = self.pending_settings.0.take() {
944+ session.set_resolution(w, h);
945+ }
946+ if let Some(fps) = self.pending_settings.1.take() {
947+ session.set_frame_rate(fps);
948+ }
936 self.fps = session.meta().frame_rate;949 self.fps = session.meta().frame_rate;
937 // This window *is* the real-time viewer: a picture already past950 // This window *is* the real-time viewer: a picture already past
938 // the clock is one `pump` takes off the channel and throws away,951 // the clock is one `pump` takes off the channel and throws away,
@@ -1212,6 +1225,10 @@ impl Player {
1212 }1225 }
1213 let text = match opened {1226 let text = match opened {
1214 Ok(mut session) => {1227 Ok(mut session) => {
1228+ // A `.edith` carries its own saved size and rate, read at
1229+ // [`engine::PlaybackSession::open_project`] -- a pick made
1230+ // before this project loaded is not this project's.
1231+ self.pending_settings = (None, None);
1215 self.fps = session.meta().frame_rate;1232 self.fps = session.meta().frame_rate;
1216 // As at the file door above: the window watches in real time.1233 // As at the file door above: the window watches in real time.
1217 session.drop_late_pictures(true);1234 session.drop_late_pictures(true);
crates/app/src/tests/cards.rsmodified+27 -0
@@ -1250,6 +1250,33 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() {
1250 );1250 );
1251 }1251 }
1252 1252
1253+/// The two settings a resolution/rate pick reaches with no file open yet:
1254+/// the plain list, since there is no media size to cycle in beside it, with
1255+/// nothing marked until a pending pick exists and exactly that row marked
1256+/// once it does -- the same shape [`resolution_choices`]/[`fps_choices`]
1257+/// have once a session exists, minus the media's own rung.
1258+#[test]
1259+fn the_resolution_and_rate_lists_work_before_any_file_is_open() {
1260+ let none = pending_resolution_choices(None);
1261+ assert_eq!(none.len(), RESOLUTIONS.len());
1262+ assert!(none.iter().all(|(.., picked)| !picked), "nothing picked yet");
1263+ for ((choice, label, detail, _), size) in none.iter().zip(RESOLUTIONS) {
1264+ assert_eq!(*choice, Choice::Size(size.0, size.1));
1265+ assert_eq!(label.as_ref(), format!("{}p", size.1));
1266+ assert_eq!(detail.as_ref(), format!("{}x{}", size.0, size.1));
1267+ }
1268+ let picked = pending_resolution_choices(Some(RESOLUTIONS[2]));
1269+ assert_eq!(picked.iter().filter(|(.., picked)| *picked).count(), 1);
1270+ assert!(picked[2].3);
1271+
1272+ let none = pending_fps_choices(None);
1273+ assert_eq!(none.len(), FRAME_RATES.len());
1274+ assert!(none.iter().all(|(.., picked)| !picked));
1275+ let picked = pending_fps_choices(Some(FRAME_RATES[3]));
1276+ assert_eq!(picked.iter().filter(|(.., picked)| *picked).count(), 1);
1277+ assert!(picked[3].3);
1278+}
1279+
1253 #[test]1280 #[test]
1254 fn the_export_card_fits_the_smallest_window() {1281 fn the_export_card_fits_the_smallest_window() {
1255 // Same 640x360 floor the keybindings card is measured against: the1282 // Same 640x360 floor the keybindings card is measured against: the
crates/app/src/tests/mod.rsmodified+1 -1
@@ -49,7 +49,7 @@ use super::{
49 IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanKey, ScanPlan, SilenceScan, import_line,49 IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanKey, ScanPlan, SilenceScan, import_line,
50 Landing, arrival, launch_queue, full_scan_key, silence_cached, slice_whole_levels,50 Landing, arrival, launch_queue, full_scan_key, silence_cached, slice_whole_levels,
51 read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write,51 read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write,
52- repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,52+ repeats, resolution_choices, resolution_ladder, pending_resolution_choices, pending_fps_choices, span_label, tone_choices, tone_label,
53 clip_width, frames_of_us, trimmed_clip, trimmed_sub, trims, unscannable, unusable,53 clip_width, frames_of_us, trimmed_clip, trimmed_sub, trims, unscannable, unusable,
54 visible_slice,54 visible_slice,
55 };55 };
crates/app/src/ui/inspector.rsmodified+8 -4
@@ -282,7 +282,10 @@ impl Player {
282 ZOOM_SLOT_W,282 ZOOM_SLOT_W,
283 BG_RAISED(),283 BG_RAISED(),
284 None,284 None,
285- resolution.map_or_else(|| "Size".to_string(), |(_, h)| format!("{h}p")),285+ match resolution.or(self.pending_settings.0) {
286+ Some((_, h)) => format!("{h}p"),
287+ None => "Size".to_string(),
288+ },
286 "the canvas every clip is composed onto, and the size the export comes out at",289 "the canvas every clip is composed onto, and the size the export comes out at",
287 ActionId::Resolution,290 ActionId::Resolution,
288 cx.listener(|this, event: &ClickEvent, _, cx| {291 cx.listener(|this, event: &ClickEvent, _, cx| {
@@ -294,9 +297,10 @@ impl Player {
294 ZOOM_SLOT_W,297 ZOOM_SLOT_W,
295 BG_RAISED(),298 BG_RAISED(),
296 None,299 None,
297- match self.session.is_some() {300+ match (self.session.is_some(), self.pending_settings.1) {
298- true => format!("{} fps", fps_label(self.fps)),301+ (true, _) => format!("{} fps", fps_label(self.fps)),
299- false => "Rate".to_string(),302+ (false, Some(fps)) => format!("{} fps", fps_label(fps)),
303+ (false, None) => "Rate".to_string(),
300 },304 },
301 "the rate the whole timeline is cut and written at",305 "the rate the whole timeline is cut and written at",
302 ActionId::Resolution,306 ActionId::Resolution,
crates/engine/src/playback.rsmodified+42 -0
@@ -3778,6 +3778,48 @@ mod tests {
3778 assert!(audio_source_of(&[]).is_none(), "and no file at all");3778 assert!(audio_source_of(&[]).is_none(), "and no file at all");
3779 }3779 }
3780 3780
3781+ /// What a front end's "resolution/rate picked before any file is open"
3782+ /// setting costs the engine: nothing new. `open` then `set_resolution`/
3783+ /// `set_frame_rate` right after construction -- the app's technique for
3784+ /// applying a pre-import pick to the session it just made, mirroring
3785+ /// [`PlaybackSession::open_project`]'s own `doc.resolution`/`doc.fps`
3786+ /// override -- lands exactly where either setter lands it whenever it is
3787+ /// called, and a later `import` of another file leaves both untouched: an
3788+ /// import registers a source and its length, and never writes `meta.width`,
3789+ /// `meta.height` or `meta.frame_rate`.
3790+ #[test]
3791+ fn a_pre_import_setting_survives_construction_and_a_later_import() {
3792+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
3793+ let native = session.native_resolution();
3794+ let native_fps = session.native_frame_rate();
3795+ // The explicit picks a pre-import setting would apply, distinct from
3796+ // the fixture's own so a no-op would be caught.
3797+ let (picked_w, picked_h) = (1920, 1080);
3798+ assert_ne!((picked_w, picked_h), native, "the test needs a real change");
3799+ let picked_fps = 24.0;
3800+ assert_ne!(picked_fps, native_fps, "the test needs a real change");
3801+ assert!(session.set_resolution(picked_w, picked_h));
3802+ assert!(session.set_frame_rate(picked_fps));
3803+ assert_eq!(session.resolution(), (picked_w, picked_h));
3804+ assert_eq!(session.meta().frame_rate, picked_fps);
3805+
3806+ // A second file joining the timeline is exactly the case the front end
3807+ // worried a later import could silently override the explicit pick --
3808+ // it cannot, because `import` never touches the canvas.
3809+ session
3810+ .import(&asset("test_av2.mp4"))
3811+ .expect("av2 matches the timeline it was set to");
3812+ assert_eq!(
3813+ session.resolution(),
3814+ (picked_w, picked_h),
3815+ "an import must not move the project's own canvas size"
3816+ );
3817+ assert_eq!(
3818+ session.meta().frame_rate, picked_fps,
3819+ "an import must not move the project's own rate"
3820+ );
3821+ }
3822+
3781 /// The seam between the two lists a source index reaches: dropping a file3823 /// The seam between the two lists a source index reaches: dropping a file
3782 /// from the library shortens `sources`, and `counts` -- the frame length3824 /// from the library shortens `sources`, and `counts` -- the frame length
3783 /// per source, which is what a trim is walled by -- has to lose the same3825 /// per source, which is what a trim is walled by -- has to lose the same