forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'main' into worktree-agent-ab451a54bd7e67440

Browse files at this commit

3e1164354e0deaf78ac9ed9b69fa3e310a2fde0bAhmet Kaan GümüşParent: c0a1847a3839ac

24 changed files +1336 -379

crates/app/src/export_ui.rsmodified+9 -8
@@ -821,14 +821,15 @@ pub(crate) fn commit_mbps(text: &str) -> Result<u32, String> {
821 }821 }
822 }822 }
823 823
824-/// Whether a stroke gets out of a running export. Escape does, whatever824+/// Whether a stroke gets out of a running export. `ctrl+escape` does -- a chord
825-/// modifiers are held with it, for the same reason it gets out of a capture and825+/// and not the bare key, which used to end an hour of encoding on the stroke a
826-/// out of the overlay: it is this window's way out, and a way out that only826+/// hand reaches for to shut a menu it has already shut. Bare escape does nothing
827-/// works with the right modifiers is not one. Whatever the keymap has on cancel827+/// at all here: the progress card is not dismissable, so there is nothing left
828-/// works too, so rebinding it adds a way rather than replacing the one that828+/// for it to mean. Whatever the keymap has on cancel works too, so rebinding it
829-/// always worked -- and that binding is still what the progress line shows.829+/// adds a way rather than replacing this one -- and that binding is what the
830-pub(crate) fn cancels_export(key: &str, action: Option<ActionId>) -> bool {830+/// card shows.
831- key == ESCAPE || action == Some(ActionId::CancelExport)831+pub(crate) fn cancels_export(key: &str, ctrl: bool, action: Option<ActionId>) -> bool {
832+ (ctrl && key == ESCAPE) || action == Some(ActionId::CancelExport)
832 }833 }
833 834
834 /// A clip's share of the lane. A timeline with no length reads as one full-width835 /// A clip's share of the lane. A timeline with no length reads as one full-width
crates/app/src/interact.rsmodified+19 -0
@@ -25,6 +25,25 @@ pub(crate) struct ClipDrag {
25 pub(crate) clip: Clip,25 pub(crate) clip: Clip,
26 }26 }
27 27
28+/// A *palette* subtitle row being dragged onto a subtitle lane: which track of
29+/// [`PlaybackSession::subtitles`] it is, which is the whole of what a row names.
30+/// The window it lands with is the track's own, from its first microsecond to
31+/// its last cue -- a placement is trimmed after it is placed, like every clip
32+/// here.
33+pub(crate) struct SubPick(pub(crate) usize);
34+
35+/// A subtitle already placed on a lane being dragged: [`ClipDrag`]'s twin, and
36+/// carrying the placement itself for that struct's reason -- an edit made during
37+/// the gesture moves the indices gpui froze into the payload, so the drop finds
38+/// its placement by value ([`Player::dragged_sub`]) rather than by an index that
39+/// may since have become another caption's.
40+#[derive(Clone, Copy)]
41+pub(crate) struct SubDrag {
42+ pub(crate) lane: Lane,
43+ pub(crate) idx: usize,
44+ pub(crate) sub: SubClip,
45+}
46+
28 /// A track *header* being dragged: which track the hand took hold of, to be47 /// A track *header* being dragged: which track the hand took hold of, to be
29 /// let go over the header of the one whose place it is to take48 /// let go over the header of the one whose place it is to take
30 /// ([`Player::reorder_lane`]). The lane alone -- a track carries its own clips49 /// ([`Player::reorder_lane`]). The lane alone -- a track carries its own clips
crates/app/src/keymap.rsmodified+41 -17
@@ -99,8 +99,13 @@ actions! {
99 AddAudioLane,99 AddAudioLane,
100 RemoveVideoLane,100 RemoveVideoLane,
101 RemoveAudioLane,101 RemoveAudioLane,
102- AddSubtitleTrack,102+ AddSubtitleLane,
103- RemoveSubtitleTrack,103+ RemoveSubtitleLane,
104+ /// The palette's own door: a file's subtitle tracks read into the list the
105+ /// panel shows, which is where a lane's words are dragged *from*. Adding a
106+ /// track to that list places nothing -- the pair above it is what makes the
107+ /// timeline row a caption can land on.
108+ ImportSubtitles,
104 ToggleMute,109 ToggleMute,
105 VolumeUp,110 VolumeUp,
106 VolumeDown,111 VolumeDown,
@@ -172,8 +177,9 @@ impl ActionId {
172 ActionId::AddAudioLane => "Add an audio track",177 ActionId::AddAudioLane => "Add an audio track",
173 ActionId::RemoveVideoLane => "Remove the last video track (it must be empty)",178 ActionId::RemoveVideoLane => "Remove the last video track (it must be empty)",
174 ActionId::RemoveAudioLane => "Remove the last audio track (it must be empty)",179 ActionId::RemoveAudioLane => "Remove the last audio track (it must be empty)",
175- ActionId::AddSubtitleTrack => "Add subtitles from a file…",180+ ActionId::AddSubtitleLane => "Add a subtitle track",
176- ActionId::RemoveSubtitleTrack => "Remove the picked subtitle track",181+ ActionId::RemoveSubtitleLane => "Remove the last subtitle track (it must be empty)",
182+ ActionId::ImportSubtitles => "Add subtitles from a file…",
177 ActionId::ToggleMute => "Mute / Unmute",183 ActionId::ToggleMute => "Mute / Unmute",
178 ActionId::VolumeUp => "Volume up",184 ActionId::VolumeUp => "Volume up",
179 ActionId::VolumeDown => "Volume down",185 ActionId::VolumeDown => "Volume down",
@@ -228,8 +234,9 @@ impl ActionId {
228 ActionId::AddAudioLane => "add-audio-lane",234 ActionId::AddAudioLane => "add-audio-lane",
229 ActionId::RemoveVideoLane => "remove-video-lane",235 ActionId::RemoveVideoLane => "remove-video-lane",
230 ActionId::RemoveAudioLane => "remove-audio-lane",236 ActionId::RemoveAudioLane => "remove-audio-lane",
231- ActionId::AddSubtitleTrack => "add-subtitle-track",237+ ActionId::AddSubtitleLane => "add-subtitle-lane",
232- ActionId::RemoveSubtitleTrack => "remove-subtitle-track",238+ ActionId::RemoveSubtitleLane => "remove-subtitle-lane",
239+ ActionId::ImportSubtitles => "import-subtitles",
233 ActionId::ToggleMute => "toggle-mute",240 ActionId::ToggleMute => "toggle-mute",
234 ActionId::VolumeUp => "volume-up",241 ActionId::VolumeUp => "volume-up",
235 ActionId::VolumeDown => "volume-down",242 ActionId::VolumeDown => "volume-down",
@@ -319,8 +326,12 @@ impl ActionId {
319 // they add is on the timeline and goes into the file an export326 // they add is on the timeline and goes into the file an export
320 // writes, where the toggle two headings down only decides whether327 // writes, where the toggle two headings down only decides whether
321 // this window draws it.328 // this window draws it.
322- | ActionId::AddSubtitleTrack329+ | ActionId::AddSubtitleLane
323- | ActionId::RemoveSubtitleTrack330+ | ActionId::RemoveSubtitleLane
331+ // ...and the door that fills the palette those lanes are dragged
332+ // from: it edits no lane, but what it brings in is the project's
333+ // and is saved with it, which is not a view setting.
334+ | ActionId::ImportSubtitles
324 | ActionId::RemoveAudioLane => Category::Editing,335 | ActionId::RemoveAudioLane => Category::Editing,
325 ActionId::ToggleMute336 ActionId::ToggleMute
326 | ActionId::VolumeUp337 | ActionId::VolumeUp
@@ -806,8 +817,12 @@ impl Keymap {
806 // ctrl chord takes it back. Ctrl+s is that save, so the removal817 // ctrl chord takes it back. Ctrl+s is that save, so the removal
807 // takes the other letter subtitles already answer to here: "t"818 // takes the other letter subtitles already answer to here: "t"
808 // shows and hides them, and ctrl+t takes one off the timeline.819 // shows and hides them, and ctrl+t takes one off the timeline.
809- b(ActionId::AddSubtitleTrack, "s", false),820+ b(ActionId::AddSubtitleLane, "s", false),
810- b(ActionId::RemoveSubtitleTrack, "t", true),821+ b(ActionId::RemoveSubtitleLane, "t", true),
822+ // Reading a file's tracks into the palette is not adding a
823+ // track to the timeline, so it is not the bare "s": ctrl+i, the
824+ // i of import, free and next to nothing that deletes.
825+ b(ActionId::ImportSubtitles, "i", true),
811 b(ActionId::ToggleMute, "m", false),826 b(ActionId::ToggleMute, "m", false),
812 // The unshifted pair, which is what gpui reports for those two827 // The unshifted pair, which is what gpui reports for those two
813 // keys ("=" and "-", platform.rs:862): the volume keys every828 // keys ("=" and "-", platform.rs:862): the volume keys every
@@ -854,7 +869,12 @@ impl Keymap {
854 // it is a preference set once, not a stroke wanted under a hand869 // it is a preference set once, not a stroke wanted under a hand
855 // that is editing.870 // that is editing.
856 b(ActionId::Theme, "h", true),871 b(ActionId::Theme, "h", true),
857- b(ActionId::CancelExport, "escape", false),872+ // A chord, and the only escape in this table: bare `esc` is the
873+ // stroke a hand throws at anything on screen, and throwing it
874+ // at a running export used to delete an hour of encoding. The
875+ // key stays the one people look for -- the modifier is what
876+ // makes it an intention ([`crate::cancels_export`]).
877+ b(ActionId::CancelExport, "escape", true),
858 // The help key, where every program's list of what it can do878 // The help key, where every program's list of what it can do
859 // has always been. Free -- gpui names it "f1"879 // has always been. Free -- gpui names it "f1"
860 // (platform.rs:880, the keysym's own name lowercased) -- and880 // (platform.rs:880, the keysym's own name lowercased) -- and
@@ -1123,7 +1143,7 @@ mod tests {
1123 #[test]1143 #[test]
1124 fn every_default_stroke_reaches_its_action() {1144 fn every_default_stroke_reaches_its_action() {
1125 let k = Keymap::defaults();1145 let k = Keymap::defaults();
1126- assert_eq!(k.entries().len(), 51);1146+ assert_eq!(k.entries().len(), 52);
1127 assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies));1147 assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies));
1128 assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies));1148 assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies));
1129 assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions));1149 assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions));
@@ -1174,8 +1194,10 @@ mod tests {
1174 assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane));1194 assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane));
1175 // The subtitle pair, the third kind of track: the initial adds and the1195 // The subtitle pair, the third kind of track: the initial adds and the
1176 // subtitle letter's chord takes it back.1196 // subtitle letter's chord takes it back.
1177- assert_eq!(k.lookup("s", false), Some(ActionId::AddSubtitleTrack));1197+ assert_eq!(k.lookup("s", false), Some(ActionId::AddSubtitleLane));
1178- assert_eq!(k.lookup("t", true), Some(ActionId::RemoveSubtitleTrack));1198+ assert_eq!(k.lookup("t", true), Some(ActionId::RemoveSubtitleLane));
1199+ // ...and the palette's own door, which adds no track to the timeline.
1200+ assert_eq!(k.lookup("i", true), Some(ActionId::ImportSubtitles));
1179 assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute));1201 assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute));
1180 assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer));1202 assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer));
1181 // The volume pair is the unshifted one, so neither needs a modifier1203 // The volume pair is the unshifted one, so neither needs a modifier
@@ -1183,7 +1205,9 @@ mod tests {
1183 assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp));1205 assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp));
1184 assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown));1206 assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown));
1185 assert_eq!(k.lookup("+", false), None);1207 assert_eq!(k.lookup("+", false), None);
1186- assert_eq!(k.lookup("escape", false), Some(ActionId::CancelExport));1208+ // The chord, and *only* the chord: bare escape reaches no action at all.
1209+ assert_eq!(k.lookup("escape", true), Some(ActionId::CancelExport));
1210+ assert_eq!(k.lookup("escape", false), None);
1187 // The modifier is half the chord: ctrl+e is not e.1211 // The modifier is half the chord: ctrl+e is not e.
1188 assert_eq!(k.lookup("e", true), None);1212 assert_eq!(k.lookup("e", true), None);
1189 assert_eq!(k.lookup("space", true), None);1213 assert_eq!(k.lookup("space", true), None);
@@ -1205,7 +1229,7 @@ mod tests {
1205 let text = emit(&Keymap::defaults());1229 let text = emit(&Keymap::defaults());
1206 assert!(text.starts_with("edith-keys 1\nplay space\n"));1230 assert!(text.starts_with("edith-keys 1\nplay space\n"));
1207 assert!(text.contains("save ctrl+s\n"));1231 assert!(text.contains("save ctrl+s\n"));
1208- assert!(text.contains("cancel-export escape\n"));1232+ assert!(text.contains("cancel-export ctrl+escape\n"));
1209 // Both directions: the file this writes is the file it reads back, and1233 // Both directions: the file this writes is the file it reads back, and
1210 // a file read in comes out byte for byte as it went.1234 // a file read in comes out byte for byte as it went.
1211 assert_eq!(whole(&text), Keymap::defaults());1235 assert_eq!(whole(&text), Keymap::defaults());
@@ -1372,7 +1396,7 @@ mod tests {
1372 assert_eq!(k.display(ActionId::Delete), "x or delete");1396 assert_eq!(k.display(ActionId::Delete), "x or delete");
1373 assert_eq!(k.display(ActionId::Undo), "z or ctrl+z");1397 assert_eq!(k.display(ActionId::Undo), "z or ctrl+z");
1374 // The one key whose common name is not gpui's.1398 // The one key whose common name is not gpui's.
1375- assert_eq!(k.display(ActionId::CancelExport), "esc");1399+ assert_eq!(k.display(ActionId::CancelExport), "ctrl+esc");
1376 assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");1400 assert_eq!(whole("edith-keys 1\n").display(ActionId::Cut), "unbound");
1377 // The label is the editor's column, and never the file's word for it.1401 // The label is the editor's column, and never the file's word for it.
1378 assert_eq!(ActionId::CancelExport.label(), "Cancel export");1402 assert_eq!(ActionId::CancelExport.label(), "Cancel export");
crates/app/src/layout.rsmodified+0 -14
@@ -142,10 +142,6 @@ pub(crate) fn sub_bottom(bars_h: f32) -> f32 {
142 // height -- either way there is nothing to clear.142 // height -- either way there is nothing to clear.
143 SUB_BOTTOM + bars_h.max(0.)143 SUB_BOTTOM + bars_h.max(0.)
144 }144 }
145-/// The subtitle strip under the lanes: thin, because it is a picture of where
146-/// the cues are and nothing on it can be dragged -- `HIT_MIN` binds targets, and
147-/// this row has none.
148-pub(crate) const SUB_LANE_H: f32 = 16.;
149 /// A mark narrower than this is still drawn this wide: a one-frame cue on a145 /// A mark narrower than this is still drawn this wide: a one-frame cue on a
150 /// zoomed-out bed is worth a fraction of a pixel, and a mark nobody can see says146 /// zoomed-out bed is worth a fraction of a pixel, and a mark nobody can see says
151 /// the track is empty. The silence preview's marks are floored by it too -- they147 /// the track is empty. The silence preview's marks are floored by it too -- they
@@ -229,16 +225,6 @@ pub(crate) fn px_below(max_offset_h: f32, offset_y: f32) -> f32 {
229 (max_offset_h + offset_y).max(0.)225 (max_offset_h + offset_y).max(0.)
230 }226 }
231 227
232-/// What the subtitle strip adds to the panel: its own row and the panel's gap
233-/// above it, and nothing at all for a timeline with no subtitles on it -- the
234-/// picture does not pay for a strip that is not drawn.
235-pub(crate) fn subtitle_strip_h(shown: bool) -> f32 {
236- match shown {
237- true => SUB_LANE_H + 8.,
238- false => 0.,
239- }
240-}
241-
242 /// How tall the panel is with `lanes` tracks in it: [`PANEL_H`] is sized for the228 /// How tall the panel is with `lanes` tracks in it: [`PANEL_H`] is sized for the
243 /// two a project starts with, and every further one adds its own row -- up to229 /// two a project starts with, and every further one adds its own row -- up to
244 /// [`LANES_MAX`], past which the lane column scrolls instead and the panel stops230 /// [`LANES_MAX`], past which the lane column scrolls instead and the panel stops
crates/app/src/main.rsmodified+41 -13
@@ -58,7 +58,7 @@ use engine::decode::Backend;
58 use engine::eq::{Band, BandKind, EqParams};58 use engine::eq::{Band, BandKind, EqParams};
59 use engine::export::{AUDIO_KBPS, DEFAULT_AUDIO_KBPS, EncoderSeat, ExportSettings, Format};59 use engine::export::{AUDIO_KBPS, DEFAULT_AUDIO_KBPS, EncoderSeat, ExportSettings, Format};
60 use engine::limiter::Limiter;60 use engine::limiter::Limiter;
61-use engine::project::{Edge, Lane, LaneKind, Source, Speed};61+use engine::project::{Edge, Lane, LaneKind, Source, Speed, SubClip};
62 use engine::scale::FitPolicy;62 use engine::scale::FitPolicy;
63 use engine::tonemap::Preset;63 use engine::tonemap::Preset;
64 use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession};64 use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession};
@@ -86,11 +86,11 @@ struct Player {
86 /// drawn ([`engine::subtitle::CueImage::rgba`]), which is a thing to do86 /// drawn ([`engine::subtitle::CueImage::rgba`]), which is a thing to do
87 /// when the cue changes -- every few seconds -- and not at every repaint.87 /// when the cue changes -- every few seconds -- and not at every repaint.
88 ///88 ///
89- /// The *track* is half the key because the four PGS tracks of a remux are89+ /// The *lane* is half the key because the four PGS tracks of a remux are
90- /// one film's subtitles in four languages: they start at the same90+ /// one film's subtitles in four languages: placed one over the other they
91- /// microsecond, and a picked row that only changed the language would go on91+ /// start at the same microsecond, and a lane whose eye was shut would leave
92- /// showing the one before it.92+ /// the one before it on screen.
93- sub_image: Option<((usize, i64), Arc<RenderImage>)>,93+ sub_image: Option<((Lane, i64), Arc<RenderImage>)>,
94 /// A frame that arrived before its time; shown on the tick it comes due.94 /// A frame that arrived before its time; shown on the tick it comes due.
95 /// The pump's buffer, not transport state -- but a frame waiting here is95 /// The pump's buffer, not transport state -- but a frame waiting here is
96 /// what keeps a finished decoder from reading as [`Transport::Ended`] one96 /// what keeps a finished decoder from reading as [`Transport::Ended`] one
@@ -228,18 +228,39 @@ struct Player {
228 /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement228 /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement
229 /// no magnet may take away.229 /// no magnet may take away.
230 snap: bool,230 snap: bool,
231- /// Whether the cue under the playhead is drawn over the picture. On by231+ /// Whether the subtitle lanes draw at all -- the mute over every lane's eye
232- /// default -- a subtitle imported and then invisible is an import nobody can232+ /// ([`Player::subs_off`]), not a lane of its own. On by default and off by
233- /// tell happened -- and off by one stroke233+ /// one stroke
234 /// ([`ActionId::ToggleSubtitles`](keymap::ActionId::ToggleSubtitles)) for234 /// ([`ActionId::ToggleSubtitles`](keymap::ActionId::ToggleSubtitles)) for
235 /// anyone watching the picture rather than reading it. The player's, not the235 /// anyone watching the picture rather than reading it. The player's, not the
236 /// project's: it changes nothing that is saved and nothing that is exported.236 /// project's: it changes nothing that is saved and nothing that is exported.
237 subs_on: bool,237 subs_on: bool,
238- /// Which subtitle track is the one on screen: an index into238+ /// Which palette row is *selected*: an index into
239- /// [`PlaybackSession::subtitles`], since a file may carry several and only239+ /// [`PlaybackSession::subtitles`], which is what the × takes off
240- /// one can be read at a time. Cleared with the timeline like every other240+ /// ([`ActionId::RemoveSubtitleTrack`](keymap::ActionId::RemoveSubtitleTrack))
241- /// index here -- track 2 of one project is not track 2 of the next.241+ /// and what the list marks. A selection and nothing more -- what is on
242+ /// screen is what is placed on a subtitle lane
243+ /// ([`Player::subtitle_overlay`]), so picking a row shows nothing by itself,
244+ /// exactly as clicking a media row plays nothing. Cleared with the timeline
245+ /// like every other index here -- track 2 of one project is not track 2 of
246+ /// the next.
242 sub_track: usize,247 sub_track: usize,
248+ /// The subtitle lanes whose eye is shut: every lane shows its captions
249+ /// until this says otherwise, so a lane that was just added is a lane that
250+ /// draws. Held as the lanes that are *off* rather than a flag per lane, so
251+ /// adding one needs no bookkeeping at all.
252+ ///
253+ /// Read where the cues are drawn ([`Player::subtitle_overlay`]): shutting an
254+ /// eye takes that lane's plate off the picture and leaves its captions on
255+ /// the lane. Not saved -- a `.edith` has no line for it yet.
256+ ///
257+ /// A [`Lane`] handle is a position among its kind, so a removal or a
258+ /// reorder leaves every shut eye naming another track: they are dropped
259+ /// wholesale there, exactly as the selection and the open cards are
260+ /// ([`Player::remove_lane`], [`Player::reorder_lane`]) -- which is why a
261+ /// lane added in a removed one's place opens with its eye open, as every
262+ /// new lane does.
263+ subs_off: Vec<Lane>,
243 /// The frame the live gesture is about to land on, or `None` while it is264 /// The frame the live gesture is about to land on, or `None` while it is
244 /// over open bed: the line every lane draws so the snap is seen before it265 /// over open bed: the line every lane draws so the snap is seen before it
245 /// happens rather than discovered after the release. Stale between gestures,266 /// happens rather than discovered after the release. Stale between gestures,
@@ -265,6 +286,11 @@ struct Player {
265 /// handle is held until the worker settles, because its last act is to286 /// handle is held until the worker settles, because its last act is to
266 /// delete the output file and a second export must not be what it deletes.287 /// delete the output file and a second export must not be what it deletes.
267 cancelling: bool,288 cancelling: bool,
289+ /// The pointer asked to cancel and the progress card is showing the pair
290+ /// that answers it ("Keep exporting" / "Cancel export"). One press is never
291+ /// the cancel itself: an hour of encoding must not end on a stray click,
292+ /// which is the reason the stroke is a chord too ([`cancels_export`]).
293+ cancel_armed: bool,
268 /// When the running export started, and how far it had come at each sample294 /// When the running export started, and how far it had come at each sample
269 /// since, as `(elapsed, progress)` marks. The elapsed clock and the295 /// since, as `(elapsed, progress)` marks. The elapsed clock and the
270 /// rolling-window estimate the progress line reads; see [`note_progress`].296 /// rolling-window estimate the progress line reads; see [`note_progress`].
@@ -629,6 +655,7 @@ fn main() {
629 snap: true,655 snap: true,
630 subs_on: true,656 subs_on: true,
631 sub_track: 0,657 sub_track: 0,
658+ subs_off: Vec::new(),
632 snap_cue: None,659 snap_cue: None,
633 ghost: None,660 ghost: None,
634 lane_drop: None,661 lane_drop: None,
@@ -636,6 +663,7 @@ fn main() {
636 last_target: 0,663 last_target: 0,
637 export: None,664 export: None,
638 cancelling: false,665 cancelling: false,
666+ cancel_armed: false,
639 export_started: None,667 export_started: None,
640 export_marks: Vec::new(),668 export_marks: Vec::new(),
641 // Both derived from the file when it lands, by the same669 // Both derived from the file when it lands, by the same
crates/app/src/oracle.rsmodified+5 -5
@@ -186,11 +186,11 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable {
186 // Nothing to draw over the picture, so nothing to switch off: the186 // Nothing to draw over the picture, so nothing to switch off: the
187 // library says how subtitles arrive, and this row would flip a state187 // library says how subtitles arrive, and this row would flip a state
188 // with no visible half either way.188 // with no visible half either way.
189- // ...and nothing to take off the timeline either, for the same reason:189+ //
190- // the row would name a track that is not there.190+ // The × on a palette row is refused by this very fact and asks this very
191- ActionId::ToggleSubtitles | ActionId::RemoveSubtitleTrack if !ctx.subtitles => {191+ // arm ([`Player::remove_subtitle_track`]): an empty list is a list with
192- Enable::No("no subtitles yet")192+ // no row to take off, said in the same words the toggle says it in.
193- }193+ ActionId::ToggleSubtitles if !ctx.subtitles => Enable::No("no subtitles yet"),
194 // Not `No`: with nothing running there is no export for this to be194 // Not `No`: with nothing running there is no export for this to be
195 // about at all, which is what keeps `esc` -- the same key -- a quiet195 // about at all, which is what keeps `esc` -- the same key -- a quiet
196 // way out of a card rather than a line about exports.196 // way out of a card rather than a line about exports.
crates/app/src/player/actions.rsmodified+31 -27
@@ -73,11 +73,14 @@ impl Player {
73 // through the × in its own header.73 // through the × in its own header.
74 ActionId::RemoveVideoLane => self.remove_last_lane(LaneKind::Video, cx),74 ActionId::RemoveVideoLane => self.remove_last_lane(LaneKind::Video, cx),
75 ActionId::RemoveAudioLane => self.remove_last_lane(LaneKind::Audio, cx),75 ActionId::RemoveAudioLane => self.remove_last_lane(LaneKind::Audio, cx),
76- // The same chooser the + S button opens, and the picked row -- the76+ // The third kind of track, added and taken back exactly as the two
77- // one the panel draws highlighted -- for the removal: the × on any77+ // above it: what a caption is dragged onto. The words themselves
78- // other row is that row's own door, and both doors are one call.78+ // arrive by the door below, which places nothing.
79- ActionId::AddSubtitleTrack => self.pick_and_add_subtitles(cx),79+ ActionId::AddSubtitleLane => self.add_lane(LaneKind::Subtitle, cx),
80- ActionId::RemoveSubtitleTrack => self.remove_subtitle_track(self.sub_track, cx),80+ ActionId::RemoveSubtitleLane => self.remove_last_lane(LaneKind::Subtitle, cx),
81+ // The chooser the palette's own button opens: a file's tracks into
82+ // the list, the file itself joining nothing.
83+ ActionId::ImportSubtitles => self.pick_and_add_subtitles(cx),
81 ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx),84 ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx),
82 ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx),85 ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx),
83 ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx),86 ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx),
@@ -163,33 +166,34 @@ impl Player {
163 self.keys_scroll.set_offset(point(px(0.), px(at)));166 self.keys_scroll.set_offset(point(px(0.), px(at)));
164 }167 }
165 168
166- /// The cues over the picture, off and on. Says which it is now *and* what is169+ /// The cues over the picture, off and on. Says which it is now *and* how
167- /// on screen while they are on: a toggle whose answer is invisible when the170+ /// much is placed underneath: a toggle whose answer is invisible -- the
168- /// playhead happens to sit between two cues would read as broken.171+ /// playhead between two cues, or a palette full of tracks nobody dragged
172+ /// onto a lane -- would read as broken.
169 pub(crate) fn toggle_subtitles(&mut self, cx: &mut Context<Self>) {173 pub(crate) fn toggle_subtitles(&mut self, cx: &mut Context<Self>) {
170 self.subs_on = !self.subs_on;174 self.subs_on = !self.subs_on;
171- // Named with its film here too: a notice saying "SUBTITLES ON — eng"175+ // Lane facts and not the picked row: what draws is what is *placed*
172- // over a timeline holding two films' eng tracks names neither.176+ // ([`Player::subtitle_overlay`]), so naming the palette selection here
173- let label = self177+ // named a track the toggle never touched.
174- .session178+ let placed = self.placed_captions();
175- .as_ref()179+ self.notify_user(subtitle_toggle_notice(self.subs_on, placed).into());
176- .and_then(|session| sub_pick_name(session.subtitles(), self.sub_track))
177- .unwrap_or_else(|| "nothing imported".to_string());
178- self.notify_user(
179- match self.subs_on {
180- true => format!("SUBTITLES ON — {label}"),
181- false => format!("SUBTITLES OFF — {label} is still on the timeline"),
182- }
183- .into(),
184- );
185 cx.notify();180 cx.notify();
186 }181 }
187 182
188- /// The subtitle track the overlay and the strip are showing: the one a183+ /// How many captions the subtitle lanes hold, all lanes together: what the
189- /// library row picked, or the first there is. `None` with no timeline and184+ /// toggle and the toolbar's own label are about, now that the picture reads
190- /// for an index left over from one that is gone.185+ /// the lanes rather than a pick ([`Player::subtitle_overlay`]). Zero with no
191- pub(crate) fn subtitle_track(&self) -> Option<&engine::subtitle::SubtitleTrack> {186+ /// timeline, and zero for a palette full of tracks nobody placed -- both
192- self.session.as_ref()?.subtitles().get(self.sub_track)187+ /// show nothing, so both read "No subs".
188+ pub(crate) fn placed_captions(&self) -> usize {
189+ let Some(session) = self.session.as_ref() else {
190+ return 0;
191+ };
192+ session
193+ .subtitle_lanes()
194+ .into_iter()
195+ .map(|lane| session.sub_lane(lane).len())
196+ .sum()
193 }197 }
194 198
195 /// Whether the editor can be asked for `action` right now, and why not when199 /// Whether the editor can be asked for `action` right now, and why not when
crates/app/src/player/export.rsmodified+9 -4
@@ -517,8 +517,8 @@ impl Player {
517 /// Worked out from the cues each time rather than kept as a pick, which is517 /// Worked out from the cues each time rather than kept as a pick, which is
518 /// what makes it impossible to desync: a row added or taken off shifts every518 /// what makes it impossible to desync: a row added or taken off shifts every
519 /// index after it, and a stored list would then name tracks nobody chose.519 /// index after it, and a stored list would then name tracks nobody chose.
520- /// `Player::sub_track` stays what it always was -- which track the *overlay*520+ /// `Player::sub_track` stays what it always was -- which palette row the
521- /// draws -- and has no say here.521+ /// list *marks* -- and has no say here.
522 ///522 ///
523 /// The honest input and not the final answer: the engine filters it again523 /// The honest input and not the final answer: the engine filters it again
524 /// per track (a track that could not be read, a picture one) and says so in524 /// per track (a track that could not be read, a picture one) and says so in
@@ -603,8 +603,12 @@ impl Player {
603 // happens to notice it.603 // happens to notice it.
604 self.export_started = Some(Instant::now());604 self.export_started = Some(Instant::now());
605 self.export_marks.clear();605 self.export_marks.clear();
606- // The card has been answered; the progress line takes the panel from606+ // A confirm left armed by the *previous* export would open this one on
607- // here, and it is the running export's escape that matters now.607+ // the pair, offering to cancel a job nobody has asked about yet.
608+ self.cancel_armed = false;
609+ // The card has been answered; the progress card takes the window from
610+ // here ([`Player::export_progress_card`]), and it is the running
611+ // export's chord that matters now.
608 self.export_open = false;612 self.export_open = false;
609 cx.notify();613 cx.notify();
610 }614 }
@@ -615,6 +619,7 @@ impl Player {
615 if let Some(export) = &self.export {619 if let Some(export) = &self.export {
616 export.cancel();620 export.cancel();
617 self.cancelling = true;621 self.cancelling = true;
622+ self.cancel_armed = false;
618 }623 }
619 }624 }
620 625
crates/app/src/player/library.rsmodified+53 -9
@@ -147,8 +147,10 @@ impl Player {
147 self.clipboard = None;147 self.clipboard = None;
148 self.selected = None;148 self.selected = None;
149 self.selected_asset = None;149 self.selected_asset = None;
150- // The subtitle rows go with the timeline they were on.150+ // The subtitle rows go with the timeline they were on, and so do the
151+ // eyes: S1 of one project is not S1 of the next.
151 self.sub_track = 0;152 self.sub_track = 0;
153+ self.subs_off.clear();
152 self.context_menu = None;154 self.context_menu = None;
153 self.library_menu = None;155 self.library_menu = None;
154 self.eq_open = None;156 self.eq_open = None;
@@ -691,7 +693,7 @@ impl Player {
691 // same question -- and *before* the chooser rather than after it: a door693 // same question -- and *before* the chooser rather than after it: a door
692 // that opens a dialog, waits for a file and only then says the timeline694 // that opens a dialog, waits for a file and only then says the timeline
693 // was never there is the second door disagreeing with the first.695 // was never there is the second door disagreeing with the first.
694- if let Some(why) = self.enable(ActionId::AddSubtitleTrack, None).why() {696+ if let Some(why) = self.enable(ActionId::ImportSubtitles, None).why() {
695 let text = format!("NO SUBTITLES ADDED — {why}");697 let text = format!("NO SUBTITLES ADDED — {why}");
696 eprintln!("{text}");698 eprintln!("{text}");
697 self.notify_user(text.into());699 self.notify_user(text.into());
@@ -782,12 +784,17 @@ impl Player {
782 ) {784 ) {
783 let text = match added {785 let text = match added {
784 Some(Ok(0)) => format!(786 Some(Ok(0)) => format!(
785- "{}'s subtitles are on the timeline already",787+ "{}'s subtitles are in the palette already",
786 file_name(path)788 file_name(path)
787 ),789 ),
790+ // Where they are and what to do with them: the tracks are in the
791+ // palette and nothing is placed until one is dragged onto an S
792+ // track, which is the whole of what this door does.
788 Some(Ok(n)) => format!(793 Some(Ok(n)) => format!(
789- "SUBTITLES {} — {n} track(s), showing over the picture, {} hides them",794+ "SUBTITLES {} — {n} track(s) in the palette — drag one onto an S track ({} adds \
795+ one), showing over the picture meanwhile, {} hides them",
790 file_name(path),796 file_name(path),
797+ self.keymap.display(ActionId::AddSubtitleLane),
791 self.keymap.display(ActionId::ToggleSubtitles)798 self.keymap.display(ActionId::ToggleSubtitles)
792 ),799 ),
793 Some(Err(e)) => format!("SUBTITLE IMPORT FAILED: {e}"),800 Some(Err(e)) => format!("SUBTITLE IMPORT FAILED: {e}"),
@@ -816,7 +823,10 @@ impl Player {
816 // action with nothing to act on, and the engine's "there is no subtitle823 // action with nothing to act on, and the engine's "there is no subtitle
817 // track 0" is an index nobody typed. A real removal that fails still824 // track 0" is an index nobody typed. A real removal that fails still
818 // says what the engine said, below.825 // says what the engine said, below.
819- if let Some(why) = self.enable(ActionId::RemoveSubtitleTrack, None).why() {826+ // The palette's list is what this takes a row off, and an empty list is
827+ // the very fact the toggle is refused by -- so the same arm answers
828+ // both (oracle.rs) rather than a second reading of the same state.
829+ if let Some(why) = self.enable(ActionId::ToggleSubtitles, None).why() {
820 let text = format!("NO SUBTITLES REMOVED — {why}");830 let text = format!("NO SUBTITLES REMOVED — {why}");
821 eprintln!("{text}");831 eprintln!("{text}");
822 self.notify_user(text.into());832 self.notify_user(text.into());
@@ -847,8 +857,9 @@ impl Player {
847 // note, for its reason and with its upgrade path.857 // note, for its reason and with its upgrade path.
848 self.sub_image = None;858 self.sub_image = None;
849 format!(859 format!(
850- "{name} REMOVED — {} puts a file's subtitles back on, the file itself stays off",860+ "{name} REMOVED — {} puts a file's subtitles back in the palette, the file \
851- self.keymap.display(ActionId::AddSubtitleTrack)861+ itself stays off",
862+ self.keymap.display(ActionId::ImportSubtitles)
852 )863 )
853 }864 }
854 Some(Err(e)) => format!("NO SUBTITLES REMOVED — {e}"),865 Some(Err(e)) => format!("NO SUBTITLES REMOVED — {e}"),
@@ -954,8 +965,16 @@ impl Player {
954 let lane = session.add_lane(kind);965 let lane = session.add_lane(kind);
955 self.notify_user(966 self.notify_user(
956 format!(967 format!(
957- "{} ADDED — drag a clip onto it, {} takes it back",968+ "{} ADDED — drag {} onto it, {} takes it back",
958 lane.label(),969 lane.label(),
970+ // A subtitle lane takes no clip at all: what lands on it
971+ // is a palette row, so the notice names the panel the
972+ // hand has to go to rather than "a clip", which is the
973+ // one thing that will never work here.
974+ match kind {
975+ LaneKind::Subtitle => "a subtitle from the panel",
976+ _ => "a clip",
977+ },
959 self.keymap.display(ActionId::Undo)978 self.keymap.display(ActionId::Undo)
960 )979 )
961 .into(),980 .into(),
@@ -991,6 +1010,10 @@ impl Player {
991 self.color_open = None;1010 self.color_open = None;
992 self.speed_open = None;1011 self.speed_open = None;
993 self.close_silence();1012 self.close_silence();
1013+ // The eyes with them: a `Lane` is a position among its
1014+ // kind, so every shut one now names another track --
1015+ // the same reason the selection and the cards go.
1016+ self.subs_off.clear();
994 format!(1017 format!(
995 "{} REMOVED — {} brings it back",1018 "{} REMOVED — {} brings it back",
996 lane.label(),1019 lane.label(),
@@ -1043,6 +1066,10 @@ impl Player {
1043 self.color_open = None;1066 self.color_open = None;
1044 self.speed_open = None;1067 self.speed_open = None;
1045 self.close_silence();1068 self.close_silence();
1069+ // The eyes with them: a `Lane` is a position among its
1070+ // kind, so every shut one now names another track --
1071+ // the same reason the selection and the cards go.
1072+ self.subs_off.clear();
1046 }1073 }
1047 self.notify_user(1074 self.notify_user(
1048 format!(1075 format!(
@@ -1069,8 +1096,25 @@ impl Player {
1069 });1096 });
1070 match last {1097 match last {
1071 Some(lane) => self.remove_lane(lane, cx),1098 Some(lane) => self.remove_lane(lane, cx),
1099+ // Two different nothings: no timeline at all, and a timeline whose
1100+ // lanes of this kind have all gone -- which is the ordinary state of
1101+ // the subtitle ones, since a project starts with none. "Open a file
1102+ // first" over an open file is a notice that reads as a bug.
1072 None => {1103 None => {
1073- self.notify_user("NO TRACK REMOVED — open a file first".into());1104+ self.notify_user(
1105+ match self.session.is_some() {
1106+ true => format!(
1107+ "NO TRACK REMOVED — there is no {} track to remove",
1108+ match kind {
1109+ LaneKind::Video => "video",
1110+ LaneKind::Audio => "audio",
1111+ LaneKind::Subtitle => "subtitle",
1112+ }
1113+ ),
1114+ false => "NO TRACK REMOVED — open a file first".to_string(),
1115+ }
1116+ .into(),
1117+ );
1074 cx.notify();1118 cx.notify();
1075 }1119 }
1076 }1120 }
crates/app/src/player/timeline_edit.rsmodified+240 -5
@@ -264,6 +264,184 @@ impl Player {
264 cx.notify();264 cx.notify();
265 }265 }
266 266
267+ /// The whole of a palette track as a placement: from its own first
268+ /// microsecond to its last cue, and as many timeline frames as that is worth
269+ /// at this rate. What a row dragged out of the Subtitles list carries, and
270+ /// what the ghost is drawn from -- `start` is ignored by
271+ /// [`PlaybackSession::place_sub`], which takes the frame the hand let go on.
272+ ///
273+ /// `None` for a track with nothing to place: one that could not be read, and
274+ /// one that genuinely has no cues.
275+ pub(crate) fn sub_of_track(&self, track: usize) -> Option<SubClip> {
276+ let cues = &self.session.as_ref()?.subtitles().get(track)?.cues;
277+ let out_us = cues.iter().map(|c| c.end_us).max()?;
278+ Some(SubClip {
279+ start: 0,
280+ frames: frames_of_us(out_us, self.fps),
281+ track,
282+ in_us: 0,
283+ out_us,
284+ })
285+ }
286+
287+ /// A palette row let go at window `x` over subtitle lane `to`: the whole
288+ /// track goes down where the hand left it, one undo step
289+ /// ([`PlaybackSession::place_sub`]). Every refusal there is words -- an
290+ /// overlap, a lane that is not a subtitle lane, a track that is not there --
291+ /// and they are shown as the engine worded them.
292+ pub(crate) fn place_sub(&mut self, track: usize, to: Lane, x: Pixels, cx: &mut Context<Self>) {
293+ if self.exporting().is_some() {
294+ return;
295+ }
296+ self.snap_cue = None;
297+ self.ghost = None;
298+ let at = self.place_frame(x).0;
299+ let text = match (self.sub_of_track(track), &mut self.session) {
300+ (Some(sub), Some(session)) => match session.place_sub(to, at, sub) {
301+ Ok(()) => None,
302+ Err(e) => Some(format!("NOT PLACED — {e}")),
303+ },
304+ // The row is greyed and says why in the list; here it says why at
305+ // the moment somebody tried to use it anyway.
306+ (None, Some(_)) => Some(
307+ "NOT PLACED — that subtitle track has no cues to place; the list says why"
308+ .to_string(),
309+ ),
310+ (_, None) => Some("NOT PLACED — open a file first".to_string()),
311+ };
312+ if let Some(text) = text {
313+ self.notify_user(text.into());
314+ }
315+ cx.notify();
316+ }
317+
318+ /// Which index its lane holds the dragged placement at *now*
319+ /// ([`Player::dragged`]'s twin, through the same [`live_idx`]): a stroke
320+ /// during the gesture -- an undo, another drop -- moves the indices gpui
321+ /// froze into the payload.
322+ pub(crate) fn dragged_sub(&self, drag: &SubDrag) -> Option<usize> {
323+ live_idx(self.session.as_ref()?.sub_lane(drag.lane), drag.idx, drag.sub)
324+ }
325+
326+ /// A placed caption let go at window `x` over subtitle lane `to`: it lands
327+ /// with its head where the hand carried it, on the lane it was dropped on --
328+ /// one undo step, and none at all for a drop that changed nothing, which is
329+ /// why an `Ok` is never a toast ([`Project::move_sub`]). An overlap and a
330+ /// lane of the wrong kind are refused in the engine's own words.
331+ pub(crate) fn move_sub(&mut self, drag: &SubDrag, to: Lane, x: Pixels, cx: &mut Context<Self>) {
332+ if self.exporting().is_some() {
333+ return;
334+ }
335+ self.snap_cue = None;
336+ self.ghost = None;
337+ let Some(idx) = self.dragged_sub(drag) else {
338+ return;
339+ };
340+ let start = self.sub_drop_frame(drag.sub, x).0;
341+ if let Some(Err(e)) = self
342+ .session
343+ .as_mut()
344+ .map(|session| session.move_sub(drag.lane, idx, to, start))
345+ {
346+ self.notify_user(format!("NOT MOVED — {e}").into());
347+ }
348+ cx.notify();
349+ }
350+
351+ /// The × on a caption's own box: it comes off the lane and leaves the gap,
352+ /// one undo step ([`PlaybackSession::lift_sub`]). The palette row it played
353+ /// stays in the list, which is what makes this a lift and not a removal --
354+ /// and the way a subtitle lane is emptied so it can be taken off at all.
355+ pub(crate) fn lift_sub(&mut self, lane: Lane, idx: usize, cx: &mut Context<Self>) {
356+ if self.exporting().is_some() {
357+ return;
358+ }
359+ let lifted = self
360+ .session
361+ .as_mut()
362+ .is_some_and(|session| session.lift_sub(lane, idx));
363+ let text = match lifted {
364+ true => format!(
365+ "CAPTION LIFTED — {} puts it back",
366+ self.keymap.display(ActionId::Undo)
367+ ),
368+ false => "NOTHING LIFTED — that caption is not there any more".to_string(),
369+ };
370+ self.notify_user(text.into());
371+ cx.notify();
372+ }
373+
374+ /// A subtitle lane's eye: whether it draws its captions. State only for now
375+ /// -- what reads it is the slice that draws the lanes over the picture --
376+ /// and said out loud, because a toggle whose only effect is a header glyph
377+ /// has to say what it has and has not done yet.
378+ pub(crate) fn toggle_sub_lane(&mut self, lane: Lane, cx: &mut Context<Self>) {
379+ let text = match self.subs_off.iter().position(|&l| l == lane) {
380+ Some(i) => {
381+ self.subs_off.remove(i);
382+ format!("{} SHOWS ITS CAPTIONS", lane.label())
383+ }
384+ None => {
385+ self.subs_off.push(lane);
386+ format!("{} IS HIDDEN — its captions stay on the lane", lane.label())
387+ }
388+ };
389+ self.notify_user(text.into());
390+ cx.notify();
391+ }
392+
393+ /// Whether that subtitle lane's captions are drawn -- the eye, read by the
394+ /// header that offers it and by whatever draws cues from here on.
395+ pub(crate) fn sub_lane_on(&self, lane: Lane) -> bool {
396+ !self.subs_off.contains(&lane)
397+ }
398+
399+ /// Where a caption let go at window `x` wants its head: [`Player::drop_frame`]'s
400+ /// twin, and the same [`landing`] -- the grab offset the press noted, and the
401+ /// snap onto the edges the rest of the timeline offers, so a caption lands on
402+ /// the cut it is spoken over.
403+ pub(crate) fn sub_drop_frame(&self, sub: SubClip, x: Pixels) -> (u32, Option<u32>) {
404+ let marks = self.snap_targets(None);
405+ landing(
406+ self.frame_under(x),
407+ self.grab,
408+ sub.frames,
409+ self.snap,
410+ self.snap_frames(),
411+ &marks,
412+ )
413+ }
414+
415+ /// The shadow a caption in the hand would fill, on the lane the pointer is
416+ /// over: [`Player::preview_ghost`]'s twin, refused for any lane that is not a
417+ /// subtitle lane -- which is the answer [`Project::move_sub`] gives at the
418+ /// release.
419+ pub(crate) fn preview_ghost_sub(&mut self, drag: &SubDrag, to: Lane, x: Pixels, cx: &mut Context<Self>) {
420+ let (start, _) = self.sub_drop_frame(drag.sub, x);
421+ let ghost = Ghost {
422+ lane: to,
423+ start,
424+ frames: drag.sub.frames,
425+ tint: CLIP_TEXT(),
426+ refused: to.kind != LaneKind::Subtitle,
427+ };
428+ self.set_ghost(Some(ghost), cx);
429+ }
430+
431+ /// The same for a palette row on its way down: it lands at the frame it is
432+ /// let go on ([`Player::place_frame`]) and is as long as the whole track it
433+ /// names.
434+ pub(crate) fn preview_ghost_pick(&mut self, track: usize, to: Lane, x: Pixels, cx: &mut Context<Self>) {
435+ let ghost = Ghost {
436+ lane: to,
437+ start: self.place_frame(x).0,
438+ frames: self.sub_of_track(track).map_or(0, |sub| sub.frames),
439+ tint: CLIP_TEXT(),
440+ refused: to.kind != LaneKind::Subtitle,
441+ };
442+ self.set_ghost(Some(ghost), cx);
443+ }
444+
267 /// Where a clip let go at window `x` over lane `to` wants its head: the445 /// Where a clip let go at window `x` over lane `to` wants its head: the
268 /// frame under the pointer, less however far into the box the hand grabbed446 /// frame under the pointer, less however far into the box the hand grabbed
269 /// it (so the clip does not jump under the pointer), pulled onto a447 /// it (so the clip does not jump under the pointer), pulled onto a
@@ -624,6 +802,33 @@ impl Player {
624 if self.modal() || self.exporting().is_some() {802 if self.modal() || self.exporting().is_some() {
625 return;803 return;
626 }804 }
805+ // A caption's edge, on a lane that holds no `Clip` at all: the same
806+ // gesture, the same `Trim`, and the branch is the lane's kind wherever
807+ // the drag is asked about ([`Player::trim_to`],
808+ // [`Player::commit_trim`]). No selection -- a placement is not in the
809+ // clip selection's index space -- and no group: a caption has no half
810+ // on another lane.
811+ if lane.kind == LaneKind::Subtitle {
812+ let Some(sub) = self
813+ .session
814+ .as_ref()
815+ .and_then(|session| session.sub_lane(lane).get(idx).copied())
816+ else {
817+ return;
818+ };
819+ self.trim = Some(Trim {
820+ lane,
821+ idx,
822+ edge,
823+ to: match edge {
824+ Edge::Start => sub.start,
825+ Edge::End => sub.end(),
826+ },
827+ link: None,
828+ });
829+ cx.notify();
830+ return;
831+ }
627 let Some(clip) = self832 let Some(clip) = self
628 .session833 .session
629 .as_ref()834 .as_ref()
@@ -659,11 +864,16 @@ impl Player {
659 // there is no other end travelling with it, so it snaps at length zero.864 // there is no other end travelling with it, so it snaps at length zero.
660 let marks = self.snap_targets(Some((trim.lane, trim.idx)));865 let marks = self.snap_targets(Some((trim.lane, trim.idx)));
661 let (at, cue) = self.snap_to(self.frame_under(x), 0, &marks);866 let (at, cue) = self.snap_to(self.frame_under(x), 0, &marks);
662- let Some((lo, hi)) = self867+ let Some((lo, hi)) = self.session.as_ref().and_then(|session| {
663- .session868+ match trim.lane.kind == LaneKind::Subtitle {
664- .as_ref()869+ // The walls a caption's edge has -- its neighbour, its own
665- .and_then(|session| session.trim_room(trim.lane, trim.idx, trim.edge))870+ // track's first microsecond and its last cue -- asked at this
666- else {871+ // timeline's rate, which is why the session is the door and not
872+ // the project.
873+ true => session.trim_sub_room(trim.lane, trim.idx, trim.edge),
874+ false => session.trim_room(trim.lane, trim.idx, trim.edge),
875+ }
876+ }) else {
667 return;877 return;
668 };878 };
669 let to = at.clamp(lo, hi);879 let to = at.clamp(lo, hi);
@@ -693,6 +903,22 @@ impl Player {
693 let Some(trim) = self.trim.take() else {903 let Some(trim) = self.trim.take() else {
694 return;904 return;
695 };905 };
906+ // A caption's edge reaches the engine through its own door, at this
907+ // timeline's rate. An `Ok` is *not* "something changed" -- an edge that
908+ // stopped at a wall it already stood against is `Ok` with no undo step
909+ // ([`Project::trim_sub`]) -- so only the refusal is ever said out loud,
910+ // and nothing reseeks: cues are drawn over whatever is decoded.
911+ if trim.lane.kind == LaneKind::Subtitle {
912+ if let Some(Err(e)) = self
913+ .session
914+ .as_mut()
915+ .map(|session| session.trim_sub(trim.lane, trim.idx, trim.edge, trim.to))
916+ {
917+ self.notify_user(format!("NOT TRIMMED — {e}").into());
918+ }
919+ cx.notify();
920+ return;
921+ }
696 let trimmed = self922 let trimmed = self
697 .session923 .session
698 .as_mut()924 .as_mut()
@@ -721,6 +947,15 @@ impl Player {
721 trimmed_clip(clip, trim.edge, trim.to, still)947 trimmed_clip(clip, trim.edge, trim.to, still)
722 }948 }
723 949
950+ /// The caption as the drag is showing it, [`Player::trimmed`]'s twin:
951+ /// display only, and the engine hears about it once, at the release.
952+ pub(crate) fn trimmed_sub(&self, lane: Lane, idx: usize, sub: SubClip) -> SubClip {
953+ match self.trim.filter(|t| (t.lane, t.idx) == (lane, idx)) {
954+ Some(trim) => trimmed_sub(sub, trim.edge, trim.to),
955+ None => sub,
956+ }
957+ }
958+
724 /// How long the timeline is *drawn* as: its own length, and while a tail is959 /// How long the timeline is *drawn* as: its own length, and while a tail is
725 /// being dragged the furthest that tail may reach. A bed that ends exactly960 /// being dragged the furthest that tail may reach. A bed that ends exactly
726 /// at the last frame has nowhere to put a pointer that means "longer", so961 /// at the last frame has nowhere to put a pointer that means "longer", so
crates/app/src/render.rsmodified+21 -1
@@ -141,7 +141,7 @@ impl Render for Player {
141 // would change, so cancelling is the only one that means141 // would change, so cancelling is the only one that means
142 // anything until it is over.142 // anything until it is over.
143 if this.exporting().is_some() {143 if this.exporting().is_some() {
144- if cancels_export(key, action) {144+ if cancels_export(key, ctrl, action) {
145 this.cancel_export();145 this.cancel_export();
146 }146 }
147 cx.notify();147 cx.notify();
@@ -515,6 +515,22 @@ impl Render for Player {
515 this.set_ghost(None, cx);515 this.set_ghost(None, cx);
516 }),516 }),
517 )517 )
518+ // The same pair for the two subtitle gestures, for the same reason:
519+ // a palette row starts up in the library and a caption starts on a
520+ // lane, and both are let go somewhere else entirely.
521+ .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubPick>, _, cx| {
522+ this.preview_place(event.event.position.x, cx);
523+ this.set_ghost(None, cx);
524+ }))
525+ .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubDrag>, _, cx| {
526+ // The placement gpui froze into the payload, whose *length* is
527+ // all the line needs; which caption it is is the drop's
528+ // question ([`Player::dragged_sub`]).
529+ let (drag, x) = (*event.drag(cx), event.event.position.x);
530+ let cue = this.sub_drop_frame(drag.sub, x).1;
531+ this.set_cue(cue, x, cx);
532+ this.set_ghost(None, cx);
533+ }))
518 // Scrubbing is tracked on the root because the pointer leaves the534 // Scrubbing is tracked on the root because the pointer leaves the
519 // 6 px ruler on the first drag and its own listeners then stop535 // 6 px ruler on the first drag and its own listeners then stop
520 // firing; the root's hitbox is the whole window.536 // firing; the root's hitbox is the whole window.
@@ -645,6 +661,10 @@ impl Render for Player {
645 // window.661 // window.
646 .children(self.keys_overlay(cx))662 .children(self.keys_overlay(cx))
647 .children(self.export_card(window.viewport_size(), cx))663 .children(self.export_card(window.viewport_size(), cx))
664+ // The same sheet once the card has been answered: the running
665+ // export is the one state in this window where nothing may be
666+ // edited, so it is drawn as what it is rather than as a strip.
667+ .children(self.export_progress_card(cx))
648 // Last, so it floats over whatever opened it -- an inspector row or668 // Last, so it floats over whatever opened it -- an inspector row or
649 // a clip menu -- rather than under it.669 // a clip menu -- rather than under it.
650 .children(self.picker_card(window.viewport_size(), cx))670 .children(self.picker_card(window.viewport_size(), cx))
crates/app/src/subs.rsmodified+59 -10
@@ -235,6 +235,11 @@ pub(crate) type Subs = engine::Result<Vec<engine::subtitle::SubtitleTrack>>;
235 /// argv named, an import, and an import into an empty window cannot say the same235 /// argv named, an import, and an import into an empty window cannot say the same
236 /// thing differently, whichever thread read the cues.236 /// thing differently, whichever thread read the cues.
237 ///237 ///
238+/// Worded for where they actually land: a *list* beside the media and nothing
239+/// over the picture -- a track shows when it is dragged onto a subtitle lane
240+/// ([`Player::subtitle_overlay`]), so the tail says the next move rather than
241+/// letting a count read as "and there they are on screen".
242+///
238 /// `None` for a file that gave none and for one whose tracks are on the timeline243 /// `None` for a file that gave none and for one whose tracks are on the timeline
239 /// already -- an import that adds nothing says nothing about subtitles. A244 /// already -- an import that adds nothing says nothing about subtitles. A
240 /// refusal is a tail too, never a failure of the import: the picture and the245 /// refusal is a tail too, never a failure of the import: the picture and the
@@ -243,12 +248,33 @@ pub(crate) fn subtitle_tail(session: &mut PlaybackSession, subs: Subs) -> Option
243 match subs {248 match subs {
244 Ok(tracks) => match session.add_subtitle_tracks(tracks) {249 Ok(tracks) => match session.add_subtitle_tracks(tracks) {
245 0 => None,250 0 => None,
246- n => Some(format!(" — {n} subtitle track(s) in the file")),251+ n => Some(format!(
252+ " — {n} subtitle track(s) in the file, in the subtitle list: drag one onto a \
253+ subtitle track to show it"
254+ )),
247 },255 },
248 Err(e) => Some(format!(" — SUBTITLES UNREAD: {e}")),256 Err(e) => Some(format!(" — SUBTITLES UNREAD: {e}")),
249 }257 }
250 }258 }
251 259
260+/// What the subtitles toggle says it just did ([`Player::toggle_subtitles`]),
261+/// worded off the lanes: `placed` is every caption on every subtitle lane
262+/// ([`Player::placed_captions`]), because that -- and never the palette row the
263+/// list marks -- is what the toggle covers and uncovers.
264+///
265+/// Nothing placed is its own sentence: "SUBTITLES SHOWN — 0 caption(s)" over an
266+/// unchanged picture reads as a broken toggle, so it says the move that would
267+/// put words there instead.
268+pub(crate) fn subtitle_toggle_notice(on: bool, placed: usize) -> String {
269+ match (on, placed) {
270+ (true, 0) => {
271+ "SUBTITLES SHOWN — nothing placed yet: drag a track onto a subtitle track".to_string()
272+ }
273+ (true, n) => format!("SUBTITLES SHOWN — {n} caption(s) on the timeline"),
274+ (false, n) => format!("SUBTITLES HIDDEN — {n} caption(s) still placed"),
275+ }
276+}
277+
252 /// The push both deliberate add-subtitles doors end on -- `+ S` and its key278 /// The push both deliberate add-subtitles doors end on -- `+ S` and its key
253 /// ([`Player::add_subtitles`]) and a dropped or argv'd subtitle file279 /// ([`Player::add_subtitles`]) and a dropped or argv'd subtitle file
254 /// ([`Player::take_subtitles`]) -- so the two cannot come to word the same file280 /// ([`Player::take_subtitles`]) -- so the two cannot come to word the same file
@@ -323,17 +349,24 @@ pub(crate) fn subtitle_plan(
323 picks: &[usize],349 picks: &[usize],
324 ) -> String {350 ) -> String {
325 let mut parts: Vec<String> = Vec::new();351 let mut parts: Vec<String> = Vec::new();
326- // "none" is the engine's word for an empty pick list and would read as a352+ // "none" is the engine's word for having nothing to say and would read as a
327- // verdict on the tracks named after it.353+ // verdict on the tracks named after it. Anything else is the sentence the
328- if !picks.is_empty() {354+ // export is actually planned from -- the lanes' own, wherever the timeline
329- parts.push(plan);355+ // places words ([`engine::export::planned_subtitles`]) -- and it is kept
356+ // whatever the palette picks are: dropping it on an empty pick list is how a
357+ // card showing "S1 eng — past the last picture" said nothing at all.
358+ if plan != "none" {
359+ parts.push(plan.clone());
330 }360 }
331 parts.extend(361 parts.extend(
332 tracks362 tracks
333 .iter()363 .iter()
334 .enumerate()364 .enumerate()
335- .filter(|(i, _)| !picks.contains(i))365+ .filter(|(i, track)| !picks.contains(i) && !spoken_for(&plan, track))
336- .map(|(_, track)| format!("{} — no cues here", track.label)),366+ // Not "no cues here": a row the export leaves out is a row nothing
367+ // on the timeline placed, and what puts that right is the drag --
368+ // the same sentence the import notice ends with.
369+ .map(|(_, track)| format!("{} — in the palette, on no track", track.label)),
337 );370 );
338 let named = parts.join("; ");371 let named = parts.join("; ");
339 if named.chars().count() <= SUB_PLAN_CHARS {372 if named.chars().count() <= SUB_PLAN_CHARS {
@@ -347,7 +380,7 @@ pub(crate) fn subtitle_plan(
347 match (380 match (
348 track.refused.is_some(),381 track.refused.is_some(),
349 track.is_bitmap(),382 track.is_bitmap(),
350- picks.contains(&i),383+ picks.contains(&i) || spoken_for(&plan, track),
351 ) {384 ) {
352 (true, _, _) => unread += 1,385 (true, _, _) => unread += 1,
353 (_, true, _) => pictures += 1,386 (_, true, _) => pictures += 1,
@@ -360,7 +393,7 @@ pub(crate) fn subtitle_plan(
360 [393 [
361 (pictures, "pictures"),394 (pictures, "pictures"),
362 (unread, "unread"),395 (unread, "unread"),
363- (off, "no cues here"),396+ (off, "in the palette, on no track"),
364 ]397 ]
365 .into_iter()398 .into_iter()
366 .filter(|(n, _)| *n > 0)399 .filter(|(n, _)| *n > 0)
@@ -369,6 +402,21 @@ pub(crate) fn subtitle_plan(
369 counted.join("; ")402 counted.join("; ")
370 }403 }
371 404
405+/// Whether the engine's sentence already speaks for this row: with words placed
406+/// on lanes, every clause of it names the palette row its lane shows
407+/// ([`engine::export::planned_subtitles`]) -- and a line that embeds a track and
408+/// then says the same track is on no track is a line contradicting itself.
409+///
410+/// corner-cut: the match is the label found in the sentence, because the engine
411+/// hands back one string and not the rows it spoke for. Ceiling: two rows whose
412+/// labels are one a prefix of the other ("eng", "eng 2") -- with the longer one
413+/// placed, the shorter loses its clause; it never gains a wrong one. Upgrade
414+/// path: `planned_subtitles` handing its clauses back as data, the same upgrade
415+/// [`subtitle_plan`]'s own note names.
416+fn spoken_for(plan: &str, track: &engine::subtitle::SubtitleTrack) -> bool {
417+ !track.label.is_empty() && plan.contains(track.label.as_str())
418+}
419+
372 /// Every subtitle track one file gave, kept together. Plain data, planned420 /// Every subtitle track one file gave, kept together. Plain data, planned
373 /// before anything is drawn -- the grouping is the branchy part and it is the421 /// before anything is drawn -- the grouping is the branchy part and it is the
374 /// same answer whatever a styling puts around it.422 /// same answer whatever a styling puts around it.
@@ -393,7 +441,8 @@ pub(crate) struct SubGroup {
393 pub(crate) struct SubRow {441 pub(crate) struct SubRow {
394 /// Which track of the session's list this row is: the *flat* index into the442 /// Which track of the session's list this row is: the *flat* index into the
395 /// add-order Vec `PlaybackSession::subtitles` hands back, which is what a443 /// add-order Vec `PlaybackSession::subtitles` hands back, which is what a
396- /// click sets `sub_track` to and what a save writes into the `.edith`.444+ /// click sets `sub_track` to and what a caption placed on a subtitle lane
445+ /// names, so it is what a save writes into the `.edith` for that caption.
397 /// Grouping moves rows around on screen and never touches this number.446 /// Grouping moves rows around on screen and never touches this number.
398 pub(crate) track: usize,447 pub(crate) track: usize,
399 /// Which of *this file's* tracks it is, counted from 1 -- the numbering448 /// Which of *this file's* tracks it is, counted from 1 -- the numbering
crates/app/src/tests/cards.rsmodified+19 -12
@@ -4,20 +4,27 @@
4 use super::*;4 use super::*;
5 5
6 #[test]6 #[test]
7-fn escape_gets_out_of_an_export_whatever_is_held_with_it() {7+fn only_a_chord_gets_out_of_an_export() {
8 use keymap::ActionId;8 use keymap::ActionId;
9- // The regression this guards: looking the stroke up in the keymap made9+ // What this guards: bare escape is the stroke a hand throws at anything on
10- // ctrl+escape mean nothing, and an export that a modifier could trap10+ // screen, and while an export ran it deleted the encode. The way out is the
11- // the user inside of is worse than an unbound chord.11+ // same key with control on it, and the card says so.
12- assert!(cancels_export("escape", None));12+ assert!(cancels_export("escape", true, Some(ActionId::CancelExport)));
13- assert!(cancels_export("escape", Some(ActionId::CancelExport)));13+ assert!(!cancels_export("escape", false, None));
14- // A rebound cancel works as well -- it adds a way out, never replaces14+ // Even if something else were ever bound to bare escape, it is not this.
15- // the one that always worked.15+ assert!(!cancels_export("escape", false, Some(ActionId::Play)));
16- assert!(cancels_export("q", Some(ActionId::CancelExport)));16+ // A rebound cancel works as well -- it adds a way out, never replaces the
17+ // chord, and the keymap is what decides whether that one carries control.
18+ assert!(cancels_export("q", false, Some(ActionId::CancelExport)));
17 // Nothing else does, whatever it means outside an export.19 // Nothing else does, whatever it means outside an export.
18- assert!(!cancels_export("e", Some(ActionId::Export)));20+ assert!(!cancels_export("e", false, Some(ActionId::Export)));
19- assert!(!cancels_export("space", Some(ActionId::Play)));21+ assert!(!cancels_export("space", false, Some(ActionId::Play)));
20- assert!(!cancels_export("q", None));22+ assert!(!cancels_export("q", false, None));
23+ // The default keymap is what the handler feeds this: the chord reaches the
24+ // action, the bare key reaches nothing.
25+ let k = keymap::Keymap::defaults();
26+ assert!(cancels_export("escape", true, k.lookup("escape", true)));
27+ assert!(!cancels_export("escape", false, k.lookup("escape", false)));
21 }28 }
22 29
23 #[test]30 #[test]
crates/app/src/tests/layout.rsmodified+120 -5
@@ -405,6 +405,82 @@ fn a_trim_preview_lands_where_the_release_commits() {
405 }405 }
406 }406 }
407 407
408+/// The caption a drag is showing lands where the release commits -- the
409+/// subtitle twin of the trim preview above -- and the two contracts the boxes
410+/// on the lanes rest on: `place_sub`'s `at` wins over the placement's own
411+/// `start`, and a gesture that changed nothing is `Ok` and not a refusal, so a
412+/// front-end that toasted every `Ok` would toast a pick-up-put-back.
413+#[test]
414+fn a_caption_trim_preview_lands_where_the_release_commits() {
415+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
416+ session.set_gain(0.0);
417+ let fps = session.meta().frame_rate;
418+ let srt = Path::new(env!("CARGO_MANIFEST_DIR"))
419+ .join("../engine/tests/data/test_subs.srt")
420+ .canonicalize()
421+ .expect("the subtitle fixture");
422+ session.import_subtitles(&srt).expect("the .srt imports");
423+ let lane = session.add_lane(LaneKind::Subtitle);
424+ // The whole track as a placement, exactly as `Player::sub_of_track` builds
425+ // one from a palette row.
426+ let out_us = session.subtitles()[0]
427+ .cues
428+ .iter()
429+ .map(|c| c.end_us)
430+ .max()
431+ .expect("the fixture has cues");
432+ let whole = SubClip {
433+ start: 0,
434+ frames: frames_of_us(out_us, fps),
435+ track: 0,
436+ in_us: 0,
437+ out_us,
438+ };
439+ session
440+ .place_sub(lane, 30, whole)
441+ .expect("an empty subtitle lane takes it");
442+ assert_eq!(
443+ session.sub_lane(lane)[0].start,
444+ 30,
445+ "the frame the hand let go on wins over the placement's own start"
446+ );
447+ for edge in [Edge::Start, Edge::End] {
448+ let (lo, hi) = session
449+ .trim_sub_room(lane, 0, edge)
450+ .expect("placement 0 is there");
451+ for to in [lo, (lo + hi) / 2, hi] {
452+ let placed = session.sub_lane(lane)[0];
453+ let preview = trimmed_sub(placed, edge, to);
454+ session
455+ .trim_sub(lane, 0, edge, to)
456+ .expect("an edge inside its own room is never refused");
457+ let now = session.sub_lane(lane)[0];
458+ assert_eq!(
459+ (preview.start, preview.frames),
460+ (now.start, now.frames),
461+ "{edge:?} to {to}"
462+ );
463+ // One edit, one undo step -- and none at all where the edge was
464+ // already there, which is the `Ok` that must stay silent.
465+ if (now.start, now.frames) != (placed.start, placed.frames) {
466+ assert!(session.undo(), "the trim is one undo step");
467+ }
468+ }
469+ }
470+ // Picked up and put back down: `Ok`, nothing moved, nothing to say.
471+ let before = session.sub_lane(lane)[0];
472+ session
473+ .move_sub(lane, 0, lane, before.start)
474+ .expect("a drop that changes nothing is not a refusal");
475+ assert_eq!(session.sub_lane(lane)[0], before);
476+ // ...and two captions over one frame are refused in words, which is what
477+ // the notice shows verbatim.
478+ let over = session
479+ .place_sub(lane, before.start, whole)
480+ .expect_err("two captions may not cover one frame");
481+ assert!(over.to_string().contains("already covers"), "{over}");
482+}
483+
408 /// A still trims the same way, and the preview knows it: its head grows484 /// A still trims the same way, and the preview knows it: its head grows
409 /// forward from source frame 0 -- every frame of it is the same picture --485 /// forward from source frame 0 -- every frame of it is the same picture --
410 /// so the box stretches instead of sliding left.486 /// so the box stretches instead of sliding left.
@@ -683,7 +759,7 @@ fn the_card_names_the_subtitle_it_leaves_off_and_counts_them_when_it_cannot() {
683 // What the engine answers about the one pick that reached it, and what759 // What the engine answers about the one pick that reached it, and what
684 // this side knows about the row that did not.760 // this side knows about the row that did not.
685 let named = subtitle_plan("[ASS] → embedded".to_string(), &two, &[0]);761 let named = subtitle_plan("[ASS] → embedded".to_string(), &two, &[0]);
686- assert_eq!(named, "[ASS] → embedded; [ASS] [FOR DUB] — no cues here");762+ assert_eq!(named, "[ASS] → embedded; [ASS] [FOR DUB] — in the palette, on no track");
687 assert!(763 assert!(
688 named.chars().count() <= SUB_PLAN_CHARS,764 named.chars().count() <= SUB_PLAN_CHARS,
689 "two tracks fit the value box: {named}"765 "two tracks fit the value box: {named}"
@@ -702,13 +778,30 @@ fn the_card_names_the_subtitle_it_leaves_off_and_counts_them_when_it_cannot() {
702 // and the nine picture ones, which the engine drops itself.778 // and the nine picture ones, which the engine drops itself.
703 let picks: Vec<usize> = (0..31usize).collect();779 let picks: Vec<usize> = (0..31usize).collect();
704 let counted = subtitle_plan("22 tracks → embedded (…)".to_string(), &many, &picks);780 let counted = subtitle_plan("22 tracks → embedded (…)".to_string(), &many, &picks);
705- assert_eq!(counted, "22 of 35 → embedded; 9 pictures; 1 unread; 3 no cues here");781+ assert_eq!(
782+ counted,
783+ "22 of 35 → embedded; 9 pictures; 1 unread; 3 in the palette, on no track"
784+ );
706 assert!(785 assert!(
707 counted.chars().count() <= SUB_PLAN_CHARS,786 counted.chars().count() <= SUB_PLAN_CHARS,
708 "thirty-five tracks still fit the value box: {counted}"787 "thirty-five tracks still fit the value box: {counted}"
709 );788 );
710 // Nothing on the timeline at all is still the engine's word for it.789 // Nothing on the timeline at all is still the engine's word for it.
711 assert_eq!(subtitle_plan("none".to_string(), &[], &[]), "none");790 assert_eq!(subtitle_plan("none".to_string(), &[], &[]), "none");
791+ // The lanes are what an export writes once anything is placed on one, and
792+ // the engine words that whole ([`engine::export::planned_subtitles`]) --
793+ // including the lanes it carries *nothing* of, which is a sentence with no
794+ // pick behind it at all. That used to be dropped on the floor: the card said
795+ // "[ASS] — no cues here" twice and never said what became of the lane.
796+ let placed = "S1 [ASS] — past the last picture".to_string();
797+ assert_eq!(
798+ subtitle_plan(placed.clone(), &two, &[]),
799+ "S1 [ASS] — past the last picture; [ASS] [FOR DUB] — in the palette, on no track"
800+ );
801+ // ...and the row that sentence speaks for gets no clause of its own: a line
802+ // that names a lane's track and then calls the same track unplaced is the
803+ // card contradicting itself in one breath.
804+ assert!(!subtitle_plan(placed, &two[..1], &[]).contains("in the palette"));
712 }805 }
713 806
714 /// The list is in the order tracks were added, which is not the order a807 /// The list is in the order tracks were added, which is not the order a
@@ -789,11 +882,33 @@ fn the_picked_subtitle_is_named_with_the_film_it_came_out_of() {
789 // A standalone `.srt` is its own file and its label already says so:882 // A standalone `.srt` is its own file and its label already says so:
790 // one track, so no number, and no stem after it saying it again.883 // one track, so no number, and no stem after it saying it again.
791 assert_eq!(name(4), "late.srt");884 assert_eq!(name(4), "late.srt");
792- // The silence `subtitle_track` gives at the same moment.885+ // The silence a row left over from a timeline that is gone gets.
793 assert_eq!(sub_pick_name(&tracks, 5), None);886 assert_eq!(sub_pick_name(&tracks, 5), None);
794 assert_eq!(sub_pick_name(&[], 0), None);887 assert_eq!(sub_pick_name(&[], 0), None);
795 }888 }
796 889
890+/// What the toggle covers is what is *placed*, so what it says is a lane fact:
891+/// naming the palette row the list happens to mark named a track the stroke
892+/// never touched ("SUBTITLES OFF — one.srt is still on the timeline" for a
893+/// one.srt nobody dragged anywhere).
894+#[test]
895+fn the_subtitles_toggle_says_what_is_placed_and_never_the_picked_row() {
896+ for on in [true, false] {
897+ let text = subtitle_toggle_notice(on, 2);
898+ assert!(text.contains('2'), "{text} counts the captions placed");
899+ assert!(
900+ !text.contains("track(s)") && !text.contains(" — a"),
901+ "{text} names no palette row"
902+ );
903+ }
904+ // Off leaves them on the lanes; that is the half a person needs told.
905+ assert!(subtitle_toggle_notice(false, 2).contains("still placed"));
906+ // An empty timeline says the move instead of a count that reads as broken.
907+ let none = subtitle_toggle_notice(true, 0);
908+ assert!(!none.contains('0'), "{none} counts nothing at nothing");
909+ assert!(none.contains("drag"), "{none} says the next move");
910+}
911+
797 /// The door this editor answers "don't make me import the film again" with,912 /// The door this editor answers "don't make me import the film again" with,
798 /// and it is in the panel where the tracks it adds are listed: the Text913 /// and it is in the panel where the tracks it adds are listed: the Text
799 /// tab's own button reads a file's subtitle tracks onto the open timeline914 /// tab's own button reads a file's subtitle tracks onto the open timeline
@@ -808,9 +923,9 @@ fn the_text_tab_carries_the_add_subtitles_door() {
808 let at = library923 let at = library
809 .find("\"add-subtitles\"")924 .find("\"add-subtitles\"")
810 .expect("no add-subtitles control in the library column");925 .expect("no add-subtitles control in the library column");
811- let block = &library[at..(at + 1400).min(library.len())];926+ let block = &library[at..(at + 1600).min(library.len())];
812 assert!(927 assert!(
813- block.contains("ActionId::AddSubtitleTrack"),928+ block.contains("ActionId::ImportSubtitles"),
814 "the button is a door of its own rather than the action: {block}"929 "the button is a door of its own rather than the action: {block}"
815 );930 );
816 assert!(931 assert!(
crates/app/src/tests/media.rsmodified+62 -16
@@ -796,18 +796,19 @@ fn a_cue_steps_over_whatever_bar_is_hanging_off_the_picture() {
796 }796 }
797 797
798 /// The two places a subtitle is drawn -- the plate over the picture and the798 /// The two places a subtitle is drawn -- the plate over the picture and the
799-/// strip under the lanes -- inside the 640x360 floor the rest of this window799+/// lanes under the tracks -- inside the 640x360 floor the rest of this window
800 /// is sized for, and the plate readable on whatever the film is showing.800 /// is sized for, and the plate readable on whatever the film is showing.
801 #[test]801 #[test]
802-fn the_subtitle_plate_and_strip_fit_the_smallest_window() {802+fn the_subtitle_plate_and_lanes_fit_the_smallest_window() {
803- // The strip costs the panel its own row and the panel's gap, and costs803+ // A subtitle lane is a lane: it costs the panel exactly what a third
804- // nothing at all when there is no track to draw.804+ // track costs it, and a timeline with none costs nothing at all -- the
805- assert_eq!(subtitle_strip_h(false), 0.);805+ // strip that used to hang under the lanes is gone, and with it the one
806- assert_eq!(subtitle_strip_h(true), SUB_LANE_H + 8.);806+ // row nothing could be dropped on.
807- // What is left for the picture at the floor, with the panel a project807+ assert_eq!(lanes_h(3) - lanes_h(2), LANE_H + 8.);
808- // starts with and the strip under it.808+ // What is left for the picture at the floor, with a project's two tracks
809- let picture = 360. - HEADER_H - panel_h(2) - subtitle_strip_h(true);809+ // and a subtitle lane under them.
810- assert!(picture > 0., "the strip pushed the picture off the window");810+ let picture = 360. - HEADER_H - panel_h(3);
811+ assert!(picture > 0., "a subtitle lane pushed the picture off the window");
811 // A two-line cue and the gap under it fit inside that, which is the812 // A two-line cue and the gap under it fit inside that, which is the
812 // whole claim: the plate sits *over* the picture and must not need more813 // whole claim: the plate sits *over* the picture and must not need more
813 // of it than there is.814 // of it than there is.
@@ -822,9 +823,10 @@ fn the_subtitle_plate_and_strip_fit_the_smallest_window() {
822 for id in crate::ui::theme::PaletteId::ALL {823 for id in crate::ui::theme::PaletteId::ALL {
823 assert!(contrast(id.palette().SUB_FG, 0x000000) >= 7., "{id:?}");824 assert!(contrast(id.palette().SUB_FG, 0x000000) >= 7., "{id:?}");
824 }825 }
825- // The strip is a picture and not a target -- nothing on it takes a826+ // A subtitle lane is dragged onto, trimmed on and lifted from, so its row
826- // click -- which is the only reason it may be under `HIT_MIN`.827+ // is a target and binds `HIT_MIN` like every other lane's -- the whole
827- assert!(SUB_LANE_H < HIT_MIN && SUB_LANE_H > 0.);828+ // reason it is a lane and no longer a 16 px strip.
829+ assert!(LANE_H >= HIT_MIN);
828 // The library's own list of tracks scrolls past three rather than830 // The library's own list of tracks scrolls past three rather than
829 // taking the media list's room.831 // taking the media list's room.
830 assert_eq!(SUB_ROWS_H / ROW_H, 3.);832 assert_eq!(SUB_ROWS_H / ROW_H, 3.);
@@ -952,7 +954,14 @@ fn subtitles_arrive_beside_the_media_and_inside_it() {
952 let track = &session.subtitles()[0];954 let track = &session.subtitles()[0];
953 assert_eq!(track.label, "test_subs.srt");955 assert_eq!(track.label, "test_subs.srt");
954 assert_eq!(subtitle_detail(track), "3 cues");956 assert_eq!(subtitle_detail(track), "3 cues");
955- // What the overlay draws at a moment inside the first cue, and between957+ // Arriving is landing in the *list* and nowhere else: no lane is made for
958+ // it, so there is nothing over the picture yet -- the rule every other
959+ // medium follows here, and what `Player::subtitle_overlay` reads.
960+ assert!(
961+ session.subtitle_lanes().is_empty(),
962+ "an import places nothing: the palette is where a track lands"
963+ );
964+ // What the track itself says at a moment inside the first cue, and between
956 // two of them -- the fixture's own timings (0.5-1.5 s, 2.0-3.25 s).965 // two of them -- the fixture's own timings (0.5-1.5 s, 2.0-3.25 s).
957 let text = |t: f64| -> Vec<String> {966 let text = |t: f64| -> Vec<String> {
958 cues_at(&track.cues, t)967 cues_at(&track.cues, t)
@@ -1017,7 +1026,7 @@ fn subtitles_arrive_beside_the_media_and_inside_it() {
1017 assert!(subtitle_detail(&refused).contains("pictures"));1026 assert!(subtitle_detail(&refused).contains("pictures"));
1018 assert!(cues_at(&refused.cues, 1.).is_empty());1027 assert!(cues_at(&refused.cues, 1.).is_empty());
1019 1028
1020- // ...and what the plate and the strip draw after a *cut*: the timeline's1029+ // ...and what an embedded track carried through a *cut* maps to: the timeline's
1021 // own clock, asked of the engine through the very map an export writes1030 // own clock, asked of the engine through the very map an export writes
1022 // the file with (`PlaybackSession::timeline_cues`), so the preview and1031 // the file with (`PlaybackSession::timeline_cues`), so the preview and
1023 // the file cannot drift apart. The numbers are the export's own1032 // the file cannot drift apart. The numbers are the export's own
@@ -1040,7 +1049,7 @@ fn subtitles_arrive_beside_the_media_and_inside_it() {
1040 .collect::<Vec<_>>(),1049 .collect::<Vec<_>>(),
1041 vec![(500_000, 1_500_000), (2_000_000, 3_000_000)]1050 vec![(500_000, 1_500_000), (2_000_000, 3_000_000)]
1042 );1051 );
1043- // The overlay's own two lines, at the same moments as above.1052+ // The export's own two lines, at the same moments as above.
1044 let drawn = |t: f64| -> Vec<String> {1053 let drawn = |t: f64| -> Vec<String> {
1045 cues_at(&mapped, t)1054 cues_at(&mapped, t)
1046 .into_iter()1055 .into_iter()
@@ -1055,4 +1064,41 @@ fn subtitles_arrive_beside_the_media_and_inside_it() {
1055 );1064 );
1056 // ...and the strip's: the second cue is one second wide now, not 1.25.1065 // ...and the strip's: the second cue is one second wide now, not 1.25.
1057 assert_eq!(cue_box(scale, &mapped[1]), (80., 40.));1066 assert_eq!(cue_box(scale, &mapped[1]), (80., 40.));
1067+
1068+ // The last mile, what the plate over the picture actually reads
1069+ // (`Player::subtitle_overlay` -> `PlaybackSession::sub_lane_cues`): a lane
1070+ // added and still empty draws nothing, and the palette row reaches the
1071+ // screen the moment it is *placed* on it -- shifted by where it sits, the
1072+ // way a clip is.
1073+ let lane = session.add_lane(LaneKind::Subtitle);
1074+ assert!(
1075+ session.sub_lane_cues(lane).is_empty(),
1076+ "an empty subtitle lane draws nothing"
1077+ );
1078+ session
1079+ .place_sub(
1080+ lane,
1081+ 0,
1082+ SubClip {
1083+ start: 0,
1084+ frames: 90,
1085+ track: 0,
1086+ in_us: 0,
1087+ out_us: 5_000_000,
1088+ },
1089+ )
1090+ .expect("the palette row goes down on the lane");
1091+ let placed = session.sub_lane_cues(lane);
1092+ let shown = |t: f64| -> Vec<String> {
1093+ cues_at(&placed, t)
1094+ .into_iter()
1095+ .map(|c| c.text.clone())
1096+ .collect()
1097+ };
1098+ // The placement keeps the track's own clock (it starts at frame 0 and
1099+ // holds the whole of it), so the words are back at the times the file
1100+ // wrote them -- the cut above moved the *carried* map, not this one.
1101+ assert_eq!(shown(0.7), ["first line"]);
1102+ assert!(shown(1.8).is_empty(), "between two cues the plate goes");
1103+ assert_eq!(shown(2.5), ["second line\nwith a break"]);
1058 }1104 }
crates/app/src/tests/mod.rsmodified+4 -4
@@ -39,7 +39,7 @@ use super::{
39 };39 };
40 40
41 use super::{41 use super::{
42- Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, LaneKind, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat,42+ Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, LaneKind, SubClip, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat,
43 Scale, View,43 Scale, View,
44 ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, av1_hw_warning, clock,44 ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, av1_hw_warning, clock,
45 encoder_choices, encoder_label, eta_secs, file_name, file_uri,45 encoder_choices, encoder_label, eta_secs, file_name, file_uri,
@@ -49,16 +49,16 @@ use super::{
49 Landing, arrival, launch_queue,49 Landing, arrival, launch_queue,
50 read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write,50 read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write,
51 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,51 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,
52- clip_width, trimmed_clip, trims, unscannable, unusable,52+ clip_width, frames_of_us, trimmed_clip, trimmed_sub, trims, unscannable, unusable,
53 visible_slice,53 visible_slice,
54 };54 };
55 55
56 use super::{56 use super::{
57- SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_FG, SUB_LANE_H, SUB_LINE_H, SUB_ROWS_H,57+ SUB_BOTTOM, SUB_CUE_MIN_W, SUB_HEAD_H, SUB_FG, SUB_LINE_H, SUB_ROWS_H,
58 SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,58 SUB_STEM_SHARE, SUB_TEXT, clip_middle, cue_box, sub_bottom,
59 carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit,59 carries_subtitles, cues_at, file_tint, is_subtitle, lang_human, row_text_w, sub_headers_fit,
60 Subs, subtitle_detail, subtitle_notice, subtitle_tail,60 Subs, subtitle_detail, subtitle_notice, subtitle_tail,
61- sub_pick_name, subtitle_rows, subtitle_strip_h, walk_subtitles,61+ sub_pick_name, subtitle_rows, subtitle_toggle_notice, walk_subtitles,
62 };62 };
63 63
64 use engine::PlaybackSession;64 use engine::PlaybackSession;
crates/app/src/tests/view.rsmodified+14 -0
@@ -126,6 +126,20 @@ fn a_lane_refuses_the_files_it_cannot_hold_before_the_release_says_so() {
126 // engine takes its sound onto one, and the words for a video-only file126 // engine takes its sound onto one, and the words for a video-only file
127 // are its own.127 // are its own.
128 assert_eq!(lane_refuses(movie, audio), None);128 assert_eq!(lane_refuses(movie, audio), None);
129+ // ...and a subtitle lane holds none of the three: a caption comes off the
130+ // Subtitles list, which is where the refusal points.
131+ for file in [sound, still, movie] {
132+ let why = lane_refuses(file, Lane::S1).expect("a subtitle lane takes no media");
133+ assert!(why.starts_with("NOT ON S1 — "), "{why}");
134+ assert!(why.contains("Subtitles list"), "{why}");
135+ }
136+ // How the two clocks a caption has meet, which is what a palette row's
137+ // length is worked out with: a second of words at 30 fps is 30 frames,
138+ // and a track shorter than one frame is still a caption to place.
139+ assert_eq!(frames_of_us(1_000_000, 30.), 30);
140+ assert_eq!(frames_of_us(500_000, 24.), 12);
141+ assert_eq!(frames_of_us(1_000, 30.), 1);
142+ assert_eq!(frames_of_us(1_000_000, 0.), 1);
129 }143 }
130 144
131 /// Where those edges come from: every lane, not the one being dropped on --145 /// Where those edges come from: every lane, not the one being dropped on --
crates/app/src/timeline_math.rsmodified+49 -2
@@ -146,6 +146,45 @@ pub(crate) fn trimmed_clip(clip: Clip, edge: Edge, to: u32, still: bool) -> Clip
146 }146 }
147 }147 }
148 148
149+/// How many timeline frames a stretch of a subtitle track is worth: the one
150+/// conversion between the two clocks a caption has -- microseconds for its
151+/// words, frames for where it sits -- and the app-side twin of the engine's own
152+/// (`Project::trim_sub_room`). Never zero: a placement of no frames is the one
153+/// [`Project::place_sub`] refuses as empty, and a track shorter than a frame is
154+/// still a caption somebody dragged.
155+pub(crate) fn frames_of_us(us: i64, fps: f64) -> u32 {
156+ match fps.is_finite() && fps > 0. {
157+ true => ((us as f64) * fps / 1e6)
158+ .round()
159+ .clamp(1., f64::from(u32::MAX)) as u32,
160+ false => 1,
161+ }
162+}
163+
164+/// The *placement* a trim is showing, the same way for a caption:
165+/// [`Project::trim_sub`] moves the head or the tail and the window follows it,
166+/// so the box on screen is the frames alone -- the words it will keep are the
167+/// engine's arithmetic at the release, and nothing here draws them.
168+///
169+/// An edge that has not moved draws the placement it pressed, and one dragged
170+/// past its other end keeps the one frame the engine's own walls always leave.
171+pub(crate) fn trimmed_sub(sub: SubClip, edge: Edge, to: u32) -> SubClip {
172+ match edge {
173+ Edge::Start => {
174+ let to = to.min(sub.end() - 1);
175+ SubClip {
176+ start: to,
177+ frames: sub.end() - to,
178+ ..sub
179+ }
180+ }
181+ Edge::End => SubClip {
182+ frames: to.max(sub.start + 1) - sub.start,
183+ ..sub
184+ },
185+ }
186+}
187+
149 /// Which index on its own lane a dragged clip is at *now*: the one it was picked188 /// Which index on its own lane a dragged clip is at *now*: the one it was picked
150 /// up at while nothing has moved, and wherever the clip itself has slid to when189 /// up at while nothing has moved, and wherever the clip itself has slid to when
151 /// an edit during the drag rippled the lane's indices -- a delete, an undo or a190 /// an edit during the drag rippled the lane's indices -- a delete, an undo or a
@@ -153,8 +192,9 @@ pub(crate) fn trimmed_clip(clip: Clip, edge: Edge, to: u32, still: bool) -> Clip
153 /// `None` when the clip is gone altogether, and then the drop is not an edit at192 /// `None` when the clip is gone altogether, and then the drop is not an edit at
154 /// all: moving whatever slid into its place is the one thing the hand did not193 /// all: moving whatever slid into its place is the one thing the hand did not
155 /// ask for. A lane's clips are disjoint and sorted, so at most one of them can194 /// ask for. A lane's clips are disjoint and sorted, so at most one of them can
156-/// be the clip that was picked up.195+/// be the clip that was picked up. Generic over what a lane holds, because a
157-pub(crate) fn live_idx(clips: &[Clip], idx: usize, clip: Clip) -> Option<usize> {196+/// [`SubClip`] is dragged under exactly the same rule.
197+pub(crate) fn live_idx<T: Copy + PartialEq>(clips: &[T], idx: usize, clip: T) -> Option<usize> {
158 match clips.get(idx) {198 match clips.get(idx) {
159 Some(&at) if at == clip => Some(idx),199 Some(&at) if at == clip => Some(idx),
160 _ => clips.iter().position(|&c| c == clip),200 _ => clips.iter().position(|&c| c == clip),
@@ -396,6 +436,13 @@ pub(crate) fn lane_refuses(path: &Path, lane: Lane) -> Option<String> {
396 LaneKind::Audio if engine::is_image(path) => {436 LaneKind::Audio if engine::is_image(path) => {
397 Some(format!("NOT ON {label} — {name} is a still image; drop it on a video lane"))437 Some(format!("NOT ON {label} — {name} is a still image; drop it on a video lane"))
398 }438 }
439+ // A subtitle lane holds words and no media at all: the refusal is here
440+ // rather than at the engine's door so the shadow is tinted red on the
441+ // way down, like every other lane a file cannot go on.
442+ LaneKind::Subtitle => Some(format!(
443+ "NOT ON {label} — {name} is a file; a subtitle track takes captions, dragged from the \
444+ Subtitles list"
445+ )),
399 _ => None,446 _ => None,
400 }447 }
401 }448 }
crates/app/src/ui/cards.rsmodified+164 -0
@@ -601,6 +601,170 @@ impl Player {
601 )601 )
602 }602 }
603 603
604+ /// The export while it runs, on the same sheet it was asked for on: an
605+ /// editor that takes no edit until the worker is done says so as a card and
606+ /// not as a strip under a panel nobody may touch. Same scrim, same width,
607+ /// same raised box as [`Player::export_card`] -- the answer arrives where
608+ /// the question was put -- and the timeline is still read around it.
609+ ///
610+ /// Two things it does *not* do. It never closes: not on a press away, not
611+ /// on `esc`. There is nothing here to dismiss while the export is still
612+ /// running, and a modal that vanishes leaves a locked editor with no reason
613+ /// on screen. And its cancel is two presses, never one -- an hour of
614+ /// encoding must not end on a stray click, which is why the stroke is a
615+ /// chord as well ([`cancels_export`]).
616+ pub(crate) fn export_progress_card(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
617+ let export = self.exporting()?;
618+ let progress = export.progress().clamp(0., 1.);
619+ let elapsed = self
620+ .export_started
621+ .map_or(0., |t| t.elapsed().as_secs_f32());
622+ // Two numbers that must both be honest: the one that counts up is
623+ // measured, the one that counts down is a guess and says so.
624+ let left = eta_secs(&self.export_marks, elapsed, progress).map_or_else(
625+ || "estimating…".to_owned(),
626+ |s| format!("~{} left", clock(s)),
627+ );
628+ // What is being read, the same files the engine names on stderr
629+ // ("export source:"): the project's own sources, never a stand-in.
630+ let source = match self.sources() {
631+ [] => "the timeline".to_owned(),
632+ [one] => file_name(&one.path),
633+ [first, rest @ ..] => format!("{} +{} more", file_name(&first.path), rest.len()),
634+ };
635+ let note = |text: SharedString| {
636+ div()
637+ .flex_none()
638+ .px(px(6.))
639+ .text_size(px(11.))
640+ .text_color(rgb(FG_SECONDARY()))
641+ .child(text)
642+ };
643+ let armed = self.cancel_armed;
644+ Some(
645+ scrim()
646+ .flex()
647+ .justify_center()
648+ .items_center()
649+ .bg(rgba(SCRIM()))
650+ // No `close_card` here, unlike every other sheet: a press away
651+ // is not a way out of a running export, and the only thing that
652+ // ends this card is the export ending.
653+ .on_mouse_down(MouseButton::Left, swallow)
654+ .child(
655+ div()
656+ .w(px(EXPORT_W))
657+ .on_mouse_down(MouseButton::Left, swallow)
658+ .flex()
659+ .flex_col()
660+ .gap(px(6.))
661+ .p(px(12.))
662+ .rounded(px(6.))
663+ .bg(rgb(BG_RAISED()))
664+ .child(div().flex_none().px(px(6.)).child("Exporting"))
665+ // The bar itself: the same number as the percentage
666+ // below it, and it only ever moves forward -- the
667+ // worker's progress is a monotone `fetch_max`.
668+ .child(
669+ div()
670+ .flex_none()
671+ .mx(px(6.))
672+ .h(px(6.))
673+ .rounded(px(3.))
674+ .bg(rgb(BG_PANEL()))
675+ .child(
676+ div()
677+ .h_full()
678+ .w(relative(progress))
679+ .rounded(px(3.))
680+ .bg(rgb(STATUS_PROGRESS())),
681+ ),
682+ )
683+ .child(div().flex_none().px(px(6.)).text_size(px(11.)).child(
684+ SharedString::from(format!(
685+ "{}% · {} elapsed · {left}",
686+ (progress * 100.) as u32,
687+ clock(elapsed),
688+ )),
689+ ))
690+ // The row that was picked, then the seats the worker
691+ // actually opened -- so a fallback to the software
692+ // encoder shows here rather than being invisible.
693+ .child(note(
694+ format!(
695+ "{} · {}",
696+ format_label(self.format),
697+ export
698+ .encoders()
699+ .unwrap_or_else(|| "opening the encoder".to_string()),
700+ )
701+ .into(),
702+ ))
703+ .child(note(
704+ format!("{source} → {}", file_name(&self.export_path)).into(),
705+ ))
706+ .child(note(
707+ match armed {
708+ true => "cancelling deletes what has been written so far"
709+ .to_string(),
710+ false => format!(
711+ "{} cancels · esc alone does nothing while this runs · the \
712+ timeline is read-only until it finishes",
713+ self.keymap.display(ActionId::CancelExport)
714+ ),
715+ }
716+ .into(),
717+ ))
718+ // One button, or the pair that answers it: never a
719+ // control that cycles -- both choices are on screen at
720+ // once, each saying which one it is.
721+ .child(
722+ div()
723+ .mt(px(2.))
724+ .flex()
725+ .gap(px(6.))
726+ .justify_end()
727+ .when(armed, |d| {
728+ d.child(control(
729+ "export-keep",
730+ 140.,
731+ ACCENT_PRIMARY(),
732+ None,
733+ "Keep exporting",
734+ "leaves the export running".to_string(),
735+ true,
736+ cx.listener(|this, _: &ClickEvent, _, cx| {
737+ this.cancel_armed = false;
738+ cx.notify();
739+ }),
740+ ))
741+ })
742+ .child(control(
743+ "export-cancel",
744+ 140.,
745+ BG_RAISED(),
746+ None,
747+ "Cancel export",
748+ match armed {
749+ true => "stops the worker and deletes the part file"
750+ .to_string(),
751+ false => "asks first -- one press only offers the choice"
752+ .to_string(),
753+ },
754+ true,
755+ cx.listener(move |this, _: &ClickEvent, _, cx| {
756+ match this.cancel_armed {
757+ true => this.cancel_export(),
758+ false => this.cancel_armed = true,
759+ }
760+ cx.notify();
761+ }),
762+ )),
763+ ),
764+ ),
765+ )
766+ }
767+
604 /// The custom bitrate's two pointer buttons. The typed digits were the last768 /// The custom bitrate's two pointer buttons. The typed digits were the last
605 /// control in this card a mouse could not reach at all -- and a number that769 /// control in this card a mouse could not reach at all -- and a number that
606 /// can only be typed is a number a hand on the pointer has to leave the770 /// can only be typed is a number a hand on the pointer has to leave the
crates/app/src/ui/library.rsmodified+3 -3
@@ -319,9 +319,9 @@ impl Player {
319 true => "Add subtitles from a file…",319 true => "Add subtitles from a file…",
320 false => "Add subtitles",320 false => "Add subtitles",
321 },321 },
322- "reads a file's subtitle tracks onto this timeline — the file itself \322+ "reads a file's subtitle tracks into the palette below — drag one onto an S \
323- joins nothing",323+ track to place it; the file itself joins nothing",
324- ActionId::AddSubtitleTrack,324+ ActionId::ImportSubtitles,
325 cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_add_subtitles(cx)),325 cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_add_subtitles(cx)),
326 )))326 )))
327 })327 })
crates/app/src/ui/preview.rsmodified+53 -22
@@ -4,19 +4,23 @@ use crate::*;
4 use crate::ui::widgets::*;4 use crate::ui::widgets::*;
5 5
6 impl Player {6 impl Player {
7- /// The cues of the picked track that are on screen at `at`, over the picture7+ /// The cues the *subtitle lanes* put on screen at `at`, over the picture and
8- /// and nothing else: bottom-centred where every player puts them, white on a8+ /// nothing else: bottom-centred where every player puts them, white on a
9 /// plate so the film underneath cannot swallow them, and each cue its own9 /// plate so the film underneath cannot swallow them, and each cue its own
10 /// plate so two at one moment stack rather than run together.10 /// plate so two at one moment stack rather than run together.
11 ///11 ///
12- /// `None` -- no element at all -- while the toggle is off, with no track12+ /// What is drawn is what was *placed*: a track walked out of a file lands in
13- /// picked, and between cues: the picture is what this window is for, and a13+ /// the palette and nothing more, exactly as a picture or a song does, and it
14- /// permanent empty band across it would be in the way of exactly that.14+ /// reaches the screen when a placement of it sits under the playhead
15+ /// ([`PlaybackSession::sub_lane_cues`], the same map the export writes the
16+ /// file with -- so what is read here is what the file will say). Every lane
17+ /// whose eye is open ([`Player::sub_lane_on`]) draws, so two enabled lanes
18+ /// are two plates: lane order bottom-up, the first lane where a single
19+ /// track's words have always been and each further one stacked above it.
15 ///20 ///
16- /// The cues are the *timeline's* ([`PlaybackSession::timeline_cues`]) and21+ /// `None` -- no element at all -- while the toggle is off, with nothing
17- /// not the track's own: on a cut timeline an embedded track's cues ride the22+ /// placed, and between cues: the picture is what this window is for, and a
18- /// pictures they belong to, and this is the same map the export writes the23+ /// permanent empty band across it would be in the way of exactly that.
19- /// file with -- so what is read here is what the file says.
20 ///24 ///
21 /// A cue off a PGS track is a *picture* and not a line25 /// A cue off a PGS track is a *picture* and not a line
22 /// ([`engine::subtitle::CueImage`]), and is drawn as one: the disc's whole26 /// ([`engine::subtitle::CueImage`]), and is drawn as one: the disc's whole
@@ -37,22 +41,42 @@ impl Player {
37 // going off, the file closing and the gap between two cues are the same41 // going off, the file closing and the gap between two cues are the same
38 // "nothing on screen", and an 8 MB atlas tile may not survive any of42 // "nothing on screen", and an 8 MB atlas tile may not survive any of
39 // them (an early return above this leaked one per toggle-off).43 // them (an early return above this leaked one per toggle-off).
40- let mapped = match self.session.as_ref().filter(|_| self.subs_on) {44+ // Per lane and not one flat list: the plates stack by lane below, and a
41- Some(session) => session.timeline_cues(self.sub_track),45+ // picture's cache key needs the lane it came off ([`Player::sub_picture`]).
42- None => Vec::new(),46+ let lanes: Vec<(Lane, Vec<engine::subtitle::Cue>)> =
43- };47+ match self.session.as_ref().filter(|_| self.subs_on) {
44- let cues = cues_at(&mapped, at);48+ Some(session) => session
45- if cues.is_empty() {49+ .subtitle_lanes()
50+ .into_iter()
51+ .filter(|&lane| self.sub_lane_on(lane))
52+ .map(|lane| {
53+ let cues = session.sub_lane_cues(lane);
54+ (lane, cues_at(&cues, at).into_iter().cloned().collect())
55+ })
56+ .filter(|(_, cues): &(_, Vec<_>)| !cues.is_empty())
57+ .collect(),
58+ None => Vec::new(),
59+ };
60+ if lanes.is_empty() {
46 self.drop_sub_image(window);61 self.drop_sub_image(window);
47 return None;62 return None;
48 }63 }
49 // The first picture cue up, decoded once and kept: two bitmap cues at64 // The first picture cue up, decoded once and kept: two bitmap cues at
50 // one moment is a thing PGS composes into one display set, so there is65 // one moment is a thing PGS composes into one display set, so there is
51- // never a second picture to stack under the first.66+ // never a second picture to stack under the first *on one lane*.
52- let picture = cues67+ //
68+ // corner-cut: two enabled lanes each showing a PGS track draw the lower
69+ // lane's picture alone -- one cache slot, one canvas over the whole
70+ // region, and a second canvas would cover the first anyway. The upgrade
71+ // path is a slot per lane, which wants the plates' stacking rule to mean
72+ // something for canvases too.
73+ let picture = lanes
53 .iter()74 .iter()
54- .find_map(|cue| Some((cue.start_us, cue.image.as_ref()?)))75+ .find_map(|(lane, cues)| {
55- .and_then(|(start_us, image)| self.sub_picture(start_us, image, window));76+ cues.iter()
77+ .find_map(|cue| Some((*lane, cue.start_us, cue.image.as_ref()?)))
78+ })
79+ .and_then(|(lane, start_us, image)| self.sub_picture(lane, start_us, image, window));
56 // A picture is fitted onto the whole region and a plate hangs off the80 // A picture is fitted onto the whole region and a plate hangs off the
57 // bottom of it, and a track is one or the other -- so they are two81 // bottom of it, and a track is one or the other -- so they are two
58 // shapes and not one with the parts switched off.82 // shapes and not one with the parts switched off.
@@ -96,7 +120,13 @@ impl Player {
96 .gap(px(2.))120 .gap(px(2.))
97 // The plate takes no click: the picture behind it is still the121 // The plate takes no click: the picture behind it is still the
98 // drop target the whole window is.122 // drop target the whole window is.
99- .children(cues.into_iter().filter(|c| c.image.is_none()).map(|cue| {123+ //
124+ // Reversed, because a column anchored at the bottom lays its
125+ // children downwards: the *last* lane is written first so the
126+ // first lane keeps the bottom line it has when it is the only
127+ // one, and a second lane stacks above it rather than pushing it
128+ // off its place.
129+ .children(lanes.into_iter().rev().flat_map(|(_, cues)| cues).filter(|c| c.image.is_none()).map(|cue| {
100 div()130 div()
101 .max_w(relative(0.9))131 .max_w(relative(0.9))
102 .px(px(6.))132 .px(px(6.))
@@ -118,7 +148,7 @@ impl Player {
118 )148 )
119 }149 }
120 150
121- /// The cue starting at `start_us` as a drawable picture, decoded on the151+ /// The cue `lane` starts at `start_us` as a drawable picture, decoded on the
122 /// first repaint it is up for and kept until another cue takes its place152 /// first repaint it is up for and kept until another cue takes its place
123 /// ([`Player::sub_image`]). `None` for a display set the decoder refuses,153 /// ([`Player::sub_image`]). `None` for a display set the decoder refuses,
124 /// which draws nothing rather than failing the frame.154 /// which draws nothing rather than failing the frame.
@@ -128,11 +158,12 @@ impl Player {
128 /// sprite atlas by the whole film.158 /// sprite atlas by the whole film.
129 pub(crate) fn sub_picture(159 pub(crate) fn sub_picture(
130 &mut self,160 &mut self,
161+ lane: Lane,
131 start_us: i64,162 start_us: i64,
132 image: &engine::subtitle::CueImage,163 image: &engine::subtitle::CueImage,
133 window: &mut Window,164 window: &mut Window,
134 ) -> Option<Arc<RenderImage>> {165 ) -> Option<Arc<RenderImage>> {
135- let key = (self.sub_track, start_us);166+ let key = (lane, start_us);
136 if let Some((up, ready)) = &self.sub_image167 if let Some((up, ready)) = &self.sub_image
137 && *up == key168 && *up == key
138 {169 {
crates/app/src/ui/theme.rsmodified+4 -6
@@ -1095,12 +1095,10 @@ pub fn clip_kind(kind: LaneKind, image: bool) -> u32 {
1095 LaneKind::Audio => CLIP_AUDIO(),1095 LaneKind::Audio => CLIP_AUDIO(),
1096 LaneKind::Video if image => CLIP_IMAGE(),1096 LaneKind::Video if image => CLIP_IMAGE(),
1097 LaneKind::Video => CLIP_VIDEO(),1097 LaneKind::Video => CLIP_VIDEO(),
1098- // A caption borrows the still's shade until the slice that draws1098+ // The purple every editor paints a title track, and the one clip colour
1099- // subtitle lanes gives it one of its own in every family: nothing on1099+ // this palette already carried and nothing drew: a caption's box is now
1100- // screen paints one yet (the engine model landed first), and inventing1100+ // that box.
1101- // a colour here for a box nobody draws is the one thing this call says1101+ LaneKind::Subtitle => CLIP_TEXT(),
1102- // not to do.
1103- LaneKind::Subtitle => CLIP_IMAGE(),
1104 }1102 }
1105 }1103 }
1106 1104
crates/app/src/ui/timeline.rsmodified+311 -191
@@ -40,43 +40,13 @@ impl Player {
40 for &lane in &lanes {40 for &lane in &lanes {
41 rows.push(self.lane_row(lane, filled, cx));41 rows.push(self.lane_row(lane, filled, cx));
42 }42 }
43- // Built from the same playhead pixel the lanes are, and before the
44- // export takes `filled` over below: the strip is a picture of the
45- // timeline, not of an export's progress.
46- let strip = self.subtitle_strip(filled, cx);
47- let strip_h = subtitle_strip_h(strip.is_some());
48 let (hint, filled) = if let Some(export) = self.exporting() {43 let (hint, filled) = if let Some(export) = self.exporting() {
49- let progress = export.progress();44+ // The words are the card's now ([`Player::export_progress_card`]):
50- let elapsed = self45+ // the export is modal, so this line is under its scrim and a second
51- .export_started46+ // copy of the clocks there is one that can only be read dimmed. The
52- .map_or(0., |t| t.elapsed().as_secs_f32());47+ // ruler keeps the number -- it is the one part of the progress the
53- // Two numbers that must both be honest: the one that counts up is48+ // card does not cover, and it costs nothing.
54- // measured, the one that counts down is a guess and says so.49+ (String::new(), export.progress())
55- let left = eta_secs(&self.export_marks, elapsed, progress).map_or_else(
56- || "estimating…".to_owned(),
57- |s| format!("~{} left", clock(s)),
58- );
59- (
60- format!(
61- // Clocks, then the way out, then what is encoding: at the
62- // 640 px floor the tail is what truncation eats, and the
63- // codec pair is the one part of this line the card already
64- // said. The escape must not be what goes missing.
65- "EXPORTING {}% · {} elapsed · {left} — {} cancels · {} · {}",
66- (progress * 100.) as u32,
67- clock(elapsed),
68- key(ActionId::CancelExport),
69- // The row that was picked; the engine's line below names the
70- // seats alone, since the library is what identifies a codec.
71- format_label(self.format),
72- // What the worker actually opened, so a fallback to the
73- // software encoder shows here rather than being invisible.
74- export
75- .encoders()
76- .unwrap_or_else(|| "opening the encoder".to_string()),
77- ),
78- progress,
79- )
80 } else {50 } else {
81 // The strokes no button carries; the rest ride on the buttons'51 // The strokes no button carries; the rest ride on the buttons'
82 // tooltips. Keys first: at a 640 px window the tail is what a52 // tooltips. Keys first: at a 640 px window the tail is what a
@@ -114,8 +84,8 @@ impl Player {
114 // number a scroll is measured against, and the one the affordance below84 // number a scroll is measured against, and the one the affordance below
115 // counts with. The line it costs is taken off the box before the count,85 // counts with. The line it costs is taken off the box before the count,
116 // or the row that says "1 more" would be the row hiding it.86 // or the row that says "1 more" would be the row hiding it.
117- let region_h = (timeline_h(lanes.len()) + strip_h).min(viewport_h * TIMELINE_SHARE);87+ let region_h = timeline_h(lanes.len()).min(viewport_h * TIMELINE_SHARE);
118- let lanes_box = (region_h - TIMELINE_FIXED_H - strip_h).max(LANE_H);88+ let lanes_box = (region_h - TIMELINE_FIXED_H).max(LANE_H);
119 let overflows = lanes.len() > lanes_shown(lanes_box);89 let overflows = lanes.len() > lanes_shown(lanes_box);
120 let lanes_box = match overflows {90 let lanes_box = match overflows {
121 true => (lanes_box - LABEL_H - 8.).max(LANE_H),91 true => (lanes_box - LABEL_H - 8.).max(LANE_H),
@@ -291,11 +261,6 @@ impl Player {
291 }),261 }),
292 )262 )
293 })263 })
294- // Under the tracks and outside their scrolling column: a subtitle is
295- // not a track -- nothing can be dropped on it and nothing dragged
296- // along it -- and a strip that scrolled away with the sixth lane
297- // would be a strip nobody could see while editing.
298- .children(strip)
299 }264 }
300 265
301 /// The subtitle tracks this timeline holds, under the media list: one row266 /// The subtitle tracks this timeline holds, under the media list: one row
@@ -332,7 +297,7 @@ impl Player {
332 let groups = subtitle_rows(tracks);297 let groups = subtitle_rows(tracks);
333 // What the row's × says the way back is, in the stroke this keymap298 // What the row's × says the way back is, in the stroke this keymap
334 // actually binds: a file's subtitles go on without the file.299 // actually binds: a file's subtitles go on without the file.
335- let add_key = self.keymap.display(ActionId::AddSubtitleTrack);300+ let add_key = self.keymap.display(ActionId::ImportSubtitles);
336 // One file's tracks need no prefix saying which file: it is the only301 // One file's tracks need no prefix saying which file: it is the only
337 // one, and every row would carry the same word.302 // one, and every row would carry the same word.
338 let several_files = groups.len() > 1;303 let several_files = groups.len() > 1;
@@ -373,16 +338,21 @@ impl Player {
373 let tip: SharedString = match &row.refused {338 let tip: SharedString = match &row.refused {
374 Some(why) => format!("{} — {why}", path.display()),339 Some(why) => format!("{} — {why}", path.display()),
375 None => format!(340 None => format!(
376- "{} — click to show this track over the picture",341+ "{} — drag it onto a subtitle track to place it; nothing is over \
342+ the picture until it is placed",
377 path.display()343 path.display()
378 ),344 ),
379 }345 }
380 .into();346 .into();
347+ // What the pointer carries onto a lane: the row's own
348+ // name, the ghost a library row makes.
349+ let carried: SharedString = title.clone().into();
381 // Named, because a × is the same glyph on every row and350 // Named, because a × is the same glyph on every row and
382 // the tooltip is what says which track it takes off.351 // the tooltip is what says which track it takes off.
383 let remove_tip: SharedString =352 let remove_tip: SharedString =
384 format!(353 format!(
385- "Remove {title} — {} puts a file's subtitles back on",354+ "Remove {title} from the palette — {} puts a file's subtitles \
355+ back in it",
386 add_key356 add_key
387 )357 )
388 .into();358 .into();
@@ -403,13 +373,23 @@ impl Player {
403 .when(usable, |d| {373 .when(usable, |d| {
404 d.cursor_pointer()374 d.cursor_pointer()
405 .hover(|s| s.bg(rgb(BG_HOVER())))375 .hover(|s| s.bg(rgb(BG_HOVER())))
376+ // Dragged, the whole track goes down on the
377+ // subtitle lane it is let go over -- the
378+ // gesture a media row already answers to,
379+ // on the list beside it. A track that could
380+ // not be read carries nothing: there is
381+ // nothing of it to place.
382+ .on_drag(SubPick(track), move |_, _, _, cx| {
383+ cx.new(|_| Tip(carried.clone()))
384+ })
385+ // Selects the row and shows nothing: a
386+ // subtitle track reaches the picture by
387+ // being placed on a subtitle lane, the way
388+ // a film reaches it by being placed on a
389+ // video one. What the selection is for is
390+ // the × and the mark on the row.
406 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {391 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
407 this.sub_track = track;392 this.sub_track = track;
408- // Picking a track is asking to see it: a
409- // click that changed nothing on screen
410- // because the toggle was off would read
411- // as a dead row.
412- this.subs_on = true;
413 cx.notify();393 cx.notify();
414 }))394 }))
415 })395 })
@@ -547,16 +527,15 @@ impl Player {
547 .truncate()527 .truncate()
548 .text_size(px(11.))528 .text_size(px(11.))
549 .text_color(rgb(FG_SECONDARY()))529 .text_color(rgb(FG_SECONDARY()))
550- .child(match (self.subs_on, sub_pick_name(tracks, self.sub_track)) {530+ .child(match self.subs_on {
551- // Which of them is on screen, named by its film:531+ // A palette and not a picker: none of these rows is
552- // the heading over a list of five is where the one532+ // "the one on screen" any more, so the heading names
553- // being shown is worth saying out loud.533+ // no track. What is on screen is on the subtitle
554- (true, Some(pick)) => format!("Subtitles — {pick}"),534+ // lanes, each with its own eye.
555- (true, None) => "Subtitles".to_string(),535+ true => "Subtitles",
556- // The toggle's state where the tracks are listed: a536+ // The mute's state where the tracks are listed: with
557- // list of subtitles nothing on screen is showing has537+ // it off no lane draws, however many are placed.
558- // to say that it is showing none.538+ false => "Subtitles — hidden",
559- (false, _) => "Subtitles — hidden".to_string(),
560 }),539 }),
561 )540 )
562 .child(541 .child(
@@ -579,136 +558,6 @@ impl Player {
579 /// is by its tint, and the tooltip is where every box says what clicking it558 /// is by its tint, and the tooltip is where every box says what clicking it
580 /// does. Never focusable, so the root keeps focus and the play binding still559 /// does. Never focusable, so the root keeps focus and the play binding still
581 /// works after a click (ledger:182).560 /// works after a click (ledger:182).
582- /// The subtitle strip: where the picked track's cues are along the very same
583- /// bed the lanes are drawn on, through the very same [`Scale`], so a cue
584- /// lines up with the take it belongs to at every zoom.
585- ///
586- /// Display only -- no drag, no trim, no drop. What it is *for* is the
587- /// question "is there a subtitle here", which a timeline could not answer at
588- /// all before: the cues are the project's and are edited in the file they
589- /// came from.
590- ///
591- /// `None` with no track picked, so a timeline without subtitles is the panel
592- /// it has always been.
593- pub(crate) fn subtitle_strip(
594- &self,
595- filled: f32,
596- cx: &mut Context<Self>,
597- ) -> Option<impl IntoElement + use<>> {
598- let track = self.subtitle_track()?;
599- let scale = self.scale;
600- // The pick with its film on it, not the raw tag: two films' "eng"
601- // tracks read alike otherwise, and a header saying "und" names a
602- // language nobody speaks.
603- let label = sub_pick_name(self.session.as_ref()?.subtitles(), self.sub_track)?;
604- // The colour the file's own rows and clips wear, so the strip says
605- // whose subtitles these are before the tooltip is asked. `None` for a
606- // standalone `.srt` -- nobody's stream, and the first film's colour
607- // would be a lie about where it came from.
608- let tint = file_tint(self.sources(), &track.path).unwrap_or(BG_RAISED());
609- // The whole of what the row says in words, since a 40 px column can hold
610- // three characters of it: which track of which file, how many cues, the
611- // file itself in full -- one stem is two films when they are two cuts of
612- // it -- and, for a track that could not be read, the engine's own reason,
613- // where the library row's grey already says the same thing.
614- let tip: SharedString = match track.refused.is_some() {
615- true => format!(
616- "Subtitles: {label} — {} — {}",
617- subtitle_detail(track),
618- track.path.display()
619- ),
620- false => format!(
621- "Subtitles: {label} — {}, {} hides them — {}",
622- subtitle_detail(track),
623- self.keymap.display(ActionId::ToggleSubtitles),
624- track.path.display()
625- ),
626- }
627- .into();
628- // Where the cues are on *this* timeline and not in the file they came
629- // from ([`PlaybackSession::timeline_cues`]) -- the same map the plate
630- // over the picture and the export both go through, which is what keeps
631- // a mark under the take it is spoken over after a cut.
632- let cues: Vec<(f32, f32)> = self
633- .session
634- .as_ref()?
635- .timeline_cues(self.sub_track)
636- .iter()
637- .map(|cue| cue_box(scale, cue))
638- .collect();
639- Some(
640- div()
641- .flex_none()
642- .h(px(SUB_LANE_H))
643- .flex()
644- .gap(px(HEADER_GAP))
645- .child(
646- // Identified for the tooltip's sake and for nothing else:
647- // the whole of what a 40 px column can say is three
648- // characters, and the rest of it hangs off the hover.
649- div()
650- .id("subtitle-lane")
651- .flex_none()
652- .w(px(HEADER_W))
653- .h_full()
654- .flex()
655- .items_center()
656- // From the left rather than centred, unlike a lane's
657- // `V1`: a track label is a language or a file name, and
658- // a centred truncation eats both of its ends.
659- .px(px(2.))
660- .rounded(px(3.))
661- .bg(rgb(tint))
662- .text_size(px(9.))
663- .text_color(rgb(FG_SECONDARY()))
664- .truncate()
665- .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into())
666- .child(label),
667- )
668- .child(
669- div()
670- .relative()
671- .flex_1()
672- .min_w(px(0.))
673- .h_full()
674- .rounded(px(3.))
675- .bg(rgb(BG_TIMELINE()))
676- .overflow_hidden()
677- // The same bed under the same [`Scale`] answers the same
678- // wheel ([`Player::timeline_wheel`]): ctrl zooms about
679- // the pointer, bare scrolls the view along. A hand that
680- // wants a cue closer aims at the cue, and a timeline
681- // surface that ignores the wheel is a dead one.
682- .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| {
683- cx.stop_propagation();
684- this.timeline_wheel(event, cx);
685- }))
686- .children(cues.into_iter().map(|(left, width)| {
687- div()
688- .absolute()
689- .top_0()
690- .h_full()
691- .left(px(left))
692- .w(px(width))
693- .rounded(px(2.))
694- .bg(rgb(BG_SELECTED()))
695- }))
696- // The playhead again, last and in the lanes' own colour:
697- // the strip is only worth anything beside them if it
698- // reads as the same moment.
699- .child(
700- div()
701- .absolute()
702- .top_0()
703- .h_full()
704- .left(px(filled))
705- .w(px(2.))
706- .bg(rgb(ACCENT_PLAYHEAD())),
707- ),
708- ),
709- )
710- }
711-
712 pub(crate) fn lane_row(561 pub(crate) fn lane_row(
713 &self,562 &self,
714 lane: Lane,563 lane: Lane,
@@ -784,6 +633,39 @@ impl Player {
784 .map_or(&[][..], PlaybackSession::sources);633 .map_or(&[][..], PlaybackSession::sources);
785 let (sel, sel_link) = (self.selected, self.selected_link());634 let (sel, sel_link) = (self.selected, self.selected_link());
786 let audio = lane.kind == LaneKind::Audio;635 let audio = lane.kind == LaneKind::Audio;
636+ // A subtitle lane holds no `Clip` and every other lane holds no
637+ // `SubClip`, so the two lists below are never both full and the bed
638+ // draws whichever it was given -- one row, and no second kind of row to
639+ // keep in step with this one.
640+ let sub = lane.kind == LaneKind::Subtitle;
641+ let shown = self.sub_lane_on(lane);
642+ let subs: Vec<SubClip> = match (sub, &self.session) {
643+ (true, Some(session)) => session.sub_lane(lane).to_vec(),
644+ _ => Vec::new(),
645+ };
646+ // Where this lane's words actually are on this timeline
647+ // ([`PlaybackSession::sub_lane_cues`], the same map an export and the
648+ // plate over the picture go through): the marks inside the placements'
649+ // boxes, so a caption's box says where in it anybody speaks.
650+ let cues: Vec<(f32, f32)> = match (sub, &self.session) {
651+ (true, Some(session)) => session
652+ .sub_lane_cues(lane)
653+ .iter()
654+ .map(|cue| cue_box(scale, cue))
655+ .collect(),
656+ _ => Vec::new(),
657+ };
658+ let eye_tip: SharedString = match shown {
659+ true => format!("{name} shows its captions — click to hide this track"),
660+ false => format!("{name} is hidden — click to show its captions again"),
661+ }
662+ .into();
663+ // What a caption's box says clicking it does; the media boxes' tooltip
664+ // names edits a placement has none of (no group, no speed, no ripple).
665+ let sub_tip: SharedString =
666+ "Drag it along the lane or onto another subtitle track, an end to trim it, × takes it \
667+ off"
668+ .into();
787 // What this track plays at, on the header it belongs to: shown only669 // What this track plays at, on the header it belongs to: shown only
788 // when it is not unity, because a column 40 px wide has room for a670 // when it is not unity, because a column 40 px wide has room for a
789 // number or for a name, and the name is what a header is for. The671 // number or for a name, and the name is what a header is for. The
@@ -881,6 +763,37 @@ impl Player {
881 false => format!("{name} {gain_db:+.0}"),763 false => format!("{name} {gain_db:+.0}"),
882 })764 })
883 .into_any_element(),765 .into_any_element(),
766+ // A subtitle track's own one setting, in the same
767+ // place and for the same reason: whether this lane's
768+ // words are drawn over the picture. The eye every
769+ // player puts on a track, `HIT_MIN` tall like the mix
770+ // button it sits where.
771+ false if sub => div()
772+ .id(("eye-lane", lane.ord))
773+ .flex_1()
774+ .w_full()
775+ .flex()
776+ .flex_col()
777+ .items_center()
778+ .justify_center()
779+ .rounded(px(3.))
780+ .cursor_pointer()
781+ .hover(|s| s.bg(rgb(BG_HOVER())))
782+ .when(!shown, |d| d.text_color(rgb(FG_DISABLED())))
783+ .tooltip(move |_, cx| cx.new(|_| Tip(eye_tip.clone())).into())
784+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
785+ this.toggle_sub_lane(lane, cx)
786+ }))
787+ .child(name.clone())
788+ .child(
789+ div()
790+ .text_size(px(9.))
791+ .child(match shown {
792+ true => "◉",
793+ false => "○",
794+ }),
795+ )
796+ .into_any_element(),
884 false => div()797 false => div()
885 .flex_1()798 .flex_1()
886 .flex()799 .flex()
@@ -993,6 +906,39 @@ impl Player {
993 this.preview_ghost(&drag, lane, event.event.position.x, cx);906 this.preview_ghost(&drag, lane, event.event.position.x, cx);
994 },907 },
995 ))908 ))
909+ // A palette row let go over a lane places that whole
910+ // subtitle track where the hand left it -- and over a lane
911+ // that is not a subtitle one, `place_sub` refuses it in
912+ // words, which is why the listener is on every bed rather
913+ // than on the subtitle beds alone.
914+ .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| {
915+ this.place_sub(drag.0, lane, window.mouse_position().x, cx);
916+ }))
917+ .drag_over::<SubPick>(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM())))
918+ .on_drag_move(cx.listener(
919+ move |this, event: &DragMoveEvent<SubPick>, _, cx| {
920+ if !event.bounds.contains(&event.event.position) {
921+ return;
922+ }
923+ let track = event.drag(cx).0;
924+ this.preview_ghost_pick(track, lane, event.event.position.x, cx);
925+ },
926+ ))
927+ // ...and a caption already on a lane moves along it, or onto
928+ // another subtitle track, exactly as a clip does.
929+ .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| {
930+ this.move_sub(drag, lane, window.mouse_position().x, cx);
931+ }))
932+ .drag_over::<SubDrag>(|s, _, _, _| s.bg(rgb(BG_HOVER_DIM())))
933+ .on_drag_move(cx.listener(
934+ move |this, event: &DragMoveEvent<SubDrag>, _, cx| {
935+ if !event.bounds.contains(&event.event.position) {
936+ return;
937+ }
938+ let drag = *event.drag(cx);
939+ this.preview_ghost_sub(&drag, lane, event.event.position.x, cx);
940+ },
941+ ))
996 .children(clips.iter().enumerate().map(|(i, clip)| {942 .children(clips.iter().enumerate().map(|(i, clip)| {
997 // The clip as the lane holds it, for the drag payload:943 // The clip as the lane holds it, for the drag payload:
998 // what a drop looks itself up by has to be the placed944 // what a drop looks itself up by has to be the placed
@@ -1290,6 +1236,180 @@ impl Player {
1290 )1236 )
1291 })1237 })
1292 }))1238 }))
1239+ // The same bed's other kind of box: a stretch of a palette
1240+ // track placed on this lane, dragged along it, dragged onto
1241+ // another subtitle lane, trimmed at either end and lifted
1242+ // off by its own ×. Empty on every lane that is not a
1243+ // subtitle one, which is why there is one row and not two.
1244+ .children(subs.iter().enumerate().map(|(i, placed)| {
1245+ // What the drag payload names, and what an edge drag is
1246+ // *showing* -- the box moves under the pointer and the
1247+ // engine hears once, at the release.
1248+ let (placed, shown_sub) = (*placed, self.trimmed_sub(lane, i, *placed));
1249+ let (start, len) = (
1250+ f64::from(shown_sub.start) / self.fps,
1251+ f64::from(shown_sub.frames) / self.fps,
1252+ );
1253+ let span = scale.width_px(len);
1254+ let width = clip_width(span);
1255+ let left = scale.px_at(start);
1256+ let (vis_x, vis_w) = visible_slice(left, width, bed);
1257+ // Which track's words these are, film and all: two
1258+ // "eng" tracks off two files read alike otherwise.
1259+ let label = self
1260+ .session
1261+ .as_ref()
1262+ .and_then(|session| sub_pick_name(session.subtitles(), placed.track));
1263+ let ghost: SharedString =
1264+ label.clone().unwrap_or_else(|| lane.label()).into();
1265+ let tip = sub_tip.clone();
1266+ let head = shown_sub.start;
1267+ div()
1268+ .id((row_id.clone(), i))
1269+ .absolute()
1270+ .top_0()
1271+ .h_full()
1272+ .left(px(left))
1273+ .w(px(width))
1274+ .overflow_hidden()
1275+ .rounded(px(3.))
1276+ .border_1()
1277+ .border_color(rgb(FG_SECONDARY()))
1278+ // The captions' own colour, dimmed on a lane whose
1279+ // eye is shut: what is not being drawn over the
1280+ // picture is still on the lane, and says so.
1281+ .bg(rgb(CLIP_TEXT()))
1282+ .when(!shown, |d| d.opacity(0.55))
1283+ .cursor_pointer()
1284+ .hover(|s| s.border_color(rgb(ACCENT_PRIMARY())))
1285+ .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into())
1286+ .on_drag(
1287+ SubDrag {
1288+ lane,
1289+ idx: i,
1290+ sub: placed,
1291+ },
1292+ move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())),
1293+ )
1294+ .on_mouse_down(
1295+ MouseButton::Left,
1296+ cx.listener(move |this, event: &MouseDownEvent, _, cx| {
1297+ // Where in the box the hand took hold, so
1298+ // the caption moves with the pointer rather
1299+ // than jumping its head under it.
1300+ this.grab =
1301+ this.frame_under(event.position.x).saturating_sub(head);
1302+ cx.notify();
1303+ }),
1304+ )
1305+ // The two strips a drag lengthens it by, on the same
1306+ // rule a clip's are drawn by ([`trims`]).
1307+ .children(
1308+ [Edge::Start, Edge::End]
1309+ .into_iter()
1310+ .filter(|_| trims(span))
1311+ .map(|edge| {
1312+ let mut zone = div()
1313+ .absolute()
1314+ .top_0()
1315+ .h_full()
1316+ .w(px(EDGE_W))
1317+ .occlude()
1318+ .cursor(CursorStyle::ResizeLeftRight)
1319+ .hover(|s| s.bg(rgb(ACCENT_PRIMARY())))
1320+ .on_mouse_down(
1321+ MouseButton::Left,
1322+ cx.listener(
1323+ move |this, _: &MouseDownEvent, _, cx| {
1324+ this.start_trim(lane, i, edge, cx);
1325+ },
1326+ ),
1327+ )
1328+ .on_scroll_wheel(cx.listener(
1329+ |this, event: &ScrollWheelEvent, _, cx| {
1330+ cx.stop_propagation();
1331+ this.timeline_wheel(event, cx);
1332+ },
1333+ ));
1334+ zone = match edge {
1335+ Edge::Start => zone.left_0(),
1336+ Edge::End => zone.right_0(),
1337+ };
1338+ zone
1339+ }),
1340+ )
1341+ .when_some(label.filter(|_| show_label(vis_w)), |d, label| {
1342+ d.child(
1343+ div()
1344+ .absolute()
1345+ .top_0()
1346+ .left(px(vis_x))
1347+ .w(px(vis_w))
1348+ .h(px(LABEL_H))
1349+ .px(px(4.))
1350+ .truncate()
1351+ .text_size(px(10.))
1352+ .child(label),
1353+ )
1354+ })
1355+ // The way back off the lane, on the box itself: a
1356+ // caption is not in the clip selection's index
1357+ // space, so no stroke reaches it -- and a lane
1358+ // holding one cannot be removed either
1359+ // ([`Project::remove_lane`] refuses it), which
1360+ // would leave a placement nobody could undo but by
1361+ // undoing. Only where the box is wide enough to
1362+ // hold a target beside its name; narrower than that
1363+ // it is lifted after zooming in, exactly as it is
1364+ // trimmed after zooming in.
1365+ //
1366+ // Clear of the tail's own trim strip by that
1367+ // strip's width: both occlude and this one is drawn
1368+ // last, so hard against the right edge it swallowed
1369+ // every press meant for the edge and the tail could
1370+ // not be dragged at all (caught driving it).
1371+ .when(vis_w >= 2. * HIT_MIN + EDGE_W, |d| {
1372+ d.child(
1373+ div()
1374+ .id(("sub-lift", i))
1375+ .absolute()
1376+ .top_0()
1377+ .left(px(vis_x + vis_w - HIT_MIN - EDGE_W))
1378+ .w(px(HIT_MIN))
1379+ .h(px(HIT_MIN))
1380+ .flex()
1381+ .items_center()
1382+ .justify_center()
1383+ .occlude()
1384+ .rounded(px(3.))
1385+ .cursor_pointer()
1386+ .hover(|s| s.bg(rgb(BG_HOVER())))
1387+ .on_click(cx.listener(
1388+ move |this, _: &ClickEvent, _, cx| {
1389+ cx.stop_propagation();
1390+ this.lift_sub(lane, i, cx);
1391+ },
1392+ ))
1393+ .child("×"),
1394+ )
1395+ })
1396+ }))
1397+ // ...and where the words actually are inside those boxes:
1398+ // the cues this lane shows on *this* timeline, in a band
1399+ // along the bottom of the row. A placement is a window of a
1400+ // track, so a box is not full of speech -- and a lane whose
1401+ // marks are all in its first half is a caption dragged too
1402+ // far, which is exactly what this band shows.
1403+ .children(cues.into_iter().map(|(left, width)| {
1404+ div()
1405+ .absolute()
1406+ .bottom_0()
1407+ .h(px(4.))
1408+ .left(px(left))
1409+ .w(px(width))
1410+ .rounded(px(2.))
1411+ .bg(rgb(BG_SELECTED()))
1412+ }))
1293 // What the silence card found, over the clips it found them1413 // What the silence card found, over the clips it found them
1294 // in and over the waveform band that shows why: on the lane1414 // in and over the waveform band that shows why: on the lane
1295 // the scan ran on and no other, because that is the only1415 // the scan ran on and no other, because that is the only
crates/app/src/ui/toolbar.rsmodified+5 -5
@@ -307,15 +307,15 @@ impl Player {
307 }),307 }),
308 ))308 ))
309 .child(self.action_control(309 .child(self.action_control(
310- "add-subtitle-track",310+ "add-subtitle-lane",
311 0.,311 0.,
312 BG_RAISED(),312 BG_RAISED(),
313 None,313 None,
314 "+ S",314 "+ S",
315- "adds every subtitle track in a file you pick",315+ "adds a subtitle track under the ones there",
316- ActionId::AddSubtitleTrack,316+ ActionId::AddSubtitleLane,
317 cx.listener(|this, _: &ClickEvent, _, cx| {317 cx.listener(|this, _: &ClickEvent, _, cx| {
318- this.pick_and_add_subtitles(cx)318+ this.add_lane(LaneKind::Subtitle, cx)
319 }),319 }),
320 ))320 ))
321 .child(separator())321 .child(separator())
@@ -341,7 +341,7 @@ impl Player {
341 SNAP_SLOT_W,341 SNAP_SLOT_W,
342 BG_RAISED(),342 BG_RAISED(),
343 None,343 None,
344- match (self.subtitle_track().is_some(), self.subs_on) {344+ match (self.placed_captions() > 0, self.subs_on) {
345 (false, _) => "No subs",345 (false, _) => "No subs",
346 (true, true) => "Subs on",346 (true, true) => "Subs on",
347 (true, false) => "Subs off",347 (true, false) => "Subs off",