The preview is the commit, and the wave is drawn where it can be seen
Browse files at this commit5530fbd1db5a6fa14b3d4e5969fdbe6bc537fb03Parent: 9935946- fix
- the preview is the commit, and the wave is drawn where it can be seen
1 changed file +358 -65
- crates/app/src/main.rs +358 -65
crates/app/src/main.rsmodified+358 -65
| @@ -85,6 +85,13 @@ const WAVE_BPS: u32 = 40; | ||
| 85 | 85 | /// Pixels per envelope column. Coarser than a pixel: the eye reads the shape, |
| 86 | 86 | /// and a path with a point per pixel is a path per repaint. |
| 87 | 87 | const WAVE_COL: f32 = 2.; |
| 88 | +/// The most columns one envelope is ever built from. A waveform is drawn into | |
| 89 | +/// the slice of its box that is on the bed ([`visible_slice`]), and a bed is a | |
| 90 | +/// screen wide, so nothing on screen ever reaches this -- it is the backstop for | |
| 91 | +/// a box laid out wider than any screen, whose path would otherwise cost a point | |
| 92 | +/// per two pixels of a width nobody can see and stall the repaint that was | |
| 93 | +/// meant to draw the wave. | |
| 94 | +const WAVE_COLS_MAX: usize = 4096; | |
| 88 | 95 | /// WCAG 2.5.8: nothing clickable is smaller than this. The scrub bar stays 6 px |
| 89 | 96 | /// to look at -- `RULER_HIT_H` is the strip that has to be hit. |
| 90 | 97 | const HIT_MIN: f32 = 24.; |
| @@ -281,6 +288,13 @@ struct AssetDrag(PathBuf, usize); | ||
| 281 | 288 | struct ClipDrag { |
| 282 | 289 | lane: Lane, |
| 283 | 290 | idx: usize, |
| 291 | + /// The clip that was picked up, so the drop can find it again: gpui freezes | |
| 292 | + /// the payload for the whole gesture, and an edit made *during* one -- a | |
| 293 | + /// stroke deletes, undoes or pastes, none of which a drag blocks -- ripples | |
| 294 | + /// the indices under it. The index alone would then name a different take at | |
| 295 | + /// the release, and the drag would move a clip nobody touched (see | |
| 296 | + /// [`live_idx`]). | |
| 297 | + clip: Clip, | |
| 284 | 298 | } |
| 285 | 299 | |
| 286 | 300 | /// A clip edge being dragged: which end of which clip, and the timeline frame |
| @@ -2573,39 +2587,13 @@ impl Player { | ||
| 2573 | 2587 | }) else { |
| 2574 | 2588 | return clip; |
| 2575 | 2589 | }; |
| 2576 | - match trim.edge { | |
| 2577 | - // A still grows forward from source frame 0 instead, exactly as | |
| 2578 | - // `Project::trim` writes it: with the in-point clamped at 0 the box | |
| 2579 | - // below would slide left rather than stretch, and the release would | |
| 2580 | - // then commit a wider clip than the drag drew. | |
| 2581 | - Edge::Start | |
| 2582 | - if self.session.as_ref().is_some_and(|session| { | |
| 2583 | - session | |
| 2584 | - .sources() | |
| 2585 | - .get(clip.source) | |
| 2586 | - .is_some_and(|s| engine::is_image(&s.path)) | |
| 2587 | - }) => | |
| 2588 | - { | |
| 2589 | - Clip { | |
| 2590 | - in_frame: 0, | |
| 2591 | - out_frame: clip.end().saturating_sub(trim.to).max(1), | |
| 2592 | - start: trim.to, | |
| 2593 | - ..clip | |
| 2594 | - } | |
| 2595 | - } | |
| 2596 | - // The in-point follows the head, exactly as `Project::trim` moves | |
| 2597 | - // it: what stays on screen plays what it always played. | |
| 2598 | - Edge::Start => Clip { | |
| 2599 | - in_frame: (i64::from(clip.in_frame) + i64::from(trim.to) - i64::from(clip.start)) | |
| 2600 | - .clamp(0, i64::from(clip.out_frame - 1)) as u32, | |
| 2601 | - start: trim.to, | |
| 2602 | - ..clip | |
| 2603 | - }, | |
| 2604 | - Edge::End => Clip { | |
| 2605 | - out_frame: clip.in_frame + trim.to.saturating_sub(clip.start).max(1), | |
| 2606 | - ..clip | |
| 2607 | - }, | |
| 2608 | - } | |
| 2590 | + let still = self.session.as_ref().is_some_and(|session| { | |
| 2591 | + session | |
| 2592 | + .sources() | |
| 2593 | + .get(clip.source) | |
| 2594 | + .is_some_and(|s| engine::is_image(&s.path)) | |
| 2595 | + }); | |
| 2596 | + trimmed_clip(clip, trim.edge, trim.to, still) | |
| 2609 | 2597 | } |
| 2610 | 2598 | |
| 2611 | 2599 | /// How long the timeline is *drawn* as: its own length, and while a tail is |
| @@ -2613,6 +2601,15 @@ impl Player { | ||
| 2613 | 2601 | /// at the last frame has nowhere to put a pointer that means "longer", so |
| 2614 | 2602 | /// without this the last clip on the timeline could be pulled in and never |
| 2615 | 2603 | /// let back out. |
| 2604 | + /// | |
| 2605 | + /// Scroll room only, now that a second is an absolute number of pixels | |
| 2606 | + /// ([`Scale`]): the extra length loosens [`View::settled`]'s clamp, which is | |
| 2607 | + /// where the pixels past the last frame come from, and moves no box by a | |
| 2608 | + /// pixel. It is still the *only* headroom at the tail -- zoomed in against | |
| 2609 | + /// the end, that clamp pins the bed's right edge to the duration and an | |
| 2610 | + /// End-trim of the last clip would have nowhere to be dragged to. What it | |
| 2611 | + /// must not do is be read as a length anyone is told: the timecode reads | |
| 2612 | + /// `PlaybackSession::timeline_duration` for exactly that reason. | |
| 2616 | 2613 | fn drawn_duration(&self) -> f64 { |
| 2617 | 2614 | let Some(session) = &self.session else { |
| 2618 | 2615 | return 0.; |
| @@ -4641,10 +4638,20 @@ impl Player { | ||
| 4641 | 4638 | .gap(px(12.)) |
| 4642 | 4639 | // Fixed width and one line: changing digits must not push |
| 4643 | 4640 | // the row around, nor wrap and change its height. |
| 4641 | + // The timeline's own length, never the drawn one: a tail | |
| 4642 | + // being dragged inflates the bed to the room that edge has | |
| 4643 | + // ([`Player::drawn_duration`]), and for a still that room is | |
| 4644 | + // ten minutes -- a total that jumped to 10:00:00 the moment | |
| 4645 | + // a picture's edge was pressed, and back on release. | |
| 4644 | 4646 | .child(div().flex_none().w(px(TIME_W)).truncate().child(format!( |
| 4645 | 4647 | "{} / {}", |
| 4646 | 4648 | timecode(position, self.fps), |
| 4647 | - timecode(duration, self.fps) | |
| 4649 | + timecode( | |
| 4650 | + self.session | |
| 4651 | + .as_ref() | |
| 4652 | + .map_or(0., PlaybackSession::timeline_duration), | |
| 4653 | + self.fps | |
| 4654 | + ) | |
| 4648 | 4655 | ))) |
| 4649 | 4656 | .child( |
| 4650 | 4657 | div() |
| @@ -6693,6 +6700,11 @@ impl Player { | ||
| 6693 | 6700 | // it, so all of them move together when it does. No bed width is needed |
| 6694 | 6701 | // to place them any more -- a second is so many pixels wherever it is. |
| 6695 | 6702 | let scale = self.scale; |
| 6703 | + // How much bed there is to be seen on, measured off the ruler's own | |
| 6704 | + // probe like every other question about it: what a box draws *inside* | |
| 6705 | + // itself is clipped to this ([`visible_slice`]), because a box at a deep | |
| 6706 | + // zoom is far wider than the strip it is being watched through. | |
| 6707 | + let bed = f32::from(self.ruler.get().size.width); | |
| 6696 | 6708 | let clips = self |
| 6697 | 6709 | .session |
| 6698 | 6710 | .as_ref() |
| @@ -6848,10 +6860,24 @@ impl Player { | ||
| 6848 | 6860 | // to -- its own included, which is the drag that moves a |
| 6849 | 6861 | // take along its track. |
| 6850 | 6862 | .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { |
| 6851 | - this.move_clip(drag.lane, drag.idx, lane, window.mouse_position().x, cx) | |
| 6863 | + // Against the lane as it is *now*, not as it was when | |
| 6864 | + // the hand took hold: an edit during the drag moves the | |
| 6865 | + // indices the payload froze ([`live_idx`]). | |
| 6866 | + let Some(idx) = this | |
| 6867 | + .session | |
| 6868 | + .as_ref() | |
| 6869 | + .and_then(|s| live_idx(s.lane_clips(drag.lane), drag.idx, drag.clip)) | |
| 6870 | + else { | |
| 6871 | + return; | |
| 6872 | + }; | |
| 6873 | + this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx) | |
| 6852 | 6874 | })) |
| 6853 | 6875 | .drag_over::<ClipDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) |
| 6854 | 6876 | .children(clips.iter().enumerate().map(|(i, clip)| { |
| 6877 | + // The clip as the lane holds it, for the drag payload: | |
| 6878 | + // what a drop looks itself up by has to be the placed | |
| 6879 | + // clip, never the preview an edge drag is drawing. | |
| 6880 | + let placed = *clip; | |
| 6855 | 6881 | // What a drag on an edge is showing, which is the clip |
| 6856 | 6882 | // itself while nothing is being dragged. |
| 6857 | 6883 | let clip = &self.trimmed(lane, i, *clip); |
| @@ -6877,15 +6903,30 @@ impl Player { | ||
| 6877 | 6903 | .unwrap_or(clip.source), |
| 6878 | 6904 | ); |
| 6879 | 6905 | let width = scale.width_px(len); |
| 6906 | + let left = scale.px_at(start); | |
| 6907 | + // The slice of this box that is on the bed: where its | |
| 6908 | + // name, its badge and its waveform go, so none of the | |
| 6909 | + // three is drawn out at a zoomed-in box's own edges. | |
| 6910 | + let (vis_x, vis_w) = visible_slice(left, width, bed); | |
| 6880 | 6911 | let label = sources.get(clip.source).map(|s| file_name(&s.path)); |
| 6881 | 6912 | let wave = sources |
| 6882 | 6913 | .get(clip.source) |
| 6883 | 6914 | .and_then(|s| self.waves.get(&(s.path.clone(), s.audio_stream))) |
| 6884 | 6915 | .cloned(); |
| 6885 | - let (from, to) = ( | |
| 6886 | - f64::from(clip.in_frame) / self.fps, | |
| 6887 | - f64::from(clip.out_frame) / self.fps, | |
| 6888 | - ); | |
| 6916 | + // The source seconds that slice plays -- not the clip's | |
| 6917 | + // whole range: the envelope is drawn for the part of the | |
| 6918 | + // box that can be seen, at the resolution of the pixels | |
| 6919 | + // it actually has, and never one column per two pixels | |
| 6920 | + // of a box millions of pixels wide. | |
| 6921 | + let along = |x: f32| match width > 0. { | |
| 6922 | + true => { | |
| 6923 | + f64::from(clip.in_frame) | |
| 6924 | + + f64::from(clip.out_frame - clip.in_frame) | |
| 6925 | + * f64::from(x / width) | |
| 6926 | + } | |
| 6927 | + false => f64::from(clip.in_frame), | |
| 6928 | + }; | |
| 6929 | + let (from, to) = (along(vis_x) / self.fps, along(vis_x + vis_w) / self.fps); | |
| 6889 | 6930 | let tip = tip.clone(); |
| 6890 | 6931 | // What the pointer carries on the way to another lane: |
| 6891 | 6932 | // the file the box is showing, the same ghost a library |
| @@ -6908,7 +6949,7 @@ impl Player { | ||
| 6908 | 6949 | // off the left edge: the bed clips what hangs out |
| 6909 | 6950 | // of it, so a half-visible clip is drawn as the |
| 6910 | 6951 | // half of itself that is on screen. |
| 6911 | - .left(px(scale.px_at(start))) | |
| 6952 | + .left(px(left)) | |
| 6912 | 6953 | .w(px(width)) |
| 6913 | 6954 | .overflow_hidden() |
| 6914 | 6955 | .rounded(px(3.)) |
| @@ -6929,9 +6970,14 @@ impl Player { | ||
| 6929 | 6970 | // starts the drag still selects, so picking a clip |
| 6930 | 6971 | // up and putting it back down where it was is |
| 6931 | 6972 | // exactly a click. |
| 6932 | - .on_drag(ClipDrag { lane, idx: i }, move |_, _, _, cx| { | |
| 6933 | - cx.new(|_| Tip(ghost.clone())) | |
| 6934 | - }) | |
| 6973 | + .on_drag( | |
| 6974 | + ClipDrag { | |
| 6975 | + lane, | |
| 6976 | + idx: i, | |
| 6977 | + clip: placed, | |
| 6978 | + }, | |
| 6979 | + move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())), | |
| 6980 | + ) | |
| 6935 | 6981 | .on_mouse_down( |
| 6936 | 6982 | MouseButton::Left, |
| 6937 | 6983 | cx.listener(move |this, event: &MouseDownEvent, _, cx| { |
| @@ -6990,7 +7036,7 @@ impl Player { | ||
| 6990 | 7036 | zone |
| 6991 | 7037 | })) |
| 6992 | 7038 | // Under the label row, never through it. |
| 6993 | - .children(wave.filter(|_| audio).and_then(|wave| { | |
| 7039 | + .children(wave.filter(|_| audio && vis_w > 0.).and_then(|wave| { | |
| 6994 | 7040 | let inner: AnyElement = match wave { |
| 6995 | 7041 | Wave::Peaks(peaks) => { |
| 6996 | 7042 | waveform(peaks, from, to).into_any_element() |
| @@ -7026,8 +7072,8 @@ impl Player { | ||
| 7026 | 7072 | Some( |
| 7027 | 7073 | div() |
| 7028 | 7074 | .absolute() |
| 7029 | - .left_0() | |
| 7030 | - .right_0() | |
| 7075 | + .left(px(vis_x)) | |
| 7076 | + .w(px(vis_w)) | |
| 7031 | 7077 | .top(px(LABEL_H)) |
| 7032 | 7078 | .bottom_0() |
| 7033 | 7079 | .child(inner), |
| @@ -7038,24 +7084,44 @@ impl Player { | ||
| 7038 | 7084 | // cannot say whether a short clip is a trim or a |
| 7039 | 7085 | // clip at 4x, and that is the difference between a |
| 7040 | 7086 | // cut and a re-time. |
| 7041 | - .when(!clip.speed.is_normal(), |d| { | |
| 7087 | + // Against the right edge of what is *visible* of the | |
| 7088 | + // box, not of the box: zoomed in, the box's own | |
| 7089 | + // right edge is off the screen and the badge with | |
| 7090 | + // it, which is a clip that stops saying it is | |
| 7091 | + // speeded exactly when it is being looked at | |
| 7092 | + // closely. | |
| 7093 | + .when(!clip.speed.is_normal() && vis_w > 0., |d| { | |
| 7042 | 7094 | d.child( |
| 7043 | 7095 | div() |
| 7044 | 7096 | .absolute() |
| 7045 | 7097 | .top_0() |
| 7046 | - .right_0() | |
| 7047 | - .px(px(3.)) | |
| 7048 | - .rounded(px(3.)) | |
| 7049 | - .bg(rgb(ACCENT)) | |
| 7050 | - .text_size(px(9.)) | |
| 7051 | - .text_color(rgb(SURFACE)) | |
| 7052 | - .child(format!("{}", clip.speed)), | |
| 7098 | + .left(px(vis_x)) | |
| 7099 | + .w(px(vis_w)) | |
| 7100 | + .flex() | |
| 7101 | + .justify_end() | |
| 7102 | + .overflow_hidden() | |
| 7103 | + .child( | |
| 7104 | + div() | |
| 7105 | + .flex_none() | |
| 7106 | + .px(px(3.)) | |
| 7107 | + .rounded(px(3.)) | |
| 7108 | + .bg(rgb(ACCENT)) | |
| 7109 | + .text_size(px(9.)) | |
| 7110 | + .text_color(rgb(SURFACE)) | |
| 7111 | + .child(format!("{}", clip.speed)), | |
| 7112 | + ), | |
| 7053 | 7113 | ) |
| 7054 | 7114 | }) |
| 7055 | - .when_some(label.filter(|_| show_label(width)), |d, label| { | |
| 7115 | + // ...and the name sits at the left edge of the same | |
| 7116 | + // slice, for the same reason: a box scrolled half | |
| 7117 | + // off names itself on the half that is on screen. | |
| 7118 | + .when_some(label.filter(|_| show_label(vis_w)), |d, label| { | |
| 7056 | 7119 | d.child( |
| 7057 | 7120 | div() |
| 7058 | - .relative() | |
| 7121 | + .absolute() | |
| 7122 | + .top_0() | |
| 7123 | + .left(px(vis_x)) | |
| 7124 | + .w(px(vis_w)) | |
| 7059 | 7125 | .h(px(LABEL_H)) |
| 7060 | 7126 | .px(px(4.)) |
| 7061 | 7127 | .truncate() |
| @@ -8455,6 +8521,97 @@ fn show_label(w: f32) -> bool { | ||
| 8455 | 8521 | w >= LABEL_MIN_W |
| 8456 | 8522 | } |
| 8457 | 8523 | |
| 8524 | +/// The clip a trim is *showing*, worked out the way `Project::trim` will write | |
| 8525 | +/// it: the timeline room the edge leaves is turned into source frames by the one | |
| 8526 | +/// conversion that exists for it ([`Speed::fit`]), and the box is drawn from | |
| 8527 | +/// that. The preview and the commit are then the same arithmetic -- a box let go | |
| 8528 | +/// of stays where the hand left it at every rate. Assigning the timeline count | |
| 8529 | +/// straight to the source field, as this used to, drew a speeded clip's tail | |
| 8530 | +/// moving at the wrong rate (it snapped on release) and drew a *head* trim | |
| 8531 | +/// moving the clip's other edge, since the length it implied was not the length | |
| 8532 | +/// the release would commit. | |
| 8533 | +/// | |
| 8534 | +/// A still grows forward from source frame 0 instead: every frame of it is the | |
| 8535 | +/// same picture, so there is no earlier one for an in-point to walk back to. | |
| 8536 | +/// | |
| 8537 | +/// Room too narrow to hold one source frame is the edit the engine refuses, and | |
| 8538 | +/// the box is drawn unchanged rather than as something that will not be | |
| 8539 | +/// committed. | |
| 8540 | +fn trimmed_clip(clip: Clip, edge: Edge, to: u32, still: bool) -> Clip { | |
| 8541 | + // An edge that has not moved is not an edit, and `Project::trim` refuses it | |
| 8542 | + // as one: the press that starts a drag must draw the clip it pressed, not a | |
| 8543 | + // clip a rounding narrower. | |
| 8544 | + if to | |
| 8545 | + == match edge { | |
| 8546 | + Edge::Start => clip.start, | |
| 8547 | + Edge::End => clip.end(), | |
| 8548 | + } | |
| 8549 | + { | |
| 8550 | + return clip; | |
| 8551 | + } | |
| 8552 | + match edge { | |
| 8553 | + Edge::Start => { | |
| 8554 | + // What survives is measured from the *end* -- the frames that stay | |
| 8555 | + // play what they always played, which is what makes this a trim. | |
| 8556 | + let Some(keep) = clip.speed.fit(clip.end().saturating_sub(to)) else { | |
| 8557 | + return clip; | |
| 8558 | + }; | |
| 8559 | + match still { | |
| 8560 | + true => Clip { | |
| 8561 | + in_frame: 0, | |
| 8562 | + out_frame: keep, | |
| 8563 | + start: to, | |
| 8564 | + ..clip | |
| 8565 | + }, | |
| 8566 | + false => Clip { | |
| 8567 | + in_frame: clip.out_frame - keep.min(clip.out_frame), | |
| 8568 | + start: to, | |
| 8569 | + ..clip | |
| 8570 | + }, | |
| 8571 | + } | |
| 8572 | + } | |
| 8573 | + Edge::End => match clip.speed.fit(to.saturating_sub(clip.start)) { | |
| 8574 | + Some(keep) => Clip { | |
| 8575 | + out_frame: clip.in_frame + keep, | |
| 8576 | + ..clip | |
| 8577 | + }, | |
| 8578 | + None => clip, | |
| 8579 | + }, | |
| 8580 | + } | |
| 8581 | +} | |
| 8582 | + | |
| 8583 | +/// Which index on its own lane a dragged clip is at *now*: the one it was picked | |
| 8584 | +/// up at while nothing has moved, and wherever the clip itself has slid to when | |
| 8585 | +/// an edit during the drag rippled the lane's indices -- a delete, an undo or a | |
| 8586 | +/// paste from a stroke, none of which gpui's frozen drag payload hears about. | |
| 8587 | +/// `None` when the clip is gone altogether, and then the drop is not an edit at | |
| 8588 | +/// all: moving whatever slid into its place is the one thing the hand did not | |
| 8589 | +/// ask for. A lane's clips are disjoint and sorted, so at most one of them can | |
| 8590 | +/// be the clip that was picked up. | |
| 8591 | +fn live_idx(clips: &[Clip], idx: usize, clip: Clip) -> Option<usize> { | |
| 8592 | + match clips.get(idx) { | |
| 8593 | + Some(&at) if at == clip => Some(idx), | |
| 8594 | + _ => clips.iter().position(|&c| c == clip), | |
| 8595 | + } | |
| 8596 | +} | |
| 8597 | + | |
| 8598 | +/// The part of a clip's box that is on the bed, in the box's own pixels: | |
| 8599 | +/// `(left, width)` of its intersection with the visible strip. Everything drawn | |
| 8600 | +/// *inside* a box -- its waveform, its name, its speed badge -- is placed in | |
| 8601 | +/// here rather than at the box's own edges, which at a deep zoom sit thousands | |
| 8602 | +/// of pixels off either side of the screen: a label out there is a label nobody | |
| 8603 | +/// can read, and a waveform out there is a path with a point per two pixels of a | |
| 8604 | +/// width nobody can see. A bed that has not been measured yet answers with the | |
| 8605 | +/// whole box, which is what was drawn before there was a bed to clip to. | |
| 8606 | +fn visible_slice(left: f32, width: f32, bed: f32) -> (f32, f32) { | |
| 8607 | + if bed <= 0. { | |
| 8608 | + return (0., width); | |
| 8609 | + } | |
| 8610 | + let from = (-left).clamp(0., width); | |
| 8611 | + let to = (bed - left).clamp(from, width); | |
| 8612 | + (from, to - from) | |
| 8613 | +} | |
| 8614 | + | |
| 8458 | 8615 | /// Scales an envelope to its own loudest sample, so a quietly mastered source |
| 8459 | 8616 | /// still draws as a shape. The fixtures peak around an eighth of full scale, and |
| 8460 | 8617 | /// an eighth of a 30 px lane is a flat line -- which says "silent" about a file |
| @@ -8479,7 +8636,7 @@ fn envelope(peaks: &[(f32, f32)], from: f64, to: f64, w: f32, h: f32) -> Vec<(f3 | ||
| 8479 | 8636 | if peaks.is_empty() || w <= 0. || h <= 0. { |
| 8480 | 8637 | return Vec::new(); |
| 8481 | 8638 | } |
| 8482 | - let cols = (w / WAVE_COL).ceil().max(1.) as usize; | |
| 8639 | + let cols = ((w / WAVE_COL).ceil().max(1.) as usize).min(WAVE_COLS_MAX); | |
| 8483 | 8640 | let mid = h / 2.; |
| 8484 | 8641 | (0..=cols) |
| 8485 | 8642 | .map(|col| { |
| @@ -9068,18 +9225,19 @@ mod tests { | ||
| 9068 | 9225 | LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_ROWS_H, MENU_W, NO_FILE, |
| 9069 | 9226 | PANEL_H, Quality, ROW_H, RULER_HIT_H, SELECTED, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, |
| 9070 | 9227 | SPEED_STEP, SURFACE, SWATCH_W, Source, Speed, StreamInfo, Transport, VOLUME_W, Volume, |
| 9071 | - WAVE_BPS, WAVE_COL, Wave, applicable, band_label, bitrate_refusal, can_add, cancels_export, | |
| 9072 | - clipboard_after_remove, color_snap, containers, envelope, eq_spectrum, eq_x, eq_y, | |
| 9073 | - estimated_mb, export_path, export_settings, format_key, format_line, format_refusal, | |
| 9074 | - fps_label, frac_along, frac_down, frame_at, histogram, is_bare_modifier, is_project, | |
| 9075 | - keymap, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, panel_h, | |
| 9076 | - project_path, push_digit, retarget, scrub_due, show_label, silence_rate, snapped, | |
| 9228 | + WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, Wave, applicable, band_label, bitrate_refusal, can_add, | |
| 9229 | + cancels_export, clipboard_after_remove, color_snap, containers, envelope, eq_spectrum, | |
| 9230 | + eq_x, eq_y, estimated_mb, export_path, export_settings, format_key, format_line, | |
| 9231 | + format_refusal, fps_label, frac_along, frac_down, frame_at, histogram, is_bare_modifier, | |
| 9232 | + is_project, keymap, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, | |
| 9233 | + panel_h, project_path, push_digit, retarget, scrub_due, show_label, silence_rate, snapped, | |
| 9077 | 9234 | source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport, |
| 9078 | 9235 | unseen_paths, unseen_sources, whole_take, window_title, |
| 9079 | 9236 | }; |
| 9080 | 9237 | use super::{ |
| 9081 | - LaneKind, PPS_DEFAULT, Repeat, Scale, View, ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, | |
| 9082 | - file_name, file_uri, library_rows, px_along, repeats, span_label, unscannable, | |
| 9238 | + Edge, LaneKind, PPS_DEFAULT, Repeat, Scale, View, ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, | |
| 9239 | + ZOOM_STEP, file_name, file_uri, library_rows, live_idx, px_along, repeats, span_label, | |
| 9240 | + trimmed_clip, unscannable, visible_slice, | |
| 9083 | 9241 | }; |
| 9084 | 9242 | |
| 9085 | 9243 | /// What the file manager is handed: the parts a path keeps as they are, and |
| @@ -11768,6 +11926,141 @@ mod tests { | ||
| 11768 | 11926 | assert!(!envelope(&peaks, 0., 99., w, h).is_empty()); |
| 11769 | 11927 | } |
| 11770 | 11928 | |
| 11929 | + /// A box laid out wider than any screen -- a long clip at a deep zoom -- is | |
| 11930 | + /// still one screen's worth of columns: the path a repaint has to build is | |
| 11931 | + /// bounded by what can be seen, not by what the layout says the box is. | |
| 11932 | + /// Unbounded, a 5 s clip zoomed to the frame is a path of millions of points | |
| 11933 | + /// per frame, and the repaint that stalls on it is the waveform that | |
| 11934 | + /// "disappeared". | |
| 11935 | + #[test] | |
| 11936 | + fn an_envelope_never_costs_more_points_than_a_screen_can_show() { | |
| 11937 | + let peaks: Vec<(f32, f32)> = (0..200).map(|i| (-(i as f32) / 199., 1.)).collect(); | |
| 11938 | + // The width a 5 s clip is laid out at when the bed shows 8 frames of it. | |
| 11939 | + let huge = 5. * 30. / 8. * 1200.; | |
| 11940 | + let cols = envelope(&peaks, 0., 5., huge, 30.); | |
| 11941 | + assert!( | |
| 11942 | + cols.len() <= WAVE_COLS_MAX + 1, | |
| 11943 | + "{} columns for a {huge} px box", | |
| 11944 | + cols.len() | |
| 11945 | + ); | |
| 11946 | + // ...and the slice actually painted is the part of the box on the bed, | |
| 11947 | + // which is where that width stops mattering: a column per two visible | |
| 11948 | + // pixels, at every zoom. | |
| 11949 | + let (x, w) = visible_slice(-huge / 2., huge, 1200.); | |
| 11950 | + assert_eq!((x, w), (huge / 2., 1200.)); | |
| 11951 | + assert_eq!(envelope(&peaks, 0., 5., w, 30.).len(), 601); | |
| 11952 | + // A box entirely off the bed has no slice, and one that has never been | |
| 11953 | + // measured is drawn whole -- what was drawn before there was a bed. | |
| 11954 | + assert_eq!(visible_slice(2000., 500., 1200.), (0., 0.)); | |
| 11955 | + assert_eq!(visible_slice(-3000., 500., 1200.), (500., 0.)); | |
| 11956 | + assert_eq!(visible_slice(-40., 500., 0.), (0., 500.)); | |
| 11957 | + // Half on, at either edge. | |
| 11958 | + assert_eq!(visible_slice(-100., 500., 1200.), (100., 400.)); | |
| 11959 | + assert_eq!(visible_slice(1000., 500., 1200.), (0., 200.)); | |
| 11960 | + } | |
| 11961 | + | |
| 11962 | + /// The box a trim draws is the box its release commits, at every speed. The | |
| 11963 | + /// preview used to hand the *timeline* frame count to a source-frame field: | |
| 11964 | + /// at 2x a tail moved twice as fast as the pointer and snapped back on | |
| 11965 | + /// release, and a head drag moved the clip's other edge. | |
| 11966 | + #[test] | |
| 11967 | + fn a_trim_preview_lands_where_the_release_commits() { | |
| 11968 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | |
| 11969 | + session.set_gain(0.0); | |
| 11970 | + for permille in SPEED_PRESETS { | |
| 11971 | + // Live, so the loop owes it no undo step: the speeds are the axis | |
| 11972 | + // this walks, and the trims below are what is undone. | |
| 11973 | + session | |
| 11974 | + .set_speed_live(Lane::V1, 0, Speed::from_permille(permille)) | |
| 11975 | + .expect("a clip alone on its lane may be speeded"); | |
| 11976 | + for edge in [Edge::Start, Edge::End] { | |
| 11977 | + let clip = session.lane_clips(Lane::V1)[0]; | |
| 11978 | + let (lo, hi) = session | |
| 11979 | + .trim_room(Lane::V1, 0, edge) | |
| 11980 | + .expect("clip 0 is there"); | |
| 11981 | + // Both walls and the middle of the room: the whole range a | |
| 11982 | + // pointer can be clamped to. | |
| 11983 | + for to in [lo, (lo + hi) / 2, hi] { | |
| 11984 | + let preview = trimmed_clip(clip, edge, to, false); | |
| 11985 | + // The drag is one edit and one undo step, so the next `to` | |
| 11986 | + // is measured from the same clip this one was. | |
| 11987 | + if session.trim_clip(Lane::V1, 0, edge, to) { | |
| 11988 | + assert_eq!( | |
| 11989 | + preview, | |
| 11990 | + session.lane_clips(Lane::V1)[0], | |
| 11991 | + "{edge:?} to {to} at {permille} per mille" | |
| 11992 | + ); | |
| 11993 | + assert!(session.undo(), "the trim is one undo step"); | |
| 11994 | + } else { | |
| 11995 | + // An edge already where it was asked to go is not an | |
| 11996 | + // edit, and the preview draws the clip unchanged. | |
| 11997 | + assert_eq!(preview, clip, "{edge:?} to {to} at {permille} per mille"); | |
| 11998 | + } | |
| 11999 | + assert_eq!(session.lane_clips(Lane::V1)[0], clip, "back where it was"); | |
| 12000 | + } | |
| 12001 | + } | |
| 12002 | + } | |
| 12003 | + } | |
| 12004 | + | |
| 12005 | + /// A still trims the same way, and the preview knows it: its head grows | |
| 12006 | + /// forward from source frame 0 -- every frame of it is the same picture -- | |
| 12007 | + /// so the box stretches instead of sliding left. | |
| 12008 | + #[test] | |
| 12009 | + fn a_stills_trim_preview_grows_forward_like_the_commit() { | |
| 12010 | + let mut session = PlaybackSession::open(asset("test_still.png")).expect("a picture opens"); | |
| 12011 | + for edge in [Edge::Start, Edge::End] { | |
| 12012 | + let clip = session.lane_clips(Lane::V1)[0]; | |
| 12013 | + let (lo, hi) = session | |
| 12014 | + .trim_room(Lane::V1, 0, edge) | |
| 12015 | + .expect("clip 0 is there"); | |
| 12016 | + for to in [lo, (lo + hi) / 2, hi] { | |
| 12017 | + let preview = trimmed_clip(clip, edge, to, true); | |
| 12018 | + match session.trim_clip(Lane::V1, 0, edge, to) { | |
| 12019 | + true => { | |
| 12020 | + assert_eq!( | |
| 12021 | + preview, | |
| 12022 | + session.lane_clips(Lane::V1)[0], | |
| 12023 | + "a still {edge:?} to {to}" | |
| 12024 | + ); | |
| 12025 | + assert!(session.undo(), "the trim is one undo step"); | |
| 12026 | + } | |
| 12027 | + false => assert_eq!(preview, clip, "a still {edge:?} to {to}"), | |
| 12028 | + } | |
| 12029 | + assert_eq!(session.lane_clips(Lane::V1)[0], clip, "back where it was"); | |
| 12030 | + } | |
| 12031 | + } | |
| 12032 | + } | |
| 12033 | + | |
| 12034 | + /// gpui freezes a drag's payload for the whole gesture, and nothing stops a | |
| 12035 | + /// stroke from editing the lane under it: the drop has to find the clip that | |
| 12036 | + /// was picked up, not whatever slid into its index. | |
| 12037 | + #[test] | |
| 12038 | + fn a_drop_moves_the_clip_that_was_picked_up_not_its_old_index() { | |
| 12039 | + let at = |start: u32| Clip { | |
| 12040 | + start, | |
| 12041 | + in_frame: 0, | |
| 12042 | + out_frame: 30, | |
| 12043 | + source: 0, | |
| 12044 | + link: None, | |
| 12045 | + eq: None, | |
| 12046 | + color: None, | |
| 12047 | + fit: FitPolicy::Fit, | |
| 12048 | + speed: Speed::NORMAL, | |
| 12049 | + }; | |
| 12050 | + let lane = [at(0), at(30), at(60)]; | |
| 12051 | + let dragged = lane[2]; | |
| 12052 | + assert_eq!(live_idx(&lane, 2, dragged), Some(2), "nothing moved"); | |
| 12053 | + // A delete in front of it: the clip is now index 1, and the index the | |
| 12054 | + // drag froze names a clip nobody grabbed. | |
| 12055 | + let after = [at(0), at(60)]; | |
| 12056 | + assert_eq!(live_idx(&after, 2, dragged), Some(1)); | |
| 12057 | + assert_eq!(live_idx(&after, 1, dragged), Some(1)); | |
| 12058 | + // Deleted mid-drag: there is nothing to move, and moving its neighbour | |
| 12059 | + // instead is exactly the bug this exists for. | |
| 12060 | + assert_eq!(live_idx(&[at(0)], 2, dragged), None); | |
| 12061 | + assert_eq!(live_idx(&[], 0, dragged), None); | |
| 12062 | + } | |
| 12063 | + | |
| 11771 | 12064 | #[test] |
| 11772 | 12065 | fn a_quiet_source_still_draws_as_a_shape() { |
| 11773 | 12066 | // An eighth of full scale, which is about where the fixtures sit. |