forge
Explore
Log in

Don't you dare go Hollow

Transition duration row — retune a dissolve or crossfade after applying it

Browse files at this commit

7f34c17b26628e1059da783c33dfc0345187ebe0Ahmet Kaan GümüşParent: 6fef2f28b3853b
  • feat
    • transition duration row — retune a dissolve or crossfade after applying it
Show full message
✨ feat(inspector): transition duration row — retune a dissolve or crossfade after applying it
crates/app/src/player/timeline_edit.rsmodified+32 -0
@@ -1550,6 +1550,38 @@ impl Player {
15501550 cx.notify();
15511551 }
15521552
1553+ /// Widens or narrows the transition the anchor already carries, one
1554+ /// frame at a step, from the inspector's duration row -- ctrl+f/ctrl+x
1555+ /// stay the toggle that seeds a fresh one at one second; this is what
1556+ /// moves it afterwards. The engine clamps both kinds to what the two
1557+ /// clips actually offer ([`Project::set_transition_out`],
1558+ /// [`Project::crossfade`]), so a step past the successor's own length
1559+ /// lands at the successor's length instead of asking for more than
1560+ /// there is.
1561+ pub(crate) fn nudge_transition(&mut self, lane: Lane, idx: usize, step: i32, cx: &mut Context<Self>) {
1562+ if self.exporting().is_some() {
1563+ return;
1564+ }
1565+ let Some(session) = &mut self.session else {
1566+ return;
1567+ };
1568+ let current = match lane.kind {
1569+ LaneKind::Video => session.transition_out_of(lane, idx),
1570+ LaneKind::Audio => session.lane_clips(lane).get(idx).map_or(0, |c| c.fade_out),
1571+ _ => return,
1572+ };
1573+ let frames = (current as i32 + step).max(0) as u32;
1574+ let ok = match lane.kind {
1575+ LaneKind::Video => session.set_transition_out(lane, idx, frames),
1576+ LaneKind::Audio => session.crossfade(lane, idx, frames),
1577+ _ => false,
1578+ };
1579+ if ok {
1580+ self.mark_dirty();
1581+ cx.notify();
1582+ }
1583+ }
1584+
15531585 /// The clip as the drag is showing it: an edge under the pointer moves its
15541586 /// own box, and the boxes of everything linked to it, before anything is
15551587 /// committed. Display only -- the project is not touched until the release.
crates/app/src/tests/cards.rsmodified+67 -0
@@ -3,6 +3,7 @@
33
44 use super::*;
55 use crate::audio_cards::EQ_GRAPH_MAX_H;
6+use crate::ui::inspector::transition_of;
67 use std::sync::atomic::Ordering;
78
89 /// FAULT 2's general shape (not just the source dot's menu): `overlaid()`
@@ -1207,6 +1208,72 @@ fn a_typed_bitrate_is_a_field_and_not_a_key_capture() {
12071208 assert!(detail.starts_with("6▏"), "{detail}");
12081209 }
12091210
1211+/// [`crate::ui::inspector::transition_of`]: the inspector's duration row
1212+/// appears only for an anchor that actually carries a dissolve or a
1213+/// crossfade, and the room it offers is capped at what the successor clip
1214+/// actually has -- the same clamp [`engine::project::Project::set_transition_out`]/
1215+/// [`engine::project::Project::crossfade`] enforce, read back here without
1216+/// either engine call so the row can never claim more than a step could land
1217+/// in.
1218+#[test]
1219+fn a_duration_row_shows_only_for_a_transition_and_its_room_is_the_successors() {
1220+ // `len` is the clip's own source length (`out_frame`, `in_frame` fixed at
1221+ // 0, `speed` 1x, so `Clip::frames()` reads back exactly `len`).
1222+ fn clip(start: u32, len: u32, transition_out: u32, fade_in: u32, fade_out: u32) -> Clip {
1223+ Clip {
1224+ start,
1225+ in_frame: 0,
1226+ out_frame: len,
1227+ source: 0,
1228+ link: None,
1229+ eq: None,
1230+ color: None,
1231+ transform: None,
1232+ fit: FitPolicy::default(),
1233+ speed: Speed::NORMAL,
1234+ fade_in,
1235+ fade_out,
1236+ transition_out,
1237+ }
1238+ }
1239+ // A plain cut carries neither field, so the row has nothing to show.
1240+ let plain = clip(0, 10, 0, 0, 0);
1241+ let plain_next = clip(10, 15, 0, 0, 0);
1242+ assert_eq!(transition_of(LaneKind::Video, &plain, Some(&plain_next)), None);
1243+
1244+ // A dissolve: video lane, `transition_out` set, an adjacent successor.
1245+ // The room offered is the shorter of the two -- here the successor's own
1246+ // 5-frame length, less than the anchor's 10.
1247+ let a = clip(0, 10, 4, 0, 0);
1248+ let b = clip(10, 5, 0, 0, 0);
1249+ assert_eq!(
1250+ transition_of(LaneKind::Video, &a, Some(&b)),
1251+ Some(("Dissolve", 4, 5))
1252+ );
1253+ // No successor, or a gap before one: no row, same as no transition.
1254+ assert_eq!(transition_of(LaneKind::Video, &a, None), None);
1255+ let gap = clip(11, 5, 0, 0, 0);
1256+ assert_eq!(transition_of(LaneKind::Video, &a, Some(&gap)), None);
1257+
1258+ // A crossfade: audio lane, both ends of the join set
1259+ // ([`Project::crossfade`]'s own signature) -- a one-sided fade (the
1260+ // successor's `fade_in` still 0) is not one, and stays a plain fade.
1261+ let a = clip(0, 10, 0, 0, 3);
1262+ let b = clip(10, 2, 0, 3, 0);
1263+ assert_eq!(
1264+ transition_of(LaneKind::Audio, &a, Some(&b)),
1265+ Some(("Crossfade", 3, 2)),
1266+ "capped at the successor's own 2-frame length, though 3 was asked for"
1267+ );
1268+ let one_sided = clip(10, 2, 0, 0, 0);
1269+ assert_eq!(transition_of(LaneKind::Audio, &a, Some(&one_sided)), None);
1270+
1271+ // A dissolve field on an audio lane, or a fade-only pair on a video
1272+ // lane, name no transition either -- each kind reads only its own lane.
1273+ let dissolving = clip(0, 10, 4, 0, 0);
1274+ assert_eq!(transition_of(LaneKind::Audio, &dissolving, Some(&b)), None);
1275+}
1276+
12101277 #[test]
12111278 fn a_clip_with_no_sound_is_refused_in_the_same_words_whichever_kind_it_is() {
12121279 // A still and a video with no audio track are one answer to one
crates/app/src/ui/inspector.rsmodified+100 -0
@@ -121,6 +121,19 @@ impl Player {
121121 let sub = self.session.as_ref()?.sub_lane(lane).get(idx).copied()?;
122122 Some((lane, sub))
123123 });
124+ // The transition the anchor's clip carries into its successor, if
125+ // any -- a dissolve on a video lane ([`Clip::transition_out`]) or a
126+ // crossfade on an audio lane, told apart from a plain one-sided fade
127+ // by [`Project::crossfade`]'s own signature: both ends of the join
128+ // set together. `cap` is what the pair actually offers, the same
129+ // ceiling the engine's own setters clamp to, so the row never claims
130+ // more room than a step could land in.
131+ let transition = self.selected.anchor().and_then(|(lane, idx)| {
132+ let session = self.session.as_ref()?;
133+ let clips = session.lane_clips(lane);
134+ let (label, frames, cap) = transition_of(lane.kind, clips.get(idx)?, clips.get(idx + 1))?;
135+ Some((lane, idx, label, frames, cap))
136+ });
124137 // A multi-selection is named for its anchor and counted: what the
125138 // panel shows is the anchor's settings, and the count says there is
126139 // more in hand than the panel is showing.
@@ -190,6 +203,14 @@ impl Player {
190203 .text_color(rgb(FG_SECONDARY()))
191204 .child(detail),
192205 )
206+ // The duration field: a value and its own two steppers, the
207+ // shape `mbps_steppers` already draws for the export card's
208+ // bitrate -- present only while the anchor carries a transition,
209+ // since a row for a number that means nothing is a row lying
210+ // about what is selected.
211+ .when_some(transition, |d, (lane, idx, label, frames, cap)| {
212+ d.child(self.transition_duration_row(lane, idx, label, frames, cap, cx))
213+ })
193214 .child(
194215 div()
195216 .flex()
@@ -268,6 +289,56 @@ impl Player {
268289 )
269290 }
270291
292+ /// The duration row a transition-carrying anchor grows under
293+ /// `selection_section`'s detail line: `frames` as the engine counts it,
294+ /// flanked by the −/+ steppers [`Player::mbps_steppers`] already draws
295+ /// for the export card's bitrate row -- a field, not the drag handle
296+ /// `659770a` deliberately shrank the join's hit target away from. Each
297+ /// press nudges by one frame ([`Player::nudge_transition`]); the engine's
298+ /// own setters clamp to `cap`, so a run of presses past what the
299+ /// successor offers stops there rather than erroring.
300+ fn transition_duration_row(
301+ &self,
302+ lane: Lane,
303+ idx: usize,
304+ label: &'static str,
305+ frames: u32,
306+ cap: u32,
307+ cx: &mut Context<Self>,
308+ ) -> impl IntoElement {
309+ let step = |id: &'static str, glyph: &'static str, by: i32, cx: &mut Context<Self>| {
310+ div()
311+ .id(id)
312+ .flex()
313+ .w(px(HIT_MIN))
314+ .h(px(HIT_MIN))
315+ .items_center()
316+ .justify_center()
317+ .rounded(px(3.))
318+ .bg(rgb(BG_RAISED()))
319+ .cursor_pointer()
320+ .hover(|s| s.bg(rgb(BG_HOVER())))
321+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
322+ this.nudge_transition(lane, idx, by, cx);
323+ }))
324+ .child(glyph)
325+ };
326+ div()
327+ .flex_none()
328+ .flex()
329+ .items_center()
330+ .gap(px(6.))
331+ .child(
332+ div()
333+ .flex_1()
334+ .text_size(px(11.))
335+ .text_color(rgb(FG_SECONDARY()))
336+ .child(format!("{label} {frames}f (of {cap}f offered)")),
337+ )
338+ .child(step("transition-down", "−", -1, cx))
339+ .child(step("transition-up", "+", 1, cx))
340+ }
341+
271342 /// The settings that are the *project's* rather than any clip's: the canvas
272343 /// every clip is composed onto, the rate it is cut at, the HDR rendition it
273344 /// is watched in, and the mix everything sums into. They used to be four
@@ -418,6 +489,35 @@ impl Player {
418489 }
419490 }
420491
492+/// The transition a clip carries into its immediate successor, if any -- a
493+/// dissolve on a video lane ([`Clip::transition_out`]) or a crossfade on an
494+/// audio lane, told apart from a plain one-sided fade drag by
495+/// [`Project::crossfade`]'s own signature: both ends of the join set
496+/// together, not just this clip's tail. `cap` is what the pair actually
497+/// offers -- the shorter of the two clips' own lengths -- the same ceiling
498+/// [`Project::set_transition_out`]/[`Project::crossfade`] clamp to, so the
499+/// row this feeds never claims more room than a step could land in.
500+///
501+/// Free of `Context` and of [`PlaybackSession`] alike, so it is testable
502+/// without either -- this test binary has neither a `TestAppContext` nor
503+/// real media to open one with (`split_drag_owes_save`'s own reason for
504+/// being pulled out the same way).
505+pub(crate) fn transition_of(
506+ lane_kind: LaneKind,
507+ clip: &Clip,
508+ next: Option<&Clip>,
509+) -> Option<(&'static str, u32, u32)> {
510+ let next = next.filter(|n| n.start == clip.end())?;
511+ let cap = clip.frames().min(next.frames());
512+ match lane_kind {
513+ LaneKind::Video if clip.transition_out > 0 => Some(("Dissolve", clip.transition_out, cap)),
514+ LaneKind::Audio if clip.fade_out > 0 && next.fade_in > 0 => {
515+ Some(("Crossfade", clip.fade_out, cap))
516+ }
517+ _ => None,
518+ }
519+}
520+
421521 /// A region's own title bar: the same 24 px strip in the library and the
422522 /// inspector, so the two columns read as the pair they are.
423523 pub(crate) fn section_head(title: &'static str) -> impl IntoElement {