diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 3ea0436..ada5a84 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1550,6 +1550,38 @@ impl Player { cx.notify(); } + /// Widens or narrows the transition the anchor already carries, one + /// frame at a step, from the inspector's duration row -- ctrl+f/ctrl+x + /// stay the toggle that seeds a fresh one at one second; this is what + /// moves it afterwards. The engine clamps both kinds to what the two + /// clips actually offer ([`Project::set_transition_out`], + /// [`Project::crossfade`]), so a step past the successor's own length + /// lands at the successor's length instead of asking for more than + /// there is. + pub(crate) fn nudge_transition(&mut self, lane: Lane, idx: usize, step: i32, cx: &mut Context) { + if self.exporting().is_some() { + return; + } + let Some(session) = &mut self.session else { + return; + }; + let current = match lane.kind { + LaneKind::Video => session.transition_out_of(lane, idx), + LaneKind::Audio => session.lane_clips(lane).get(idx).map_or(0, |c| c.fade_out), + _ => return, + }; + let frames = (current as i32 + step).max(0) as u32; + let ok = match lane.kind { + LaneKind::Video => session.set_transition_out(lane, idx, frames), + LaneKind::Audio => session.crossfade(lane, idx, frames), + _ => false, + }; + if ok { + self.mark_dirty(); + cx.notify(); + } + } + /// The clip as the drag is showing it: an edge under the pointer moves its /// own box, and the boxes of everything linked to it, before anything is /// committed. Display only -- the project is not touched until the release. diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 55a6017..121013f 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -3,6 +3,7 @@ use super::*; use crate::audio_cards::EQ_GRAPH_MAX_H; +use crate::ui::inspector::transition_of; use std::sync::atomic::Ordering; /// 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() { assert!(detail.starts_with("6▏"), "{detail}"); } +/// [`crate::ui::inspector::transition_of`]: the inspector's duration row +/// appears only for an anchor that actually carries a dissolve or a +/// crossfade, and the room it offers is capped at what the successor clip +/// actually has -- the same clamp [`engine::project::Project::set_transition_out`]/ +/// [`engine::project::Project::crossfade`] enforce, read back here without +/// either engine call so the row can never claim more than a step could land +/// in. +#[test] +fn a_duration_row_shows_only_for_a_transition_and_its_room_is_the_successors() { + // `len` is the clip's own source length (`out_frame`, `in_frame` fixed at + // 0, `speed` 1x, so `Clip::frames()` reads back exactly `len`). + fn clip(start: u32, len: u32, transition_out: u32, fade_in: u32, fade_out: u32) -> Clip { + Clip { + start, + in_frame: 0, + out_frame: len, + source: 0, + link: None, + eq: None, + color: None, + transform: None, + fit: FitPolicy::default(), + speed: Speed::NORMAL, + fade_in, + fade_out, + transition_out, + } + } + // A plain cut carries neither field, so the row has nothing to show. + let plain = clip(0, 10, 0, 0, 0); + let plain_next = clip(10, 15, 0, 0, 0); + assert_eq!(transition_of(LaneKind::Video, &plain, Some(&plain_next)), None); + + // A dissolve: video lane, `transition_out` set, an adjacent successor. + // The room offered is the shorter of the two -- here the successor's own + // 5-frame length, less than the anchor's 10. + let a = clip(0, 10, 4, 0, 0); + let b = clip(10, 5, 0, 0, 0); + assert_eq!( + transition_of(LaneKind::Video, &a, Some(&b)), + Some(("Dissolve", 4, 5)) + ); + // No successor, or a gap before one: no row, same as no transition. + assert_eq!(transition_of(LaneKind::Video, &a, None), None); + let gap = clip(11, 5, 0, 0, 0); + assert_eq!(transition_of(LaneKind::Video, &a, Some(&gap)), None); + + // A crossfade: audio lane, both ends of the join set + // ([`Project::crossfade`]'s own signature) -- a one-sided fade (the + // successor's `fade_in` still 0) is not one, and stays a plain fade. + let a = clip(0, 10, 0, 0, 3); + let b = clip(10, 2, 0, 3, 0); + assert_eq!( + transition_of(LaneKind::Audio, &a, Some(&b)), + Some(("Crossfade", 3, 2)), + "capped at the successor's own 2-frame length, though 3 was asked for" + ); + let one_sided = clip(10, 2, 0, 0, 0); + assert_eq!(transition_of(LaneKind::Audio, &a, Some(&one_sided)), None); + + // A dissolve field on an audio lane, or a fade-only pair on a video + // lane, name no transition either -- each kind reads only its own lane. + let dissolving = clip(0, 10, 4, 0, 0); + assert_eq!(transition_of(LaneKind::Audio, &dissolving, Some(&b)), None); +} + #[test] fn a_clip_with_no_sound_is_refused_in_the_same_words_whichever_kind_it_is() { // A still and a video with no audio track are one answer to one diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index 51ae599..97fa15c 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -121,6 +121,19 @@ impl Player { let sub = self.session.as_ref()?.sub_lane(lane).get(idx).copied()?; Some((lane, sub)) }); + // The transition the anchor's clip carries into its successor, if + // any -- a dissolve on a video lane ([`Clip::transition_out`]) or a + // crossfade on an audio lane, told apart from a plain one-sided fade + // by [`Project::crossfade`]'s own signature: both ends of the join + // set together. `cap` is what the pair actually offers, the same + // ceiling the engine's own setters clamp to, so the row never claims + // more room than a step could land in. + let transition = self.selected.anchor().and_then(|(lane, idx)| { + let session = self.session.as_ref()?; + let clips = session.lane_clips(lane); + let (label, frames, cap) = transition_of(lane.kind, clips.get(idx)?, clips.get(idx + 1))?; + Some((lane, idx, label, frames, cap)) + }); // A multi-selection is named for its anchor and counted: what the // panel shows is the anchor's settings, and the count says there is // more in hand than the panel is showing. @@ -190,6 +203,14 @@ impl Player { .text_color(rgb(FG_SECONDARY())) .child(detail), ) + // The duration field: a value and its own two steppers, the + // shape `mbps_steppers` already draws for the export card's + // bitrate -- present only while the anchor carries a transition, + // since a row for a number that means nothing is a row lying + // about what is selected. + .when_some(transition, |d, (lane, idx, label, frames, cap)| { + d.child(self.transition_duration_row(lane, idx, label, frames, cap, cx)) + }) .child( div() .flex() @@ -268,6 +289,56 @@ impl Player { ) } + /// The duration row a transition-carrying anchor grows under + /// `selection_section`'s detail line: `frames` as the engine counts it, + /// flanked by the −/+ steppers [`Player::mbps_steppers`] already draws + /// for the export card's bitrate row -- a field, not the drag handle + /// `659770a` deliberately shrank the join's hit target away from. Each + /// press nudges by one frame ([`Player::nudge_transition`]); the engine's + /// own setters clamp to `cap`, so a run of presses past what the + /// successor offers stops there rather than erroring. + fn transition_duration_row( + &self, + lane: Lane, + idx: usize, + label: &'static str, + frames: u32, + cap: u32, + cx: &mut Context, + ) -> impl IntoElement { + let step = |id: &'static str, glyph: &'static str, by: i32, cx: &mut Context| { + div() + .id(id) + .flex() + .w(px(HIT_MIN)) + .h(px(HIT_MIN)) + .items_center() + .justify_center() + .rounded(px(3.)) + .bg(rgb(BG_RAISED())) + .cursor_pointer() + .hover(|s| s.bg(rgb(BG_HOVER()))) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.nudge_transition(lane, idx, by, cx); + })) + .child(glyph) + }; + div() + .flex_none() + .flex() + .items_center() + .gap(px(6.)) + .child( + div() + .flex_1() + .text_size(px(11.)) + .text_color(rgb(FG_SECONDARY())) + .child(format!("{label} {frames}f (of {cap}f offered)")), + ) + .child(step("transition-down", "−", -1, cx)) + .child(step("transition-up", "+", 1, cx)) + } + /// The settings that are the *project's* rather than any clip's: the canvas /// every clip is composed onto, the rate it is cut at, the HDR rendition it /// is watched in, and the mix everything sums into. They used to be four @@ -418,6 +489,35 @@ impl Player { } } +/// The transition a clip carries into its immediate successor, if any -- a +/// dissolve on a video lane ([`Clip::transition_out`]) or a crossfade on an +/// audio lane, told apart from a plain one-sided fade drag by +/// [`Project::crossfade`]'s own signature: both ends of the join set +/// together, not just this clip's tail. `cap` is what the pair actually +/// offers -- the shorter of the two clips' own lengths -- the same ceiling +/// [`Project::set_transition_out`]/[`Project::crossfade`] clamp to, so the +/// row this feeds never claims more room than a step could land in. +/// +/// Free of `Context` and of [`PlaybackSession`] alike, so it is testable +/// without either -- this test binary has neither a `TestAppContext` nor +/// real media to open one with (`split_drag_owes_save`'s own reason for +/// being pulled out the same way). +pub(crate) fn transition_of( + lane_kind: LaneKind, + clip: &Clip, + next: Option<&Clip>, +) -> Option<(&'static str, u32, u32)> { + let next = next.filter(|n| n.start == clip.end())?; + let cap = clip.frames().min(next.frames()); + match lane_kind { + LaneKind::Video if clip.transition_out > 0 => Some(("Dissolve", clip.transition_out, cap)), + LaneKind::Audio if clip.fade_out > 0 && next.fade_in > 0 => { + Some(("Crossfade", clip.fade_out, cap)) + } + _ => None, + } +} + /// A region's own title bar: the same 24 px strip in the library and the /// inspector, so the two columns read as the pair they are. pub(crate) fn section_head(title: &'static str) -> impl IntoElement {