Skip to content

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

feat(timeline): keyframe diamonds on the ruler, scrolling at the edge, a drop that slots in, a waveform about the centre, and a detached pair that moves together

Jareerf236c9573dbf
diff --git a/src/crates/concat-project/src/commands/clips.rs b/src/crates/concat-project/src/commands/clips.rs
index 10b1d7da..76a98ecc 100644
--- a/src/crates/concat-project/src/commands/clips.rs
+++ b/src/crates/concat-project/src/commands/clips.rs
@@ -29,9 +29,11 @@ pub(super) fn apply(
if timeline.track(&track_id).is_none() {
return Err(CommandError::TrackGone);
}
- if ripple {
- ripple_room_for(timeline, &track_id, start, &media);
- }
+ let start = if ripple {
+ ripple_room_for(timeline, &track_id, start, &media)
+ } else {
+ start
+ };
let id = mint.next("c");
timeline
.clips
@@ -633,24 +635,36 @@ fn default_clip(id: String, track_id: String, media: &MediaItem, start: f64) ->
clip
}
-/// Shifts every clip on `track_id` at or after `start` right by the
-/// duration the new clip will take, when the new clip would overlap
-/// something already there. A drop with room to spare changes nothing.
-fn ripple_room_for(timeline: &mut Timeline, track_id: &str, start: f64, media: &MediaItem) {
+/// Makes room on `track_id` for a new clip at `start`: a drop onto the
+/// middle of a clip lands at that clip's end instead, and every clip at
+/// or after the place it lands moves right by the new clip's length, so
+/// the new clip slots in and nothing is covered (#129). Returns where the
+/// new clip lands. A drop with room to spare changes nothing.
+fn ripple_room_for(timeline: &mut Timeline, track_id: &str, start: f64, media: &MediaItem) -> f64 {
let duration = match media.kind {
MediaKind::Image => DEFAULT_IMAGE_DURATION,
_ => media.duration.unwrap_or(UNKNOWN_DURATION),
};
+ // Dropped onto a clip: after it, rather than over it or through it.
+ let start = timeline
+ .clips
+ .iter()
+ .filter(|clip| {
+ clip.track_id == track_id && clip.start < start && start < clip.start + clip.duration
+ })
+ .map(|clip| clip.start + clip.duration)
+ .fold(start, f64::max);
let end = start + duration;
let overlaps = timeline.clips.iter().any(|clip| {
clip.track_id == track_id && clip.start < end && start < clip.start + clip.duration
});
if !overlaps {
- return;
+ return start;
}
for clip in timeline.clips_where(|clip| clip.track_id == track_id && clip.start >= start) {
clip.start += duration;
}
+ start
}
/// The lowest track with nothing occupying `[start, start + duration)`,
diff --git a/src/crates/concat/src/format.rs b/src/crates/concat/src/format.rs
index f8073dd8..75c3b739 100644
--- a/src/crates/concat/src/format.rs
+++ b/src/crates/concat/src/format.rs
@@ -178,8 +178,8 @@ pub fn wave_path(
/// screen wide reads a column a pixel, few enough that the string stays
/// under a few hundred kilobytes.
const COLUMNS: std::ops::RangeInclusive<usize> = 8..=4096;
- /// Silence still draws a sliver: a hairline along the floor of a clip
- /// rather than a gap in it.
+ /// Silence still draws a sliver: a hairline through the middle of a
+ /// clip rather than a gap in it.
const FLOOR: f32 = 0.024;
if duration.is_nan() || duration <= 0.0 || peaks.finest().is_empty() {
@@ -191,7 +191,9 @@ pub fn wave_path(
// Each bar is the peak of everything under its pitch, drawn on the
// leading `bar` of it: the rest is the gap that makes it a bar and
- // not a run of columns.
+ // not a run of columns. Bars stand about the centre line, the way
+ // every editor draws sound, so a beat reads as a spike both ways and
+ // silence as a hairline through the middle (#105).
let bar = bar.clamp(0.1, 1.0);
let pitch = 1.0 / columns as f32;
for column in 0..columns {
@@ -201,10 +203,12 @@ pub fn wave_path(
source_start + (left + pitch) * duration,
);
let right = left + pitch * bar;
- let top = 1.0 - high.max(-low).clamp(0.0, 1.0).max(FLOOR);
+ let amplitude = high.max(-low).clamp(0.0, 1.0).max(FLOOR);
+ let top = 0.5 - amplitude / 2.0;
+ let bottom = 0.5 + amplitude / 2.0;
path.push_str(&format!(
"M {left:.4} {top:.4} L {right:.4} {top:.4} \
- L {right:.4} 1.0000 L {left:.4} 1.0000 Z "
+ L {right:.4} {bottom:.4} L {left:.4} {bottom:.4} Z "
));
}
path
@@ -378,7 +382,7 @@ mod tests {
}
#[test]
- fn a_waveform_has_one_floored_bar_per_column() {
+ fn a_waveform_has_one_centred_bar_per_column() {
let peaks = concat_media::Pyramid::of(concat_media::Peaks {
min: vec![-0.5; 2000],
max: vec![0.5; 2000],
@@ -386,10 +390,11 @@ mod tests {
});
let wave = wave_path(&peaks, 0.0, 2.0, 128, WAVE_BAR);
assert_eq!(wave.matches('M').count(), 128);
- // A bar stands on the floor: its top is one less its height.
+ // A bar stands about the centre: half amplitude runs from a
+ // quarter of the way down to three quarters.
assert!(
- wave.contains(" 0.5000 L") && wave.contains(" 1.0000 Z"),
- "half amplitude, floored: {wave}"
+ wave.contains(" 0.2500 L") && wave.contains(" 0.7500 Z"),
+ "half amplitude, centred: {wave}"
);
assert!(wave_path(&peaks, 0.0, 0.0, 128, WAVE_BAR).is_empty());
assert!(wave_path(&peaks, 0.0, f32::NAN, 128, WAVE_BAR).is_empty());
@@ -408,16 +413,16 @@ mod tests {
);
// A bar takes `bar` of its pitch; the rest is the gap.
let eight = wave_path(&peaks, 0.0, 2.0, 8, 0.75);
- assert!(eight.contains("M 0.0000 0.5000 L 0.0938 0.5000"), "{eight}");
- assert!(eight.contains("M 0.1250 0.5000 L 0.2188 0.5000"), "{eight}");
+ assert!(eight.contains("M 0.0000 0.2500 L 0.0938 0.2500"), "{eight}");
+ assert!(eight.contains("M 0.1250 0.2500 L 0.2188 0.2500"), "{eight}");
let thin = wave_path(&peaks, 0.0, 2.0, 8, 0.5);
- assert!(thin.contains("M 0.0000 0.5000 L 0.0625 0.5000"), "{thin}");
+ assert!(thin.contains("M 0.0000 0.2500 L 0.0625 0.2500"), "{thin}");
// Held to a sliver at the least, and never over the pitch.
let hair = wave_path(&peaks, 0.0, 2.0, 8, 0.0);
- assert!(hair.contains("M 0.0000 0.5000 L 0.0125 0.5000"), "{hair}");
+ assert!(hair.contains("M 0.0000 0.2500 L 0.0125 0.2500"), "{hair}");
let solid = wave_path(&peaks, 0.0, 2.0, 8, 7.0);
- assert!(solid.contains("M 0.0000 0.5000 L 0.1250 0.5000"), "{solid}");
- // Silence is a sliver on the floor, never a gap.
+ assert!(solid.contains("M 0.0000 0.2500 L 0.1250 0.2500"), "{solid}");
+ // Silence is a hairline through the middle, never a gap.
let silence = concat_media::Pyramid::of(concat_media::Peaks {
min: vec![0.0; 100],
max: vec![0.0; 100],
@@ -425,7 +430,10 @@ mod tests {
});
let flat = wave_path(&silence, 0.0, 1.0, 10, WAVE_BAR);
assert_eq!(flat.matches('M').count(), 10);
- assert!(flat.contains(" 0.9760 L"), "{flat}");
+ assert!(
+ flat.contains(" 0.4880 L") && flat.contains(" 0.5120 Z"),
+ "{flat}"
+ );
}
/// A zoomed-in clip reads the fine buckets: a single loud millisecond
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 47efe530..3ba05a52 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -196,6 +196,7 @@ pub fn run() -> Result<(), slint::PlatformError> {
.set_rows(ModelRc::from(models.key_rows.clone()));
app.global::<KeyEditor>()
.set_rows(ModelRc::from(models.key_editor_rows.clone()));
+ editor.set_key_marks(ModelRc::from(models.key_marks.clone()));
app.global::<Library>()
.set_views(ModelRc::from(models.library_views.clone()));
editor.set_menu_items(ModelRc::from(models.menu.clone()));
@@ -730,6 +731,9 @@ pub fn run() -> Result<(), slint::PlatformError> {
}));
// ── the view ──
+ editor.on_key_mark_moved(on_lanes!(|state, from: f32, to: f32| {
+ state.move_keys_at(from, to);
+ }));
editor.on_scrubbed(on_lanes!(|state, seconds: f32| {
state.seek(seconds.max(0.0));
}));
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index 59d42b2b..43804a88 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -491,6 +491,8 @@ pub struct Models {
pub key_rows: Rc<VecModel<ClipKeyData>>,
/// The Keyframes panel's rows; see `Studio::key_editor_rows`.
pub key_editor_rows: Rc<VecModel<KeyRowData>>,
+ /// The ruler's diamonds; see `Studio::key_marks`.
+ pub key_marks: Rc<VecModel<f32>>,
pub library_views: Rc<VecModel<LibraryViewData>>,
pub menu: Rc<VecModel<MenuItemData>>,
pub bar: Rc<VecModel<MenuItemData>>,
@@ -538,6 +540,7 @@ impl Models {
adjust_params: Rc::new(VecModel::default()),
key_rows: Rc::new(VecModel::default()),
key_editor_rows: Rc::new(VecModel::default()),
+ key_marks: Rc::new(VecModel::default()),
library_views: Rc::new(VecModel::default()),
menu: Rc::new(VecModel::default()),
bar: Rc::new(VecModel::default()),
@@ -1973,6 +1976,20 @@ impl Studio {
let end = studio.duration();
let position = studio.host.playback.position() as f32;
studio.playhead = position.min(end);
+ // The view follows: a playhead that runs off the
+ // right edge, or sits off the left, pages the lanes
+ // to it, the way every editor keeps the cut in view.
+ if let Some((low, high)) = studio.lanes.published_span() {
+ let screen = (high - low) / 3.0;
+ let left = studio.lanes.scroll_left;
+ if screen > 0.0
+ && (studio.playhead > left + screen * 0.95
+ || studio.playhead < left)
+ {
+ studio.lanes.scroll_left =
+ (studio.playhead - screen * 0.05).max(0.0);
+ }
+ }
if position >= end {
studio.pause();
} else {
@@ -3186,11 +3203,31 @@ impl Studio {
};
return;
}
- let moving = if self.selection.iter().any(|held| held == id) {
+ let mut moving = if self.selection.iter().any(|held| held == id) {
self.selection.clone()
} else {
vec![id.to_owned()]
};
+ // A detached sound travels with its picture and the picture with
+ // its sound: the pair stays in step unless one of them is moved
+ // on its own lane by a lock (#105).
+ let partners: Vec<String> = moving
+ .iter()
+ .filter_map(|clip_id| self.clip(clip_id))
+ .flat_map(|clip| {
+ let mut found: Vec<String> = clip.detached_from.iter().cloned().collect();
+ found.extend(
+ self.timeline()
+ .clips
+ .iter()
+ .filter(|other| other.detached_from.as_deref() == Some(clip.id.as_str()))
+ .map(|other| other.id.clone()),
+ );
+ found
+ })
+ .filter(|partner| !moving.contains(partner))
+ .collect();
+ moving.extend(partners);
let origins = moving
.iter()
.filter_map(|clip_id| {
@@ -5969,6 +6006,7 @@ impl Studio {
.unwrap_or(0);
editor.set_timeline_current_tab(active as i32);
editor.set_playhead(self.playhead);
+ sync(&models.key_marks, self.key_marks());
editor.set_scroll_left(self.lanes.scroll_left);
editor.set_seconds_per_pixel(self.lanes.seconds_per_pixel);
editor.set_frame_rate(self.frame_rate());
@@ -6368,6 +6406,95 @@ impl Studio {
rows
}
+ /// The selected clip's keys as instants on the timeline, every property
+ /// and Adjust knob together, one diamond per instant: what the ruler
+ /// draws while exactly one clip is selected (#188).
+ pub fn key_marks(&self) -> Vec<f32> {
+ let Some(clip) = self.sole_selection().and_then(|id| self.clip(&id)) else {
+ return Vec::new();
+ };
+ let mut ats: Vec<f64> = model::KeyProperty::ALL
+ .iter()
+ .flat_map(|&property| clip.keys_on(property).map(|key| key.at))
+ .collect();
+ if let Some(link) = clip
+ .video_effects
+ .iter()
+ .find(|entry| entry.id == ADJUST_ID)
+ {
+ ats.extend(link.keys.values().flatten().map(|key| key.at));
+ }
+ ats.sort_by(f64::total_cmp);
+ ats.dedup_by(|a, b| (*a - *b).abs() <= model::KEY_EPSILON);
+ ats.iter()
+ .map(|at| (clip.start + at * clip.duration) as f32)
+ .collect()
+ }
+
+ /// Moves every key of the selected clip that sits at the instant
+ /// `from` to the instant `to`, as one undo step: what a dragged ruler
+ /// diamond does.
+ pub fn move_keys_at(&mut self, from: f32, to: f32) {
+ let Some(clip) = self.sole_selection().and_then(|id| self.clip(&id)) else {
+ return;
+ };
+ if clip.duration <= 0.0 {
+ return;
+ }
+ let clip_id = clip.id.clone();
+ let from_at = (f64::from(from) - clip.start) / clip.duration;
+ let to_at = ((f64::from(to) - clip.start) / clip.duration).clamp(0.0, 1.0);
+ let mut commands = Vec::new();
+ for property in model::KeyProperty::ALL {
+ let Some(index) = clip.key_at(property, from_at) else {
+ continue;
+ };
+ let key = &clip.keys[index];
+ commands.push(Command::ClearClipKey {
+ clip_id: clip_id.clone(),
+ property,
+ at: key.at,
+ });
+ commands.push(Command::SetClipKey {
+ clip_id: clip_id.clone(),
+ property,
+ at: to_at,
+ value: key.value,
+ ease: key.ease,
+ });
+ }
+ if let Some(entry) = clip
+ .video_effects
+ .iter()
+ .position(|entry| entry.id == ADJUST_ID)
+ {
+ let link = &clip.video_effects[entry];
+ for name in link.keys.keys() {
+ let Some(index) = link.key_at(name, from_at) else {
+ continue;
+ };
+ let key = &link.keys_on(name)[index];
+ commands.push(Command::ClearEffectKey {
+ clip_id: clip_id.clone(),
+ entry,
+ key: name.clone(),
+ at: key.at,
+ });
+ commands.push(Command::SetEffectKey {
+ clip_id: clip_id.clone(),
+ entry,
+ key: name.clone(),
+ at: to_at,
+ value: key.value,
+ ease: key.ease,
+ });
+ }
+ }
+ if !commands.is_empty() {
+ self.apply(Command::Batch { commands });
+ }
+ }
+
/// Moves the playhead to `at` of the selected clip, `0..1`.
pub fn jump_to_key(&mut self, at: f32) {
let Some(clip) = self.sole_selection().and_then(|id| self.clip(&id)) else {
diff --git a/src/crates/concat/ui/editor.slint b/src/crates/concat/ui/editor.slint
index 7e2702c2..16a8a3eb 100644
--- a/src/crates/concat/ui/editor.slint
+++ b/src/crates/concat/ui/editor.slint
@@ -269,6 +269,9 @@ export global Editor {
in-out property <bool> sound-selected;
in-out property <bool> title-selected;
in-out property <float> playhead;
+ /// The selected clip's keys, as instants on the timeline: the ruler's
+ /// diamonds. Empty unless exactly one clip is selected.
+ in-out property <[float]> key-marks;
in-out property <float> frame-rate;
in-out property <float> scroll-left;
in-out property <float> seconds-per-pixel;
@@ -307,6 +310,8 @@ export global Editor {
/// decides which clips are worth publishing.
callback lanes-resized(width: float);
callback scrubbed(seconds: float);
+ /// A ruler diamond was dragged: every key at `from` moves to `to`.
+ callback key-mark-moved(from: float, to: float);
callback clip-pressed(id: string, additive: bool, edge: int);
callback clip-dragged(seconds: float, pixels: length);
callback clip-released();
diff --git a/src/crates/concat/ui/primitives/wave.slint b/src/crates/concat/ui/primitives/wave.slint
index 3cd834bd..3acbe9da 100644
--- a/src/crates/concat/ui/primitives/wave.slint
+++ b/src/crates/concat/ui/primitives/wave.slint
@@ -3,24 +3,28 @@
import { Theme } from "../theme/theme.slint";
-// A waveform drawn: the bars in `tint`, scaled by `gain` from the floor
-// up, and the part of them over the hot line drawn again in the hot colour
-// - the same path, clipped to the band above the line. The path is at
-// unity (see `format::wave_path`), so the gain is a layout property here
-// and a volume drag costs no rebuild; a gain over one pushes the bars past
-// the top and the box clips them, which is what full scale looks like.
+// A waveform drawn: the bars in `tint`, standing about the centre line and
+// scaled by `gain`, and the part of them past the hot lines - above the
+// upper one, below the lower - drawn again in the hot colour: the same
+// path, clipped to the two bands. The path is at unity (see
+// `format::wave_path`), so the gain is a layout property here and a
+// volume drag costs no rebuild; a gain over one pushes the bars past the
+// edges and the box clips them, which is what full scale looks like.
export component Wave inherits Rectangle {
in property <string> commands;
in property <float> gain: 1;
in property <brush> tint;
property <length> bars-h: root.height * Math.max(0, root.gain);
+ property <length> bars-y: (root.height - root.bars-h) / 2;
+ /// How far from the middle the hot band begins, either way.
+ property <length> hot-inset: root.height * (1 - Theme.wave-hot-line) / 2;
clip: true;
Path {
x: 0;
- y: root.height - root.bars-h;
+ y: root.bars-y;
width: root.width;
height: root.bars-h;
commands: root.commands;
@@ -30,16 +34,16 @@ export component Wave inherits Rectangle {
fill: root.tint;
}
- Rectangle {
+ for band in [0, 1]: Rectangle {
x: 0;
- y: 0;
+ y: band == 0 ? 0 : root.height - root.hot-inset;
width: root.width;
- height: root.height * (1 - Theme.wave-hot-line);
+ height: root.hot-inset;
clip: true;
Path {
x: 0;
- y: root.height - root.bars-h;
+ y: root.bars-y - parent.y;
width: root.width;
height: root.bars-h;
commands: root.commands;
@@ -50,4 +54,3 @@ export component Wave inherits Rectangle {
}
}
}
-
diff --git a/src/crates/concat/ui/timeline/lanes.slint b/src/crates/concat/ui/timeline/lanes.slint
index 1528ca8b..cd1a6bf6 100644
--- a/src/crates/concat/ui/timeline/lanes.slint
+++ b/src/crates/concat/ui/timeline/lanes.slint
@@ -134,6 +134,9 @@ component Clip inherits Rectangle {
/// lanes down — the lanes differ in height, so which row a drag has
/// reached is a question only the side holding the heights can answer.
callback dragged(seconds: float, pixels: length);
+ /// Where the pointer is across the clip while it drags, for the lanes
+ /// to scroll when it reaches their edge.
+ callback pointer-at(x: length);
callback released();
callback context-requested();
/// The pointer over this clip, at this x in it, and then not. For the
@@ -552,6 +555,7 @@ component Clip inherits Rectangle {
moved => {
if (root.tool == TimelineTool.select) {
+ root.pointer-at(self.mouse-x);
root.dragged(
(self.absolute-position.x + self.mouse-x - self.origin-x)
/ root.px-per-second,
@@ -891,6 +895,8 @@ export component Lanes inherits Rectangle {
in property <[ClipData]> clips;
in property <TimelineTool> tool: TimelineTool.select;
in property <float> playhead;
+ /// The selected clip's keys as instants; see `Editor.key-marks`.
+ in property <[float]> key-marks;
in property <float> frame-rate: 30;
/// Seconds at the left edge of the lanes.
in property <float> scroll-left;
@@ -906,6 +912,8 @@ export component Lanes inherits Rectangle {
in property <length> ruler-height: 28px;
callback scrubbed(seconds: float);
+ /// A ruler diamond dragged from one instant to another.
+ callback key-mark-moved(from: float, to: float);
/// The preview axis: the pointer is over the lanes at this instant,
/// and then - a beat after it last was - it is not.
callback hovered(seconds: float);
@@ -993,6 +1001,36 @@ export component Lanes inherits Rectangle {
pure function at(seconds: float) -> length {
return (seconds - root.scroll-left) * root.px-per-second;
}
+ // ── scrolling at the edge ─────────────────────────────────────────
+ // A scrub or a clip drag that reaches the lanes' edge scrolls the view
+ // that way, a dozen pixels a tick, and re-reports the pointer so the
+ // playhead or the clip keeps up (#101). What is pressed says which
+ // report to repeat.
+ property <bool> scrubbing;
+ property <bool> clip-dragging;
+ property <length> pointer-x;
+ property <float> drag-seconds;
+ property <length> drag-pixels;
+ /// `scroll-left` when the clip was pressed; see the clip's `dragged`.
+ property <float> press-scroll;
+ property <length> edge-zone: 40px;
+ property <bool> at-edge: (root.scrubbing || root.clip-dragging)
+ && (root.pointer-x < root.edge-zone || root.pointer-x > root.width - root.edge-zone);
+
+ edge-scroll := Timer {
+ interval: 16ms;
+ running: root.at-edge;
+ triggered => {
+ root.scrolled(Math.max(0, root.scroll-left
+ + (root.pointer-x < root.edge-zone ? -12 : 12) * root.seconds-per-pixel));
+ if (root.scrubbing) {
+ root.scrubbed(Math.max(0, root.seconds-at(root.pointer-x)));
+ } else {
+ root.clip-dragged(root.drag-seconds + (root.scroll-left - root.press-scroll), root.drag-pixels);
+ }
+ }
+ }
+
pure function seconds-at(x: length) -> float {
return root.scroll-left + x / root.px-per-second;
}
@@ -1174,9 +1212,24 @@ export component Lanes inherits Rectangle {
// onto every clip would be one more thing to keep in step.
locked: root.tracks[entry.row].locked;
- pressed(additive, edge) => { root.clip-pressed(entry.id, additive, edge); }
- dragged(seconds, pixels) => { root.clip-dragged(seconds, pixels); }
- released => { root.clip-released(); }
+ pressed(additive, edge) => {
+ root.press-scroll = root.scroll-left;
+ root.clip-dragging = true;
+ root.clip-pressed(entry.id, additive, edge);
+ }
+ // The clip reports its delta from the press; a view that has
+ // scrolled since then is added, so the clip stays under the
+ // pointer while the edge scrolls it along.
+ dragged(seconds, pixels) => {
+ root.drag-seconds = seconds;
+ root.drag-pixels = pixels;
+ root.clip-dragged(seconds + (root.scroll-left - root.press-scroll), pixels);
+ }
+ pointer-at(x) => { root.pointer-x = self.x + x; }
+ released => {
+ root.clip-dragging = false;
+ root.clip-released();
+ }
hovered(x) => { root.hover-at(self.x + x); }
hover-ended => { root.hover-off(); }
context-requested => {
@@ -1356,15 +1409,65 @@ export component Lanes inherits Rectangle {
}
pointer-event(event) => {
if (event.kind == PointerEventKind.down) {
+ root.scrubbing = true;
+ root.pointer-x = self.mouse-x;
root.scrubbed(Math.max(0, root.seconds-at(self.mouse-x)));
+ } else if (event.kind == PointerEventKind.up || event.kind == PointerEventKind.cancel) {
+ root.scrubbing = false;
}
}
moved => {
if (self.pressed) {
+ root.pointer-x = self.mouse-x;
root.scrubbed(Math.max(0, root.seconds-at(self.mouse-x)));
}
}
}
+
+ // The selected clip's keys, as diamonds on the ruler's floor:
+ // clicked to go to one, dragged to move every key at that
+ // instant. Only while one clip is selected (#188).
+ for mark in root.key-marks: TouchArea {
+ property <float> drag-to: mark;
+ property <bool> dragging;
+
+ x: root.at(self.dragging ? self.drag-to : mark) - 7px;
+ y: root.ruler-height - 14px;
+ width: 14px;
+ height: 14px;
+ mouse-cursor: pointer;
+
+ Path {
+ x: 2px;
+ y: 2px;
+ width: 10px;
+ height: 10px;
+ viewbox-width: 10;
+ viewbox-height: 10;
+ commands: "M 5 0.75 L 9.25 5 L 5 9.25 L 0.75 5 Z";
+ fill: Theme.accent;
+ stroke: Theme.ruler;
+ stroke-width: 1px;
+ }
+
+ moved => {
+ if (self.pressed) {
+ self.dragging = true;
+ self.drag-to = Math.max(0,
+ root.seconds-at(root.at(mark) + self.mouse-x - self.pressed-x));
+ }
+ }
+ pointer-event(event) => {
+ if (event.kind == PointerEventKind.up || event.kind == PointerEventKind.cancel) {
+ if (self.dragging && Math.abs(self.drag-to - mark) > 0.0005) {
+ root.key-mark-moved(mark, self.drag-to);
+ } else if (event.kind == PointerEventKind.up) {
+ root.scrubbed(mark);
+ }
+ self.dragging = false;
+ }
+ }
+ }
}
// Last of all, so its surface is over everything. A PopupWindow is its
diff --git a/src/crates/concat/ui/workspace/seat.slint b/src/crates/concat/ui/workspace/seat.slint
index 1470678d..651feef4 100644
--- a/src/crates/concat/ui/workspace/seat.slint
+++ b/src/crates/concat/ui/workspace/seat.slint
@@ -310,6 +310,7 @@ export component Seat inherits Rectangle {
current-tab: Editor.timeline-current-tab;
tracks: Editor.tracks;
clips: Editor.clips;
+ key-marks: Editor.key-marks;
tool: Editor.tool;
snap: Editor.snap;
magnetic: Editor.magnetic;
@@ -352,6 +353,7 @@ export component Seat inherits Rectangle {
zoom(factor, anchor) => { Editor.zoom(factor, anchor); }
lanes-resized(width) => { Editor.lanes-resized(width); }
floor-pressed => { Editor.blur(); }
+ key-mark-moved(from, to) => { Editor.key-mark-moved(from, to); }
scrubbed(seconds) => {
Editor.blur();
Editor.scrubbed(seconds);
diff --git a/src/crates/concat/ui/workspace/timeline-pane.slint b/src/crates/concat/ui/workspace/timeline-pane.slint
index 37fe91bd..262ebd3e 100644
--- a/src/crates/concat/ui/workspace/timeline-pane.slint
+++ b/src/crates/concat/ui/workspace/timeline-pane.slint
@@ -75,12 +75,14 @@ export component TimelinePane inherits Rectangle {
in property <[TrackData]> tracks;
in property <[ClipData]> clips;
in property <float> playhead;
+ in property <[float]> key-marks;
in property <float> frame-rate: 30;
in property <float> scroll-left;
in property <float> seconds-per-pixel: 0.05;
in-out property <length> track-scroll;
callback scrubbed(seconds: float);
+ callback key-mark-moved(from: float, to: float);
/// A press on an empty stretch of lane; see Editor.blur.
callback floor-pressed();
callback clip-pressed(id: string, additive: bool, edge: int);
@@ -321,6 +323,7 @@ export component TimelinePane inherits Rectangle {
tracks: root.tracks;
clips: root.clips;
+ key-marks: root.key-marks;
tool: root.tool;
playhead: root.playhead;
frame-rate: root.frame-rate;
@@ -332,6 +335,7 @@ export component TimelinePane inherits Rectangle {
preview-axis: root.preview-axis;
scrubbed(seconds) => { root.scrubbed(seconds); }
+ key-mark-moved(from, to) => { root.key-mark-moved(from, to); }
hovered(seconds) => { root.hovered(seconds); }
hover-ended => { root.hover-ended(); }
floor-pressed => { root.floor-pressed(); }