Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

feat(timeline): the magnetic timeline, a switch that closes every gap

Jareer25a388f15995
diff --git a/src/crates/concat-host/tests/export.rs b/src/crates/concat-host/tests/export.rs
index 2c2977c7..b00a9677 100644
--- a/src/crates/concat-host/tests/export.rs
+++ b/src/crates/concat-host/tests/export.rs
@@ -664,6 +664,7 @@ fn every_edit_still_exports() {
clip_id: tail.clone(),
edge: TrimEdge::Start,
delta: 0.5,
+ ripple: false,
});
let exported = studio.export("trimmed");
exported.expect_black(2.25);
@@ -811,6 +812,7 @@ fn every_edit_still_exports() {
clip_id: cam_clip.clone(),
edge: TrimEdge::Start,
delta: 1.0,
+ ripple: false,
});
for kind in [
"cross-fade",
@@ -1150,6 +1152,7 @@ fn the_edges_export_too() {
clip_id: clip.clone(),
edge: TrimEdge::Start,
delta: 4.0 - 1.0 / 30.0,
+ ripple: false,
});
let length = studio.clip(&clip).duration;
assert!(
@@ -1176,6 +1179,7 @@ fn the_edges_export_too() {
clip_id: clip.clone(),
edge: TrimEdge::Start,
delta: 3.0,
+ ripple: false,
});
studio.apply(Command::SetClipSpeed {
clip_id: clip.clone(),
diff --git a/src/crates/concat-project/src/commands/clips.rs b/src/crates/concat-project/src/commands/clips.rs
index 2db31e28..36d8bcc2 100644
--- a/src/crates/concat-project/src/commands/clips.rs
+++ b/src/crates/concat-project/src/commands/clips.rs
@@ -177,12 +177,19 @@ pub(super) fn apply(
clip_id,
edge,
delta,
+ ripple,
} => {
let timeline = project.active_mut();
let Some(clip) = timeline.clip_mut(&clip_id) else {
return Ok(Outcome::default());
};
- let applied = match edge {
+ let track_id = clip.track_id.clone();
+ let anchor = clip.start;
+ let old_end = clip.start + clip.duration;
+ // What the trim did, and what the lane behind it does about
+ // it when it is magnetic: `by` is how far the later clips
+ // move, `behind` where "later" begins.
+ let (applied, by, behind) = match edge {
TrimEdge::End => {
let duration = (clip.duration + delta).max(MIN_CLIP_DURATION);
let old = clip.duration;
@@ -190,7 +197,7 @@ pub(super) fn apply(
if applied {
clip.rewindow_keys(old, 0.0, duration);
}
- applied
+ (applied, duration - old, old_end - JOIN_EPSILON)
}
TrimEdge::Start => {
// Dragging the head moves the in-point too, so the pixels
@@ -203,7 +210,14 @@ pub(super) fn apply(
// The head cannot reach before the source begins.
shift = shift.max(-clip.source_start / clip.speed);
}
- let start = (clip.start + shift).max(0.0);
+ // A magnetic head trim never moves the clip, so the
+ // timeline's own start is no limit to it; a plain one
+ // stops at zero.
+ let start = if ripple {
+ clip.start + shift
+ } else {
+ (clip.start + shift).max(0.0)
+ };
let moved = start - clip.start;
let duration = clip.duration - moved;
let source_start = if clip.reverse {
@@ -219,9 +233,21 @@ pub(super) fn apply(
if applied {
clip.rewindow_keys(old, moved, old);
}
- applied
+ if ripple {
+ // The in-point moved; the clip stays put, and the
+ // lane behind it closes by what came off the head.
+ clip.start = anchor;
+ }
+ (applied, -moved, anchor + JOIN_EPSILON)
}
};
+ if ripple && applied && by != 0.0 {
+ for other in timeline.clips_mut() {
+ if other.id != clip_id && other.track_id == track_id && other.start >= behind {
+ other.start = (other.start + by).max(0.0);
+ }
+ }
+ }
Ok(Outcome {
created_id: None,
applied,
diff --git a/src/crates/concat-project/src/commands/mod.rs b/src/crates/concat-project/src/commands/mod.rs
index 6fac7d2d..d5c5a675 100644
--- a/src/crates/concat-project/src/commands/mod.rs
+++ b/src/crates/concat-project/src/commands/mod.rs
@@ -461,6 +461,15 @@ pub enum Command {
/// Signed seconds of timeline the edge moves: positive drags the
/// head right (shortening) or the tail right (lengthening).
delta: f64,
+ /// When true the lane closes up behind the trim - the magnetic
+ /// timeline. A tail trim moves every later clip on the track by
+ /// the change in length. A head trim keeps the clip where it was
+ /// (the in-point moves, the start does not) and moves every later
+ /// clip by what was cut or restored, so the trimmed clip and the
+ /// one behind it stay touching. False trims the clip alone.
+ /// https://github.com/jub0t/Concat/issues/106
+ #[serde(default)]
+ ripple: bool,
},
/// Cuts each named clip in two at one playhead time. The head keeps the
/// id and the transition; the tail is minted fresh and stays
diff --git a/src/crates/concat-project/src/lib.rs b/src/crates/concat-project/src/lib.rs
index 5adfdd3b..5375c425 100644
--- a/src/crates/concat-project/src/lib.rs
+++ b/src/crates/concat-project/src/lib.rs
@@ -369,6 +369,217 @@ mod tests {
}
}
+ // ── magnetic trim: https://github.com/jub0t/Concat/issues/106 ──
+
+ fn trim(clip_id: &str, edge: TrimEdge, delta: f64, ripple: bool) -> Command {
+ Command::TrimClip {
+ clip_id: clip_id.to_owned(),
+ edge,
+ delta,
+ ripple,
+ }
+ }
+
+ #[test]
+ fn magnetic_tail_trim_moves_the_lane_behind_it_both_ways() {
+ let (mut editor, media_id, first) = fixture();
+ let (video, sound) = {
+ let tracks = &editor.project().active().tracks;
+ (tracks[0].id.clone(), tracks[1].id.clone())
+ };
+ let behind = lane(&mut editor, &media_id, &video, &[10.0, 20.0]);
+ let other = lane(&mut editor, &media_id, &sound, &[12.0]);
+
+ editor
+ .apply(trim(&first, TrimEdge::End, -2.0, true))
+ .expect("shortens");
+ assert_eq!(start_of(&editor, &behind[0]), 8.0, "closes up");
+ assert_eq!(
+ start_of(&editor, &behind[1]),
+ 18.0,
+ "and the one behind that"
+ );
+ assert_eq!(start_of(&editor, &other[0]), 12.0, "another lane stays");
+
+ editor
+ .apply(trim(&first, TrimEdge::End, 3.0, true))
+ .expect("lengthens");
+ assert_eq!(start_of(&editor, &behind[0]), 11.0, "makes room");
+ assert_eq!(start_of(&editor, &behind[1]), 21.0);
+ }
+
+ #[test]
+ fn a_plain_trim_still_leaves_the_lane_alone() {
+ let (mut editor, media_id, first) = fixture();
+ let video = editor.project().active().tracks[0].id.clone();
+ let behind = lane(&mut editor, &media_id, &video, &[10.0]);
+ editor
+ .apply(trim(&first, TrimEdge::End, -2.0, false))
+ .expect("shortens");
+ assert_eq!(start_of(&editor, &behind[0]), 10.0);
+ }
+
+ #[test]
+ fn magnetic_head_trim_keeps_the_clip_where_it_was_and_closes_behind_it() {
+ let (mut editor, media_id, first) = fixture();
+ let video = editor.project().active().tracks[0].id.clone();
+ let behind = lane(&mut editor, &media_id, &video, &[10.0]);
+ editor
+ .apply(trim(&first, TrimEdge::Start, 2.0, true))
+ .expect("trims the head");
+ let clip = editor
+ .project()
+ .active()
+ .clip(&first)
+ .expect("kept")
+ .clone();
+ assert_eq!(clip.start, 0.0, "the clip does not move");
+ assert_eq!(clip.duration, 8.0);
+ assert_eq!(clip.source_start, 2.0, "the in-point does");
+ assert_eq!(start_of(&editor, &behind[0]), 8.0, "and the lane closes");
+ }
+
+ #[test]
+ fn a_plain_head_trim_moves_the_head_and_nothing_else() {
+ let (mut editor, media_id, first) = fixture();
+ let video = editor.project().active().tracks[0].id.clone();
+ let behind = lane(&mut editor, &media_id, &video, &[10.0]);
+ editor
+ .apply(trim(&first, TrimEdge::Start, 2.0, false))
+ .expect("trims the head");
+ assert_eq!(start_of(&editor, &first), 2.0);
+ assert_eq!(start_of(&editor, &behind[0]), 10.0);
+ }
+
+ #[test]
+ fn magnetic_head_trim_can_reach_back_only_as_far_as_the_source_and_moves_nothing_when_it_cannot()
+ {
+ let (mut editor, media_id, first) = fixture();
+ let video = editor.project().active().tracks[0].id.clone();
+ let behind = lane(&mut editor, &media_id, &video, &[10.0]);
+ let before_can_undo = editor.can_undo();
+ // In-point at zero: there is nothing before it to restore.
+ let outcome = editor
+ .apply(trim(&first, TrimEdge::Start, -3.0, true))
+ .expect("tolerated");
+ assert!(!outcome.applied);
+ assert_eq!(start_of(&editor, &behind[0]), 10.0);
+ assert_eq!(editor.can_undo(), before_can_undo, "a no-op is not a step");
+ }
+
+ #[test]
+ fn magnetic_head_trim_restoring_source_pushes_the_lane_back() {
+ let (mut editor, media_id, first) = fixture();
+ let video = editor.project().active().tracks[0].id.clone();
+ let behind = lane(&mut editor, &media_id, &video, &[10.0]);
+ editor
+ .apply(trim(&first, TrimEdge::Start, 4.0, true))
+ .expect("cuts four off the head");
+ assert_eq!(start_of(&editor, &behind[0]), 6.0);
+ // Ask for five back: only four exist, so four come back.
+ editor
+ .apply(trim(&first, TrimEdge::Start, -5.0, true))
+ .expect("restores what there is");
+ let clip = editor
+ .project()
+ .active()
+ .clip(&first)
+ .expect("kept")
+ .clone();
+ assert_eq!(
+ clip.start, 0.0,
+ "a magnetic clip at zero still does not move"
+ );
+ assert_eq!(clip.source_start, 0.0);
+ assert_eq!(clip.duration, 10.0);
+ assert_eq!(
+ start_of(&editor, &behind[0]),
+ 10.0,
+ "the lane went back by four"
+ );
+ }
+
+ #[test]
+ fn magnetic_trim_stops_at_the_minimum_and_the_lane_stays_touching() {
+ let (mut editor, media_id, first) = fixture();
+ let video = editor.project().active().tracks[0].id.clone();
+ let behind = lane(&mut editor, &media_id, &video, &[10.0]);
+ editor
+ .apply(trim(&first, TrimEdge::End, -100.0, true))
+ .expect("clamps");
+ let clip = editor
+ .project()
+ .active()
+ .clip(&first)
+ .expect("kept")
+ .clone();
+ assert!(
+ clip.duration > 0.0 && clip.duration < 1.0,
+ "floored at the minimum"
+ );
+ let gap = start_of(&editor, &behind[0]) - (clip.start + clip.duration);
+ assert!(
+ gap.abs() < 1e-9,
+ "the lane moved by the clamped amount, not the asked one: gap {gap}"
+ );
+ }
+
+ #[test]
+ fn magnetic_trim_leaves_a_clip_in_front_of_the_edge_alone() {
+ let (mut editor, media_id, first) = fixture();
+ let video = editor.project().active().tracks[0].id.clone();
+ // A clip behind the trimmed one, and one stacked before its tail
+ // on the same lane: a tail trim is about what is behind the tail.
+ let more = lane(&mut editor, &media_id, &video, &[10.0, 3.0]);
+ editor
+ .apply(trim(&first, TrimEdge::End, -2.0, true))
+ .expect("shortens");
+ assert_eq!(start_of(&editor, &more[0]), 8.0);
+ assert_eq!(
+ start_of(&editor, &more[1]),
+ 3.0,
+ "in front of the edge; not moved"
+ );
+ }
+
+ #[test]
+ fn magnetic_trim_is_one_undo_step_that_puts_the_lane_back() {
+ let (mut editor, media_id, first) = fixture();
+ let video = editor.project().active().tracks[0].id.clone();
+ let behind = lane(&mut editor, &media_id, &video, &[10.0]);
+ editor
+ .apply(trim(&first, TrimEdge::Start, 2.0, true))
+ .expect("trims");
+ assert_eq!(start_of(&editor, &behind[0]), 8.0);
+ assert!(editor.undo());
+ assert_eq!(start_of(&editor, &behind[0]), 10.0);
+ let clip = editor
+ .project()
+ .active()
+ .clip(&first)
+ .expect("kept")
+ .clone();
+ assert_eq!(
+ (clip.start, clip.duration, clip.source_start),
+ (0.0, 10.0, 0.0)
+ );
+ }
+
+ #[test]
+ fn a_trim_clip_document_without_the_ripple_field_still_parses_as_a_plain_trim() {
+ let command: Command = serde_json::from_value(json!({
+ "op": "trimClip",
+ "clipId": "c1",
+ "edge": "end",
+ "delta": -1.0
+ }))
+ .expect("the field is new; old callers do not send it");
+ match command {
+ Command::TrimClip { ripple, .. } => assert!(!ripple),
+ _ => panic!("not a trim"),
+ }
+ }
+
#[test]
fn a_new_project_has_one_timeline_and_four_lanes() {
let editor = Editor::new();
@@ -616,6 +827,7 @@ mod tests {
clip_id: clip_id.clone(),
edge: TrimEdge::Start,
delta: 3.0,
+ ripple: false,
})
.expect("trims");
let clip = &editor.project().active().clips[0];
@@ -646,6 +858,7 @@ mod tests {
clip_id: clip_id.clone(),
edge: TrimEdge::Start,
delta: -4.0,
+ ripple: false,
})
.expect("trims");
let clip = &editor.project().active().clips[0];
@@ -735,6 +948,7 @@ mod tests {
clip_id: clip_id.clone(),
edge: TrimEdge::End,
delta: f64::NAN,
+ ripple: false,
}],
},
] {
@@ -1154,6 +1368,7 @@ mod tests {
clip_id: tail.id.clone(),
edge: TrimEdge::Start,
delta: 1.0,
+ ripple: false,
})
.expect("trims");
let trimmed = editor
@@ -1177,6 +1392,7 @@ mod tests {
clip_id: tail.id.clone(),
edge: TrimEdge::Start,
delta: -1.0,
+ ripple: false,
})
.expect("trims back");
@@ -1206,6 +1422,7 @@ mod tests {
clip_id: clip_id.clone(),
edge: TrimEdge::End,
delta: 10.0,
+ ripple: false,
})
.expect("extends");
let longer = editor
@@ -1371,6 +1588,7 @@ mod tests {
clip_id,
edge: TrimEdge::Start,
delta: 1.0,
+ ripple: false,
})
.expect("trims");
let clip = &editor.project().active().clips[0];
@@ -1875,6 +2093,7 @@ mod tests {
clip_id,
edge: TrimEdge::Start,
delta: 2.0,
+ ripple: false,
})
.expect("trims");
editor
@@ -2281,6 +2500,7 @@ mod tests {
clip_id: "nope".to_owned(),
edge: TrimEdge::End,
delta: 1.0,
+ ripple: false,
})
.expect("tolerated");
assert!(!outcome.applied);
@@ -2356,6 +2576,7 @@ mod tests {
clip_id: "nope".to_owned(),
edge: TrimEdge::End,
delta: 1.0,
+ ripple: false,
},
],
})
@@ -2450,6 +2671,7 @@ mod tests {
clip_id: clip_id.clone(),
edge: TrimEdge::End,
delta: -4.0,
+ ripple: false,
})
.expect("trims");
let clip = editor.project().active().clip(&clip_id).expect("exists");
@@ -2464,6 +2686,7 @@ mod tests {
clip_id: clip_id.clone(),
edge: TrimEdge::End,
delta: -100.0,
+ ripple: false,
})
.expect("trims");
assert_eq!(
@@ -2882,6 +3105,7 @@ mod tests {
clip_id: "c1".to_owned(),
edge: TrimEdge::End,
delta: -0.5,
+ ripple: false,
},
Command::SplitClips {
clip_ids: vec!["c1".to_owned()],
diff --git a/src/crates/concat/locales/en.json b/src/crates/concat/locales/en.json
index 8614d583..e1e97cd0 100644
--- a/src/crates/concat/locales/en.json
+++ b/src/crates/concat/locales/en.json
@@ -118,6 +118,7 @@
"Clear project cache": "Clear project cache",
"Clears the room out of a recording: rumble, hiss, sibilance and uneven level.": "Clears the room out of a recording: rumble, hiss, sibilance and uneven level.",
"Clips": "Clips",
+ "Close gaps when deleting and trimming": "Close gaps when deleting and trimming",
"Close project": "Close project",
"Close window": "Close window",
"Cloudless Sky": "Cloudless Sky",
@@ -360,6 +361,8 @@
"Lower third": "Lower third",
"LUT": "LUT",
"Magenta in the shadows, cyan in the highlights, hard contrast, colour turned up, and the lights themselves blooming. Night streets and signage.": "Magenta in the shadows, cyan in the highlights, hard contrast, colour turned up, and the lights themselves blooming. Night streets and signage.",
+ "Magnetic timeline": "Magnetic timeline",
+ "Magnetic timeline: deleting and trimming close the gap": "Magnetic timeline: deleting and trimming close the gap",
"male": "male",
"Marquee": "Marquee",
"Mask": "Mask",
@@ -433,6 +436,7 @@
"Off": "Off",
"off": "off",
"Off, a click on the ruler past the last clip lands the playhead there, and a clip placed at the playhead goes with it. On, the playhead never leaves the content.": "Off, a click on the ruler past the last clip lands the playhead there, and a clip placed at the playhead goes with it. On, the playhead never leaves the content.",
+ "On, deleting a clip pulls what follows it on the same track into the gap, and trimming an edge moves the rest of the track with it. Off, a delete leaves a gap and a trim moves only the edge. Shift-Delete closes the gap either way.": "On, deleting a clip pulls what follows it on the same track into the gap, and trimming an edge moves the rest of the track with it. Off, a delete leaves a gap and a trim moves only the edge. Shift-Delete closes the gap either way.",
"On, video decodes on this machine's own hardware, which is what makes 4K play on a laptop. A file the hardware will not take decodes in software as before.": "On, video decodes on this machine's own hardware, which is what makes 4K play on a laptop. A file the hardware will not take decodes in software as before.",
"One repeat, fading.": "One repeat, fading.",
"One title per phrase spoken, cut to the words' own timing, on the first lane with room.": "One title per phrase spoken, cut to the words' own timing, on the first lane with room.",
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 4adc9c25..e4ea1454 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -629,6 +629,9 @@ pub fn run() -> Result<(), slint::PlatformError> {
editor.on_snap_changed(on_window!(|state, snap: bool| {
state.handle(Msg::Timeline(TimelineMsg::SnapChanged(snap)));
}));
+ editor.on_magnetic_changed(on_window!(|state, on: bool| {
+ state.handle(Msg::Timeline(TimelineMsg::MagneticChanged(on)));
+ }));
editor.on_add_track(on_window!(|state| {
state.apply(concat_project::Command::AddTrack);
}));
@@ -924,7 +927,8 @@ pub fn run() -> Result<(), slint::PlatformError> {
app.global::<Focus>()
.on_release(|| Shell::with(|_, app| app.invoke_blur()));
editor.on_shortcut(move |action: SharedString| match action.as_str() {
- "import" | "export" | "settings" | "zoom-in" | "zoom-out" | "start" | "end" | "snap" => {
+ "import" | "export" | "settings" | "zoom-in" | "zoom-out" | "start" | "end" | "snap"
+ | "magnetic" => {
Shell::with(|_, app| app.invoke_app_menu_selected(action.clone()));
}
_ => Shell::with(|shell, app| {
@@ -1036,6 +1040,9 @@ pub fn run() -> Result<(), slint::PlatformError> {
app.on_settings_custom_context_actions_changed(on_window!(|state, on: bool| {
state.handle(Msg::Settings(SettingsMsg::CustomContextActionsChanged(on)));
}));
+ app.on_settings_magnetic_changed(on_window!(|state, on: bool| {
+ state.handle(Msg::Settings(SettingsMsg::MagneticChanged(on)));
+ }));
app.on_settings_hardware_decode_changed(on_window!(|state, on: bool| {
state.handle(Msg::Settings(SettingsMsg::HardwareDecodeChanged(on)));
}));
@@ -1169,6 +1176,7 @@ pub fn run() -> Result<(), slint::PlatformError> {
"undo" => state.undo(),
"redo" => state.redo(),
"snap" => state.handle(Msg::Timeline(TimelineMsg::SnapToggled)),
+ "magnetic" => state.handle(Msg::Timeline(TimelineMsg::MagneticToggled)),
"sort-added" => state.handle(Msg::Media(MediaMsg::SortChanged(0))),
"sort-name" => state.handle(Msg::Media(MediaMsg::SortChanged(1))),
"sort-kind" => state.handle(Msg::Media(MediaMsg::SortChanged(2))),
diff --git a/src/crates/concat/src/panes/settings.rs b/src/crates/concat/src/panes/settings.rs
index 43633868..def78f13 100644
--- a/src/crates/concat/src/panes/settings.rs
+++ b/src/crates/concat/src/panes/settings.rs
@@ -40,6 +40,8 @@ pub enum SettingsMsg {
LanguageChanged(i32),
PlayheadStopsChanged(bool),
CustomContextActionsChanged(bool),
+ /// The magnetic timeline switch; the tray's button is the same fact.
+ MagneticChanged(bool),
HardwareDecodeChanged(bool),
DownloadSourceChanged(i32),
DownloadBaseEdited(String),
@@ -213,6 +215,10 @@ impl SettingsPane {
studio.prefs.custom_context_actions = on;
studio.prefs.save(&studio.host.dirs);
}
+ SettingsMsg::MagneticChanged(on) => {
+ studio.prefs.magnetic = on;
+ studio.prefs.save(&studio.host.dirs);
+ }
SettingsMsg::HardwareDecodeChanged(on) => {
self.hardware_decode = on;
studio.prefs.hardware_decode = Some(on);
@@ -546,6 +552,7 @@ impl SettingsPane {
language: self.language as i32,
playhead_stops: self.playhead_stops,
custom_context_actions: self.custom_context_actions,
+ magnetic: studio.prefs.magnetic,
hardware_decode: self.hardware_decode,
hardware_decode_offered: concat_media::HwDevice::platform_default()
.is_some_and(concat_media::HwDevice::linked),
diff --git a/src/crates/concat/src/panes/timeline.rs b/src/crates/concat/src/panes/timeline.rs
index 49723320..1cfebd15 100644
--- a/src/crates/concat/src/panes/timeline.rs
+++ b/src/crates/concat/src/panes/timeline.rs
@@ -52,6 +52,12 @@ pub enum TimelineMsg {
SnapChanged(bool),
/// The menu's Snap row: the other way round.
SnapToggled,
+ /// The magnetic timeline, from the tray's button or the Settings
+ /// switch. A preference, not view state: it is remembered.
+ /// https://github.com/jub0t/Concat/issues/106
+ MagneticChanged(bool),
+ /// The menu's Magnetic row: the other way round.
+ MagneticToggled,
/// The lanes scrolled sideways, to this many seconds from the start.
Scrolled(f32),
/// The wheel or a pinch: by a factor, about an instant; an anchor
@@ -108,6 +114,14 @@ impl TimelinePane {
TimelineMsg::PanChanged(on) => self.pan_mode = on,
TimelineMsg::SnapChanged(on) => self.snap = on,
TimelineMsg::SnapToggled => self.snap = !self.snap,
+ TimelineMsg::MagneticChanged(on) => {
+ studio.prefs.magnetic = on;
+ studio.prefs.save(&studio.host.dirs);
+ }
+ TimelineMsg::MagneticToggled => {
+ studio.prefs.magnetic = !studio.prefs.magnetic;
+ studio.prefs.save(&studio.host.dirs);
+ }
TimelineMsg::Scrolled(seconds) => self.scroll_left = seconds.max(0.0),
TimelineMsg::Zoomed { factor, anchor } => self.zoom(factor, anchor),
TimelineMsg::ZoomToFit(width) => {
diff --git a/src/crates/concat/src/prefs.rs b/src/crates/concat/src/prefs.rs
index ed81934d..b998750a 100644
--- a/src/crates/concat/src/prefs.rs
+++ b/src/crates/concat/src/prefs.rs
@@ -37,6 +37,11 @@ pub struct Preferences {
/// Show flip horizontal, flip vertical, and reverse in the clip context
/// menu. Keyboard shortcuts (H, J, R) are always available.
pub custom_context_actions: bool,
+ /// The magnetic timeline: a delete and a trim close the gap they would
+ /// leave, on the lane they happen on. Off by default, because a gap is
+ /// sometimes the point; ⇧⌫ ripples either way.
+ /// https://github.com/jub0t/Concat/issues/106
+ pub magnetic: bool,
/// Video decodes on the platform's own hardware where it has some:
/// VideoToolbox on a Mac. `None` is the platform's default, which is on
/// where the hardware path has been exercised (macOS and iOS) and off
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index f84082ef..48da4035 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -2866,6 +2866,9 @@ impl Studio {
Edge::End => TrimEdge::End,
},
delta,
+ // Magnetic: the lane closes behind the edge.
+ // https://github.com/jub0t/Concat/issues/106
+ ripple: self.prefs.magnetic,
});
}
}
@@ -4227,9 +4230,11 @@ impl Studio {
}
}
- /// Delete: the selection goes and the hole stays.
+ /// Delete: the selection goes, and the hole stays unless the timeline
+ /// is magnetic.
pub fn delete_selected(&mut self) {
- self.remove_selected(false);
+ let magnetic = self.prefs.magnetic;
+ self.remove_selected(magnetic);
}
/// Ripple delete (⇧⌫): the selection goes and each lane closes behind
@@ -4432,6 +4437,7 @@ impl Studio {
clip_id: created.clone(),
edge: TrimEdge::Start,
delta: head,
+ ripple: false,
});
}
let after_head = placed.duration - head.max(0.0);
@@ -4441,6 +4447,7 @@ impl Studio {
clip_id: created.clone(),
edge: TrimEdge::End,
delta: tail,
+ ripple: false,
});
}
commands.push(Command::UpdateClip {
@@ -5003,6 +5010,7 @@ impl Studio {
editor.set_frame_rate(self.frame_rate());
editor.set_tool(self.lanes.tool);
editor.set_snap(self.lanes.snap);
+ editor.set_magnetic(self.prefs.magnetic);
editor.set_pan_mode(self.lanes.pan_mode);
editor.set_selected_count(self.selection.len() as i32);
let (sound_selected, title_selected) = self.sound_tools();
@@ -5995,6 +6003,17 @@ impl Studio {
checkable: true,
checked: self.lanes.snap,
},
+ MenuItemData {
+ id: "magnetic".into(),
+ label: t("Magnetic timeline").into(),
+ kind: MenuRow::Action,
+ glyph: Glyph::None,
+ shortcut: "".into(),
+ enabled: true,
+ danger: false,
+ checkable: true,
+ checked: self.prefs.magnetic,
+ },
],
2 => vec![
row("zoom-in", t("Zoom in"), Glyph::Plus, "+", true),
@@ -6268,7 +6287,7 @@ impl Studio {
// A clip that is part of the selection takes the selection with
// it: Delete on one of five selected clips means the five.
"delete" | "ripple-delete" => {
- let ripple = action == "ripple-delete";
+ let ripple = action == "ripple-delete" || self.prefs.magnetic;
if self.selection.len() > 1 && self.selection.iter().any(|held| held == id) {
self.remove_selected(ripple);
} else {
diff --git a/src/crates/concat/ui/app.slint b/src/crates/concat/ui/app.slint
index 8d972feb..25e81351 100644
--- a/src/crates/concat/ui/app.slint
+++ b/src/crates/concat/ui/app.slint
@@ -197,6 +197,7 @@ export component App inherits Window {
callback settings-theme-changed(dark: bool);
callback settings-playhead-stops-changed(on: bool);
callback settings-custom-context-actions-changed(on: bool);
+ callback settings-magnetic-changed(on: bool);
callback settings-hardware-decode-changed(on: bool);
callback settings-download-source-changed(index: int);
callback settings-download-base-edited(text: string);
@@ -505,6 +506,7 @@ export component App inherits Window {
theme-changed(dark) => { root.settings-theme-changed(dark); }
playhead-stops-changed(on) => { root.settings-playhead-stops-changed(on); }
custom-context-actions-changed(on) => { root.settings-custom-context-actions-changed(on); }
+ magnetic-changed(on) => { root.settings-magnetic-changed(on); }
hardware-decode-changed(on) => { root.settings-hardware-decode-changed(on); }
download-source-changed(index) => { root.settings-download-source-changed(index); }
download-base-edited(text) => { root.settings-download-base-edited(text); }
diff --git a/src/crates/concat/ui/dialogs/settings.slint b/src/crates/concat/ui/dialogs/settings.slint
index c347a612..e5a94514 100644
--- a/src/crates/concat/ui/dialogs/settings.slint
+++ b/src/crates/concat/ui/dialogs/settings.slint
@@ -52,6 +52,8 @@ export struct SettingsData {
playhead-stops: bool,
/// show flip/reverse in clip context menu
custom-context-actions: bool,
+ /// the magnetic timeline: deleting and trimming close the gap
+ magnetic: bool,
/// video decodes on the platform's own hardware
hardware-decode: bool,
/// this build and machine have hardware to decode on; off, the
@@ -367,6 +369,7 @@ export component SettingsDialog inherits Modal {
callback theme-changed(dark: bool);
callback playhead-stops-changed(on: bool);
callback custom-context-actions-changed(on: bool);
+ callback magnetic-changed(on: bool);
callback hardware-decode-changed(on: bool);
callback download-source-changed(index: int);
callback download-base-edited(text: string);
@@ -489,6 +492,36 @@ export component SettingsDialog inherits Modal {
}
}
+ // Off, a delete leaves its hole and a trim moves one edge.
+ // On, the lane closes up behind either - the magnetic
+ // timeline of CapCut and the rest, asked for in
+ // https://github.com/jub0t/Concat/issues/106
+ DialogSection {
+ title: I18n.t("Magnetic timeline");
+ hint: I18n.t("On, deleting a clip pulls what follows it on the same track into the gap, and trimming an edge moves the rest of the track with it. Off, a delete leaves a gap and a trim moves only the edge. Shift-Delete closes the gap either way.");
+
+ HorizontalLayout {
+ spacing: 6px;
+
+ Text {
+ text: I18n.t("Close gaps when deleting and trimming");
+ color: Theme.fg;
+ font-size: Theme.fs;
+ vertical-alignment: center;
+ }
+
+ Rectangle { horizontal-stretch: 1; }
+
+ VerticalLayout {
+ alignment: center;
+ Switch {
+ checked: root.data.magnetic;
+ toggled(on) => { root.magnetic-changed(on); }
+ }
+ }
+ }
+ }
+
// Off, the playhead goes wherever the ruler is clicked, past
// the last clip included, so a clip can be placed out there.
// On, it stops where the content does.
diff --git a/src/crates/concat/ui/editor.slint b/src/crates/concat/ui/editor.slint
index 947ade8c..35ec0838 100644
--- a/src/crates/concat/ui/editor.slint
+++ b/src/crates/concat/ui/editor.slint
@@ -230,6 +230,10 @@ export global Editor {
in-out property <[ClipData]> clips;
in-out property <TimelineTool> tool;
in-out property <bool> snap;
+ /// The magnetic timeline: a delete or a trim closes the gap it would
+ /// leave. A remembered preference, which Rust owns; the tray's button
+ /// and the Settings switch both show it.
+ in-out property <bool> magnetic;
/// Hand tool: wheel and drag pan time instead of scrolling the stack.
in-out property <bool> pan-mode: false;
in-out property <int> selected-count;
@@ -250,6 +254,7 @@ export global Editor {
callback tab-added();
callback tool-changed(tool: TimelineTool);
callback snap-changed(snap: bool);
+ callback magnetic-changed(on: bool);
callback pan-changed(on: bool);
callback split();
callback merge();
diff --git a/src/crates/concat/ui/icons.slint b/src/crates/concat/ui/icons.slint
index 118b341d..e080adcc 100644
--- a/src/crates/concat/ui/icons.slint
+++ b/src/crates/concat/ui/icons.slint
@@ -92,6 +92,7 @@ export enum Glyph {
merge,
trash,
magnet,
+ fold,
waveform,
filter,
eye-off,
@@ -489,6 +490,14 @@ export component Icon inherits Rectangle {
+ " 1.704 0l6.365-6.367A1 1 0 0 0 8.716 4.282z M5 8l4 4";
}
+ // lucide/fold-horizontal: two arrows closing on a dashed seam, for the
+ // magnetic timeline - the lane folding shut over a gap.
+ if root.glyph == Glyph.fold: Stroked {
+ size: root.size; tint: root.tint; weight: root.weight;
+ commands: "M2 12h6 M22 12h-6 M12 2v2 M12 8v2 M12 14v2 M12 20v2"
+ + " M19 9l-3 3 3 3 M5 15l3-3-3-3";
+ }
+
// lucide/blend: two circles overlapping, for a filter - a look laid
// over whatever plays under it.
if root.glyph == Glyph.filter: Stroked {
diff --git a/src/crates/concat/ui/timeline/tray.slint b/src/crates/concat/ui/timeline/tray.slint
index 58972aef..fefac3d2 100644
--- a/src/crates/concat/ui/timeline/tray.slint
+++ b/src/crates/concat/ui/timeline/tray.slint
@@ -46,6 +46,7 @@ component Divider inherits Rectangle {
export component TimelineTray inherits Rectangle {
in property <TimelineTool> tool: TimelineTool.select;
in property <bool> snap: true;
+ in property <bool> magnetic: false;
in property <bool> pan-mode: false;
in property <int> selected-count;
/// Empty when the selection can be merged; otherwise why it cannot.
@@ -59,6 +60,7 @@ export component TimelineTray inherits Rectangle {
callback tool-changed(tool: TimelineTool);
callback snap-changed(snap: bool);
+ callback magnetic-changed(on: bool);
callback pan-changed(on: bool);
callback split();
callback merge();
@@ -171,6 +173,16 @@ export component TimelineTray inherits Rectangle {
checked: root.snap;
clicked => { root.snap-changed(!root.snap); }
}
+ // The magnetic timeline, beside the snap it is so often mistaken
+ // for: snap is where a drag lands, magnetic is that a delete or a
+ // trim leaves no hole. https://github.com/jub0t/Concat/issues/106
+ IconButton {
+ glyph: Glyph.fold;
+ label: I18n.t("Magnetic timeline: deleting and trimming close the gap");
+ icon-size: 16px;
+ checked: root.magnetic;
+ clicked => { root.magnetic-changed(!root.magnetic); }
+ }
Divider { }
diff --git a/src/crates/concat/ui/workspace/seat.slint b/src/crates/concat/ui/workspace/seat.slint
index b6c024fe..606b7427 100644
--- a/src/crates/concat/ui/workspace/seat.slint
+++ b/src/crates/concat/ui/workspace/seat.slint
@@ -317,6 +317,7 @@ export component Seat inherits Rectangle {
tab-moved(from, to) => { Editor.tab-moved(from, to); }
tool-changed(tool) => { Editor.tool-changed(tool); }
snap-changed(snap) => { Editor.snap-changed(snap); }
+ magnetic-changed(on) => { Editor.magnetic-changed(on); }
pan-changed(on) => { Editor.pan-changed(on); }
split => { Editor.split(); }
merge => { Editor.merge(); }
diff --git a/src/crates/concat/ui/workspace/timeline-pane.slint b/src/crates/concat/ui/workspace/timeline-pane.slint
index e75448d8..212b2a49 100644
--- a/src/crates/concat/ui/workspace/timeline-pane.slint
+++ b/src/crates/concat/ui/workspace/timeline-pane.slint
@@ -44,6 +44,7 @@ export component TimelinePane inherits Rectangle {
callback tool-changed(tool: TimelineTool);
callback snap-changed(snap: bool);
+ callback magnetic-changed(on: bool);
callback pan-changed(on: bool);
callback split();
callback merge();
@@ -187,6 +188,7 @@ export component TimelinePane inherits Rectangle {
tool-changed(tool) => { root.tool-changed(tool); }
snap-changed(snap) => { root.snap-changed(snap); }
+ magnetic-changed(on) => { root.magnetic-changed(on); }
pan-changed(on) => { root.pan-changed(on); }
split => { root.split(); }
merge => { root.merge(); }