wip(engine): transform table threads through project/playback/proxy, .edith v20
Browse files at this commit621274e126a3c47d336e6d4f673624e080b709e6Parent: d89279e7 changed files +104 -12
- crates/app/src/tests/editing.rs +3 -0
- crates/app/src/tests/layout.rs +1 -0
- crates/app/src/tests/view.rs +1 -0
- crates/engine/src/edith.rs +67 -10
- crates/engine/src/playback.rs +10 -2
- crates/engine/src/project.rs +20 -0
- crates/engine/src/proxy.rs +2 -0
crates/app/src/tests/editing.rsmodified+3 -0
| @@ -625,6 +625,7 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { | ||
| 625 | 625 | link: None, |
| 626 | 626 | eq: None, |
| 627 | 627 | color: None, |
| 628 | + transform: None, | |
| 628 | 629 | fit: FitPolicy::default(), |
| 629 | 630 | speed: Speed::NORMAL, |
| 630 | 631 | }; |
| @@ -998,6 +999,7 @@ fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() { | ||
| 998 | 999 | link: Some(1), |
| 999 | 1000 | eq: None, |
| 1000 | 1001 | color: None, |
| 1002 | + transform: None, | |
| 1001 | 1003 | fit: FitPolicy::default(), |
| 1002 | 1004 | speed: Speed::NORMAL, |
| 1003 | 1005 | }; |
| @@ -1631,6 +1633,7 @@ fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() { | ||
| 1631 | 1633 | link: None, |
| 1632 | 1634 | eq: None, |
| 1633 | 1635 | color: None, |
| 1636 | + transform: None, | |
| 1634 | 1637 | fit: Default::default(), |
| 1635 | 1638 | speed: Default::default(), |
| 1636 | 1639 | }; |
crates/app/src/tests/layout.rsmodified+1 -0
| @@ -811,6 +811,7 @@ fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() { | ||
| 811 | 811 | link: None, |
| 812 | 812 | eq: None, |
| 813 | 813 | color: None, |
| 814 | + transform: None, | |
| 814 | 815 | fit: FitPolicy::Fit, |
| 815 | 816 | speed: Speed::NORMAL, |
| 816 | 817 | }; |
crates/app/src/tests/view.rsmodified+1 -0
| @@ -157,6 +157,7 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { | ||
| 157 | 157 | link, |
| 158 | 158 | eq: None, |
| 159 | 159 | color: None, |
| 160 | + transform: None, | |
| 160 | 161 | fit: Default::default(), |
| 161 | 162 | speed: Default::default(), |
| 162 | 163 | }; |
crates/engine/src/edith.rsmodified+67 -10
| @@ -220,10 +220,12 @@ use crate::limiter::Limiter; | ||
| 220 | 220 | use crate::project::{Clip, Lane, LaneKind, Source, Speed, SubClip}; |
| 221 | 221 | use crate::scale::FitPolicy; |
| 222 | 222 | use crate::subtitle::SubtitleTrack; |
| 223 | +use crate::transform::TransformParams; | |
| 223 | 224 | |
| 224 | 225 | /// What [`save`] writes. Read support goes back to `edith 1`; see the module |
| 225 | 226 | /// docs for what those dialects looked like. |
| 226 | -const MAGIC: &[u8] = b"edith 19"; | |
| 227 | +const MAGIC: &[u8] = b"edith 20"; | |
| 228 | +const MAGIC_V19: &[u8] = b"edith 19"; | |
| 227 | 229 | const MAGIC_V18: &[u8] = b"edith 18"; |
| 228 | 230 | const MAGIC_V17: &[u8] = b"edith 17"; |
| 229 | 231 | const MAGIC_V16: &[u8] = b"edith 16"; |
| @@ -265,6 +267,9 @@ pub struct Document { | ||
| 265 | 267 | /// The colour table [`Clip::color`] indexes into, in file order. Empty for |
| 266 | 268 | /// every dialect before v6. |
| 267 | 269 | pub color: Vec<ColorParams>, |
| 270 | + /// The transform table [`Clip::transform`] indexes into, in file order. | |
| 271 | + /// Empty for every dialect before v20. | |
| 272 | + pub transform: Vec<TransformParams>, | |
| 268 | 273 | /// The project's own picture size. `None` for every dialect before v7 and |
| 269 | 274 | /// for a v7 file that leaves it out, which both mean "source 0's picture". |
| 270 | 275 | pub resolution: Option<(u32, u32)>, |
| @@ -333,6 +338,7 @@ pub fn save( | ||
| 333 | 338 | subtitles: &[SubtitleTrack], |
| 334 | 339 | eq: &[EqParams], |
| 335 | 340 | color: &[ColorParams], |
| 341 | + transform: &[TransformParams], | |
| 336 | 342 | resolution: (u32, u32), |
| 337 | 343 | fps: Option<f64>, |
| 338 | 344 | tone: crate::tonemap::Preset, |
| @@ -354,8 +360,8 @@ pub fn save( | ||
| 354 | 360 | let result = std::fs::File::create(&part) |
| 355 | 361 | .and_then(|mut f| { |
| 356 | 362 | f.write_all(&emit( |
| 357 | - &dir, sources, lanes, gains, subs, subtitles, eq, color, resolution, fps, tone, | |
| 358 | - proxy, auto_proxy, encoder, limiter, sample_rate, playhead, | |
| 363 | + &dir, sources, lanes, gains, subs, subtitles, eq, color, transform, resolution, | |
| 364 | + fps, tone, proxy, auto_proxy, encoder, limiter, sample_rate, playhead, | |
| 359 | 365 | ))?; |
| 360 | 366 | f.sync_all() |
| 361 | 367 | }) |
| @@ -396,6 +402,7 @@ fn emit( | ||
| 396 | 402 | subtitles: &[SubtitleTrack], |
| 397 | 403 | eq: &[EqParams], |
| 398 | 404 | color: &[ColorParams], |
| 405 | + transform: &[TransformParams], | |
| 399 | 406 | resolution: (u32, u32), |
| 400 | 407 | fps: Option<f64>, |
| 401 | 408 | tone: crate::tonemap::Preset, |
| @@ -504,6 +511,16 @@ fn emit( | ||
| 504 | 511 | .as_bytes(), |
| 505 | 512 | ); |
| 506 | 513 | } |
| 514 | + // ...and the transform table, for the same reason and by the same rules. | |
| 515 | + for p in transform { | |
| 516 | + out.extend_from_slice( | |
| 517 | + format!( | |
| 518 | + "transform {:?}:{:?}:{:?}:{:?}:{:?}:{:?}:{:?}:{:?}\n", | |
| 519 | + p.pos_x, p.pos_y, p.scale, p.rotate, p.crop_l, p.crop_r, p.crop_t, p.crop_b | |
| 520 | + ) | |
| 521 | + .as_bytes(), | |
| 522 | + ); | |
| 523 | + } | |
| 507 | 524 | // Lane by lane rather than interleaved by time: a lane reads as a list, the |
| 508 | 525 | // parser gets its sortedness check for free from the order it is in, and |
| 509 | 526 | // the lanes come back out in the order they are displayed in. |
| @@ -556,9 +573,10 @@ fn emit( | ||
| 556 | 573 | let link = c.link.map_or("-".to_string(), |l| l.to_string()); |
| 557 | 574 | let eq = c.eq.map_or("-".to_string(), |e| e.to_string()); |
| 558 | 575 | let color = c.color.map_or("-".to_string(), |e| e.to_string()); |
| 576 | + let transform = c.transform.map_or("-".to_string(), |e| e.to_string()); | |
| 559 | 577 | out.extend_from_slice( |
| 560 | 578 | format!( |
| 561 | - "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {} {}\n", | |
| 579 | + "{keyword} {ord} {} {} {} {} {link} {eq} {color} {} {} {} {} {} {transform}\n", | |
| 562 | 580 | c.start, |
| 563 | 581 | c.in_frame, |
| 564 | 582 | c.out_frame, |
| @@ -610,8 +628,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | ||
| 610 | 628 | // The dialects that wrote a source line without its stream field. Reading |
| 611 | 629 | // one is the whole of what "an old project still opens" means here. |
| 612 | 630 | let streamless = v1 || first == MAGIC_V2; |
| 613 | - // The one that carries a per-clip cross-dissolve into its successor... | |
| 614 | - let v19 = first == MAGIC; | |
| 631 | + // The one that carries a per-clip transform (position/scale/rotate/crop)... | |
| 632 | + let v20 = first == MAGIC; | |
| 633 | + // ...the one that carries a per-clip cross-dissolve into its successor... | |
| 634 | + let v19 = v20 || first == MAGIC_V19; | |
| 615 | 635 | // ...the one that carries a per-clip fade envelope... |
| 616 | 636 | let v18 = v19 || first == MAGIC_V18; |
| 617 | 637 | // ...the one that carries an explicit sound rate... |
| @@ -668,6 +688,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | ||
| 668 | 688 | // Nothing before v5 equalizes anything, and nothing before v6 grades. |
| 669 | 689 | eq: Vec::new(), |
| 670 | 690 | color: Vec::new(), |
| 691 | + // Nothing before v20 places any clip anywhere but its fit policy's own | |
| 692 | + // spot: the identity transform is what leaving a clip's index out | |
| 693 | + // still means. | |
| 694 | + transform: Vec::new(), | |
| 671 | 695 | // Nothing before v7 has a resolution of its own: source 0's picture is |
| 672 | 696 | // what those projects were, and `None` is how the loader is told so. |
| 673 | 697 | resolution: None, |
| @@ -972,6 +996,30 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | ||
| 972 | 996 | tint: float(parts[3], n)?, |
| 973 | 997 | }); |
| 974 | 998 | } |
| 999 | + b"transform" if v20 => { | |
| 1000 | + if doc.lanes.iter().any(|(_, clips)| !clips.is_empty()) { | |
| 1001 | + return Err(format!("line {n}: transform after a clip").into()); | |
| 1002 | + } | |
| 1003 | + let f = fields(rest, 1, "transform", n)?; | |
| 1004 | + let parts: Vec<&[u8]> = f[0].split(|&b| b == b':').collect(); | |
| 1005 | + if parts.len() != 8 { | |
| 1006 | + return Err(format!( | |
| 1007 | + "line {n}: transform wants 8 fields, found {}", | |
| 1008 | + parts.len() | |
| 1009 | + ) | |
| 1010 | + .into()); | |
| 1011 | + } | |
| 1012 | + doc.transform.push(TransformParams { | |
| 1013 | + pos_x: float(parts[0], n)?, | |
| 1014 | + pos_y: float(parts[1], n)?, | |
| 1015 | + scale: float(parts[2], n)?, | |
| 1016 | + rotate: float(parts[3], n)?, | |
| 1017 | + crop_l: float(parts[4], n)?, | |
| 1018 | + crop_r: float(parts[5], n)?, | |
| 1019 | + crop_t: float(parts[6], n)?, | |
| 1020 | + crop_b: float(parts[7], n)?, | |
| 1021 | + }); | |
| 1022 | + } | |
| 975 | 1023 | // v1: one lane, no placement, no groups. Every clip becomes one |
| 976 | 1024 | // grouped video+audio pair laid where the queue reached, which is |
| 977 | 1025 | // what the file always meant. |
| @@ -989,6 +1037,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | ||
| 989 | 1037 | link: Some(doc.lanes[0].1.len() as u32), |
| 990 | 1038 | eq: None, |
| 991 | 1039 | color: None, |
| 1040 | + transform: None, | |
| 992 | 1041 | fit: FitPolicy::default(), |
| 993 | 1042 | speed: Speed::NORMAL, |
| 994 | 1043 | }, |
| @@ -1100,16 +1149,18 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | ||
| 1100 | 1149 | if numbered && rest.is_empty() { |
| 1101 | 1150 | continue; |
| 1102 | 1151 | } |
| 1103 | - // v18 grew the two fade fields, v19 the transition one, v8 | |
| 1104 | - // the speed one, v7 the fit one, v6 the colour one and v5 the | |
| 1105 | - // eq one; every older dialect ends at the link. | |
| 1152 | + // v20 grew the transform field, v18 the two fade fields, v19 | |
| 1153 | + // the transition one, v8 the speed one, v7 the fit one, v6 | |
| 1154 | + // the colour one and v5 the eq one; every older dialect ends | |
| 1155 | + // at the link. | |
| 1106 | 1156 | let want = 5 |
| 1107 | 1157 | + usize::from(v5) |
| 1108 | 1158 | + usize::from(v6) |
| 1109 | 1159 | + usize::from(v7) |
| 1110 | 1160 | + usize::from(v8) |
| 1111 | 1161 | + 2 * usize::from(v18) |
| 1112 | - + usize::from(v19); | |
| 1162 | + + usize::from(v19) | |
| 1163 | + + usize::from(v20); | |
| 1113 | 1164 | let f = fields(rest, want, "clip", n)?; |
| 1114 | 1165 | let in_frame = number(f[1], n)?; |
| 1115 | 1166 | let out_frame = number(f[2], n)?; |
| @@ -1134,6 +1185,12 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | ||
| 1134 | 1185 | }, |
| 1135 | 1186 | eq: table_index(f.get(5).copied(), doc.eq.len(), "eq", n)?, |
| 1136 | 1187 | color: table_index(f.get(6).copied(), doc.color.len(), "color", n)?, |
| 1188 | + transform: table_index( | |
| 1189 | + f.get(12).copied(), | |
| 1190 | + doc.transform.len(), | |
| 1191 | + "transform", | |
| 1192 | + n, | |
| 1193 | + )?, | |
| 1137 | 1194 | fit: fit_policy(f.get(7).copied(), n)?, |
| 1138 | 1195 | speed, |
| 1139 | 1196 | }, |
crates/engine/src/playback.rsmodified+10 -2
| @@ -580,6 +580,7 @@ impl PlaybackSession { | ||
| 580 | 580 | vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, Vec::new())], |
| 581 | 581 | Vec::new(), |
| 582 | 582 | Vec::new(), |
| 583 | + Vec::new(), | |
| 583 | 584 | )?; |
| 584 | 585 | // Onto the emptied mapping: black picture, silence, zero duration. |
| 585 | 586 | session.seek(0.); |
| @@ -628,6 +629,7 @@ impl PlaybackSession { | ||
| 628 | 629 | link: None, |
| 629 | 630 | eq: None, |
| 630 | 631 | color: None, |
| 632 | + transform: None, | |
| 631 | 633 | fit: FitPolicy::default(), |
| 632 | 634 | speed: Speed::NORMAL, |
| 633 | 635 | }; |
| @@ -636,6 +638,7 @@ impl PlaybackSession { | ||
| 636 | 638 | vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, vec![clip])], |
| 637 | 639 | Vec::new(), |
| 638 | 640 | Vec::new(), |
| 641 | + Vec::new(), | |
| 639 | 642 | )?; |
| 640 | 643 | // Every frame of this timeline is a gap, since no video lane covers |
| 641 | 644 | // anything: `composite_span_at` says so and the black worker |
| @@ -714,6 +717,7 @@ impl PlaybackSession { | ||
| 714 | 717 | link: None, |
| 715 | 718 | eq: None, |
| 716 | 719 | color: None, |
| 720 | + transform: None, | |
| 717 | 721 | fit: FitPolicy::default(), |
| 718 | 722 | speed: Speed::NORMAL, |
| 719 | 723 | }; |
| @@ -724,6 +728,7 @@ impl PlaybackSession { | ||
| 724 | 728 | vec![(LaneKind::Video, vec![clip]), (LaneKind::Audio, Vec::new())], |
| 725 | 729 | Vec::new(), |
| 726 | 730 | Vec::new(), |
| 731 | + Vec::new(), | |
| 727 | 732 | )?; |
| 728 | 733 | let span = project.composite_span_at(0); |
| 729 | 734 | // The placeholder the first seek supersedes, opened here for `open`'s |
| @@ -1014,7 +1019,8 @@ impl PlaybackSession { | ||
| 1014 | 1019 | // whole to reach one track: a film whose project names many of its |
| 1015 | 1020 | // tracks is one walk here rather than one per row. |
| 1016 | 1021 | let subtitles = crate::subtitle::open_all(&doc.subtitles); |
| 1017 | - let project = Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color)? | |
| 1022 | + let project = | |
| 1023 | + Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color, doc.transform)? | |
| 1018 | 1024 | .with_mix(&doc.gains, doc.limiter) |
| 1019 | 1025 | .with_tone(doc.tone) |
| 1020 | 1026 | // The palette before what is placed on it: a caption names a row of |
| @@ -1306,7 +1312,7 @@ impl PlaybackSession { | ||
| 1306 | 1312 | if self.project.sources().is_empty() { |
| 1307 | 1313 | return Err("this project names no file: there is nothing to save".into()); |
| 1308 | 1314 | } |
| 1309 | - let (sources, lanes, eq, color) = self.project.without_orphan_sources(); | |
| 1315 | + let (sources, lanes, eq, color, transform) = self.project.without_orphan_sources(); | |
| 1310 | 1316 | let playhead = secs_to_frame(self.now(), self.meta.frame_rate) |
| 1311 | 1317 | .min(self.project.timeline_frames().saturating_sub(1)); |
| 1312 | 1318 | crate::edith::save( |
| @@ -1326,6 +1332,7 @@ impl PlaybackSession { | ||
| 1326 | 1332 | self.project.subtitles(), |
| 1327 | 1333 | &eq, |
| 1328 | 1334 | &color, |
| 1335 | + &transform, | |
| 1329 | 1336 | (self.meta.width, self.meta.height), |
| 1330 | 1337 | // ...and the rate it was cut at, which nothing else in the file |
| 1331 | 1338 | // says: a timeline of stills and songs used to come back at |
| @@ -2689,6 +2696,7 @@ impl PlaybackSession { | ||
| 2689 | 2696 | link: None, |
| 2690 | 2697 | eq: None, |
| 2691 | 2698 | color: None, |
| 2699 | + transform: None, | |
| 2692 | 2700 | fit: FitPolicy::default(), |
| 2693 | 2701 | speed: Speed::NORMAL, |
| 2694 | 2702 | }; |
crates/engine/src/project.rsmodified+20 -0
| @@ -1308,6 +1308,7 @@ impl Project { | ||
| 1308 | 1308 | link: Some(self.new_link()), |
| 1309 | 1309 | eq: None, |
| 1310 | 1310 | color: None, |
| 1311 | + transform: None, | |
| 1311 | 1312 | fit: FitPolicy::default(), |
| 1312 | 1313 | speed: Speed::NORMAL, |
| 1313 | 1314 | }; |
| @@ -4593,6 +4594,7 @@ impl Project { | ||
| 4593 | 4594 | lanes: self.lanes.clone(), |
| 4594 | 4595 | eq: self.eq.clone(), |
| 4595 | 4596 | color: self.color.clone(), |
| 4597 | + transform: self.transform.clone(), | |
| 4596 | 4598 | history: Vec::new(), |
| 4597 | 4599 | redo: Vec::new(), |
| 4598 | 4600 | next_link: self.next_link, |
| @@ -4934,6 +4936,20 @@ fn color_finite(p: &ColorParams) -> bool { | ||
| 4934 | 4936 | && p.tint.is_finite() |
| 4935 | 4937 | } |
| 4936 | 4938 | |
| 4939 | +/// The same for a transform: [`crate::scale`] clamps a non-finite value to | |
| 4940 | +/// identity at read time, but a value that cannot round-trip has no business | |
| 4941 | +/// reaching the model. | |
| 4942 | +fn transform_finite(p: &TransformParams) -> bool { | |
| 4943 | + p.pos_x.is_finite() | |
| 4944 | + && p.pos_y.is_finite() | |
| 4945 | + && p.scale.is_finite() | |
| 4946 | + && p.rotate.is_finite() | |
| 4947 | + && p.crop_l.is_finite() | |
| 4948 | + && p.crop_r.is_finite() | |
| 4949 | + && p.crop_t.is_finite() | |
| 4950 | + && p.crop_b.is_finite() | |
| 4951 | +} | |
| 4952 | + | |
| 4937 | 4953 | fn sorted_disjoint(clips: &[Clip]) -> bool { |
| 4938 | 4954 | clips.iter().all(|c| c.out_frame > c.in_frame) |
| 4939 | 4955 | && clips.windows(2).all(|w| w[0].end() <= w[1].start) |
| @@ -5286,6 +5302,7 @@ mod tests { | ||
| 5286 | 5302 | link: None, |
| 5287 | 5303 | eq: None, |
| 5288 | 5304 | color: None, |
| 5305 | + transform: None, | |
| 5289 | 5306 | fit: FitPolicy::default(), |
| 5290 | 5307 | speed: Speed::NORMAL, |
| 5291 | 5308 | } |
| @@ -6756,6 +6773,7 @@ mod tests { | ||
| 6756 | 6773 | link: None, |
| 6757 | 6774 | eq: None, |
| 6758 | 6775 | color: None, |
| 6776 | + transform: None, | |
| 6759 | 6777 | fit: FitPolicy::Fit, |
| 6760 | 6778 | speed: Speed::NORMAL, |
| 6761 | 6779 | }; |
| @@ -8283,6 +8301,7 @@ mod tests { | ||
| 8283 | 8301 | link: Some(link), |
| 8284 | 8302 | eq: None, |
| 8285 | 8303 | color: None, |
| 8304 | + transform: None, | |
| 8286 | 8305 | fit: FitPolicy::default(), |
| 8287 | 8306 | speed: Speed::NORMAL, |
| 8288 | 8307 | }; |
| @@ -9063,6 +9082,7 @@ mod tests { | ||
| 9063 | 9082 | link: Some(link), |
| 9064 | 9083 | eq: None, |
| 9065 | 9084 | color: None, |
| 9085 | + transform: None, | |
| 9066 | 9086 | fit: FitPolicy::default(), |
| 9067 | 9087 | speed: Speed::NORMAL, |
| 9068 | 9088 | }; |
crates/engine/src/proxy.rsmodified+2 -0
| @@ -497,6 +497,7 @@ fn started(source: &Path, only_if: fn(&VideoMeta) -> bool) -> crate::Result<Opti | ||
| 497 | 497 | link: None, |
| 498 | 498 | eq: None, |
| 499 | 499 | color: None, |
| 500 | + transform: None, | |
| 500 | 501 | fit: FitPolicy::default(), |
| 501 | 502 | speed: Speed::NORMAL, |
| 502 | 503 | }; |
| @@ -505,6 +506,7 @@ fn started(source: &Path, only_if: fn(&VideoMeta) -> bool) -> crate::Result<Opti | ||
| 505 | 506 | vec![(LaneKind::Video, vec![clip])], |
| 506 | 507 | Vec::new(), |
| 507 | 508 | Vec::new(), |
| 509 | + Vec::new(), | |
| 508 | 510 | )?; |
| 509 | 511 | let bitrate = |
| 510 | 512 | (f64::from(width) * f64::from(height) * meta.frame_rate * BITS_PER_PIXEL) as u64; |