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
fix(bin): several selected cards go onto the timeline together, end to end on one lane
Jareer38056f19ebac
diff --git a/src/crates/concat-project/src/commands/clips.rs b/src/crates/concat-project/src/commands/clips.rsindex 7b51ed0d..b15f7f85 100644--- a/src/crates/concat-project/src/commands/clips.rs+++ b/src/crates/concat-project/src/commands/clips.rs@@ -65,6 +65,55 @@ pub(super) fn apply(})}+ Command::AddClipsInSequence {+ media_ids,+ track_id,+ start,+ ripple,+ } => {+ let items = media_ids+ .iter()+ .map(|id| project.media_by_id(id).cloned().ok_or(CommandError::MediaGone))+ .collect::<Result<Vec<_>, _>>()?;+ if items.is_empty() {+ return Ok(Outcome {+ created_id: None,+ applied: false,+ });+ }+ let start = start.max(0.0);+ let total: f64 = items.iter().map(clip_length).sum();+ let timeline = project.active_mut();+ let track_id = match track_id {+ Some(id) if timeline.track(&id).is_none() => return Err(CommandError::TrackGone),+ Some(id) => id,+ None => first_free_track(timeline, start, total)+ .unwrap_or_else(|| fresh_track(timeline, mint)),+ };+ let mut at = start;+ let mut first = None;+ for media in &items {+ let place = if ripple {+ ripple_room_for(timeline, &track_id, at, media)+ } else {+ timeline.nearest_free_start(&track_id, at, clip_length(media), &[])+ };+ let id = mint.next("c");+ timeline.clips.push(Arc::new(default_clip(+ id.clone(),+ track_id.clone(),+ media,+ place,+ )));+ first.get_or_insert(id);+ at = place + clip_length(media);+ }+ Ok(Outcome {+ created_id: first,+ applied: true,+ })+ }+Command::AddTextClip {track_id,start,diff --git a/src/crates/concat-project/src/commands/mod.rs b/src/crates/concat-project/src/commands/mod.rsindex 90834942..810f6dd2 100644--- a/src/crates/concat-project/src/commands/mod.rs+++ b/src/crates/concat-project/src/commands/mod.rs@@ -303,6 +303,25 @@ pub enum Command {/// Timeline position in seconds, floored at 0.start: f64,},+ /// Several bin items one after another on one lane, as one step: what+ /// a selection of cards dragged from the bin, or added at the playhead,+ /// lands as. Each clip starts where the one before it ends. Naming a+ /// lane puts the run there, each clip placed as [`Command::AddClip`]+ /// places one with the same `ripple`; without one, the run goes on the+ /// lowest lane free for its whole length, a new one when none is.+ AddClipsInSequence {+ /// The bin items, in the order they are laid down.+ media_ids: Vec<String>,+ /// The lane, or None for the lowest one free for the whole run.+ #[serde(default)]+ track_id: Option<String>,+ /// Where the first clip starts, in seconds, floored at 0.+ start: f64,+ /// On a named lane, make room as a drop does rather than take the+ /// nearest gap.+ #[serde(default)]+ ripple: bool,+ },/// Places a title: a clip with no media behind it, named after the/// text's first line, minting a "c" id.AddTextClip {@@ -956,9 +975,9 @@ impl Command {Command::AddMedia { item }| Command::FillSlot { item, .. }| Command::ConsolidateClips { item, .. } => bad(item.duration) || bad(item.frame_rate),- Command::AddClip { start, .. } | Command::AddClipAtFirstFree { start, .. } => {- bad([*start])- }+ Command::AddClip { start, .. }+ | Command::AddClipAtFirstFree { start, .. }+ | Command::AddClipsInSequence { start, .. } => bad([*start]),Command::AddShapeClip {start,duration,@@ -1136,6 +1155,7 @@ pub fn apply(| Command::SetMediaColorRange { .. }) => media::apply(project, mint, command),command @ (Command::AddClip { .. }| Command::AddClipAtFirstFree { .. }+ | Command::AddClipsInSequence { .. }| Command::AddTextClip { .. }| Command::AddShapeClip { .. }| Command::AddLayerClip { .. }diff --git a/src/crates/concat-project/src/lib.rs b/src/crates/concat-project/src/lib.rsindex 81b69f3b..93a2ca72 100644--- a/src/crates/concat-project/src/lib.rs+++ b/src/crates/concat-project/src/lib.rs@@ -3880,6 +3880,41 @@ mod tests {);}+ #[test]+ fn a_sequence_lands_end_to_end_on_one_lane_and_undoes_as_one() {+ let (mut editor, media_id, _) = fixture();+ let before = editor.project().active().clips.len();+ let first = editor+ .apply(Command::AddClipsInSequence {+ media_ids: vec![media_id.clone(), media_id.clone(), media_id.clone()],+ track_id: None,+ start: 20.0,+ ripple: false,+ })+ .expect("adds")+ .created_id+ .expect("id");+ let timeline = editor.project().active();+ let lane = timeline.clip(&first).expect("exists").track_id.clone();+ let mut run: Vec<_> = timeline+ .clips+ .iter()+ .filter(|clip| clip.start >= 20.0)+ .collect();+ run.sort_by(|a, b| a.start.total_cmp(&b.start));+ assert_eq!(run.len(), 3);+ assert!((run[0].start - 20.0).abs() < 1e-9);+ for pair in run.windows(2) {+ assert_eq!(pair[0].track_id, lane, "one lane");+ assert!(+ (pair[1].start - (pair[0].start + pair[0].duration)).abs() < 1e-9,+ "each starts where the one before ends"+ );+ }+ assert!(editor.undo(), "undoes");+ assert_eq!(editor.project().active().clips.len(), before, "one undo step");+ }+#[test]fn add_at_first_free_takes_the_lowest_empty_lane_or_opens_one() {let (mut editor, media_id, _) = fixture();diff --git a/src/crates/concat/src/panes/media_bin.rs b/src/crates/concat/src/panes/media_bin.rsindex 3b90b901..420bd713 100644--- a/src/crates/concat/src/panes/media_bin.rs+++ b/src/crates/concat/src/panes/media_bin.rs@@ -199,10 +199,15 @@ impl MediaBin {.filter(|item| self.selected.contains(&item.id)).map(|item| item.id.clone()).collect();+ // One after another on one lane, as one step - not each at+ // the playhead on a lane of its own, which stacked them.let start = f64::from(studio.playhead.max(0.0));- for media_id in ids {- studio.apply(Command::AddClipAtFirstFree { media_id, start });- }+ studio.apply(Command::AddClipsInSequence {+ media_ids: ids,+ track_id: None,+ start,+ ripple: false,+ });}}}diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rsindex 829084c4..19e72172 100644--- a/src/crates/concat/src/studio.rs+++ b/src/crates/concat/src/studio.rs@@ -3678,6 +3678,23 @@ impl Studio {Some(plan)}+ /// The bin's selection, in the bin's order, when `media_id` is one card+ /// of a selection of several: what a drag of that card carries.+ fn dragged_selection(&self, media_id: &str) -> Option<Vec<String>> {+ let held = &self.media.selected;+ if held.len() < 2 || !held.contains(media_id) {+ return None;+ }+ Some(+ self.project()+ .media+ .iter()+ .filter(|item| held.contains(&item.id))+ .map(|item| item.id.clone())+ .collect(),+ )+ }+/// Commits a plan that has a lane, and selects what it made.pub fn place(&mut self, plan: &DropPlan) {let Some(track_id) = self.row_track(plan.row).map(|track| track.id.clone()) else {@@ -3706,6 +3723,16 @@ impl Studio {effect_id: plan.media.clone(),name: plan.label.clone(),})+ } else if let Some(media_ids) = self.dragged_selection(&plan.media) {+ // A card dragged out of a selection in the bin brings the whole+ // selection, laid end to end from the drop, in the bin's order.+ // Only the dragged card used to land (reported on Reddit).+ self.apply(Command::AddClipsInSequence {+ media_ids,+ track_id: Some(track_id),+ start: f64::from(plan.start),+ ripple: true,+ })} else {self.apply(Command::AddClip {media_id: plan.media.clone(),