diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 96726e4..457c9e0 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -115,6 +115,11 @@ actions! { /// else -- the sound and every export stay the film's whichever way it /// is set. ToggleProxies, + /// Whether a film that wants a stand-in gets one made as it is imported + /// ([`engine::proxy::wanted`]): what is *encoded*, where the switch above + /// is what is decoded. With it off the switch above is also the ask -- it + /// starts the ones the project is missing. + ToggleAutoProxies, /// The window's own colours, which belong to the person looking at them and /// not to the project: a list of the palettes, opened here and from the /// toolbar's Theme button. It was a build feature once, which made it a @@ -179,6 +184,7 @@ impl ActionId { ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", ActionId::ToggleSubtitles => "Subtitles on / off over the picture", ActionId::ToggleProxies => "Proxies on / off for the picture", + ActionId::ToggleAutoProxies => "Make proxies on import: on / off", ActionId::Theme => "Theme: the window's colours…", ActionId::CancelExport => "Cancel export", ActionId::ShowActions => "All actions and their keys…", @@ -234,6 +240,7 @@ impl ActionId { ActionId::ToggleSnap => "toggle-snap", ActionId::ToggleSubtitles => "toggle-subtitles", ActionId::ToggleProxies => "toggle-proxies", + ActionId::ToggleAutoProxies => "toggle-auto-proxies", ActionId::Theme => "theme", ActionId::CancelExport => "cancel-export", ActionId::ShowActions => "show-actions", @@ -290,6 +297,10 @@ impl ActionId { // nothing that is saved and nothing that is exported: a stand-in // is what one watches while cutting, not what one delivers. | ActionId::ToggleProxies + // ...and whether those stand-ins are made without being asked: the + // other half of the same switch, filed beside it so a card reader + // meets the pair the panel shows as a pair. + | ActionId::ToggleAutoProxies // ...and what the whole window is painted in: it edits nothing at // all, it is what one is looking *with*. | ActionId::Theme => Category::View, @@ -827,6 +838,11 @@ impl Keymap { // thrown once for a whole session rather than one wanted under // a hand -- the theme takes ctrl+h for that reason. b(ActionId::ToggleProxies, "p", true), + // Making them takes the key next to it, ctrl+o: the pair is one + // subject and the two chords are under the same finger, and + // every letter of the word itself is spoken for ("a" adds an + // audio lane, ctrl+a removes one). + b(ActionId::ToggleAutoProxies, "o", true), // The theme takes ctrl+h -- the h of the word, since "t" is the // subtitles and ctrl+t takes one off -- and a ctrl chord because // it is a preference set once, not a stroke wanted under a hand @@ -1101,8 +1117,9 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 50); + assert_eq!(k.entries().len(), 51); assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies)); + assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies)); assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions)); assert_eq!(k.lookup("h", true), Some(ActionId::Theme)); assert_eq!(k.lookup("space", false), Some(ActionId::Play)); diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 9a76f90..b631dff 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -88,6 +88,7 @@ impl Player { ActionId::ToggleSnap => self.toggle_snap(cx), ActionId::ToggleSubtitles => self.toggle_subtitles(cx), ActionId::ToggleProxies => self.toggle_proxies(cx), + ActionId::ToggleAutoProxies => self.toggle_auto_proxies(cx), // The keyboard's door to the same list the toolbar button opens. // At the window's corner, since a stroke names no place -- and // [`menu_at`] keeps it on screen from there. diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index 2f25f37..191e214 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -117,7 +117,19 @@ impl Player { // walk above is -- the decision reads the same header -- and the encode // itself is the engine's own worker, so what comes back here is a // handle to poll and not a wait. - for path in unseen_paths(session.sources(), &self.proxies) { + // + // ...unless this project makes none by itself + // ([`engine::PlaybackSession::auto_proxies`]), and then the Proxies + // switch is the ask: turning it on brings the films that want a + // stand-in through here at the next repaint, which is the only door + // there is. Left unseen meanwhile, so nothing is missed by having been + // imported while the switch was off. + for path in proxies_to_start( + session.auto_proxies(), + session.proxies(), + session.sources(), + &self.proxies, + ) { // Two at a time, and the rest at the next repaint: a stand-in is a // whole film re-encoded, and a library of ten dropped at once would // otherwise start ten encodes fighting over the one hardware seat. diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 994dc2a..9355c9f 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -414,6 +414,29 @@ impl Player { cx.notify(); } + /// Makes the stand-ins as the films arrive, or makes none until they are + /// asked for. The other half of the switch above: this one decides what is + /// *encoded*, that one what is *watched*. + /// + /// With it off nothing is started by an import at all -- turning Proxies on + /// is what asks for the ones this project needs ([`Player::cache_media`]), + /// which is said here because a switch whose only effect is elsewhere is a + /// switch that reads as doing nothing. + pub(crate) fn toggle_auto_proxies(&mut self, cx: &mut Context) { + let Some(session) = &mut self.session else { + return; + }; + let on = !session.auto_proxies(); + session.set_auto_proxies(on); + let text = match on { + true => "AUTO PROXIES ON — a film that wants a stand-in gets one as it arrives", + false => "AUTO PROXIES OFF — no import makes one; Proxies on is what asks for them", + }; + eprintln!("{text}"); + self.notify_user(text.into()); + cx.notify(); + } + pub(crate) fn poll_import(&mut self, cx: &mut Context) { match &mut self.importing { Some(import) => { diff --git a/crates/app/src/subs.rs b/crates/app/src/subs.rs index ae9fd2d..5e0395d 100644 --- a/crates/app/src/subs.rs +++ b/crates/app/src/subs.rs @@ -579,6 +579,26 @@ pub(crate) fn unseen_paths(sources: &[Source], seen: &HashMap) -> out } +/// The films a repaint may start a stand-in for ([`engine::proxy`]): the unseen +/// ones while this project makes them by itself, and **none at all** while it +/// does not -- until the Proxies switch is thrown, which is the ask, since +/// nothing else offers to make one. +/// +/// A film left out here stays out of the map it was checked against, which is +/// what brings it back the moment either switch says yes: an import made while +/// both were off is not a film that missed its turn. +pub(crate) fn proxies_to_start( + auto: bool, + cut_on_them: bool, + sources: &[Source], + seen: &HashMap, +) -> Vec { + match auto || cut_on_them { + true => unseen_paths(sources, seen), + false => Vec::new(), + } +} + /// Which timeline frame the playhead is on, by the rule the engine's own edits /// use (playback.rs `secs_to_frame`): the frame that has started, with the /// epsilon that keeps a clock sitting exactly on a boundary from reading as the diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index 4213a7b..e387a18 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -1516,6 +1516,36 @@ fn a_source_is_only_ever_asked_for_its_peaks_once() { assert_eq!(unseen_paths(&sources, &streams).len(), 1); } +/// The auto switch, which is the whole of what an import asks: with it off no +/// film is handed to [`engine::proxy`] at all, and turning Proxies on is what +/// asks for the ones the project is missing -- there is no other door, so a +/// project that never wants a stand-in never spends a minute encoding one. +#[test] +fn a_project_that_makes_no_proxies_by_itself_starts_none_until_it_is_cut_on_them() { + let sources = [Source { + path: asset("test_av.mp4"), + audio_stream: 0, + }]; + let none: HashMap = HashMap::new(); + let one = vec![asset("test_av.mp4")]; + // Today's behaviour, both ways round: auto on starts them whether or not + // the picture is cut on them -- the cache is warmed for later. + assert_eq!(proxies_to_start(true, false, &sources, &none), one); + assert_eq!(proxies_to_start(true, true, &sources, &none), one); + // Auto off and not cut on them: nothing is started at all. + assert!( + proxies_to_start(false, false, &sources, &none).is_empty(), + "an import started a stand-in the project asked it not to" + ); + // ...and the switch is the ask: the film comes through the moment Proxies + // goes on, because it was left unseen rather than marked done. + assert_eq!(proxies_to_start(false, true, &sources, &none), one); + // One start per film either way: a film already in the map is one already + // asked about, sixty repaints a second notwithstanding. + let seen: HashMap = HashMap::from([(asset("test_av.mp4"), ())]); + assert!(proxies_to_start(true, true, &sources, &seen).is_empty()); +} + #[test] fn the_add_button_is_dead_unless_it_would_do_something() { let picked = (PathBuf::from("/m/0.mp4"), 0); diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 268a0aa..735b25b 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -34,7 +34,7 @@ use super::{ SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport, EXPORT_DONE, NOTICES_MAX, STATUS_ERROR, TIMELINE_FIXED_H, TIMELINE_SHARE, lanes_shown, px_below, rows_below, STATUS_SUCCESS, STATUS_WARNING, notice_tone, - push_notice, typed, unseen_paths, unseen_sources, + proxies_to_start, push_notice, typed, unseen_paths, unseen_sources, whole_take, window_title, }; diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index c25c9ea..b024a83 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -302,6 +302,25 @@ impl Player { ActionId::ToggleProxies, cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_proxies(cx)), )) + // Beside it, because the two are one subject: that one is + // what the picture is decoded from, this one is whether the + // stand-in is ever made. Two states and no cycle, the rule + // the switch beside it keeps. + .child(self.action_control( + "auto-proxies", + TONE_SLOT_W, + BG_RAISED(), + None, + match self.session.as_ref().map(PlaybackSession::auto_proxies) { + Some(true) => "Auto proxies on", + Some(false) => "Auto proxies off", + None => "Auto proxies", + }, + "makes a stand-in for every big film as it is imported; with it off, \ + turning Proxies on is what asks for them", + ActionId::ToggleAutoProxies, + cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_auto_proxies(cx)), + )) .child(self.action_control( "inspect-mix", 0., diff --git a/crates/engine/src/edith.rs b/crates/engine/src/edith.rs index e9505df..bc2771b 100644 --- a/crates/engine/src/edith.rs +++ b/crates/engine/src/edith.rs @@ -1,12 +1,13 @@ //! The project file: a line of text per thing, and nothing else. //! //! ```text -//! edith 12 +//! edith 13 //! playhead 90 //! resolution 1920 1080 //! fps 30.0 //! tonemap vivid //! proxy on +//! autoproxy off //! limiter -1.0 on //! source 0 test_av.mp4 //! source 1 /elsewhere/test_av2.mp4 @@ -52,6 +53,14 @@ //! film's own path, length and modification time, so the cache is the only //! answer and a project file cannot go stale about it. //! +//! The `autoproxy` line is whether a film this machine cuts slowly gets a +//! stand-in made for it the moment it is imported ([`crate::proxy::wanted`]), +//! spelled `on` or `off`. Left out when it is on, which is what every dialect +//! before v13 did and could not be told not to. With it off an import makes +//! nothing at all, and turning the `proxy` switch on is what asks for the +//! stand-ins this project is missing -- which is the only way to ask, so a +//! project that never wants them never spends a minute of encode on one. +//! //! The `limiter` line is the master limiter over the whole mix //! ([`crate::limiter`]): its ceiling in dBFS and whether it is in circuit, //! spelled `on` or `off`. Left out when it is the default, which is off. @@ -108,7 +117,10 @@ //! is the only way an empty lane could still be there on the way back. A lane //! number may not skip one of its kind. //! -//! **Version 11** was this without the `proxy` line: such a project is cut on +//! **Version 12** was this without the `autoproxy` line: such a project makes a +//! stand-in for every film that wants one the moment it arrives, which is all +//! any project could do. +//! **Version 11** was that without the `proxy` line: such a project is cut on //! its films themselves, which is all any project could do. //! **Version 10** was that without the `tonemap` line: such a project is shown //! in the reference rendition, which is the only one there was. @@ -133,7 +145,7 @@ //! what a v1 timeline meant, and an older file simply equalizes and grades //! nothing, and an older one plays everything at real time, and an older one //! mixes flat, and an older one shows no subtitles, and an older one is shown -//! in the reference rendition -- and saving any of them writes v11. An older +//! in the reference rendition -- and saving any of them writes v13. An older //! reader refuses a newer file by name. //! //! Text because an edit list is a few integers and a path, and a path is @@ -169,7 +181,8 @@ use crate::subtitle::SubtitleTrack; /// What [`save`] writes. Read support goes back to `edith 1`; see the module /// docs for what those dialects looked like. -const MAGIC: &[u8] = b"edith 12"; +const MAGIC: &[u8] = b"edith 13"; +const MAGIC_V12: &[u8] = b"edith 12"; const MAGIC_V11: &[u8] = b"edith 11"; const MAGIC_V10: &[u8] = b"edith 10"; const MAGIC_V9: &[u8] = b"edith 9"; @@ -230,6 +243,11 @@ pub struct Document { /// out, which both mean the films themselves -- the only thing those /// projects could do. pub proxy: bool, + /// Whether an import makes a stand-in for a film that wants one by itself + /// ([`crate::proxy`]). `true` for every dialect before v13 and for a v13 + /// file that leaves the line out, which both mean by itself -- the only + /// thing those projects did. + pub auto_proxy: bool, pub playhead: u32, } @@ -250,6 +268,7 @@ pub fn save( fps: Option, tone: crate::tonemap::Preset, proxy: bool, + auto_proxy: bool, limiter: Limiter, playhead: u32, ) -> crate::Result<()> { @@ -265,7 +284,7 @@ pub fn save( .and_then(|mut f| { f.write_all(&emit( &dir, sources, lanes, gains, subtitles, eq, color, resolution, fps, tone, proxy, - limiter, playhead, + auto_proxy, limiter, playhead, ))?; f.sync_all() }) @@ -309,6 +328,7 @@ fn emit( fps: Option, tone: crate::tonemap::Preset, proxy: bool, + auto_proxy: bool, limiter: Limiter, playhead: u32, ) -> Vec { @@ -333,6 +353,12 @@ fn emit( if proxy { out.extend_from_slice(b"proxy on\n"); } + // Beside it and by the same rule the other way up: making them by itself is + // what every project before this line did, so only a project told to stop + // has anything to say here. + if !auto_proxy { + out.extend_from_slice(b"autoproxy off\n"); + } // Written only when it is not the default, so a project nobody has limited // is the same bytes it was in v8 bar the version line. if limiter != Limiter::default() { @@ -462,8 +488,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { // The dialects that wrote a source line without its stream field. Reading // one is the whole of what "an old project still opens" means here. let streamless = v1 || first == MAGIC_V2; - // The one that says whether it is cut on stand-ins... - let v12 = first == MAGIC; + // The one that says whether the stand-ins are made by themselves... + let v13 = first == MAGIC; + // ...the ones that say whether it is cut on stand-ins... + let v12 = v13 || first == MAGIC_V12; // ...the ones that carry an HDR rendition... let v11 = v12 || first == MAGIC_V11; // ...the ones that carry subtitle tracks... @@ -513,6 +541,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { limiter: Limiter::default(), tone: crate::tonemap::Preset::default(), proxy: false, + // ...and nothing before v13 could be told *not* to make one: an import + // that wanted a stand-in got one, which is what leaving the line out + // still means. + auto_proxy: true, fps: None, playhead: 0, }; @@ -602,6 +634,25 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { } }; } + b"autoproxy" if v13 => { + if !doc.sources.is_empty() { + return Err( + format!("line {n}: autoproxy belongs once, before the sources").into(), + ); + } + let f = fields(rest, 1, "autoproxy", n)?; + doc.auto_proxy = match f[0] { + b"on" => true, + b"off" => false, + other => { + return Err(format!( + "line {n}: autoproxy is on or off, not {:?}", + String::from_utf8_lossy(other) + ) + .into()); + } + }; + } b"limiter" if v9 => { if !doc.sources.is_empty() { return Err( @@ -1122,6 +1173,7 @@ mod tests { None, crate::tonemap::Preset::default(), false, + true, Limiter::default(), playhead, ) @@ -1166,6 +1218,7 @@ mod tests { None, crate::tonemap::Preset::default(), false, + true, Limiter::default(), 0, ); @@ -1194,7 +1247,7 @@ mod tests { video 1 0 0 30 0 - - - fit 1000\n"; let old = parse(v9, &dir).expect("v9 still loads"); assert_eq!(old.subtitles, Vec::new()); - assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 12\n")); + assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 13\n")); // ...and the line itself is not a v9 line: a dialect may not be mixed. let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir) .unwrap_err() @@ -1230,6 +1283,7 @@ mod tests { None, crate::tonemap::Preset::default(), proxy, + true, Limiter::default(), 0, ) @@ -1261,7 +1315,7 @@ mod tests { assert_eq!(mixed, "line 3: unknown keyword \"proxy\""); // Anything but on or off is a corrupt line, by name. for line in ["proxy\n", "proxy yes\n", "proxy On\n"] { - let file = format!("edith 12\nsource 0 a.mp4\n{line}"); + let file = format!("edith 13\nsource 0 a.mp4\n{line}"); assert!( parse(file.as_bytes(), &dir).is_err(), "{line:?} is not a proxy line" @@ -1269,6 +1323,69 @@ mod tests { } } + /// The v13 line: whether an import makes a stand-in by itself. Written the + /// other way up from every other switch here -- on is the default and the + /// line left out -- because that is what every dialect before it did, and a + /// v12 file must come back doing it. + #[test] + fn the_auto_proxy_switch_round_trips_and_a_v12_file_makes_them_by_itself() { + let dir = PathBuf::from("/proj"); + let (_, sources, lanes) = doc(); + let bytes = |proxy, auto| { + super::emit( + &dir, + &sources, + &lanes, + &[], + &[], + &[], + &[], + (1280, 720), + None, + crate::tonemap::Preset::default(), + proxy, + auto, + Limiter::default(), + 0, + ) + }; + // The default is the line left out, and the two switches are two lines: + // a project cut on stand-ins it does not make writes both. + let on = bytes(false, true); + assert!( + !String::from_utf8_lossy(&on).contains("autoproxy"), + "on is the line left out: {}", + String::from_utf8_lossy(&on) + ); + assert!(parse(&on, &dir).expect("v13 parses").auto_proxy); + let off = bytes(true, false); + let text = String::from_utf8_lossy(&off).to_string(); + assert!(text.contains("proxy on\nautoproxy off\n"), "{text}"); + let back = parse(&off, &dir).expect("v13 parses"); + assert!(back.proxy, "the other switch came back too"); + assert!(!back.auto_proxy); + + // A v12 project made them by itself and could not be told otherwise. + let v12 = b"edith 12\nplayhead 0\nresolution 1280 720\nproxy on\nsource 0 a.mp4\n\ + video 1 0 0 30 0 - - - fit 1000\n"; + let old = parse(v12, &dir).expect("v12 still loads"); + assert!(old.auto_proxy, "a v12 project made its stand-ins by itself"); + assert!(old.proxy, "the rest of it came back too"); + // ...and the line is not a v12 line: a dialect may not be mixed. + let mixed = parse(b"edith 12\nsource 0 a.mp4\nautoproxy off\n", &dir) + .unwrap_err() + .to_string(); + assert_eq!(mixed, "line 3: unknown keyword \"autoproxy\""); + // Anything but on or off is a corrupt line, by name. + for line in ["autoproxy\n", "autoproxy no\n", "autoproxy Off\n"] { + let file = format!("edith 13\nsource 0 a.mp4\n{line}"); + assert!( + parse(file.as_bytes(), &dir).is_err(), + "{line:?} is not an autoproxy line" + ); + } + } + /// The v11 line: the HDR rendition, written by name, read back as the very /// preset -- and the dialect before it, which had no way to say one and /// meant the published conversion. @@ -1289,6 +1406,7 @@ mod tests { None, preset, false, + true, Limiter::default(), 0, ); @@ -1383,7 +1501,7 @@ mod tests { let bytes = flat(&dir, &sources, &lanes, 12); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 12\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ source 2 /elsewhere/b.mp4\n\ video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ audio 1 0 0 30 0 0 - - fit 1000\n", @@ -1420,7 +1538,7 @@ mod tests { let bytes = flat(&dir, &sources, &lanes, 7); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 12\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\ video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\ video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n", "an empty lane is a line of its own; everything else is its clips" @@ -1528,7 +1646,7 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 12\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ eq 16777215.0:-0.1:3.918315e-39:hs\n\ eq\n\ @@ -1632,7 +1750,7 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 12\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ color 0.1:1.2:0.9:-0.3\n\ color -1e-7:16777215.0:3.918315e-39:-0.0\n\ color 0.0:1.0:1.0:0.0\n\ @@ -1697,7 +1815,7 @@ mod tests { (1280, 720), old.playhead )), - "edith 12\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ eq 80.0:-3.0:0.707:ls\n\ video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n" ); @@ -1735,7 +1853,7 @@ mod tests { let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 12\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\ video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\ audio 1 0 0 30 0 - - - fit 2000\n", "the rate is the clip line's last field, in thousandths" @@ -1764,7 +1882,7 @@ mod tests { (1280, 720), old.playhead )), - "edith 12\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n" ); // A rate outside what the editor can set is a corrupt line, by name. @@ -1806,12 +1924,13 @@ mod tests { Some(23.976023976023978), crate::tonemap::Preset::default(), false, + true, limiter, 0, ); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 12\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\ + "edith 13\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\ limiter -1.5 on\nsource 0 a.mp4\n\ video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\ audio 2 0 0 30 0 - - - fit 1000\n\ @@ -1843,7 +1962,7 @@ mod tests { (1280, 720), old.playhead )), - "edith 12\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\ video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n" ); @@ -2007,7 +2126,7 @@ mod tests { assert!(old.eq.is_empty(), "nothing before v5 equalizes anything"); assert_eq!( String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)), - "edith 12\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ source 2 /elsewhere/b.mp4\n\ video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ audio 1 0 0 30 0 0 - - fit 1000\n" @@ -2060,7 +2179,7 @@ mod tests { let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); assert_eq!( String::from_utf8_lossy(&v5), - "edith 12\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ + "edith 13\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\ source 0 /elsewhere/b.mp4\n\ video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\ audio 1 0 0 30 0 0 - - fit 1000\n", @@ -2092,7 +2211,7 @@ mod tests { // Saved again it is the current version, which round-trips to the // same document. let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead); - assert!(v5.starts_with(b"edith 12\n")); + assert!(v5.starts_with(b"edith 13\n")); let again = parse(&v5, &dir).expect("v5 parses"); assert_eq!(again.lanes, back.lanes); // A dialect may not be mixed: lane lines under v1, `clip` under v2. @@ -2191,6 +2310,7 @@ mod tests { None, crate::tonemap::Preset::default(), false, + true, Limiter::default(), 0, ) @@ -2198,7 +2318,7 @@ mod tests { let bytes = std::fs::read(&path).expect("read back"); assert_eq!( String::from_utf8_lossy(&bytes), - "edith 12\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\ + "edith 13\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\ video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n" ); // Loading rejoins the *given* directory, so the file is reached by the @@ -2243,10 +2363,10 @@ mod tests { #[test] fn a_wrong_first_line_is_refused_by_name() { let dir = PathBuf::from("/proj"); - let err = parse(b"edith 13\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) + let err = parse(b"edith 14\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir) .unwrap_err() .to_string(); - assert_eq!(err, "line 1: unsupported version 13"); + assert_eq!(err, "line 1: unsupported version 14"); for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] { assert_eq!( parse(junk, &dir).unwrap_err().to_string(), diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 4b07b74..56af7e6 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -388,6 +388,12 @@ pub struct PlaybackSession { /// file open that already costs milliseconds, so a proxy made (or deleted) /// mid-session is picked up at the next seek and nothing can go stale. proxies: bool, + /// Whether a source that wants a stand-in gets one made for it as it + /// arrives ([`crate::proxy::wanted`]). On unless a project says otherwise, + /// which is what every project did before the switch existed. Saved with + /// the project like the one above it, and read by the front end: the engine + /// starts no encode of its own. + auto_proxies: bool, } /// What an edit dirtied -- which half of the pipeline has to be rebuilt for the @@ -505,6 +511,7 @@ impl PlaybackSession { drop_late: false, // A file just opened is a project nobody has picked stand-ins for. proxies: false, + auto_proxies: true, }) } @@ -620,6 +627,7 @@ impl PlaybackSession { drop_late: false, // A file just opened is a project nobody has picked stand-ins for. proxies: false, + auto_proxies: true, }) } @@ -699,6 +707,7 @@ impl PlaybackSession { drop_late: false, // A file just opened is a project nobody has picked stand-ins for. proxies: false, + auto_proxies: true, }) } @@ -996,6 +1005,9 @@ impl PlaybackSession { // What the file says, and `false` for every dialect before v12: // a project cut on the films themselves opens on them. proxies: doc.proxy, + // ...and what it says about making them, which is "yes" for every + // dialect before v13 and for one that leaves the line out. + auto_proxies: doc.auto_proxy, }; // The scaffolding above opened source 0 from its first frame and the // whole of its audio; this puts both onto the clip the playhead is @@ -1251,6 +1263,10 @@ impl PlaybackSession { // *Which* files have one is not saved: [`crate::proxy`] finds that // out from the film itself, so nothing here can go stale. self.proxies, + // ...and whether it makes them by itself, which is a different + // question from whether it cuts on them and the only one an import + // asks ([`Self::auto_proxies`]). + self.auto_proxies, self.project.limiter(), playhead, ) @@ -1998,6 +2014,19 @@ impl PlaybackSession { self.seek(now); } + /// Whether an imported film that wants a stand-in gets one made for it + /// there and then ([`Self::set_auto_proxies`]). + pub fn auto_proxies(&self) -> bool { + self.auto_proxies + } + + /// Make the stand-ins on import, or make none until asked. Nothing to + /// reseek: this decides what is *started*, never what is decoded -- a proxy + /// already in the cache is still cut on while [`Self::proxies`] is on. + pub fn set_auto_proxies(&mut self, on: bool) { + self.auto_proxies = on; + } + /// Which source `path` is, canonicalising only if it has to: a source's own /// path is canonical ([`Source::new`]), so a caller handing one back from /// [`sources`](Self::sources) -- which is every library row -- hits on the diff --git a/crates/engine/tests/export.rs b/crates/engine/tests/export.rs index b7f1ec4..676beca 100644 --- a/crates/engine/tests/export.rs +++ b/crates/engine/tests/export.rs @@ -985,7 +985,7 @@ fn a_proxy_is_picture_only_every_frame_a_starting_point_and_cached() { session.set_proxies(true); session.save_project(&project).expect("save"); let text = std::fs::read_to_string(&project).expect("read the project back"); - assert!(text.starts_with("edith 12\n"), "{text}"); + assert!(text.starts_with("edith 13\n"), "{text}"); assert!(text.contains("\nproxy on\n"), "{text}"); let reopened = PlaybackSession::open_project(&project).expect("load"); assert!(reopened.proxies(), "the switch came back on"); diff --git a/crates/engine/tests/saveload.rs b/crates/engine/tests/saveload.rs index fa70bb9..c008d74 100644 --- a/crates/engine/tests/saveload.rs +++ b/crates/engine/tests/saveload.rs @@ -97,6 +97,43 @@ fn a_picked_audio_stream_lands_saves_and_comes_back() { std::fs::remove_dir_all(&dir).expect("cleanup"); } +/// Both stand-in switches through the front door: what the picture is cut on +/// and whether an import makes one at all are two settings, saved and reopened +/// as the pair they are -- and a session that was never told keeps making them, +/// which is what every project did before there was a switch. +#[test] +fn both_proxy_switches_survive_a_save_and_a_reopen() { + let dir = scratch("proxyswitches"); + let media = copy_in(&dir, "test_av.mp4"); + let mut session = PlaybackSession::open(&media).expect("open the fixture"); + session.set_gain(0.0); + assert!(session.auto_proxies(), "a fresh project makes them by itself"); + assert!(!session.proxies(), "and is cut on the film itself"); + + session.set_proxies(true); + session.set_auto_proxies(false); + let path = dir.join("switches.edith"); + session.save_project(&path).expect("save"); + let text = std::fs::read_to_string(&path).expect("read back"); + assert!(text.contains("proxy on\nautoproxy off\n"), "{text}"); + + let loaded = PlaybackSession::open_project(&path).expect("reopen"); + assert!(loaded.proxies(), "cut on the stand-ins came back"); + assert!(!loaded.auto_proxies(), "and so did making none of them"); + + // ...and the default is the line left out, which is what a v12 file is. + session.set_auto_proxies(true); + session.save_project(&path).expect("save"); + let text = std::fs::read_to_string(&path).expect("read back"); + assert!(!text.contains("autoproxy"), "on is written by saying nothing"); + assert!( + PlaybackSession::open_project(&path) + .expect("reopen") + .auto_proxies() + ); + std::fs::remove_dir_all(&dir).expect("cleanup"); +} + /// Why a trim's tail stops where the file ends: a clip reaching past the last /// frame of its source is a project that will not open again (`open_project` /// refuses it by name). Pulled in on both ends and then dragged out as far as @@ -208,7 +245,7 @@ fn a_version_1_project_loads_fully_grouped_and_saves_as_version_7() { let v2 = dir.join("new.edith"); loaded.save_project(&v2).expect("save"); let text = std::fs::read_to_string(&v2).expect("read back"); - assert!(text.starts_with("edith 12\n"), "{text}"); + assert!(text.starts_with("edith 13\n"), "{text}"); assert!( text.contains("\nresolution 1280 720\n"), "a project with no resolution of its own is saved at source 0's: {text}" @@ -296,7 +333,7 @@ fn a_version_4_project_holds_more_than_two_lanes() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 12\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 13\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ video 1 0 0 30 0 3 - - fit 1000\naudio 1\n\ video 2 40 0 20 0 - - - fit 1000\naudio 2 0 0 30 0 3 - - fit 1000\n", "a four-lane project is written as it was read, three versions on" @@ -326,7 +363,7 @@ fn a_version_5_project_carries_per_clip_equalizers() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 12\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 13\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\ eq 12000.0:6.25:0.5:hs\n\ video 1 0 0 30 0 - 0 - fit 1000\nvideo 1 30 30 60 0 - 1 - fit 1000\n\ @@ -361,7 +398,7 @@ fn a_version_6_project_carries_per_clip_colours() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 12\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 13\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\ eq 80.0:-3.0:0.707:ls\n\ color 0.1:1.2:0.9:-0.3\n\ color -0.25:1.0:0.0:0.5\n\ @@ -411,7 +448,7 @@ fn a_version_7_project_carries_a_resolution_and_fit_policies() { loaded.save_project(&again).expect("save"); assert_eq!( std::fs::read_to_string(&again).expect("read back"), - "edith 12\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\ + "edith 13\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\ video 1 0 0 30 0 - - - fill 1000\nvideo 1 30 30 60 0 - - - center 1000\n\ audio 1 0 0 60 0 - - - fit 1000\n", "a v7 project is written back as the v8 it now is: the same clips, each \ @@ -669,7 +706,7 @@ fn malformed_files_are_numbered_errors_and_never_panics() { for (text, want) in [ ( - "edith 13\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n", + "edith 14\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n", "line 1", ), // An eq index the table does not hold, and a band shape there is none. diff --git a/crates/engine/tests/silence.rs b/crates/engine/tests/silence.rs index fe52fd9..d207604 100644 --- a/crates/engine/tests/silence.rs +++ b/crates/engine/tests/silence.rs @@ -377,13 +377,14 @@ fn scanning_a_clip_and_cutting_what_it_finds() { None, p.tone(), false, + true, p.limiter(), 0, ) .expect("save"); let text = std::fs::read_to_string(&file).expect("read it back"); assert!( - text.starts_with("edith 12"), + text.starts_with("edith 13"), "{:?}", &text[..16.min(text.len())] ); diff --git a/crates/engine/tests/subtitles.rs b/crates/engine/tests/subtitles.rs index 8aa9805..38b14cf 100644 --- a/crates/engine/tests/subtitles.rs +++ b/crates/engine/tests/subtitles.rs @@ -259,7 +259,7 @@ fn a_project_keeps_its_subtitles_across_a_save() { let project = dir.join("cut.edith"); session.save_project(&project).expect("save"); let text = std::fs::read_to_string(&project).expect("read the project back"); - assert!(text.starts_with("edith 12\n"), "{text}"); + assert!(text.starts_with("edith 13\n"), "{text}"); assert!( text.contains("\nsubtitle - test_subs.srt\n"), "the reference is written relative, and no cue is: {text}"