forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB978e685Tahinli3 months ago627 commits

main.rs1043 lines, 57.8 KiBHistoryRawDownload
1mod keymap;
2mod player;
3mod ui;
4
5mod audio_cards;
6mod color_ui;
7mod eq_ui;
8mod export_ui;
9mod files;
10mod importing;
11mod interact;
12mod layout;
13mod library_meta;
14mod menus;
15mod notices;
16mod oracle;
17mod render;
18mod subs;
19mod timeline_math;
20mod transform_ui;
21mod transport;
22mod viewport;
23
24pub(crate) use audio_cards::*;
25pub(crate) use color_ui::*;
26pub(crate) use eq_ui::*;
27pub(crate) use export_ui::*;
28pub(crate) use files::*;
29pub(crate) use importing::*;
30pub(crate) use interact::*;
31pub(crate) use layout::*;
32pub(crate) use library_meta::*;
33pub(crate) use menus::*;
34// The tests' door to the escape rule; render.rs calls it by its own name.
35#[cfg(test)]
36pub(crate) use render::escape_leaves_player_fullscreen;
37// The Contain letterbox, shared with the subtitle picture overlay
38// (ui/preview.rs) so both draw the same fitted rect the same way.
39pub(crate) use render::letterboxed_image;
40pub(crate) use notices::*;
41pub(crate) use oracle::*;
42pub(crate) use subs::*;
43pub(crate) use timeline_math::*;
44pub(crate) use transform_ui::*;
45pub(crate) use transport::*;
46pub(crate) use viewport::*;
47
48use ui::theme::*;
49use ui::widgets::*;
50
51use keymap::{ActionId, Keymap};
52
53use std::cell::Cell;
54use std::collections::{HashMap, HashSet};
55use std::path::{Path, PathBuf};
56use std::rc::Rc;
57use std::sync::Arc;
58use std::sync::atomic::{AtomicBool, Ordering};
59use std::time::{Duration, Instant};
60
61use engine::audio::StreamInfo;
62use engine::color::ColorParams;
63use engine::decode::Backend;
64use engine::eq::{Band, BandKind, EqParams};
65use engine::export::{AUDIO_KBPS, DEFAULT_AUDIO_KBPS, EncoderSeat, ExportSettings, Format};
66use engine::limiter::Limiter;
67use engine::project::{Edge, Lane, LaneKind, Source, Speed, SubClip};
68use engine::scale::FitPolicy;
69use engine::tonemap::Preset;
70use engine::transform::TransformParams;
71use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession};
72use gpui::{
73 AnyElement, App, Application, Bounds, ClickEvent, Context, Corners, CursorStyle, Div,
74 DragMoveEvent, FocusHandle, KeyDownEvent, KeyUpEvent, MouseButton, MouseDownEvent,
75 MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, Point, RenderImage, ScrollDelta,
76 ScrollHandle, ScrollWheelEvent, SharedString, Size, Stateful, TextAlign, TitlebarOptions,
77 Window, WindowBounds, WindowOptions, canvas, div, point, prelude::*, px, relative, rgb, rgba,
78 size,
79};
80
81struct Player {
82 /// DESIGN.md §12 step 2: the stance skeleton behind `EDITH_DARKROOM`, read
83 /// once at startup ([`main`]) and never toggled at runtime -- a mid-session
84 /// flip would mean every region rebuilding under the pointer, which is not
85 /// this flag's job. [`crate::render`] branches its one `Render::render` on
86 /// it; nothing else reads it.
87 darkroom: bool,
88 /// The timeline, once there is one. A run with no file opens without it and
89 /// waits: the first media import or project load is what fills it, and
90 /// until then every action that needs a timeline says so instead of acting.
91 session: Option<PlaybackSession>,
92 /// A resolution and/or frame rate picked before any file exists to derive
93 /// them from -- what [`Player::cycle_resolution`] and its fps sibling edit
94 /// instead of refusing, with nothing open yet. Applied as the explicit
95 /// override [`engine::PlaybackSession::set_resolution`]/`set_frame_rate`
96 /// already are for a `.edith`'s own saved values ([`Player::install_media`])
97 /// the moment the first session exists, and cleared there: consumed once,
98 /// the way a project's own saved settings are read once at
99 /// [`engine::PlaybackSession::open_project`].
100 pending_settings: (Option<(u32, u32)>, Option<f64>, Option<u32>),
101 /// A library row's own file, opened and playing in place of the
102 /// timeline's picture, and never written to `session` or its undo stack:
103 /// a preview is watched, not edited. `Some` is what [`Player::pump`] and
104 /// [`Player::transport`] read first -- the timeline's own session and its
105 /// silence scan sit untouched underneath until this clears again
106 /// ([`Player::close_preview`]).
107 preview_session: Option<PlaybackSession>,
108 /// Whether the timeline was playing when a preview took it over
109 /// ([`Player::open_preview`] pauses it so the two sounds never overlap):
110 /// what [`Player::close_preview`] resumes, and only then.
111 preview_playing: bool,
112 /// The picture alone, filling the window -- what `Fullscreen` gives every
113 /// consumer video player, and not what gpui's own `toggle_fullscreen`
114 /// gives on its own (the OS window, chrome and all). Kept apart from
115 /// `window.is_fullscreen()` because the two can fall out of step: a
116 /// compositor keybind changes the window's without this flag hearing
117 /// about it, so [`Player::act`] reconciles them rather than trusting
118 /// either alone.
119 player_fullscreen: bool,
120 /// Whether the active session -- the timeline or a library preview,
121 /// whichever [`Player::active_session`] is reading -- restarts from the
122 /// top on reaching its end instead of stopping there. One flag for both,
123 /// since only one of them is ever playing at a time.
124 loop_on: bool,
125 /// The in/out mark an export is clipped to, half-open `[start, end)` in
126 /// timeline frames -- `None` for the whole timeline. Session state, like
127 /// the mark itself: never saved to a `.edith` ([`ExportSettings::range`]).
128 range: Option<(u32, u32)>,
129 /// Loop-trim (DESIGN.md §6, `/`): the frame window `[start, end)` the
130 /// transport loops inside while it is on -- the subject cut's own clip
131 /// span, which is what a `[`/`]` nudge is moving. `None` is the mode off,
132 /// which is also what lets [`Player::pump`] answer
133 /// [`should_loop_restart`] with one field instead of asking whether the
134 /// mode is on and then separately what the window is.
135 loop_trim: Option<(u32, u32)>,
136 /// Timeline seconds -> frame index, so the clock can be compared to what
137 /// the decoder hands over.
138 fps: f64,
139 name: SharedString,
140 image: Option<Arc<RenderImage>>,
141 /// The picture of the bitmap cue on screen, and which cue that is: the
142 /// track it is a row of and where it starts on the timeline. A PGS display
143 /// set is run-length and has to be walked into a canvas-sized buffer to be
144 /// drawn ([`engine::subtitle::CueImage::rgba`]), which is a thing to do
145 /// when the cue changes -- every few seconds -- and not at every repaint.
146 ///
147 /// The *lane* is half the key because the four PGS tracks of a remux are
148 /// one film's subtitles in four languages: placed one over the other they
149 /// start at the same microsecond, and a lane whose eye was shut would leave
150 /// the one before it on screen.
151 sub_image: Option<((Lane, i64), Arc<RenderImage>)>,
152 /// A frame that arrived before its time; shown on the tick it comes due.
153 /// The pump's buffer, not transport state -- but a frame waiting here is
154 /// what keeps a finished decoder from reading as [`Transport::Ended`] one
155 /// tick early. See [`Player::transport`].
156 held: Option<Frame>,
157 /// A seek is waiting for its frame, and since when. Keeps the repaint loop
158 /// alive while paused, which is the only way the new still ever reaches the
159 /// screen; the instant is what a drag's samples are gated on
160 /// ([`Player::flush_drag`]) and what says so in words when one open stands
161 /// too long ([`seek_line`]).
162 seek_since: Option<Instant>,
163 /// The ruler's own box, recorded at prepaint: a mouse listener is handed
164 /// the window position and nothing else.
165 ruler: Rc<Cell<Bounds<Pixels>>>,
166 /// The scrollbar track's laid-out box, recorded at prepaint like the
167 /// ruler's: a thumb drag is followed on the root (the pointer leaves the
168 /// strip at once), and the root has only window coordinates to work with.
169 scroll_track: Rc<Cell<Bounds<Pixels>>>,
170 /// A thumb in the hand: how far into the thumb the press landed, in
171 /// track pixels. `None` with no drag in flight.
172 scroll_drag: Option<f32>,
173 /// A thumb of the lane stack's own scrollbar in the hand: how far into
174 /// the thumb the press landed, in track pixels. `None` with no drag in
175 /// flight. The stack's box itself is read straight off the scroll handle
176 /// each frame, so unlike the time axis's strip it needs no probe of its
177 /// own.
178 lanes_drag: Option<f32>,
179 /// How wide a second of timeline is drawn, and from which moment. Held here
180 /// and nowhere else: every frame-to-pixel answer in the panel comes out of
181 /// it, so the boxes, the playhead and the pointer cannot disagree.
182 scale: Scale,
183 /// A hand has moved the view itself -- a wheel scroll, a zoom about the
184 /// pointer -- and until the playhead runs back into what it chose to look
185 /// at, the view is the hand's and the follow keeps off it. Without this a
186 /// notch during playback was undone by the very next frame: the follow
187 /// centres a playhead that has left the bed, and a scroll away from it is
188 /// exactly a playhead leaving the bed. Given back by [`Render`] the moment
189 /// the head is on screen again, and by every transport ask (a seek, a
190 /// play/pause) outright -- those are a person saying where to look.
191 panned: bool,
192 /// Which placements the edit keys act on: the lane each is in and its
193 /// index there, every ctrl-click in the order it was made. The *clicked*
194 /// half and not the group -- a group is what gets marked on screen, but
195 /// Lift has to know which half it was aimed at -- and the last pick is the
196 /// [`anchor`](Selection::anchor) every single-thing action uses. Indices
197 /// move under every edit, so this is cleared by all of them.
198 selected: Selection,
199 /// The clip menu a right-click opened, if one is up. Holds an index like
200 /// `selected` does, so it is closed by anything that can move indices --
201 /// every stroke, and every item of its own.
202 context_menu: Option<ContextMenu>,
203 /// The choice list a click on an enumerated setting opened, if one is up:
204 /// the project resolution or a clip's fit policy, every value on screen at
205 /// once. Closed by anything that closes the menus, and for the same reason.
206 picker: Option<Picker>,
207 /// The library menu a right-click on a row opened, if one is up. Names its
208 /// row by file and stream rather than by position, so it acts on the row it
209 /// was opened on however the list is rebuilt under it.
210 library_menu: Option<LibraryMenu>,
211 /// Which library row is picked: the file and the audio stream that row
212 /// names, which is what an insert needs and what survives a row list being
213 /// rebuilt. Its own selection and not the timeline's: Delete keeps acting
214 /// on the clip that was clicked in a lane, whatever the library is showing.
215 selected_asset: Option<(PathBuf, usize)>,
216 /// Which category of the library is being looked at. A tab and not a
217 /// filter box: the categories are what the media *is*, and every editor
218 /// this one is measured against splits its pool the same way.
219 library_tab: LibraryTab,
220 /// Which of the darkroom dock's Src/Clip tabs is showing (DESIGN §5).
221 /// `Player`-owned rather than the process-global static it used to be
222 /// (VIOLATION 3), and persisted the way `ui::theme`'s pick is
223 /// (`ui::dock_stance::load`/`save`) so "a room reopens exactly as left"
224 /// survives a quit and relaunch, not just this window.
225 pub(crate) dock_src_active: bool,
226 /// The Sources tab's own filter text (darkroom dock, MOCK-SPEC "Dock" §2)
227 /// and whether it is the thing typed strokes go to right now -- the same
228 /// capture-flag shape `keys_search`/`keys_open` already use, so a letter
229 /// filters the list instead of firing a spine action while the box is
230 /// focused, and does nothing to the keymap once it is not.
231 pub(crate) dock_filter: String,
232 pub(crate) dock_filter_edit: bool,
233 /// Which of the four sort chips is showing (MOCK-SPEC "Dock" §3).
234 pub(crate) dock_sort: ui::dock_stance::DockSort,
235 /// What is known about each source's audio, taken once and kept. Keyed on
236 /// the path *and stream* -- two streams of one file are two envelopes -- and
237 /// the key is inserted the moment the decode is *started*: presence means
238 /// "asked", so a repaint mid-decode cannot ask again.
239 waves: HashMap<(PathBuf, usize), Wave>,
240 /// The bench's poster frame per file ([`Thumb`]), filled like `waves` --
241 /// presence means "asked" -- one per file rather than one per clip, since
242 /// every clip cut from a file shares its picture.
243 thumbs: HashMap<PathBuf, Thumb>,
244 /// What each source's stand-in is up to ([`engine::proxy`]), filled like
245 /// `waves`: presence means "asked", so the encode is started once per file
246 /// however many times the library is drawn. The switch that decides whether
247 /// they are *played* is the session's own -- it is the project's and is
248 /// saved with it, where this map is this window's view of the cache.
249 proxies: HashMap<PathBuf, Proxy>,
250 /// Which audio streams each imported file has, as its header describes
251 /// them: one library row per entry. Keyed and filled like `waves` --
252 /// presence means "asked" -- and an empty list is a silent file, which is
253 /// exactly one row and no stream tags.
254 streams: HashMap<PathBuf, Vec<StreamInfo>>,
255 /// What each source is coded at, read off its header once and kept: what a
256 /// properties card says about a file's rate. Filled like `streams` --
257 /// presence means "asked" -- and the inner `None` is "asked, not answered
258 /// yet", which the card draws as an ellipsis: the probe walks a Matroska's
259 /// clusters, so a big film answers in seconds rather than at once.
260 bitrates: HashMap<PathBuf, Option<MediaBitrate>>,
261 /// How big each still source's picture is, read from its header once and
262 /// kept -- what a library row and its card say about a file that has no
263 /// streams to describe. Filled like `streams`: presence means "asked", and
264 /// `None` is a file with no picture to report (every source that is not an
265 /// image, and one whose header would not read).
266 sizes: HashMap<PathBuf, Option<(u32, u32)>>,
267 /// Every frame of each source a decoder may be started from -- its sync
268 /// points ([`engine::demux::sync_points`]), which are the frames a cut may
269 /// be placed on for an export to *copy* the film instead of coding all of
270 /// it again. Filled like `bitrates` and off the render thread for the same
271 /// reason, and more so: the answer is that Matroska cluster walk. An empty
272 /// list is a source with no grid to offer (an mp4, a still, a song), which
273 /// must stay in the map or every repaint would ask again.
274 syncs: HashMap<PathBuf, Vec<u32>>,
275 /// Which decoder each source will run on, probed once at import and kept:
276 /// the codec (`None` for a still) and the seat the engine picked for it.
277 /// What a library row says *before* anything plays; the running answer is
278 /// the session's own (`PlaybackSession::decode_backend`), which follows a
279 /// fallback this cannot. Filled like `sizes`: presence means "asked", and
280 /// `None` is a source with no decoder to name -- a song, or one the probe
281 /// refused -- which must stay in the map or every repaint would ask again.
282 decoders: HashMap<PathBuf, Option<(Option<Codec>, Backend)>>,
283 /// What an export of the picked settings would open -- the picture's seat
284 /// or the copy that means it opens none, and the sound's -- and what it was
285 /// asked about: the settings, the canvas and the *cuts*, since where they
286 /// land is what decides whether the picture is copied at all. The probe
287 /// opens a real VA-API encoder (~100 ms) and reads every source's header,
288 /// so it runs off the render thread and only while the export card is up.
289 /// The inner `None` is "asked, not answered yet".
290 export_seat: Option<(
291 ExportSettings,
292 (u32, u32),
293 Vec<Clip>,
294 Option<(Option<&'static str>, &'static str)>,
295 )>,
296 /// What this machine's GPU decodes and encodes, as the plugin answered it:
297 /// asked once, off the render thread like `export_seat` and for the same
298 /// reason (a VA-API init), and kept for the life of the process because the
299 /// answer cannot change while we run. `None` is "not asked yet".
300 hw_caps: Option<SharedString>,
301 /// The copied clip. Frame ranges only, so it survives the clip it was taken
302 /// from being deleted -- and it outlives the selection.
303 clipboard: Option<Clip>,
304 /// A drag that started on the ruler. Moves anywhere in the window scrub
305 /// while it is set; the release commits the exact position.
306 scrubbing: bool,
307 /// What the hand has made of the three panel seams, and which one it is
308 /// holding now. Kept here rather than worked out per frame from the
309 /// window's own shares: a size a person dragged is a size that has to
310 /// survive the release ([`Splits`]).
311 splits: Splits,
312 /// A drag that started on a divider, tracked on the root for `scrubbing`'s
313 /// reason -- the strip is 6 px and the pointer leaves it at once.
314 split_drag: Option<Split>,
315 /// A drag that started on a clip's edge, tracked on the root for
316 /// `scrubbing`'s reason: a 6 px strip is not where the pointer stays. See
317 /// [`Trim`].
318 trim: Option<Trim>,
319 /// A drag that started on a fade handle, tracked on the root for the same
320 /// reason a trim is: a 10 px square is not where the pointer stays. See
321 /// [`FadeDrag`].
322 fade_drag: Option<FadeDrag>,
323 /// How far into the clip the last press on a box landed, in timeline
324 /// frames: what a drag lets go of is the *point that was grabbed*, so the
325 /// head lands that much in front of the pointer and the clip does not jump
326 /// under the hand. Recorded at the press because gpui hands the drop only
327 /// the value being dragged, and stale between drags, which costs nothing --
328 /// no drag starts without a press on the box it moves.
329 grab: u32,
330 /// Whether a drag or a trim is pulled onto the edges near it. On by
331 /// default, because clips meeting exactly is what a timeline is for, and off
332 /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement
333 /// no magnet may take away.
334 snap: bool,
335 /// Whether the subtitle lanes draw at all -- the mute over the shown lane
336 /// ([`Player::sub_lane`]), not a lane of its own. On by default and off by
337 /// one stroke
338 /// ([`ActionId::ToggleSubtitles`](keymap::ActionId::ToggleSubtitles)) for
339 /// anyone watching the picture rather than reading it. The player's, not the
340 /// project's: it changes nothing that is saved and nothing that is exported.
341 subs_on: bool,
342 /// Which palette row is *selected*: an index into
343 /// [`PlaybackSession::subtitles`], which is what the × takes off
344 /// ([`ActionId::RemoveSubtitleTrack`](keymap::ActionId::RemoveSubtitleTrack))
345 /// and what the list marks. A selection and nothing more -- what is on
346 /// screen is what is placed on a subtitle lane
347 /// ([`Player::subtitle_overlay`]), so picking a row shows nothing by itself,
348 /// exactly as clicking a media row plays nothing. Cleared with the timeline
349 /// like every other index here -- track 2 of one project is not track 2 of
350 /// the next.
351 sub_track: usize,
352 /// Which files' subtitle groups in the library are folded shut, keyed by
353 /// the group's own path -- the same key [`subtitle_rows`] groups on, so a
354 /// fold survives a track being added or removed off the file it belongs
355 /// to. Session-lifetime only: a fold is a "not looking at this one right
356 /// now", not a project setting, so it is never saved and every file opens
357 /// unfolded.
358 sub_folded: HashSet<PathBuf>,
359 /// Which subtitle lane is *shown*: one of them and never two, the way a
360 /// player has one subtitle track chosen at a time -- two hundred lanes of
361 /// different words all drawn at once is two hundred plates over one
362 /// picture, and nothing readable.
363 ///
364 /// `None` is nobody having picked yet, which reads as the first subtitle
365 /// lane ([`Player::active_sub_lane`]) -- so one lane is shown without a
366 /// pick, the first lane added draws, and a pick naming a lane that has
367 /// since gone falls back to the first rather than showing nothing.
368 ///
369 /// Read where the cues are drawn ([`Player::subtitle_overlay`]) and nowhere
370 /// else: what an *export* writes is every lane on the timeline
371 /// ([`engine::export`]), which this pick has no say in. Not saved -- a
372 /// `.edith` has no line for it yet.
373 ///
374 /// A [`Lane`] handle is a position among its kind, so a removal or a
375 /// reorder leaves a pick naming another track: it is dropped there,
376 /// exactly as the selection and the open cards are ([`Player::remove_lane`],
377 /// [`Player::reorder_lane`]), which shows the first lane again.
378 sub_lane: Option<Lane>,
379 /// The frame the live gesture is about to land on, or `None` while it is
380 /// over open bed: the line every lane draws so the snap is seen before it
381 /// happens rather than discovered after the release. Stale between gestures,
382 /// which costs nothing -- it is drawn only while one is live.
383 snap_cue: Option<u32>,
384 /// The box the same gesture is about to fill, or `None` while the pointer is
385 /// over no lane: the shadow every proper editor draws under a drag. Set by
386 /// the lane the pointer is actually over -- that is the one question the
387 /// line above does not answer -- and drawn only while a drag is live, for
388 /// [`Player::snap_cue`]'s reason.
389 ghost: Option<Ghost>,
390 /// The slot a track header being dragged is about to drop into, or `None`
391 /// while the pointer is over no lane: the line drawn between two headers,
392 /// for the reason [`Player::ghost`] draws a shadow -- where a gesture lands
393 /// is seen before the release. Drawn only while a drag is live.
394 lane_drop: Option<LaneDrop>,
395 last_scrub: Instant,
396 last_target: u32,
397 /// The running export. While it owns the UI the editor is read-only.
398 export: Option<ExportHandle>,
399 /// The export above was cancelled and is only winding down. The editor is
400 /// already free -- the worker took its own copy of the edit list -- but the
401 /// handle is held until the worker settles, because its last act is to
402 /// delete the output file and a second export must not be what it deletes.
403 cancelling: bool,
404 /// The pointer asked to cancel and the progress card is showing the pair
405 /// that answers it ("Keep exporting" / "Cancel export"). One press is never
406 /// the cancel itself: an hour of encoding must not end on a stray click,
407 /// which is the reason the stroke is a chord too ([`cancels_export`]).
408 cancel_armed: bool,
409 /// When the running export started, and how far it had come at each sample
410 /// since, as `(elapsed, progress)` marks. The elapsed clock and the
411 /// rolling-window estimate the progress line reads; see [`note_progress`].
412 export_started: Option<Instant>,
413 export_marks: Vec<(f32, f32)>,
414 /// The file an import worker is reading right now, and the files waiting
415 /// behind it in arrival order. Unlike an export, an import owns nothing:
416 /// the editor stays live, the timeline keeps playing, and the only thing
417 /// this holds is the line above the panel ([`Player::import_bar`]).
418 importing: Option<Import>,
419 imports: std::collections::VecDeque<PathBuf>,
420 /// The file argv named, until its read lands. It goes through the queue
421 /// above like any other file -- that is what puts the window on screen
422 /// before a byte of a 25 GB film is read -- and this is what tells
423 /// [`Player::take_import`] that this one is an *open* and not an import:
424 /// it becomes the timeline, and the clock, the title and the export path
425 /// come from it. Cleared the moment it lands, so a later drop of the very
426 /// same path is an import like any other.
427 opening: Option<PathBuf>,
428 /// Where an export writes. Built once from the source path, which is not
429 /// otherwise kept.
430 export_path: PathBuf,
431 /// Where the save action writes: the project this timeline was loaded from,
432 /// or the one derived beside the media it started as. Saving twice
433 /// overwrites the same file rather than making a second one.
434 project_path: PathBuf,
435 /// Whether an edit has landed since the sidecar last caught up with it --
436 /// set at every edit's own door ([`Player::mark_dirty`]) and cleared once
437 /// [`Player::autosave_tick`] has written it out. `project_path` itself is
438 /// never touched here: only [`Player::save_project`] writes the real file.
439 autosave_dirty: bool,
440 /// When the dirty flag above was last set, so a tick can debounce: a
441 /// sidecar write waits until the hand has been off the timeline for a
442 /// few seconds, rather than chasing every pointer sample of a drag.
443 autosave_last_edit: Option<Instant>,
444 /// When the sidecar was last actually written, so a long unbroken run of
445 /// edits still gets caught by the periodic safety net rather than being
446 /// debounced forever.
447 autosave_last_run: Option<Instant>,
448 /// A sidecar found newer than the project it sits beside, offered on the
449 /// notice bar the moment that project opens ([`Player::install_project`]).
450 /// The path is the sidecar's own, so accepting it needs nowhere else to
451 /// look; declining or answering any other key just drops it here --
452 /// `project_path` is never touched by either path, only a manual save
453 /// writes the real file.
454 recovery_sidecar: Option<PathBuf>,
455 /// Whether `project_path` names a file this window itself put there --
456 /// loaded from a `.edith` ([`Player::install_project`]) or written by a
457 /// manual save ([`Player::save_project`]) -- rather than one merely
458 /// derived beside an imported media file. [`Player::autosave_tick`]
459 /// requires it: a path derived from `media.mp4` names `media.edith`
460 /// whether or not that file is the user's own saved project, and writing
461 /// a sidecar beside a *foreign* `.edith` the user never opened is what
462 /// let a scratch timeline's autosave outdate and "recover" over a real
463 /// one. `mark_dirty` does not touch this -- an edit earns nothing an open
464 /// or save has not already granted.
465 autosave_armed: bool,
466 /// Which stroke means what, and what every shortcut on screen is called.
467 /// The one place either question is answered.
468 keymap: Keymap,
469 /// How loud the monitoring is, and whether it is muted. Lives here rather
470 /// than in the session so it survives closing one file and opening the
471 /// next -- it is a setting of the player, not of the timeline, which is
472 /// also why it is not written to the project file and cannot reach an
473 /// export. [`Player::apply_volume`] is what pushes it at a session.
474 volume: Volume,
475 /// Where the volume slider was last painted, and whether a hand is on it --
476 /// the speed bar's pair, for the speed bar's reason: the pointer moves
477 /// arrive at the root, so the bar's own geometry has to be readable there.
478 volume_bar: Rc<Cell<Bounds<Pixels>>>,
479 volume_dragging: bool,
480 /// Where the preview's own seek bar was last painted, and whether a hand
481 /// is on it -- `volume_bar`'s pair and `scrubbing`'s reason: the bar
482 /// spans the preview's whole length rather than a zoomed [`Scale`], so
483 /// it needs no `ruler` of its own, only its geometry.
484 preview_bar: Rc<Cell<Bounds<Pixels>>>,
485 preview_scrubbing: bool,
486 /// The two stand-in switches ([`engine::proxy`]) as this window has them
487 /// set: whether the picture is cut on the stand-ins, and whether an
488 /// arriving film gets one made for it. Kept here for the volume's reason
489 /// and one more of their own -- they are *import* options, so they have to
490 /// be settable before there is any import to have a session about.
491 ///
492 /// The session's own pair is the project's (it is saved with it): these are
493 /// pushed at every new one ([`Player::apply_proxies`]) and taken back from
494 /// a project as it loads ([`Player::install_project`]), so the button, the
495 /// switch and the file cannot come to disagree. Their initial values are
496 /// the ones a fresh session comes up at.
497 proxies_on: bool,
498 auto_proxies_on: bool,
499 /// The keybindings overlay is up. While it is, it owns the keyboard and the
500 /// pointer: a stroke or a click meant for a row must not also cut the
501 /// timeline.
502 keys_open: bool,
503 /// What has been typed into the card's search box, which is the card's own
504 /// input exactly as the export card's digits are (nothing in it takes
505 /// focus, so the root's key handler is the field). Emptied every time the
506 /// card opens: a search is a look at the list, not a setting.
507 keys_search: String,
508 /// Where that list is scrolled to. Held here rather than left to the
509 /// wheel alone: forty actions are four times what a 360 px window shows,
510 /// and the rows past the fold have to be reachable from the keyboard that
511 /// is already typing in the search box.
512 keys_scroll: ScrollHandle,
513 /// Where the lane column and the inspector's rows have been taken to. Read
514 /// back at render, not only written by the wheel: the line each of them
515 /// carries about what is below the fold is a count of what is *still* below
516 /// it, and a scroll that nothing reads is a scroll the affordance cannot
517 /// follow.
518 lanes_scroll: ScrollHandle,
519 inspector_scroll: ScrollHandle,
520 /// And where the equalizer card's own body has been taken to. It is the
521 /// tallest card in the column -- a graph with a row of numbers and a row of
522 /// buttons under it -- and at the 360 px floor its title and its buttons
523 /// were off both ends of the column with no way to reach them.
524 eq_scroll: ScrollHandle,
525 /// The export options card is up: what the export action opens now, so
526 /// nothing is written until the card's own button says so. One card at a
527 /// time -- opening either closes the other, since both are the whole window
528 /// and two stacked scrims say nothing about which one is listening.
529 export_open: bool,
530 /// How the card lays its rows out, and where the formats this program
531 /// cannot write are said. Two shapes of the same card, kept behind `g` and
532 /// `r` so the choice between them can be made by looking at both rather
533 /// than by argument: sections with headers against one flat list, and a
534 /// collapsed "cannot write" footer against a dimmed row each. The defaults
535 /// are grouped and collapsed -- the five dead rows used to eat the fold.
536 /// Not persisted: this is a look, not a setting.
537 export_grouped: bool,
538 export_refusals_inline: bool,
539 /// Whether the card's Advanced pane -- codec, container, quality,
540 /// sound, encoder, subtitles, this machine -- is open under the primary
541 /// pane's destination and preset rows. Closed by default: most exports
542 /// are one of the bundled presets, and the fifteen-odd rows under them
543 /// are what a person who is not one of those goes looking for, kept
544 /// behind one row rather than eaten by the fold. Not persisted, like the
545 /// two switches above it -- this is a look, not a setting.
546 export_advanced_open: bool,
547 /// Which quality row the card has picked, and the megabits typed against
548 /// the custom one. Kept across closes, so a second export offers what the
549 /// first one chose.
550 quality: Quality,
551 custom_mbps: u32,
552 /// The custom row's number *while it is being typed*, or `None` when nobody
553 /// is typing one. A field with a caret in it and not a key capture: digits
554 /// used to change the bitrate from anywhere in the card, with no caret to
555 /// say where they were landing and nothing to look at before the number
556 /// took effect. Nothing in this card takes gpui focus (the root keeps the
557 /// keyboard), so the field is a modal state on the player exactly as a
558 /// waiting rebind row is, and the root's handler is what types into it.
559 mbps_edit: Option<NumberEdit>,
560 /// What the *sound* is coded at, in kbps, for every format that encodes it
561 /// -- the AAC inside a video export as much as an MP3. Kept across closes
562 /// like the picture's quality, and starts at the figure this program wrote
563 /// before the row existed ([`engine::export::DEFAULT_AUDIO_KBPS`]), so a
564 /// user who never touches the row gets the file they always got.
565 audio_kbps: u32,
566 /// Which file the card will write. Kept across closes like the quality, and
567 /// what [`Player::export_path`](Player) is named after.
568 format: Format,
569 /// The equalizer card is up on this clip -- the lane and index it was
570 /// opened on. Held rather than re-read from `selected` every paint because
571 /// the card is modal: while it is up nothing else can move an index, and
572 /// the one edit it makes (`set_eq`) moves none.
573 eq_open: Option<(Lane, usize)>,
574 /// The curve the card is showing, which is the clip's own or the flat
575 /// five-band default. Edited live and written at the clip once per gesture
576 /// ([`Player::commit_eq`]): the project's equalizer table is append-only, so
577 /// a write per pointer sample would be a table entry -- and an undo step --
578 /// per pixel.
579 eq_params: EqParams,
580 /// Which band the keyboard moves, and which one a drag is holding.
581 eq_band: usize,
582 /// A handle on the curve is being dragged. Tracked on the root like
583 /// `scrubbing`, for the same reason: a hand pulling a band to +12 dB runs
584 /// off the top of the graph long before it lets go.
585 eq_dragging: bool,
586 /// The curve box, recorded at prepaint: gpui hands a mouse listener the
587 /// window position only, so this is what a press and a drag are read
588 /// against ([`frac_along`], [`frac_down`]).
589 eq_graph: Rc<Cell<Bounds<Pixels>>>,
590 /// Whether the analyser is drawn behind the curve. On by default -- what
591 /// the curve is being *shaped against* is the point of drawing it -- and
592 /// off with one press for anyone who would rather read the curve alone.
593 /// Card state, not the project's: it changes nothing that plays.
594 eq_spectrum: bool,
595 /// The colour card is up on this clip -- the lane it is on and its index
596 /// there. `None` when it is closed, which is the only place that state
597 /// lives: the grade itself is the project's.
598 color_open: Option<(Lane, usize)>,
599 /// The speed card is up on this clip -- the lane it is on and its index
600 /// there, exactly as the colour card's handle is. `None` when it is closed;
601 /// the rate itself is the project's, so there is nothing else to hold.
602 speed_open: Option<(Lane, usize)>,
603 /// The speed bar's box, recorded at prepaint: a mouse listener is handed the
604 /// window position only, so this is what a press and a drag are read against
605 /// ([`frac_along`]).
606 speed_bar: Rc<Cell<Bounds<Pixels>>>,
607 /// The bar is being dragged. On the root like the colour card's, for the
608 /// same reason: the pointer leaves a 4 px bar on the first move.
609 speed_dragging: bool,
610 /// The rate the hand is on, held back because the worker still owes a frame
611 /// ([`Player::flush_drag`]). What the bar draws while it stands, so the
612 /// handle stays under the hand even though the picture has not caught up.
613 pending_speed: Option<Speed>,
614 /// The mix card is up: every audio track's own volume and the master
615 /// limiter, which are project settings and not any clip's -- so unlike the
616 /// four clip cards there is no handle to hold, only whether it is open.
617 mix_open: bool,
618 /// Which of its rows the arrow keys move -- a fader, the limiter's ceiling
619 /// or its switch. The card's own focus, since nothing in it takes gpui's
620 /// (ledger:182).
621 mix_field: usize,
622 /// The cue plate's own size, in force this session and kept in
623 /// `~/.config/edith/subtitle-style` beside the keybindings -- an
624 /// app-global preference like the theme, since export never burns
625 /// subtitles into the picture. [`SUB_TEXT`] is the default it opens at,
626 /// never the value read at paint; [`sub_line_h`](Player::sub_line_h) is
627 /// what preview.rs reads for the line height, derived from this.
628 sub_text: f32,
629 /// Which family the cue plate draws in, or the platform default with
630 /// nothing picked -- `None` calls no [`gpui::Styled::font_family`] at
631 /// all, which is what leaves the window's own choice in force.
632 sub_family: Option<String>,
633 /// The subtitle style card is up.
634 subtitle_style_open: bool,
635 /// Which of its rows the arrow keys move: 0 is the size stepper, every
636 /// row after it a family in [`Self::subtitle_fonts`]. The card's own
637 /// focus, since nothing in it takes gpui's (ledger:182).
638 subtitle_style_field: usize,
639 /// Every family the platform can draw, asked for once when the card
640 /// opens and kept for as long as it is up: [`gpui::TextSystem::all_font_names`]
641 /// walks the whole font registry, which is not a repaint's business.
642 subtitle_fonts: Vec<String>,
643 /// The silence card is up on this clip -- the lane it is on and its index
644 /// there, exactly as the speed card's handle is.
645 silence_open: Option<(Lane, usize)>,
646 /// What a scan is told to look for, and how fast the speed-up button plays
647 /// what it found. Kept across closes like the export card's quality: a
648 /// second run offers what the first one settled on.
649 silence: engine::silence::Settings,
650 silence_factor: Speed,
651 /// How wide the apply reaches ([`Scope`]). Kept across closes for the same
652 /// reason, and never *widened* on anyone's behalf: the whole point of it is
653 /// that a track nobody named does not move.
654 silence_scope: Scope,
655 /// Which of the card's [`SILENCE_ROWS`] the arrow keys move. The card's own
656 /// focus, since nothing in it takes gpui's (ledger:182).
657 silence_field: usize,
658 /// Whether the threshold is *labelled* dBFS or dB. Display only, and the
659 /// number is the same either way: the setting is a level below full scale,
660 /// so 0 is the loudest sample a file can hold and -40 is forty decibels
661 /// under it -- "dBFS" names that reference out loud, "dB" leaves it unsaid.
662 /// No conversion is hiding behind the row (there is no reference here worth
663 /// inventing, and a made-up SPL would be a lie about what was measured);
664 /// what it changes is which of the two spellings a person reads.
665 silence_dbfs: bool,
666 /// What the last scan found, in timeline frames: what the lane draws marks
667 /// over and what an apply acts on -- *exactly* the previewed set, never a
668 /// second scan at the moment of the press.
669 silence_marks: Vec<(u32, u32)>,
670 /// The levels of every stretch scanned this session, kept so moving a
671 /// threshold is arithmetic rather than another decode. Keyed by
672 /// [`ScanKey`], and not one entry: two films on one timeline would
673 /// otherwise evict each other, and the decode being paid twice is the fifty
674 /// seconds this card exists to not spend.
675 silence_levels: HashMap<ScanKey, Arc<Vec<f32>>>,
676 /// The scan a worker is running for the card, if one is. `None` means the
677 /// card is drawing numbers it already has.
678 silence_scan: Option<SilenceScan>,
679 /// Whole-source background scans in flight, keyed the same as
680 /// [`Self::silence_levels`]'s own whole-source entries
681 /// ([`full_scan_key`]). Started at import ([`Player::cache_media`]) so a
682 /// card opened later finds the levels already read; presence here is what
683 /// stops a re-add of the same source from starting a second one, and its
684 /// [`engine::silence::Progress::cancel`] is what a removed source is told.
685 silence_bg: HashMap<(PathBuf, usize), Arc<engine::silence::Progress>>,
686 /// Which of the card's four sliders the arrow keys and a drag move. The
687 /// card's own focus, since nothing in it takes gpui's (ledger:182).
688 color_band: usize,
689 /// A slider is being dragged. Tracked on the root like `scrubbing` and the
690 /// equalizer's drag, for the same reason: a 4 px bar is left by the pointer
691 /// on the first move and its own listeners then stop firing.
692 color_dragging: bool,
693 /// Each slider's box, recorded at prepaint: a mouse listener is handed the
694 /// window position only, so this is what a press and a drag are read against
695 /// ([`frac_along`]). One per band, because the press picks the row it landed
696 /// on and the drag then belongs to that row's range.
697 color_bars: [Rc<Cell<Bounds<Pixels>>>; COLOR_BANDS.len()],
698 /// The grade the hand is on, held back because the worker still owes a
699 /// frame ([`Player::flush_drag`]): a live write into a busy worker only
700 /// cancels the open the picture is already waiting for, so a bar-wide sweep
701 /// would pay for forty of them and show one. What the sliders draw while it
702 /// stands, and never lost -- the frame that lands writes it, and so does the
703 /// release.
704 pending_color: Option<ColorParams>,
705 /// The transform card is up on this clip -- the lane it is on and its
706 /// index there, exactly as the colour card's handle is. `None` when it is
707 /// closed: the placement itself is the project's.
708 transform_open: Option<(Lane, usize)>,
709 /// Which of the card's eight sliders the arrow keys and a drag move. The
710 /// card's own focus, since nothing in it takes gpui's (ledger:182).
711 transform_band: usize,
712 /// A slider is being dragged. Tracked on the root like the colour card's,
713 /// for the same reason: a 4 px bar is left by the pointer on the first
714 /// move and its own listeners then stop firing.
715 transform_dragging: bool,
716 /// Each slider's box, recorded at prepaint -- [`Self::color_bars`]' own
717 /// reason, one per band.
718 transform_bars: [Rc<Cell<Bounds<Pixels>>>; TRANSFORM_BANDS.len()],
719 /// The placement the hand is on, held back because the worker still owes a
720 /// frame -- [`Self::pending_color`]'s own reason.
721 pending_transform: Option<TransformParams>,
722 /// The frame on screen counted into `HIST_BINS` bins per channel -- the
723 /// *graded* frame, because the grade is applied in the decode worker and
724 /// what arrives here is already through it. Refilled by every pumped frame,
725 /// which is what makes the colour card's graph move as a slider is dragged:
726 /// each live write reseeks, and the reseek's frame is the next count.
727 histogram: [[u32; HIST_BINS]; 3],
728 /// The action whose row is waiting for a stroke. The next key that is
729 /// neither escape nor a lone modifier becomes the whole of what reaches it.
730 rebinding: Option<ActionId>,
731 /// What the file actions have had to say, oldest first. A *queue* and not a
732 /// slot: two imports that fail back to back used to be one message, because
733 /// the second overwrote the first before a frame had drawn it -- the failure
734 /// a user never learns about is the one that was answered by another
735 /// failure. The front holds its own bar above the panel until it is answered
736 /// -- any key retires it, so does a click on it -- the bar says how many are
737 /// behind it, and answering it brings the next one up.
738 notices: std::collections::VecDeque<SharedString>,
739 /// How tall the transient bars hanging off the bottom of the picture (the
740 /// import line, the seek line, the notice) came out at prepaint, so the cue
741 /// plate can sit clear of them ([`sub_bottom`]). Measured and not counted:
742 /// a notice wraps to as many lines as the window is narrow.
743 notice_h: Rc<Cell<Pixels>>,
744 /// What the last finished export wrote, so the notice can be the way to it.
745 /// Only the [`EXPORT_DONE`] line reads it -- any later notice has replaced
746 /// that text -- so a click never opens a file the bar is not naming.
747 exported: Option<PathBuf>,
748 /// What the compositor was last told this window is called. Setting a title
749 /// is a protocol round trip and a repaint is sixty a second, so the title is
750 /// pushed only when it is not this any more.
751 titled: String,
752 displayed: u32,
753 dropped: u32,
754 /// When the picture was last restarted at the clock for falling behind it
755 /// ([`should_resync`]). The cool-down's only state.
756 resynced: Option<Instant>,
757 /// Wall clock of the first displayed frame -- the real-speed measurement.
758 started: Option<Instant>,
759 focus: FocusHandle,
760}
761
762#[cfg(test)]
763mod tests;
764
765fn main() {
766 // A keymap file that cannot be read leaves the defaults in force, and takes
767 // the notice slot ahead of an open or import refusal: it is about every key
768 // the window has, and those refusals are on stderr either way.
769 let (keymap, notice) = Keymap::load();
770 if let Some(text) = &notice {
771 eprintln!("{text}");
772 }
773 // The palette the last session picked, before the first paint: a window that
774 // opened cool and turned warm a frame later would be the theme announcing
775 // itself. Silent on a missing or unreadable file -- the default is a whole
776 // answer, and nothing of the user's is lost by it.
777 ui::theme::load();
778 // DESIGN.md §1: "the room is the film's" -- darkroom mode owns the
779 // palette outright, so the saved pick above is overridden the moment the
780 // flag is read, once, before the first paint.
781 //
782 // Darkroom is the default room now (user order: "make darkroom default
783 // no need to pass environment"). `OLD_GUI=1` (any case) is the one door
784 // back into the legacy four-region tree -- `EDITH_DARKROOM` opted IN to
785 // the new room; this opts OUT of it, which is why the sense of the read
786 // below is inverted rather than the flag renamed in place.
787 let old_gui = std::env::vars()
788 .find(|(k, _)| k.eq_ignore_ascii_case("OLD_GUI"))
789 .is_some_and(|(_, v)| v.eq_ignore_ascii_case("1"));
790 let darkroom = !old_gui;
791 if darkroom {
792 ui::theme::set(ui::theme::PaletteId::Darkroom);
793 }
794 // The subtitle style the last session picked, same silence on a missing
795 // or unreadable file.
796 let (sub_family, sub_text) = load_subtitle_style();
797 // Nothing named on the command line is read here. The first file makes the
798 // timeline -- a `.edith` restores a whole one, anything else *is* one --
799 // and the rest are imports like any other: rows in the library, dragged
800 // onto a lane when they are wanted there. All of them go through the queue
801 // a drop uses ([`Player::import`]), which is the door with a progress line
802 // on it, and their refusals arrive in the notice bar as a drop's do.
803 //
804 // Queued rather than opened because a 25 GB film cold is twelve seconds of
805 // header walk, and it used to be twelve seconds of *no window at all* -- a
806 // window that has not opened cannot say what it is waiting for. Now the
807 // window is up in the time it takes to make one, naming the file and the
808 // read that is running, and the timeline appears when that read lands
809 // ([`Player::take_import`]).
810 //
811 // No argument at all opens the window empty, exactly as before: the library
812 // then arrives by drop or by the Import button.
813 let (arg, queue) = launch_queue(std::env::args().skip(1).map(PathBuf::from));
814 let name: SharedString = arg
815 .as_deref()
816 .map_or_else(|| NO_FILE.into(), |arg| file_name(arg).into());
817
818 Application::new().run(move |cx: &mut App| {
819 // Bundled Archivo / Spline Sans Mono, before the first paint --
820 // DESIGN §3's two faces, embedded so no build depends on the host
821 // having them installed (see `ui::type_scale`'s doc comment).
822 ui::type_scale::register(cx);
823 // 720p: the picture's own size is not known yet -- knowing it is the
824 // twelve seconds this window exists to be up during -- and a window
825 // that resized itself under a hand already dragging it would be worse
826 // than one that opened at the size the empty window has always used.
827 let bounds = Bounds::centered(None, size(px(1280.), px(720.)), cx);
828 cx.open_window(
829 WindowOptions {
830 window_bounds: Some(WindowBounds::Windowed(bounds)),
831 titlebar: Some(TitlebarOptions {
832 title: Some("edith".into()),
833 ..Default::default()
834 }),
835 // What a desktop groups this window under. The title beside it
836 // is pushed from the render, because wayland takes neither of
837 // them from the titlebar options above (gpui's wayland window
838 // reads only `app_id`, window.rs:1202 / window.rs:939) and the
839 // title has to follow the file being opened anyway.
840 app_id: Some("edith".to_string()),
841 ..Default::default()
842 },
843 |window, cx| {
844 let queue = queue.clone();
845 let player = cx.new(|cx| Player {
846 darkroom,
847 // Nothing to wait for yet: the file named on the command
848 // line is still queued, and the repaint that carries its
849 // poster frame to the screen is asked for when it lands
850 // (`open_media` -> `reset_after_reseek`).
851 seek_since: None,
852 resynced: None,
853 session: None,
854 pending_settings: (None, None, None),
855 preview_session: None,
856 preview_playing: false,
857 player_fullscreen: false,
858 loop_on: false,
859 range: None,
860 loop_trim: None,
861 // Full and unmuted, which is what the session it was just
862 // handed is already set to: nothing to push at startup.
863 volume: Volume::default(),
864 volume_bar: Rc::default(),
865 preview_bar: Rc::default(),
866 preview_scrubbing: false,
867 volume_dragging: false,
868 // What a session comes up at, so the first one opened is
869 // pushed the values it already holds.
870 proxies_on: false,
871 auto_proxies_on: true,
872 // Only ever used with a timeline; 30 keeps the empty
873 // timecode reading in frames rather than in NaN.
874 fps: 30.,
875 ruler: Rc::default(),
876 scroll_track: Rc::default(),
877 scroll_drag: None,
878 lanes_drag: None,
879 // draws: the title bar and the header name it while its
880 // header is still being read.
881 name: name.clone(),
882 image: None,
883 sub_image: None,
884 held: None,
885 notice_h: Rc::default(),
886 // A second is [`PPS_DEFAULT`] pixels wide until someone
887 // zooms or asks for the fit: a project opens at a scale, not
888 // at whatever its first import happens to be long.
889 scale: Scale::default(),
890 // Nobody has scrolled anything yet, so the follow has the
891 // view: the first frame is drawn where the head is.
892 panned: false,
893 selected: Selection::new(),
894 context_menu: None,
895 picker: None,
896 library_menu: None,
897 selected_asset: None,
898 library_tab: LibraryTab::Media,
899 dock_src_active: ui::dock_stance::load(),
900 dock_filter: String::new(),
901 dock_filter_edit: false,
902 dock_sort: ui::dock_stance::DockSort::Recent,
903 waves: HashMap::new(),
904 thumbs: HashMap::new(),
905 proxies: HashMap::new(),
906 streams: HashMap::new(),
907 bitrates: HashMap::new(),
908 sizes: HashMap::new(),
909 syncs: HashMap::new(),
910 decoders: HashMap::new(),
911 export_seat: None,
912 hw_caps: None,
913 clipboard: None,
914 scrubbing: false,
915 splits: Splits::default(),
916 split_drag: None,
917 trim: None,
918 fade_drag: None,
919 grab: 0,
920 snap: true,
921 subs_on: true,
922 sub_track: 0,
923 sub_folded: HashSet::new(),
924 sub_lane: None,
925 snap_cue: None,
926 ghost: None,
927 lane_drop: None,
928 last_scrub: Instant::now(),
929 last_target: 0,
930 export: None,
931 cancelling: false,
932 cancel_armed: false,
933 export_started: None,
934 export_marks: Vec::new(),
935 // Both derived from the file when it lands, by the same
936 // `open_media`/`load_project` a drop goes through: an
937 // export beside the picture, a save beside it too.
938 export_path: PathBuf::new(),
939 project_path: PathBuf::new(),
940 autosave_dirty: false,
941 autosave_last_edit: None,
942 autosave_last_run: None,
943 recovery_sidecar: None,
944 autosave_armed: false,
945 keymap: keymap.clone(),
946 keys_open: false,
947 keys_search: String::new(),
948 keys_scroll: ScrollHandle::new(),
949 lanes_scroll: ScrollHandle::new(),
950 inspector_scroll: ScrollHandle::new(),
951 eq_scroll: ScrollHandle::new(),
952 export_open: false,
953 export_grouped: true,
954 export_refusals_inline: false,
955 export_advanced_open: false,
956 eq_open: None,
957 // Replaced by the clip's own curve the moment the card
958 // opens; nothing reads it before that.
959 eq_params: EqParams::default(),
960 eq_band: 0,
961 eq_dragging: false,
962 eq_graph: Rc::default(),
963 eq_spectrum: true,
964 speed_open: None,
965 speed_bar: Rc::default(),
966 speed_dragging: false,
967 pending_speed: None,
968 mix_open: false,
969 mix_field: 0,
970 sub_text,
971 sub_family,
972 subtitle_style_open: false,
973 subtitle_style_field: 0,
974 subtitle_fonts: Vec::new(),
975 silence_open: None,
976 // The conservative defaults the engine documents: a first
977 // scan that leaves a little too much is one nobody undoes.
978 silence: engine::silence::Settings::default(),
979 silence_factor: Speed::MAX,
980 // The take, not the timeline: the narrower answer is the
981 // one a person can widen on purpose.
982 silence_scope: Scope::Take,
983 silence_field: 0,
984 // The reference named, which is what the card said before
985 // there was a choice about it.
986 silence_dbfs: true,
987 silence_marks: Vec::new(),
988 silence_levels: HashMap::new(),
989 silence_scan: None,
990 silence_bg: HashMap::new(),
991 color_open: None,
992 color_band: 0,
993 color_dragging: false,
994 color_bars: std::array::from_fn(|_| Rc::default()),
995 pending_color: None,
996 transform_open: None,
997 transform_band: 0,
998 transform_dragging: false,
999 transform_bars: std::array::from_fn(|_| Rc::default()),
1000 pending_transform: None,
1001 // Empty until the first frame is pumped, which draws as a
1002 // flat line rather than as a shape nothing measured.
1003 histogram: [[0; HIST_BINS]; 3],
1004 // What an export is until someone says otherwise: the Web
1005 // bundle, so `ExportPreset::from_state` opens on a real
1006 // preset rather than a `Custom` nobody picked -- `Auto`
1007 // paired with `Format::default()`'s MP4 matched no bundle
1008 // at all.
1009 quality: Quality::Medium,
1010 custom_mbps: 0,
1011 mbps_edit: None,
1012 // ...and the rate the sound has always been written at.
1013 audio_kbps: DEFAULT_AUDIO_KBPS,
1014 // Picture and sound, which is what an export was before
1015 // there was anything to pick.
1016 format: Format::default(),
1017 rebinding: None,
1018 notices: notice.clone().map(SharedString::from).into_iter().collect(),
1019 exported: None,
1020 // The whole of argv, waiting for the first repaint to start
1021 // it: the window is up before a byte of it is read.
1022 importing: None,
1023 imports: queue,
1024 opening: arg.clone(),
1025 // Nothing pushed yet, and never a real title: the first
1026 // render is what names the window.
1027 titled: String::new(),
1028 displayed: 0,
1029 dropped: 0,
1030 started: None,
1031 focus: cx.focus_handle(),
1032 });
1033 // Nothing else takes focus, and without it the key listener
1034 // above is never reached.
1035 window.focus(&player.read(cx).focus);
1036 player.update(cx, |player, cx| player.start_autosave(cx));
1037 player
1038 },
1039 )
1040 .unwrap();
1041 cx.activate(true);
1042 });
1043}