🔀 merge: main (E2's export clocks) into E1
Browse files at this commit6 changed files +1195 -78
- crates/app/src/keymap.rs +27 -4
- crates/app/src/main.rs +842 -73
- crates/engine-hw/src/lib.rs +132 -1
- crates/engine/src/caps.rs +141 -0
- crates/engine/src/hw.rs +52 -0
- crates/engine/src/lib.rs +1 -0
crates/app/src/keymap.rsmodified+27 -4
| @@ -80,12 +80,16 @@ pub enum ActionId { | |||
| 80 | Mix, | 80 | Mix, |
| 81 | ToggleSnap, | 81 | ToggleSnap, |
| 82 | CancelExport, | 82 | CancelExport, |
| 83 | + /// Opens the actions card -- the list every other action is on. A door of | ||
| 84 | + /// its own, because a card reachable only by a button in the panel is one a | ||
| 85 | + /// hand on the keyboard has to leave the keyboard for. | ||
| 86 | + ShowActions, | ||
| 83 | } | 87 | } |
| 84 | 88 | ||
| 85 | impl ActionId { | 89 | impl ActionId { |
| 86 | /// Display order everywhere -- the editor lists them in it and | 90 | /// Display order everywhere -- the editor lists them in it and |
| 87 | /// [`Keymap::defaults`] binds them in it. | 91 | /// [`Keymap::defaults`] binds them in it. |
| 88 | - pub const ALL: [ActionId; 40] = [ | 92 | + pub const ALL: [ActionId; 41] = [ |
| 89 | ActionId::Play, | 93 | ActionId::Play, |
| 90 | ActionId::StepBack, | 94 | ActionId::StepBack, |
| 91 | ActionId::StepForward, | 95 | ActionId::StepForward, |
| @@ -126,6 +130,7 @@ impl ActionId { | |||
| 126 | ActionId::Mix, | 130 | ActionId::Mix, |
| 127 | ActionId::ToggleSnap, | 131 | ActionId::ToggleSnap, |
| 128 | ActionId::CancelExport, | 132 | ActionId::CancelExport, |
| 133 | + ActionId::ShowActions, | ||
| 129 | ]; | 134 | ]; |
| 130 | 135 | ||
| 131 | /// What a person calls it. | 136 | /// What a person calls it. |
| @@ -171,6 +176,7 @@ impl ActionId { | |||
| 171 | ActionId::Mix => "Mix: track volumes and the limiter…", | 176 | ActionId::Mix => "Mix: track volumes and the limiter…", |
| 172 | ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", | 177 | ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", |
| 173 | ActionId::CancelExport => "Cancel export", | 178 | ActionId::CancelExport => "Cancel export", |
| 179 | + ActionId::ShowActions => "All actions and their keys…", | ||
| 174 | } | 180 | } |
| 175 | } | 181 | } |
| 176 | 182 | ||
| @@ -218,6 +224,7 @@ impl ActionId { | |||
| 218 | ActionId::Mix => "mix", | 224 | ActionId::Mix => "mix", |
| 219 | ActionId::ToggleSnap => "toggle-snap", | 225 | ActionId::ToggleSnap => "toggle-snap", |
| 220 | ActionId::CancelExport => "cancel-export", | 226 | ActionId::CancelExport => "cancel-export", |
| 227 | + ActionId::ShowActions => "show-actions", | ||
| 221 | } | 228 | } |
| 222 | } | 229 | } |
| 223 | 230 | ||
| @@ -282,7 +289,12 @@ impl ActionId { | |||
| 282 | // are this machine's monitoring. Both are audio, and the card says | 289 | // are this machine's monitoring. Both are audio, and the card says |
| 283 | // which is which. | 290 | // which is which. |
| 284 | | ActionId::Mix => Category::Audio, | 291 | | ActionId::Mix => Category::Audio, |
| 285 | - ActionId::Save | ActionId::Export | ActionId::CancelExport => Category::File, | 292 | + // Under the heading the panel button sits in, beside the save and |
| 293 | + // the export it stands next to on screen. | ||
| 294 | + ActionId::Save | ||
| 295 | + | ActionId::Export | ||
| 296 | + | ActionId::CancelExport | ||
| 297 | + | ActionId::ShowActions => Category::File, | ||
| 286 | } | 298 | } |
| 287 | } | 299 | } |
| 288 | } | 300 | } |
| @@ -686,6 +698,11 @@ impl Keymap { | |||
| 686 | // it with: free here, and nowhere near the two keys that delete. | 698 | // it with: free here, and nowhere near the two keys that delete. |
| 687 | b(ActionId::ToggleSnap, "n", false), | 699 | b(ActionId::ToggleSnap, "n", false), |
| 688 | b(ActionId::CancelExport, "escape", false), | 700 | b(ActionId::CancelExport, "escape", false), |
| 701 | + // The help key, where every program's list of what it can do | ||
| 702 | + // has always been. Free -- gpui names it "f1" | ||
| 703 | + // (platform.rs:880, the keysym's own name lowercased) -- and | ||
| 704 | + // not a letter, so it takes nothing away from the clip keys. | ||
| 705 | + b(ActionId::ShowActions, "f1", false), | ||
| 689 | ], | 706 | ], |
| 690 | } | 707 | } |
| 691 | } | 708 | } |
| @@ -947,7 +964,8 @@ mod tests { | |||
| 947 | #[test] | 964 | #[test] |
| 948 | fn every_default_stroke_reaches_its_action() { | 965 | fn every_default_stroke_reaches_its_action() { |
| 949 | let k = Keymap::defaults(); | 966 | let k = Keymap::defaults(); |
| 950 | - assert_eq!(k.entries().len(), 42); | 967 | + assert_eq!(k.entries().len(), 43); |
| 968 | + assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions)); | ||
| 951 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); | 969 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); |
| 952 | // The seek keys: bare arrows a frame, ctrl arrows a second, and the two | 970 | // The seek keys: bare arrows a frame, ctrl arrows a second, and the two |
| 953 | // ends of the timeline. | 971 | // ends of the timeline. |
| @@ -1138,6 +1156,10 @@ mod tests { | |||
| 1138 | // Refused means unchanged, on both sides of the conflict. | 1156 | // Refused means unchanged, on both sides of the conflict. |
| 1139 | assert_eq!(k.lookup("e", false), Some(ActionId::Export)); | 1157 | assert_eq!(k.lookup("e", false), Some(ActionId::Export)); |
| 1140 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); | 1158 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); |
| 1159 | + // And the refusal is a name, not a shrug: it is the holder's own label | ||
| 1160 | + // the card prints back at the waiting row (`Player::capture`, "ALREADY | ||
| 1161 | + // BOUND — space is Play / Pause"). | ||
| 1162 | + assert_eq!(ActionId::Play.label(), "Play / Pause"); | ||
| 1141 | // A free stroke takes, and the old one stops meaning anything. | 1163 | // A free stroke takes, and the old one stops meaning anything. |
| 1142 | assert_eq!(k.rebind_action(ActionId::Export, chord("w", true)), Ok(())); | 1164 | assert_eq!(k.rebind_action(ActionId::Export, chord("w", true)), Ok(())); |
| 1143 | assert_eq!(k.lookup("w", true), Some(ActionId::Export)); | 1165 | assert_eq!(k.lookup("w", true), Some(ActionId::Export)); |
| @@ -1181,8 +1203,9 @@ mod tests { | |||
| 1181 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); | 1203 | assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound"); |
| 1182 | // The label is the editor's column, and never the file's word for it. | 1204 | // The label is the editor's column, and never the file's word for it. |
| 1183 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); | 1205 | assert_eq!(ActionId::CancelExport.label(), "Cancel export"); |
| 1184 | - assert_eq!(ActionId::ALL.len(), 40); | 1206 | + assert_eq!(ActionId::ALL.len(), 41); |
| 1185 | assert_eq!(k.display(ActionId::ToggleSnap), "n"); | 1207 | assert_eq!(k.display(ActionId::ToggleSnap), "n"); |
| 1208 | + assert_eq!(k.display(ActionId::ShowActions), "f1"); | ||
| 1186 | assert_eq!(k.display(ActionId::ZoomIn), "ctrl+="); | 1209 | assert_eq!(k.display(ActionId::ZoomIn), "ctrl+="); |
| 1187 | } | 1210 | } |
| 1188 | 1211 | ||
crates/app/src/main.rsmodified+842 -73
| @@ -21,9 +21,9 @@ use engine::{Clip, Codec, ExportHandle, Frame, PlaybackSession}; | |||
| 21 | use gpui::{ | 21 | use gpui::{ |
| 22 | AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent, | 22 | AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent, |
| 23 | FocusHandle, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, | 23 | FocusHandle, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, |
| 24 | - PathBuilder, Pixels, Point, RenderImage, ScrollDelta, ScrollWheelEvent, SharedString, Size, | 24 | + PathBuilder, Pixels, Point, RenderImage, ScrollDelta, ScrollHandle, ScrollWheelEvent, |
| 25 | - Stateful, TextAlign, TitlebarOptions, Window, WindowBounds, WindowOptions, canvas, div, img, | 25 | + SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, WindowBounds, WindowOptions, |
| 26 | - point, prelude::*, px, relative, rgb, rgba, size, | 26 | + canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size, |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | /// Editor chrome: three grays and one accent, all darker than the picture so the | 29 | /// Editor chrome: three grays and one accent, all darker than the picture so the |
| @@ -40,6 +40,18 @@ const SELECTED: u32 = 0x2a4a6b; | |||
| 40 | /// the lane stays in the dark family the rest of the chrome lives in | 40 | /// the lane stays in the dark family the rest of the chrome lives in |
| 41 | /// (ledger:187), and the first source keeps `SURFACE` exactly. | 41 | /// (ledger:187), and the first source keeps `SURFACE` exactly. |
| 42 | const SOURCE_TINTS: [u32; 4] = [SURFACE, 0x3b3329, 0x293b33, 0x33293b]; | 42 | const SOURCE_TINTS: [u32; 4] = [SURFACE, 0x3b3329, 0x293b33, 0x33293b]; |
| 43 | +/// The mirror of `SELECTED`: a drop the lane will not take, tinting the shadow | ||
| 44 | +/// a drag draws ([`Ghost`]) so a refusal is seen before the release rather than | ||
| 45 | +/// read afterwards. Same brightness as the rest of the chrome -- a warning, not | ||
| 46 | +/// an alarm. | ||
| 47 | +const REFUSE: u32 = 0x6b2a2a; | ||
| 48 | +/// How solid that shadow is (`0xRRGGBBAA`): enough to read as a box, little | ||
| 49 | +/// enough that the clip it is drawn over is still legible through it. | ||
| 50 | +const GHOST_ALPHA: u32 = 0x66; | ||
| 51 | +/// ...and the narrowest it is drawn: a library row whose length the engine has | ||
| 52 | +/// not measured yet has a landing place but no width, and a head marker says | ||
| 53 | +/// where it goes where a zero-width box would say nothing. | ||
| 54 | +const GHOST_MIN: f32 = 2.; | ||
| 43 | /// One step lighter than whatever it sits on: the pointer's answer that this is | 55 | /// One step lighter than whatever it sits on: the pointer's answer that this is |
| 44 | /// clickable. Two of them, because buttons stand on `SURFACE` and the scrub | 56 | /// clickable. Two of them, because buttons stand on `SURFACE` and the scrub |
| 45 | /// strip stands on `CHROME`. | 57 | /// strip stands on `CHROME`. |
| @@ -297,6 +309,29 @@ struct ClipDrag { | |||
| 297 | clip: Clip, | 309 | clip: Clip, |
| 298 | } | 310 | } |
| 299 | 311 | ||
| 312 | +/// Where the drag in flight would leave what it is carrying: the lane the | ||
| 313 | +/// pointer is over, the snapped head the release will commit ([`landing`]), and | ||
| 314 | +/// how long the thing is. Drawn on that lane as a translucent box the size of | ||
| 315 | +/// the take, so a landing is *seen* before the release rather than discovered | ||
| 316 | +/// after it -- the line ([`Player::snap_cue`]) marks the frame, this shows the | ||
| 317 | +/// body. `refused` is a drop the lane cannot take -- a picture over an audio | ||
| 318 | +/// track, a sound over a video one -- tinted rather than silent, because the | ||
| 319 | +/// refusal is coming at the release either way ([`lane_refuses`], | ||
| 320 | +/// [`Project::move_clip`]). | ||
| 321 | +#[derive(Clone, Copy, PartialEq)] | ||
| 322 | +struct Ghost { | ||
| 323 | + lane: Lane, | ||
| 324 | + start: u32, | ||
| 325 | + /// Timeline frames, which a speed has already been counted into: the box is | ||
| 326 | + /// as wide as the clip is *long where it lands*. Zero for a library row of | ||
| 327 | + /// unknown length, drawn as a head marker. | ||
| 328 | + frames: u32, | ||
| 329 | + /// The swatch of the file being carried ([`Player::file_tint`]), so the | ||
| 330 | + /// ghost reads as the thing in the hand. | ||
| 331 | + tint: u32, | ||
| 332 | + refused: bool, | ||
| 333 | +} | ||
| 334 | + | ||
| 300 | /// A clip edge being dragged: which end of which clip, and the timeline frame | 335 | /// A clip edge being dragged: which end of which clip, and the timeline frame |
| 301 | /// the pointer has pulled it to. The box on screen is drawn from `to` while this | 336 | /// the pointer has pulled it to. The box on screen is drawn from `to` while this |
| 302 | /// is set and the engine hears about it once, at the release | 337 | /// is set and the engine hears about it once, at the release |
| @@ -497,6 +532,65 @@ fn keys_rows() -> Vec<KeyRow> { | |||
| 497 | rows | 532 | rows |
| 498 | } | 533 | } |
| 499 | 534 | ||
| 535 | +/// [`keys_rows`] with a search applied: the rows whose label or whose stroke | ||
| 536 | +/// carries `needle`, and the heading each one lives under. A heading with | ||
| 537 | +/// nothing left beneath it goes with them -- an empty "Playback" over a gap | ||
| 538 | +/// reads as a list that lost its rows rather than as a search that found none. | ||
| 539 | +/// | ||
| 540 | +/// Each row keeps the index it has in the unfiltered list, so an element id is | ||
| 541 | +/// the same one before and after a keystroke: filtering is a look at the list, | ||
| 542 | +/// and gpui's per-element state is keyed on that id. | ||
| 543 | +/// | ||
| 544 | +/// Case-insensitive substring, on both columns: people look for an action by | ||
| 545 | +/// what it does ("vol") and for a stroke by what they pressed ("ctrl"). | ||
| 546 | +fn keys_filter(needle: &str, keymap: &Keymap) -> Vec<(usize, KeyRow)> { | ||
| 547 | + let needle = needle.trim().to_lowercase(); | ||
| 548 | + let rows = keys_rows().into_iter().enumerate(); | ||
| 549 | + if needle.is_empty() { | ||
| 550 | + return rows.collect(); | ||
| 551 | + } | ||
| 552 | + let hit = |label: &str, chord: &str| { | ||
| 553 | + label.to_lowercase().contains(&needle) || chord.to_lowercase().contains(&needle) | ||
| 554 | + }; | ||
| 555 | + let mut out: Vec<(usize, KeyRow)> = Vec::new(); | ||
| 556 | + // The heading above the row being looked at, until a row under it earns it | ||
| 557 | + // a place -- then it goes in once, ahead of that row. | ||
| 558 | + let mut pending: Option<(usize, KeyRow)> = None; | ||
| 559 | + for (i, row) in rows { | ||
| 560 | + match &row { | ||
| 561 | + KeyRow::Head(_) => pending = Some((i, row)), | ||
| 562 | + KeyRow::Act(action) => { | ||
| 563 | + if hit(action.label(), &keymap.display(*action)) { | ||
| 564 | + out.extend(pending.take()); | ||
| 565 | + out.push((i, row)); | ||
| 566 | + } | ||
| 567 | + } | ||
| 568 | + KeyRow::Fixed(f) => { | ||
| 569 | + let fixed = &keymap::FIXED[*f]; | ||
| 570 | + if hit(fixed.label, fixed.chord) { | ||
| 571 | + out.extend(pending.take()); | ||
| 572 | + out.push((i, row)); | ||
| 573 | + } | ||
| 574 | + } | ||
| 575 | + } | ||
| 576 | + } | ||
| 577 | + out | ||
| 578 | +} | ||
| 579 | + | ||
| 580 | +/// The character a stroke types into the actions card's search box, if it types | ||
| 581 | +/// one. gpui reports a printable key as itself and the space bar by name | ||
| 582 | +/// (platform.rs:866), and everything else -- the arrows, the function keys -- | ||
| 583 | +/// is a word this must not spell into the box letter by letter. | ||
| 584 | +fn typed(key: &str) -> Option<char> { | ||
| 585 | + match key { | ||
| 586 | + "space" => Some(' '), | ||
| 587 | + _ => key | ||
| 588 | + .chars() | ||
| 589 | + .next() | ||
| 590 | + .filter(|c| c.is_ascii_graphic() && key.chars().count() == 1), | ||
| 591 | + } | ||
| 592 | +} | ||
| 593 | + | ||
| 500 | /// The project resolutions [`Player::cycle_resolution`] offers, largest first. | 594 | /// The project resolutions [`Player::cycle_resolution`] offers, largest first. |
| 501 | /// A short list of the sizes people name; the media's own is cycled in beside | 595 | /// A short list of the sizes people name; the media's own is cycled in beside |
| 502 | /// them, which is what makes the trip round come back to where it started. | 596 | /// them, which is what makes the trip round come back to where it started. |
| @@ -862,6 +956,11 @@ struct Player { | |||
| 862 | /// runs off the render thread and only while the export card is up. The | 956 | /// runs off the render thread and only while the export card is up. The |
| 863 | /// inner `None` is "asked, not answered yet". | 957 | /// inner `None` is "asked, not answered yet". |
| 864 | export_seat: Option<(ExportSettings, (u32, u32), Option<&'static str>)>, | 958 | export_seat: Option<(ExportSettings, (u32, u32), Option<&'static str>)>, |
| 959 | + /// What this machine's GPU decodes and encodes, as the plugin answered it: | ||
| 960 | + /// asked once, off the render thread like `export_seat` and for the same | ||
| 961 | + /// reason (a VA-API init), and kept for the life of the process because the | ||
| 962 | + /// answer cannot change while we run. `None` is "not asked yet". | ||
| 963 | + hw_caps: Option<SharedString>, | ||
| 865 | /// The copied clip. Frame ranges only, so it survives the clip it was taken | 964 | /// The copied clip. Frame ranges only, so it survives the clip it was taken |
| 866 | /// from being deleted -- and it outlives the selection. | 965 | /// from being deleted -- and it outlives the selection. |
| 867 | clipboard: Option<Clip>, | 966 | clipboard: Option<Clip>, |
| @@ -889,6 +988,12 @@ struct Player { | |||
| 889 | /// happens rather than discovered after the release. Stale between gestures, | 988 | /// happens rather than discovered after the release. Stale between gestures, |
| 890 | /// which costs nothing -- it is drawn only while one is live. | 989 | /// which costs nothing -- it is drawn only while one is live. |
| 891 | snap_cue: Option<u32>, | 990 | snap_cue: Option<u32>, |
| 991 | + /// The box the same gesture is about to fill, or `None` while the pointer is | ||
| 992 | + /// over no lane: the shadow every proper editor draws under a drag. Set by | ||
| 993 | + /// the lane the pointer is actually over -- that is the one question the | ||
| 994 | + /// line above does not answer -- and drawn only while a drag is live, for | ||
| 995 | + /// [`Player::snap_cue`]'s reason. | ||
| 996 | + ghost: Option<Ghost>, | ||
| 892 | last_scrub: Instant, | 997 | last_scrub: Instant, |
| 893 | last_target: u32, | 998 | last_target: u32, |
| 894 | /// The running export. While it owns the UI the editor is read-only. | 999 | /// The running export. While it owns the UI the editor is read-only. |
| @@ -898,6 +1003,11 @@ struct Player { | |||
| 898 | /// handle is held until the worker settles, because its last act is to | 1003 | /// handle is held until the worker settles, because its last act is to |
| 899 | /// delete the output file and a second export must not be what it deletes. | 1004 | /// delete the output file and a second export must not be what it deletes. |
| 900 | cancelling: bool, | 1005 | cancelling: bool, |
| 1006 | + /// When the running export started, and how far it had come at each sample | ||
| 1007 | + /// since, as `(elapsed, progress)` marks. The elapsed clock and the | ||
| 1008 | + /// rolling-window estimate the progress line reads; see [`note_progress`]. | ||
| 1009 | + export_started: Option<Instant>, | ||
| 1010 | + export_marks: Vec<(f32, f32)>, | ||
| 901 | /// Where an export writes. Built once from the source path, which is not | 1011 | /// Where an export writes. Built once from the source path, which is not |
| 902 | /// otherwise kept. | 1012 | /// otherwise kept. |
| 903 | export_path: PathBuf, | 1013 | export_path: PathBuf, |
| @@ -923,6 +1033,16 @@ struct Player { | |||
| 923 | /// pointer: a stroke or a click meant for a row must not also cut the | 1033 | /// pointer: a stroke or a click meant for a row must not also cut the |
| 924 | /// timeline. | 1034 | /// timeline. |
| 925 | keys_open: bool, | 1035 | keys_open: bool, |
| 1036 | + /// What has been typed into the card's search box, which is the card's own | ||
| 1037 | + /// input exactly as the export card's digits are (nothing in it takes | ||
| 1038 | + /// focus, so the root's key handler is the field). Emptied every time the | ||
| 1039 | + /// card opens: a search is a look at the list, not a setting. | ||
| 1040 | + keys_search: String, | ||
| 1041 | + /// Where that list is scrolled to. Held here rather than left to the | ||
| 1042 | + /// wheel alone: forty actions are four times what a 360 px window shows, | ||
| 1043 | + /// and the rows past the fold have to be reachable from the keyboard that | ||
| 1044 | + /// is already typing in the search box. | ||
| 1045 | + keys_scroll: ScrollHandle, | ||
| 926 | /// The export options card is up: what the export action opens now, so | 1046 | /// The export options card is up: what the export action opens now, so |
| 927 | /// nothing is written until the card's own button says so. One card at a | 1047 | /// nothing is written until the card's own button says so. One card at a |
| 928 | /// time -- opening either closes the other, since both are the whole window | 1048 | /// time -- opening either closes the other, since both are the whole window |
| @@ -1185,6 +1305,10 @@ impl Player { | |||
| 1185 | // index would trim a clip nobody grabbed. Dropping it is the whole fix: | 1305 | // index would trim a clip nobody grabbed. Dropping it is the whole fix: |
| 1186 | // nothing has been written yet. | 1306 | // nothing has been written yet. |
| 1187 | self.trim = None; | 1307 | self.trim = None; |
| 1308 | + // ...and the shadow a drag is drawn under promises a landing on a lane | ||
| 1309 | + // this edit has just reshaped. The next move of the drag draws it | ||
| 1310 | + // again; until then it says nothing. | ||
| 1311 | + self.ghost = None; | ||
| 1188 | } | 1312 | } |
| 1189 | 1313 | ||
| 1190 | /// What an action does, wherever it was asked for -- a stroke, or the clip | 1314 | /// What an action does, wherever it was asked for -- a stroke, or the clip |
| @@ -1242,6 +1366,7 @@ impl Player { | |||
| 1242 | // Nothing to cancel while nothing is exporting; the export guard in | 1366 | // Nothing to cancel while nothing is exporting; the export guard in |
| 1243 | // the key handler is what answers this one while there is. | 1367 | // the key handler is what answers this one while there is. |
| 1244 | ActionId::CancelExport => {} | 1368 | ActionId::CancelExport => {} |
| 1369 | + ActionId::ShowActions => self.show_actions(cx), | ||
| 1245 | } | 1370 | } |
| 1246 | } | 1371 | } |
| 1247 | 1372 | ||
| @@ -1251,6 +1376,7 @@ impl Player { | |||
| 1251 | fn toggle_snap(&mut self, cx: &mut Context<Self>) { | 1376 | fn toggle_snap(&mut self, cx: &mut Context<Self>) { |
| 1252 | self.snap = !self.snap; | 1377 | self.snap = !self.snap; |
| 1253 | self.snap_cue = None; | 1378 | self.snap_cue = None; |
| 1379 | + self.ghost = None; | ||
| 1254 | self.notice = Some(match self.snap { | 1380 | self.notice = Some(match self.snap { |
| 1255 | true => "SNAP ON — drags land on clip edges, the playhead and the start".into(), | 1381 | true => "SNAP ON — drags land on clip edges, the playhead and the start".into(), |
| 1256 | false => "SNAP OFF — drags land exactly where the hand leaves them".into(), | 1382 | false => "SNAP OFF — drags land exactly where the hand leaves them".into(), |
| @@ -1258,6 +1384,37 @@ impl Player { | |||
| 1258 | cx.notify(); | 1384 | cx.notify(); |
| 1259 | } | 1385 | } |
| 1260 | 1386 | ||
| 1387 | + /// The actions card, from its key, from the panel button, or from its own | ||
| 1388 | + /// row: open, with an empty search box -- a card that opens showing the | ||
| 1389 | + /// last search would hide most of the list for a reason nobody remembers. | ||
| 1390 | + fn show_actions(&mut self, cx: &mut Context<Self>) { | ||
| 1391 | + self.keys_open = true; | ||
| 1392 | + self.keys_search.clear(); | ||
| 1393 | + self.scroll_keys(None); | ||
| 1394 | + self.rebinding = None; | ||
| 1395 | + // One card at a time, the rule the other cards follow. | ||
| 1396 | + self.export_open = false; | ||
| 1397 | + cx.notify(); | ||
| 1398 | + } | ||
| 1399 | + | ||
| 1400 | + /// Moves the actions card's row list by `by` pixels, or puts it back at the | ||
| 1401 | + /// top (`None`). Back to the top after every keystroke that changes the | ||
| 1402 | + /// search: a filtered list is shorter than the offset a scrolled one left | ||
| 1403 | + /// behind, and a card showing the empty space past its last row reads as a | ||
| 1404 | + /// search that found nothing. | ||
| 1405 | + /// | ||
| 1406 | + /// Clamped to what there is to scroll, so the list cannot be pushed off | ||
| 1407 | + /// either end -- `max_offset` is what the last paint measured, which is the | ||
| 1408 | + /// only place that number exists. | ||
| 1409 | + fn scroll_keys(&self, by: Option<f32>) { | ||
| 1410 | + let at = match by { | ||
| 1411 | + Some(by) => (f32::from(self.keys_scroll.offset().y) + by) | ||
| 1412 | + .clamp(-f32::from(self.keys_scroll.max_offset().height), 0.), | ||
| 1413 | + None => 0., | ||
| 1414 | + }; | ||
| 1415 | + self.keys_scroll.set_offset(point(px(0.), px(at))); | ||
| 1416 | + } | ||
| 1417 | + | ||
| 1261 | /// Whether the editor can be asked for `action` right now, and why not when | 1418 | /// Whether the editor can be asked for `action` right now, and why not when |
| 1262 | /// it cannot. `on` is the clip the question is about -- the one a clip menu | 1419 | /// it cannot. `on` is the clip the question is about -- the one a clip menu |
| 1263 | /// was opened on -- and `None` asks about the marked clip instead, which is | 1420 | /// was opened on -- and `None` asks about the marked clip instead, which is |
| @@ -2637,6 +2794,31 @@ impl Player { | |||
| 2637 | .detach(); | 2794 | .detach(); |
| 2638 | } | 2795 | } |
| 2639 | 2796 | ||
| 2797 | + /// Asks the plugin what this machine's GPU can do, once, the first time the | ||
| 2798 | + /// export card is up to show it. Off the render thread for `cache_export_seat`'s | ||
| 2799 | + /// reason: the plugin initialises VA-API to answer, and a driver that is | ||
| 2800 | + /// slow to load must not be a frame the user waits for. | ||
| 2801 | + fn cache_hw_caps(&mut self, cx: &mut Context<Self>) { | ||
| 2802 | + if !self.export_open || self.hw_caps.is_some() { | ||
| 2803 | + return; | ||
| 2804 | + } | ||
| 2805 | + // Written before the spawn, exactly as the probes above are, so the | ||
| 2806 | + // repaints during it start no second one. | ||
| 2807 | + self.hw_caps = Some("asking the driver…".into()); | ||
| 2808 | + let asked = cx | ||
| 2809 | + .background_executor() | ||
| 2810 | + .spawn(async move { engine::caps::hardware() }); | ||
| 2811 | + cx.spawn(async move |this, cx| { | ||
| 2812 | + let line = asked.await; | ||
| 2813 | + this.update(cx, |this, cx| { | ||
| 2814 | + this.hw_caps = Some(line.into()); | ||
| 2815 | + cx.notify(); | ||
| 2816 | + }) | ||
| 2817 | + .ok(); | ||
| 2818 | + }) | ||
| 2819 | + .detach(); | ||
| 2820 | + } | ||
| 2821 | + | ||
| 2640 | /// The group id of the clicked clip, which is what marks the other half. | 2822 | /// The group id of the clicked clip, which is what marks the other half. |
| 2641 | fn selected_link(&self) -> Option<u32> { | 2823 | fn selected_link(&self) -> Option<u32> { |
| 2642 | let (lane, idx) = self.selected?; | 2824 | let (lane, idx) = self.selected?; |
| @@ -2734,9 +2916,32 @@ impl Player { | |||
| 2734 | /// leave a screen of empty bed after the end, the way every NLE does. | 2916 | /// leave a screen of empty bed after the end, the way every NLE does. |
| 2735 | fn drop_frame(&self, from: Lane, idx: usize, x: Pixels) -> Option<(u32, Option<u32>)> { | 2917 | fn drop_frame(&self, from: Lane, idx: usize, x: Pixels) -> Option<(u32, Option<u32>)> { |
| 2736 | let clip = self.session.as_ref()?.lane_clips(from).get(idx).copied()?; | 2918 | let clip = self.session.as_ref()?.lane_clips(from).get(idx).copied()?; |
| 2737 | - let raw = self.frame_under(x).saturating_sub(self.grab); | ||
| 2738 | let marks = self.snap_targets(Some((from, idx))); | 2919 | let marks = self.snap_targets(Some((from, idx))); |
| 2739 | - Some(self.snap_to(raw, clip.frames(), &marks)) | 2920 | + Some(landing( |
| 2921 | + self.frame_under(x), | ||
| 2922 | + self.grab, | ||
| 2923 | + clip.frames(), | ||
| 2924 | + self.snap, | ||
| 2925 | + self.snap_frames(), | ||
| 2926 | + &marks, | ||
| 2927 | + )) | ||
| 2928 | + } | ||
| 2929 | + | ||
| 2930 | + /// The same answer for a library row on its way down: nothing is in the hand | ||
| 2931 | + /// yet, so there is no grab offset to take off and no length to snap by -- | ||
| 2932 | + /// the file's own is not known until the engine has placed it -- and only | ||
| 2933 | + /// its head lands. Asked by the line, by the ghost and by the drop itself | ||
| 2934 | + /// ([`Player::insert_source`]), so all three name one frame. | ||
| 2935 | + fn place_frame(&self, x: Pixels) -> (u32, Option<u32>) { | ||
| 2936 | + let marks = self.snap_targets(None); | ||
| 2937 | + landing( | ||
| 2938 | + self.frame_under(x), | ||
| 2939 | + 0, | ||
| 2940 | + 0, | ||
| 2941 | + self.snap, | ||
| 2942 | + self.snap_frames(), | ||
| 2943 | + &marks, | ||
| 2944 | + ) | ||
| 2740 | } | 2945 | } |
| 2741 | 2946 | ||
| 2742 | /// Which index the clip in the hand is at *now*: [`live_idx`] against the | 2947 | /// Which index the clip in the hand is at *now*: [`live_idx`] against the |
| @@ -2759,15 +2964,91 @@ impl Player { | |||
| 2759 | } | 2964 | } |
| 2760 | 2965 | ||
| 2761 | /// The same line for a library row on its way to a lane: it goes down at | 2966 | /// The same line for a library row on its way to a lane: it goes down at |
| 2762 | - /// the frame it is let go on ([`Player::insert_source`]), so that frame is | 2967 | + /// the frame it is let go on ([`Player::place_frame`]), so that frame is |
| 2763 | - /// what snaps and what is drawn. No length to snap by -- the file's own is | 2968 | + /// what snaps and what is drawn. |
| 2764 | - /// not known until the engine has placed it -- so only its head lands. | ||
| 2765 | fn preview_place(&mut self, x: Pixels, cx: &mut Context<Self>) { | 2969 | fn preview_place(&mut self, x: Pixels, cx: &mut Context<Self>) { |
| 2766 | - let marks = self.snap_targets(None); | 2970 | + let cue = self.place_frame(x).1; |
| 2767 | - let cue = self.snap_to(self.frame_under(x), 0, &marks).1; | ||
| 2768 | self.set_cue(cue, x, cx); | 2971 | self.set_cue(cue, x, cx); |
| 2769 | } | 2972 | } |
| 2770 | 2973 | ||
| 2974 | + /// The shadow the clip in the hand would fill, on the lane the pointer is | ||
| 2975 | + /// over: its head where [`Player::drop_frame`] says the release will put it | ||
| 2976 | + /// -- the same call the drop makes, so the box drawn and the box committed | ||
| 2977 | + /// are one answer -- and its own length at this zoom. A lane of the other | ||
| 2978 | + /// kind refuses the drop ([`Project::move_clip`]), and the shadow says so | ||
| 2979 | + /// before the release does. | ||
| 2980 | + fn preview_ghost(&mut self, drag: &ClipDrag, to: Lane, x: Pixels, cx: &mut Context<Self>) { | ||
| 2981 | + let ghost = self | ||
| 2982 | + .dragged(drag) | ||
| 2983 | + .and_then(|idx| self.drop_frame(drag.lane, idx, x)) | ||
| 2984 | + .map(|(start, _)| Ghost { | ||
| 2985 | + lane: to, | ||
| 2986 | + start, | ||
| 2987 | + frames: drag.clip.frames(), | ||
| 2988 | + tint: self.clip_tint(drag.clip.source), | ||
| 2989 | + refused: drag.lane.kind != to.kind, | ||
| 2990 | + }); | ||
| 2991 | + self.set_ghost(ghost, cx); | ||
| 2992 | + } | ||
| 2993 | + | ||
| 2994 | + /// The same shadow for a library row: its head at [`Player::place_frame`], | ||
| 2995 | + /// which is where the drop inserts it, and the file's own length for its | ||
| 2996 | + /// width -- the length the library row already reports. A file this lane | ||
| 2997 | + /// cannot hold ([`lane_refuses`]) is tinted as refused, which is the answer | ||
| 2998 | + /// the release would give in words. | ||
| 2999 | + fn preview_ghost_asset(&mut self, path: &Path, to: Lane, x: Pixels, cx: &mut Context<Self>) { | ||
| 3000 | + let ghost = Ghost { | ||
| 3001 | + lane: to, | ||
| 3002 | + start: self.place_frame(x).0, | ||
| 3003 | + frames: self | ||
| 3004 | + .session | ||
| 3005 | + .as_ref() | ||
| 3006 | + .map_or(0, |session| session.file_frames(path)), | ||
| 3007 | + tint: self.file_tint(path), | ||
| 3008 | + refused: lane_refuses(path, to).is_some(), | ||
| 3009 | + }; | ||
| 3010 | + self.set_ghost(Some(ghost), cx); | ||
| 3011 | + } | ||
| 3012 | + | ||
| 3013 | + /// Sets the shadow, or takes it away, repainting only when it moved -- the | ||
| 3014 | + /// listeners below run it on every pointer sample of a drag. Cleared by the | ||
| 3015 | + /// root and set again by the lane under the pointer, in that order (gpui | ||
| 3016 | + /// runs the capture phase parent-first), so a pointer over no lane at all | ||
| 3017 | + /// leaves nothing drawn. | ||
| 3018 | + fn set_ghost(&mut self, ghost: Option<Ghost>, cx: &mut Context<Self>) { | ||
| 3019 | + if ghost != self.ghost { | ||
| 3020 | + self.ghost = ghost; | ||
| 3021 | + cx.notify(); | ||
| 3022 | + } | ||
| 3023 | + } | ||
| 3024 | + | ||
| 3025 | + /// The swatch a clip from source `n` wears: [`source_tint`] over the first | ||
| 3026 | + /// source entry naming that *file*, since two audio streams of one file are | ||
| 3027 | + /// two sources and one colour. Every box on a lane and every ghost a drag | ||
| 3028 | + /// draws asks this, so the shadow is recognisably the thing in the hand. | ||
| 3029 | + fn clip_tint(&self, source: usize) -> u32 { | ||
| 3030 | + match self.sources().get(source) { | ||
| 3031 | + Some(entry) => self.file_tint(&entry.path), | ||
| 3032 | + None => source_tint(source), | ||
| 3033 | + } | ||
| 3034 | + } | ||
| 3035 | + | ||
| 3036 | + /// The same swatch asked by path, which is what a library row is named by. | ||
| 3037 | + fn file_tint(&self, path: &Path) -> u32 { | ||
| 3038 | + source_tint( | ||
| 3039 | + self.sources() | ||
| 3040 | + .iter() | ||
| 3041 | + .position(|s| s.path == path) | ||
| 3042 | + .unwrap_or(0), | ||
| 3043 | + ) | ||
| 3044 | + } | ||
| 3045 | + | ||
| 3046 | + fn sources(&self) -> &[Source] { | ||
| 3047 | + self.session | ||
| 3048 | + .as_ref() | ||
| 3049 | + .map_or(&[][..], PlaybackSession::sources) | ||
| 3050 | + } | ||
| 3051 | + | ||
| 2771 | /// Sets the line, or takes it away, and repaints only when it moved: a | 3052 | /// Sets the line, or takes it away, and repaints only when it moved: a |
| 2772 | /// pointer dragged off the bed (up to the library, say) is not promising a | 3053 | /// pointer dragged off the bed (up to the library, say) is not promising a |
| 2773 | /// landing any more. | 3054 | /// landing any more. |
| @@ -2991,28 +3272,13 @@ impl Player { | |||
| 2991 | if self.exporting().is_some() { | 3272 | if self.exporting().is_some() { |
| 2992 | return; | 3273 | return; |
| 2993 | } | 3274 | } |
| 2994 | - // A file with no picture belongs on an audio lane and nowhere else: | 3275 | + // The lane the pointer named cannot hold this kind of file: refused by |
| 2995 | - // dropped on a video lane it is refused by name, and asked for by the | 3276 | + // name, in the same words the ghost was tinted by on the way down |
| 2996 | - // Add button (which names no lane) it goes to the audio one -- which is | 3277 | + // ([`lane_refuses`]). The Add button names no lane and so is never |
| 2997 | - // the engine's choice, in `place_stream_at`, not one made twice here. | 3278 | + // refused here -- where a file goes when nobody says is the engine's |
| 2998 | - if engine::is_audio(path) && onto.is_some_and(|lane| lane.kind == LaneKind::Video) { | 3279 | + // choice, in `place_stream_at`, not one made twice here. |
| 2999 | - let name = file_name(path); | 3280 | + if let Some(why) = onto.and_then(|lane| lane_refuses(path, lane)) { |
| 3000 | - let lane = onto.expect("checked above").label(); | 3281 | + self.notice = Some(why.into()); |
| 3001 | - self.notice = Some( | ||
| 3002 | - format!("NOT ON {lane} — {name} has no picture; drop it on an audio lane").into(), | ||
| 3003 | - ); | ||
| 3004 | - cx.notify(); | ||
| 3005 | - return; | ||
| 3006 | - } | ||
| 3007 | - // ...and the mirror of it: a still is silent, so an audio lane is the | ||
| 3008 | - // one place it cannot go. The engine puts it on `V1` regardless | ||
| 3009 | - // (`place_stream_at`); this is the word that says why it moved. | ||
| 3010 | - if engine::is_image(path) && onto.is_some_and(|lane| lane.kind == LaneKind::Audio) { | ||
| 3011 | - let name = file_name(path); | ||
| 3012 | - let lane = onto.expect("checked above").label(); | ||
| 3013 | - self.notice = Some( | ||
| 3014 | - format!("NOT ON {lane} — {name} is a still image; drop it on a video lane").into(), | ||
| 3015 | - ); | ||
| 3016 | cx.notify(); | 3282 | cx.notify(); |
| 3017 | return; | 3283 | return; |
| 3018 | } | 3284 | } |
| @@ -3789,6 +4055,10 @@ impl Player { | |||
| 3789 | } | 4055 | } |
| 3790 | session.pause(); | 4056 | session.pause(); |
| 3791 | self.export = Some(session.export_to_with(&self.export_path, &settings)); | 4057 | self.export = Some(session.export_to_with(&self.export_path, &settings)); |
| 4058 | + // The clock starts with the worker, not with the first repaint that | ||
| 4059 | + // happens to notice it. | ||
| 4060 | + self.export_started = Some(Instant::now()); | ||
| 4061 | + self.export_marks.clear(); | ||
| 3792 | // The card has been answered; the progress line takes the panel from | 4062 | // The card has been answered; the progress line takes the panel from |
| 3793 | // here, and it is the running export's escape that matters now. | 4063 | // here, and it is the running export's escape that matters now. |
| 3794 | self.export_open = false; | 4064 | self.export_open = false; |
| @@ -3807,10 +4077,23 @@ impl Player { | |||
| 3807 | /// Takes the export's verdict once it has one. The only place the app | 4077 | /// Takes the export's verdict once it has one. The only place the app |
| 3808 | /// touches the handle's completion side. | 4078 | /// touches the handle's completion side. |
| 3809 | fn poll_export(&mut self) { | 4079 | fn poll_export(&mut self) { |
| 4080 | + // Sampled here rather than while drawing: a repaint stays a repaint, | ||
| 4081 | + // and this runs once per repaint either way. | ||
| 4082 | + if let (Some(progress), Some(started)) = ( | ||
| 4083 | + self.exporting().map(ExportHandle::progress), | ||
| 4084 | + self.export_started, | ||
| 4085 | + ) { | ||
| 4086 | + note_progress( | ||
| 4087 | + &mut self.export_marks, | ||
| 4088 | + started.elapsed().as_secs_f32(), | ||
| 4089 | + progress, | ||
| 4090 | + ); | ||
| 4091 | + } | ||
| 3810 | let Some(result) = self.export.as_ref().and_then(ExportHandle::result) else { | 4092 | let Some(result) = self.export.as_ref().and_then(ExportHandle::result) else { |
| 3811 | return; | 4093 | return; |
| 3812 | }; | 4094 | }; |
| 3813 | self.export = None; | 4095 | self.export = None; |
| 4096 | + self.export_started = None; | ||
| 3814 | // A cancellation is reported as an error, and the one who asked for it | 4097 | // A cancellation is reported as an error, and the one who asked for it |
| 3815 | // has had the editor back since the keystroke. Nothing to say. | 4098 | // has had the editor back since the keystroke. Nothing to say. |
| 3816 | if std::mem::take(&mut self.cancelling) { | 4099 | if std::mem::take(&mut self.cancelling) { |
| @@ -3845,6 +4128,7 @@ impl Render for Player { | |||
| 3845 | // is the one place that has to notice a new one. | 4128 | // is the one place that has to notice a new one. |
| 3846 | self.cache_media(cx); | 4129 | self.cache_media(cx); |
| 3847 | self.cache_export_seat(cx); | 4130 | self.cache_export_seat(cx); |
| 4131 | + self.cache_hw_caps(cx); | ||
| 3848 | // What the compositor calls this window. Pushed only when it changes: | 4132 | // What the compositor calls this window. Pushed only when it changes: |
| 3849 | // it is a protocol round trip and this runs at vsync. | 4133 | // it is a protocol round trip and this runs at vsync. |
| 3850 | let title = window_title(&self.name); | 4134 | let title = window_title(&self.name); |
| @@ -3930,14 +4214,37 @@ impl Render for Player { | |||
| 3930 | cx.notify(); | 4214 | cx.notify(); |
| 3931 | return; | 4215 | return; |
| 3932 | } | 4216 | } |
| 3933 | - // The overlay owns the keyboard while it is up: a stroke aimed | 4217 | + // The overlay owns the keyboard while it is up -- but it types |
| 3934 | - // at a row must not also cut the timeline, and the way out of it | 4218 | + // now: a printable stroke is the search box's, which is why |
| 3935 | - // is the same key that gets out of a capture. | 4219 | + // nothing here reaches the keymap. A waiting row is answered |
| 4220 | + // above and still wins, so a rebind onto "v" binds the key | ||
| 4221 | + // rather than typing it. | ||
| 3936 | if this.keys_open { | 4222 | if this.keys_open { |
| 3937 | if key == ESCAPE { | 4223 | if key == ESCAPE { |
| 3938 | - this.keys_open = false; | 4224 | + // Two steps out, the way a search box anywhere gets |
| 3939 | - cx.notify(); | 4225 | + // out: the filter first -- the whole list back -- |
| 4226 | + // and the card only once there is no search to clear. | ||
| 4227 | + if this.keys_search.is_empty() { | ||
| 4228 | + this.keys_open = false; | ||
| 4229 | + } else { | ||
| 4230 | + this.keys_search.clear(); | ||
| 4231 | + this.scroll_keys(None); | ||
| 4232 | + } | ||
| 4233 | + // The rows past the fold, without a wheel: forty actions | ||
| 4234 | + // are four times what the viewport shows, and the hand | ||
| 4235 | + // typing in the search box is already on the keyboard. | ||
| 4236 | + } else if key == "up" { | ||
| 4237 | + this.scroll_keys(Some(KEYS_ROW_H)); | ||
| 4238 | + } else if key == "down" { | ||
| 4239 | + this.scroll_keys(Some(-KEYS_ROW_H)); | ||
| 4240 | + } else if key == "backspace" { | ||
| 4241 | + this.keys_search.pop(); | ||
| 4242 | + this.scroll_keys(None); | ||
| 4243 | + } else if let Some(c) = typed(key) { | ||
| 4244 | + this.keys_search.push(c); | ||
| 4245 | + this.scroll_keys(None); | ||
| 3940 | } | 4246 | } |
| 4247 | + cx.notify(); | ||
| 3941 | return; | 4248 | return; |
| 3942 | } | 4249 | } |
| 3943 | // The export card owns it the same way, and for the same | 4250 | // The export card owns it the same way, and for the same |
| @@ -4212,10 +4519,18 @@ impl Render for Player { | |||
| 4212 | if let Some(idx) = this.dragged(&drag) { | 4519 | if let Some(idx) = this.dragged(&drag) { |
| 4213 | this.preview_drop(drag.lane, idx, event.event.position.x, cx); | 4520 | this.preview_drop(drag.lane, idx, event.event.position.x, cx); |
| 4214 | } | 4521 | } |
| 4522 | + // The shadow belongs to a *lane*, and which lane the pointer is | ||
| 4523 | + // over is the one thing this element cannot see. Cleared here | ||
| 4524 | + // and drawn again by the lane the pointer is actually inside | ||
| 4525 | + // (`lane_row`), which gpui runs straight after this one: the | ||
| 4526 | + // capture phase goes parent first, so a pointer over no lane at | ||
| 4527 | + // all -- up in the library, say -- promises nothing. | ||
| 4528 | + this.set_ghost(None, cx); | ||
| 4215 | })) | 4529 | })) |
| 4216 | .on_drag_move( | 4530 | .on_drag_move( |
| 4217 | cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| { | 4531 | cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| { |
| 4218 | this.preview_place(event.event.position.x, cx); | 4532 | this.preview_place(event.event.position.x, cx); |
| 4533 | + this.set_ghost(None, cx); | ||
| 4219 | }), | 4534 | }), |
| 4220 | ) | 4535 | ) |
| 4221 | // Scrubbing is tracked on the root because the pointer leaves the | 4536 | // Scrubbing is tracked on the root because the pointer leaves the |
| @@ -4745,10 +5060,25 @@ impl Player { | |||
| 4745 | } | 5060 | } |
| 4746 | let (hint, filled) = if let Some(export) = self.exporting() { | 5061 | let (hint, filled) = if let Some(export) = self.exporting() { |
| 4747 | let progress = export.progress(); | 5062 | let progress = export.progress(); |
| 5063 | + let elapsed = self | ||
| 5064 | + .export_started | ||
| 5065 | + .map_or(0., |t| t.elapsed().as_secs_f32()); | ||
| 5066 | + // Two numbers that must both be honest: the one that counts up is | ||
| 5067 | + // measured, the one that counts down is a guess and says so. | ||
| 5068 | + let left = eta_secs(&self.export_marks, elapsed, progress).map_or_else( | ||
| 5069 | + || "estimating…".to_owned(), | ||
| 5070 | + |s| format!("~{} left", clock(s)), | ||
| 5071 | + ); | ||
| 4748 | ( | 5072 | ( |
| 4749 | format!( | 5073 | format!( |
| 4750 | - "EXPORTING {}% · {} · {} — {} cancels", | 5074 | + // Clocks, then the way out, then what is encoding: at the |
| 5075 | + // 640 px floor the tail is what truncation eats, and the | ||
| 5076 | + // codec pair is the one part of this line the card already | ||
| 5077 | + // said. The escape must not be what goes missing. | ||
| 5078 | + "EXPORTING {}% · {} elapsed · {left} — {} cancels · {} · {}", | ||
| 4751 | (progress * 100.) as u32, | 5079 | (progress * 100.) as u32, |
| 5080 | + clock(elapsed), | ||
| 5081 | + key(ActionId::CancelExport), | ||
| 4752 | // The row that was picked; the engine's line below names the | 5082 | // The row that was picked; the engine's line below names the |
| 4753 | // seats alone, since the library is what identifies a codec. | 5083 | // seats alone, since the library is what identifies a codec. |
| 4754 | format_label(self.format), | 5084 | format_label(self.format), |
| @@ -4757,7 +5087,6 @@ impl Player { | |||
| 4757 | export | 5087 | export |
| 4758 | .encoders() | 5088 | .encoders() |
| 4759 | .unwrap_or_else(|| "opening the encoder".to_string()), | 5089 | .unwrap_or_else(|| "opening the encoder".to_string()), |
| 4760 | - key(ActionId::CancelExport) | ||
| 4761 | ), | 5090 | ), |
| 4762 | progress, | 5091 | progress, |
| 4763 | ) | 5092 | ) |
| @@ -5052,23 +5381,27 @@ impl Player { | |||
| 5052 | live, | 5381 | live, |
| 5053 | cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)), | 5382 | cx.listener(|this, _: &ClickEvent, _, cx| this.save_project(cx)), |
| 5054 | )) | 5383 | )) |
| 5055 | - // No shortcut of its own -- and closed while an export runs, | 5384 | + // Closed while an export runs, which is what keeps a waiting |
| 5056 | - // which is what keeps a waiting row from swallowing the | 5385 | + // row from swallowing the escape the progress line promises |
| 5057 | - // escape the progress line promises cancels the export. | 5386 | + // cancels the export. |
| 5058 | .child(control( | 5387 | .child(control( |
| 5059 | "keys", | 5388 | "keys", |
| 5060 | None, | 5389 | None, |
| 5061 | "Actions", | 5390 | "Actions", |
| 5062 | // The pointer's way to every action there is, including | 5391 | // The pointer's way to every action there is, including |
| 5063 | // the ones no button here has room for. | 5392 | // the ones no button here has room for. |
| 5064 | - "do any action, or change the key that does it".to_string(), | 5393 | + format!( |
| 5394 | + "{} — do any action, or change the key that does it", | ||
| 5395 | + key(ActionId::ShowActions) | ||
| 5396 | + ), | ||
| 5065 | !exporting, | 5397 | !exporting, |
| 5066 | - cx.listener(|this, _: &ClickEvent, _, cx| { | 5398 | + cx.listener(|this, _: &ClickEvent, _, cx| match this.keys_open { |
| 5067 | - this.keys_open = !this.keys_open; | 5399 | + true => { |
| 5068 | - this.rebinding = None; | 5400 | + this.keys_open = false; |
| 5069 | - // One card at a time, both ways round. | 5401 | + this.rebinding = None; |
| 5070 | - this.export_open = false; | 5402 | + cx.notify(); |
| 5071 | - cx.notify(); | 5403 | + } |
| 5404 | + false => this.show_actions(cx), | ||
| 5072 | }), | 5405 | }), |
| 5073 | )), | 5406 | )), |
| 5074 | ) | 5407 | ) |
| @@ -5302,7 +5635,26 @@ impl Player { | |||
| 5302 | .px(px(6.)) | 5635 | .px(px(6.)) |
| 5303 | .rounded(px(3.)) | 5636 | .rounded(px(3.)) |
| 5304 | }; | 5637 | }; |
| 5305 | - for (i, key_row) in keys_rows().into_iter().enumerate() { | 5638 | + let found = keys_filter(&self.keys_search, &self.keymap); |
| 5639 | + // What the search box says: the typed text, and how much of the list is | ||
| 5640 | + // left under it -- a filter that found nothing has to say so, or the | ||
| 5641 | + // card reads as a list that lost its rows. | ||
| 5642 | + let search = if self.keys_search.is_empty() { | ||
| 5643 | + "search: type to filter · ↑ ↓ scroll the list".to_string() | ||
| 5644 | + } else { | ||
| 5645 | + let rows = found | ||
| 5646 | + .iter() | ||
| 5647 | + .filter(|(_, r)| !matches!(r, KeyRow::Head(_))) | ||
| 5648 | + .count(); | ||
| 5649 | + match rows { | ||
| 5650 | + 0 => format!( | ||
| 5651 | + "search: {} — nothing matches · {out} clears", | ||
| 5652 | + self.keys_search | ||
| 5653 | + ), | ||
| 5654 | + n => format!("search: {} — {n} shown · {out} clears", self.keys_search), | ||
| 5655 | + } | ||
| 5656 | + }; | ||
| 5657 | + for (i, key_row) in found { | ||
| 5306 | rows.push(match key_row { | 5658 | rows.push(match key_row { |
| 5307 | KeyRow::Head(category) => div() | 5659 | KeyRow::Head(category) => div() |
| 5308 | .flex_none() | 5660 | .flex_none() |
| @@ -5440,6 +5792,19 @@ impl Player { | |||
| 5440 | }), | 5792 | }), |
| 5441 | ), | 5793 | ), |
| 5442 | ) | 5794 | ) |
| 5795 | + // The search box: no focus and no text field -- the | ||
| 5796 | + // card's key handler is the field, exactly as the | ||
| 5797 | + // export card's digits are typed into it. Its own line | ||
| 5798 | + // above the list, so the rows below it are always the | ||
| 5799 | + // answer to what it says. | ||
| 5800 | + .child( | ||
| 5801 | + div() | ||
| 5802 | + .flex_none() | ||
| 5803 | + .px(px(6.)) | ||
| 5804 | + .text_size(px(11.)) | ||
| 5805 | + .text_color(rgb(INK_DIM)) | ||
| 5806 | + .child(search), | ||
| 5807 | + ) | ||
| 5443 | // Capped and scrolling rather than as tall as the action | 5808 | // Capped and scrolling rather than as tall as the action |
| 5444 | // list happens to be: the list grows with the editor, | 5809 | // list happens to be: the list grows with the editor, |
| 5445 | // the smallest window does not. | 5810 | // the smallest window does not. |
| @@ -5451,6 +5816,10 @@ impl Player { | |||
| 5451 | .gap(px(2.)) | 5816 | .gap(px(2.)) |
| 5452 | .max_h(px(KEYS_ROWS_H)) | 5817 | .max_h(px(KEYS_ROWS_H)) |
| 5453 | .overflow_y_scroll() | 5818 | .overflow_y_scroll() |
| 5819 | + // The wheel's offset and the arrow keys' are | ||
| 5820 | + // the same one, so the two cannot disagree | ||
| 5821 | + // about where the list is. | ||
| 5822 | + .track_scroll(&self.keys_scroll) | ||
| 5454 | .children(rows), | 5823 | .children(rows), |
| 5455 | ), | 5824 | ), |
| 5456 | ), | 5825 | ), |
| @@ -5741,6 +6110,30 @@ impl Player { | |||
| 5741 | .into_any_element(), | 6110 | .into_any_element(), |
| 5742 | ); | 6111 | ); |
| 5743 | } | 6112 | } |
| 6113 | + // What is doing the work, on this machine and in this build: the GPU | ||
| 6114 | + // half is asked of the driver through the plugin (a different answer on | ||
| 6115 | + // every machine, and "none" where there is no plugin at all), the build | ||
| 6116 | + // half is the crates that were compiled in. Last in the list, because it | ||
| 6117 | + // is what a user checks rather than what they pick -- and a listing | ||
| 6118 | + // rather than rows, since none of it can be clicked. | ||
| 6119 | + if self.export_grouped { | ||
| 6120 | + list.push(header("THIS MACHINE")); | ||
| 6121 | + } | ||
| 6122 | + let note = |text: String| { | ||
| 6123 | + div() | ||
| 6124 | + .flex_none() | ||
| 6125 | + .px(px(6.)) | ||
| 6126 | + .py(px(2.)) | ||
| 6127 | + .text_size(px(11.)) | ||
| 6128 | + .text_color(rgb(INK_DIM)) | ||
| 6129 | + .child(text) | ||
| 6130 | + .into_any_element() | ||
| 6131 | + }; | ||
| 6132 | + list.push(note(format!( | ||
| 6133 | + "GPU: {}", | ||
| 6134 | + self.hw_caps.clone().unwrap_or_else(|| "asking…".into()) | ||
| 6135 | + ))); | ||
| 6136 | + list.push(note(format!("Built in: {}", engine::caps::software()))); | ||
| 5744 | // What the rows add up to, which is the one thing that has to be right: | 6137 | // What the rows add up to, which is the one thing that has to be right: |
| 5745 | // codec, box, size, rate, sound, where it goes and about how big. Two | 6138 | // codec, box, size, rate, sound, where it goes and about how big. Two |
| 5746 | // lines, outside the scrolling list, so it is on screen whatever the | 6139 | // lines, outside the scrolling list, so it is on screen whatever the |
| @@ -7519,6 +7912,11 @@ impl Player { | |||
| 7519 | .snap_cue | 7912 | .snap_cue |
| 7520 | .filter(|_| self.trim.is_some() || cx.has_active_drag()) | 7913 | .filter(|_| self.trim.is_some() || cx.has_active_drag()) |
| 7521 | .map(|frame| scale.px_at(f64::from(frame) / self.fps)); | 7914 | .map(|frame| scale.px_at(f64::from(frame) / self.fps)); |
| 7915 | + // The shadow, on the one lane the pointer is over -- and, like the line, | ||
| 7916 | + // only while the drag that asked for it is still in flight. | ||
| 7917 | + let ghost = self | ||
| 7918 | + .ghost | ||
| 7919 | + .filter(|g| g.lane == lane && cx.has_active_drag()); | ||
| 7522 | let clips = self | 7920 | let clips = self |
| 7523 | .session | 7921 | .session |
| 7524 | .as_ref() | 7922 | .as_ref() |
| @@ -7668,12 +8066,26 @@ impl Player { | |||
| 7668 | // Onto the edges near it, exactly as a clip carried by | 8066 | // Onto the edges near it, exactly as a clip carried by |
| 7669 | // hand lands: the line drawn while it was in flight is | 8067 | // hand lands: the line drawn while it was in flight is |
| 7670 | // the frame it goes down on. | 8068 | // the frame it goes down on. |
| 7671 | - let x = window.mouse_position().x; | 8069 | + let at = this.place_frame(window.mouse_position().x).0; |
| 7672 | - let marks = this.snap_targets(None); | ||
| 7673 | - let (at, _) = this.snap_to(this.frame_under(x), 0, &marks); | ||
| 7674 | this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) | 8070 | this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) |
| 7675 | })) | 8071 | })) |
| 7676 | .drag_over::<AssetDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) | 8072 | .drag_over::<AssetDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) |
| 8073 | + // The shadow of the row in flight, drawn by the lane the | ||
| 8074 | + // pointer is inside: `on_drag_move` fires on every painted | ||
| 8075 | + // element while a drag of its type is live, wherever the | ||
| 8076 | + // pointer is, and hands each one its own box -- which is how | ||
| 8077 | + // a lane knows the pointer is over *it* (gpui div.rs:282). | ||
| 8078 | + // The root cleared it a moment ago, so exactly one lane | ||
| 8079 | + // draws one. | ||
| 8080 | + .on_drag_move(cx.listener( | ||
| 8081 | + move |this, event: &DragMoveEvent<AssetDrag>, _, cx| { | ||
| 8082 | + if !event.bounds.contains(&event.event.position) { | ||
| 8083 | + return; | ||
| 8084 | + } | ||
| 8085 | + let path = event.drag(cx).0.clone(); | ||
| 8086 | + this.preview_ghost_asset(&path, lane, event.event.position.x, cx); | ||
| 8087 | + }, | ||
| 8088 | + )) | ||
| 7677 | // ...and a clip let go over a lane lands the same way: on | 8089 | // ...and a clip let go over a lane lands the same way: on |
| 7678 | // the track it was dropped on, at the frame it was carried | 8090 | // the track it was dropped on, at the frame it was carried |
| 7679 | // to -- its own included, which is the drag that moves a | 8091 | // to -- its own included, which is the drag that moves a |
| @@ -7689,6 +8101,17 @@ impl Player { | |||
| 7689 | this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx) | 8101 | this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx) |
| 7690 | })) | 8102 | })) |
| 7691 | .drag_over::<ClipDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) | 8103 | .drag_over::<ClipDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) |
| 8104 | + // ...and the same shadow for the clip in the hand, seated on | ||
| 8105 | + // this lane when the pointer is inside it. | ||
| 8106 | + .on_drag_move(cx.listener( | ||
| 8107 | + move |this, event: &DragMoveEvent<ClipDrag>, _, cx| { | ||
| 8108 | + if !event.bounds.contains(&event.event.position) { | ||
| 8109 | + return; | ||
| 8110 | + } | ||
| 8111 | + let drag = *event.drag(cx); | ||
| 8112 | + this.preview_ghost(&drag, lane, event.event.position.x, cx); | ||
| 8113 | + }, | ||
| 8114 | + )) | ||
| 7692 | .children(clips.iter().enumerate().map(|(i, clip)| { | 8115 | .children(clips.iter().enumerate().map(|(i, clip)| { |
| 7693 | // The clip as the lane holds it, for the drag payload: | 8116 | // The clip as the lane holds it, for the drag payload: |
| 7694 | // what a drop looks itself up by has to be the placed | 8117 | // what a drop looks itself up by has to be the placed |
| @@ -7712,12 +8135,7 @@ impl Player { | |||
| 7712 | // Tinted by *file*, not by source entry: two audio | 8135 | // Tinted by *file*, not by source entry: two audio |
| 7713 | // streams of one file are two sources, and the library | 8136 | // streams of one file are two sources, and the library |
| 7714 | // gives them one swatch because they are one file. | 8137 | // gives them one swatch because they are one file. |
| 7715 | - let tint = source_tint( | 8138 | + let tint = self.clip_tint(clip.source); |
| 7716 | - sources | ||
| 7717 | - .get(clip.source) | ||
| 7718 | - .and_then(|s| sources.iter().position(|o| o.path == s.path)) | ||
| 7719 | - .unwrap_or(clip.source), | ||
| 7720 | - ); | ||
| 7721 | let width = scale.width_px(len); | 8139 | let width = scale.width_px(len); |
| 7722 | let left = scale.px_at(start); | 8140 | let left = scale.px_at(start); |
| 7723 | // The slice of this box that is on the bed: where its | 8141 | // The slice of this box that is on the bed: where its |
| @@ -7965,6 +8383,34 @@ impl Player { | |||
| 7965 | .bg(rgba(0x4a9effaa)) | 8383 | .bg(rgba(0x4a9effaa)) |
| 7966 | }), | 8384 | }), |
| 7967 | ) | 8385 | ) |
| 8386 | + // Where the thing in the hand would come to rest, at the size | ||
| 8387 | + // it would come to rest at: the shadow a proper editor draws | ||
| 8388 | + // under a drag. Over the clips (it is translucent, so what | ||
| 8389 | + // it would cover shows through) and under the line, which | ||
| 8390 | + // marks the frame this box merely fills. | ||
| 8391 | + .children(ghost.map(|g| { | ||
| 8392 | + div() | ||
| 8393 | + .absolute() | ||
| 8394 | + .top_0() | ||
| 8395 | + .h_full() | ||
| 8396 | + .left(px(scale.px_at(f64::from(g.start) / self.fps))) | ||
| 8397 | + // A row whose length the engine has not measured | ||
| 8398 | + // draws a head marker rather than nothing: where it | ||
| 8399 | + // lands is known, how long it is is not. | ||
| 8400 | + .w(px(scale | ||
| 8401 | + .width_px(f64::from(g.frames) / self.fps) | ||
| 8402 | + .max(GHOST_MIN))) | ||
| 8403 | + .rounded(px(3.)) | ||
| 8404 | + .border_1() | ||
| 8405 | + .border_color(rgb(if g.refused { REFUSE } else { INK })) | ||
| 8406 | + // The file's own swatch at a third of its weight, so | ||
| 8407 | + // the box beneath is still legible through it -- and | ||
| 8408 | + // the refusal red instead, for a lane that will not | ||
| 8409 | + // take this drop at all. | ||
| 8410 | + .bg(rgba( | ||
| 8411 | + ((if g.refused { REFUSE } else { g.tint }) << 8) | GHOST_ALPHA, | ||
| 8412 | + )) | ||
| 8413 | + })) | ||
| 7968 | // What the gesture in flight is about to land on, drawn on | 8414 | // What the gesture in flight is about to land on, drawn on |
| 7969 | // every lane so a clip lining up with a take one track over | 8415 | // every lane so a clip lining up with a take one track over |
| 7970 | // can be seen to line up with it. Under the playhead's line | 8416 | // can be seen to line up with it. Under the playhead's line |
| @@ -8334,6 +8780,17 @@ struct Ctx { | |||
| 8334 | /// disagree about what an action needs -- exactly the reason [`Player::act`] is | 8780 | /// disagree about what an action needs -- exactly the reason [`Player::act`] is |
| 8335 | /// one table too. | 8781 | /// one table too. |
| 8336 | fn enable(action: ActionId, ctx: Ctx) -> Enable { | 8782 | fn enable(action: ActionId, ctx: Ctx) -> Enable { |
| 8783 | + // The one action that is about the editor rather than about the timeline: | ||
| 8784 | + // the list of what everything does, and where a key is changed. An empty | ||
| 8785 | + // window has no clips and still has keys -- so this answers ahead of the | ||
| 8786 | + // timeline question, and only an export shuts it (a waiting row would | ||
| 8787 | + // swallow the escape the progress line promises cancels the export). | ||
| 8788 | + if action == ActionId::ShowActions { | ||
| 8789 | + return match ctx.exporting { | ||
| 8790 | + true => Enable::No("an export is running"), | ||
| 8791 | + false => Enable::Yes, | ||
| 8792 | + }; | ||
| 8793 | + } | ||
| 8337 | if !ctx.timeline { | 8794 | if !ctx.timeline { |
| 8338 | return Enable::No("no timeline open"); | 8795 | return Enable::No("no timeline open"); |
| 8339 | } | 8796 | } |
| @@ -10023,6 +10480,44 @@ fn snap_cue(on: bool, raw: u32, len: u32, tol: u32, marks: &[u32]) -> (u32, Opti | |||
| 10023 | (start, mark) | 10480 | (start, mark) |
| 10024 | } | 10481 | } |
| 10025 | 10482 | ||
| 10483 | +/// Where a drag lands and the mark that pulled it there: the frame under the | ||
| 10484 | +/// pointer, less however far into the box the hand grabbed it (so a clip travels | ||
| 10485 | +/// with the pointer rather than jumping its head under it), snapped by | ||
| 10486 | +/// [`snap_cue`]. One answer, asked by the shadow drawn in flight | ||
| 10487 | +/// ([`Player::preview_ghost`]), by the line ([`Player::preview_drop`]) and by | ||
| 10488 | +/// the drop that commits ([`Player::move_clip`]) -- which is what makes the | ||
| 10489 | +/// promise and the landing the same frame. | ||
| 10490 | +fn landing( | ||
| 10491 | + under: u32, | ||
| 10492 | + grab: u32, | ||
| 10493 | + len: u32, | ||
| 10494 | + on: bool, | ||
| 10495 | + tol: u32, | ||
| 10496 | + marks: &[u32], | ||
| 10497 | +) -> (u32, Option<u32>) { | ||
| 10498 | + snap_cue(on, under.saturating_sub(grab), len, tol, marks) | ||
| 10499 | +} | ||
| 10500 | + | ||
| 10501 | +/// Why this file may not go on that lane, in the words the refusal is told in -- | ||
| 10502 | +/// `None` when it may. A file with no picture belongs on an audio lane and | ||
| 10503 | +/// nowhere else, and a still is silent, so an audio lane is the one place it | ||
| 10504 | +/// cannot go. Asked twice: by the ghost tinting itself as refused on the way | ||
| 10505 | +/// down, and by the insert that commits ([`Player::insert_source`]), so what is | ||
| 10506 | +/// shown as impossible is exactly what is refused. | ||
| 10507 | +fn lane_refuses(path: &Path, lane: Lane) -> Option<String> { | ||
| 10508 | + let name = file_name(path); | ||
| 10509 | + let label = lane.label(); | ||
| 10510 | + match lane.kind { | ||
| 10511 | + LaneKind::Video if engine::is_audio(path) => { | ||
| 10512 | + Some(format!("NOT ON {label} — {name} has no picture; drop it on an audio lane")) | ||
| 10513 | + } | ||
| 10514 | + LaneKind::Audio if engine::is_image(path) => { | ||
| 10515 | + Some(format!("NOT ON {label} — {name} is a still image; drop it on a video lane")) | ||
| 10516 | + } | ||
| 10517 | + _ => None, | ||
| 10518 | + } | ||
| 10519 | +} | ||
| 10520 | + | ||
| 10026 | /// Where down an element a pointer sits, 0..1 from the top: the vertical twin | 10521 | /// Where down an element a pointer sits, 0..1 from the top: the vertical twin |
| 10027 | /// of [`frac_along`], for the equalizer, whose gain axis is the y one. An | 10522 | /// of [`frac_along`], for the equalizer, whose gain axis is the y one. An |
| 10028 | /// element that was never painted reads as its middle -- flat, the one answer | 10523 | /// element that was never painted reads as its middle -- flat, the one answer |
| @@ -10373,6 +10868,57 @@ fn timecode(t: f64, fps: f64) -> String { | |||
| 10373 | ) | 10868 | ) |
| 10374 | } | 10869 | } |
| 10375 | 10870 | ||
| 10871 | +/// Wall clock for a progress line: `M:SS`, minutes past the hour included | ||
| 10872 | +/// rather than an hours field nobody reads on an export. | ||
| 10873 | +fn clock(secs: f32) -> String { | ||
| 10874 | + let secs = secs.max(0.) as u64; | ||
| 10875 | + format!("{}:{:02}", secs / 60, secs % 60) | ||
| 10876 | +} | ||
| 10877 | + | ||
| 10878 | +/// How often a progress mark is worth keeping, how far back the rate is | ||
| 10879 | +/// measured, and the least span that may answer at all. An export crosses | ||
| 10880 | +/// hardware and software segments that run at different speeds, so the | ||
| 10881 | +/// estimate is a window's average and never the instant's. | ||
| 10882 | +const ETA_SAMPLE: f32 = 0.5; | ||
| 10883 | +const ETA_WINDOW: f32 = 8.; | ||
| 10884 | +const ETA_SPAN: f32 = 1.5; | ||
| 10885 | + | ||
| 10886 | +/// Records where the export has got to and forgets what has fallen out of the | ||
| 10887 | +/// window. One mark per `ETA_SAMPLE`, a window's worth kept: a bounded list | ||
| 10888 | +/// whichever way the encode goes. | ||
| 10889 | +fn note_progress(marks: &mut Vec<(f32, f32)>, elapsed: f32, progress: f32) { | ||
| 10890 | + if marks.last().is_none_or(|&(t, _)| elapsed - t >= ETA_SAMPLE) { | ||
| 10891 | + marks.push((elapsed, progress)); | ||
| 10892 | + } | ||
| 10893 | + while marks.len() > 2 && marks[0].0 < elapsed - ETA_WINDOW { | ||
| 10894 | + marks.remove(0); | ||
| 10895 | + } | ||
| 10896 | +} | ||
| 10897 | + | ||
| 10898 | +/// Seconds left at the window's rate, or `None` while nothing measurable has | ||
| 10899 | +/// happened yet -- which the line says as "estimating…" rather than as a | ||
| 10900 | +/// number it would have to take back. | ||
| 10901 | +fn eta_secs(marks: &[(f32, f32)], elapsed: f32, progress: f32) -> Option<f32> { | ||
| 10902 | + // A finished pass is not a guess: it is over. | ||
| 10903 | + if progress >= 1. { | ||
| 10904 | + return Some(0.); | ||
| 10905 | + } | ||
| 10906 | + if progress <= 0. || elapsed < ETA_SPAN { | ||
| 10907 | + return None; | ||
| 10908 | + } | ||
| 10909 | + // Two rates, averaged. The window's follows the encode across a | ||
| 10910 | + // hardware-to-software handover; the whole run's is what keeps a window | ||
| 10911 | + // that is all stall from throwing the number minutes out and back. Neither | ||
| 10912 | + // alone reads well: raw window rate spikes eightfold on either edge of a | ||
| 10913 | + // stall, and the run average alone never notices a segment change. | ||
| 10914 | + let overall = progress / elapsed; | ||
| 10915 | + let recent = marks | ||
| 10916 | + .first() | ||
| 10917 | + .filter(|&&(t, _)| elapsed - t >= ETA_SPAN) | ||
| 10918 | + .map_or(overall, |&(t, p)| (progress - p) / (elapsed - t)); | ||
| 10919 | + Some(2. * (1. - progress) / (recent + overall)) | ||
| 10920 | +} | ||
| 10921 | + | ||
| 10376 | #[cfg(test)] | 10922 | #[cfg(test)] |
| 10377 | mod tests { | 10923 | mod tests { |
| 10378 | use super::{ | 10924 | use super::{ |
| @@ -10390,19 +10936,20 @@ mod tests { | |||
| 10390 | enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y, | 10936 | enable, envelope, eq_card_w, eq_freq, eq_freq_label, eq_spectrum, eq_x, eq_y, |
| 10391 | estimated_mb, export_path, export_settings, format_key, | 10937 | estimated_mb, export_path, export_settings, format_key, |
| 10392 | format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram, | 10938 | format_line, format_refusal, fps_label, frac_along, frac_down, frame_at, histogram, |
| 10393 | - inserted_band, is_bare_modifier, is_project, keymap, keys_rows, lanes_h, marked, menu_at, | 10939 | + inserted_band, is_bare_modifier, is_project, keymap, keys_filter, keys_rows, lanes_h, |
| 10394 | - next_audio_kbps, next_container, | 10940 | + marked, menu_at, next_audio_kbps, next_container, normalise, nothing_to_play, panel_h, project_path, |
| 10395 | - normalise, nothing_to_play, panel_h, project_path, push_digit, retarget, scrub_due, | 10941 | + push_digit, retarget, scrub_due, show_label, silence_rate, snap_cue, snap_marks, snapped, |
| 10396 | - show_label, silence_rate, snap_cue, snap_marks, snapped, source_tint, span_partner, | 10942 | + source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport, |
| 10397 | - speed_at, summary_head, summary_tail, timecode, transport, unseen_paths, unseen_sources, | 10943 | + typed, unseen_paths, unseen_sources, |
| 10398 | whole_take, window_title, | 10944 | whole_take, window_title, |
| 10399 | }; | 10945 | }; |
| 10400 | use super::{ | 10946 | use super::{ |
| 10401 | - Choice, Edge, FITS, LaneKind, PPS_DEFAULT, RESOLUTIONS, Repeat, Scale, View, | 10947 | + Choice, ETA_SPAN, Edge, FITS, LaneKind, PPS_DEFAULT, RESOLUTIONS, Repeat, Scale, View, |
| 10402 | - ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, audio_rate_choices, file_name, file_uri, | 10948 | + ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri, |
| 10403 | - fit_choices, | 10949 | + fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution, |
| 10404 | - library_rows, live_idx, next_fit, next_resolution, px_along, repeats, resolution_choices, | 10950 | + note_progress, px_along, |
| 10405 | - resolution_ladder, span_label, trimmed_clip, unscannable, visible_slice, | 10951 | + repeats, resolution_choices, resolution_ladder, span_label, trimmed_clip, unscannable, |
| 10952 | + visible_slice, | ||
| 10406 | }; | 10953 | }; |
| 10407 | 10954 | ||
| 10408 | /// What the file manager is handed: the parts a path keeps as they are, and | 10955 | /// What the file manager is handed: the parts a path keeps as they are, and |
| @@ -11672,6 +12219,64 @@ mod tests { | |||
| 11672 | assert_eq!(snapped(2, 40, 4, &marks), 0); | 12219 | assert_eq!(snapped(2, 40, 4, &marks), 0); |
| 11673 | } | 12220 | } |
| 11674 | 12221 | ||
| 12222 | + /// The shadow a drag draws and the drop that commits are one answer: both | ||
| 12223 | + /// ask [`landing`], so the box seen in flight is the box the release leaves | ||
| 12224 | + /// behind. What this pins down is the composition around the snap -- the | ||
| 12225 | + /// grab offset comes off *before* the magnet, or a clip taken by its tail | ||
| 12226 | + /// would land a boxful late. | ||
| 12227 | + #[test] | ||
| 12228 | + fn a_ghost_and_a_drop_are_one_landing() { | ||
| 12229 | + // A neighbour covering [100, 160), the playhead at 300, and a 40 frame | ||
| 12230 | + // clip taken hold of 12 frames in. | ||
| 12231 | + let marks = [100, 160, 300, 0]; | ||
| 12232 | + let (len, grab, tol) = (40, 12, 4); | ||
| 12233 | + // Pointer at frame 170: the head is 12 frames behind it, at 158, which | ||
| 12234 | + // is a frame short of the neighbour's tail -- so both the ghost and the | ||
| 12235 | + // drop say 160, and the line stands on the mark that pulled it. | ||
| 12236 | + assert_eq!(landing(170, grab, len, true, tol, &marks), (160, Some(160))); | ||
| 12237 | + // Without the grab taken off first, the same pointer would land the | ||
| 12238 | + // box at 170 and no mark would be in reach: the offset is not cosmetic. | ||
| 12239 | + assert_eq!(landing(170, 0, len, true, tol, &marks), (170, None)); | ||
| 12240 | + // A library row carries no grab and no length the engine has measured, | ||
| 12241 | + // which is how `Player::place_frame` asks: only its head lands, on the | ||
| 12242 | + // playhead here. | ||
| 12243 | + assert_eq!(landing(298, 0, 0, true, tol, &marks), (300, Some(300))); | ||
| 12244 | + // The magnet off, ghost and drop agree on the raw frame and no line is | ||
| 12245 | + // drawn -- the frame-by-frame placement the switch is for. | ||
| 12246 | + assert_eq!(landing(170, grab, len, false, tol, &marks), (158, None)); | ||
| 12247 | + // A pointer nearer the bed's start than the hand is into the box cannot | ||
| 12248 | + // pull a head below zero. | ||
| 12249 | + assert_eq!(landing(3, grab, len, true, tol, &marks), (0, Some(0))); | ||
| 12250 | + } | ||
| 12251 | + | ||
| 12252 | + /// Which lanes tint that shadow as refused: the two kinds of file a lane | ||
| 12253 | + /// cannot hold, in the words the release would say them in -- one rule, so | ||
| 12254 | + /// what is shown as impossible is exactly what is refused. | ||
| 12255 | + #[test] | ||
| 12256 | + fn a_lane_refuses_the_files_it_cannot_hold_before_the_release_says_so() { | ||
| 12257 | + let (video, audio) = (Lane::V1, Lane::A1); | ||
| 12258 | + let sound = Path::new("/media/take.mp3"); | ||
| 12259 | + let still = Path::new("/media/card.png"); | ||
| 12260 | + let movie = Path::new("/media/take.mp4"); | ||
| 12261 | + assert_eq!( | ||
| 12262 | + lane_refuses(sound, video).as_deref(), | ||
| 12263 | + Some("NOT ON V1 — take.mp3 has no picture; drop it on an audio lane") | ||
| 12264 | + ); | ||
| 12265 | + assert_eq!( | ||
| 12266 | + lane_refuses(still, audio).as_deref(), | ||
| 12267 | + Some("NOT ON A1 — card.png is a still image; drop it on a video lane") | ||
| 12268 | + ); | ||
| 12269 | + // ...and every lane a file *can* go on says nothing at all, which is a | ||
| 12270 | + // ghost drawn in the file's own colour. | ||
| 12271 | + assert_eq!(lane_refuses(sound, audio), None); | ||
| 12272 | + assert_eq!(lane_refuses(still, video), None); | ||
| 12273 | + assert_eq!(lane_refuses(movie, video), None); | ||
| 12274 | + // A file with a picture is not refused by an audio lane here: the | ||
| 12275 | + // engine takes its sound onto one, and the words for a video-only file | ||
| 12276 | + // are its own. | ||
| 12277 | + assert_eq!(lane_refuses(movie, audio), None); | ||
| 12278 | + } | ||
| 12279 | + | ||
| 11675 | /// Where those edges come from: every lane, not the one being dropped on -- | 12280 | /// Where those edges come from: every lane, not the one being dropped on -- |
| 11676 | /// and never the clip in the hand or the half of it one track down. | 12281 | /// and never the clip in the hand or the half of it one track down. |
| 11677 | #[test] | 12282 | #[test] |
| @@ -12211,19 +12816,106 @@ mod tests { | |||
| 12211 | assert!(KEYS_ROW_H >= HIT_MIN); | 12816 | assert!(KEYS_ROW_H >= HIT_MIN); |
| 12212 | } | 12817 | } |
| 12213 | 12818 | ||
| 12819 | + /// The search box: what a typed word leaves standing. Forty actions is more | ||
| 12820 | + /// than a 360 px window shows at once, so this is the card's answer to | ||
| 12821 | + /// "where is the one I want" -- and a heading with nothing under it would | ||
| 12822 | + /// be worse than no filter at all. | ||
| 12823 | + #[test] | ||
| 12824 | + fn a_search_leaves_the_rows_it_names_under_their_own_headings() { | ||
| 12825 | + use keymap::{ActionId, Category, Keymap}; | ||
| 12826 | + let keymap = Keymap::defaults(); | ||
| 12827 | + let acts = |found: &[(usize, KeyRow)]| -> Vec<ActionId> { | ||
| 12828 | + found | ||
| 12829 | + .iter() | ||
| 12830 | + .filter_map(|(_, r)| match r { | ||
| 12831 | + KeyRow::Act(a) => Some(*a), | ||
| 12832 | + _ => None, | ||
| 12833 | + }) | ||
| 12834 | + .collect() | ||
| 12835 | + }; | ||
| 12836 | + let heads = |found: &[(usize, KeyRow)]| -> Vec<Category> { | ||
| 12837 | + found | ||
| 12838 | + .iter() | ||
| 12839 | + .filter_map(|(_, r)| match r { | ||
| 12840 | + KeyRow::Head(c) => Some(*c), | ||
| 12841 | + _ => None, | ||
| 12842 | + }) | ||
| 12843 | + .collect() | ||
| 12844 | + }; | ||
| 12845 | + // Nothing typed hides nothing, and every row keeps its place in the | ||
| 12846 | + // unfiltered list: an element id must not move under a keystroke. | ||
| 12847 | + let all = keys_filter("", &keymap); | ||
| 12848 | + assert_eq!(all.len(), keys_rows().len()); | ||
| 12849 | + assert!(all.iter().enumerate().all(|(n, (i, _))| n == *i)); | ||
| 12850 | + // The word the user types is the word on the row. The mix card names | ||
| 12851 | + // the track volumes, so it is an honest hit; the fixed row about the | ||
| 12852 | + // volume keys is another, and each comes with its own heading only. | ||
| 12853 | + let vol = keys_filter("vol", &keymap); | ||
| 12854 | + assert_eq!( | ||
| 12855 | + acts(&vol), | ||
| 12856 | + vec![ActionId::VolumeUp, ActionId::VolumeDown, ActionId::Mix] | ||
| 12857 | + ); | ||
| 12858 | + assert_eq!(heads(&vol), vec![Category::Audio, Category::View]); | ||
| 12859 | + // Case is not part of the question, in either direction. | ||
| 12860 | + assert_eq!(keys_filter("VoL", &keymap).len(), vol.len()); | ||
| 12861 | + // The stroke column is searched too -- "what did ctrl do again" -- and | ||
| 12862 | + // an unbound-looking word finds nothing rather than everything. | ||
| 12863 | + let ctrl = keys_filter("ctrl+", &keymap); | ||
| 12864 | + assert!(acts(&ctrl).contains(&ActionId::Save)); | ||
| 12865 | + assert!(!acts(&ctrl).contains(&ActionId::Play)); | ||
| 12866 | + assert!( | ||
| 12867 | + keys_filter("qzx", &keymap).is_empty(), | ||
| 12868 | + "headings left behind" | ||
| 12869 | + ); | ||
| 12870 | + // The card's own door is on the card, by name and by stroke. | ||
| 12871 | + assert_eq!( | ||
| 12872 | + acts(&keys_filter("f1", &keymap)), | ||
| 12873 | + vec![ActionId::ShowActions] | ||
| 12874 | + ); | ||
| 12875 | + assert_eq!( | ||
| 12876 | + acts(&keys_filter("all actions", &keymap)), | ||
| 12877 | + vec![ActionId::ShowActions] | ||
| 12878 | + ); | ||
| 12879 | + } | ||
| 12880 | + | ||
| 12881 | + /// What a keystroke means to that box: a letter is a letter, and a word | ||
| 12882 | + /// gpui reports for a key that prints nothing is not typed letter by | ||
| 12883 | + /// letter into the search. | ||
| 12884 | + #[test] | ||
| 12885 | + fn only_a_printable_stroke_types_into_the_search() { | ||
| 12886 | + assert_eq!(typed("a"), Some('a')); | ||
| 12887 | + assert_eq!(typed("-"), Some('-')); | ||
| 12888 | + assert_eq!(typed("1"), Some('1')); | ||
| 12889 | + // The one printable key gpui reports by name. | ||
| 12890 | + assert_eq!(typed("space"), Some(' ')); | ||
| 12891 | + for word in ["left", "escape", "f1", "backspace", "tab", "delete", "home"] { | ||
| 12892 | + assert_eq!(typed(word), None, "{word}"); | ||
| 12893 | + } | ||
| 12894 | + } | ||
| 12895 | + | ||
| 12214 | #[test] | 12896 | #[test] |
| 12215 | fn the_keybindings_card_fits_the_smallest_window() { | 12897 | fn the_keybindings_card_fits_the_smallest_window() { |
| 12216 | // The row list is capped and scrolls, so the card's height no longer | 12898 | // The row list is capped and scrolls, so the card's height no longer |
| 12217 | - // depends on how many actions there are: a title, a status line and the | 12899 | + // depends on how many actions there are: a title, a status line, the |
| 12218 | - // viewport, inside the 640x360 the rest of the layout is sized for. | 12900 | + // search box and the viewport, inside the 640x360 the rest of the |
| 12901 | + // layout is sized for. | ||
| 12219 | let title = 17.; // 13 px text on its own line | 12902 | let title = 17.; // 13 px text on its own line |
| 12220 | let status = 28.; // 11 px text, two lines: a refusal wraps | 12903 | let status = 28.; // 11 px text, two lines: a refusal wraps |
| 12221 | - let gaps = 3. * 2.; | 12904 | + let search = 15.; // 11 px text, one line: it never wraps |
| 12905 | + let gaps = 4. * 2.; | ||
| 12222 | let padding = 24.; | 12906 | let padding = 24.; |
| 12223 | assert!( | 12907 | assert!( |
| 12224 | - title + status + KEYS_ROWS_H + gaps + padding <= 360., | 12908 | + title + status + search + KEYS_ROWS_H + gaps + padding <= 360., |
| 12225 | "card too tall" | 12909 | "card too tall" |
| 12226 | ); | 12910 | ); |
| 12911 | + // ...and the list is the only part that grows with the editor, so the | ||
| 12912 | + // rows past the fold are reached by scrolling that viewport (and, with | ||
| 12913 | + // forty of them, by the search box above it) rather than by a card | ||
| 12914 | + // taller than the window. | ||
| 12915 | + assert!( | ||
| 12916 | + keys_rows().len() as f32 * KEYS_ROW_H > KEYS_ROWS_H, | ||
| 12917 | + "the list outgrew the viewport long ago; the cap must still scroll" | ||
| 12918 | + ); | ||
| 12227 | // The cap is only honest if it is the taller list that scrolls, not the | 12919 | // The cap is only honest if it is the taller list that scrolls, not the |
| 12228 | // card that grows: every action must be reachable by scrolling, and | 12920 | // card that grows: every action must be reachable by scrolling, and |
| 12229 | // enough of them visible that the list reads as a list. | 12921 | // enough of them visible that the list reads as a list. |
| @@ -13192,6 +13884,77 @@ mod tests { | |||
| 13192 | ); | 13884 | ); |
| 13193 | } | 13885 | } |
| 13194 | 13886 | ||
| 13887 | + /// The progress line's two clocks, driven the way a repaint drives them: | ||
| 13888 | + /// steady work, a stall where hardware hands over to software, then steady | ||
| 13889 | + /// work again. The estimate may not whipsaw, may not vanish once it has | ||
| 13890 | + /// been given, and must meet the elapsed clock at the end. | ||
| 13891 | + #[test] | ||
| 13892 | + fn the_export_estimate_rides_out_a_stall_and_converges() { | ||
| 13893 | + let (mut marks, mut elapsed, mut progress) = (Vec::new(), 0f32, 0f32); | ||
| 13894 | + // 2%/s, a 12 s stall at 40% -- longer than the window, so the window | ||
| 13895 | + // alone would have nothing left to measure -- and the same rate to the | ||
| 13896 | + // end: 62 s of wall clock for 50 s of work. | ||
| 13897 | + let rate = 0.02; | ||
| 13898 | + let (mut quiet, mut before_stall, mut after_stall, mut last) = (0f32, 0., 0., f32::MAX); | ||
| 13899 | + while progress < 1. { | ||
| 13900 | + let stalled = (20. ..32.).contains(&elapsed); | ||
| 13901 | + note_progress(&mut marks, elapsed, progress); | ||
| 13902 | + // What is really left, to hold every guess against. | ||
| 13903 | + let truth = (1. - progress) / rate + if stalled { 32. - elapsed } else { 0. }; | ||
| 13904 | + match eta_secs(&marks, elapsed, progress) { | ||
| 13905 | + // "estimating…" is only allowed before there is a span to | ||
| 13906 | + // measure, and never again after the first number. | ||
| 13907 | + None => { | ||
| 13908 | + assert!(elapsed < ETA_SPAN + 1., "estimate vanished at {elapsed}"); | ||
| 13909 | + quiet = elapsed; | ||
| 13910 | + } | ||
| 13911 | + Some(left) => { | ||
| 13912 | + // No guess is ever wilder than four times the truth: that | ||
| 13913 | + // is the eightfold spike a raw window rate throws on either | ||
| 13914 | + // edge of the stall. | ||
| 13915 | + assert!(left <= truth * 4., "at {elapsed}s: {left} vs {truth}"); | ||
| 13916 | + // While the rate holds, the answer is the true one and it | ||
| 13917 | + // only ever counts down. | ||
| 13918 | + if elapsed >= 5. && elapsed < 20. { | ||
| 13919 | + assert!((left - truth).abs() <= truth * 0.15, "{elapsed}s: {left}"); | ||
| 13920 | + assert!(left < last, "estimate grew while the rate held"); | ||
| 13921 | + } | ||
| 13922 | + // Eight seconds past the stall it has caught up again. | ||
| 13923 | + if elapsed >= 40. { | ||
| 13924 | + assert!((left - truth).abs() <= truth * 0.25, "{elapsed}s: {left}"); | ||
| 13925 | + assert!(left < last + 0.001, "estimate grew after the stall"); | ||
| 13926 | + } | ||
| 13927 | + if (20. ..20.25).contains(&elapsed) { | ||
| 13928 | + before_stall = left; | ||
| 13929 | + } | ||
| 13930 | + if (31.5..31.75).contains(&elapsed) { | ||
| 13931 | + after_stall = left; | ||
| 13932 | + } | ||
| 13933 | + last = left; | ||
| 13934 | + } | ||
| 13935 | + } | ||
| 13936 | + // A window's worth of marks and no more, however long the encode. | ||
| 13937 | + assert!(marks.len() <= 20, "{} marks", marks.len()); | ||
| 13938 | + elapsed += 0.25; | ||
| 13939 | + if !stalled { | ||
| 13940 | + progress = (progress + rate * 0.25).min(1.); | ||
| 13941 | + } | ||
| 13942 | + } | ||
| 13943 | + assert!(quiet > 0. && quiet < ETA_SPAN + 1.); | ||
| 13944 | + // The stall stretched the guess instead of erasing it, and by more than | ||
| 13945 | + // the stopped clock adds on its own. | ||
| 13946 | + assert!( | ||
| 13947 | + after_stall > before_stall + 12., | ||
| 13948 | + "{before_stall} -> {after_stall}" | ||
| 13949 | + ); | ||
| 13950 | + // Both clocks meet: a finished pass has nothing left. | ||
| 13951 | + assert_eq!(eta_secs(&marks, elapsed, 1.), Some(0.)); | ||
| 13952 | + assert!((elapsed - 62.).abs() < 1., "{elapsed}"); | ||
| 13953 | + assert_eq!(clock(83.4), "1:23"); | ||
| 13954 | + assert_eq!(clock(114.), "1:54"); | ||
| 13955 | + assert_eq!(clock(-1.), "0:00"); | ||
| 13956 | + } | ||
| 13957 | + | ||
| 13195 | #[test] | 13958 | #[test] |
| 13196 | fn every_codec_row_is_offered_or_says_why_not() { | 13959 | fn every_codec_row_is_offered_or_says_why_not() { |
| 13197 | // One row per codec, and the boxes it can go in are the container row's | 13960 | // One row per codec, and the boxes it can go in are the container row's |
| @@ -14071,20 +14834,26 @@ fn main() { | |||
| 14071 | sizes: HashMap::new(), | 14834 | sizes: HashMap::new(), |
| 14072 | decoders: HashMap::new(), | 14835 | decoders: HashMap::new(), |
| 14073 | export_seat: None, | 14836 | export_seat: None, |
| 14837 | + hw_caps: None, | ||
| 14074 | clipboard: None, | 14838 | clipboard: None, |
| 14075 | scrubbing: false, | 14839 | scrubbing: false, |
| 14076 | trim: None, | 14840 | trim: None, |
| 14077 | grab: 0, | 14841 | grab: 0, |
| 14078 | snap: true, | 14842 | snap: true, |
| 14079 | snap_cue: None, | 14843 | snap_cue: None, |
| 14844 | + ghost: None, | ||
| 14080 | last_scrub: Instant::now(), | 14845 | last_scrub: Instant::now(), |
| 14081 | last_target: 0, | 14846 | last_target: 0, |
| 14082 | export: None, | 14847 | export: None, |
| 14083 | cancelling: false, | 14848 | cancelling: false, |
| 14849 | + export_started: None, | ||
| 14850 | + export_marks: Vec::new(), | ||
| 14084 | export_path: out.clone(), | 14851 | export_path: out.clone(), |
| 14085 | project_path: project.clone(), | 14852 | project_path: project.clone(), |
| 14086 | keymap: keymap.clone(), | 14853 | keymap: keymap.clone(), |
| 14087 | keys_open: false, | 14854 | keys_open: false, |
| 14855 | + keys_search: String::new(), | ||
| 14856 | + keys_scroll: ScrollHandle::new(), | ||
| 14088 | export_open: false, | 14857 | export_open: false, |
| 14089 | export_grouped: true, | 14858 | export_grouped: true, |
| 14090 | export_refusals_inline: false, | 14859 | export_refusals_inline: false, |
crates/engine-hw/src/lib.rsmodified+132 -1
| @@ -46,7 +46,7 @@ use cros_codecs::{Fourcc, FrameLayout, PlaneLayout, Resolution}; | |||
| 46 | use gbm::{BufferObjectFlags, Format as GbmFormat}; | 46 | use gbm::{BufferObjectFlags, Format as GbmFormat}; |
| 47 | 47 | ||
| 48 | use engine::demux::{Codec, Demuxer}; | 48 | use engine::demux::{Codec, Demuxer}; |
| 49 | -use engine::hw::{VhFrame, VhMeta}; | 49 | +use engine::hw::{CAP_AV1, CAP_H264, CAP_HEVC, CAP_VP9, VhCaps, VhFrame, VhMeta}; |
| 50 | 50 | ||
| 51 | type PooledFrame = PooledVideoFrame<GenericDmaVideoFrame>; | 51 | type PooledFrame = PooledVideoFrame<GenericDmaVideoFrame>; |
| 52 | type Dec<C> = StatelessDecoder<C, VaapiBackend<PooledFrame>>; | 52 | type Dec<C> = StatelessDecoder<C, VaapiBackend<PooledFrame>>; |
| @@ -560,6 +560,112 @@ pub unsafe extern "C" fn vh_close(session: *mut c_void) { | |||
| 560 | })); | 560 | })); |
| 561 | } | 561 | } |
| 562 | 562 | ||
| 563 | +/// What each codec needs of the driver before this plugin can claim it: the | ||
| 564 | +/// 8-bit decode profiles, the 10-bit ones, and the profile the *encoder* here | ||
| 565 | +/// would open -- `None` for the two this plugin has no encoder for at all, so a | ||
| 566 | +/// GPU with an HEVC or VP9 encode entrypoint is never reported as one edith can | ||
| 567 | +/// reach. The encode profiles are the very ones [`EncSession::open_codec`] | ||
| 568 | +/// asks for, which is what keeps this a description of the plugin rather than a | ||
| 569 | +/// second opinion about it. | ||
| 570 | +const CAP_TABLE: [(u32, &[VAProfile::Type], &[VAProfile::Type], Option<VAProfile::Type>); 4] = [ | ||
| 571 | + ( | ||
| 572 | + CAP_H264, | ||
| 573 | + &[ | ||
| 574 | + VAProfile::VAProfileH264ConstrainedBaseline, | ||
| 575 | + VAProfile::VAProfileH264Main, | ||
| 576 | + VAProfile::VAProfileH264High, | ||
| 577 | + ], | ||
| 578 | + &[], | ||
| 579 | + Some(VAProfile::VAProfileH264Main), | ||
| 580 | + ), | ||
| 581 | + ( | ||
| 582 | + CAP_HEVC, | ||
| 583 | + &[VAProfile::VAProfileHEVCMain], | ||
| 584 | + &[VAProfile::VAProfileHEVCMain10], | ||
| 585 | + None, | ||
| 586 | + ), | ||
| 587 | + ( | ||
| 588 | + CAP_VP9, | ||
| 589 | + &[VAProfile::VAProfileVP9Profile0], | ||
| 590 | + &[VAProfile::VAProfileVP9Profile2], | ||
| 591 | + None, | ||
| 592 | + ), | ||
| 593 | + ( | ||
| 594 | + CAP_AV1, | ||
| 595 | + &[VAProfile::VAProfileAV1Profile0], | ||
| 596 | + // AV1 carries 8- and 10-bit in the same profile 0, so the profile bit | ||
| 597 | + // is the same one and the P010 read-back is what decides. | ||
| 598 | + &[VAProfile::VAProfileAV1Profile0], | ||
| 599 | + Some(VAProfile::VAProfileAV1Profile0), | ||
| 600 | + ), | ||
| 601 | +]; | ||
| 602 | + | ||
| 603 | +/// This machine's decode and encode seats, asked of the driver rather than | ||
| 604 | +/// assumed: which profiles it has, which entrypoints each of those carries, and | ||
| 605 | +/// whether a P010 image exists to read a 10-bit picture back through. Only | ||
| 606 | +/// codecs this plugin actually implements can light up -- `CAP_TABLE` is that | ||
| 607 | +/// half of the intersection. | ||
| 608 | +/// | ||
| 609 | +/// `None` when there is no display to ask at all, which is the same "software | ||
| 610 | +/// only" a missing plugin means. | ||
| 611 | +fn query_caps() -> Option<VhCaps> { | ||
| 612 | + let (display, _gbm) = open_devices()?; | ||
| 613 | + let profiles = display.query_config_profiles().ok()?; | ||
| 614 | + let p010 = display | ||
| 615 | + .query_image_formats() | ||
| 616 | + .is_ok_and(|formats| formats.iter().any(|f| f.fourcc == VA_FOURCC_P010)); | ||
| 617 | + let has = |profile: VAProfile::Type, entrypoint: VAEntrypoint::Type| { | ||
| 618 | + profiles.contains(&profile) | ||
| 619 | + && display | ||
| 620 | + .query_config_entrypoints(profile) | ||
| 621 | + .is_ok_and(|e| e.contains(&entrypoint)) | ||
| 622 | + }; | ||
| 623 | + let decodes = |list: &[VAProfile::Type]| { | ||
| 624 | + list.iter() | ||
| 625 | + .any(|&p| has(p, VAEntrypoint::VAEntrypointVLD)) | ||
| 626 | + }; | ||
| 627 | + let mut caps = VhCaps::default(); | ||
| 628 | + for (bit, eight, ten, encode) in CAP_TABLE { | ||
| 629 | + if decodes(eight) { | ||
| 630 | + caps.decode |= bit; | ||
| 631 | + } | ||
| 632 | + if p010 && decodes(ten) { | ||
| 633 | + caps.decode_10bit |= bit; | ||
| 634 | + } | ||
| 635 | + // Both entrypoints, exactly as the encoder's own open takes either. | ||
| 636 | + if encode.is_some_and(|p| { | ||
| 637 | + has(p, VAEntrypoint::VAEntrypointEncSlice) || has(p, VAEntrypoint::VAEntrypointEncSliceLP) | ||
| 638 | + }) { | ||
| 639 | + caps.encode |= bit; | ||
| 640 | + } | ||
| 641 | + } | ||
| 642 | + Some(caps) | ||
| 643 | +} | ||
| 644 | + | ||
| 645 | +/// Fills `out` with what this machine and this plugin can do together. 0 on | ||
| 646 | +/// success, negative when there is nothing to report -- an *optional* symbol on | ||
| 647 | +/// purpose, so the caller resolving it is free to be older or newer than this. | ||
| 648 | +/// | ||
| 649 | +/// Costs one VA-API init; the caller caches the answer. | ||
| 650 | +/// | ||
| 651 | +/// # Safety | ||
| 652 | +/// `out` must be writable. | ||
| 653 | +#[unsafe(no_mangle)] | ||
| 654 | +pub unsafe extern "C" fn vh_caps(out: *mut VhCaps) -> i32 { | ||
| 655 | + catch_unwind(AssertUnwindSafe(|| { | ||
| 656 | + if out.is_null() { | ||
| 657 | + return -1; | ||
| 658 | + } | ||
| 659 | + let Some(caps) = query_caps() else { | ||
| 660 | + return -1; | ||
| 661 | + }; | ||
| 662 | + // SAFETY: caller-guaranteed writable destination. | ||
| 663 | + unsafe { *out = caps }; | ||
| 664 | + 0 | ||
| 665 | + })) | ||
| 666 | + .unwrap_or(-1) | ||
| 667 | +} | ||
| 668 | + | ||
| 563 | fn align16(v: u32) -> u32 { | 669 | fn align16(v: u32) -> u32 { |
| 564 | v.div_ceil(16) * 16 | 670 | v.div_ceil(16) * 16 |
| 565 | } | 671 | } |
| @@ -993,3 +1099,28 @@ pub unsafe extern "C" fn vh_enc_close(session: *mut c_void) { | |||
| 993 | } | 1099 | } |
| 994 | })); | 1100 | })); |
| 995 | } | 1101 | } |
| 1102 | + | ||
| 1103 | +#[cfg(test)] | ||
| 1104 | +mod tests { | ||
| 1105 | + use super::*; | ||
| 1106 | + | ||
| 1107 | + /// Runs against whatever GPU this machine has -- and passes on one with no | ||
| 1108 | + /// VA-API at all, which is exactly what `None` means here. What it pins is | ||
| 1109 | + /// the *shape* of the answer, the contents being the driver's: nothing may | ||
| 1110 | + /// be claimed that this plugin cannot actually reach. | ||
| 1111 | + #[test] | ||
| 1112 | + fn the_caps_query_never_claims_more_than_this_plugin_implements() { | ||
| 1113 | + let Some(caps) = query_caps() else { | ||
| 1114 | + return; | ||
| 1115 | + }; | ||
| 1116 | + eprintln!("{caps:?}"); | ||
| 1117 | + // Encode is this plugin's two seats and no others, whatever entrypoints | ||
| 1118 | + // the driver has: an HEVC or VP9 EncSlice is not an encoder here. | ||
| 1119 | + assert_eq!(caps.encode & !(CAP_H264 | CAP_AV1), 0, "{caps:?}"); | ||
| 1120 | + // A 10-bit claim is a decode claim -- same profile family, read back | ||
| 1121 | + // through P010 -- and there is no 10-bit encode path at all. | ||
| 1122 | + assert_eq!(caps.decode_10bit & !caps.decode, 0, "{caps:?}"); | ||
| 1123 | + // H.264 here is 8-bit 4:2:0; the table has no 10-bit profile for it. | ||
| 1124 | + assert_eq!(caps.decode_10bit & CAP_H264, 0, "{caps:?}"); | ||
| 1125 | + } | ||
| 1126 | +} | ||
crates/engine/src/caps.rsadded+141 -0
| @@ -0,0 +1,141 @@ | |||
| 1 | +//! What this editor can really decode and encode, in one place and in two | ||
| 2 | +//! halves. | ||
| 3 | +//! | ||
| 4 | +//! The *software* half is what this binary was built with: a table, because | ||
| 5 | +//! "is `rav1e` linked into this build" is a question the build already answered | ||
| 6 | +//! and probing for it would only be a slower way of reading the manifest. | ||
| 7 | +//! | ||
| 8 | +//! The *hardware* half is a different answer on every machine and is therefore | ||
| 9 | +//! never a table: [`crate::hw::caps`] asks the plugin, the plugin asks the | ||
| 10 | +//! driver, and what comes back is the intersection of the GPU's entrypoints | ||
| 11 | +//! with the codecs the plugin implements. No plugin, an older plugin or no | ||
| 12 | +//! driver all read the same way -- "software only" -- because that is what they | ||
| 13 | +//! mean for the file a user is about to write. | ||
| 14 | + | ||
| 15 | +use crate::hw::{CAP_AV1, CAP_H264, CAP_HEVC, CAP_VP9, VhCaps}; | ||
| 16 | + | ||
| 17 | +/// The codecs a hardware line can name, in the order it lists them. | ||
| 18 | +const HW_CODECS: [(u32, &str); 4] = [ | ||
| 19 | + (CAP_H264, "H.264"), | ||
| 20 | + (CAP_HEVC, "HEVC"), | ||
| 21 | + (CAP_VP9, "VP9"), | ||
| 22 | + (CAP_AV1, "AV1"), | ||
| 23 | +]; | ||
| 24 | + | ||
| 25 | +/// The software half: the codec, the crate that carries it here, and which | ||
| 26 | +/// halves of the job that crate does. Named crates rather than a bare "SW", | ||
| 27 | +/// because the answer to "why is my HEVC file so large" is `oxideav-h265 | ||
| 28 | +/// intra`, and the row that says so is the row that answers it. | ||
| 29 | +const SW_CODECS: [(&str, &str, bool, bool); 10] = [ | ||
| 30 | + ("H.264", "rusty_h264", true, true), | ||
| 31 | + ("HEVC", "oxideav-h265 intra", false, true), | ||
| 32 | + ("AV1", "rav1e", false, true), | ||
| 33 | + ("AAC", "rusty_aac", true, true), | ||
| 34 | + ("MP3", "symphonia / rusty_mp3", true, true), | ||
| 35 | + ("FLAC", "symphonia / flacenc", true, true), | ||
| 36 | + ("PCM", "symphonia / hound", true, true), | ||
| 37 | + ("AC-3", "oxideav-ac3", true, false), | ||
| 38 | + ("Vorbis", "symphonia", true, false), | ||
| 39 | + ("ALAC", "symphonia", true, false), | ||
| 40 | +]; | ||
| 41 | + | ||
| 42 | +/// The hardware line as a front-end shows it: one measurement per process, | ||
| 43 | +/// costing the plugin's VA-API init (~90 ms) the first time. Ask it off a | ||
| 44 | +/// render thread. | ||
| 45 | +pub fn hardware() -> String { | ||
| 46 | + hw_line(crate::hw::caps()) | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +/// The software line. Pure and constant -- a caller may ask it per repaint. | ||
| 50 | +pub fn software() -> String { | ||
| 51 | + SW_CODECS | ||
| 52 | + .iter() | ||
| 53 | + .map(|&(name, krate, decodes, encodes)| { | ||
| 54 | + format!("{name} {} ({krate})", seats(decodes, encodes)) | ||
| 55 | + }) | ||
| 56 | + .collect::<Vec<_>>() | ||
| 57 | + .join(" · ") | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +/// What the plugin answered, in words. Separate from [`hardware`] so the | ||
| 61 | +/// wording can be tested against a machine this test suite does not have. | ||
| 62 | +fn hw_line(caps: Option<VhCaps>) -> String { | ||
| 63 | + let Some(caps) = caps else { | ||
| 64 | + return "none — no plugin, no driver, or a plugin too old to say".to_string(); | ||
| 65 | + }; | ||
| 66 | + let listed: Vec<String> = HW_CODECS | ||
| 67 | + .iter() | ||
| 68 | + .filter(|&&(bit, _)| caps.decode & bit != 0 || caps.encode & bit != 0) | ||
| 69 | + .map(|&(bit, name)| { | ||
| 70 | + let seats = seats(caps.decode & bit != 0, caps.encode & bit != 0); | ||
| 71 | + match caps.decode_10bit & bit != 0 { | ||
| 72 | + true => format!("{name} {seats} (10-bit)"), | ||
| 73 | + false => format!("{name} {seats}"), | ||
| 74 | + } | ||
| 75 | + }) | ||
| 76 | + .collect(); | ||
| 77 | + match listed.is_empty() { | ||
| 78 | + // A driver answered and takes none of the codecs this build carries: | ||
| 79 | + // not the same thing as no driver, and worth saying so. | ||
| 80 | + true => "none — the driver takes none of these codecs".to_string(), | ||
| 81 | + false => listed.join(" · "), | ||
| 82 | + } | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +/// Which halves of the job one seat does. Never both empty: a codec with | ||
| 86 | +/// neither is not listed at all. | ||
| 87 | +fn seats(decodes: bool, encodes: bool) -> &'static str { | ||
| 88 | + match (decodes, encodes) { | ||
| 89 | + (true, true) => "dec+enc", | ||
| 90 | + (true, false) => "dec", | ||
| 91 | + _ => "enc", | ||
| 92 | + } | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +#[cfg(test)] | ||
| 96 | +mod tests { | ||
| 97 | + use super::*; | ||
| 98 | + | ||
| 99 | + #[test] | ||
| 100 | + fn the_hardware_line_says_what_the_plugin_answered_and_nothing_more() { | ||
| 101 | + // No answer at all -- no plugin, no driver, or one older than the | ||
| 102 | + // symbol -- is one line, and never an empty listing that would read as | ||
| 103 | + // "still loading". | ||
| 104 | + assert!(hw_line(None).starts_with("none —")); | ||
| 105 | + // A driver that answers with nothing is its own sentence. | ||
| 106 | + assert!(hw_line(Some(VhCaps::default())).starts_with("none —")); | ||
| 107 | + // This project's own GPU as `vainfo` lists it: H.264 both ways, HEVC | ||
| 108 | + // and VP9 decode with their 10-bit profiles, AV1 both ways. HEVC has a | ||
| 109 | + // VA encode entrypoint here and is *not* an encode seat: the plugin has | ||
| 110 | + // no HEVC encoder, so the line must not offer one. | ||
| 111 | + let radeonsi = VhCaps { | ||
| 112 | + decode: CAP_H264 | CAP_HEVC | CAP_VP9 | CAP_AV1, | ||
| 113 | + encode: CAP_H264 | CAP_AV1, | ||
| 114 | + decode_10bit: CAP_HEVC | CAP_VP9 | CAP_AV1, | ||
| 115 | + }; | ||
| 116 | + assert_eq!( | ||
| 117 | + hw_line(Some(radeonsi)), | ||
| 118 | + "H.264 dec+enc · HEVC dec (10-bit) · VP9 dec (10-bit) · AV1 dec+enc (10-bit)" | ||
| 119 | + ); | ||
| 120 | + // A codec the driver has neither seat for is left out rather than | ||
| 121 | + // listed as a refusal: this line is what the machine *can* do. | ||
| 122 | + let h264_only = VhCaps { | ||
| 123 | + decode: CAP_H264, | ||
| 124 | + ..Default::default() | ||
| 125 | + }; | ||
| 126 | + assert_eq!(hw_line(Some(h264_only)), "H.264 dec"); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + #[test] | ||
| 130 | + fn the_software_line_names_every_encoder_this_build_carries() { | ||
| 131 | + let line = software(); | ||
| 132 | + for name in ["rusty_h264", "oxideav-h265 intra", "rav1e", "rusty_aac"] { | ||
| 133 | + assert!(line.contains(name), "{name} missing from {line}"); | ||
| 134 | + } | ||
| 135 | + // Decode-only crates must not read as encoders, and the seat words are | ||
| 136 | + // the only thing saying which is which. | ||
| 137 | + assert!(line.contains("AC-3 dec (oxideav-ac3)")); | ||
| 138 | + assert!(line.contains("H.264 dec+enc (rusty_h264)")); | ||
| 139 | + assert!(line.contains("HEVC enc (oxideav-h265 intra)")); | ||
| 140 | + } | ||
| 141 | +} | ||
crates/engine/src/hw.rsmodified+52 -0
| @@ -62,11 +62,39 @@ impl Default for VhFrame { | |||
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | +/// What *this machine* takes, as far as the plugin implements it: one bit per | ||
| 66 | +/// codec ([`CAP_H264`] and its three neighbours) in each mask, so a caller reads | ||
| 67 | +/// "H.264 decodes and encodes here, HEVC only decodes" off three `u32`s. | ||
| 68 | +/// | ||
| 69 | +/// The intersection is the plugin's to compute, never the driver's alone: a GPU | ||
| 70 | +/// with an HEVC *encode* entrypoint is still not an HEVC encoder here -- the | ||
| 71 | +/// plugin has no such entry point -- and a capability nothing can reach would be | ||
| 72 | +/// a lie in whatever the front-end draws from this. | ||
| 73 | +#[repr(C)] | ||
| 74 | +#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)] | ||
| 75 | +pub struct VhCaps { | ||
| 76 | + pub decode: u32, | ||
| 77 | + pub encode: u32, | ||
| 78 | + /// Codecs whose 10-bit profiles decode: the driver has the profile *and* a | ||
| 79 | + /// P010 image format for the read-back, which is the pair the plugin's | ||
| 80 | + /// 10-bit path needs. | ||
| 81 | + pub decode_10bit: u32, | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +pub const CAP_H264: u32 = 1 << 0; | ||
| 85 | +pub const CAP_HEVC: u32 = 1 << 1; | ||
| 86 | +pub const CAP_VP9: u32 = 1 << 2; | ||
| 87 | +pub const CAP_AV1: u32 = 1 << 3; | ||
| 88 | + | ||
| 65 | struct Plugin { | 89 | struct Plugin { |
| 66 | open_at: unsafe extern "C" fn(*const c_char, u32) -> *mut c_void, | 90 | open_at: unsafe extern "C" fn(*const c_char, u32) -> *mut c_void, |
| 67 | meta: unsafe extern "C" fn(*mut c_void, *mut VhMeta) -> i32, | 91 | meta: unsafe extern "C" fn(*mut c_void, *mut VhMeta) -> i32, |
| 68 | next_frame: unsafe extern "C" fn(*mut c_void, *mut VhFrame) -> i32, | 92 | next_frame: unsafe extern "C" fn(*mut c_void, *mut VhFrame) -> i32, |
| 69 | close: unsafe extern "C" fn(*mut c_void), | 93 | close: unsafe extern "C" fn(*mut c_void), |
| 94 | + /// The capability query, and the one symbol of this table that may be | ||
| 95 | + /// missing: a plugin built before it exports the four above and not this, | ||
| 96 | + /// which costs a front-end the listing and never a decode. | ||
| 97 | + caps: Option<unsafe extern "C" fn(*mut VhCaps) -> i32>, | ||
| 70 | // Never dropped (lives in a static), so the fn pointers above stay valid. | 98 | // Never dropped (lives in a static), so the fn pointers above stay valid. |
| 71 | _lib: Library, | 99 | _lib: Library, |
| 72 | } | 100 | } |
| @@ -102,6 +130,7 @@ fn load() -> Option<Plugin> { | |||
| 102 | meta: *lib.get(b"vh_meta\0").ok()?, | 130 | meta: *lib.get(b"vh_meta\0").ok()?, |
| 103 | next_frame: *lib.get(b"vh_next_frame\0").ok()?, | 131 | next_frame: *lib.get(b"vh_next_frame\0").ok()?, |
| 104 | close: *lib.get(b"vh_close\0").ok()?, | 132 | close: *lib.get(b"vh_close\0").ok()?, |
| 133 | + caps: lib.get(b"vh_caps\0").ok().map(|s| *s), | ||
| 105 | _lib: lib, | 134 | _lib: lib, |
| 106 | }) | 135 | }) |
| 107 | })() | 136 | })() |
| @@ -113,6 +142,29 @@ fn load() -> Option<Plugin> { | |||
| 113 | None | 142 | None |
| 114 | } | 143 | } |
| 115 | 144 | ||
| 145 | +/// What the plugin says this machine decodes and encodes, asked once per | ||
| 146 | +/// process and cached: the answer cannot change while we run. | ||
| 147 | +/// | ||
| 148 | +/// `None` on every way there is no answer -- no plugin, a plugin older than the | ||
| 149 | +/// symbol (optional exactly as `vh_enc_av1_open` is: such a plugin still | ||
| 150 | +/// decodes), no driver, a driver that refuses the query -- and a caller says | ||
| 151 | +/// "software only" for all of them, which is what they mean. | ||
| 152 | +/// | ||
| 153 | +/// Costs one VA-API init (~90 ms) the first time: ask it off a render thread. | ||
| 154 | +pub fn caps() -> Option<VhCaps> { | ||
| 155 | + static CAPS: OnceLock<Option<VhCaps>> = OnceLock::new(); | ||
| 156 | + *CAPS.get_or_init(|| { | ||
| 157 | + let query = plugin()?.caps?; | ||
| 158 | + let mut caps = VhCaps::default(); | ||
| 159 | + // SAFETY: the plugin writes the struct it is handed and reports "no | ||
| 160 | + // answer" as a negative code; nothing is borrowed across the call. | ||
| 161 | + match unsafe { query(&mut caps) } { | ||
| 162 | + 0 => Some(caps), | ||
| 163 | + _ => None, | ||
| 164 | + } | ||
| 165 | + }) | ||
| 166 | +} | ||
| 167 | + | ||
| 116 | /// An open hardware decode session. Dropping it closes the plugin session. | 168 | /// An open hardware decode session. Dropping it closes the plugin session. |
| 117 | pub struct HwSession { | 169 | pub struct HwSession { |
| 118 | plugin: &'static Plugin, | 170 | plugin: &'static Plugin, |
crates/engine/src/lib.rsmodified+1 -0
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | pub mod ao; | 3 | pub mod ao; |
| 4 | pub mod audio; | 4 | pub mod audio; |
| 5 | +pub mod caps; | ||
| 5 | pub mod clock; | 6 | pub mod clock; |
| 6 | pub mod color; | 7 | pub mod color; |
| 7 | pub mod convert; | 8 | pub mod convert; |