From 14bd4a65ade27399289c741d80f4363a21d16824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 09:32:38 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(ui):=20the=20cut=20becomes=20t?= =?UTF-8?q?he=20subject=20and=20the=20dock=20fills?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DESIGN.md §12 steps 3 and 4. The cut grammar dispatches for real: , and . walk the marked clip's cuts (shift strides ten), [ and ] trim its edges at frame detents through the same engine door the mouse drag uses, / loops the subject span while the transport pumps. The maths live as pure functions in timeline_math.rs with their own tests. The stance's own regions fill in: the spine carries its commands as ghost glyphs wearing chords read live from the keymap, the screen draws the picture through the same path the legacy room uses and puts OUT|IN plates up when the playhead rests on a cut, the time band leads with timecode and the cut odometer. The stance root now takes focus and reads keys — before this it had none, so the chords were unreachable there. The dock delegates to ui/dock_stance.rs: Sources reuses the library assembly, Clip shows Speed, Colour, Transform and EQ as ghost verbs over the existing param cards. No box in the dock; the only one is Export. --- crates/app/src/main.rs | 16 ++ crates/app/src/player/actions.rs | 113 +++++++++++++- crates/app/src/player/transport.rs | 11 ++ crates/app/src/render.rs | 6 +- crates/app/src/tests/editing.rs | 40 +++++ crates/app/src/tests/layout.rs | 5 +- crates/app/src/timeline_math.rs | 31 ++++ crates/app/src/ui/dock_stance.rs | 228 +++++++++++++++++++++++++++++ crates/app/src/ui/mod.rs | 1 + crates/app/src/ui/preview.rs | 86 +++++++++++ crates/app/src/ui/stance.rs | 187 ++++++++++++++++------- 11 files changed, 660 insertions(+), 64 deletions(-) create mode 100644 crates/app/src/ui/dock_stance.rs diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 5d61507..a07c895 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -122,6 +122,20 @@ struct Player { /// timeline frames -- `None` for the whole timeline. Session state, like /// the mark itself: never saved to a `.edith` ([`ExportSettings::range`]). range: Option<(u32, u32)>, + /// Loop-trim (DESIGN.md §6, `/`): the frame window `[start, end)` the + /// transport loops inside while it is on -- the subject cut's own clip + /// span, which is what a `[`/`]` nudge is moving. `None` is the mode off, + /// which is also what lets [`Player::pump`] answer + /// [`should_loop_restart`] with one field instead of asking whether the + /// mode is on and then separately what the window is. + loop_trim: Option<(u32, u32)>, + /// Whether the stroke [`Player::act`] is running for was held with shift + /// -- the odometer's stride (DESIGN.md §6: bare walks one cut, shift + /// strides ten). Set by the key handler right before `act`, since + /// [`ActionId`] carries no modifier of its own (`.` and `shift+.` are the + /// same [`ActionId::WalkCutNext`], by design -- see keymap.rs's own + /// `bshift`) and nothing else here reads it. + walk_shift: bool, /// Timeline seconds -> frame index, so the clock can be compared to what /// the decoder hands over. fps: f64, @@ -814,6 +828,8 @@ fn main() { player_fullscreen: false, loop_on: false, range: None, + loop_trim: None, + walk_shift: false, // Full and unmuted, which is what the session it was just // handed is already set to: nothing to push at startup. volume: Volume::default(), diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 28a1586..1b1915b 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -162,13 +162,20 @@ impl Player { ActionId::CancelExport => {} ActionId::ShowActions => self.show_actions(cx), ActionId::Screenshot => self.take_screenshot(cx), - // Cut machinery (DESIGN.md §6): keymap.rs/oracle.rs plumbing only - // so far -- a later task wires these to real behaviour. - ActionId::WalkCutNext - | ActionId::WalkCutPrev - | ActionId::TrimIn - | ActionId::TrimOut - | ActionId::LoopTrim => {} + // Cut machinery (DESIGN.md §6): the subject cut is the marked + // clip ([`Selection::anchor`]) -- the oracle already refused + // every one of these with nothing marked, so an anchor is here + // to read. + ActionId::WalkCutNext => self.walk_cut(true, cx), + ActionId::WalkCutPrev => self.walk_cut(false, cx), + // `[` `]` close in on the clip like the brackets they are: `[` + // trims a frame off the head, `]` a frame off the tail -- no-aim, + // frame detents, clamped to the room the engine already answers + // ([`nudge_edge`]), which is what makes them work at any zoom + // down to a 4px clip with nothing to click. + ActionId::TrimIn => self.nudge_cut(Edge::Start, 1, cx), + ActionId::TrimOut => self.nudge_cut(Edge::End, -1, cx), + ActionId::LoopTrim => self.toggle_loop_trim(cx), } } @@ -452,6 +459,98 @@ impl Player { cx.notify(); } + /// The odometer (DESIGN.md §6, `,` `.`): the subject cut steps to its + /// neighbour along its own lane, [`walk_shift`](Player) striding ten + /// instead of one, clamped rather than wrapping at either end + /// ([`walk_cut`]). The playhead follows it there, which is what puts the + /// screen at rest on the new cut for the two-up to draw. + pub(crate) fn walk_cut(&mut self, forward: bool, cx: &mut Context) { + let Some((lane, idx)) = self.selected.anchor() else { + return; + }; + let Some(session) = &self.session else { + return; + }; + let clips = session.lane_clips(lane); + let stride = if self.walk_shift { 10 } else { 1 }; + let next = walk_cut(idx, clips.len(), forward, stride); + let at = clips.get(next).map(|c| f64::from(c.start) / self.fps); + self.select((lane, next), cx); + if let Some(at) = at { + self.seek(at, cx); + } + } + + /// The subject cut's own span, `[start, end)` in timeline frames -- + /// what loop-trim loops and what the odometer's readout counts against. + pub(crate) fn cut_span(&self, lane: Lane, idx: usize) -> Option<(u32, u32)> { + self.session + .as_ref()? + .lane_clips(lane) + .get(idx) + .map(|c| (c.start, c.end())) + } + + /// The no-aim trim (DESIGN.md §6, `[` `]`): one frame detent off the + /// subject cut's chosen edge, clamped to the room the engine already + /// answers ([`nudge_edge`]) -- the same wall a pointer drag is clamped + /// to, so no aim and no hit-testing are needed at any zoom. + pub(crate) fn nudge_cut(&mut self, edge: Edge, dir: i32, cx: &mut Context) { + let Some((lane, idx)) = self.selected.anchor() else { + return; + }; + let Some(session) = &self.session else { + return; + }; + let Some((lo, hi)) = session.trim_room(lane, idx, edge) else { + return; + }; + let Some(current) = session.lane_clips(lane).get(idx).map(|c| match edge { + Edge::Start => c.start, + Edge::End => c.end(), + }) else { + return; + }; + let to = nudge_edge(current, dir, lo, hi); + self.mark_dirty(); + let trimmed = self + .session + .as_mut() + .is_some_and(|s| s.trim_clip(lane, idx, edge, to)); + if trimmed { + self.reset_after_reseek(); + // Loop-trim follows the edge it is trimming: the whole point of + // the mode is hearing the cut as it moves. + if self.loop_trim.is_some() { + self.loop_trim = self.cut_span(lane, idx); + } + } + cx.notify(); + } + + /// Loop-trim (DESIGN.md §6, `/`): loops the transport around the subject + /// cut's own span while `[`/`]` move its edges -- the modernized Avid + /// trim mode. Off again drops the window and leaves playback running, + /// exactly as it was found. + pub(crate) fn toggle_loop_trim(&mut self, cx: &mut Context) { + if self.loop_trim.take().is_some() { + self.notify_user("LOOP-TRIM OFF".into()); + cx.notify(); + return; + } + let Some((lane, idx)) = self.selected.anchor() else { + return; + }; + self.loop_trim = self.cut_span(lane, idx); + if self.loop_trim.is_some() { + self.notify_user("LOOP-TRIM ON — looping the subject cut while you trim".into()); + if let Some(session) = self.active_session_mut() { + session.play(); + } + } + cx.notify(); + } + pub(crate) fn undo(&mut self, cx: &mut Context) { if self.session.as_mut().is_some_and(PlaybackSession::undo) { self.reset_after_reseek(); diff --git a/crates/app/src/player/transport.rs b/crates/app/src/player/transport.rs index 723e728..51d95df 100644 --- a/crates/app/src/player/transport.rs +++ b/crates/app/src/player/transport.rs @@ -46,6 +46,17 @@ impl Player { let Some(session) = self.preview_session.as_mut().or(self.session.as_mut()) else { return; }; + // Loop-trim (DESIGN.md §6): the transport is kept inside the subject + // cut's own span while the mode is on, so a trim can be heard and + // seen without a manual replay after every nudge. Checked off the + // engine's own clock, not a frame counter this pump keeps -- the + // same `now()` [`Player::step`] reads. + if session.is_playing() + && should_loop_restart(frame_at(session.now(), fps), self.loop_trim) + { + let start = self.loop_trim.map_or(0, |(lo, _)| lo); + session.seek(f64::from(start) / fps); + } // Whether the span now decoding has yet to hand over a picture, read // *before* the drain: the frame the drain is about to take is the one // that ends the prime, and its own lateness -- however long the span's diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index 0364851..c3cea8d 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -17,8 +17,10 @@ impl Player { /// The picture region alone: the image, the subtitle cue plate, the /// preview badge and the three transient bars over its bottom edge. /// Its own method so player fullscreen ([`Player::act`]) can stand it up - /// as the window's only child without a second copy of what it draws. - fn picture_area( + /// as the window's only child without a second copy of what it draws -- + /// and so the darkroom's own screen region (DESIGN.md §5, + /// `ui::stance::screen`) draws the same picture rather than a second one. + pub(crate) fn picture_area( &mut self, position: f64, window: &mut Window, diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index bfcec58..afe2bdb 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -2062,3 +2062,43 @@ fn a_fade_drag_converts_pixels_to_frames_at_the_beds_scale() { assert_eq!(fade_delta_frames(40., 0., 25.), 0); assert_eq!(fade_delta_frames(40., -1., 25.), 0); } + +/// The cut odometer (DESIGN.md §6): `,` `.` walk it one cut at a time, shift +/// strides ten, and either end holds rather than wrapping. +#[test] +fn walk_cut_strides_and_clamps_at_either_end() { + use crate::timeline_math::walk_cut; + assert_eq!(walk_cut(3, 10, true, 1), 4); + assert_eq!(walk_cut(3, 10, false, 1), 2); + assert_eq!(walk_cut(3, 10, true, 10), 9, "clamps at the last cut"); + assert_eq!(walk_cut(3, 10, false, 10), 0, "clamps at the first cut"); + assert_eq!(walk_cut(9, 10, true, 1), 9, "already at the end holds"); + assert_eq!(walk_cut(0, 10, false, 1), 0, "already at the start holds"); + // No cuts at all: nothing to land on. + assert_eq!(walk_cut(0, 0, true, 1), 0); +} + +/// The no-aim trim (DESIGN.md §6): a frame detent clamped to the room the +/// engine already answered, in either direction, and never past it. +#[test] +fn nudge_edge_moves_one_frame_and_clamps_to_the_room() { + use crate::timeline_math::nudge_edge; + assert_eq!(nudge_edge(50, 1, 0, 100), 51); + assert_eq!(nudge_edge(50, -1, 0, 100), 49); + assert_eq!(nudge_edge(0, -1, 0, 100), 0, "the room's own floor holds"); + assert_eq!(nudge_edge(100, 1, 0, 100), 100, "the room's own ceiling holds"); + // A 4px-wide clip's room can be one frame wide: still clamps, never + // panics on the narrow end. + assert_eq!(nudge_edge(5, 1, 5, 5), 5); +} + +/// Loop-trim's restart (DESIGN.md §6): only once the window's far edge is +/// reached, and never with the mode off. +#[test] +fn should_loop_restart_only_at_the_windows_far_edge() { + use crate::timeline_math::should_loop_restart; + assert!(!should_loop_restart(40, Some((30, 60)))); + assert!(should_loop_restart(60, Some((30, 60)))); + assert!(should_loop_restart(61, Some((30, 60))), "past it restarts too"); + assert!(!should_loop_restart(60, None), "loop-trim off restarts nothing"); +} diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 212e271..9823a6c 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1743,7 +1743,10 @@ fn the_stance_renders_its_six_regions_in_the_documented_order() { // them in it too, or the geometry above is dead prose. let render_body = &stance[stance.find("pub(crate) fn render(").expect("the stance's entry point")..]; - let calls = ["spine()", "screen()", "time_band()", "bench()", "ledger()", "dock()"]; + // Open paren only, no close: DESIGN §12 steps 3 and 4 hand most of the + // regions player/window state to read, so their call sites carry + // arguments now. Order is what this asserts, not arity. + let calls = ["spine(", "screen(", "time_band(", "bench(", "ledger(", "dock("]; let composed: Vec = calls .iter() .map(|c| { diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index a4f77c2..fe66fca 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -331,6 +331,37 @@ pub(crate) fn trimmed_clip(clip: Clip, edge: Edge, to: u32, still: bool) -> Clip } } +/// The cut odometer's own arithmetic (DESIGN.md §6): where `,` `.` land from +/// `idx`, `stride` cuts forward or back among `len` of them. Clamped rather +/// than wrapping -- an odometer that wraps at the last cut reads as landing +/// back at the first, which is not "next" -- so a walk already at either end +/// simply holds there, the way [`Player::step`]'s own ends do. +pub(crate) fn walk_cut(idx: usize, len: usize, forward: bool, stride: usize) -> usize { + if len == 0 { + return 0; + } + let delta = stride.min(len - 1) as isize; + let at = if forward { idx as isize + delta } else { idx as isize - delta }; + at.clamp(0, len as isize - 1) as usize +} + +/// The no-aim trim's own arithmetic (DESIGN.md §6): `current` moved `dir` +/// frames (usually ±1, a held key's ratchet) and clamped into the room +/// [`engine::PlaybackSession::trim_room`] already answered -- the same wall a +/// pointer drag is clamped to, so a keyboard trim can never draw an edge the +/// engine would refuse. +pub(crate) fn nudge_edge(current: u32, dir: i32, lo: u32, hi: u32) -> u32 { + (i64::from(current) + i64::from(dir)).clamp(i64::from(lo), i64::from(hi)) as u32 +} + +/// Whether a loop-trim window ([`ActionId::LoopTrim`]) has been played out to +/// its far edge and wants restarting at its near one: pure so the pump's own +/// tick ([`Player::pump`]) is one `if` over a fact this decides. `None` -- +/// loop-trim off -- never restarts anything. +pub(crate) fn should_loop_restart(frame: u32, window: Option<(u32, u32)>) -> bool { + window.is_some_and(|(_, hi)| frame >= hi) +} + /// How many timeline frames a stretch of a subtitle track is worth: the one /// conversion between the two clocks a caption has -- microseconds for its /// words, frames for where it sits -- and the app-side twin of the engine's own diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs new file mode 100644 index 0000000..1b98330 --- /dev/null +++ b/crates/app/src/ui/dock_stance.rs @@ -0,0 +1,228 @@ +//! The dock's own content: the Sources/Clip tab pair and what each shows +//! (DESIGN.md §5, §12 step 4). `stance.rs::dock()` owns the panel's frame +//! (width, surfaces, border); this module owns what fills it. + +use crate::*; + +/// corner-cut: which dock tab is showing lives in a module-level flag rather +/// than a `Player` field, because the stance's other regions (spine, screen, +/// time band) are being threaded onto `Player` by a second builder in this +/// same pass and a shared struct is not a safe place for two agents to land +/// fields at once. Ceiling: fold into a `Player::dock_tab` field once that +/// pass lands, so DESIGN §5's "a room reopens exactly as left ... dock tab" +/// continuity (session save/load) can reach it -- today the flag resets with +/// the process. +static DOCK_SRC_ACTIVE: AtomicBool = AtomicBool::new(true); + +/// A ghost verb (DESIGN §4): borderless glyph/label in `ink2`, its chord in +/// `ink3` beside it, read live off the keymap so it can never drift from the +/// key that does the same thing. Hover is one fill step and an ink brighten; +/// held open (`active`) keeps both. A refused verb dims and says why on +/// hover instead of disappearing (§8). +fn ghost_verb( + id: &'static str, + label: &'static str, + action: ActionId, + active: bool, + hint: &str, + player: &Player, + on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, +) -> impl IntoElement { + let enabled = player.enable(action, None); + let key = player.keymap.display(action); + let say: SharedString = match enabled.why() { + Some(why) => format!("{key} — {why}"), + None => format!("{key} — {hint}"), + } + .into(); + let on = enabled.yes(); + div() + .id(id) + .flex_none() + .flex() + .items_center() + .justify_between() + .h(px(CONTROL_H)) + .px(px(8.)) + .rounded(px(3.)) + .when(active, |d| d.bg(rgb(DARK_RAISED()))) + .text_color(rgb(if active { INK1() } else { INK2() })) + .tooltip(move |_, cx| cx.new(|_| Tip(say.clone())).into()) + .when(!on, |d| d.opacity(0.4).cursor_not_allowed()) + .when(on, |d| { + d.cursor_pointer() + .hover(|s| s.bg(rgb(DARK_RAISED())).text_color(rgb(INK1()))) + .on_click(on_click) + }) + .child(label) + .child( + div() + .flex_none() + .text_size(px(9.5)) + .text_color(rgb(if active { INK1() } else { INK3() })) + .child(key), + ) +} + +/// One tab glyph of the Src/Clip pair: a plate (2px radius per §4), `ink1` + +/// `raised` fill when it is the showing tab, `ink2` at rest. +fn dock_tab(id: &'static str, label: &'static str, active: bool, cx: &mut Context) -> impl IntoElement { + div() + .id(id) + .flex_1() + .flex() + .items_center() + .justify_center() + .rounded(px(2.)) + .py(px(6.)) + .text_size(px(10.5)) + .text_color(rgb(if active { INK1() } else { INK2() })) + .when(active, |d| d.bg(rgb(DARK_RAISED()))) + .cursor_pointer() + .hover(|s| s.bg(rgb(DARK_RAISED()))) + .on_click(cx.listener(move |_this, _: &ClickEvent, _, cx| { + DOCK_SRC_ACTIVE.store(label == "Src", Ordering::Relaxed); + cx.notify(); + })) + .child(label) +} + +/// The Sources tab: [`Player::library`] verbatim -- filter tabs, usage +/// (proxy/preview) chips, Import, drag, Add at playhead -- restyled for free, +/// because its rows already paint through the theme tokens `library.rs` +/// shares with this stance (`BG_PANEL` etc. alias to the Darkroom substrate +/// under `PaletteId::Darkroom`). No ink/re-inking control lives in it (DESIGN +/// §2's demotion rule): `library.rs` never put one on a row to begin with, so +/// there is nothing here to strip. +fn sources_tab(player: &Player, width: f32, cx: &mut Context) -> impl IntoElement { + player.library(width, cx) +} + +/// The Clip tab: the four verbs DESIGN §5 names, as ghosts, over whichever +/// param-row card they open -- [`Player::eq_card`], [`Player::color_card`], +/// [`Player::transform_card`], [`Player::speed_card`] verbatim, the same +/// param-row rendering `inspector.rs`'s selection section already opens +/// these onto. Drag-while-playing and every other gesture on a row is +/// whatever that card already does; nothing about the gesture is reimplemented +/// here. +fn clip_tab(player: &Player, width: f32, window_h: Pixels, cx: &mut Context) -> impl IntoElement { + let room = size(px(width), window_h); + let none_open = player.eq_open.is_none() + && player.color_open.is_none() + && player.transform_open.is_none() + && player.speed_open.is_none(); + div() + .id("dock-clip") + .flex_1() + .min_h(px(0.)) + .flex() + .flex_col() + .overflow_y_scroll() + .child( + div() + .id("dock-clip-verbs") + .flex_none() + .flex() + .flex_col() + .gap(px(2.)) + .p(px(8.)) + .child(ghost_verb( + "dock-verb-speed", + "Speed", + ActionId::Speed, + player.speed_open.is_some(), + "how fast this clip and its group play", + player, + cx.listener(|this, _: &ClickEvent, _, cx| this.open_speed(cx)), + )) + .child(ghost_verb( + "dock-verb-color", + "Colour", + ActionId::Color, + player.color_open.is_some(), + "exposure, contrast, saturation and temperature", + player, + cx.listener(|this, _: &ClickEvent, _, cx| this.open_color(cx)), + )) + .child(ghost_verb( + "dock-verb-transform", + "Transform", + ActionId::Transform, + player.transform_open.is_some(), + "position, scale, rotation and crop for this clip", + player, + cx.listener(|this, _: &ClickEvent, _, cx| this.open_transform(cx)), + )) + .child(ghost_verb( + "dock-verb-eq", + "EQ", + ActionId::Equalizer, + player.eq_open.is_some(), + "the bands this clip's sound is filtered through", + player, + cx.listener(|this, _: &ClickEvent, _, cx| this.open_eq(cx)), + )), + ) + .child( + div() + .id("dock-clip-rows") + .flex_1() + .min_h(px(0.)) + .px(px(8.)) + .pb(px(8.)) + .children(player.eq_card(room, cx)) + .children(player.color_card(cx)) + .children(player.transform_card(cx)) + .children(player.speed_card(cx)) + // A plate, not bare space: DESIGN §11's "states" checklist -- + // nothing picked reads as a hint, not as a hole in the panel. + .when(none_open, |d| { + d.child( + div() + .rounded(px(2.)) + .bg(rgb(DARK_CANVAS())) + .p(px(8.)) + .text_size(px(10.5)) + .text_color(rgb(INK3())) + .child("pick a verb above"), + ) + }), + ) +} + +/// The dock's content, under `stance.rs::dock()`'s tab-bar-and-body frame: +/// the tab row, then whichever tab is showing. +/// +/// Degradation (DESIGN §7): the dock is a fixed-width side panel, not a lane +/// bed, so it has no width ladder of its own to walk -- the panel is either +/// on screen at its one width or, at the narrowest floors this editor draws +/// to, is the first region asked to give up its width entirely (a step +/// `layout.rs`'s split budget already owns for the legacy inspector/library +/// pair). What degrades *inside* fixed width is the two tabs' own content: +/// Sources hands off to `library.rs`'s own row anatomy and ladder; Clip's +/// param rows are whatever their card already draws at this width. +pub(crate) fn render(player: &Player, width: f32, window_h: Pixels, cx: &mut Context) -> impl IntoElement { + let src_active = DOCK_SRC_ACTIVE.load(Ordering::Relaxed); + div() + .id("stance-dock-body") + .flex_1() + .min_h(px(0.)) + .flex() + .flex_col() + .child( + div() + .id("stance-dock-tabs") + .flex_none() + .flex() + .gap(px(4.)) + .p(px(8.)) + .border_b_1() + .border_color(rgb(DARK_HAIRLINE())) + .child(dock_tab("dock-tab-src", "Src", src_active, cx)) + .child(dock_tab("dock-tab-clip", "Clip", !src_active, cx)), + ) + .child(match src_active { + true => sources_tab(player, width, cx).into_any_element(), + false => clip_tab(player, width, window_h, cx).into_any_element(), + }) +} diff --git a/crates/app/src/ui/mod.rs b/crates/app/src/ui/mod.rs index cb76298..38ebf22 100644 --- a/crates/app/src/ui/mod.rs +++ b/crates/app/src/ui/mod.rs @@ -4,6 +4,7 @@ //! which is why a colour or a rule fixed in one place kept surviving in the //! next: there was no seam to sweep. The seams are the regions themselves. pub mod cards; +pub mod dock_stance; pub mod inspector; pub mod library; pub mod overlays; diff --git a/crates/app/src/ui/preview.rs b/crates/app/src/ui/preview.rs index 1e0677a..260a6d2 100644 --- a/crates/app/src/ui/preview.rs +++ b/crates/app/src/ui/preview.rs @@ -310,6 +310,92 @@ impl Player { } } + /// Two-up OUT|IN judging (DESIGN.md §6): drawn over the screen only when + /// the playhead rests exactly on one edge of the subject cut -- the + /// outgoing clip's tail beside the incoming one's head, whichever edge + /// the playhead is on. `None` off a cut, off the darkroom path, or with + /// nothing marked, so the legacy picture and a mid-clip darkroom picture + /// both draw untouched. + /// + /// corner-cut: each side names its neighbour (source, timecode) on a + /// plate rather than decoding its edge frame into a second picture -- + /// the pixel-accurate two-up wants a frame read off the *other* clip's + /// span while the shown picture is the marked one's, which is a second + /// decode this step does not open. Upgrade path: a still pulled from the + /// neighbour's edge frame ([`engine::PlaybackSession::video_source_frame_at`] + /// is the same lookup [`Player::live_decode`] already makes) in place of + /// the plate's text. + pub(crate) fn two_up(&self) -> Option { + if !self.darkroom { + return None; + } + let (lane, idx) = self.selected.anchor()?; + let session = self.session.as_ref()?; + let clips = session.lane_clips(lane); + let clip = clips.get(idx)?; + let now = frame_at(session.now(), self.fps); + let name_of = |source: usize| { + session + .sources() + .get(source) + .map_or_else(|| "?".to_string(), |s| file_name(&s.path)) + }; + // Which edge, if either, the playhead is resting on -- the one + // question "at rest on a cut" is. + let (out_label, in_label) = if now == clip.start { + let out = idx + .checked_sub(1) + .and_then(|i| clips.get(i)) + .map_or("— nothing before it".to_string(), |c| { + format!("{} @{}", name_of(c.source), c.end()) + }); + (out, format!("{} @{}", name_of(clip.source), clip.start)) + } else if now == clip.end() { + let inn = clips + .get(idx + 1) + .map_or("— nothing after it".to_string(), |c| { + format!("{} @{}", name_of(c.source), c.start) + }); + (format!("{} @{}", name_of(clip.source), clip.end()), inn) + } else { + return None; + }; + let plate = |label: &str, text: String| { + div() + .flex_1() + .flex() + .flex_col() + .gap(px(4.)) + .p(px(8.)) + .bg(rgb(DARK_CANVAS())) + .rounded(px(2.)) + .child( + div() + .text_size(px(9.)) + .text_color(rgb(INK3())) + .child(label.to_string()), + ) + .child( + div() + .text_size(px(10.5)) + .text_color(rgb(INK1())) + .child(text), + ) + }; + Some( + div() + .absolute() + .bottom_0() + .left_0() + .right_0() + .flex() + .gap(px(1.)) + .p(px(8.)) + .child(plate("OUT", out_label)) + .child(plate("IN", in_label)), + ) + } + /// What is decoding the picture right now, for the transport line: the /// backend is the running worker's own (it is written where a hardware /// session falls back to software, so this follows reality), and the codec diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 0951b29..906d303 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -8,6 +8,7 @@ //! later steps in DESIGN §12's package attach. use crate::*; +use crate::ui::dock_stance; /// Left rail, full height (DESIGN §5). const SPINE_W: f32 = 56.; @@ -33,9 +34,34 @@ fn section_head(label: &str) -> impl IntoElement { .child(label.to_uppercase()) } -/// The spine: 56px, left, full height. Every command as ghost glyph + chord -/// lands here later, grouped by task frequency (DESIGN §5). -fn spine() -> impl IntoElement { +/// A ghost command (DESIGN §4): borderless glyph (`ink2`) + dim chord +/// (`ink3`), read live off the keymap so a rebind can never leave the spine +/// showing a stroke that no longer fires it. +fn ghost(player: &Player, glyph: &str, action: ActionId) -> impl IntoElement { + div() + .flex_none() + .flex() + .flex_col() + .items_center() + .gap(px(2.)) + .py(px(6.)) + .rounded(px(3.)) + .text_size(px(13.)) + .text_color(rgb(INK2())) + .child(glyph.to_string()) + .child( + div() + .text_size(px(9.5)) + .text_color(rgb(INK3())) + .child(player.keymap.display(action)), + ) +} + +/// The spine: 56px, left, full height. Every command as ghost glyph + chord, +/// grouped by task frequency (DESIGN §5) -- transport first (every second), +/// then the cut machinery (DESIGN §6, every cut), then the split and the one +/// boxed exception is left to the time band, which is where Export lives. +fn spine(player: &Player) -> impl IntoElement { div() .id("stance-spine") .flex_none() @@ -48,30 +74,53 @@ fn spine() -> impl IntoElement { .flex_col() .items_center() .py(px(8.)) + .gap(px(4.)) .child(section_head("spine")) - // hook: §12 step 3 -- ghost glyph + chord per command, task-frequency order. + .child(ghost(player, "▶", ActionId::Play)) + .child(ghost(player, "‹", ActionId::WalkCutPrev)) + .child(ghost(player, "›", ActionId::WalkCutNext)) + .child(ghost(player, "[", ActionId::TrimIn)) + .child(ghost(player, "]", ActionId::TrimOut)) + .child(ghost(player, "↻", ActionId::LoopTrim)) + .child(ghost(player, "✂", ActionId::Cut)) } /// The picture region: top of the centre column, takes the remaining space, -/// never occluded (DESIGN §5). -fn screen() -> impl IntoElement { +/// never occluded (DESIGN §5). Reuses [`Player::picture_area`] rather than a +/// second image element -- the darkroom draws the same picture the legacy +/// tree does -- and layers the two-up OUT|IN judging over it at rest on a +/// cut (DESIGN §6). +fn screen(player: &mut Player, position: f64, window: &mut Window, cx: &mut Context) -> impl IntoElement { div() .id("stance-screen") .flex_1() .min_h(px(0.)) + .relative() // §4: room chrome takes 0 radius. .rounded(px(0.)) .bg(rgb(DARK_CANVAS())) - .flex() - .items_center() - .justify_center() - .child(section_head("screen")) - // hook: §12 step 3 -- the picture, and two-up OUT|IN judging at rest on a cut. + .child(player.picture_area(position, window, cx)) + .children(player.two_up()) } /// Fixed-height strip under the screen: timecode leads, ghost transport, cut /// readout, the contact strip, boxed Export at the end (DESIGN §5). -fn time_band() -> impl IntoElement { +fn time_band(player: &Player) -> impl IntoElement { + let position = player.active_session().map_or(0., PlaybackSession::now); + let tc = timecode(position, player.active_fps()); + // The odometer (DESIGN §6): the subject cut's own place among its + // lane's, or an empty readout with nothing marked -- a plate that reads + // blank rather than one that lies about a cut zero. + let readout = player + .selected + .anchor() + .and_then(|(lane, idx)| { + player + .session + .as_ref() + .map(|s| format!("{}/{}", idx + 1, s.lane_clips(lane).len())) + }) + .unwrap_or_else(|| "—/—".to_string()); div() .id("stance-time-band") .flex_none() @@ -81,9 +130,46 @@ fn time_band() -> impl IntoElement { .border_color(rgb(DARK_SEAM())) .flex() .items_center() + .gap(px(16.)) .px(px(12.)) - .child(section_head("time band")) - // hook: §12 step 3 -- timecode, ghost transport, cut readout, contact strip, Export. + // The most-read element anchors its region (DESIGN §5): the + // timecode leads, 13px hero, 700, colons in `ink3`. + .child( + div() + .text_size(px(13.)) + .text_color(rgb(INK1())) + .child(tc), + ) + .child(ghost(player, if player.transport().is_playing() { "❚❚" } else { "▶" }, ActionId::Play)) + // The cut readout: a plate, mono, the odometer DESIGN §6 asks for. + .child( + div() + .flex_none() + .px(px(8.)) + .py(px(4.)) + .rounded(px(2.)) + .bg(rgb(DARK_CANVAS())) + .text_size(px(10.5)) + .text_color(rgb(INK1())) + .child(readout), + ) + .child(div().flex_1()) + // Boxed Export: the one bordered control on the surface (DESIGN §4). + .child( + div() + .id("stance-export") + .flex_none() + .px(px(10.)) + .py(px(6.)) + .rounded(px(3.)) + .border_1() + .border_color(rgb(DARK_HAIRLINE())) + .bg(rgb(DARK_RAISED())) + .text_size(px(10.5)) + .text_color(rgb(INK1())) + .cursor_pointer() + .child(format!("Export ({})", player.keymap.display(ActionId::Export))), + ) } /// Lanes, under the time band. `canvas` is the bench background too (DESIGN @@ -122,22 +208,10 @@ fn ledger() -> impl IntoElement { // hook: §12 step 7 -- project identity/state, last action, export progress, notices. } -/// One tab of the dock's Src/Clip pair -- a plate (2px radius), `ink1` when -/// active and `ink2` at rest, never a hue (DESIGN §4). -fn dock_tab(label: &str, active: bool) -> impl IntoElement { - div() - .flex_1() - .rounded(px(2.)) - .py(px(6.)) - .text_size(px(10.5)) - .text_color(rgb(if active { INK1() } else { INK2() })) - .bg(rgb(if active { DARK_RAISED() } else { DARK_PANEL() })) - .child(label.to_string()) -} - /// The dock: the only side panel, right, fixed width, carrying the Src/Clip -/// tab pair (DESIGN §5). -fn dock() -> impl IntoElement { +/// tab pair (DESIGN §5). The frame is drawn here; `dock_stance.rs` owns the +/// tab row and both tabs' content (DESIGN §12 step 4). +fn dock(player: &Player, window_h: Pixels, cx: &mut Context) -> impl IntoElement { div() .id("stance-dock") .flex_none() @@ -148,38 +222,43 @@ fn dock() -> impl IntoElement { .border_color(rgb(DARK_SEAM())) .flex() .flex_col() - .child( - div() - .id("stance-dock-tabs") - .flex_none() - .flex() - .gap(px(4.)) - .p(px(8.)) - .border_b_1() - .border_color(rgb(DARK_HAIRLINE())) - .child(dock_tab("Src", true)) - .child(dock_tab("Clip", false)), - ) - .child(section_head("dock")) - // hook: §12 step 4 -- Sources assembly (filter, usage chips, import) / Clip verbs - // (Speed / Colour / Transform / EQ as ghost verbs over param rows). + .child(dock_stance::render(player, DOCK_W, window_h, cx)) } /// The whole stance: spine, screen, time band, bench, ledger, dock, in the -/// order DESIGN §5 draws them. `player` and the window/context pair are -/// unread by this skeleton -- later steps in the §12 package are what fill -/// each region from live state (cut position, dock tab, lane contents). +/// order DESIGN §5 draws them, over the same key handler the legacy tree +/// uses (DESIGN §12 step 3): the darkroom draws its own regions but answers +/// to the one keymap, `shift` threaded through for the odometer's stride +/// ([`Player::walk_shift`]) since [`ActionId`] carries no modifier of its +/// own. pub(crate) fn render( - _player: &mut Player, - _window: &mut Window, - _cx: &mut Context, + player: &mut Player, + window: &mut Window, + cx: &mut Context, ) -> impl IntoElement { + let window_h = window.viewport_size().height; + let position = player.playhead(player.drawn_duration()); div() .id("stance-room") + .track_focus(&player.focus) + .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| { + let key = event.keystroke.key.as_str(); + let ctrl = event.keystroke.modifiers.control; + if event.is_held && !repeats(this.repeat_scope(), key, this.keymap.lookup(key, ctrl)) { + return; + } + if this.dismiss_notice() { + cx.notify(); + } + this.walk_shift = event.keystroke.modifiers.shift; + if let Some(action) = this.keymap.lookup(key, ctrl) { + this.act(action, window, cx); + } + })) .size_full() .flex() .bg(rgb(DARK_CANVAS())) - .child(spine()) + .child(spine(player)) .child( div() .id("stance-centre") @@ -187,10 +266,10 @@ pub(crate) fn render( .min_w(px(0.)) .flex() .flex_col() - .child(screen()) - .child(time_band()) + .child(screen(player, position, window, cx)) + .child(time_band(player)) .child(bench()) .child(ledger()), ) - .child(dock()) + .child(dock(player, window_h, cx)) }