🚧 wip(app): the transform card compiles
Browse files at this commita1cea17257cf6a702444e7b932b7a4a6ae09e4d7Parent: 8108e2811 changed files +489 -1
- crates/app/src/keymap.rs +12 -1
- crates/app/src/main.rs +25 -0
- crates/app/src/player/actions.rs +2 -0
- crates/app/src/player/cards.rs +128 -0
- crates/app/src/player/library.rs +6 -0
- crates/app/src/player/timeline_edit.rs +15 -0
- crates/app/src/render.rs +23 -0
- crates/app/src/transform_ui.rs +108 -0
- crates/app/src/ui/cards.rs +139 -0
- crates/app/src/ui/inspector.rs +1 -0
- crates/engine/src/playback.rs +30 -0
crates/app/src/keymap.rsmodified+12 -1
| @@ -106,6 +106,10 @@ actions! { | |||
| 106 | Delete, | 106 | Delete, |
| 107 | Lift, | 107 | Lift, |
| 108 | Color, | 108 | Color, |
| 109 | + /// Where a clip sits, how big and which way up | ||
| 110 | + /// ([`crate::transform_ui::TRANSFORM_BANDS`]) -- the geometry twin of | ||
| 111 | + /// [`ActionId::Color`], filed right beside it. | ||
| 112 | + Transform, | ||
| 109 | Fit, | 113 | Fit, |
| 110 | Resolution, | 114 | Resolution, |
| 111 | ZoomIn, | 115 | ZoomIn, |
| @@ -209,6 +213,7 @@ impl ActionId { | |||
| 209 | ActionId::Delete => "Delete", | 213 | ActionId::Delete => "Delete", |
| 210 | ActionId::Lift => "Lift (leave a gap)", | 214 | ActionId::Lift => "Lift (leave a gap)", |
| 211 | ActionId::Color => "Colour…", | 215 | ActionId::Color => "Colour…", |
| 216 | + ActionId::Transform => "Transform — position, scale, rotation, crop", | ||
| 212 | ActionId::Fit => "Fit policy: fit → fill → stretch → centre", | 217 | ActionId::Fit => "Fit policy: fit → fill → stretch → centre", |
| 213 | ActionId::Resolution => "Project resolution: source → 2160p → 1080p → 720p → 480p", | 218 | ActionId::Resolution => "Project resolution: source → 2160p → 1080p → 720p → 480p", |
| 214 | ActionId::ZoomIn => "Zoom in on the timeline (around the playhead)", | 219 | ActionId::ZoomIn => "Zoom in on the timeline (around the playhead)", |
| @@ -277,6 +282,7 @@ impl ActionId { | |||
| 277 | ActionId::Delete => "delete", | 282 | ActionId::Delete => "delete", |
| 278 | ActionId::Lift => "lift", | 283 | ActionId::Lift => "lift", |
| 279 | ActionId::Color => "color", | 284 | ActionId::Color => "color", |
| 285 | + ActionId::Transform => "transform", | ||
| 280 | ActionId::Fit => "fit", | 286 | ActionId::Fit => "fit", |
| 281 | ActionId::Resolution => "resolution", | 287 | ActionId::Resolution => "resolution", |
| 282 | ActionId::ZoomIn => "zoom-in", | 288 | ActionId::ZoomIn => "zoom-in", |
| @@ -344,6 +350,7 @@ impl ActionId { | |||
| 344 | | ActionId::Delete | 350 | | ActionId::Delete |
| 345 | | ActionId::Lift | 351 | | ActionId::Lift |
| 346 | | ActionId::Color | 352 | | ActionId::Color |
| 353 | + | ActionId::Transform | ||
| 347 | | ActionId::Fit | 354 | | ActionId::Fit |
| 348 | // A rate is the clip's, not the sound's: it re-times the picture | 355 | // A rate is the clip's, not the sound's: it re-times the picture |
| 349 | // and the sound together, and the card opens on whichever half was | 356 | // and the sound together, and the card opens on whichever half was |
| @@ -903,6 +910,10 @@ impl Keymap { | |||
| 903 | // k: free, next to nothing that edits, and one press like the | 910 | // k: free, next to nothing that edits, and one press like the |
| 904 | // rest of the clip keys. | 911 | // rest of the clip keys. |
| 905 | b(ActionId::Color, "k", false), | 912 | b(ActionId::Color, "k", false), |
| 913 | + // The placement card takes the ctrl chord of the grade's own | ||
| 914 | + // key: the two sit beside each other on a clip and neither | ||
| 915 | + // steals a bare letter that already means something else. | ||
| 916 | + b(ActionId::Transform, "k", true), | ||
| 906 | // The fit policy is a clip key like the grade beside it: "p" for | 917 | // The fit policy is a clip key like the grade beside it: "p" for |
| 907 | // policy, free, and one press like the rest of them. The project | 918 | // policy, free, and one press like the rest of them. The project |
| 908 | // resolution is not a clip key and takes a ctrl chord, next to | 919 | // resolution is not a clip key and takes a ctrl chord, next to |
| @@ -1290,7 +1301,7 @@ mod tests { | |||
| 1290 | #[test] | 1301 | #[test] |
| 1291 | fn every_default_stroke_reaches_its_action() { | 1302 | fn every_default_stroke_reaches_its_action() { |
| 1292 | let k = Keymap::defaults(); | 1303 | let k = Keymap::defaults(); |
| 1293 | - assert_eq!(k.entries().len(), 63); | 1304 | + assert_eq!(k.entries().len(), 64); |
| 1294 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); | 1305 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); |
| 1295 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); | 1306 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); |
| 1296 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); | 1307 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); |
crates/app/src/main.rsmodified+25 -0
| @@ -17,6 +17,7 @@ mod oracle; | |||
| 17 | mod render; | 17 | mod render; |
| 18 | mod subs; | 18 | mod subs; |
| 19 | mod timeline_math; | 19 | mod timeline_math; |
| 20 | +mod transform_ui; | ||
| 20 | mod transport; | 21 | mod transport; |
| 21 | mod viewport; | 22 | mod viewport; |
| 22 | 23 | ||
| @@ -37,6 +38,7 @@ pub(crate) use notices::*; | |||
| 37 | pub(crate) use oracle::*; | 38 | pub(crate) use oracle::*; |
| 38 | pub(crate) use subs::*; | 39 | pub(crate) use subs::*; |
| 39 | pub(crate) use timeline_math::*; | 40 | pub(crate) use timeline_math::*; |
| 41 | +pub(crate) use transform_ui::*; | ||
| 40 | pub(crate) use transport::*; | 42 | pub(crate) use transport::*; |
| 41 | pub(crate) use viewport::*; | 43 | pub(crate) use viewport::*; |
| 42 | 44 | ||
| @@ -62,6 +64,7 @@ use engine::limiter::Limiter; | |||
| 62 | use engine::project::{Edge, Lane, LaneKind, Source, Speed, SubClip}; | 64 | use engine::project::{Edge, Lane, LaneKind, Source, Speed, SubClip}; |
| 63 | use engine::scale::FitPolicy; | 65 | use engine::scale::FitPolicy; |
| 64 | use engine::tonemap::Preset; | 66 | use engine::tonemap::Preset; |
| 67 | +use engine::transform::TransformParams; | ||
| 65 | use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession}; | 68 | use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession}; |
| 66 | use gpui::{ | 69 | use gpui::{ |
| 67 | AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent, | 70 | AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent, |
| @@ -663,6 +666,23 @@ struct Player { | |||
| 663 | /// stands, and never lost -- the frame that lands writes it, and so does the | 666 | /// stands, and never lost -- the frame that lands writes it, and so does the |
| 664 | /// release. | 667 | /// release. |
| 665 | pending_color: Option<ColorParams>, | 668 | pending_color: Option<ColorParams>, |
| 669 | + /// The transform card is up on this clip -- the lane it is on and its | ||
| 670 | + /// index there, exactly as the colour card's handle is. `None` when it is | ||
| 671 | + /// closed: the placement itself is the project's. | ||
| 672 | + transform_open: Option<(Lane, usize)>, | ||
| 673 | + /// Which of the card's eight sliders the arrow keys and a drag move. The | ||
| 674 | + /// card's own focus, since nothing in it takes gpui's (ledger:182). | ||
| 675 | + transform_band: usize, | ||
| 676 | + /// A slider is being dragged. Tracked on the root like the colour card's, | ||
| 677 | + /// for the same reason: a 4 px bar is left by the pointer on the first | ||
| 678 | + /// move and its own listeners then stop firing. | ||
| 679 | + transform_dragging: bool, | ||
| 680 | + /// Each slider's box, recorded at prepaint -- [`Self::color_bars`]' own | ||
| 681 | + /// reason, one per band. | ||
| 682 | + transform_bars: [Rc<Cell<Bounds<Pixels>>>; TRANSFORM_BANDS.len()], | ||
| 683 | + /// The placement the hand is on, held back because the worker still owes a | ||
| 684 | + /// frame -- [`Self::pending_color`]'s own reason. | ||
| 685 | + pending_transform: Option<TransformParams>, | ||
| 666 | /// The frame on screen counted into `HIST_BINS` bins per channel -- the | 686 | /// The frame on screen counted into `HIST_BINS` bins per channel -- the |
| 667 | /// *graded* frame, because the grade is applied in the decode worker and | 687 | /// *graded* frame, because the grade is applied in the decode worker and |
| 668 | /// what arrives here is already through it. Refilled by every pumped frame, | 688 | /// what arrives here is already through it. Refilled by every pumped frame, |
| @@ -910,6 +930,11 @@ fn main() { | |||
| 910 | color_dragging: false, | 930 | color_dragging: false, |
| 911 | color_bars: std::array::from_fn(|_| Rc::default()), | 931 | color_bars: std::array::from_fn(|_| Rc::default()), |
| 912 | pending_color: None, | 932 | pending_color: None, |
| 933 | + transform_open: None, | ||
| 934 | + transform_band: 0, | ||
| 935 | + transform_dragging: false, | ||
| 936 | + transform_bars: std::array::from_fn(|_| Rc::default()), | ||
| 937 | + pending_transform: None, | ||
| 913 | // Empty until the first frame is pumped, which draws as a | 938 | // Empty until the first frame is pumped, which draws as a |
| 914 | // flat line rather than as a shape nothing measured. | 939 | // flat line rather than as a shape nothing measured. |
| 915 | histogram: [[0; HIST_BINS]; 3], | 940 | histogram: [[0; HIST_BINS]; 3], |
crates/app/src/player/actions.rsmodified+2 -0
| @@ -101,6 +101,7 @@ impl Player { | |||
| 101 | ActionId::Delete => self.delete_selected(cx), | 101 | ActionId::Delete => self.delete_selected(cx), |
| 102 | ActionId::Lift => self.lift_selected(cx), | 102 | ActionId::Lift => self.lift_selected(cx), |
| 103 | ActionId::Color => self.open_color(cx), | 103 | ActionId::Color => self.open_color(cx), |
| 104 | + ActionId::Transform => self.open_transform(cx), | ||
| 104 | ActionId::Fit => self.cycle_fit(cx), | 105 | ActionId::Fit => self.cycle_fit(cx), |
| 105 | ActionId::Resolution => self.cycle_resolution(cx), | 106 | ActionId::Resolution => self.cycle_resolution(cx), |
| 106 | // The playhead is what a key zoom is aimed at: it is the one place | 107 | // The playhead is what a key zoom is aimed at: it is the one place |
| @@ -377,6 +378,7 @@ impl Player { | |||
| 377 | Repeat::Nothing | 378 | Repeat::Nothing |
| 378 | } else if self.eq_open.is_some() | 379 | } else if self.eq_open.is_some() |
| 379 | || self.color_open.is_some() | 380 | || self.color_open.is_some() |
| 381 | + || self.transform_open.is_some() | ||
| 380 | || self.speed_open.is_some() | 382 | || self.speed_open.is_some() |
| 381 | || self.silence_open.is_some() | 383 | || self.silence_open.is_some() |
| 382 | || self.mix_open | 384 | || self.mix_open |
crates/app/src/player/cards.rsmodified+128 -0
| @@ -383,6 +383,132 @@ impl Player { | |||
| 383 | } | 383 | } |
| 384 | } | 384 | } |
| 385 | 385 | ||
| 386 | + /// Opens the transform card on the clip a placement would go on -- | ||
| 387 | + /// [`open_color`](Self::open_color)'s own rule, since it targets the same | ||
| 388 | + /// clip a grade would. | ||
| 389 | + pub(crate) fn open_transform(&mut self, cx: &mut Context<Self>) { | ||
| 390 | + if self.exporting().is_some() { | ||
| 391 | + return; | ||
| 392 | + } | ||
| 393 | + let Some(session) = &self.session else { | ||
| 394 | + self.notify_user("no timeline to place — open a file first".into()); | ||
| 395 | + cx.notify(); | ||
| 396 | + return; | ||
| 397 | + }; | ||
| 398 | + let target = match self.selected.anchor() { | ||
| 399 | + Some((lane, idx)) if lane.kind == LaneKind::Subtitle => { | ||
| 400 | + match caption_media_half(session, (lane, idx), LaneKind::Video) { | ||
| 401 | + Some(half) => Some(half), | ||
| 402 | + None => { | ||
| 403 | + self.notify_user( | ||
| 404 | + "NOTHING TO PLACE — a caption has no picture; group it with a clip \ | ||
| 405 | + first (ctrl-click both, then Group)" | ||
| 406 | + .into(), | ||
| 407 | + ); | ||
| 408 | + cx.notify(); | ||
| 409 | + return; | ||
| 410 | + } | ||
| 411 | + } | ||
| 412 | + } | ||
| 413 | + Some((lane, _)) if lane.kind == LaneKind::Audio => session.video_clip_at(session.now()), | ||
| 414 | + other => other.or_else(|| session.video_clip_at(session.now())), | ||
| 415 | + }; | ||
| 416 | + match target { | ||
| 417 | + Some(clip) => { | ||
| 418 | + self.transform_open = Some(clip); | ||
| 419 | + self.transform_band = 0; | ||
| 420 | + self.transform_dragging = false; | ||
| 421 | + self.pending_transform = None; | ||
| 422 | + self.keys_open = false; | ||
| 423 | + self.export_open = false; | ||
| 424 | + self.context_menu = None; | ||
| 425 | + } | ||
| 426 | + None => self.notify_user("no clip under the playhead to place".into()), | ||
| 427 | + } | ||
| 428 | + cx.notify(); | ||
| 429 | + } | ||
| 430 | + | ||
| 431 | + /// What the card's clip is placed by right now -- [`color_params`](Self::color_params)'s | ||
| 432 | + /// own rule. | ||
| 433 | + pub(crate) fn transform_params(&self) -> TransformParams { | ||
| 434 | + if let Some(params) = self.pending_transform { | ||
| 435 | + return params; | ||
| 436 | + } | ||
| 437 | + self.transform_open | ||
| 438 | + .zip(self.session.as_ref()) | ||
| 439 | + .and_then(|((lane, idx), session)| session.transform_of(lane, idx).copied()) | ||
| 440 | + .unwrap_or_default() | ||
| 441 | + } | ||
| 442 | + | ||
| 443 | + /// Puts `params` on the card's clip, or takes the placement off when they | ||
| 444 | + /// are the identity -- [`set_color`](Self::set_color)'s own rule. | ||
| 445 | + pub(crate) fn set_transform(&mut self, params: TransformParams, cx: &mut Context<Self>) { | ||
| 446 | + self.write_transform(params, false, cx); | ||
| 447 | + } | ||
| 448 | + | ||
| 449 | + /// Both writes: `live` is the one that takes no undo step, which is what | ||
| 450 | + /// every sample *inside* a drag goes through -- | ||
| 451 | + /// [`write_color`](Self::write_color)'s own rule. | ||
| 452 | + pub(crate) fn write_transform(&mut self, params: TransformParams, live: bool, cx: &mut Context<Self>) { | ||
| 453 | + self.pending_transform = None; | ||
| 454 | + let Some((lane, idx)) = self.transform_open else { | ||
| 455 | + return; | ||
| 456 | + }; | ||
| 457 | + let Some(session) = &mut self.session else { | ||
| 458 | + return; | ||
| 459 | + }; | ||
| 460 | + let placement = Some(params).filter(|p| !p.is_identity()); | ||
| 461 | + let took = match live { | ||
| 462 | + true => session.set_transform_live(lane, idx, placement), | ||
| 463 | + false => session.set_transform(lane, idx, placement), | ||
| 464 | + }; | ||
| 465 | + if took { | ||
| 466 | + self.mark_dirty(); | ||
| 467 | + self.reset_after_reseek(); | ||
| 468 | + } | ||
| 469 | + cx.notify(); | ||
| 470 | + } | ||
| 471 | + | ||
| 472 | + /// Moves the picked slider by `steps` -- [`nudge_color`](Self::nudge_color)'s | ||
| 473 | + /// own rule, except rotation wraps into its range on | ||
| 474 | + /// [`transform_snap`] instead of clamping. | ||
| 475 | + pub(crate) fn nudge_transform(&mut self, steps: f32, cx: &mut Context<Self>) { | ||
| 476 | + let mut params = self.transform_params(); | ||
| 477 | + let (_, low, high) = TRANSFORM_BANDS[self.transform_band]; | ||
| 478 | + let step = if self.transform_band == ROTATE_BAND { | ||
| 479 | + ROTATE_STEP | ||
| 480 | + } else { | ||
| 481 | + TRANSFORM_STEP | ||
| 482 | + }; | ||
| 483 | + let value = transform_band_mut(&mut params, self.transform_band); | ||
| 484 | + let raw = *value + steps * step; | ||
| 485 | + *value = if self.transform_band == ROTATE_BAND { | ||
| 486 | + transform_snap(self.transform_band, raw) | ||
| 487 | + } else { | ||
| 488 | + raw.clamp(low, high) | ||
| 489 | + }; | ||
| 490 | + self.set_transform(params, cx); | ||
| 491 | + } | ||
| 492 | + | ||
| 493 | + /// Where the pointer sits along a slider, as that band's value -- | ||
| 494 | + /// [`drag_color`](Self::drag_color)'s own rule. | ||
| 495 | + pub(crate) fn drag_transform(&mut self, x: Pixels, first: bool, cx: &mut Context<Self>) { | ||
| 496 | + let (_, low, high) = TRANSFORM_BANDS[self.transform_band]; | ||
| 497 | + let along = frac_along(x, self.transform_bars[self.transform_band].get()); | ||
| 498 | + let value = transform_snap(self.transform_band, low + along * (high - low)); | ||
| 499 | + let mut params = self.transform_params(); | ||
| 500 | + let at = transform_band_mut(&mut params, self.transform_band); | ||
| 501 | + if *at == value && !first { | ||
| 502 | + return; | ||
| 503 | + } | ||
| 504 | + *at = value; | ||
| 505 | + let busy = self.seek_since.is_some(); | ||
| 506 | + match stash_or_write(&mut self.pending_transform, params, first, busy) { | ||
| 507 | + Some(params) => self.write_transform(params, !first, cx), | ||
| 508 | + None => cx.notify(), | ||
| 509 | + } | ||
| 510 | + } | ||
| 511 | + | ||
| 386 | /// Opens the speed card on the clip whose rate is to change: the selected | 512 | /// Opens the speed card on the clip whose rate is to change: the selected |
| 387 | /// one, or -- with nothing selected -- the clip the picture is coming from, | 513 | /// one, or -- with nothing selected -- the clip the picture is coming from, |
| 388 | /// which is what a person means by "this shot". Either half of a take will | 514 | /// which is what a person means by "this shot". Either half of a take will |
| @@ -1132,6 +1258,7 @@ impl Player { | |||
| 1132 | || self.export_open | 1258 | || self.export_open |
| 1133 | || self.eq_open.is_some() | 1259 | || self.eq_open.is_some() |
| 1134 | || self.color_open.is_some() | 1260 | || self.color_open.is_some() |
| 1261 | + || self.transform_open.is_some() | ||
| 1135 | || self.speed_open.is_some() | 1262 | || self.speed_open.is_some() |
| 1136 | || self.silence_open.is_some() | 1263 | || self.silence_open.is_some() |
| 1137 | || self.mix_open | 1264 | || self.mix_open |
| @@ -1159,6 +1286,7 @@ impl Player { | |||
| 1159 | self.eq_open = None; | 1286 | self.eq_open = None; |
| 1160 | self.eq_dragging = false; | 1287 | self.eq_dragging = false; |
| 1161 | self.color_open = None; | 1288 | self.color_open = None; |
| 1289 | + self.transform_open = None; | ||
| 1162 | self.speed_open = None; | 1290 | self.speed_open = None; |
| 1163 | // Marks and a running scan go with this one, which is why it is a call | 1291 | // Marks and a running scan go with this one, which is why it is a call |
| 1164 | // and not an assignment ([`Player::close_silence`]). | 1292 | // and not an assignment ([`Player::close_silence`]). |
crates/app/src/player/library.rsmodified+6 -0
| @@ -168,6 +168,7 @@ impl Player { | |||
| 168 | self.library_menu = None; | 168 | self.library_menu = None; |
| 169 | self.eq_open = None; | 169 | self.eq_open = None; |
| 170 | self.color_open = None; | 170 | self.color_open = None; |
| 171 | + self.transform_open = None; | ||
| 171 | self.speed_open = None; | 172 | self.speed_open = None; |
| 172 | self.close_silence(); | 173 | self.close_silence(); |
| 173 | self.waves.clear(); | 174 | self.waves.clear(); |
| @@ -196,6 +197,8 @@ impl Player { | |||
| 196 | self.speed_dragging = false; | 197 | self.speed_dragging = false; |
| 197 | self.color_dragging = false; | 198 | self.color_dragging = false; |
| 198 | self.pending_color = None; | 199 | self.pending_color = None; |
| 200 | + self.transform_dragging = false; | ||
| 201 | + self.pending_transform = None; | ||
| 199 | self.pending_speed = None; | 202 | self.pending_speed = None; |
| 200 | self.displayed = 0; | 203 | self.displayed = 0; |
| 201 | self.dropped = 0; | 204 | self.dropped = 0; |
| @@ -1279,6 +1282,7 @@ impl Player { | |||
| 1279 | self.context_menu = None; | 1282 | self.context_menu = None; |
| 1280 | self.eq_open = None; | 1283 | self.eq_open = None; |
| 1281 | self.color_open = None; | 1284 | self.color_open = None; |
| 1285 | + self.transform_open = None; | ||
| 1282 | // Marks are timeline frames of the timeline that was. | 1286 | // Marks are timeline frames of the timeline that was. |
| 1283 | self.close_silence(); | 1287 | self.close_silence(); |
| 1284 | // A different set of sources: the row that was picked is not | 1288 | // A different set of sources: the row that was picked is not |
| @@ -1541,6 +1545,7 @@ impl Player { | |||
| 1541 | self.context_menu = None; | 1545 | self.context_menu = None; |
| 1542 | self.eq_open = None; | 1546 | self.eq_open = None; |
| 1543 | self.color_open = None; | 1547 | self.color_open = None; |
| 1548 | + self.transform_open = None; | ||
| 1544 | self.speed_open = None; | 1549 | self.speed_open = None; |
| 1545 | self.close_silence(); | 1550 | self.close_silence(); |
| 1546 | // The shown lane with them: a `Lane` is a position among | 1551 | // The shown lane with them: a `Lane` is a position among |
| @@ -1599,6 +1604,7 @@ impl Player { | |||
| 1599 | self.context_menu = None; | 1604 | self.context_menu = None; |
| 1600 | self.eq_open = None; | 1605 | self.eq_open = None; |
| 1601 | self.color_open = None; | 1606 | self.color_open = None; |
| 1607 | + self.transform_open = None; | ||
| 1602 | self.speed_open = None; | 1608 | self.speed_open = None; |
| 1603 | self.close_silence(); | 1609 | self.close_silence(); |
| 1604 | // The shown lane with them: a `Lane` is a position among its | 1610 | // The shown lane with them: a `Lane` is a position among its |
crates/app/src/player/timeline_edit.rsmodified+15 -0
| @@ -1554,6 +1554,16 @@ impl Player { | |||
| 1554 | } | 1554 | } |
| 1555 | return; | 1555 | return; |
| 1556 | } | 1556 | } |
| 1557 | + // The transform card's sliders, [`Self::color_dragging`]'s own reason. | ||
| 1558 | + if self.transform_dragging { | ||
| 1559 | + if event.pressed_button == Some(MouseButton::Left) { | ||
| 1560 | + self.drag_transform(event.position.x, false, cx); | ||
| 1561 | + } else { | ||
| 1562 | + self.transform_dragging = false; | ||
| 1563 | + self.flush_drag(cx); | ||
| 1564 | + } | ||
| 1565 | + return; | ||
| 1566 | + } | ||
| 1557 | // The speed bar, the same 4 px and the same live writes: the | 1567 | // The speed bar, the same 4 px and the same live writes: the |
| 1558 | // press took the undo step and every sample since is live. | 1568 | // press took the undo step and every sample since is live. |
| 1559 | if self.speed_dragging { | 1569 | if self.speed_dragging { |
| @@ -1652,6 +1662,11 @@ impl Player { | |||
| 1652 | self.flush_drag(cx); | 1662 | self.flush_drag(cx); |
| 1653 | return; | 1663 | return; |
| 1654 | } | 1664 | } |
| 1665 | + if std::mem::take(&mut self.transform_dragging) { | ||
| 1666 | + self.drag_transform(event.position.x, false, cx); | ||
| 1667 | + self.flush_drag(cx); | ||
| 1668 | + return; | ||
| 1669 | + } | ||
| 1655 | if std::mem::take(&mut self.speed_dragging) { | 1670 | if std::mem::take(&mut self.speed_dragging) { |
| 1656 | self.drag_speed(event.position.x, false, cx); | 1671 | self.drag_speed(event.position.x, false, cx); |
| 1657 | self.flush_drag(cx); | 1672 | self.flush_drag(cx); |
crates/app/src/render.rsmodified+23 -0
| @@ -476,6 +476,29 @@ impl Render for Player { | |||
| 476 | cx.notify(); | 476 | cx.notify(); |
| 477 | return; | 477 | return; |
| 478 | } | 478 | } |
| 479 | + // The transform card, the same way again: the arrows pick a | ||
| 480 | + // slider and move it, and `r` puts the placement back to | ||
| 481 | + // identity. Card-local, [`ActionId::Color`]'s own reason (see | ||
| 482 | + // `FIXED`, where the keys menu still lists them). | ||
| 483 | + if this.transform_open.is_some() { | ||
| 484 | + let n = TRANSFORM_BANDS.len(); | ||
| 485 | + if key == ESCAPE { | ||
| 486 | + this.transform_open = None; | ||
| 487 | + this.transform_dragging = false; | ||
| 488 | + } else if key == "down" { | ||
| 489 | + this.transform_band = (this.transform_band + 1) % n; | ||
| 490 | + } else if key == "up" { | ||
| 491 | + this.transform_band = (this.transform_band + n - 1) % n; | ||
| 492 | + } else if key == "right" { | ||
| 493 | + this.nudge_transform(1., cx); | ||
| 494 | + } else if key == "left" { | ||
| 495 | + this.nudge_transform(-1., cx); | ||
| 496 | + } else if key == "r" { | ||
| 497 | + this.set_transform(TransformParams::default(), cx); | ||
| 498 | + } | ||
| 499 | + cx.notify(); | ||
| 500 | + return; | ||
| 501 | + } | ||
| 479 | // The speed card, the same way again: its arrows move the rate | 502 | // The speed card, the same way again: its arrows move the rate |
| 480 | // and `r` puts it back to real time, and neither means anything | 503 | // and `r` puts it back to real time, and neither means anything |
| 481 | // outside the card -- so neither is a binding (see `FIXED`, | 504 | // outside the card -- so neither is a binding (see `FIXED`, |
crates/app/src/transform_ui.rsadded+108 -0
| @@ -0,0 +1,108 @@ | |||
| 1 | +//! The transform card's numbers -- [`crate::color_ui`]'s twin for where a | ||
| 2 | +//! clip sits instead of what it looks like. | ||
| 3 | + | ||
| 4 | +use crate::*; | ||
| 5 | + | ||
| 6 | +/// The transform card's eight controls, in the order it lists them: what each | ||
| 7 | +/// is called and the range it moves in. The order is `TransformParams`' own, | ||
| 8 | +/// which is what [`transform_band_mut`] indexes. Rotation's range is one turn | ||
| 9 | +/// short (`0..270`) because 360 is the same picture as 0 and a slider with two | ||
| 10 | +/// ends that read the same is not a range, it is a cycle | ||
| 11 | +/// ([`ROTATE_BAND`]/[`rotate_key`]). | ||
| 12 | +pub(crate) const TRANSFORM_BANDS: [(&str, f32, f32); 8] = [ | ||
| 13 | + ("Position X", -1., 1.), | ||
| 14 | + ("Position Y", -1., 1.), | ||
| 15 | + ("Scale", 0.1, 4.), | ||
| 16 | + ("Rotation", 0., 270.), | ||
| 17 | + ("Crop left", 0., 0.45), | ||
| 18 | + ("Crop right", 0., 0.45), | ||
| 19 | + ("Crop top", 0., 0.45), | ||
| 20 | + ("Crop bottom", 0., 0.45), | ||
| 21 | +]; | ||
| 22 | + | ||
| 23 | +/// Which band is rotation: the one control on the card that wraps at its ends | ||
| 24 | +/// instead of clamping, and steps by [`ROTATE_STEP`] rather than | ||
| 25 | +/// [`TRANSFORM_STEP`] -- the engine only ever renders a 90-degree turn | ||
| 26 | +/// ([`crate::transform::TransformParams::rotate`]), so a finer grid on this | ||
| 27 | +/// one row would be numbers nothing on screen answers to. | ||
| 28 | +pub(crate) const ROTATE_BAND: usize = 3; | ||
| 29 | + | ||
| 30 | +/// A press of a nudge key on every band but rotation: a fortieth-ish of a | ||
| 31 | +/// band's range, [`crate::color_ui::COLOR_STEP`]'s own reason. A drag lands on | ||
| 32 | +/// the same grid ([`Player::drag_transform`]). | ||
| 33 | +pub(crate) const TRANSFORM_STEP: f32 = 0.05; | ||
| 34 | + | ||
| 35 | +/// Rotation's own step: one 90-degree turn, [`ROTATE_BAND`]'s reason. | ||
| 36 | +pub(crate) const ROTATE_STEP: f32 = 90.; | ||
| 37 | + | ||
| 38 | +/// The card's width, [`crate::color_ui::COLOR_W`]'s own measure against this | ||
| 39 | +/// card's longest label ("Position X" is short, but the value column is wider | ||
| 40 | +/// here for the crop rows' extra digit). | ||
| 41 | +pub(crate) const TRANSFORM_W: f32 = 460.; | ||
| 42 | +/// How much of a slider row the bar itself gets, [`crate::color_ui::COLOR_BAR_W`]. | ||
| 43 | +pub(crate) const TRANSFORM_BAR_W: f32 = 240.; | ||
| 44 | + | ||
| 45 | +/// A slider value on the band's own grid: [`ROTATE_BAND`] snaps to | ||
| 46 | +/// [`ROTATE_STEP`] and wraps into its range, every other band snaps to | ||
| 47 | +/// [`TRANSFORM_STEP`] and clamps into its own -- what a drag rounds to, so the | ||
| 48 | +/// pointer stops where the arrow keys do. | ||
| 49 | +pub(crate) fn transform_snap(band: usize, value: f32) -> f32 { | ||
| 50 | + let (_, low, high) = TRANSFORM_BANDS[band]; | ||
| 51 | + if band == ROTATE_BAND { | ||
| 52 | + let span = high - low + ROTATE_STEP; // one turn: 0..360 | ||
| 53 | + let wrapped = (value - low).rem_euclid(span); | ||
| 54 | + low + (wrapped / ROTATE_STEP).round() * ROTATE_STEP | ||
| 55 | + } else { | ||
| 56 | + ((value / TRANSFORM_STEP).round() * TRANSFORM_STEP).clamp(low, high) | ||
| 57 | + } | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +/// The band'th control of a placement, to read or to write. The order is | ||
| 61 | +/// [`TRANSFORM_BANDS`]', which is the order the card lists them in -- | ||
| 62 | +/// [`crate::export_ui::band_mut`]'s own twin. | ||
| 63 | +pub(crate) fn transform_band_mut(params: &mut TransformParams, band: usize) -> &mut f32 { | ||
| 64 | + match band { | ||
| 65 | + 0 => &mut params.pos_x, | ||
| 66 | + 1 => &mut params.pos_y, | ||
| 67 | + 2 => &mut params.scale, | ||
| 68 | + 3 => &mut params.rotate, | ||
| 69 | + 4 => &mut params.crop_l, | ||
| 70 | + 5 => &mut params.crop_r, | ||
| 71 | + 6 => &mut params.crop_t, | ||
| 72 | + _ => &mut params.crop_b, | ||
| 73 | + } | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +#[cfg(test)] | ||
| 77 | +mod tests { | ||
| 78 | + use super::*; | ||
| 79 | + | ||
| 80 | + #[test] | ||
| 81 | + fn ordinary_bands_snap_to_the_step_and_clamp() { | ||
| 82 | + assert_eq!(transform_snap(0, 0.024), 0.0); | ||
| 83 | + assert_eq!(transform_snap(0, 0.026), 0.05); | ||
| 84 | + assert_eq!(transform_snap(0, 5.0), 1.0); // clamped to Position X's high | ||
| 85 | + assert_eq!(transform_snap(0, -5.0), -1.0); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + #[test] | ||
| 89 | + fn rotation_snaps_to_ninety_and_wraps() { | ||
| 90 | + assert_eq!(transform_snap(ROTATE_BAND, 44.0), 0.0); | ||
| 91 | + assert_eq!(transform_snap(ROTATE_BAND, 46.0), 90.0); | ||
| 92 | + assert_eq!(transform_snap(ROTATE_BAND, 270.0), 270.0); | ||
| 93 | + // Past the last stop wraps back to the first, not clamps to the last. | ||
| 94 | + assert_eq!(transform_snap(ROTATE_BAND, 315.0), 0.0); | ||
| 95 | + assert_eq!(transform_snap(ROTATE_BAND, -45.0), 270.0); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + #[test] | ||
| 99 | + fn transform_band_mut_indexes_in_bands_order() { | ||
| 100 | + let mut p = TransformParams::default(); | ||
| 101 | + *transform_band_mut(&mut p, 0) = 0.1; | ||
| 102 | + *transform_band_mut(&mut p, 3) = 90.; | ||
| 103 | + *transform_band_mut(&mut p, 7) = 0.2; | ||
| 104 | + assert_eq!(p.pos_x, 0.1); | ||
| 105 | + assert_eq!(p.rotate, 90.); | ||
| 106 | + assert_eq!(p.crop_b, 0.2); | ||
| 107 | + } | ||
| 108 | +} | ||
crates/app/src/ui/cards.rsmodified+139 -0
| @@ -1523,6 +1523,145 @@ impl Player { | |||
| 1523 | ) | 1523 | ) |
| 1524 | } | 1524 | } |
| 1525 | 1525 | ||
| 1526 | + /// The transform card: [`color_card`](Self::color_card)'s own shape, one | ||
| 1527 | + /// row per [`TRANSFORM_BANDS`] entry instead of four, and no histogram -- | ||
| 1528 | + /// there is nothing here a graded frame would tilt. | ||
| 1529 | + pub(crate) fn transform_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { | ||
| 1530 | + let (lane, idx) = self.transform_open?; | ||
| 1531 | + let params = self.transform_params(); | ||
| 1532 | + let rows: Vec<_> = TRANSFORM_BANDS | ||
| 1533 | + .iter() | ||
| 1534 | + .enumerate() | ||
| 1535 | + .map(|(i, &(label, low, high))| { | ||
| 1536 | + let mut read = params; | ||
| 1537 | + let value = *transform_band_mut(&mut read, i); | ||
| 1538 | + let frac = ((value - low) / (high - low)).clamp(0., 1.); | ||
| 1539 | + let picked = i == self.transform_band; | ||
| 1540 | + div() | ||
| 1541 | + .id(("transform-row", i)) | ||
| 1542 | + .flex() | ||
| 1543 | + .min_h(px(KEYS_ROW_H)) | ||
| 1544 | + .items_center() | ||
| 1545 | + .gap(px(8.)) | ||
| 1546 | + .px(px(6.)) | ||
| 1547 | + .rounded(px(3.)) | ||
| 1548 | + .cursor_pointer() | ||
| 1549 | + .when(picked, |d| d.bg(rgb(BG_SELECTED()))) | ||
| 1550 | + .hover(|s| s.bg(rgb(BG_HOVER()))) | ||
| 1551 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 1552 | + this.transform_band = i; | ||
| 1553 | + cx.notify(); | ||
| 1554 | + })) | ||
| 1555 | + .child(div().flex_1().min_w(px(0.)).truncate().child(label)) | ||
| 1556 | + .child( | ||
| 1557 | + div() | ||
| 1558 | + .id(("transform-bar", i)) | ||
| 1559 | + .relative() | ||
| 1560 | + .flex_1() | ||
| 1561 | + .min_w(px(0.)) | ||
| 1562 | + .max_w(px(TRANSFORM_BAR_W)) | ||
| 1563 | + .h(px(KEYS_ROW_H)) | ||
| 1564 | + .flex() | ||
| 1565 | + .items_center() | ||
| 1566 | + .on_mouse_down( | ||
| 1567 | + MouseButton::Left, | ||
| 1568 | + cx.listener(move |this, event: &MouseDownEvent, _, cx| { | ||
| 1569 | + this.transform_band = i; | ||
| 1570 | + this.transform_dragging = true; | ||
| 1571 | + this.drag_transform(event.position.x, true, cx); | ||
| 1572 | + }), | ||
| 1573 | + ) | ||
| 1574 | + .child(bounds_probe(self.transform_bars[i].clone())) | ||
| 1575 | + .child( | ||
| 1576 | + div() | ||
| 1577 | + .w_full() | ||
| 1578 | + .h(px(4.)) | ||
| 1579 | + .rounded(px(2.)) | ||
| 1580 | + .bg(rgb(BG_PANEL())) | ||
| 1581 | + .child( | ||
| 1582 | + div() | ||
| 1583 | + .h_full() | ||
| 1584 | + .w(relative(frac)) | ||
| 1585 | + .rounded(px(2.)) | ||
| 1586 | + .bg(rgb(ACCENT_PRIMARY())), | ||
| 1587 | + ), | ||
| 1588 | + ), | ||
| 1589 | + ) | ||
| 1590 | + .child( | ||
| 1591 | + div() | ||
| 1592 | + .w(px(44.)) | ||
| 1593 | + .text_size(px(11.)) | ||
| 1594 | + .text_color(rgb(FG_SECONDARY())) | ||
| 1595 | + .child(match i == ROTATE_BAND { | ||
| 1596 | + true => format!("{value:.0}°"), | ||
| 1597 | + false => format!("{value:.2}"), | ||
| 1598 | + }), | ||
| 1599 | + ) | ||
| 1600 | + }) | ||
| 1601 | + .collect(); | ||
| 1602 | + Some( | ||
| 1603 | + drag_scrim(cx) | ||
| 1604 | + .flex() | ||
| 1605 | + .justify_center() | ||
| 1606 | + .items_center() | ||
| 1607 | + .bg(rgba(SCRIM())) | ||
| 1608 | + .on_mouse_down( | ||
| 1609 | + MouseButton::Left, | ||
| 1610 | + cx.listener(|this, _: &MouseDownEvent, _, cx| { | ||
| 1611 | + this.close_card(); | ||
| 1612 | + cx.notify(); | ||
| 1613 | + cx.stop_propagation(); | ||
| 1614 | + }), | ||
| 1615 | + ) | ||
| 1616 | + .child( | ||
| 1617 | + div() | ||
| 1618 | + .w_full() | ||
| 1619 | + .max_w(px(TRANSFORM_W)) | ||
| 1620 | + .on_mouse_down(MouseButton::Left, swallow) | ||
| 1621 | + .flex() | ||
| 1622 | + .flex_col() | ||
| 1623 | + .gap(px(2.)) | ||
| 1624 | + .p(px(12.)) | ||
| 1625 | + .rounded(px(6.)) | ||
| 1626 | + .bg(rgb(BG_RAISED())) | ||
| 1627 | + .child(div().flex_none().px(px(6.)).child(format!( | ||
| 1628 | + "Transform — {} clip {}", | ||
| 1629 | + lane.label(), | ||
| 1630 | + idx + 1 | ||
| 1631 | + ))) | ||
| 1632 | + .child( | ||
| 1633 | + div() | ||
| 1634 | + .flex_none() | ||
| 1635 | + .px(px(6.)) | ||
| 1636 | + .text_size(px(11.)) | ||
| 1637 | + .text_color(rgb(FG_SECONDARY())) | ||
| 1638 | + .child( | ||
| 1639 | + "drag a bar, or ↑↓ picks one and ←→ moves it (rotation steps \ | ||
| 1640 | + by 90°), r resets — a click away or esc closes", | ||
| 1641 | + ), | ||
| 1642 | + ) | ||
| 1643 | + .children(rows) | ||
| 1644 | + .child( | ||
| 1645 | + div() | ||
| 1646 | + .id("transform-reset") | ||
| 1647 | + .mt(px(4.)) | ||
| 1648 | + .flex() | ||
| 1649 | + .h(px(CONTROL_H)) | ||
| 1650 | + .items_center() | ||
| 1651 | + .justify_center() | ||
| 1652 | + .rounded(px(3.)) | ||
| 1653 | + .bg(rgb(BG_SELECTED())) | ||
| 1654 | + .cursor_pointer() | ||
| 1655 | + .hover(|s| s.bg(rgb(BG_HOVER()))) | ||
| 1656 | + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { | ||
| 1657 | + this.set_transform(TransformParams::default(), cx); | ||
| 1658 | + })) | ||
| 1659 | + .child("Reset"), | ||
| 1660 | + ), | ||
| 1661 | + ), | ||
| 1662 | + ) | ||
| 1663 | + } | ||
| 1664 | + | ||
| 1526 | /// The speed card: one bar from a quarter speed to four times it, the rates | 1665 | /// The speed card: one bar from a quarter speed to four times it, the rates |
| 1527 | /// people name as buttons under it, and the clip's new length in frames -- | 1666 | /// people name as buttons under it, and the clip's new length in frames -- |
| 1528 | /// which is the number a person is actually choosing. Built like the colour | 1667 | /// which is the number a person is actually choosing. Built like the colour |
crates/app/src/ui/inspector.rsmodified+1 -0
| @@ -81,6 +81,7 @@ impl Player { | |||
| 81 | }) | 81 | }) |
| 82 | .children(self.eq_card(room, cx)) | 82 | .children(self.eq_card(room, cx)) |
| 83 | .children(self.color_card(cx)) | 83 | .children(self.color_card(cx)) |
| 84 | + .children(self.transform_card(cx)) | ||
| 84 | .children(self.speed_card(cx)) | 85 | .children(self.speed_card(cx)) |
| 85 | .children(self.silence_card(cx)) | 86 | .children(self.silence_card(cx)) |
| 86 | .children(self.mix_card(cx)) | 87 | .children(self.mix_card(cx)) |
crates/engine/src/playback.rsmodified+30 -0
| @@ -2603,6 +2603,36 @@ impl PlaybackSession { | |||
| 2603 | self.edit(Dirty::Picture, |p| p.set_color_live(lane, idx, params)) | 2603 | self.edit(Dirty::Picture, |p| p.set_color_live(lane, idx, params)) |
| 2604 | } | 2604 | } |
| 2605 | 2605 | ||
| 2606 | + /// Where the clip at `idx` of `lane` is placed -- [`color_of`](Self::color_of)'s | ||
| 2607 | + /// twin for geometry instead of grade. | ||
| 2608 | + pub fn transform_of(&self, lane: Lane, idx: usize) -> Option<&TransformParams> { | ||
| 2609 | + self.project.transform_of(lane, idx) | ||
| 2610 | + } | ||
| 2611 | + | ||
| 2612 | + /// Moves/scales/rotates/crops that clip, or takes the placement off with | ||
| 2613 | + /// `None` -- [`set_color`](Self::set_color)'s twin, one undo step and one | ||
| 2614 | + /// reseek. | ||
| 2615 | + pub fn set_transform( | ||
| 2616 | + &mut self, | ||
| 2617 | + lane: Lane, | ||
| 2618 | + idx: usize, | ||
| 2619 | + params: Option<TransformParams>, | ||
| 2620 | + ) -> bool { | ||
| 2621 | + self.edit(Dirty::Picture, |p| p.set_transform(lane, idx, params)) | ||
| 2622 | + } | ||
| 2623 | + | ||
| 2624 | + /// The same placement and the same reseek without the undo step | ||
| 2625 | + /// ([`Project::set_transform_live`]) -- [`set_color_live`](Self::set_color_live)'s | ||
| 2626 | + /// twin for a slider drag. | ||
| 2627 | + pub fn set_transform_live( | ||
| 2628 | + &mut self, | ||
| 2629 | + lane: Lane, | ||
| 2630 | + idx: usize, | ||
| 2631 | + params: Option<TransformParams>, | ||
| 2632 | + ) -> bool { | ||
| 2633 | + self.edit(Dirty::Picture, |p| p.set_transform_live(lane, idx, params)) | ||
| 2634 | + } | ||
| 2635 | + | ||
| 2606 | /// The project's resolution: what every clip is composed onto, what the | 2636 | /// The project's resolution: what every clip is composed onto, what the |
| 2607 | /// window is sized to and what an export writes -- *not* any one file's. | 2637 | /// window is sized to and what an export writes -- *not* any one file's. |
| 2608 | /// It starts as source 0's picture, which is what a project meant before it | 2638 | /// It starts as source 0's picture, which is what a project meant before it |