forge
Explore
Log in

Don't you dare go Hollow

wip(engine): transform table threads through project/playback/proxy, .edith v20

Browse files at this commit

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