The bench grows lanes so the cut has something to cut
Browse files at this commitde91645012a06aaf00e809b70cbe7646630b8dfdParent: 9e2bfd6- feat
- the bench grows lanes so the cut has something to cut
3 changed files +376 -8
- crates/app/src/ui/bench_stance.rs +363 -0
- crates/app/src/ui/mod.rs +1 -0
- crates/app/src/ui/stance.rs +12 -8
crates/app/src/ui/bench_stance.rsadded+363 -0
| @@ -0,0 +1,363 @@ | ||
| 1 | +//! The bench's own content: lanes, ruler and clips (DESIGN.md §5's clip | |
| 2 | +//! anatomy, §7's degradation ladder). `stance.rs::bench()` owns the frame | |
| 3 | +//! (height, surfaces, section head); this module owns what fills it, the way | |
| 4 | +//! `dock_stance.rs` owns the dock's content next to `stance.rs::dock()`'s | |
| 5 | +//! frame. | |
| 6 | +//! | |
| 7 | +//! Reused rather than reimplemented (`ui/timeline.rs` already shipped this | |
| 8 | +//! plumbing on the legacy timeline): `Player::insert_source` and the | |
| 9 | +//! `AssetDrag` payload for add-at-playhead and drag-drop from the Sources | |
| 10 | +//! tab, `Player::pick`/`Player::marks`/`marked` for selection, and | |
| 11 | +//! `Player::nudge_cut`/`walk_cut`/`cut`/`toggle_loop_trim` (DESIGN §6, wired | |
| 12 | +//! in `player/actions.rs` already, and answered to by every keystroke the | |
| 13 | +//! stance's own key handler forwards) for the whole cut grammar -- none of | |
| 14 | +//! that is touched here, because a clip's `start`/`frames()` already reflect | |
| 15 | +//! a commit the moment the keymap makes one (`nudge_cut` writes straight to | |
| 16 | +//! the session), so this module reads the session straight, needing no live | |
| 17 | +//! drag-preview state to mirror it. New here: the clip anatomy (ink spine, | |
| 18 | +//! trace, name plate, splice gaps) and the width ladder that degrades it | |
| 19 | +//! (DESIGN §7) -- neither existed on the legacy timeline in this shape. | |
| 20 | +//! | |
| 21 | +//! Not reused, deferred: `ClipDrag` (moving a placed clip to another lane by | |
| 22 | +//! hand), the mouse edge-trim strips, fades/dissolve glyphs and the lane | |
| 23 | +//! header reorder drag. The cut grammar (`,` `.` `[` `]` `/` `s`) never needs | |
| 24 | +//! any of them -- `nudge_cut` and friends act on `Player::selected` directly, | |
| 25 | +//! with no element under the pointer required -- so they are out of this | |
| 26 | +//! slice's reach; `Player::pick` (click-select) and the asset drop (place) | |
| 27 | +//! are the two pointer gestures the charter actually asked this surface to | |
| 28 | +//! answer for. | |
| 29 | + | |
| 30 | +use crate::*; | |
| 31 | +use crate::ui::widgets::waveform; | |
| 32 | + | |
| 33 | +/// The pinned ruler's own height, above the lane stack. | |
| 34 | +const RULER_H: f32 = 10.; | |
| 35 | +/// The pinned track-head column, DESIGN §5's "track heads" -- narrower than | |
| 36 | +/// the legacy timeline's `HEADER_W` since a darkroom lane carries no mix/eye | |
| 37 | +/// button yet (deferred with the rest of the header's verbs). | |
| 38 | +const HEAD_W: f32 = 28.; | |
| 39 | +const ROW_GAP: f32 = 2.; | |
| 40 | +/// DESIGN §7: lanes compress evenly up to this many rows before the column | |
| 41 | +/// scrolls behind the pinned ruler and heads instead of compressing further. | |
| 42 | +const LANES_COMPRESS: usize = 5; | |
| 43 | +const LANE_FULL_H: f32 = 40.; | |
| 44 | +const LANE_MIN_H: f32 = 18.; | |
| 45 | + | |
| 46 | +/// One clip's degradation tier (DESIGN §7), picked off the clip's own worth | |
| 47 | +/// in pixels (`span`, unclamped) rather than its drawn floor | |
| 48 | +/// ([`clip_width`]'s `HIT_MIN`) -- a clip zoomed far out is worth a fraction | |
| 49 | +/// of a pixel long before its box stops shrinking, and the ladder has to see | |
| 50 | +/// that or "sliver" would never fire under the floor that keeps it clickable. | |
| 51 | +#[derive(Clone, Copy, PartialEq)] | |
| 52 | +enum Tier { | |
| 53 | + /// Trace + name plate + speed chip. | |
| 54 | + Full, | |
| 55 | + /// Trace + name plate. | |
| 56 | + NoChip, | |
| 57 | + /// Trace only -- DESIGN §7's explicit "<48px" boundary. | |
| 58 | + NoLabel, | |
| 59 | + /// Spine + trace only, thinned. | |
| 60 | + SpineTrace, | |
| 61 | + /// Sliver fill + splice gaps: film scale. | |
| 62 | + Sliver, | |
| 63 | +} | |
| 64 | + | |
| 65 | +fn tier(span: f32) -> Tier { | |
| 66 | + match span { | |
| 67 | + s if s >= 120. => Tier::Full, | |
| 68 | + s if s >= 48. => Tier::NoChip, | |
| 69 | + s if s >= 24. => Tier::NoLabel, | |
| 70 | + s if s >= 10. => Tier::SpineTrace, | |
| 71 | + _ => Tier::Sliver, | |
| 72 | + } | |
| 73 | +} | |
| 74 | + | |
| 75 | +/// The lane stack's own height budget, split evenly across up to | |
| 76 | +/// [`LANES_COMPRESS`] rows before the column scrolls instead (DESIGN §7). | |
| 77 | +fn row_h(lanes: usize, box_h: f32) -> f32 { | |
| 78 | + let n = lanes.clamp(1, LANES_COMPRESS) as f32; | |
| 79 | + ((box_h - (n - 1.) * ROW_GAP) / n).clamp(LANE_MIN_H, LANE_FULL_H) | |
| 80 | +} | |
| 81 | + | |
| 82 | +/// A clip's ink spine + body, degrading by [`Tier`] (DESIGN §5, §7). A single | |
| 83 | +/// placeholder ink stands in for every source until real extraction lands. | |
| 84 | +/// | |
| 85 | +/// hook: §12 step 5 -- per-source film ink attaches here, replacing | |
| 86 | +/// `INK2()` with the source's own quantized hue. | |
| 87 | +fn clip_box( | |
| 88 | + player: &Player, | |
| 89 | + lane: Lane, | |
| 90 | + idx: usize, | |
| 91 | + clip: &Clip, | |
| 92 | + scale: Scale, | |
| 93 | + picks: &[(Lane, usize)], | |
| 94 | + pick_links: &[Option<u32>], | |
| 95 | + cx: &mut Context<Player>, | |
| 96 | +) -> impl IntoElement + use<> { | |
| 97 | + let (start, len) = ( | |
| 98 | + f64::from(clip.start) / player.fps, | |
| 99 | + f64::from(clip.frames()) / player.fps, | |
| 100 | + ); | |
| 101 | + let span = scale.width_px(len); | |
| 102 | + let width = clip_width(span); | |
| 103 | + let left = scale.px_at(start); | |
| 104 | + let on = marked((lane, idx), clip.link, picks, pick_links); | |
| 105 | + let t = tier(span); | |
| 106 | + let label = player.sources().get(clip.source).map(|s| file_name(&s.path)); | |
| 107 | + let audio = lane.kind == LaneKind::Audio; | |
| 108 | + let wave = player | |
| 109 | + .sources() | |
| 110 | + .get(clip.source) | |
| 111 | + .and_then(|s| player.waves.get(&(s.path.clone(), s.audio_stream))) | |
| 112 | + .cloned(); | |
| 113 | + let has_trace = t != Tier::Sliver; | |
| 114 | + let has_spine = t != Tier::Sliver; | |
| 115 | + let has_label = matches!(t, Tier::Full | Tier::NoChip); | |
| 116 | + let has_chip = t == Tier::Full && !clip.speed.is_normal(); | |
| 117 | + let (in_frame, out_frame) = (f64::from(clip.in_frame) / player.fps, f64::from(clip.out_frame) / player.fps); | |
| 118 | + let speed = clip.speed; | |
| 119 | + div() | |
| 120 | + .id(("bench-clip", lane.ord * 1000 + lane.kind as usize * 100 + idx)) | |
| 121 | + .absolute() | |
| 122 | + .top_0() | |
| 123 | + .h_full() | |
| 124 | + .left(px(left)) | |
| 125 | + .w(px(width)) | |
| 126 | + .overflow_hidden() | |
| 127 | + .rounded(px(0.)) | |
| 128 | + .bg(rgb(DARK_PANEL())) | |
| 129 | + // Focus/selection ring, 1px `ink1`, lamp-adjacent and never coloured | |
| 130 | + // (DESIGN §4). | |
| 131 | + .when(on, |d| d.border_1().border_color(rgb(INK1()))) | |
| 132 | + .cursor_pointer() | |
| 133 | + // Selection: reuses `Player::pick`, the same call the legacy | |
| 134 | + // timeline's clip box makes. | |
| 135 | + .on_mouse_down( | |
| 136 | + MouseButton::Left, | |
| 137 | + cx.listener(move |this, event: &MouseDownEvent, _, cx| { | |
| 138 | + this.pick((lane, idx), event.modifiers.control, cx); | |
| 139 | + }), | |
| 140 | + ) | |
| 141 | + // Ink spine: 3px left edge, the placeholder ink until §12 step 5. | |
| 142 | + .when(has_spine, |d| { | |
| 143 | + d.child( | |
| 144 | + div() | |
| 145 | + .absolute() | |
| 146 | + .left_0() | |
| 147 | + .top_0() | |
| 148 | + .h_full() | |
| 149 | + .w(px(3.)) | |
| 150 | + .bg(rgb(INK2())), | |
| 151 | + ) | |
| 152 | + }) | |
| 153 | + // Trace: real waveform for audio, a flat placeholder body for video | |
| 154 | + // (thumbnails are §12 step 5's, same hook). | |
| 155 | + .when(has_trace && audio, |d| { | |
| 156 | + d.children(wave.and_then(|w| match w { | |
| 157 | + Wave::Peaks(peaks) => Some( | |
| 158 | + div() | |
| 159 | + .absolute() | |
| 160 | + .left(px(3.)) | |
| 161 | + .right_0() | |
| 162 | + .top_0() | |
| 163 | + .bottom_0() | |
| 164 | + .child(waveform(peaks, in_frame, out_frame)), | |
| 165 | + ), | |
| 166 | + _ => None, | |
| 167 | + })) | |
| 168 | + }) | |
| 169 | + .when(has_trace && !audio, |d| { | |
| 170 | + d.child( | |
| 171 | + div() | |
| 172 | + .absolute() | |
| 173 | + .left(px(3.)) | |
| 174 | + .right_0() | |
| 175 | + .top(px(2.)) | |
| 176 | + .bottom(px(2.)) | |
| 177 | + .bg(rgb(INK4())), | |
| 178 | + ) | |
| 179 | + }) | |
| 180 | + // Name plate: DESIGN §4's plate (canvas-on-panel), mono label. | |
| 181 | + .when_some(label.filter(|_| has_label), |d, label| { | |
| 182 | + d.child( | |
| 183 | + div() | |
| 184 | + .absolute() | |
| 185 | + .left(px(3.)) | |
| 186 | + .right_0() | |
| 187 | + .bottom_0() | |
| 188 | + .h(px(13.)) | |
| 189 | + .px(px(3.)) | |
| 190 | + .bg(rgba(DARK_SEAM())) | |
| 191 | + .truncate() | |
| 192 | + .text_size(px(9.5)) | |
| 193 | + .text_color(rgb(INK1())) | |
| 194 | + .child(label), | |
| 195 | + ) | |
| 196 | + }) | |
| 197 | + // Speed chip: dropped first in the ladder. | |
| 198 | + .when(has_chip, |d| { | |
| 199 | + d.child( | |
| 200 | + div() | |
| 201 | + .absolute() | |
| 202 | + .top_0() | |
| 203 | + .right_0() | |
| 204 | + .px(px(3.)) | |
| 205 | + .bg(rgb(DARK_RAISED())) | |
| 206 | + .text_size(px(9.)) | |
| 207 | + .text_color(rgb(INK2())) | |
| 208 | + .child(format!("{speed}")), | |
| 209 | + ) | |
| 210 | + }) | |
| 211 | + // Splice gap: the lamp-white sliver at every clip's trailing edge -- | |
| 212 | + // DESIGN §1 law 3's other legal white, present at every tier (a | |
| 213 | + // sliver at film scale is spine gone too, so the splice is what is | |
| 214 | + // left to read). | |
| 215 | + .child( | |
| 216 | + div() | |
| 217 | + .absolute() | |
| 218 | + .top_0() | |
| 219 | + .right_0() | |
| 220 | + .h_full() | |
| 221 | + .w(px(1.)) | |
| 222 | + .bg(rgb(LAMP_WHITE())), | |
| 223 | + ) | |
| 224 | +} | |
| 225 | + | |
| 226 | +/// One lane row: pinned head + bed of clips, DESIGN §5's "lanes V/A/S", drawn | |
| 227 | +/// at the compressed height [`row_h`] gives it. | |
| 228 | +fn lane_row( | |
| 229 | + player: &Player, | |
| 230 | + lane: Lane, | |
| 231 | + h: f32, | |
| 232 | + scale: Scale, | |
| 233 | + picks: &[(Lane, usize)], | |
| 234 | + pick_links: &[Option<u32>], | |
| 235 | + cx: &mut Context<Player>, | |
| 236 | +) -> impl IntoElement + use<> { | |
| 237 | + let clips: Vec<Clip> = player | |
| 238 | + .session | |
| 239 | + .as_ref() | |
| 240 | + .map_or(&[][..], |s| s.lane_clips(lane)) | |
| 241 | + .to_vec(); | |
| 242 | + let boxes: Vec<_> = clips | |
| 243 | + .iter() | |
| 244 | + .enumerate() | |
| 245 | + .map(|(idx, clip)| clip_box(player, lane, idx, clip, scale, picks, pick_links, cx)) | |
| 246 | + .collect(); | |
| 247 | + div() | |
| 248 | + .id(("bench-lane", lane.ord * 10 + lane.kind as usize)) | |
| 249 | + .flex_none() | |
| 250 | + .h(px(h)) | |
| 251 | + .flex() | |
| 252 | + .child( | |
| 253 | + // Pinned track head. | |
| 254 | + div() | |
| 255 | + .flex_none() | |
| 256 | + .w(px(HEAD_W)) | |
| 257 | + .h_full() | |
| 258 | + .flex() | |
| 259 | + .items_center() | |
| 260 | + .justify_center() | |
| 261 | + .bg(rgb(DARK_PANEL())) | |
| 262 | + .text_size(px(9.5)) | |
| 263 | + .text_color(rgb(INK2())) | |
| 264 | + .child(lane.label()), | |
| 265 | + ) | |
| 266 | + .child( | |
| 267 | + // The bed: a drop target for the Sources tab (`AssetDrag`, | |
| 268 | + // reused from `ui/timeline.rs`) and every clip on it. | |
| 269 | + div() | |
| 270 | + .id(("bench-bed", lane.ord * 10 + lane.kind as usize)) | |
| 271 | + .relative() | |
| 272 | + .flex_1() | |
| 273 | + .min_w(px(0.)) | |
| 274 | + .h_full() | |
| 275 | + .bg(rgb(DARK_CANVAS())) | |
| 276 | + .border_l_1() | |
| 277 | + .border_color(rgba(DARK_SEAM())) | |
| 278 | + .drag_over::<AssetDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | |
| 279 | + .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { | |
| 280 | + let at = this.place_frame(window.mouse_position().x).0; | |
| 281 | + this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) | |
| 282 | + })) | |
| 283 | + .children(boxes), | |
| 284 | + ) | |
| 285 | +} | |
| 286 | + | |
| 287 | +/// The bench's content: pinned ruler, pinned heads, lane stack -- compressed | |
| 288 | +/// evenly to [`LANES_COMPRESS`] rows and then scrolling (DESIGN §7). | |
| 289 | +pub(crate) fn render(player: &mut Player, box_h: f32, cx: &mut Context<Player>) -> impl IntoElement { | |
| 290 | + let lanes = player | |
| 291 | + .session | |
| 292 | + .as_ref() | |
| 293 | + .map_or_else(|| vec![Lane::V1, Lane::A1], PlaybackSession::lanes); | |
| 294 | + let position = player.active_session().map_or(0., PlaybackSession::now); | |
| 295 | + let scale = player.scale; | |
| 296 | + let bed_w = f32::from(player.ruler.get().size.width).max(1.); | |
| 297 | + let filled = scale.px_at(position).clamp(0., bed_w); | |
| 298 | + let (picks, pick_links) = player.marks(); | |
| 299 | + let h = row_h(lanes.len(), (box_h - RULER_H - ROW_GAP).max(LANE_MIN_H)); | |
| 300 | + let mut rows = Vec::new(); | |
| 301 | + for &lane in &lanes { | |
| 302 | + rows.push(lane_row(player, lane, h, scale, &picks, &pick_links, cx)); | |
| 303 | + } | |
| 304 | + div() | |
| 305 | + .id("bench-content") | |
| 306 | + .flex_1() | |
| 307 | + .min_w(px(0.)) | |
| 308 | + .h_full() | |
| 309 | + .flex() | |
| 310 | + .flex_col() | |
| 311 | + .gap(px(ROW_GAP)) | |
| 312 | + .child( | |
| 313 | + // Pinned ruler: click/drag to seek (reuses `Player::scrub_to`, | |
| 314 | + // the same call the legacy ruler makes), the playhead's own | |
| 315 | + // lamp-white line (DESIGN §1 law 3 -- the only other legal use | |
| 316 | + // of pure white besides the splice). | |
| 317 | + div() | |
| 318 | + .id("bench-ruler") | |
| 319 | + .flex_none() | |
| 320 | + .h(px(RULER_H)) | |
| 321 | + .ml(px(HEAD_W)) | |
| 322 | + .relative() | |
| 323 | + .rounded(px(2.)) | |
| 324 | + .bg(rgb(DARK_HAIRLINE())) | |
| 325 | + .cursor_pointer() | |
| 326 | + .child(bounds_probe(player.ruler.clone())) | |
| 327 | + .on_mouse_down( | |
| 328 | + MouseButton::Left, | |
| 329 | + cx.listener(|this, event: &MouseDownEvent, _, cx| { | |
| 330 | + this.scrubbing = true; | |
| 331 | + this.scrub_to(event.position.x, true, cx); | |
| 332 | + }), | |
| 333 | + ) | |
| 334 | + .child( | |
| 335 | + div() | |
| 336 | + .h_full() | |
| 337 | + .w(px(filled)) | |
| 338 | + .rounded(px(2.)) | |
| 339 | + .bg(rgb(INK1())), | |
| 340 | + ) | |
| 341 | + .child( | |
| 342 | + div() | |
| 343 | + .absolute() | |
| 344 | + .top_0() | |
| 345 | + .h_full() | |
| 346 | + .left(px(filled)) | |
| 347 | + .w(px(1.)) | |
| 348 | + .bg(rgb(LAMP_WHITE())), | |
| 349 | + ), | |
| 350 | + ) | |
| 351 | + .child( | |
| 352 | + div() | |
| 353 | + .id("bench-lanes") | |
| 354 | + .flex_1() | |
| 355 | + .min_h(px(0.)) | |
| 356 | + .overflow_y_scroll() | |
| 357 | + .track_scroll(&player.lanes_scroll) | |
| 358 | + .flex() | |
| 359 | + .flex_col() | |
| 360 | + .gap(px(ROW_GAP)) | |
| 361 | + .children(rows), | |
| 362 | + ) | |
| 363 | +} |
crates/app/src/ui/mod.rsmodified+1 -0
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | //! The whole UI used to be one 19,916-line file with one `Render` impl in it, |
| 4 | 4 | //! which is why a colour or a rule fixed in one place kept surviving in the |
| 5 | 5 | //! next: there was no seam to sweep. The seams are the regions themselves. |
| 6 | +pub mod bench_stance; | |
| 6 | 7 | pub mod cards; |
| 7 | 8 | pub mod dock_stance; |
| 8 | 9 | pub mod inspector; |
crates/app/src/ui/stance.rsmodified+12 -8
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | //! later steps in DESIGN §12's package attach. |
| 9 | 9 | |
| 10 | 10 | use crate::*; |
| 11 | +use crate::ui::bench_stance; | |
| 11 | 12 | use crate::ui::dock_stance; |
| 12 | 13 | |
| 13 | 14 | /// Left rail, full height (DESIGN §5). |
| @@ -15,10 +16,12 @@ const SPINE_W: f32 = 56.; | ||
| 15 | 16 | /// Fixed strip under the screen: timecode, transport, cut readout, contact |
| 16 | 17 | /// strip, Export -- all placeholder at this step. |
| 17 | 18 | const TIME_BAND_H: f32 = 88.; |
| 18 | -/// corner-cut: the lane bed has no lanes to size itself against yet, so this | |
| 19 | -/// is a placeholder height rather than a measured one. Ceiling: replaced by | |
| 20 | -/// the real lane stack's own height once DESIGN §12 step 4 fills the bench. | |
| 21 | -const BENCH_H: f32 = 160.; | |
| 19 | +/// corner-cut: a fixed share of the window rather than one measured against | |
| 20 | +/// the picture's own room, matching the placeholder every other stance | |
| 21 | +/// region still carries at this step. Ceiling: fold into the same split the | |
| 22 | +/// legacy timeline's `Split::Timeline` answers once the stance grows a | |
| 23 | +/// resizable seam of its own. | |
| 24 | +const BENCH_H: f32 = 200.; | |
| 22 | 25 | /// Thin strip at the foot of the centre column. |
| 23 | 26 | const LEDGER_H: f32 = 28.; |
| 24 | 27 | /// Right side panel, fixed width, carrying the Src/Clip tab pair. |
| @@ -174,7 +177,7 @@ fn time_band(player: &Player) -> impl IntoElement { | ||
| 174 | 177 | |
| 175 | 178 | /// Lanes, under the time band. `canvas` is the bench background too (DESIGN |
| 176 | 179 | /// §2's token table), so it shares its surface with the screen above it. |
| 177 | -fn bench() -> impl IntoElement { | |
| 180 | +fn bench(player: &mut Player, cx: &mut Context<Player>) -> impl IntoElement { | |
| 178 | 181 | div() |
| 179 | 182 | .id("stance-bench") |
| 180 | 183 | .flex_none() |
| @@ -185,10 +188,11 @@ fn bench() -> impl IntoElement { | ||
| 185 | 188 | .border_t_1() |
| 186 | 189 | .border_color(rgba(DARK_SEAM())) |
| 187 | 190 | .flex() |
| 188 | - .items_center() | |
| 191 | + .flex_col() | |
| 189 | 192 | .px(px(12.)) |
| 193 | + .py(px(4.)) | |
| 190 | 194 | .child(section_head("bench")) |
| 191 | - // hook: §12 step 4 -- lanes V/A/S; ink spine + thumbnails/waveform + name plate + splice gaps. | |
| 195 | + .child(bench_stance::render(player, BENCH_H - 20., cx)) | |
| 192 | 196 | } |
| 193 | 197 | |
| 194 | 198 | /// Thin strip at the bottom of the centre column: project identity, last |
| @@ -292,7 +296,7 @@ pub(crate) fn render( | ||
| 292 | 296 | .flex_col() |
| 293 | 297 | .child(screen(player, position, window, cx)) |
| 294 | 298 | .child(time_band(player)) |
| 295 | - .child(bench()) | |
| 299 | + .child(bench(player, cx)) | |
| 296 | 300 | .child(ledger()), |
| 297 | 301 | ) |
| 298 | 302 | .child(dock(player, window_h, cx)) |