The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
Format the workspace and check it in CI
Jareerc56424e92de2
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 67c1848c..18a8483f 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -47,6 +47,8 @@ jobs:echo "FFMPEG_DIR=$PWD/ffmpeg-dev" >> "$GITHUB_ENV"echo "LD_LIBRARY_PATH=$PWD/ffmpeg-dev/lib" >> "$GITHUB_ENV"+ - run: cargo fmt --check+ working-directory: engine- run: cargo test --workspaceworking-directory: engine# -D warnings covers rustc lints too (missing_docs among them), so adiff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 6c62544c..afad0e2d 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -376,8 +376,7 @@ tests, which is fine.- **Zero TODO/FIXME/HACK comments** in the tree. Invariants live in prosecomments instead; keep it that way.-- `cargo fmt --check` is not enforced in CI. Run it across the workspace- once and add it to `ci.yml`.+- `cargo fmt --check` runs in CI; keep it clean.---diff --git a/engine/crates/concat-project/src/commands.rs b/engine/crates/concat-project/src/commands.rsindex 8bc65154..90a389f9 100644--- a/engine/crates/concat-project/src/commands.rs+++ b/engine/crates/concat-project/src/commands.rs@@ -12,8 +12,8 @@ use std::collections::HashSet;use serde::{Deserialize, Serialize};use crate::model::{- AppliedFilter, Clip, ClipKind, CustomFont, MediaItem, MediaKind, Project, TextStyle,- Timeline, Track, Transition,+ AppliedFilter, Clip, ClipKind, CustomFont, MediaItem, MediaKind, Project, TextStyle, Timeline,+ Track, Transition,};/// Fallback length for media whose container reports no duration.@@ -95,11 +95,19 @@ pub struct ClipPatch {pub video_effects: Option<Vec<AppliedFilter>>,/// The transition on the cut into the clip: absent leaves it alone,/// null clears it, a value replaces it.- #[serde(default, with = "double_option", skip_serializing_if = "Option::is_none")]+ #[serde(+ default,+ with = "double_option",+ skip_serializing_if = "Option::is_none"+ )]pub transition_in: Option<Option<Transition>>,/// The title styling, same three-way wire semantics as `transition_in`./// Setting a style also renames the clip after its first line.- #[serde(default, with = "double_option", skip_serializing_if = "Option::is_none")]+ #[serde(+ default,+ with = "double_option",+ skip_serializing_if = "Option::is_none"+ )]pub text: Option<Option<TextStyle>>,}@@ -565,7 +573,11 @@ fn first_line(content: &str) -> String {.unwrap_or("Text").trim();let label: String = line.chars().take(40).collect();- if label.is_empty() { "Text".to_owned() } else { label }+ if label.is_empty() {+ "Text".to_owned()+ } else {+ label+ }}/// "Track 5" from the highest number already in use, not from the count.@@ -641,7 +653,11 @@ pub fn apply() -> Result<Outcome, CommandError> {match command {Command::AddMedia { item } => {- if project.media.iter().any(|existing| existing.path == item.path) {+ if project+ .media+ .iter()+ .any(|existing| existing.path == item.path)+ {return Ok(Outcome::default());}let id = mint.next("m");@@ -660,16 +676,25 @@ pub fn apply(has_audio: item.has_audio,placeholder: false,});- Ok(Outcome { created_id: Some(id), applied: true })+ Ok(Outcome {+ created_id: Some(id),+ applied: true,+ })}- Command::SetMediaPlaceholder { media_id, placeholder } => {+ Command::SetMediaPlaceholder {+ media_id,+ placeholder,+ } => {let applied = project.media.iter_mut().find(|item| item.id == media_id).is_some_and(|item| assign(&mut item.placeholder, placeholder));- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}Command::FillSlot { media_id, item } => {@@ -719,7 +744,10 @@ pub fn apply(}// Filling always changes the project: the target was a// placeholder and is one no longer.- Ok(Outcome { created_id: None, applied: true })+ Ok(Outcome {+ created_id: None,+ applied: true,+ })}Command::Batch { commands } => {@@ -737,7 +765,10 @@ pub fn apply(applied |= outcome.applied;}*project = staged;- Ok(Outcome { created_id: created, applied })+ Ok(Outcome {+ created_id: created,+ applied,+ })}Command::RemoveMedia { media_id } => {@@ -751,10 +782,17 @@ pub fn apply(timeline.clips.retain(|clip| clip.media_id != media_id);applied |= timeline.clips.len() != clip_count;}- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}- Command::AddClip { media_id, track_id, start } => {+ Command::AddClip {+ media_id,+ track_id,+ start,+ } => {let media = project.media_by_id(&media_id).ok_or(CommandError::MediaGone)?@@ -764,8 +802,13 @@ pub fn apply(return Err(CommandError::TrackGone);}let id = mint.next("c");- timeline.clips.push(default_clip(id.clone(), track_id, &media, start));- Ok(Outcome { created_id: Some(id), applied: true })+ timeline+ .clips+ .push(default_clip(id.clone(), track_id, &media, start));+ Ok(Outcome {+ created_id: Some(id),+ applied: true,+ })}Command::AddClipAtFirstFree { media_id, start } => {@@ -781,19 +824,33 @@ pub fn apply(let track_id =first_free_track(timeline, start, duration).ok_or(CommandError::NoTracks)?;let id = mint.next("c");- timeline.clips.push(default_clip(id.clone(), track_id, &media, start));- Ok(Outcome { created_id: Some(id), applied: true })+ timeline+ .clips+ .push(default_clip(id.clone(), track_id, &media, start));+ Ok(Outcome {+ created_id: Some(id),+ applied: true,+ })}- Command::AddTextClip { track_id, start, style, duration, offset_y } => {+ Command::AddTextClip {+ track_id,+ start,+ style,+ duration,+ offset_y,+ } => {let style = style.unwrap_or_default();- let duration = duration.unwrap_or(DEFAULT_TEXT_DURATION).max(MIN_CLIP_DURATION);+ let duration = duration+ .unwrap_or(DEFAULT_TEXT_DURATION)+ .max(MIN_CLIP_DURATION);let timeline = project.active_mut();let track_id = match track_id {Some(id) if timeline.track(&id).is_some() => id,Some(_) => return Err(CommandError::TrackGone),- None => first_free_track(timeline, start, duration)- .ok_or(CommandError::NoTracks)?,+ None => {+ first_free_track(timeline, start, duration).ok_or(CommandError::NoTracks)?+ }};let id = mint.next("c");timeline.clips.push(Clip {@@ -822,13 +879,19 @@ pub fn apply(transition_in: None,text: Some(style),});- Ok(Outcome { created_id: Some(id), applied: true })+ Ok(Outcome {+ created_id: Some(id),+ applied: true,+ })}Command::MoveClips { moves } => {let timeline = project.active_mut();- let track_ids: HashSet<String> =- timeline.tracks.iter().map(|track| track.id.clone()).collect();+ let track_ids: HashSet<String> = timeline+ .tracks+ .iter()+ .map(|track| track.id.clone())+ .collect();let mut applied = false;for wanted in moves {if let Some(clip) = timeline.clip_mut(&wanted.clip_id) {@@ -838,10 +901,17 @@ pub fn apply(}}}- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}- Command::TrimClip { clip_id, edge, delta } => {+ Command::TrimClip {+ clip_id,+ edge,+ delta,+ } => {let timeline = project.active_mut();let Some(clip) = timeline.clip_mut(&clip_id) else {return Ok(Outcome::default());@@ -865,15 +935,17 @@ pub fn apply(| assign(&mut clip.source_start, source_start)}};- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}Command::SplitClips { clip_ids, time } => {let timeline = project.active_mut();let mut created = None;for clip_id in clip_ids {- let Some(index) = timeline.clips.iter().position(|clip| clip.id == clip_id)- else {+ let Some(index) = timeline.clips.iter().position(|clip| clip.id == clip_id) else {continue;};let clip = &timeline.clips[index];@@ -896,7 +968,10 @@ pub fn apply(// A split always mints the tail, so "minted anything" and// "changed anything" are the same fact here.let applied = created.is_some();- Ok(Outcome { created_id: created, applied })+ Ok(Outcome {+ created_id: created,+ applied,+ })}Command::MergeClips { clip_ids } => {@@ -904,8 +979,10 @@ pub fn apply(if let Some(reason) = why_not_merge(timeline, &clip_ids) {return Err(CommandError::CannotMerge { reason });}- let mut ordered: Vec<Clip> =- clip_ids.iter().filter_map(|id| timeline.clip(id).cloned()).collect();+ let mut ordered: Vec<Clip> = clip_ids+ .iter()+ .filter_map(|id| timeline.clip(id).cloned())+ .collect();ordered.sort_by(|left, right| left.start.total_cmp(&right.start));let first = ordered.first().expect("validated above").clone();let last = ordered.last().expect("validated above");@@ -916,20 +993,29 @@ pub fn apply(let doomed: HashSet<String> =ordered.iter().skip(1).map(|clip| clip.id.clone()).collect();timeline.clips.retain(|clip| !doomed.contains(&clip.id));- let survivor =- timeline.clip_mut(&first.id).expect("the first piece survives the retain");+ let survivor = timeline+ .clip_mut(&first.id)+ .expect("the first piece survives the retain");survivor.duration = merged_duration;// A validated merge always absorbs at least one piece.- Ok(Outcome { created_id: Some(first.id), applied: true })+ Ok(Outcome {+ created_id: Some(first.id),+ applied: true,+ })}Command::RemoveClips { clip_ids } => {let timeline = project.active_mut();let doomed: HashSet<&str> = clip_ids.iter().map(String::as_str).collect();let clip_count = timeline.clips.len();- timeline.clips.retain(|clip| !doomed.contains(clip.id.as_str()));+ timeline+ .clips+ .retain(|clip| !doomed.contains(clip.id.as_str()));let applied = timeline.clips.len() != clip_count;- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}Command::UpdateClip { clip_id, patch } => {@@ -972,7 +1058,10 @@ pub fn apply(}applied |= assign(&mut clip.text, text);}- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}Command::SetClipSpeed { clip_id, speed } => {@@ -986,11 +1075,23 @@ pub fn apply(let source_covered = clip.duration * clip.speed;// Bitwise so no assignment is short-circuited away.let applied = assign(&mut clip.speed, next)- | assign(&mut clip.duration, (source_covered / next).max(MIN_CLIP_DURATION));- Ok(Outcome { created_id: None, applied })+ | assign(+ &mut clip.duration,+ (source_covered / next).max(MIN_CLIP_DURATION),+ );+ Ok(Outcome {+ created_id: None,+ applied,+ })}- Command::SetClipTransform { clip_id, scale, offset_x, offset_y, rotation } => {+ Command::SetClipTransform {+ clip_id,+ scale,+ offset_x,+ offset_y,+ rotation,+ } => {let timeline = project.active_mut();let Some(clip) = timeline.clip_mut(&clip_id) else {return Ok(Outcome::default());@@ -1011,7 +1112,10 @@ pub fn apply(let next = if wrapped == -180.0 { 180.0 } else { wrapped };applied |= assign(&mut clip.rotation, next);}- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}Command::DetachAudio { clip_id } => {@@ -1079,7 +1183,10 @@ pub fn apply(let video = timeline.clip_mut(&clip_id).expect("still present");video.muted = Some(true);video.filters = Vec::new();- Ok(Outcome { created_id: Some(sound_id), applied: true })+ Ok(Outcome {+ created_id: Some(sound_id),+ applied: true,+ })}Command::ReattachAudio { clip_id } => {@@ -1111,16 +1218,29 @@ pub fn apply(video.muted = None;video.filters = sounds[0].filters.clone();// Reaching here means at least one sound clip was deleted.- Ok(Outcome { created_id: None, applied: true })+ Ok(Outcome {+ created_id: None,+ applied: true,+ })}Command::AddTrack => {let timeline = project.active_mut();let id = mint.next("t");- let name =- next_numbered("Track", timeline.tracks.iter().map(|track| track.name.clone()));- timeline.tracks.push(Track { id: id.clone(), name, visible: true, muted: false });- Ok(Outcome { created_id: Some(id), applied: true })+ let name = next_numbered(+ "Track",+ timeline.tracks.iter().map(|track| track.name.clone()),+ );+ timeline.tracks.push(Track {+ id: id.clone(),+ name,+ visible: true,+ muted: false,+ });+ Ok(Outcome {+ created_id: Some(id),+ applied: true,+ })}Command::RemoveTrack { track_id } => {@@ -1134,7 +1254,10 @@ pub fn apply(// Clips only ever sit on existing tracks, so an unknown id - the// tolerated no-op - removes neither.let applied = timeline.tracks.len() != track_count;- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}Command::RenameTrack { track_id, name } => {@@ -1148,10 +1271,17 @@ pub fn apply(.iter_mut().find(|track| track.id == track_id).is_some_and(|track| assign(&mut track.name, trimmed.to_owned()));- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}- Command::SetTrackFlag { track_id, flag, value } => {+ Command::SetTrackFlag {+ track_id,+ flag,+ value,+ } => {let timeline = project.active_mut();let applied = timeline.tracks@@ -1161,14 +1291,20 @@ pub fn apply(TrackFlag::Visible => assign(&mut track.visible, value),TrackFlag::Muted => assign(&mut track.muted, value),});- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}Command::AddTimeline => {let id = mint.next("tl");let name = next_numbered("Timeline",- project.timelines.iter().map(|timeline| timeline.name.clone()),+ project+ .timelines+ .iter()+ .map(|timeline| timeline.name.clone()),);let tracks = (1..=4).map(|number| Track {@@ -1178,26 +1314,43 @@ pub fn apply(muted: false,}).collect();- project.timelines.push(Timeline { id: id.clone(), name, tracks, clips: Vec::new() });+ project.timelines.push(Timeline {+ id: id.clone(),+ name,+ tracks,+ clips: Vec::new(),+ });project.active_timeline_id = id.clone();- Ok(Outcome { created_id: Some(id), applied: true })+ Ok(Outcome {+ created_id: Some(id),+ applied: true,+ })}Command::RemoveTimeline { timeline_id } => {if project.timelines.len() <= 1 {return Err(CommandError::LastTimeline);}- let Some(index) =- project.timelines.iter().position(|timeline| timeline.id == timeline_id)+ let Some(index) = project+ .timelines+ .iter()+ .position(|timeline| timeline.id == timeline_id)else {return Ok(Outcome::default());};if project.active_timeline_id == timeline_id {- let neighbour = if index + 1 < project.timelines.len() { index + 1 } else { index - 1 };+ let neighbour = if index + 1 < project.timelines.len() {+ index + 1+ } else {+ index - 1+ };project.active_timeline_id = project.timelines[neighbour].id.clone();}project.timelines.remove(index);- Ok(Outcome { created_id: None, applied: true })+ Ok(Outcome {+ created_id: None,+ applied: true,+ })}Command::RenameTimeline { timeline_id, name } => {@@ -1210,20 +1363,31 @@ pub fn apply(.iter_mut().find(|timeline| timeline.id == timeline_id).is_some_and(|timeline| assign(&mut timeline.name, trimmed.to_owned()));- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}Command::SelectTimeline { timeline_id } => {// Short-circuiting is right here: an unknown id must not touch// the selection at all.- let applied = project.timelines.iter().any(|timeline| timeline.id == timeline_id)+ let applied = project+ .timelines+ .iter()+ .any(|timeline| timeline.id == timeline_id)&& assign(&mut project.active_timeline_id, timeline_id);- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}Command::MoveTimeline { timeline_id, index } => {- let Some(from) =- project.timelines.iter().position(|timeline| timeline.id == timeline_id)+ let Some(from) = project+ .timelines+ .iter()+ .position(|timeline| timeline.id == timeline_id)else {return Ok(Outcome::default());};@@ -1233,7 +1397,10 @@ pub fn apply(}let timeline = project.timelines.remove(from);project.timelines.insert(to, timeline);- Ok(Outcome { created_id: None, applied: true })+ Ok(Outcome {+ created_id: None,+ applied: true,+ })}Command::AddFont { family, path } => {@@ -1241,7 +1408,10 @@ pub fn apply(return Ok(Outcome::default());}project.fonts.push(CustomFont { family, path });- Ok(Outcome { created_id: None, applied: true })+ Ok(Outcome {+ created_id: None,+ applied: true,+ })}Command::RemoveFont { family } => {@@ -1250,7 +1420,10 @@ pub fn apply(let font_count = project.fonts.len();project.fonts.retain(|font| font.family != family);let applied = project.fonts.len() != font_count;- Ok(Outcome { created_id: None, applied })+ Ok(Outcome {+ created_id: None,+ applied,+ })}}}diff --git a/engine/crates/concat-project/src/doc.rs b/engine/crates/concat-project/src/doc.rsindex f04320fa..6cfde28f 100644--- a/engine/crates/concat-project/src/doc.rs+++ b/engine/crates/concat-project/src/doc.rs@@ -21,8 +21,8 @@use serde_json::{Map, Value, json};use crate::model::{- AppliedFilter, Clip, ClipKind, CustomFont, MediaItem, MediaKind, Project, TextAlign,- TextStyle, Timeline, Track, Transition,+ AppliedFilter, Clip, ClipKind, CustomFont, MediaItem, MediaKind, Project, TextAlign, TextStyle,+ Timeline, Track, Transition,};/// Bumped only when a change cannot be absorbed by defaulting.@@ -33,7 +33,10 @@ fn text(value: Option<&Value>, fallback: &str) -> String {}fn number(value: Option<&Value>, fallback: f64) -> f64 {- value.and_then(Value::as_f64).filter(|n| n.is_finite()).unwrap_or(fallback)+ value+ .and_then(Value::as_f64)+ .filter(|n| n.is_finite())+ .unwrap_or(fallback)}fn flag(value: Option<&Value>, fallback: bool) -> bool {@@ -41,7 +44,9 @@ fn flag(value: Option<&Value>, fallback: bool) -> bool {}fn opt_u32(value: Option<&Value>) -> Option<u32> {- value.and_then(Value::as_u64).and_then(|n| u32::try_from(n).ok())+ value+ .and_then(Value::as_u64)+ .and_then(|n| u32::try_from(n).ok())}fn opt_string(value: Option<&Value>) -> Option<String> {@@ -49,7 +54,9 @@ fn opt_string(value: Option<&Value>) -> Option<String> {}fn read_media(raw: Option<&Value>) -> Vec<MediaItem> {- let Some(entries) = raw.and_then(Value::as_array) else { return Vec::new() };+ let Some(entries) = raw.and_then(Value::as_array) else {+ return Vec::new();+ };entries.iter().filter_map(|entry| {@@ -80,7 +87,9 @@ fn read_media(raw: Option<&Value>) -> Vec<MediaItem> {}fn read_tracks(raw: Option<&Value>) -> Vec<Track> {- let Some(entries) = raw.and_then(Value::as_array) else { return Vec::new() };+ let Some(entries) = raw.and_then(Value::as_array) else {+ return Vec::new();+ };entries.iter().filter_map(|entry| {@@ -96,7 +105,9 @@ fn read_tracks(raw: Option<&Value>) -> Vec<Track> {}fn read_filters(raw: Option<&Value>) -> Vec<AppliedFilter> {- let Some(entries) = raw.and_then(Value::as_array) else { return Vec::new() };+ let Some(entries) = raw.and_then(Value::as_array) else {+ return Vec::new();+ };entries.iter().filter_map(|entry| {@@ -110,14 +121,20 @@ fn read_filters(raw: Option<&Value>) -> Vec<AppliedFilter> {.collect()}).unwrap_or_default();- Some(AppliedFilter { id, params, enabled: flag(entry.get("enabled"), true) })+ Some(AppliedFilter {+ id,+ params,+ enabled: flag(entry.get("enabled"), true),+ })}).collect()}fn read_text_style(raw: Option<&Value>) -> TextStyle {let base = TextStyle::default();- let Some(style) = raw.filter(|value| value.is_object()) else { return base };+ let Some(style) = raw.filter(|value| value.is_object()) else {+ return base;+ };TextStyle {content: text(style.get("content"), &base.content),font_family: text(style.get("fontFamily"), &base.font_family),@@ -143,7 +160,9 @@ fn read_text_style(raw: Option<&Value>) -> TextStyle {}fn read_clips(raw: Option<&Value>, tracks: &[Track], media: &[MediaItem]) -> Vec<Clip> {- let Some(entries) = raw.and_then(Value::as_array) else { return Vec::new() };+ let Some(entries) = raw.and_then(Value::as_array) else {+ return Vec::new();+ };entries.iter().filter_map(|entry| {@@ -228,7 +247,9 @@ pub fn from_document(document: &Value) -> Option<Project> {let mut timelines: Vec<Timeline> = Vec::new();if let Some(entries) = document.get("timelines").and_then(Value::as_array) {for entry in entries {- let Some(id) = entry.get("id").and_then(Value::as_str) else { continue };+ let Some(id) = entry.get("id").and_then(Value::as_str) else {+ continue;+ };if timelines.iter().any(|existing| existing.id == id) {continue;}@@ -282,7 +303,12 @@ pub fn from_document(document: &Value) -> Option<Project> {}).unwrap_or_default();- Some(Project { media, fonts, timelines, active_timeline_id })+ Some(Project {+ media,+ fonts,+ timelines,+ active_timeline_id,+ })}/// Settings the host manages around the edit: the manifest's identity fields.@@ -316,14 +342,28 @@ pub fn to_document(settings: &DocumentSettings, project: &Project) -> Value {"rateDen": settings.rate_den,}),);- document.insert("media".into(), serde_json::to_value(&project.media).expect("serialises"));+ document.insert(+ "media".into(),+ serde_json::to_value(&project.media).expect("serialises"),+ );// The flat mirror of the active timeline, for builds that predate// multiple timelines.- document.insert("tracks".into(), serde_json::to_value(&active.tracks).expect("serialises"));- document.insert("clips".into(), serde_json::to_value(&active.clips).expect("serialises"));- document.insert("fonts".into(), serde_json::to_value(&project.fonts).expect("serialises"));- document- .insert("timelines".into(), serde_json::to_value(&project.timelines).expect("serialises"));+ document.insert(+ "tracks".into(),+ serde_json::to_value(&active.tracks).expect("serialises"),+ );+ document.insert(+ "clips".into(),+ serde_json::to_value(&active.clips).expect("serialises"),+ );+ document.insert(+ "fonts".into(),+ serde_json::to_value(&project.fonts).expect("serialises"),+ );+ document.insert(+ "timelines".into(),+ serde_json::to_value(&project.timelines).expect("serialises"),+ );document.insert("activeTimelineId".into(), json!(project.active_timeline_id));Value::Object(document)}diff --git a/engine/crates/concat-project/src/editor.rs b/engine/crates/concat-project/src/editor.rsindex 8c5b10fb..09e3f3e8 100644--- a/engine/crates/concat-project/src/editor.rs+++ b/engine/crates/concat-project/src/editor.rs@@ -49,7 +49,12 @@ impl Editor {let project = from_document(document)?;let mut mint = IdMint::default();mint.adopt_project(&project);- Some(Self { project, mint, undo: VecDeque::new(), redo: Vec::new() })+ Some(Self {+ project,+ mint,+ undo: VecDeque::new(),+ redo: Vec::new(),+ })}/// The current state, read-only: all mutation goes through@@ -81,7 +86,8 @@ impl Editor {pub fn undo(&mut self) -> bool {match self.undo.pop_back() {Some(previous) => {- self.redo.push(std::mem::replace(&mut self.project, previous));+ self.redo+ .push(std::mem::replace(&mut self.project, previous));true}None => false,@@ -92,7 +98,8 @@ impl Editor {pub fn redo(&mut self) -> bool {match self.redo.pop() {Some(next) => {- self.undo.push_back(std::mem::replace(&mut self.project, next));+ self.undo+ .push_back(std::mem::replace(&mut self.project, next));true}None => false,diff --git a/engine/crates/concat-project/src/lib.rs b/engine/crates/concat-project/src/lib.rsindex a53b00c5..b1dd0269 100644--- a/engine/crates/concat-project/src/lib.rs+++ b/engine/crates/concat-project/src/lib.rs@@ -71,11 +71,18 @@ mod tests {/// Editor with one media item and one clip at [0, 10) on track one.fn fixture() -> (Editor, String, String) {let mut editor = Editor::new();- let media_id =- editor.apply(media("/a.mp4", 10.0, true)).expect("adds").created_id.expect("id");+ let media_id = editor+ .apply(media("/a.mp4", 10.0, true))+ .expect("adds")+ .created_id+ .expect("id");let track_id = editor.project().active().tracks[0].id.clone();let clip_id = editor- .apply(Command::AddClip { media_id: media_id.clone(), track_id, start: 0.0 })+ .apply(Command::AddClip {+ media_id: media_id.clone(),+ track_id,+ start: 0.0,+ }).expect("adds").created_id.expect("id");@@ -101,7 +108,10 @@ mod tests {fn split_produces_source_continuous_halves_and_merge_rejoins_them() {let (mut editor, _, clip_id) = fixture();editor- .apply(Command::SplitClips { clip_ids: vec![clip_id.clone()], time: 4.0 })+ .apply(Command::SplitClips {+ clip_ids: vec![clip_id.clone()],+ time: 4.0,+ }).expect("splits");let clips = &editor.project().active().clips;@@ -111,7 +121,9 @@ mod tests {assert_eq!(clips[1].source_start, 4.0);let ids: Vec<String> = clips.iter().map(|clip| clip.id.clone()).collect();- editor.apply(Command::MergeClips { clip_ids: ids }).expect("merges");+ editor+ .apply(Command::MergeClips { clip_ids: ids })+ .expect("merges");let clips = &editor.project().active().clips;assert_eq!(clips.len(), 1);assert_eq!(clips[0].duration, 10.0);@@ -122,7 +134,10 @@ mod tests {fn rearranged_pieces_refuse_to_merge() {let (mut editor, _, clip_id) = fixture();editor- .apply(Command::SplitClips { clip_ids: vec![clip_id.clone()], time: 4.0 })+ .apply(Command::SplitClips {+ clip_ids: vec![clip_id.clone()],+ time: 4.0,+ }).expect("splits");let tail_id = editor.project().active().clips[1].id.clone();let track_id = editor.project().active().tracks[0].id.clone();@@ -130,36 +145,73 @@ mod tests {editor.apply(Command::MoveClips {moves: vec![- ClipMove { clip_id: clip_id.clone(), start: 6.0, track_id: track_id.clone() },- ClipMove { clip_id: tail_id.clone(), start: 0.0, track_id },+ ClipMove {+ clip_id: clip_id.clone(),+ start: 6.0,+ track_id: track_id.clone(),+ },+ ClipMove {+ clip_id: tail_id.clone(),+ start: 0.0,+ track_id,+ },],}).expect("moves");- let refused = editor.apply(Command::MergeClips { clip_ids: vec![tail_id, clip_id] });- assert!(refused.unwrap_err().to_string().contains("no longer in their original order"));+ let refused = editor.apply(Command::MergeClips {+ clip_ids: vec![tail_id, clip_id],+ });+ assert!(+ refused+ .unwrap_err()+ .to_string()+ .contains("no longer in their original order")+ );}#[test]fn a_head_trim_moves_the_in_point_with_speed() {let (mut editor, _, clip_id) = fixture();- editor.apply(Command::SetClipSpeed { clip_id: clip_id.clone(), speed: 2.0 }).expect("ok");+ editor+ .apply(Command::SetClipSpeed {+ clip_id: clip_id.clone(),+ speed: 2.0,+ })+ .expect("ok");// 10s of source at 2x occupies 5s of timeline.assert_eq!(editor.project().active().clips[0].duration, 5.0);editor- .apply(Command::TrimClip { clip_id, edge: TrimEdge::Start, delta: 1.0 })+ .apply(Command::TrimClip {+ clip_id,+ edge: TrimEdge::Start,+ delta: 1.0,+ }).expect("trims");let clip = &editor.project().active().clips[0];assert_eq!(clip.start, 1.0);assert_eq!(clip.duration, 4.0);- assert_eq!(clip.source_start, 2.0, "a timeline second covers two source seconds");+ assert_eq!(+ clip.source_start, 2.0,+ "a timeline second covers two source seconds"+ );}#[test]fn speed_clamps_to_the_engine_range() {let (mut editor, _, clip_id) = fixture();- editor.apply(Command::SetClipSpeed { clip_id: clip_id.clone(), speed: 100.0 }).expect("ok");+ editor+ .apply(Command::SetClipSpeed {+ clip_id: clip_id.clone(),+ speed: 100.0,+ })+ .expect("ok");assert_eq!(editor.project().active().clips[0].speed, 16.0);- editor.apply(Command::SetClipSpeed { clip_id, speed: 0.0 }).expect("ok");+ editor+ .apply(Command::SetClipSpeed {+ clip_id,+ speed: 0.0,+ })+ .expect("ok");assert_eq!(editor.project().active().clips[0].speed, 0.0625);}@@ -167,7 +219,9 @@ mod tests {fn detach_and_reattach_round_trip_the_sound() {let (mut editor, _, clip_id) = fixture();let sound_id = editor- .apply(Command::DetachAudio { clip_id: clip_id.clone() })+ .apply(Command::DetachAudio {+ clip_id: clip_id.clone(),+ }).expect("detaches").created_id.expect("sound clip");@@ -179,7 +233,9 @@ mod tests {assert_eq!(sound.detached_from.as_deref(), Some(clip_id.as_str()));assert_eq!(timeline.clip(&clip_id).expect("exists").muted, Some(true));- editor.apply(Command::ReattachAudio { clip_id: sound_id }).expect("reattaches");+ editor+ .apply(Command::ReattachAudio { clip_id: sound_id })+ .expect("reattaches");let timeline = editor.project().active();assert_eq!(timeline.clips.len(), 1);assert_eq!(timeline.clip(&clip_id).expect("exists").muted, None);@@ -188,19 +244,33 @@ mod tests {#[test]fn timelines_add_switch_and_delete_with_a_floor_of_one() {let mut editor = Editor::new();- let second =- editor.apply(Command::AddTimeline).expect("adds").created_id.expect("id");+ let second = editor+ .apply(Command::AddTimeline)+ .expect("adds")+ .created_id+ .expect("id");assert_eq!(editor.project().active_timeline_id, second);assert_eq!(editor.project().timelines[1].name, "Timeline 2");assert!(- editor.project().timelines[1].tracks.iter().all(|track| track.id != "T1"),+ editor.project().timelines[1]+ .tracks+ .iter()+ .all(|track| track.id != "T1"),"fresh lanes must not reuse the first timeline's ids");- editor.apply(Command::SelectTimeline { timeline_id: "TL1".to_owned() }).expect("ok");+ editor+ .apply(Command::SelectTimeline {+ timeline_id: "TL1".to_owned(),+ })+ .expect("ok");assert_eq!(editor.project().active_timeline_id, "TL1");- editor.apply(Command::RemoveTimeline { timeline_id: "TL1".to_owned() }).expect("ok");+ editor+ .apply(Command::RemoveTimeline {+ timeline_id: "TL1".to_owned(),+ })+ .expect("ok");assert_eq!(editor.project().active_timeline_id, second);let last = editor.project().timelines[0].id.clone();let refused = editor.apply(Command::RemoveTimeline { timeline_id: last });@@ -210,29 +280,62 @@ mod tests {#[test]fn a_timeline_moves_to_a_new_slot_without_stealing_the_selection() {let mut editor = Editor::new();- let second = editor.apply(Command::AddTimeline).expect("adds").created_id.expect("id");- let third = editor.apply(Command::AddTimeline).expect("adds").created_id.expect("id");- editor.apply(Command::SelectTimeline { timeline_id: "TL1".to_owned() }).expect("ok");+ let second = editor+ .apply(Command::AddTimeline)+ .expect("adds")+ .created_id+ .expect("id");+ let third = editor+ .apply(Command::AddTimeline)+ .expect("adds")+ .created_id+ .expect("id");+ editor+ .apply(Command::SelectTimeline {+ timeline_id: "TL1".to_owned(),+ })+ .expect("ok");editor- .apply(Command::MoveTimeline { timeline_id: third.clone(), index: 0 })+ .apply(Command::MoveTimeline {+ timeline_id: third.clone(),+ index: 0,+ }).expect("moves");- let order: Vec<_> =- editor.project().timelines.iter().map(|timeline| timeline.id.clone()).collect();+ let order: Vec<_> = editor+ .project()+ .timelines+ .iter()+ .map(|timeline| timeline.id.clone())+ .collect();assert_eq!(order, vec![third.clone(), "TL1".to_owned(), second.clone()]);- assert_eq!(editor.project().active_timeline_id, "TL1", "moving must not select");+ assert_eq!(+ editor.project().active_timeline_id,+ "TL1",+ "moving must not select"+ );// An index past the end clamps to the last slot; a same-slot move and// an unknown id apply nothing, so neither records history.editor- .apply(Command::MoveTimeline { timeline_id: third.clone(), index: 99 })+ .apply(Command::MoveTimeline {+ timeline_id: third.clone(),+ index: 99,+ }).expect("ok");- let order: Vec<_> =- editor.project().timelines.iter().map(|timeline| timeline.id.clone()).collect();+ let order: Vec<_> = editor+ .project()+ .timelines+ .iter()+ .map(|timeline| timeline.id.clone())+ .collect();assert_eq!(order, vec!["TL1".to_owned(), second, third]);let before_can_undo = editor.can_undo();let outcome = editor- .apply(Command::MoveTimeline { timeline_id: "nope".to_owned(), index: 0 })+ .apply(Command::MoveTimeline {+ timeline_id: "nope".to_owned(),+ index: 0,+ }).expect("no-op");assert!(!outcome.applied);assert_eq!(editor.can_undo(), before_can_undo);@@ -242,7 +345,10 @@ mod tests {fn undo_and_redo_walk_the_history() {let (mut editor, _, clip_id) = fixture();editor- .apply(Command::SplitClips { clip_ids: vec![clip_id], time: 5.0 })+ .apply(Command::SplitClips {+ clip_ids: vec![clip_id],+ time: 5.0,+ }).expect("splits");assert_eq!(editor.project().active().clips.len(), 2);@@ -251,14 +357,19 @@ mod tests {assert!(editor.redo());assert_eq!(editor.project().active().clips.len(), 2);assert!(editor.undo() && editor.undo() && editor.undo());- assert!(editor.project().media.is_empty(), "all the way back to empty");+ assert!(+ editor.project().media.is_empty(),+ "all the way back to empty"+ );}#[test]fn a_failed_command_records_no_history() {let (mut editor, _, _) = fixture();let before_can_undo = editor.can_undo();- let _ = editor.apply(Command::MergeClips { clip_ids: vec!["nope".to_owned()] });+ let _ = editor.apply(Command::MergeClips {+ clip_ids: vec!["nope".to_owned()],+ });assert_eq!(editor.can_undo(), before_can_undo);}@@ -344,8 +455,18 @@ mod tests {.created_id.expect("id");assert!(- restored.project().media.iter().filter(|item| item.id == media_id).count() == 1- && editor.project().media.iter().all(|item| item.id != media_id),+ restored+ .project()+ .media+ .iter()+ .filter(|item| item.id == media_id)+ .count()+ == 1+ && editor+ .project()+ .media+ .iter()+ .all(|item| item.id != media_id),"the fresh id collides with nothing");}@@ -371,7 +492,13 @@ mod tests {"op": "setMediaPlaceholder", "mediaId": "m1", "placeholder": true})).expect("parses");- assert!(matches!(mark, Command::SetMediaPlaceholder { placeholder: true, .. }));+ assert!(matches!(+ mark,+ Command::SetMediaPlaceholder {+ placeholder: true,+ ..+ }+ ));let batch: Command = serde_json::from_value(json!({"op": "batch",@@ -402,10 +529,17 @@ mod tests {// Shape the clip the way a template slot looks: trimmed off the front,// so it has a real in-point to forget.editor- .apply(Command::TrimClip { clip_id, edge: TrimEdge::Start, delta: 2.0 })+ .apply(Command::TrimClip {+ clip_id,+ edge: TrimEdge::Start,+ delta: 2.0,+ }).expect("trims");editor- .apply(Command::SetMediaPlaceholder { media_id: media_id.clone(), placeholder: true })+ .apply(Command::SetMediaPlaceholder {+ media_id: media_id.clone(),+ placeholder: true,+ }).expect("marks");assert!(editor.project().media[0].placeholder);@@ -437,7 +571,10 @@ mod tests {let clip = &project.active().clips[0];assert_eq!(clip.start, 2.0, "slot position is the template's");assert_eq!(clip.duration, 8.0, "slot length is the template's");- assert_eq!(clip.source_start, 0.0, "the in-point referred to the old footage");+ assert_eq!(+ clip.source_start, 0.0,+ "the in-point referred to the old footage"+ );assert_eq!(clip.kind, ClipKind::Image);assert_eq!(clip.name, "photo.jpg");}@@ -461,7 +598,12 @@ mod tests {has_audio: false,},});- assert!(refused.unwrap_err().to_string().contains("not a template slot"));+ assert!(+ refused+ .unwrap_err()+ .to_string()+ .contains("not a template slot")+ );}#[test]@@ -470,8 +612,14 @@ mod tests {editor.apply(Command::Batch {commands: vec![- Command::SplitClips { clip_ids: vec![clip_id.clone()], time: 4.0 },- Command::SetClipSpeed { clip_id, speed: 2.0 },+ Command::SplitClips {+ clip_ids: vec![clip_id.clone()],+ time: 4.0,+ },+ Command::SetClipSpeed {+ clip_id,+ speed: 2.0,+ },],}).expect("applies");@@ -490,12 +638,21 @@ mod tests {let before = editor.project().clone();let refused = editor.apply(Command::Batch {commands: vec![- Command::SplitClips { clip_ids: vec![clip_id], time: 4.0 },- Command::MergeClips { clip_ids: vec!["nope".to_owned()] },+ Command::SplitClips {+ clip_ids: vec![clip_id],+ time: 4.0,+ },+ Command::MergeClips {+ clip_ids: vec!["nope".to_owned()],+ },],});assert!(refused.is_err());- assert_eq!(editor.project(), &before, "the successful half was rolled back");+ assert_eq!(+ editor.project(),+ &before,+ "the successful half was rolled back"+ );assert!(editor.undo());assert!(@@ -508,12 +665,18 @@ mod tests {fn the_placeholder_flag_round_trips_and_defaults_off() {let (mut editor, media_id, _) = fixture();editor- .apply(Command::SetMediaPlaceholder { media_id, placeholder: true })+ .apply(Command::SetMediaPlaceholder {+ media_id,+ placeholder: true,+ }).expect("marks");let document = editor.to_document(&settings());let restored = Editor::from_document(&document).expect("loads");- assert!(restored.project().media[0].placeholder, "the flag survives the document");+ assert!(+ restored.project().media[0].placeholder,+ "the flag survives the document"+ );// A document from a build that predates templates has no such field.let legacy = json!({@@ -540,7 +703,10 @@ mod tests {.apply(Command::AddTextClip {track_id: None,start: 2.0,- style: Some(TextStyle { content: "Lower third\nsecond line".to_owned(), ..TextStyle::default() }),+ style: Some(TextStyle {+ content: "Lower third\nsecond line".to_owned(),+ ..TextStyle::default()+ }),duration: Some(2.5),offset_y: Some(0.38),})@@ -561,7 +727,11 @@ mod tests {.expect("old wire shape parses");assert!(matches!(bare,- Command::AddTextClip { duration: None, offset_y: None, .. }+ Command::AddTextClip {+ duration: None,+ offset_y: None,+ ..+ }));let document = editor.to_document(&settings());@@ -599,12 +769,18 @@ mod tests {let outcome = editor.apply(Command::UpdateClip {clip_id,- patch: ClipPatch { volume: Some(1.0), ..ClipPatch::default() },+ patch: ClipPatch {+ volume: Some(1.0),+ ..ClipPatch::default()+ },}).expect("tolerated");assert!(!outcome.applied);assert!(editor.undo());- assert!(editor.project().active().clips.is_empty(), "straight back past the add-clip");+ assert!(+ editor.project().active().clips.is_empty(),+ "straight back past the add-clip"+ );}#[test]@@ -620,19 +796,30 @@ mod tests {flag: TrackFlag::Visible,value: true,},- Command::SetClipSpeed { clip_id, speed: 2.0 },+ Command::SetClipSpeed {+ clip_id,+ speed: 2.0,+ },],}).expect("applies");assert!(outcome.applied);assert!(editor.undo());- assert_eq!(editor.project().active().clips[0].speed, 1.0, "one undo undoes the batch");+ assert_eq!(+ editor.project().active().clips[0].speed,+ 1.0,+ "one undo undoes the batch"+ );// A batch of nothing-but-no-ops is itself a no-op: no undo entry.let outcome = editor.apply(Command::Batch {commands: vec![- Command::SetTrackFlag { track_id, flag: TrackFlag::Visible, value: true },+ Command::SetTrackFlag {+ track_id,+ flag: TrackFlag::Visible,+ value: true,+ },Command::TrimClip {clip_id: "nope".to_owned(),edge: TrimEdge::End,@@ -700,13 +887,24 @@ mod tests {.apply(Command::MoveClips {moves: vec![// The unknown clip is skipped; the rest still lands.- ClipMove { clip_id: "nope".to_owned(), start: 9.0, track_id: target.clone() },- ClipMove { clip_id: clip_id.clone(), start: -2.0, track_id: target.clone() },+ ClipMove {+ clip_id: "nope".to_owned(),+ start: 9.0,+ track_id: target.clone(),+ },+ ClipMove {+ clip_id: clip_id.clone(),+ start: -2.0,+ track_id: target.clone(),+ },],}).expect("tolerated");let clip = editor.project().active().clip(&clip_id).expect("exists");- assert_eq!(clip.start, 0.0, "negative starts clamp to the timeline head");+ assert_eq!(+ clip.start, 0.0,+ "negative starts clamp to the timeline head"+ );assert_eq!(clip.track_id, target);}@@ -714,7 +912,11 @@ mod tests {fn a_tail_trim_stretches_only_the_duration_and_stops_at_the_minimum() {let (mut editor, _, clip_id) = fixture();editor- .apply(Command::TrimClip { clip_id: clip_id.clone(), edge: TrimEdge::End, delta: -4.0 })+ .apply(Command::TrimClip {+ clip_id: clip_id.clone(),+ edge: TrimEdge::End,+ delta: -4.0,+ }).expect("trims");let clip = editor.project().active().clip(&clip_id).expect("exists");assert_eq!(clip.duration, 6.0);@@ -731,7 +933,12 @@ mod tests {}).expect("trims");assert_eq!(- editor.project().active().clip(&clip_id).expect("exists").duration,+ editor+ .project()+ .active()+ .clip(&clip_id)+ .expect("exists")+ .duration,1.0 / 60.0);}@@ -741,42 +948,72 @@ mod tests {let (mut editor, media_id, _) = fixture();// Track one is occupied for [0, 10), so the same span lands on two.let second = editor- .apply(Command::AddClipAtFirstFree { media_id: media_id.clone(), start: 0.0 })+ .apply(Command::AddClipAtFirstFree {+ media_id: media_id.clone(),+ start: 0.0,+ }).expect("adds").created_id.expect("id");assert_eq!(- editor.project().active().clip(&second).expect("exists").track_id,+ editor+ .project()+ .active()+ .clip(&second)+ .expect("exists")+ .track_id,editor.project().active().tracks[1].id);// Fill the remaining lanes, then ask again: rather than refusing,// the clip overlaps on the first track.editor- .apply(Command::AddClipAtFirstFree { media_id: media_id.clone(), start: 0.0 })+ .apply(Command::AddClipAtFirstFree {+ media_id: media_id.clone(),+ start: 0.0,+ }).expect("adds");editor- .apply(Command::AddClipAtFirstFree { media_id: media_id.clone(), start: 0.0 })+ .apply(Command::AddClipAtFirstFree {+ media_id: media_id.clone(),+ start: 0.0,+ }).expect("adds");let overflow = editor- .apply(Command::AddClipAtFirstFree { media_id: media_id.clone(), start: 0.0 })+ .apply(Command::AddClipAtFirstFree {+ media_id: media_id.clone(),+ start: 0.0,+ }).expect("adds").created_id.expect("id");assert_eq!(- editor.project().active().clip(&overflow).expect("exists").track_id,+ editor+ .project()+ .active()+ .clip(&overflow)+ .expect("exists")+ .track_id,editor.project().active().tracks[0].id,"a full timeline falls back to the first track, overlap and all");// A clear span later in time finds track one free again.let clear = editor- .apply(Command::AddClipAtFirstFree { media_id, start: 20.0 })+ .apply(Command::AddClipAtFirstFree {+ media_id,+ start: 20.0,+ }).expect("adds").created_id.expect("id");assert_eq!(- editor.project().active().clip(&clear).expect("exists").track_id,+ editor+ .project()+ .active()+ .clip(&clear)+ .expect("exists")+ .track_id,editor.project().active().tracks[0].id);}@@ -785,22 +1022,36 @@ mod tests {fn removing_a_track_takes_its_clips_and_stops_at_the_floor_of_one() {let (mut editor, _, _) = fixture();let track_id = editor.project().active().tracks[0].id.clone();- editor.apply(Command::RemoveTrack { track_id: track_id.clone() }).expect("removes");+ editor+ .apply(Command::RemoveTrack {+ track_id: track_id.clone(),+ })+ .expect("removes");let timeline = editor.project().active();assert_eq!(timeline.tracks.len(), 3);- assert!(timeline.clips.is_empty(), "the clip on the removed track went with it");+ assert!(+ timeline.clips.is_empty(),+ "the clip on the removed track went with it"+ );// An unknown id is the tolerated no-op, not an error.- let outcome = editor.apply(Command::RemoveTrack { track_id }).expect("tolerated");+ let outcome = editor+ .apply(Command::RemoveTrack { track_id })+ .expect("tolerated");assert!(!outcome.applied);while editor.project().active().tracks.len() > 1 {let next = editor.project().active().tracks[0].id.clone();- editor.apply(Command::RemoveTrack { track_id: next }).expect("removes");+ editor+ .apply(Command::RemoveTrack { track_id: next })+ .expect("removes");}let last = editor.project().active().tracks[0].id.clone();let refused = editor.apply(Command::RemoveTrack { track_id: last });- assert_eq!(refused.unwrap_err().to_string(), "A timeline needs at least one track.");+ assert_eq!(+ refused.unwrap_err().to_string(),+ "A timeline needs at least one track."+ );}#[test]@@ -809,18 +1060,32 @@ mod tests {editor.apply(Command::AddTimeline).expect("adds");let track_id = editor.project().active().tracks[0].id.clone();editor- .apply(Command::AddClip { media_id: media_id.clone(), track_id, start: 0.0 })+ .apply(Command::AddClip {+ media_id: media_id.clone(),+ track_id,+ start: 0.0,+ }).expect("adds");- editor.apply(Command::RemoveMedia { media_id: media_id.clone() }).expect("removes");+ editor+ .apply(Command::RemoveMedia {+ media_id: media_id.clone(),+ })+ .expect("removes");assert!(editor.project().media.is_empty());assert!(- editor.project().timelines.iter().all(|timeline| timeline.clips.is_empty()),+ editor+ .project()+ .timelines+ .iter()+ .all(|timeline| timeline.clips.is_empty()),"the inactive timeline's clip is swept too, not left dangling");// Removing what is already gone is a tolerated no-op.- let outcome = editor.apply(Command::RemoveMedia { media_id }).expect("tolerated");+ let outcome = editor+ .apply(Command::RemoveMedia { media_id })+ .expect("tolerated");assert!(!outcome.applied);}@@ -838,7 +1103,10 @@ mod tests {// Whitespace-only would leave the lane unlabelled, so it is ignored.let outcome = editor- .apply(Command::RenameTrack { track_id, name: " ".to_owned() })+ .apply(Command::RenameTrack {+ track_id,+ name: " ".to_owned(),+ }).expect("tolerated");assert!(!outcome.applied);assert_eq!(editor.project().active().tracks[0].name, "Cutaways");@@ -851,7 +1119,10 @@ mod tests {.expect("renames");assert_eq!(editor.project().timelines[0].name, "Cut A");let outcome = editor- .apply(Command::RenameTimeline { timeline_id: "TL1".to_owned(), name: String::new() })+ .apply(Command::RenameTimeline {+ timeline_id: "TL1".to_owned(),+ name: String::new(),+ }).expect("tolerated");assert!(!outcome.applied);assert_eq!(editor.project().timelines[0].name, "Cut A");@@ -882,7 +1153,11 @@ mod tests {// Setting the value already in place is a no-op, exactly as the old// deep-compare judged it.let outcome = editor- .apply(Command::SetTrackFlag { track_id, flag: TrackFlag::Muted, value: true })+ .apply(Command::SetTrackFlag {+ track_id,+ flag: TrackFlag::Muted,+ value: true,+ }).expect("tolerated");assert!(!outcome.applied);}@@ -911,7 +1186,12 @@ mod tests {}).expect("sets");assert_eq!(- editor.project().active().clip(&clip_id).expect("exists").rotation,+ editor+ .project()+ .active()+ .clip(&clip_id)+ .expect("exists")+ .rotation,landed,"{sent} degrees should land at {landed}");@@ -921,30 +1201,56 @@ mod tests {#[test]fn removing_a_timeline_moves_the_active_tab_to_a_neighbour() {let mut editor = Editor::new();- let second = editor.apply(Command::AddTimeline).expect("adds").created_id.expect("id");- let third = editor.apply(Command::AddTimeline).expect("adds").created_id.expect("id");+ let second = editor+ .apply(Command::AddTimeline)+ .expect("adds")+ .created_id+ .expect("id");+ let third = editor+ .apply(Command::AddTimeline)+ .expect("adds")+ .created_id+ .expect("id");assert_eq!(editor.project().active_timeline_id, third);// An unknown id is a tolerated no-op while the floor allows it.let outcome = editor- .apply(Command::RemoveTimeline { timeline_id: "ghost".to_owned() })+ .apply(Command::RemoveTimeline {+ timeline_id: "ghost".to_owned(),+ }).expect("tolerated");assert!(!outcome.applied);// Removing the active last tab falls back to the previous one.- editor.apply(Command::RemoveTimeline { timeline_id: third }).expect("removes");+ editor+ .apply(Command::RemoveTimeline { timeline_id: third })+ .expect("removes");assert_eq!(editor.project().active_timeline_id, second);// Removing an active middle tab prefers the neighbour to its right.- let third = editor.apply(Command::AddTimeline).expect("adds").created_id.expect("id");+ let third = editor+ .apply(Command::AddTimeline)+ .expect("adds")+ .created_id+ .expect("id");editor- .apply(Command::SelectTimeline { timeline_id: second.clone() })+ .apply(Command::SelectTimeline {+ timeline_id: second.clone(),+ }).expect("selects");- editor.apply(Command::RemoveTimeline { timeline_id: second }).expect("removes");+ editor+ .apply(Command::RemoveTimeline {+ timeline_id: second,+ })+ .expect("removes");assert_eq!(editor.project().active_timeline_id, third);// Removing an inactive tab leaves the selection alone.- editor.apply(Command::RemoveTimeline { timeline_id: "TL1".to_owned() }).expect("removes");+ editor+ .apply(Command::RemoveTimeline {+ timeline_id: "TL1".to_owned(),+ })+ .expect("removes");assert_eq!(editor.project().active_timeline_id, third);}@@ -971,7 +1277,10 @@ mod tests {.apply(Command::AddTextClip {track_id: None,start: 0.0,- style: Some(TextStyle { font_family: "Inter".to_owned(), ..TextStyle::default() }),+ style: Some(TextStyle {+ font_family: "Inter".to_owned(),+ ..TextStyle::default()+ }),duration: None,offset_y: None,})@@ -979,7 +1288,11 @@ mod tests {.created_id.expect("id");- editor.apply(Command::RemoveFont { family: "Inter".to_owned() }).expect("removes");+ editor+ .apply(Command::RemoveFont {+ family: "Inter".to_owned(),+ })+ .expect("removes");assert!(editor.project().fonts.is_empty());let clip = editor.project().active().clip(&clip_id).expect("exists");assert_eq!(@@ -989,8 +1302,11 @@ mod tests {);// Removing what is already gone is a tolerated no-op.- let outcome =- editor.apply(Command::RemoveFont { family: "Inter".to_owned() }).expect("tolerated");+ let outcome = editor+ .apply(Command::RemoveFont {+ family: "Inter".to_owned(),+ })+ .expect("tolerated");assert!(!outcome.applied);}@@ -1004,12 +1320,29 @@ mod tests {};let commands = vec![Command::AddMedia { item: item.clone() },- Command::RemoveMedia { media_id: "m1".to_owned() },- Command::SetMediaPlaceholder { media_id: "m1".to_owned(), placeholder: true },- Command::FillSlot { media_id: "m1".to_owned(), item },- Command::Batch { commands: vec![Command::AddTrack] },- Command::AddClip { media_id: "m1".to_owned(), track_id: "T1".to_owned(), start: 1.0 },- Command::AddClipAtFirstFree { media_id: "m1".to_owned(), start: 2.0 },+ Command::RemoveMedia {+ media_id: "m1".to_owned(),+ },+ Command::SetMediaPlaceholder {+ media_id: "m1".to_owned(),+ placeholder: true,+ },+ Command::FillSlot {+ media_id: "m1".to_owned(),+ item,+ },+ Command::Batch {+ commands: vec![Command::AddTrack],+ },+ Command::AddClip {+ media_id: "m1".to_owned(),+ track_id: "T1".to_owned(),+ start: 1.0,+ },+ Command::AddClipAtFirstFree {+ media_id: "m1".to_owned(),+ start: 2.0,+ },Command::AddTextClip {track_id: Some("T1".to_owned()),start: 0.0,@@ -1024,10 +1357,21 @@ mod tests {track_id: "T2".to_owned(),}],},- Command::TrimClip { clip_id: "c1".to_owned(), edge: TrimEdge::End, delta: -0.5 },- Command::SplitClips { clip_ids: vec!["c1".to_owned()], time: 3.0 },- Command::MergeClips { clip_ids: vec!["c1".to_owned(), "c2".to_owned()] },- Command::RemoveClips { clip_ids: vec!["c1".to_owned()] },+ Command::TrimClip {+ clip_id: "c1".to_owned(),+ edge: TrimEdge::End,+ delta: -0.5,+ },+ Command::SplitClips {+ clip_ids: vec!["c1".to_owned()],+ time: 3.0,+ },+ Command::MergeClips {+ clip_ids: vec!["c1".to_owned(), "c2".to_owned()],+ },+ Command::RemoveClips {+ clip_ids: vec!["c1".to_owned()],+ },Command::UpdateClip {clip_id: "c1".to_owned(),patch: ClipPatch {@@ -1036,7 +1380,10 @@ mod tests {..ClipPatch::default()},},- Command::SetClipSpeed { clip_id: "c1".to_owned(), speed: 2.0 },+ Command::SetClipSpeed {+ clip_id: "c1".to_owned(),+ speed: 2.0,+ },Command::SetClipTransform {clip_id: "c1".to_owned(),scale: Some(1.5),@@ -1044,22 +1391,43 @@ mod tests {offset_y: Some(-0.25),rotation: Some(90.0),},- Command::DetachAudio { clip_id: "c1".to_owned() },- Command::ReattachAudio { clip_id: "c1".to_owned() },+ Command::DetachAudio {+ clip_id: "c1".to_owned(),+ },+ Command::ReattachAudio {+ clip_id: "c1".to_owned(),+ },Command::AddTrack,- Command::RemoveTrack { track_id: "T1".to_owned() },- Command::RenameTrack { track_id: "T1".to_owned(), name: "Cutaways".to_owned() },+ Command::RemoveTrack {+ track_id: "T1".to_owned(),+ },+ Command::RenameTrack {+ track_id: "T1".to_owned(),+ name: "Cutaways".to_owned(),+ },Command::SetTrackFlag {track_id: "T1".to_owned(),flag: TrackFlag::Muted,value: true,},Command::AddTimeline,- Command::RemoveTimeline { timeline_id: "TL1".to_owned() },- Command::RenameTimeline { timeline_id: "TL1".to_owned(), name: "Cut A".to_owned() },- Command::SelectTimeline { timeline_id: "TL1".to_owned() },- Command::AddFont { family: "Inter".to_owned(), path: "/fonts/inter.ttf".to_owned() },- Command::RemoveFont { family: "Inter".to_owned() },+ Command::RemoveTimeline {+ timeline_id: "TL1".to_owned(),+ },+ Command::RenameTimeline {+ timeline_id: "TL1".to_owned(),+ name: "Cut A".to_owned(),+ },+ Command::SelectTimeline {+ timeline_id: "TL1".to_owned(),+ },+ Command::AddFont {+ family: "Inter".to_owned(),+ path: "/fonts/inter.ttf".to_owned(),+ },+ Command::RemoveFont {+ family: "Inter".to_owned(),+ },];for command in commands {let wire = serde_json::to_value(&command).expect("serialises");@@ -1089,8 +1457,13 @@ mod tests {]});let editor = Editor::from_document(&document).expect("loads");- let ids: Vec<&str> =- editor.project().active().clips.iter().map(|clip| clip.id.as_str()).collect();+ let ids: Vec<&str> = editor+ .project()+ .active()+ .clips+ .iter()+ .map(|clip| clip.id.as_str())+ .collect();assert_eq!(ids, ["c3", "c4"]);}@@ -1124,10 +1497,19 @@ mod tests {assert_eq!(clip.scale, 0.05);assert_eq!(clip.transition_in.as_ref().expect("kept").duration, 0.1);- let text = editor.project().active().clips[1].text.as_ref().expect("text");- assert_eq!(text.font_size, 0.01, "a zero size would render an invisible title");+ let text = editor.project().active().clips[1]+ .text+ .as_ref()+ .expect("text");+ assert_eq!(+ text.font_size, 0.01,+ "a zero size would render an invisible title"+ );assert_eq!(text.font_weight, 900.0);- assert_eq!(text.line_height, 0.5, "lines cannot collapse onto each other");+ assert_eq!(+ text.line_height, 0.5,+ "lines cannot collapse onto each other"+ );assert_eq!(text.opacity, 1.0);}}diff --git a/engine/crates/concat-render/src/compositor.rs b/engine/crates/concat-render/src/compositor.rsindex 61846d67..6b520482 100644--- a/engine/crates/concat-render/src/compositor.rs+++ b/engine/crates/concat-render/src/compositor.rs@@ -30,8 +30,12 @@ pub struct Placement {impl Placement {/// Unscaled, unrotated, unmoved.- pub const IDENTITY: Placement =- Placement { scale: 1.0, rotation: 0.0, translate_x: 0.0, translate_y: 0.0 };+ pub const IDENTITY: Placement = Placement {+ scale: 1.0,+ rotation: 0.0,+ translate_x: 0.0,+ translate_y: 0.0,+ };/// True when applying this placement would change nothing.pub fn is_identity(&self) -> bool {@@ -63,7 +67,13 @@ pub struct Layer<'a> {impl<'a> Layer<'a> {/// A layer drawn at the origin, fully opaque.pub fn new(frame: &'a Frame) -> Self {- Self { frame, opacity: 1.0, x: 0, y: 0, placement: Placement::IDENTITY }+ Self {+ frame,+ opacity: 1.0,+ x: 0,+ y: 0,+ placement: Placement::IDENTITY,+ }}/// Sets the blend strength.@@ -265,8 +275,9 @@ fn blend_region(let src_row = &src_pixels[src_offset..src_offset + span];let dst_row = &mut dst_pixels[dst_offset..dst_offset + span];- for (src_pixel, dst_pixel) in- src_row.chunks_exact(BYTES_PER_PIXEL).zip(dst_row.chunks_exact_mut(BYTES_PER_PIXEL))+ for (src_pixel, dst_pixel) in src_row+ .chunks_exact(BYTES_PER_PIXEL)+ .zip(dst_row.chunks_exact_mut(BYTES_PER_PIXEL)){let alpha = (f32::from(src_pixel[3]) / 255.0) * opacity;if alpha <= 0.0 {@@ -341,7 +352,11 @@ mod tests {// Placed so only its bottom-right pixel lands on the output's top-left.let frame = CpuCompositor.composite(2, 2, &[Layer::new(&red).at(-1, -1)]);assert_eq!(frame.pixel(0, 0), Some([255, 0, 0, 255]));- assert_eq!(frame.pixel(1, 1), Some([0, 0, 0, 255]), "must not wrap around");+ assert_eq!(+ frame.pixel(1, 1),+ Some([0, 0, 0, 255]),+ "must not wrap around"+ );}#[test]@@ -362,7 +377,10 @@ mod tests {#[test]fn scaling_doubles_coverage() {let red = solid(2, 2, [255, 0, 0, 255]);- let placement = Placement { scale: 2.0, ..Placement::IDENTITY };+ let placement = Placement {+ scale: 2.0,+ ..Placement::IDENTITY+ };let frame =CpuCompositor.composite(4, 4, &[Layer::new(&red).at(1, 1).with_placement(placement)]);// A 2x2 layer based at (1,1) scaled x2 about its centre covers the@@ -374,7 +392,10 @@ mod tests {#[test]fn translation_moves_the_layer() {let red = solid(1, 1, [255, 0, 0, 255]);- let placement = Placement { translate_x: 2.0, ..Placement::IDENTITY };+ let placement = Placement {+ translate_x: 2.0,+ ..Placement::IDENTITY+ };let frame = CpuCompositor.composite(3, 1, &[Layer::new(&red).with_placement(placement)]);assert_eq!(frame.pixel(0, 0), Some([0, 0, 0, 255]));assert_eq!(frame.pixel(2, 0), Some([255, 0, 0, 255]));@@ -385,7 +406,10 @@ mod tests {let mut strip = Frame::transparent(2, 1);strip.set_pixel(0, 0, [255, 0, 0, 255]);strip.set_pixel(1, 0, [0, 0, 255, 255]);- let placement = Placement { rotation: std::f32::consts::PI, ..Placement::IDENTITY };+ let placement = Placement {+ rotation: std::f32::consts::PI,+ ..Placement::IDENTITY+ };let frame = CpuCompositor.composite(2, 1, &[Layer::new(&strip).with_placement(placement)]);assert_eq!(frame.pixel(0, 0), Some([0, 0, 255, 255]));assert_eq!(frame.pixel(1, 0), Some([255, 0, 0, 255]));@@ -394,7 +418,10 @@ mod tests {#[test]fn a_transformed_layer_is_clipped_at_the_frame_edge() {let red = solid(2, 2, [255, 0, 0, 255]);- let placement = Placement { scale: 100.0, ..Placement::IDENTITY };+ let placement = Placement {+ scale: 100.0,+ ..Placement::IDENTITY+ };let frame = CpuCompositor.composite(2, 2, &[Layer::new(&red).with_placement(placement)]);assert_eq!(frame.width(), 2);assert_eq!(frame.pixel(1, 1), Some([255, 0, 0, 255]));diff --git a/engine/crates/concat-render/src/gpu.rs b/engine/crates/concat-render/src/gpu.rsindex e8c08dfb..2a15096f 100644--- a/engine/crates/concat-render/src/gpu.rs+++ b/engine/crates/concat-render/src/gpu.rs@@ -130,8 +130,7 @@ impl WgpuCompositor {/// Builds a compositor on the best available adapter, or `None` when the/// machine has nothing usable - callers fall back to the CPU path.pub fn new() -> Option<Self> {- let instance =- wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle());+ let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle());let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {power_preference: wgpu::PowerPreference::HighPerformance,..Default::default()@@ -262,7 +261,11 @@ impl WgpuCompositor {if stale {let texture = self.device.create_texture(&wgpu::TextureDescriptor {label: Some("concat output"),- size: wgpu::Extent3d { width, height, depth_or_array_layers: 1 },+ size: wgpu::Extent3d {+ width,+ height,+ depth_or_array_layers: 1,+ },mip_level_count: 1,sample_count: 1,dimension: wgpu::TextureDimension::D2,@@ -277,7 +280,13 @@ impl WgpuCompositor {usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,mapped_at_creation: false,});- self.target = Some(Target { width, height, texture, staging, padded_row });+ self.target = Some(Target {+ width,+ height,+ texture,+ staging,+ padded_row,+ });}self.target.as_ref().expect("just ensured")}@@ -318,7 +327,10 @@ impl WgpuCompositor {},],});- pool.push(PooledTexture { texture, bind_group });+ pool.push(PooledTexture {+ texture,+ bind_group,+ });}let index = *used;@@ -381,7 +393,14 @@ impl WgpuCompositor {let top_right = corner(1.0, -1.0, 1.0, 0.0);let bottom_left = corner(-1.0, 1.0, 0.0, 1.0);let bottom_right = corner(1.0, 1.0, 1.0, 1.0);- [top_left, top_right, bottom_left, top_right, bottom_right, bottom_left]+ [+ top_left,+ top_right,+ bottom_left,+ top_right,+ bottom_right,+ bottom_left,+ ]}/// Copies the rendered target back into a [`Frame`], forcing it opaque.@@ -450,15 +469,19 @@ impl Compositor for WgpuCompositor {});}if !vertices.is_empty() {- self.queue.write_buffer(&self.vertices, 0, as_bytes(&vertices));+ self.queue+ .write_buffer(&self.vertices, 0, as_bytes(&vertices));}self.target(width, height);let target = self.target.as_ref().expect("just ensured");- let view = target.texture.create_view(&wgpu::TextureViewDescriptor::default());+ let view = target+ .texture+ .create_view(&wgpu::TextureViewDescriptor::default());- let mut encoder =- self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor {+ let mut encoder = self+ .device+ .create_command_encoder(&wgpu::CommandEncoderDescriptor {label: Some("concat composite"),});{@@ -481,8 +504,7 @@ impl Compositor for WgpuCompositor {pass.set_pipeline(&self.pipeline);pass.set_vertex_buffer(0, self.vertices.slice(..));for (draw, (layer_width, layer_height, pooled)) in draws.iter().enumerate() {- let bind_group =- &self.pool[&(*layer_width, *layer_height)][*pooled].bind_group;+ let bind_group = &self.pool[&(*layer_width, *layer_height)][*pooled].bind_group;pass.set_bind_group(0, bind_group, &[]);let first = (draw * 6) as u32;pass.draw(first..first + 6, 0..1);@@ -504,7 +526,11 @@ impl Compositor for WgpuCompositor {rows_per_image: Some(height),},},- wgpu::Extent3d { width, height, depth_or_array_layers: 1 },+ wgpu::Extent3d {+ width,+ height,+ depth_or_array_layers: 1,+ },);self.queue.submit([encoder.finish()]);@@ -618,7 +644,10 @@ mod tests {fn scaling_matches_the_cpu_reference_away_from_edges() {let Some(mut gpu) = gpu() else { return };let red = solid(4, 4, [255, 0, 0, 255]);- let placement = Placement { scale: 2.0, ..Placement::IDENTITY };+ let placement = Placement {+ scale: 2.0,+ ..Placement::IDENTITY+ };let layers = [Layer::new(&red).at(2, 2).with_placement(placement)];// Interior pixels are unambiguous; the half-pixel border where the two@@ -627,7 +656,10 @@ mod tests {for (x, y) in [(1, 1), (4, 4), (6, 6)] {assert_eq!(frame.pixel(x, y), Some([255, 0, 0, 255]), "at ({x},{y})");}- assert_eq!(CpuCompositor.composite(8, 8, &layers).pixel(4, 4), Some([255, 0, 0, 255]));+ assert_eq!(+ CpuCompositor.composite(8, 8, &layers).pixel(4, 4),+ Some([255, 0, 0, 255])+ );}#[test]@@ -636,7 +668,10 @@ mod tests {let mut strip = Frame::transparent(2, 1);strip.set_pixel(0, 0, [255, 0, 0, 255]);strip.set_pixel(1, 0, [0, 0, 255, 255]);- let placement = Placement { rotation: std::f32::consts::PI, ..Placement::IDENTITY };+ let placement = Placement {+ rotation: std::f32::consts::PI,+ ..Placement::IDENTITY+ };let frame = gpu.composite(2, 1, &[Layer::new(&strip).with_placement(placement)]);assert_eq!(frame.pixel(0, 0), Some([0, 0, 255, 255]));assert_eq!(frame.pixel(1, 0), Some([255, 0, 0, 255]));diff --git a/engine/crates/concat-render/src/plan.rs b/engine/crates/concat-render/src/plan.rsindex 9e6e220d..7ecdcc59 100644--- a/engine/crates/concat-render/src/plan.rs+++ b/engine/crates/concat-render/src/plan.rs@@ -89,7 +89,12 @@ pub fn plan_frame(timeline: &Timeline, time: Rational) -> FramePlan {});}- FramePlan { time, width: timeline.width, height: timeline.height, layers }+ FramePlan {+ time,+ width: timeline.width,+ height: timeline.height,+ layers,+ }}#[cfg(test)]@@ -109,15 +114,28 @@ mod tests {let lower = timeline.add_track(Track::new("V1", TrackKind::Video));let upper = timeline.add_track(Track::new("V2", TrackKind::Video));timeline- .add_clip(lower, Clip::new(MediaRef::new("bottom.mp4"), seconds(0), seconds(10)))+ .add_clip(+ lower,+ Clip::new(MediaRef::new("bottom.mp4"), seconds(0), seconds(10)),+ ).expect("track exists");timeline- .add_clip(upper, Clip::new(MediaRef::new("top.mp4"), seconds(0), seconds(10)))+ .add_clip(+ upper,+ Clip::new(MediaRef::new("top.mp4"), seconds(0), seconds(10)),+ ).expect("track exists");let plan = plan_frame(&timeline, seconds(4));- let media: Vec<_> = plan.layers.iter().map(|layer| layer.media.clone()).collect();- assert_eq!(media, vec![PathBuf::from("bottom.mp4"), PathBuf::from("top.mp4")]);+ let media: Vec<_> = plan+ .layers+ .iter()+ .map(|layer| layer.media.clone())+ .collect();+ assert_eq!(+ media,+ vec![PathBuf::from("bottom.mp4"), PathBuf::from("top.mp4")]+ );assert_eq!((plan.width, plan.height), (640, 360));}@@ -130,7 +148,11 @@ mod tests {timeline.add_clip(track, clip).expect("track exists");let plan = plan_frame(&timeline, seconds(7));- assert_eq!(plan.layers[0].source_time, seconds(32), "2s into a clip that starts at 30s");+ assert_eq!(+ plan.layers[0].source_time,+ seconds(32),+ "2s into a clip that starts at 30s"+ );}#[test]@@ -142,7 +164,11 @@ mod tests {timeline.add_clip(track, clip).expect("track exists");let plan = plan_frame(&timeline, seconds(3));- assert_eq!(plan.layers[0].source_time, seconds(6), "3s in at 2x is 6s of source");+ assert_eq!(+ plan.layers[0].source_time,+ seconds(6),+ "3s in at 2x is 6s of source"+ );assert_eq!(plan.layers[0].speed, Rational::from_int(2));}@@ -151,7 +177,10 @@ mod tests {let mut timeline = Timeline::new(640, 360, FrameRate::THIRTY);let track = timeline.add_track(Track::new("V1", TrackKind::Video));timeline- .add_clip(track, Clip::new(MediaRef::new("a.mp4"), seconds(0), seconds(2)))+ .add_clip(+ track,+ Clip::new(MediaRef::new("a.mp4"), seconds(0), seconds(2)),+ ).expect("track exists");assert!(plan_frame(&timeline, seconds(5)).is_empty());@@ -166,7 +195,10 @@ mod tests {for track in [muted, audio] {timeline- .add_clip(track, Clip::new(MediaRef::new("a.mp4"), seconds(0), seconds(10)))+ .add_clip(+ track,+ Clip::new(MediaRef::new("a.mp4"), seconds(0), seconds(10)),+ ).expect("track exists");}