Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

M3.9: Sequence and Markers menu long tail

Brandon Thomas858403ebf388
diff --git a/crates/edit/src/lib.rs b/crates/edit/src/lib.rs
index bf6de640d..8ceb92c14 100644
--- a/crates/edit/src/lib.rs
+++ b/crates/edit/src/lib.rs
@@ -17,6 +17,7 @@
pub mod captions;
pub mod multicam;
+pub mod through;
use std::collections::HashMap;
diff --git a/crates/edit/src/through.rs b/crates/edit/src/through.rs
new file mode 100644
index 000000000..d0203355a
--- /dev/null
+++ b/crates/edit/src/through.rs
@@ -0,0 +1,263 @@
+//! Through edits, gaps and range copies.
+//!
+//! - A **through edit** is a cut between two adjacent pieces of the same source that continue each
+//! other in media time (what Add Edit leaves behind). The timeline can mark them (Sequence ▸ Show
+//! Through Edits) and Join Through Edits heals them; the left piece's attributes win.
+//! - A **gap** is empty time followed by material: on one track, or on every track at once (Sequence
+//! ▸ Go to Gap).
+//! - [`clip_item_to`] trims a copy of an item to a time range (Make Subsequence).
+
+use filmcraft_project::{ClipId, Sequence, Track, TrackId, TrackItem};
+use filmcraft_time::{Tick, TimeRange};
+
+use crate::remove_orphan_transitions;
+
+/// Media-time slack when comparing the pieces of a cut (speed changes round each piece's source
+/// range to whole ticks).
+const MEDIA_SLACK: i64 = 2;
+
+/// Whether the cut between adjacent items `a` (left) and `b` (right) is a through edit: same
+/// source, same speed and direction, and `b` continues `a` in media time.
+pub fn is_through_edit(a: &TrackItem, b: &TrackItem) -> bool {
+ if a.end() != b.start || a.item != b.item || a.speed != b.speed || a.reverse != b.reverse || a.multicam != b.multicam {
+ return false;
+ }
+ match (a.frame_hold, b.frame_hold) {
+ (None, None) => {}
+ (Some(x), Some(y)) => return x == y,
+ _ => return false,
+ }
+ let diff = if a.reverse { b.source_out() - a.source_in } else { b.source_in - a.source_out() };
+ diff.0.abs() <= MEDIA_SLACK
+}
+
+/// One through edit on a track.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub struct ThroughEdit {
+ pub track: TrackId,
+ pub left: ClipId,
+ pub right: ClipId,
+ pub time: Tick,
+}
+
+/// Through edits on one track, left to right.
+pub fn track_through_edits(track: &Track) -> Vec<ThroughEdit> {
+ track
+ .items
+ .windows(2)
+ .filter(|w| is_through_edit(&w[0], &w[1]))
+ .map(|w| ThroughEdit { track: track.id, left: w[0].id, right: w[1].id, time: w[1].start })
+ .collect()
+}
+
+/// Through edits on every video and audio track.
+pub fn through_edits(seq: &Sequence) -> Vec<ThroughEdit> {
+ seq.all_tracks().flat_map(track_through_edits).collect()
+}
+
+/// Join through edits on unlocked tracks. With `only` non-empty, just the edits whose left or right
+/// piece is listed. The left piece absorbs the right one (keeping its own effects and attributes);
+/// a transition sitting on the cut is removed. Returns the number of edits joined.
+pub fn join_through_edits(seq: &mut Sequence, only: &[ClipId]) -> usize {
+ let mut n = 0;
+ for tr in seq.all_tracks_mut() {
+ if tr.locked {
+ continue;
+ }
+ let mut i = 0;
+ while i + 1 < tr.items.len() {
+ let (a, b) = (&tr.items[i], &tr.items[i + 1]);
+ let wanted = only.is_empty() || only.contains(&a.id) || only.contains(&b.id);
+ if !(wanted && is_through_edit(a, b)) {
+ i += 1;
+ continue;
+ }
+ let (aid, bid) = (a.id, b.id);
+ let (dur, b_source_in) = (b.duration, b.source_in);
+ let left = &mut tr.items[i];
+ left.duration += dur;
+ if left.reverse {
+ // reversed: the right piece shows the earlier media
+ left.source_in = b_source_in;
+ }
+ tr.items.remove(i + 1);
+ tr.transitions.retain(|t| !(t.from == Some(aid) && t.to == Some(bid)));
+ for t in &mut tr.transitions {
+ if t.from == Some(bid) {
+ t.from = Some(aid);
+ }
+ if t.to == Some(bid) {
+ t.to = Some(aid);
+ }
+ }
+ n += 1;
+ }
+ remove_orphan_transitions(tr);
+ }
+ n
+}
+
+/// Start times of the gaps on one track: empty time from 0 or from the end of an item up to the
+/// next item (trailing empty time after the last item is not a gap).
+pub fn track_gaps(track: &Track) -> Vec<TimeRange> {
+ gaps_of(track.items.iter().map(TrackItem::range))
+}
+
+/// Gaps of the whole sequence: time where no video or audio track has material, followed by
+/// material.
+pub fn sequence_gaps(seq: &Sequence) -> Vec<TimeRange> {
+ let mut spans: Vec<TimeRange> = seq.all_tracks().flat_map(|t| t.items.iter().map(TrackItem::range)).collect();
+ spans.sort_by_key(|r| r.start);
+ gaps_of(spans.into_iter())
+}
+
+/// Gaps between `spans` (sorted by start), from time 0.
+fn gaps_of(spans: impl Iterator<Item = TimeRange>) -> Vec<TimeRange> {
+ let mut out = Vec::new();
+ let mut covered = Tick::ZERO;
+ for r in spans {
+ if r.start > covered {
+ out.push(TimeRange::from_bounds(covered, r.start));
+ }
+ covered = covered.max(r.end());
+ }
+ out
+}
+
+/// A copy of `it` trimmed to the timeline `range` (None when they don't overlap). Media time
+/// follows the trim, so the copy shows the same frames at the same timeline times.
+pub fn clip_item_to(it: &TrackItem, range: TimeRange) -> Option<TrackItem> {
+ let a = it.start.max(range.start);
+ let b = it.end().min(range.end());
+ if b <= a {
+ return None;
+ }
+ let mut c = it.clone();
+ let head = a - it.start;
+ let tail = it.end() - b;
+ let speed = it.speed.abs();
+ let src = |d: Tick| Tick((d.0 as f64 * speed).round() as i64);
+ if it.frame_hold.is_none() {
+ if it.reverse {
+ c.source_in += src(tail);
+ } else {
+ c.source_in += src(head);
+ }
+ }
+ c.start = a;
+ c.duration = b - a;
+ Some(c)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::{EditCtx, razor};
+ use filmcraft_project::{ItemId, Label, SequenceSettings, TrackKind};
+
+ fn item(id: u64, start: i64, dur: i64, src: i64) -> TrackItem {
+ TrackItem {
+ id: ClipId(id),
+ item: ItemId(1),
+ name: "c".into(),
+ label: Label::Iris,
+ start: Tick(start),
+ duration: Tick(dur),
+ source_in: Tick(src),
+ speed: 1.0,
+ reverse: false,
+ enabled: true,
+ link: None,
+ group: None,
+ effects: vec![],
+ markers: vec![],
+ gain_db: 0.0,
+ frame_hold: None,
+ scale_to_frame: false,
+ essential: None,
+ multicam: None,
+ }
+ }
+
+ fn seq_with(items: Vec<TrackItem>) -> Sequence {
+ let mut p = filmcraft_project::Project::new("t");
+ let id = p.new_sequence("s", SequenceSettings::default(), 1, 1, None);
+ let mut q = p.sequence(id).unwrap().clone();
+ q.video_tracks[0].items = items;
+ q
+ }
+
+ fn ctx(next: &mut u64) -> EditCtx<'_> {
+ EditCtx { next_id: next, media_duration: &|_| None, min_duration: Tick(1) }
+ }
+
+ #[test]
+ fn razor_makes_a_through_edit_and_join_heals_it() {
+ let mut q = seq_with(vec![item(10, 0, 100, 500)]);
+ let orig = q.clone();
+ let mut n = 1000;
+ razor(&mut q, &[], Tick(40), &mut ctx(&mut n));
+ let te = through_edits(&q);
+ assert_eq!(te.len(), 1);
+ assert_eq!(te[0].time, Tick(40));
+ assert_eq!(join_through_edits(&mut q, &[]), 1);
+ assert_eq!(q.video_tracks[0].items, orig.video_tracks[0].items);
+ }
+
+ #[test]
+ fn reversed_and_speed_changed_pieces_join() {
+ for (speed, reverse) in [(1.0, true), (1.5, false), (0.7, true)] {
+ let mut it = item(10, 0, 99, 500);
+ it.speed = speed;
+ it.reverse = reverse;
+ let mut q = seq_with(vec![it.clone()]);
+ let mut n = 1000;
+ razor(&mut q, &[], Tick(37), &mut ctx(&mut n));
+ assert_eq!(through_edits(&q).len(), 1, "speed {speed} reverse {reverse}");
+ join_through_edits(&mut q, &[]);
+ let j = &q.video_tracks[0].items[0];
+ assert_eq!((j.start, j.duration), (it.start, it.duration));
+ assert!((j.source_in - it.source_in).0.abs() <= MEDIA_SLACK, "speed {speed} reverse {reverse}: {:?} vs {:?}", j.source_in, it.source_in);
+ }
+ }
+
+ #[test]
+ fn discontinuous_neighbours_are_not_through_edits() {
+ let q = seq_with(vec![item(10, 0, 40, 500), item(11, 40, 60, 600)]);
+ assert!(through_edits(&q).is_empty());
+ let mut other = item(11, 40, 60, 540);
+ other.item = ItemId(2);
+ let q = seq_with(vec![item(10, 0, 40, 500), other]);
+ assert!(through_edits(&q).is_empty());
+ }
+
+ #[test]
+ fn join_only_listed_edits() {
+ let mut q = seq_with(vec![item(10, 0, 30, 0), item(11, 30, 30, 30), item(12, 60, 30, 60)]);
+ assert_eq!(join_through_edits(&mut q, &[ClipId(12)]), 1);
+ assert_eq!(q.video_tracks[0].items.len(), 2);
+ assert_eq!(q.video_tracks[0].items[1].duration, Tick(60));
+ }
+
+ #[test]
+ fn gaps_on_tracks_and_sequence() {
+ let mut q = seq_with(vec![item(10, 10, 20, 0), item(11, 50, 10, 0)]);
+ q.audio_tracks[0].items = vec![item(20, 0, 15, 0), item(21, 40, 15, 0)];
+ assert_eq!(track_gaps(&q.video_tracks[0]), vec![TimeRange::from_bounds(Tick(0), Tick(10)), TimeRange::from_bounds(Tick(30), Tick(50))]);
+ assert_eq!(sequence_gaps(&q), vec![TimeRange::from_bounds(Tick(30), Tick(40))]);
+ assert_eq!(q.audio_tracks[0].kind, TrackKind::Audio);
+ }
+
+ #[test]
+ fn clip_to_range_keeps_frames_in_place() {
+ let it = item(10, 100, 100, 1000);
+ let c = clip_item_to(&it, TimeRange::from_bounds(Tick(120), Tick(150))).unwrap();
+ assert_eq!((c.start, c.duration, c.source_in), (Tick(120), Tick(30), Tick(1020)));
+ assert_eq!(c.source_time_at(Tick(130)), it.source_time_at(Tick(130)));
+ let mut r = it.clone();
+ r.reverse = true;
+ let c = clip_item_to(&r, TimeRange::from_bounds(Tick(120), Tick(150))).unwrap();
+ assert_eq!(c.source_time_at(Tick(130)), r.source_time_at(Tick(130)));
+ assert!(clip_item_to(&it, TimeRange::from_bounds(Tick(0), Tick(100))).is_none());
+ }
+}
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index d7919b166..6bd0c81c7 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -266,6 +266,7 @@ fn place_item(
adest: Option<TrackId>,
insert: bool,
label: &str,
+ audio_split: Option<(TimeRange, Tick)>,
) -> Result<Vec<ClipId>> {
let pi = s.project.item(item).ok_or_else(|| bad(label, "no such item"))?.clone();
let has_v = pi.has_video() && vdest.is_some();
@@ -297,7 +298,8 @@ fn place_item(
placements.push((vdest.expect("checked"), v));
}
if has_a {
- let mut a = p.make_track_item(item, TrackKind::Audio, at, range, rate).ok_or_else(|| bad(label, "bad item"))?;
+ let (arange, aat) = audio_split.unwrap_or((range, at));
+ let mut a = p.make_track_item(item, TrackKind::Audio, aat, arange, rate).ok_or_else(|| bad(label, "bad item"))?;
a.link = link;
placements.push((adest.expect("checked"), a));
}
@@ -307,7 +309,14 @@ fn place_item(
let mut next = p.next_id;
let seq = p.sequence_mut(seq_id).ok_or(EngineError::NoSequence)?;
let mut ctx = edit::EditCtx { next_id: &mut next, media_duration: &durations, min_duration: min };
+ let span = placements.iter().map(|x| x.1.start).min().zip(placements.iter().map(|x| x.1.end()).max());
let ids = if insert { edit::insert(seq, placements, &mut ctx)? } else { edit::overwrite(seq, placements, &mut ctx)? };
+ if insert
+ && st.ripple_sequence_markers
+ && let Some((a, b)) = span
+ {
+ crate::sequence_tools::ripple_markers(&mut seq.markers, a, b - a);
+ }
p.next_id = next;
st.selection = ids.clone();
Ok(ids)
@@ -339,8 +348,17 @@ fn edit_at_source(s: &mut Session, insert: bool) -> Result<Value> {
let at = seq.mark_in.unwrap_or(s.playhead());
let tg = s.targeting();
let label = if insert { "Insert" } else { "Overwrite" };
- let ids = place_item(s, item, range, at, tg.video_dest, tg.audio_dest, insert, label)?;
- let end = at + s.sequence_rate().snap_nearest(range.duration);
+ // split points: each channel takes its own range, offset by the difference of the In points
+ let (vr, ar) = crate::sequence_tools::split_source_ranges(s, item, range);
+ let base = vr.start.min(ar.start);
+ let (vat, aat) = (at + (vr.start - base), at + (ar.start - base));
+ let ids = if vr == ar {
+ place_item(s, item, range, at, tg.video_dest, tg.audio_dest, insert, label, None)?
+ } else {
+ place_item(s, item, vr, vat, tg.video_dest, tg.audio_dest, insert, label, Some((ar, aat)))?
+ };
+ let end =
+ if vr == ar { at + s.sequence_rate().snap_nearest(range.duration) } else { s.sequence_rate().snap_nearest((vat + vr.duration).max(aat + ar.duration)) };
s.set_playhead(end);
Ok(json!({"clips": ids.iter().map(|c| c.0).collect::<Vec<_>>()}))
}
@@ -422,7 +440,7 @@ fn build() -> Vec<CommandSpec> {
if let Some(from) = item_p(p, "fromItem") {
let dur = s.project.item(from).map(|i| i.duration()).unwrap_or_default();
let tg = s.targeting();
- place_item(s, from, TimeRange::new(Tick::ZERO, dur), Tick::ZERO, tg.video_dest, tg.audio_dest, false, "New Sequence From Clip")?;
+ place_item(s, from, TimeRange::new(Tick::ZERO, dur), Tick::ZERO, tg.video_dest, tg.audio_dest, false, "New Sequence From Clip", None)?;
}
s.events.push(crate::Event::OpenSequence(id));
Ok(json!({"sequence": id.0}))
@@ -737,7 +755,15 @@ fn build() -> Vec<CommandSpec> {
}
let sel = with_links(s, &clips_p(s, p));
s.edit_sequence("Ripple Delete", |q, _, st| {
+ let mut spans: Vec<TimeRange> = sel.iter().filter_map(|c| q.find_item(*c).map(|(_, i)| i.range())).collect();
+ spans.sort_by_key(|r| (r.start, r.duration));
+ spans.dedup();
edit::ripple_delete_items(q, &sel)?;
+ if st.ripple_sequence_markers {
+ for r in spans.iter().rev() {
+ crate::sequence_tools::ripple_markers(&mut q.markers, r.end(), -r.duration);
+ }
+ }
st.selection.clear();
Ok(())
})?;
@@ -959,10 +985,14 @@ fn build() -> Vec<CommandSpec> {
cmd!("sequence.extract", "Extract", ["Sequence"], Some("'"), "{}", has_in_out, |s, _| {
let r = in_out_range(s)?;
let tg = s.targeting().targeted;
- s.edit_sequence("Extract", |q, ctx, _| {
+ s.edit_sequence("Extract", |q, ctx, st| {
edit::extract(q, &tg, r, ctx);
+ if st.ripple_sequence_markers {
+ crate::sequence_tools::ripple_markers(&mut q.markers, r.end(), -r.duration);
+ }
q.mark_in = None;
q.mark_out = None;
+ q.split = Default::default();
Ok(())
})?;
s.set_playhead(r.start);
@@ -989,7 +1019,21 @@ fn build() -> Vec<CommandSpec> {
cmd!("sequence.closeGap", "Close Gap", ["Sequence"], None, r#"{"track":"V1"|id,"time":ticks}"#, has_seq, |s, p| {
let tr = track_p(s, p, "track").ok_or_else(|| bad("sequence.closeGap", "need `track`"))?;
let t = time_p(s, p, "").unwrap_or(s.playhead());
- s.edit_sequence("Ripple Delete", |q, _, _| Ok(edit::close_gap(q, tr, t)?))?;
+ s.edit_sequence("Ripple Delete", |q, _, st| {
+ let before: Vec<(ClipId, Tick)> = q.track(tr).map(|x| x.items.iter().map(|i| (i.id, i.start)).collect()).unwrap_or_default();
+ edit::close_gap(q, tr, t)?;
+ if st.ripple_sequence_markers {
+ // the gap ended where the first clip that moved started
+ let moved = before
+ .iter()
+ .filter_map(|(id, old)| q.find_item(*id).filter(|(_, i)| i.start != *old).map(|(_, i)| (*old, *old - i.start)))
+ .min_by_key(|m| m.0);
+ if let Some((end, len)) = moved {
+ crate::sequence_tools::ripple_markers(&mut q.markers, end, -len);
+ }
+ }
+ Ok(())
+ })?;
Ok(Value::Null)
}),
cmd!("sequence.snap", "Snap in Timeline", ["Sequence"], Some("S"), r#"{"on":bool?}"#, always, |s, p| {
@@ -1120,6 +1164,8 @@ fn build() -> Vec<CommandSpec> {
cmd!("markers.clearIn", "Clear In", ["Markers"], Some("Cmd+Shift+I"), "{}", has_seq, |s, _| {
s.edit_sequence("Clear In", |q, _, _| {
q.mark_in = None;
+ q.split.video_in = None;
+ q.split.audio_in = None;
Ok(())
})?;
Ok(Value::Null)
@@ -1127,6 +1173,8 @@ fn build() -> Vec<CommandSpec> {
cmd!("markers.clearOut", "Clear Out", ["Markers"], Some("Cmd+Shift+O"), "{}", has_seq, |s, _| {
s.edit_sequence("Clear Out", |q, _, _| {
q.mark_out = None;
+ q.split.video_out = None;
+ q.split.audio_out = None;
Ok(())
})?;
Ok(Value::Null)
@@ -1135,6 +1183,7 @@ fn build() -> Vec<CommandSpec> {
s.edit_sequence("Clear In and Out", |q, _, _| {
q.mark_in = None;
q.mark_out = None;
+ q.split = Default::default();
Ok(())
})?;
Ok(Value::Null)
@@ -1184,7 +1233,7 @@ fn build() -> Vec<CommandSpec> {
})?;
Ok(Value::Null)
}),
- cmd!("markers.clearAll", "Clear All Markers", ["Markers"], Some("Cmd+Alt+Shift+M"), "{}", has_seq, |s, _| {
+ cmd!("markers.clearAll", "Clear Markers", ["Markers"], Some("Cmd+Alt+Shift+M"), "{}", has_seq, |s, _| {
s.edit_sequence("Clear All Markers", |q, _, _| {
q.markers.clear();
Ok(())
@@ -1318,7 +1367,7 @@ fn build() -> Vec<CommandSpec> {
};
let sin = p.get("sourceIn").and_then(Value::as_i64).map(Tick).or(mi).unwrap_or_default();
let dur = p.get("duration").and_then(Value::as_i64).map(Tick).unwrap_or_else(|| mo.unwrap_or(full) - sin);
- let ids = place_item(s, item, TimeRange::new(sin, dur), at, v, a, bool_p(p, "insert").unwrap_or(false), "Place Clip")?;
+ let ids = place_item(s, item, TimeRange::new(sin, dur), at, v, a, bool_p(p, "insert").unwrap_or(false), "Place Clip", None)?;
Ok(json!({"clips": ids.iter().map(|c| c.0).collect::<Vec<_>>()}))
}
),
@@ -1380,7 +1429,8 @@ fn build() -> Vec<CommandSpec> {
.or_else(|| p.get("deltaFrames").and_then(Value::as_i64).map(|f| s.sequence_rate().tick_of(f)))
.unwrap_or_default();
let clips = with_links(s, &[c]);
- let applied = s.edit_sequence(if mode == TrimMode::Ripple { "Ripple Trim" } else { "Trim" }, |q, ctx, _| {
+ let applied = s.edit_sequence(if mode == TrimMode::Ripple { "Ripple Trim" } else { "Trim" }, |q, ctx, st| {
+ let before = q.find_item(c).map(|(_, i)| i.range());
// clamp across all linked partners, then apply the common delta
let mut dd = d;
for c in &clips {
@@ -1394,6 +1444,16 @@ fn build() -> Vec<CommandSpec> {
let mut group = vec![c];
group.extend(clips.iter().copied().filter(|o| *o != c));
dd = edit::ripple_trim_group(q, &group, edge, dd, ctx)?;
+ if st.ripple_sequence_markers
+ && let Some(r) = before
+ {
+ let (from, shift) = match edge {
+ Edge::In if dd > Tick::ZERO => (r.start + dd, -dd),
+ Edge::In => (r.start, -dd),
+ Edge::Out => (r.end(), dd),
+ };
+ crate::sequence_tools::ripple_markers(&mut q.markers, from, shift);
+ }
} else {
for c in &clips {
edit::trim(q, *c, edge, mode, dd, ctx)?;
@@ -1849,6 +1909,15 @@ fn build() -> Vec<CommandSpec> {
let p = p.clone();
s.edit("Mark", |pr, _| {
let it = pr.item_mut(id).ok_or_else(|| bad("project.setMarks", "no such item"))?;
+ // an ordinary In/Out replaces that side's split points
+ if p.get("in").is_some() {
+ it.split.video_in = None;
+ it.split.audio_in = None;
+ }
+ if p.get("out").is_some() {
+ it.split.video_out = None;
+ it.split.audio_out = None;
+ }
if let Some(m) = it.as_media_mut() {
if let Some(v) = p.get("in") {
m.mark_in = v.as_i64().map(Tick);
@@ -1887,6 +1956,7 @@ fn build() -> Vec<CommandSpec> {
json!({"undo": s.history.undo.iter().map(|h| &h.0).collect::<Vec<_>>(), "redo": s.history.redo.iter().map(|h| &h.0).collect::<Vec<_>>()})
)),
];
+ crate::sequence_tools::splice(&mut v);
v.extend(crate::captions::commands());
v.extend(crate::mixer::commands());
v.extend(crate::multicam::commands());
@@ -2058,11 +2128,15 @@ fn mark(s: &mut Session, p: &Value, is_in: bool) -> Result<Value> {
s.edit_sequence(if is_in { "Mark In" } else { "Mark Out" }, |q, _, _| {
if is_in {
q.mark_in = Some(t);
+ q.split.video_in = None;
+ q.split.audio_in = None;
if q.mark_out.is_some_and(|o| o < t) {
q.mark_out = None;
}
} else {
q.mark_out = Some(t);
+ q.split.video_out = None;
+ q.split.audio_out = None;
if q.mark_in.is_some_and(|i| i > t) {
q.mark_in = None;
}
@@ -2103,6 +2177,13 @@ fn copy_selection(s: &mut Session) {
let Some(q) = s.active_sequence() else { return };
let sel = with_links(s, &s.state.selection);
let min = sel.iter().filter_map(|c| q.find_item(*c).map(|(_, i)| i.start)).min().unwrap_or_default();
+ let max = sel.iter().filter_map(|c| q.find_item(*c).map(|(_, i)| i.end())).max().unwrap_or_default();
+ // Copy Paste Includes Sequence Markers: the markers inside the copied span go along
+ let markers: Vec<Marker> = if s.state.copy_paste_sequence_markers {
+ q.markers.iter().filter(|m| m.start >= min && m.start < max).map(|m| Marker { start: m.start - min, ..m.clone() }).collect()
+ } else {
+ Vec::new()
+ };
let mut clip = Vec::new();
for (kind, tracks) in [(TrackKind::Video, &q.video_tracks), (TrackKind::Audio, &q.audio_tracks)] {
for (ti, t) in tracks.iter().enumerate() {
@@ -2114,11 +2195,13 @@ fn copy_selection(s: &mut Session) {
}
}
s.state.clipboard = clip;
+ s.state.clipboard_markers = markers;
}
fn paste(s: &mut Session, insert: bool) -> Result<Value> {
let at = s.playhead();
let clip = s.state.clipboard.clone();
+ let markers = if s.state.copy_paste_sequence_markers { s.state.clipboard_markers.clone() } else { Vec::new() };
let end = s.edit_sequence(if insert { "Paste Insert" } else { "Paste" }, |q, ctx, st| {
let mut placements = Vec::new();
let mut links = std::collections::HashMap::new();
@@ -2135,6 +2218,13 @@ fn paste(s: &mut Session, insert: bool) -> Result<Value> {
}
let end = placements.iter().map(|p| p.1.end()).max().unwrap_or(at);
let ids = if insert { edit::insert(q, placements, ctx)? } else { edit::overwrite(q, placements, ctx)? };
+ if insert && st.ripple_sequence_markers {
+ crate::sequence_tools::ripple_markers(&mut q.markers, at, end - at);
+ }
+ for m in &markers {
+ q.markers.push(Marker { id: MarkerId(ctx.alloc()), start: m.start + at, ..m.clone() });
+ }
+ q.markers.sort_by_key(|m| m.start);
st.selection = ids;
Ok(end)
})?;
@@ -2312,7 +2402,8 @@ pub fn inspect_sequence(s: &Session, id: ItemId, q: &filmcraft_project::Sequence
"playhead": s.state.playheads.get(&id).map(|t| t.0),
"in": q.mark_in.map(|t| t.0),
"out": q.mark_out.map(|t| t.0),
- "markers": q.markers.iter().map(|m| json!({"id": m.id.0, "start": m.start.0, "name": m.name, "color": m.color.name()})).collect::<Vec<_>>(),
+ "split": q.split,
+ "markers": q.markers.iter().map(|m| json!({"id": m.id.0, "start": m.start.0, "duration": m.duration.0, "kind": format!("{:?}", m.kind), "name": m.name, "color": m.color.name()})).collect::<Vec<_>>(),
"video": q.video_tracks.iter().map(tr).collect::<Vec<_>>(),
"audio": q.audio_tracks.iter().map(tr).collect::<Vec<_>>(),
"selection": s.state.selection.iter().map(|c| c.0).collect::<Vec<_>>(),
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 91fc6e348..2eed4f578 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -25,6 +25,7 @@ pub mod previews;
pub mod project_manager;
pub mod proxies;
pub mod relink;
+pub mod sequence_tools;
pub mod shortcut_presets;
pub mod shortcuts;
pub mod sync;
@@ -179,6 +180,25 @@ pub struct EditorState {
/// audio clips too.
#[serde(default)]
pub multicam_audio_follows_video: bool,
+ /// Sequence ▸ Selection Follows Playhead: moving the playhead selects the clips under it on
+ /// targeted tracks.
+ #[serde(default)]
+ pub selection_follows_playhead: bool,
+ /// Sequence ▸ Show Through Edits: the timeline marks cuts between continuous pieces of a clip.
+ #[serde(default)]
+ pub show_through_edits: bool,
+ /// Markers ▸ Ripple Sequence Markers: ripple edits move (and delete) sequence markers too.
+ #[serde(default)]
+ pub ripple_sequence_markers: bool,
+ /// Markers ▸ Copy Paste Includes Sequence Markers.
+ #[serde(default)]
+ pub copy_paste_sequence_markers: bool,
+ /// Marker colours hidden in the Markers panel (Show All Marker Colors clears this).
+ #[serde(default)]
+ pub hidden_marker_colors: Vec<filmcraft_project::Label>,
+ /// Sequence markers copied with the clipboard clips (start relative to the copied range).
+ #[serde(skip)]
+ pub clipboard_markers: Vec<filmcraft_project::Marker>,
}
/// Events for frontends (drained each frame).
@@ -583,6 +603,9 @@ impl Session {
if let Some(s) = self.state.active_sequence {
let rate = self.active_sequence().map(|s| s.settings.frame_rate).unwrap_or_default();
self.state.playheads.insert(s, rate.snap(t.max(Tick::ZERO)));
+ if self.state.selection_follows_playhead {
+ sequence_tools::select_under_playhead(self);
+ }
}
}
@@ -668,6 +691,8 @@ mod proxies_tests;
#[cfg(test)]
mod relink_tests;
#[cfg(test)]
+mod sequence_tools_tests;
+#[cfg(test)]
mod shortcuts_tests;
#[cfg(test)]
mod tests;
diff --git a/crates/engine/src/sequence_tools.rs b/crates/engine/src/sequence_tools.rs
new file mode 100644
index 000000000..03b23e5e9
--- /dev/null
+++ b/crates/engine/src/sequence_tools.rs
@@ -0,0 +1,685 @@
+//! Sequence and Markers menu commands: gaps, reverse match frame, subsequences, track deletion,
+//! through edits, split edit points, range and chapter markers and the marker toggles.
+//!
+//! | Id | Menu | Default key |
+//! |---|---|---|
+//! | `sequence.reverseMatchFrame` | Sequence ▸ Reverse Match Frame | Shift+R |
+//! | `sequence.goToNextGap` / `sequence.goToPrevGap` | Sequence ▸ Go to Gap ▸ Next / Previous in Sequence | Shift+; / Cmd+Shift+; |
+//! | `sequence.goToNextGapInTrack` / `sequence.goToPrevGapInTrack` | Sequence ▸ Go to Gap ▸ Next / Previous in Track | |
+//! | `sequence.selectionFollowsPlayhead` | Sequence ▸ Selection Follows Playhead | |
+//! | `sequence.showThroughEdits` | Sequence ▸ Show Through Edits | |
+//! | `sequence.joinThroughEdits` | (clip context menu) Join Through Edits | |
+//! | `sequence.throughEdits` | query: the through edits of the active sequence | |
+//! | `sequence.makeSubsequence` | Sequence ▸ Make Subsequence | Shift+U |
+//! | `sequence.deleteTracks` | Sequence ▸ Delete Tracks… | |
+//! | `markers.markSplitVideoIn` … `markers.markSplitAudioOut` | Markers ▸ Mark Split ▸ Video In … Audio Out | |
+//! | `markers.goToSplitVideoIn` … `markers.goToSplitAudioOut` | Markers ▸ Go to Split ▸ Video In … Audio Out | |
+//! | `markers.addRange` | Markers ▸ Add Range Marker | Ctrl+Shift+M |
+//! | `markers.addRangeInOut` | Markers ▸ Add Range Marker to In and Out | Ctrl+M |
+//! | `markers.showAllMarkerColors` / `markers.filterColors` | Markers ▸ Show All Marker Colors / Markers panel colour filter | |
+//! | `markers.addChapter` | Markers ▸ Add Chapter Marker… | |
+//! | `markers.rippleSequenceMarkers` | Markers ▸ Ripple Sequence Markers | |
+//! | `markers.copyPasteIncludesSequenceMarkers` | Markers ▸ Copy Paste Includes Sequence Markers | |
+//!
+//! Split points: Mark Split sets a video-only or audio-only In/Out (on the sequence, or with
+//! `"target":"source"` on the Source monitor clip). Ordinary Mark In / Mark Out clear the split of
+//! that side. Insert / Overwrite from the Source monitor honour source split points: each channel
+//! takes its own range and lands offset by the difference of the In points (J- and L-cuts).
+
+use filmcraft_edit as edit;
+use filmcraft_project::{ClipId, ItemId, Label, Marker, MarkerId, MarkerKind, SplitMarks, TrackId, TrackItem, TrackKind};
+use filmcraft_time::{Tick, TimeRange};
+use serde_json::{Value, json};
+
+use crate::commands::{CommandSpec, always, bad, bool_p, clips_p, has_seq, str_p, time_p, track_p, with_links};
+use crate::{EngineError, Result, Session};
+
+type Run = fn(&mut Session, &Value) -> Result<Value>;
+type Enabled = fn(&Session) -> std::result::Result<(), String>;
+
+fn spec(
+ id: &'static str,
+ label: &'static str,
+ menu: &'static [&'static str],
+ shortcut: Option<&'static str>,
+ params: &'static str,
+ enabled: Enabled,
+ run: Run,
+) -> CommandSpec {
+ CommandSpec { id, label, menu, shortcut, params, enabled, run, journal: true }
+}
+
+fn query(id: &'static str, label: &'static str, params: &'static str, run: Run) -> CommandSpec {
+ CommandSpec { id, label, menu: &[], shortcut: None, params, enabled: always, run, journal: false }
+}
+
+/// Insert this module's commands into the registry after their anchors, so the menus list them in
+/// Premiere's order.
+pub(crate) fn splice(v: &mut Vec<CommandSpec>) {
+ for (anchor, specs) in groups() {
+ let at = v.iter().position(|c| c.id == anchor).map(|i| i + 1).unwrap_or(v.len());
+ for (k, c) in specs.into_iter().enumerate() {
+ v.insert(at + k, c);
+ }
+ }
+}
+
+const SPLIT: &str = r#"{"time":ticks?,"target":"program|source"}"#;
+
+fn groups() -> Vec<(&'static str, Vec<CommandSpec>)> {
+ vec![
+ (
+ "sequence.matchFrame",
+ vec![spec("sequence.reverseMatchFrame", "Reverse Match Frame", &["Sequence"], Some("Shift+R"), "{}", has_source, |s, _| reverse_match_frame(s))],
+ ),
+ (
+ "sequence.closeGap",
+ vec![
+ spec("sequence.goToNextGap", "Next in Sequence", &["Sequence", "Go to Gap"], Some("Shift+;"), "{}", has_seq, |s, p| {
+ go_to_gap(s, p, true, false)
+ }),
+ spec("sequence.goToPrevGap", "Previous in Sequence", &["Sequence", "Go to Gap"], Some("Cmd+Shift+;"), "{}", has_seq, |s, p| {
+ go_to_gap(s, p, false, false)
+ }),
+ spec("sequence.goToNextGapInTrack", "Next in Track", &["Sequence", "Go to Gap"], None, r#"{"track":"V1"|id?}"#, has_seq, |s, p| {
+ go_to_gap(s, p, true, true)
+ }),
+ spec("sequence.goToPrevGapInTrack", "Previous in Track", &["Sequence", "Go to Gap"], None, r#"{"track":"V1"|id?}"#, has_seq, |s, p| {
+ go_to_gap(s, p, false, true)
+ }),
+ ],
+ ),
+ (
+ "sequence.linkedSelection",
+ vec![
+ spec("sequence.selectionFollowsPlayhead", "Selection Follows Playhead", &["Sequence"], None, r#"{"on":bool?}"#, always, |s, p| {
+ s.state.selection_follows_playhead = bool_p(p, "on").unwrap_or(!s.state.selection_follows_playhead);
+ if s.state.selection_follows_playhead {
+ select_under_playhead(s);
+ }
+ Ok(json!({"selectionFollowsPlayhead": s.state.selection_follows_playhead}))
+ }),
+ spec("sequence.showThroughEdits", "Show Through Edits", &["Sequence"], None, r#"{"on":bool?}"#, always, |s, p| {
+ s.state.show_through_edits = bool_p(p, "on").unwrap_or(!s.state.show_through_edits);
+ Ok(json!({"showThroughEdits": s.state.show_through_edits}))
+ }),
+ spec("sequence.joinThroughEdits", "Join Through Edits", &[], None, r#"{"clips":[id]?,"all":bool?}"#, has_seq, join_through_edits),
+ query("sequence.throughEdits", "List Through Edits", "{}", |s, _| {
+ let q = s.active_sequence().ok_or(EngineError::NoSequence)?;
+ Ok(Value::Array(
+ edit::through::through_edits(q)
+ .iter()
+ .map(|e| json!({"track": e.track.0, "left": e.left.0, "right": e.right.0, "time": e.time.0}))
+ .collect(),
+ ))
+ }),
+ spec("sequence.makeSubsequence", "Make Subsequence", &["Sequence"], Some("Shift+U"), r#"{"name":str?}"#, has_seq, make_subsequence),
+ ],
+ ),
+ (
+ "sequence.addTracks",
+ vec![spec(
+ "sequence.deleteTracks",
+ "Delete Tracks…",
+ &["Sequence"],
+ None,
+ r#"{"video":"empty"|"V2"|id?,"audio":"empty"|"A2"|id?}"#,
+ has_seq,
+ delete_tracks,
+ )],
+ ),
+ (
+ "markers.markSelection",
+ vec![
+ spec("markers.markSplitVideoIn", "Video In", &["Markers", "Mark Split"], None, SPLIT, always, |s, p| mark_split(s, p, Side::VideoIn)),
+ spec("markers.markSplitVideoOut", "Video Out", &["Markers", "Mark Split"], None, SPLIT, always, |s, p| mark_split(s, p, Side::VideoOut)),
+ spec("markers.markSplitAudioIn", "Audio In", &["Markers", "Mark Split"], None, SPLIT, always, |s, p| mark_split(s, p, Side::AudioIn)),
+ spec("markers.markSplitAudioOut", "Audio Out", &["Markers", "Mark Split"], None, SPLIT, always, |s, p| mark_split(s, p, Side::AudioOut)),
+ ],
+ ),
+ (
+ "markers.goToOut",
+ vec![
+ spec("markers.goToSplitVideoIn", "Video In", &["Markers", "Go to Split"], None, r#"{"target":"program|source"}"#, has_split, |s, p| {
+ go_to_split(s, p, Side::VideoIn)
+ }),
+ spec("markers.goToSplitVideoOut", "Video Out", &["Markers", "Go to Split"], None, r#"{"target":"program|source"}"#, has_split, |s, p| {
+ go_to_split(s, p, Side::VideoOut)
+ }),
+ spec("markers.goToSplitAudioIn", "Audio In", &["Markers", "Go to Split"], None, r#"{"target":"program|source"}"#, has_split, |s, p| {
+ go_to_split(s, p, Side::AudioIn)
+ }),
+ spec("markers.goToSplitAudioOut", "Audio Out", &["Markers", "Go to Split"], None, r#"{"target":"program|source"}"#, has_split, |s, p| {
+ go_to_split(s, p, Side::AudioOut)
+ }),
+ ],
+ ),
+ (
+ "markers.add",
+ vec![
+ spec(
+ "markers.addRange",
+ "Add Range Marker",
+ &["Markers"],
+ Some("Ctrl+Shift+M"),
+ r#"{"time":ticks?,"durationFrames":i64=1s,"duration":ticks?,"name":str?,"comment":str?,"color":label?}"#,
+ has_seq,
+ add_range_marker,
+ ),
+ spec(
+ "markers.addRangeInOut",
+ "Add Range Marker to In and Out",
+ &["Markers"],
+ Some("Ctrl+M"),
+ r#"{"name":str?,"comment":str?,"color":label?}"#,
+ has_in_and_out,
+ add_range_marker_in_out,
+ ),
+ ],
+ ),
+ (
+ "markers.clearAll",
+ vec![
+ spec("markers.showAllMarkerColors", "Show All Marker Colors", &["Markers"], None, "{}", has_hidden_colors, |s, _| {
+ s.state.hidden_marker_colors.clear();
+ Ok(json!({"hidden": []}))
+ }),
+ spec("markers.filterColors", "Marker Colour Filter", &[], None, r#"{"hidden":[label]}|{"color":label,"visible":bool?}"#, always, filter_colors),
+ ],
+ ),
+ (
+ "markers.edit",
+ vec![
+ spec(
+ "markers.addChapter",
+ "Add Chapter Marker…",
+ &["Markers"],
+ None,
+ r#"{"time":ticks?,"name":str?,"comment":str?,"color":label?}"#,
+ has_seq,
+ |s, p| {
+ let t = time_p(s, p, "").unwrap_or(s.playhead());
+ let n = s.active_sequence().map(|q| q.markers.iter().filter(|m| m.kind == MarkerKind::Chapter).count()).unwrap_or(0) + 1;
+ let name = str_p(p, "name").map(str::to_string).unwrap_or_else(|| format!("Chapter {n}"));
+ let id = add_marker(s, "Add Chapter Marker", t, Tick::ZERO, MarkerKind::Chapter, name, p)?;
+ Ok(json!({"marker": id.0}))
+ },
+ ),
+ spec("markers.rippleSequenceMarkers", "Ripple Sequence Markers", &["Markers"], None, r#"{"on":bool?}"#, always, |s, p| {
+ s.state.ripple_sequence_markers = bool_p(p, "on").unwrap_or(!s.state.ripple_sequence_markers);
+ Ok(json!({"rippleSequenceMarkers": s.state.ripple_sequence_markers}))
+ }),
+ spec(
+ "markers.copyPasteIncludesSequenceMarkers",
+ "Copy Paste Includes Sequence Markers",
+ &["Markers"],
+ None,
+ r#"{"on":bool?}"#,
+ always,
+ |s, p| {
+ s.state.copy_paste_sequence_markers = bool_p(p, "on").unwrap_or(!s.state.copy_paste_sequence_markers);
+ Ok(json!({"copyPasteIncludesSequenceMarkers": s.state.copy_paste_sequence_markers}))
+ },
+ ),
+ ],
+ ),
+ ]
+}
+
+// ---------- enablement ----------
+
+fn has_source(s: &Session) -> std::result::Result<(), String> {
+ has_seq(s)?;
+ s.state.source_item.map(|_| ()).ok_or_else(|| "no clip in the Source monitor".into())
+}
+fn has_in_and_out(s: &Session) -> std::result::Result<(), String> {
+ let q = s.active_sequence().ok_or("no sequence is open")?;
+ if q.mark_in.is_some() && q.mark_out.is_some() { Ok(()) } else { Err("mark an In and an Out point first".into()) }
+}
+fn has_split(s: &Session) -> std::result::Result<(), String> {
+ let program = s.active_sequence().is_some_and(|q| !q.split.is_empty());
+ let source = s.state.source_item.and_then(|i| s.project.item(i)).is_some_and(|i| !i.split.is_empty());
+ if program || source { Ok(()) } else { Err("there are no split points".into()) }
+}
+fn has_hidden_colors(s: &Session) -> std::result::Result<(), String> {
+ if s.state.hidden_marker_colors.is_empty() { Err("all marker colours are shown".into()) } else { Ok(()) }
+}
+
+// ---------- selection follows playhead ----------
+
+/// Select the clips under the playhead on targeted tracks (with linked partners).
+pub fn select_under_playhead(s: &mut Session) {
+ let t = s.playhead();
+ let tg = s.targeting().targeted;
+ let Some(q) = s.active_sequence() else { return };
+ let ids: Vec<ClipId> = q.all_tracks().filter(|tr| tg.contains(&tr.id)).filter_map(|tr| tr.item_at(t).map(|i| i.id)).collect();
+ s.state.selection = with_links(s, &ids);
+}
+
+// ---------- match frame ----------
+
+/// Timeline time at which `it` shows media time `src` (None when it doesn't).
+pub fn timeline_time_of(it: &TrackItem, src: Tick) -> Option<Tick> {
+ if let Some(h) = it.frame_hold {
+ return (h == src).then_some(it.start);
+ }
+ let speed = it.speed.abs();
+ if speed <= 0.0 {
+ return None;
+ }
+ let total = it.source_out() - it.source_in;
+ let rel_src = if it.reverse { it.source_in + total - Tick(1) - src } else { src - it.source_in };
+ if rel_src < Tick::ZERO || rel_src >= total {
+ return None;
+ }
+ let t = it.start + Tick((rel_src.0 as f64 / speed).floor() as i64);
+ (t < it.end()).then_some(t)
+}
+
+/// Sequence ▸ Reverse Match Frame: find the Source monitor frame in the active sequence (targeted
+/// tracks first, top video track down, then audio) and move the playhead there.
+fn reverse_match_frame(s: &mut Session) -> Result<Value> {
+ let item = s.state.source_item.ok_or_else(|| EngineError::Other("no clip in the Source monitor".into()))?;
+ let src = s.state.source_playhead;
+ let tg = s.targeting().targeted;
+ let q = s.active_sequence().ok_or(EngineError::NoSequence)?;
+ let mut hits: Vec<(bool, Tick, ClipId)> = Vec::new();
+ for tr in q.video_tracks.iter().rev().chain(&q.audio_tracks) {
+ for it in tr.items.iter().filter(|i| i.item == item) {
+ if let Some(t) = timeline_time_of(it, src) {
+ hits.push((!tg.contains(&tr.id), t, it.id));
+ }
+ }
+ }
+ // stable: targeted first, then track order, then time
+ hits.sort_by_key(|h| h.0);
+ let (_, t, clip) = *hits.first().ok_or_else(|| EngineError::Other("the Source monitor frame is not used in this sequence".into()))?;
+ s.set_playhead(t);
+ Ok(json!({"clip": clip.0, "time": s.playhead().0}))
+}
+
+// ---------- gaps ----------
+
+fn go_to_gap(s: &mut Session, p: &Value, next: bool, in_track: bool) -> Result<Value> {
+ let t = s.playhead();
+ let q = s.active_sequence().ok_or(EngineError::NoSequence)?;
+ let gaps: Vec<TimeRange> = if in_track {
+ let tracks: Vec<TrackId> = match track_p(s, p, "track") {
+ Some(id) => vec![id],
+ None => s.targeting().targeted,
+ };
+ q.all_tracks().filter(|tr| tracks.contains(&tr.id)).flat_map(edit::through::track_gaps).collect()
+ } else {
+ edit::through::sequence_gaps(q)
+ };
+ let starts = gaps.iter().map(|g| g.start);
+ let hit = if next { starts.filter(|g| *g > t).min() } else { starts.filter(|g| *g < t).max() };
+ match hit {
+ Some(g) => {
+ s.set_playhead(g);
+ Ok(json!({"time": s.playhead().0}))
+ }
+ None => Ok(json!({"time": null})),
+ }
+}
+
+// ---------- through edits ----------
+
+fn join_through_edits(s: &mut Session, p: &Value) -> Result<Value> {
+ let all = bool_p(p, "all").unwrap_or(false) || (p.get("clips").is_none() && p.get("clip").is_none() && s.state.selection.is_empty());
+ let only = if all { Vec::new() } else { with_links(s, &clips_p(s, p)) };
+ let q = s.active_sequence().ok_or(EngineError::NoSequence)?;
+ let any = edit::through::through_edits(q)
+ .iter()
+ .any(|e| (only.is_empty() || only.contains(&e.left) || only.contains(&e.right)) && q.track(e.track).is_some_and(|t| !t.locked));
+ if !any {
+ return Err(EngineError::Other("there are no through edits to join".into()));
+ }
+ let n = s.edit_sequence("Join Through Edits", |q, _, st| {
+ let n = edit::through::join_through_edits(q, &only);
+ st.selection.retain(|c| q.find_item(*c).is_some());
+ Ok(n)
+ })?;
+ Ok(json!({"joined": n}))
+}
+
+// ---------- subsequence ----------
+
+/// Sequence ▸ Make Subsequence: a new sequence (same settings and track layout) holding copies of the
+/// selected clips, or of everything on targeted tracks between In and Out, trimmed to In/Out when
+/// they are set. The new sequence is added to the project and selected; the original is unchanged.
+fn make_subsequence(s: &mut Session, p: &Value) -> Result<Value> {
+ let seq_id = s.state.active_sequence.ok_or(EngineError::NoSequence)?;
+ let q = s.active_sequence().ok_or(EngineError::NoSequence)?.clone();
+ let seq_name = s.project.item(seq_id).map(|i| i.name.clone()).unwrap_or_default();
+ let sel = with_links(s, &s.state.selection);
+ let fd = q.settings.frame_rate.frame_duration();
+ let range = (q.mark_in.is_some() || q.mark_out.is_some())
+ .then(|| TimeRange::from_bounds(q.mark_in.unwrap_or(Tick::ZERO), q.mark_out.map(|o| o + fd).unwrap_or(q.duration())))
+ .filter(|r| r.duration > Tick::ZERO);
+ if sel.is_empty() && range.is_none() {
+ return Err(EngineError::Other("select clips or mark In and Out first".into()));
+ }
+ let tg = s.targeting().targeted;
+ let mut items: Vec<(TrackKind, usize, TrackItem)> = Vec::new();
+ for (kind, tracks) in [(TrackKind::Video, &q.video_tracks), (TrackKind::Audio, &q.audio_tracks)] {
+ for (ti, tr) in tracks.iter().enumerate() {
+ for it in &tr.items {
+ let wanted = if sel.is_empty() { tg.contains(&tr.id) } else { sel.contains(&it.id) };
+ if !wanted {
+ continue;
+ }
+ if let Some(c) = edit::through::clip_item_to(it, range.unwrap_or(it.range())) {
+ items.push((kind, ti, c));
+ }
+ }
+ }
+ }
+ if items.is_empty() {
+ return Err(EngineError::Other("there are no clips between In and Out on the targeted tracks".into()));
+ }
+ let offset = range.map(|r| r.start).unwrap_or_else(|| items.iter().map(|i| i.2.start).min().unwrap_or_default());
+ let name = match str_p(p, "name") {
+ Some(n) => n.to_string(),
+ None => (1..).map(|k| format!("{seq_name}_Sub_{k:02}")).find(|n| !s.project.items.values().any(|i| &i.name == n)).expect("free name"),
+ };
+ let id = s.edit("Make Subsequence", |pr, st| {
+ let nid = pr.new_sequence(&name, q.settings.clone(), q.video_tracks.len(), q.audio_tracks.len(), None);
+ let mut ids = std::collections::HashMap::new();
+ let mut links = std::collections::HashMap::new();
+ let mut placed: Vec<(TrackKind, usize, TrackItem)> = Vec::new();
+ for (kind, ti, mut it) in items.clone() {
+ let new_id = ClipId(pr.alloc_id());
+ ids.insert(it.id, new_id);
+ it.id = new_id;
+ it.start -= offset;
+ if let Some(l) = it.link {
+ it.link = Some(*links.entry(l).or_insert_with(|| pr.alloc_id()));
+ }
+ placed.push((kind, ti, it));
+ }
+ let mut transitions = Vec::new();
+ for (kind, tracks) in [(TrackKind::Video, &q.video_tracks), (TrackKind::Audio, &q.audio_tracks)] {
+ for (ti, tr) in tracks.iter().enumerate() {
+ for trn in &tr.transitions {
+ let from = trn.from.map(|c| ids.get(&c).copied());
+ let to = trn.to.map(|c| ids.get(&c).copied());
+ let inside = range.is_none_or(|r| trn.start >= r.start && trn.end() <= r.end());
+ if inside && from != Some(None) && to != Some(None) {
+ let mut t = trn.clone();
+ t.id = filmcraft_project::TransitionId(pr.alloc_id());
+ t.from = from.flatten();
+ t.to = to.flatten();
+ t.start -= offset;
+ transitions.push((kind, ti, t));
+ }
+ }
+ }
+ }
+ let nq = pr.sequence_mut(nid).ok_or(EngineError::NoSequence)?;
+ for (i, tr) in nq.video_tracks.iter_mut().enumerate() {
+ tr.name = q.video_tracks[i].name.clone();
+ }
+ for (i, tr) in nq.audio_tracks.iter_mut().enumerate() {
+ tr.name = q.audio_tracks[i].name.clone();
+ tr.channels = q.audio_tracks[i].channels;
+ }
+ for (kind, ti, it) in placed {
+ nq.tracks_mut(kind)[ti].items.push(it);
+ }
+ for (kind, ti, t) in transitions {
+ nq.tracks_mut(kind)[ti].transitions.push(t);
+ }
+ for tr in nq.all_tracks_mut() {
+ tr.sort();
+ edit::remove_orphan_transitions(tr);
+ }
+ nq.check().map_err(EngineError::Other)?;
+ st.project_selection = vec![nid];
+ Ok(nid)
+ })?;
+ Ok(json!({"sequence": id.0, "name": name}))
+}
+
+// ---------- delete tracks ----------
+
+/// Sequence ▸ Delete Tracks…: delete all empty video / audio tracks (`"empty"`) or one track per
+/// kind. A sequence always keeps at least one video and one audio track.
+fn delete_tracks(s: &mut Session, p: &Value) -> Result<Value> {
+ let seq_id = s.state.active_sequence.ok_or(EngineError::NoSequence)?;
+ let q = s.active_sequence().ok_or(EngineError::NoSequence)?;
+ let mut doomed: Vec<TrackId> = Vec::new();
+ for (key, kind) in [("video", TrackKind::Video), ("audio", TrackKind::Audio)] {
+ let tracks = q.tracks(kind);
+ let mut mine: Vec<TrackId> = match p.get(key) {
+ None | Some(Value::Null) => continue,
+ Some(v) if v.as_str().is_some_and(|x| matches!(x, "empty" | "allEmpty" | "all-empty")) => {
+ tracks.iter().filter(|t| t.items.is_empty()).map(|t| t.id).collect()
+ }
+ Some(_) => {
+ let id = track_p(s, p, key).ok_or_else(|| bad("sequence.deleteTracks", format!("unknown {key} track")))?;
+ if !tracks.iter().any(|t| t.id == id) {
+ return Err(bad("sequence.deleteTracks", format!("`{key}` must name a {key} track")));
+ }
+ vec![id]
+ }
+ };
+ if mine.len() == tracks.len() {
+ // keep the first one
+ mine.retain(|id| *id != tracks[0].id);
+ }
+ doomed.extend(mine);
+ }
+ if doomed.is_empty() {
+ return Err(EngineError::Other("no tracks to delete".into()));
+ }
+ let n = doomed.len();
+ s.edit_sequence("Delete Tracks", |q, _, st| {
+ q.video_tracks.retain(|t| !doomed.contains(&t.id));
+ q.audio_tracks.retain(|t| !doomed.contains(&t.id));
+ st.selection.retain(|c| q.find_item(*c).is_some());
+ if let Some(tg) = st.targeting.get_mut(&seq_id) {
+ tg.targeted.retain(|t| !doomed.contains(t));
+ if tg.video_dest.is_some_and(|t| doomed.contains(&t)) {
+ tg.video_dest = q.video_tracks.first().map(|t| t.id);
+ }
+ if tg.audio_dest.is_some_and(|t| doomed.contains(&t)) {
+ tg.audio_dest = q.audio_tracks.first().map(|t| t.id);
+ }
+ }
+ Ok(())
+ })?;
+ Ok(json!({"deleted": n}))
+}
+
+// ---------- split points ----------
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+enum Side {
+ VideoIn,
+ VideoOut,
+ AudioIn,
+ AudioOut,
+}
+
+impl Side {
+ fn label(self) -> &'static str {
+ match self {
+ Side::VideoIn => "Video In",
+ Side::VideoOut => "Video Out",
+ Side::AudioIn => "Audio In",
+ Side::AudioOut => "Audio Out",
+ }
+ }
+ /// Set this split point; a split point of the same channel on the wrong side of it is cleared.
+ fn set(self, m: &mut SplitMarks, t: Tick) {
+ match self {
+ Side::VideoIn => {
+ m.video_in = Some(t);
+ m.video_out = m.video_out.filter(|o| *o >= t);
+ }
+ Side::VideoOut => {
+ m.video_out = Some(t);
+ m.video_in = m.video_in.filter(|i| *i <= t);
+ }
+ Side::AudioIn => {
+ m.audio_in = Some(t);
+ m.audio_out = m.audio_out.filter(|o| *o >= t);
+ }
+ Side::AudioOut => {
+ m.audio_out = Some(t);
+ m.audio_in = m.audio_in.filter(|i| *i <= t);
+ }
+ }
+ }
+ /// The effective point (the split point, or the ordinary In/Out).
+ fn get(self, m: &SplitMarks, mark_in: Option<Tick>, mark_out: Option<Tick>) -> Option<Tick> {
+ match self {
+ Side::VideoIn => m.video_in_or(mark_in),
+ Side::VideoOut => m.video_out_or(mark_out),
+ Side::AudioIn => m.audio_in_or(mark_in),
+ Side::AudioOut => m.audio_out_or(mark_out),
+ }
+ }
+}
+
+fn source_marks(s: &Session, item: ItemId) -> (Option<Tick>, Option<Tick>) {
+ match s.project.item(item).map(|i| &i.kind) {
+ Some(filmcraft_project::ItemKind::Media(m)) => (m.mark_in, m.mark_out),
+ Some(filmcraft_project::ItemKind::Sequence(q)) => (q.mark_in, q.mark_out),
+ _ => (None, None),
+ }
+}
+
+fn mark_split(s: &mut Session, p: &Value, side: Side) -> Result<Value> {
+ let label = format!("Mark Split {}", side.label());
+ if str_p(p, "target") == Some("source") {
+ let item = s.state.source_item.ok_or_else(|| EngineError::Other("no clip in the Source monitor".into()))?;
+ let t = p.get("time").and_then(Value::as_i64).map(Tick).unwrap_or(s.state.source_playhead);
+ let split = s.edit(&label, |pr, _| {
+ let it = pr.item_mut(item).ok_or_else(|| EngineError::Other("no such item".into()))?;
+ side.set(&mut it.split, t);
+ Ok(it.split)
+ })?;
+ return Ok(serde_json::to_value(split).unwrap_or_default());
+ }
+ s.active_sequence().ok_or(EngineError::NoSequence)?;
+ let t = time_p(s, p, "").unwrap_or(s.playhead());
+ let split = s.edit_sequence(&label, |q, _, _| {
+ side.set(&mut q.split, t);
+ Ok(q.split)
+ })?;
+ Ok(serde_json::to_value(split).unwrap_or_default())
+}
+
+fn go_to_split(s: &mut Session, p: &Value, side: Side) -> Result<Value> {
+ let none = || EngineError::Other(format!("there is no {} point", side.label()));
+ if str_p(p, "target") == Some("source") {
+ let item = s.state.source_item.ok_or_else(|| EngineError::Other("no clip in the Source monitor".into()))?;
+ let (mi, mo) = source_marks(s, item);
+ let split = s.project.item(item).map(|i| i.split).unwrap_or_default();
+ let t = side.get(&split, mi, mo).ok_or_else(none)?;
+ s.state.source_playhead = t;
+ return Ok(json!({"time": t.0}));
+ }
+ let q = s.active_sequence().ok_or(EngineError::NoSequence)?;
+ let t = side.get(&q.split, q.mark_in, q.mark_out).ok_or_else(none)?;
+ s.set_playhead(t);
+ Ok(json!({"time": s.playhead().0}))
+}
+
+/// Source ranges for Insert / Overwrite with split points: (video range, audio range). Equal when
+/// the source has no split points. `full` is the range the ordinary In/Out give.
+pub(crate) fn split_source_ranges(s: &Session, item: ItemId, full: TimeRange) -> (TimeRange, TimeRange) {
+ let Some(pi) = s.project.item(item) else { return (full, full) };
+ let sp = pi.split;
+ if sp.is_empty() {
+ return (full, full);
+ }
+ let fd = pi.frame_rate().frame_duration();
+ let range = |i: Option<Tick>, o: Option<Tick>| {
+ let a = i.unwrap_or(full.start);
+ let b = o.map(|o| o + fd).unwrap_or(full.end());
+ TimeRange::from_bounds(a, b.max(a + fd))
+ };
+ (range(sp.video_in, sp.video_out), range(sp.audio_in, sp.audio_out))
+}
+
+// ---------- markers ----------
+
+/// Move sequence markers for a ripple edit at `from` by `shift`: later markers move; with a
+/// negative shift, markers in the removed span `[from + shift, from)` are deleted.
+pub fn ripple_markers(markers: &mut Vec<Marker>, from: Tick, shift: Tick) {
+ if shift == Tick::ZERO {
+ return;
+ }
+ if shift < Tick::ZERO {
+ markers.retain(|m| !(m.start >= from + shift && m.start < from));
+ }
+ for m in markers.iter_mut().filter(|m| m.start >= from) {
+ m.start += shift;
+ }
+ markers.sort_by_key(|m| m.start);
+}
+
+fn add_marker(s: &mut Session, label: &str, t: Tick, dur: Tick, kind: MarkerKind, name: String, p: &Value) -> Result<MarkerId> {
+ let comment = str_p(p, "comment").unwrap_or("").to_string();
+ let color = str_p(p, "color").and_then(Label::from_name).unwrap_or(Label::Green);
+ s.edit_sequence(label, |q, ctx, _| {
+ let id = MarkerId(ctx.alloc());
+ q.markers.push(Marker { id, start: t, duration: dur, name, comment, kind, color });
+ q.markers.sort_by_key(|m| m.start);
+ Ok(id)
+ })
+}
+
+/// Markers ▸ Add Range Marker: a marker with a duration (one second unless `durationFrames` or
+/// `duration` say otherwise) at the playhead.
+fn add_range_marker(s: &mut Session, p: &Value) -> Result<Value> {
+ let rate = s.sequence_rate();
+ let t = time_p(s, p, "").unwrap_or(s.playhead());
+ let dur = p
+ .get("duration")
+ .and_then(Value::as_i64)
+ .map(Tick)
+ .or_else(|| p.get("durationFrames").and_then(Value::as_i64).map(|f| rate.tick_of(f)))
+ .unwrap_or(rate.tick_of(rate.timecode_base()));
+ if dur <= Tick::ZERO {
+ return Err(bad("markers.addRange", "the duration must be positive"));
+ }
+ let name = str_p(p, "name").unwrap_or("").to_string();
+ let id = add_marker(s, "Add Range Marker", t, dur, MarkerKind::Comment, name, p)?;
+ Ok(json!({"marker": id.0}))
+}
+
+/// Markers ▸ Add Range Marker to In and Out: a marker spanning the sequence In to Out (inclusive).
+fn add_range_marker_in_out(s: &mut Session, p: &Value) -> Result<Value> {
+ let q = s.active_sequence().ok_or(EngineError::NoSequence)?;
+ let (Some(i), Some(o)) = (q.mark_in, q.mark_out) else { return Err(EngineError::Other("mark an In and an Out point first".into())) };
+ let dur = o + q.settings.frame_rate.frame_duration() - i;
+ let name = str_p(p, "name").unwrap_or("").to_string();
+ let id = add_marker(s, "Add Range Marker", i, dur, MarkerKind::Comment, name, p)?;
+ Ok(json!({"marker": id.0}))
+}
+
+fn filter_colors(s: &mut Session, p: &Value) -> Result<Value> {
+ if let Some(a) = p.get("hidden").and_then(Value::as_array) {
+ let mut v = Vec::new();
+ for x in a {
+ let n = x.as_str().unwrap_or_default();
+ v.push(Label::from_name(n).ok_or_else(|| bad("markers.filterColors", format!("unknown colour `{n}`")))?);
+ }
+ s.state.hidden_marker_colors = v;
+ } else if let Some(n) = str_p(p, "color") {
+ let c = Label::from_name(n).ok_or_else(|| bad("markers.filterColors", format!("unknown colour `{n}`")))?;
+ let hidden = s.state.hidden_marker_colors.contains(&c);
+ let visible = bool_p(p, "visible").unwrap_or(hidden);
+ s.state.hidden_marker_colors.retain(|x| *x != c);
+ if !visible {
+ s.state.hidden_marker_colors.push(c);
+ }
+ } else {
+ return Err(bad("markers.filterColors", "need `hidden` or `color`"));
+ }
+ Ok(json!({"hidden": s.state.hidden_marker_colors.iter().map(|c| c.name()).collect::<Vec<_>>()}))
+}
diff --git a/crates/engine/src/sequence_tools_tests.rs b/crates/engine/src/sequence_tools_tests.rs
new file mode 100644
index 000000000..c69016a46
--- /dev/null
+++ b/crates/engine/src/sequence_tools_tests.rs
@@ -0,0 +1,383 @@
+//! Sequence / Markers menu commands (`sequence_tools`).
+
+use super::*;
+use filmcraft_project::{Label, MarkerKind};
+use serde_json::json;
+
+fn demo() -> Session {
+ let mut s = Session::default();
+ s.execute("file.openDemoProject", json!({})).unwrap();
+ s
+}
+
+/// An empty 23.976 sequence and a 20 s Bars and Tone item (video + audio).
+fn fresh() -> (Session, u64) {
+ let mut s = Session::default();
+ s.execute("file.newSequence", json!({"name": "Test"})).unwrap();
+ let item = s.execute("file.newBarsAndTone", json!({"seconds": 20.0})).unwrap()["item"].as_u64().unwrap();
+ (s, item)
+}
+
+fn f(s: &Session, frames: i64) -> Tick {
+ s.sequence_rate().tick_of(frames)
+}
+
+fn place(s: &mut Session, item: u64, track: &str, at: i64, source_in: i64, frames: i64) -> Vec<u64> {
+ let (sin, dur) = (f(s, source_in), f(s, frames));
+ let at = f(s, at);
+ let audio = track.replace('V', "A");
+ let r =
+ s.execute("timeline.place", json!({"item": item, "track": track, "audioTrack": audio, "time": at.0, "sourceIn": sin.0, "duration": dur.0})).unwrap();
+ r["clips"].as_array().unwrap().iter().map(|c| c.as_u64().unwrap()).collect()
+}
+
+fn ids() -> Vec<&'static str> {
+ command_specs().iter().map(|c| c.id).collect()
+}
+
+#[test]
+fn commands_are_registered_in_premiere_menu_order() {
+ let s = Session::default();
+ let all = ids();
+ let after = |a: &str, b: &str| all.iter().position(|x| *x == a).unwrap() + 1 == all.iter().position(|x| *x == b).unwrap();
+ assert!(after("sequence.matchFrame", "sequence.reverseMatchFrame"));
+ assert!(after("sequence.closeGap", "sequence.goToNextGap"));
+ assert!(after("sequence.addTracks", "sequence.deleteTracks"));
+ assert!(after("markers.markSelection", "markers.markSplitVideoIn"));
+ assert!(after("markers.goToOut", "markers.goToSplitVideoIn"));
+ assert!(after("markers.add", "markers.addRange"));
+ let gap = find_command("sequence.goToPrevGap").unwrap();
+ assert_eq!(gap.menu, &["Sequence", "Go to Gap"]);
+ assert_eq!(gap.label, "Previous in Sequence");
+ assert_eq!(find_command("markers.clearAll").unwrap().label, "Clear Markers");
+ assert_eq!(s.shortcuts.primary("sequence.reverseMatchFrame").as_deref(), Some("Shift+R"));
+ assert_eq!(s.shortcuts.primary("sequence.goToNextGap").as_deref(), Some("Shift+;"));
+ assert_eq!(s.shortcuts.primary("sequence.makeSubsequence").as_deref(), Some("Shift+U"));
+ assert_eq!(s.shortcuts.primary("markers.addRangeInOut").as_deref(), Some("Ctrl+M"));
+ // every id is unique
+ let mut sorted = all.clone();
+ sorted.sort_unstable();
+ sorted.dedup();
+ assert_eq!(sorted.len(), all.len());
+}
+
+#[test]
+fn go_to_gap_in_sequence_and_in_track() {
+ let (mut s, bars) = fresh();
+ let matte = s.execute("file.newColorMatte", json!({"seconds": 20.0})).unwrap()["item"].as_u64().unwrap();
+ place(&mut s, bars, "V1", 0, 0, 48); // V1/A1 0–48
+ place(&mut s, bars, "V1", 96, 0, 48); // V1/A1 96–144
+ s.execute("timeline.place", json!({"item": matte, "track": "V2", "frame": 48, "duration": f(&s, 24).0})).unwrap(); // V2 48–72
+ // sequence: empty everywhere only in 72–96; V1: 48–96
+ s.execute("playhead.set", json!({"frame": 0})).unwrap();
+ let r = s.execute("sequence.goToNextGap", json!({})).unwrap();
+ assert_eq!(r["time"], json!(f(&s, 72).0));
+ s.execute("playhead.set", json!({"frame": 0})).unwrap();
+ s.execute("sequence.goToNextGapInTrack", json!({"track": "V1"})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 48));
+ // V2 has a leading gap from 0 and nothing after its clip
+ s.execute("playhead.set", json!({"frame": 100})).unwrap();
+ s.execute("sequence.goToPrevGapInTrack", json!({"track": "V2"})).unwrap();
+ assert_eq!(s.playhead(), Tick::ZERO);
+ s.execute("playhead.set", json!({"frame": 120})).unwrap();
+ s.execute("sequence.goToPrevGap", json!({})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 72));
+ // no further gap: the playhead stays
+ let r = s.execute("sequence.goToNextGap", json!({})).unwrap();
+ assert!(r["time"].is_null());
+ assert_eq!(s.playhead(), f(&s, 72));
+ // in track defaults to the targeted tracks
+ s.execute("playhead.set", json!({"frame": 0})).unwrap();
+ s.execute("sequence.goToNextGapInTrack", json!({})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 48));
+}
+
+#[test]
+fn reverse_match_frame_finds_the_source_frame() {
+ let (mut s, bars) = fresh();
+ place(&mut s, bars, "V1", 0, 0, 48); // media 0–48
+ place(&mut s, bars, "V1", 96, 72, 48); // media 72–120 at 96
+ assert!(s.execute("sequence.reverseMatchFrame", json!({})).is_err(), "needs a source clip");
+ s.execute("source.open", json!({"item": bars})).unwrap();
+ s.execute("source.setPlayhead", json!({"frame": 84})).unwrap();
+ let r = s.execute("sequence.reverseMatchFrame", json!({})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 108), "{r}");
+ s.execute("source.setPlayhead", json!({"frame": 10})).unwrap();
+ s.execute("sequence.reverseMatchFrame", json!({})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 10));
+ s.execute("source.setPlayhead", json!({"frame": 60})).unwrap();
+ assert!(s.execute("sequence.reverseMatchFrame", json!({})).is_err(), "frame 60 is not in the sequence");
+ // match frame (F) and reverse match frame (Shift+R) are inverses
+ s.execute("playhead.set", json!({"frame": 130})).unwrap();
+ s.execute("sequence.matchFrame", json!({})).unwrap();
+ s.execute("playhead.set", json!({"frame": 0})).unwrap();
+ s.execute("sequence.reverseMatchFrame", json!({})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 130));
+}
+
+#[test]
+fn through_edits_show_and_join() {
+ let mut s = demo();
+ let before = s.active_sequence().unwrap().clone();
+ assert!(s.execute("sequence.throughEdits", json!({})).unwrap().as_array().unwrap().is_empty());
+ s.execute("playhead.set", json!({"frame": 30})).unwrap();
+ s.execute("sequence.addEditAllTracks", json!({})).unwrap();
+ let te = s.execute("sequence.throughEdits", json!({})).unwrap();
+ let n = te.as_array().unwrap().len();
+ assert!(n >= 2, "V1 and A1 (and the music) get through edits: {te}");
+ assert!(te.as_array().unwrap().iter().all(|e| e["time"] == json!(f(&s, 30).0)));
+ assert_eq!(s.execute("sequence.showThroughEdits", json!({})).unwrap()["showThroughEdits"], json!(true));
+ // join only the V1 one (and its linked audio)
+ let v1 = te.as_array().unwrap().iter().find(|e| e["track"] == json!(before.video_tracks[0].id.0)).unwrap()["right"].as_u64().unwrap();
+ let r = s.execute("sequence.joinThroughEdits", json!({"clips": [v1]})).unwrap();
+ assert_eq!(r["joined"], json!(2), "V1 + linked A1");
+ assert_eq!(s.execute("sequence.throughEdits", json!({})).unwrap().as_array().unwrap().len(), n - 2);
+ s.execute("sequence.joinThroughEdits", json!({"all": true})).unwrap();
+ let q = s.active_sequence().unwrap();
+ for (a, b) in q.all_tracks().zip(before.all_tracks()) {
+ assert_eq!(a.items, b.items, "{}", a.name);
+ }
+ assert!(s.execute("sequence.joinThroughEdits", json!({"all": true})).is_err(), "nothing left to join");
+ s.execute("edit.undo", json!({})).unwrap();
+ assert_eq!(s.execute("sequence.throughEdits", json!({})).unwrap().as_array().unwrap().len(), n - 2);
+}
+
+#[test]
+fn make_subsequence_from_in_out_and_from_selection() {
+ let mut s = demo();
+ let seq = s.state.active_sequence.unwrap();
+ let orig = s.active_sequence().unwrap().clone();
+ assert!(s.execute("sequence.makeSubsequence", json!({})).is_err(), "needs In/Out or a selection");
+ s.execute("markers.markIn", json!({"frame": 30})).unwrap();
+ s.execute("markers.markOut", json!({"frame": 77})).unwrap();
+ let r = s.execute("sequence.makeSubsequence", json!({})).unwrap();
+ let sub = ItemId(r["sequence"].as_u64().unwrap());
+ assert_eq!(r["name"], json!("Main Edit_Sub_01"));
+ assert_eq!(s.state.active_sequence, Some(seq), "the original stays open");
+ assert_eq!(s.state.project_selection, vec![sub]);
+ let q = s.project.sequence(sub).unwrap();
+ q.check().unwrap();
+ assert_eq!(q.duration(), f(&s, 48));
+ assert_eq!(q.video_tracks.len(), orig.video_tracks.len());
+ // same frames at the same relative times
+ for (nt, ot) in q.all_tracks().zip(orig.all_tracks()) {
+ for it in &nt.items {
+ let t = it.start + Tick(1);
+ let o = ot.item_at(t + f(&s, 30)).expect("source clip");
+ assert_eq!(it.item, o.item);
+ assert_eq!(it.source_time_at(t), o.source_time_at(t + f(&s, 30)));
+ }
+ }
+ // ids are fresh, links stay pairwise
+ let all: Vec<_> = q.all_tracks().flat_map(|t| t.items.iter().map(|i| i.id)).collect();
+ assert!(all.iter().all(|c| orig.find_item(*c).is_none()));
+ for (a, b) in s.active_sequence().unwrap().all_tracks().zip(orig.all_tracks()) {
+ assert_eq!(a, b, "source sequence untouched");
+ }
+ // from a selection (no In/Out): the clips, starting at 0
+ s.execute("markers.clearInOut", json!({})).unwrap();
+ let c = orig.video_tracks[0].items[2].clone();
+ s.execute("timeline.select", json!({"clips": [c.id.0]})).unwrap();
+ let r = s.execute("sequence.makeSubsequence", json!({"name": "Shot 3"})).unwrap();
+ let q = s.project.sequence(ItemId(r["sequence"].as_u64().unwrap())).unwrap();
+ assert_eq!(q.video_tracks[0].items.len(), 1);
+ assert_eq!(q.video_tracks[0].items[0].start, Tick::ZERO);
+ assert_eq!(q.video_tracks[0].items[0].duration, c.duration);
+ assert_eq!(q.audio_tracks[0].items.len(), 1, "linked audio comes along");
+ assert_eq!(s.project.item(ItemId(r["sequence"].as_u64().unwrap())).unwrap().name, "Shot 3");
+ s.execute("edit.undo", json!({})).unwrap();
+ assert!(s.project.items.values().all(|i| i.name != "Shot 3"));
+}
+
+#[test]
+fn delete_tracks_empty_and_specific() {
+ let mut s = demo();
+ let q = s.active_sequence().unwrap().clone();
+ let empty_v = q.video_tracks.iter().filter(|t| t.items.is_empty()).count();
+ let empty_a = q.audio_tracks.iter().filter(|t| t.items.is_empty()).count();
+ assert!(empty_v > 0 && empty_a > 0, "demo has empty tracks");
+ let r = s.execute("sequence.deleteTracks", json!({"video": "empty", "audio": "empty"})).unwrap();
+ assert_eq!(r["deleted"], json!(empty_v + empty_a));
+ let q2 = s.active_sequence().unwrap();
+ assert!(q2.all_tracks().all(|t| !t.items.is_empty()));
+ assert!(s.execute("sequence.deleteTracks", json!({"video": "empty"})).is_err(), "nothing left to delete");
+ // a specific track; its clips go with it
+ s.execute("sequence.deleteTracks", json!({"video": "V2"})).unwrap();
+ assert_eq!(s.active_sequence().unwrap().video_tracks.len(), q.video_tracks.len() - empty_v - 1);
+ assert!(s.execute("sequence.deleteTracks", json!({"video": "A1"})).is_err(), "kind must match");
+ // the last track of a kind stays
+ let r = s.execute("sequence.deleteTracks", json!({"video": "V1"}));
+ assert!(r.is_err(), "{r:?}");
+ s.execute("edit.undo", json!({})).unwrap();
+ s.execute("edit.undo", json!({})).unwrap();
+ assert_eq!(s.active_sequence().unwrap(), &q);
+}
+
+#[test]
+fn split_points_on_the_sequence() {
+ let (mut s, bars) = fresh();
+ place(&mut s, bars, "V1", 0, 0, 240);
+ s.execute("markers.markIn", json!({"frame": 10})).unwrap();
+ s.execute("markers.markOut", json!({"frame": 100})).unwrap();
+ assert!(!s.is_enabled("markers.goToSplitVideoIn"), "no split yet");
+ s.execute("markers.markSplitAudioIn", json!({"frame": 20})).unwrap();
+ s.execute("markers.markSplitVideoOut", json!({"frame": 90})).unwrap();
+ let q = s.active_sequence().unwrap();
+ assert_eq!(q.split.audio_in, Some(f(&s, 20)));
+ assert_eq!(q.split.video_out, Some(f(&s, 90)));
+ // go to: split points, or the ordinary In/Out for the other channel
+ s.execute("markers.goToSplitAudioIn", json!({})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 20));
+ s.execute("markers.goToSplitVideoIn", json!({})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 10));
+ s.execute("markers.goToSplitVideoOut", json!({})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 90));
+ s.execute("markers.goToSplitAudioOut", json!({})).unwrap();
+ assert_eq!(s.playhead(), f(&s, 100));
+ // a split Out before a split In clears the In of that channel
+ s.execute("markers.markSplitAudioOut", json!({"frame": 15})).unwrap();
+ assert_eq!(s.active_sequence().unwrap().split.audio_in, None);
+ // Mark In replaces the In splits; Clear In and Out clears everything
+ s.execute("markers.markSplitAudioIn", json!({"frame": 5})).unwrap();
+ s.execute("markers.markIn", json!({"frame": 12})).unwrap();
+ let sp = s.active_sequence().unwrap().split;
+ assert_eq!((sp.video_in, sp.audio_in), (None, None));
+ assert!(sp.video_out.is_some());
+ s.execute("markers.clearInOut", json!({})).unwrap();
+ assert!(s.active_sequence().unwrap().split.is_empty());
+ s.execute("edit.undo", json!({})).unwrap();
+ assert!(!s.active_sequence().unwrap().split.is_empty(), "split points are undoable");
+}
+
+#[test]
+fn source_split_points_make_l_and_j_cuts() {
+ let (mut s, bars) = fresh();
+ s.execute("source.open", json!({"item": bars})).unwrap();
+ let r = s.sequence_rate();
+ s.execute("project.setMarks", json!({"item": bars, "in": r.tick_of(48).0, "out": r.tick_of(95).0})).unwrap();
+ // J-cut: audio starts 12 frames before the picture
+ s.execute("markers.markSplitAudioIn", json!({"target": "source", "time": r.tick_of(36).0})).unwrap();
+ assert_eq!(s.project.item(ItemId(bars)).unwrap().split.audio_in, Some(r.tick_of(36)));
+ s.execute("markers.goToSplitAudioIn", json!({"target": "source"})).unwrap();
+ assert_eq!(s.state.source_playhead, r.tick_of(36));
+ s.execute("playhead.set", json!({"frame": 0})).unwrap();
+ s.execute("source.overwrite", json!({})).unwrap();
+ let q = s.active_sequence().unwrap();
+ let v = &q.video_tracks[0].items[0];
+ let a = &q.audio_tracks[0].items[0];
+ assert_eq!((v.start, v.duration, v.source_in), (r.tick_of(12), r.tick_of(48), r.tick_of(48)));
+ assert_eq!((a.start, a.duration, a.source_in), (Tick::ZERO, r.tick_of(60), r.tick_of(36)));
+ assert_eq!(v.link, a.link, "still linked");
+ assert_eq!(v.source_time_at(r.tick_of(30)), a.source_time_at(r.tick_of(30)), "in sync");
+ assert_eq!(s.playhead(), r.tick_of(60));
+ // an ordinary In clears the source split In
+ s.execute("markers.markIn", json!({"target": "source", "time": r.tick_of(40).0})).unwrap();
+ assert!(s.project.item(ItemId(bars)).unwrap().split.audio_in.is_none());
+}
+
+#[test]
+fn range_and_chapter_markers() {
+ let mut s = demo();
+ s.execute("playhead.set", json!({"frame": 24})).unwrap();
+ let id = s.execute("markers.addRange", json!({})).unwrap()["marker"].as_u64().unwrap();
+ let m = s.active_sequence().unwrap().markers.iter().find(|m| m.id.0 == id).unwrap().clone();
+ assert_eq!((m.start, m.duration), (f(&s, 24), f(&s, 24)), "one second");
+ s.execute("markers.addRange", json!({"durationFrames": 10, "color": "Rose"})).unwrap();
+ assert!(!s.is_enabled("markers.addRangeInOut"));
+ s.execute("markers.markIn", json!({"frame": 48})).unwrap();
+ s.execute("markers.markOut", json!({"frame": 71})).unwrap();
+ let id = s.execute("markers.addRangeInOut", json!({"name": "Scene"})).unwrap()["marker"].as_u64().unwrap();
+ let m = s.active_sequence().unwrap().markers.iter().find(|m| m.id.0 == id).unwrap().clone();
+ assert_eq!((m.start, m.duration, m.name.as_str()), (f(&s, 48), f(&s, 24), "Scene"));
+ let id = s.execute("markers.addChapter", json!({"frame": 100})).unwrap()["marker"].as_u64().unwrap();
+ let m = s.active_sequence().unwrap().markers.iter().find(|m| m.id.0 == id).unwrap().clone();
+ assert_eq!((m.kind, m.name.as_str(), m.start), (MarkerKind::Chapter, "Chapter 1", f(&s, 100)));
+ // colour filter + Show All Marker Colors
+ assert!(!s.is_enabled("markers.showAllMarkerColors"));
+ s.execute("markers.filterColors", json!({"color": "Rose", "visible": false})).unwrap();
+ assert_eq!(s.state.hidden_marker_colors, vec![Label::Rose]);
+ s.execute("markers.showAllMarkerColors", json!({})).unwrap();
+ assert!(s.state.hidden_marker_colors.is_empty());
+ assert!(s.execute("markers.filterColors", json!({"hidden": ["Nope"]})).is_err());
+ s.execute("markers.clearAll", json!({})).unwrap();
+ assert!(s.active_sequence().unwrap().markers.is_empty());
+}
+
+#[test]
+fn ripple_sequence_markers_follow_ripple_edits() {
+ let mut s = demo();
+ s.execute("markers.clearAll", json!({})).unwrap();
+ let mk = |s: &mut Session, frame: i64| {
+ s.execute("markers.add", json!({"frame": frame})).unwrap()["marker"].as_u64().unwrap();
+ };
+ mk(&mut s, 30);
+ mk(&mut s, 200);
+ let starts = |s: &Session| s.active_sequence().unwrap().markers.iter().map(|m| m.start).collect::<Vec<_>>();
+ // off: extract leaves markers alone
+ s.execute("markers.markIn", json!({"frame": 24})).unwrap();
+ s.execute("markers.markOut", json!({"frame": 47})).unwrap();
+ s.execute("sequence.extract", json!({})).unwrap();
+ assert_eq!(starts(&s), vec![f(&s, 30), f(&s, 200)]);
+ s.execute("edit.undo", json!({})).unwrap();
+ // on: the marker inside goes, the later one moves left
+ assert_eq!(s.execute("markers.rippleSequenceMarkers", json!({})).unwrap()["rippleSequenceMarkers"], json!(true));
+ s.execute("sequence.extract", json!({})).unwrap();
+ assert_eq!(starts(&s), vec![f(&s, 176)]);
+ s.execute("edit.undo", json!({})).unwrap();
+ // insert from the source pushes later markers right
+ let item = s.active_sequence().unwrap().video_tracks[0].items[0].item;
+ s.execute("source.open", json!({"item": item.0})).unwrap();
+ let r = s.sequence_rate();
+ s.execute("project.setMarks", json!({"item": item.0, "in": r.tick_of(0).0, "out": r.tick_of(11).0})).unwrap();
+ s.execute("markers.clearInOut", json!({})).unwrap();
+ s.execute("playhead.set", json!({"frame": 100})).unwrap();
+ s.execute("source.insert", json!({})).unwrap();
+ assert_eq!(starts(&s), vec![f(&s, 30), f(&s, 212)]);
+ // ripple trim of the first clip's out point moves the later markers
+ let first = s.active_sequence().unwrap().video_tracks[0].items[0].clone();
+ s.execute("timeline.setTrack", json!({"track": "A2", "syncLock": false})).unwrap();
+ s.execute("timeline.trim", json!({"clip": first.id.0, "edge": "out", "mode": "ripple", "deltaFrames": -6})).unwrap();
+ let st = starts(&s);
+ assert_eq!(st.last(), Some(&f(&s, 206)), "{st:?}");
+}
+
+#[test]
+fn copy_paste_includes_sequence_markers() {
+ let mut s = demo();
+ s.execute("markers.clearAll", json!({})).unwrap();
+ let first = s.active_sequence().unwrap().video_tracks[0].items[0].clone();
+ s.execute("markers.add", json!({"frame": 10, "name": "a"})).unwrap();
+ s.execute("timeline.select", json!({"clips": [first.id.0]})).unwrap();
+ s.execute("edit.copy", json!({})).unwrap();
+ s.execute("playhead.set", json!({"frame": 500})).unwrap();
+ s.execute("edit.paste", json!({})).unwrap();
+ assert_eq!(s.active_sequence().unwrap().markers.len(), 1, "off: markers stay behind");
+ s.execute("edit.undo", json!({})).unwrap();
+ s.execute("markers.copyPasteIncludesSequenceMarkers", json!({"on": true})).unwrap();
+ s.execute("timeline.select", json!({"clips": [first.id.0]})).unwrap();
+ s.execute("edit.copy", json!({})).unwrap();
+ s.execute("playhead.set", json!({"frame": 500})).unwrap();
+ s.execute("edit.paste", json!({})).unwrap();
+ let ms = &s.active_sequence().unwrap().markers;
+ assert_eq!(ms.len(), 2);
+ assert_eq!(ms[1].start, f(&s, 510));
+ assert_eq!(ms[1].name, "a");
+ assert_ne!(ms[0].id, ms[1].id);
+}
+
+#[test]
+fn selection_follows_playhead() {
+ let mut s = demo();
+ s.execute("sequence.selectionFollowsPlayhead", json!({"on": true})).unwrap();
+ s.execute("playhead.set", json!({"frame": 10})).unwrap();
+ let q = s.active_sequence().unwrap();
+ let v = q.video_tracks[0].item_at(f(&s, 10)).unwrap().id;
+ let a = q.audio_tracks[0].item_at(f(&s, 10)).unwrap().id;
+ assert!(s.state.selection.contains(&v) && s.state.selection.contains(&a), "{:?}", s.state.selection);
+ s.execute("playhead.nextEdit", json!({})).unwrap();
+ assert!(!s.state.selection.contains(&v), "moves on with the playhead");
+ s.execute("sequence.selectionFollowsPlayhead", json!({})).unwrap();
+ let sel = s.state.selection.clone();
+ s.execute("playhead.set", json!({"frame": 10})).unwrap();
+ assert_eq!(s.state.selection, sel, "off again");
+}
diff --git a/crates/engine/src/shortcut_presets.rs b/crates/engine/src/shortcut_presets.rs
index fa4d1fdc0..a82d143e6 100644
--- a/crates/engine/src/shortcut_presets.rs
+++ b/crates/engine/src/shortcut_presets.rs
@@ -123,6 +123,12 @@ pub const PREMIERE: &[Entry] = &[
("markers.goPrev", "Cmd+Shift+M", ""),
("markers.clearCurrent", "Alt+M", ""),
("markers.clearAll", "Cmd+Alt+M", ""),
+ ("markers.addRange", "Ctrl+Shift+M", ""),
+ ("markers.addRangeInOut", "Ctrl+M", ""),
+ ("sequence.reverseMatchFrame", "Shift+R", ""),
+ ("sequence.goToNextGap", "Shift+;", ""),
+ ("sequence.goToPrevGap", "Alt+;", ""),
+ ("sequence.makeSubsequence", "Shift+U", ""),
// Window
("window.workspace.reset", "Alt+Shift+0", ""),
("window.workspace.editing", "Alt+Shift+1", ""),
diff --git a/crates/interchange/src/common.rs b/crates/interchange/src/common.rs
index f7332252e..e886b3b0a 100644
--- a/crates/interchange/src/common.rs
+++ b/crates/interchange/src/common.rs
@@ -486,6 +486,7 @@ pub(crate) fn empty_sequence(settings: SequenceSettings) -> Sequence {
caption_tracks: Vec::new(),
multicam: None,
merged: None,
+ split: Default::default(),
}
}
diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs
index f8d4d80cc..513257c86 100644
--- a/crates/project/src/lib.rs
+++ b/crates/project/src/lib.rs
@@ -254,6 +254,10 @@ pub struct ProjectItem {
/// Import time counter (for "Date Created"/sorting), not wall clock.
#[serde(default)]
pub created: u64,
+ /// Split In/Out points set in the Source monitor (Markers ▸ Mark Split); they override the
+ /// item's In/Out for one channel (J- and L-cuts).
+ #[serde(default, skip_serializing_if = "SplitMarks::is_empty")]
+ pub split: SplitMarks,
}
impl ProjectItem {
@@ -740,6 +744,39 @@ pub struct Sequence {
/// Set on merged clips (the merged video and audio items).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub merged: Option<MergedClip>,
+ /// Split In/Out points (Markers ▸ Mark Split): per-channel overrides of `mark_in`/`mark_out`.
+ #[serde(default, skip_serializing_if = "SplitMarks::is_empty")]
+ pub split: SplitMarks,
+}
+
+/// Split edit points: separate video and audio In/Out points (Markers ▸ Mark Split). `None` means
+/// the channel uses the ordinary In/Out point.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(default, rename_all = "camelCase")]
+pub struct SplitMarks {
+ pub video_in: Option<Tick>,
+ pub video_out: Option<Tick>,
+ pub audio_in: Option<Tick>,
+ pub audio_out: Option<Tick>,
+}
+
+impl SplitMarks {
+ pub fn is_empty(&self) -> bool {
+ *self == Self::default()
+ }
+ /// The video In point given the ordinary In point.
+ pub fn video_in_or(&self, mark_in: Option<Tick>) -> Option<Tick> {
+ self.video_in.or(mark_in)
+ }
+ pub fn video_out_or(&self, mark_out: Option<Tick>) -> Option<Tick> {
+ self.video_out.or(mark_out)
+ }
+ pub fn audio_in_or(&self, mark_in: Option<Tick>) -> Option<Tick> {
+ self.audio_in.or(mark_in)
+ }
+ pub fn audio_out_or(&self, mark_out: Option<Tick>) -> Option<Tick> {
+ self.audio_out.or(mark_out)
+ }
}
impl Sequence {
@@ -923,7 +960,7 @@ impl Project {
pub fn add_item(&mut self, name: &str, label: Label, kind: ItemKind, bin: Option<BinId>) -> ItemId {
let id = ItemId(self.alloc_id());
let created = id.0;
- self.items.insert(id, ProjectItem { id, name: name.into(), label, kind, metadata: BTreeMap::new(), created });
+ self.items.insert(id, ProjectItem { id, name: name.into(), label, kind, metadata: BTreeMap::new(), created, split: SplitMarks::default() });
if let Some(b) = bin.and_then(|b| self.root.find_bin_mut(b)) {
b.children.push(BinEntry::Item(id));
} else {
@@ -992,6 +1029,7 @@ impl Project {
caption_tracks: Vec::new(),
multicam: None,
merged: None,
+ split: SplitMarks::default(),
};
for i in 0..v {
let id = TrackId(self.alloc_id());
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 8b2c24388..87e157c97 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -75,6 +75,8 @@ pub enum Dialog {
RevertConfirm,
/// Clip ▸ Audio Gain… (G).
AudioGain,
+ /// Sequence ▸ Delete Tracks….
+ DeleteTracks,
}
#[derive(Default)]
@@ -639,7 +641,9 @@ impl FilmcraftApp {
});
for id in fire {
// Mark In/Out in the Source monitor when it has focus.
- let params = if self.ui.focused == PanelKind::Source && matches!(id.as_str(), "markers.markIn" | "markers.markOut") {
+ let params = if self.ui.focused == PanelKind::Source
+ && (matches!(id.as_str(), "markers.markIn" | "markers.markOut") || id.starts_with("markers.markSplit") || id.starts_with("markers.goToSplit"))
+ {
json!({"target": "source"})
} else {
json!({})
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 490d8c6fb..3e7888dff 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -202,6 +202,12 @@ pub fn invoke(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, params: Val
crate::panels::color_dialogs::open_interpret(app, &params);
return Ok(json!({"dialog": "interpretFootage"}));
}
+ "sequence.deleteTracks" if params.as_object().is_none_or(|m| m.is_empty()) => {
+ filmcraft_engine::find_command(id).map_or(Ok(()), |c| (c.enabled)(&app.session))?;
+ app.ui.delete_tracks = Default::default();
+ app.dialog = Some(crate::Dialog::DeleteTracks);
+ return Ok(json!({"dialog": "deleteTracks"}));
+ }
"sequence.colorSettings" if params.as_object().is_none_or(|m| m.is_empty()) => {
filmcraft_engine::find_command(id).map_or(Ok(()), |c| (c.enabled)(&app.session))?;
crate::panels::color_dialogs::open_sequence(app);
@@ -357,10 +363,29 @@ pub type KeyBinding = (egui::Modifiers, egui::Key, String, Option<String>);
pub fn bindings(app: &FilmcraftApp) -> Vec<KeyBinding> {
let mut v: Vec<KeyBinding> =
app.session.shortcuts.bindings.iter().filter_map(|b| parse_shortcut(&b.keys).map(|(m, k)| (m, k, b.command.clone(), b.panel.clone()))).collect();
+ // With Shift held, a punctuation key arrives as its shifted glyph (Shift+; is `:` on US layouts).
+ let shifted: Vec<KeyBinding> =
+ v.iter().filter(|b| b.0.shift).filter_map(|(m, k, id, p)| shifted_key(*k).map(|k2| (*m, k2, id.clone(), p.clone()))).collect();
+ v.extend(shifted);
v.sort_by_key(|(m, ..)| std::cmp::Reverse(m.command as u8 + m.shift as u8 + m.alt as u8 + m.ctrl as u8));
v
}
+/// The key a US layout reports for `k` with Shift held, when it differs.
+fn shifted_key(k: egui::Key) -> Option<egui::Key> {
+ use egui::Key;
+ Some(match k {
+ Key::Semicolon => Key::Colon,
+ Key::Slash => Key::Questionmark,
+ Key::Equals => Key::Plus,
+ Key::Backslash => Key::Pipe,
+ Key::Num1 => Key::Exclamationmark,
+ Key::OpenBracket => Key::OpenCurlyBracket,
+ Key::CloseBracket => Key::CloseCurlyBracket,
+ _ => return None,
+ })
+}
+
/// Frontend-owned commands, registered with the engine's shortcut set so they can be listed,
/// rebound and resolved alongside engine commands (the `shortcuts.` commands).
pub fn external_commands() -> Vec<filmcraft_engine::shortcuts::CommandInfo> {
diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs
index dc18d4ace..574476c74 100644
--- a/crates/ui-egui/src/panels/dialogs.rs
+++ b/crates/ui-egui/src/panels/dialogs.rs
@@ -37,6 +37,12 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
}
return;
}
+ Dialog::DeleteTracks => {
+ if !delete_tracks(app, ctx) {
+ app.dialog = None;
+ }
+ return;
+ }
Dialog::NewSequence | Dialog::Preferences | Dialog::Recovery | Dialog::RevertConfirm => {}
}
if !open {
@@ -124,3 +130,84 @@ fn audio_gain(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
app.ui.audio_gain = draft;
keep
}
+
+/// Sequence ▸ Delete Tracks…: "Delete Video Tracks" / "Delete Audio Tracks" checkboxes, each with a
+/// track choice (All Empty Tracks or one track). Returns whether the dialog stays open.
+///
+/// Automation ids: `deleteTracks.video`, `deleteTracks.audio` (checkboxes),
+/// `deleteTracks.video.target`, `deleteTracks.audio.target` (track menus),
+/// `deleteTracks.<kind>.option.<empty|V1|A2…>` (menu entries while open), `deleteTracks.ok`,
+/// `deleteTracks.cancel`.
+fn delete_tracks(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
+ let Some(seq) = app.session.active_sequence() else { return false };
+ let names = |n: usize, p: &str| (1..=n).map(|i| format!("{p}{i}")).collect::<Vec<_>>();
+ let vnames = names(seq.video_tracks.len(), "V");
+ let anames = names(seq.audio_tracks.len(), "A");
+ let mut draft = app.ui.delete_tracks.clone();
+ let mut keep = true;
+ let mut apply = false;
+ let mut elems: Vec<(String, egui::Rect, String)> = Vec::new();
+ egui::Window::new("Delete Tracks").collapsible(false).resizable(false).anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0]).show(ctx, |ui| {
+ ui.set_min_width(300.0);
+ for (kind, title, on, target, list) in [
+ ("video", "Video Tracks", &mut draft.video, &mut draft.video_target, &vnames),
+ ("audio", "Audio Tracks", &mut draft.audio, &mut draft.audio_target, &anames),
+ ] {
+ ui.add_space(4.0);
+ ui.label(egui::RichText::new(title).strong());
+ let label = format!("Delete {title}");
+ let c = ui.checkbox(on, &label);
+ elems.push((format!("deleteTracks.{kind}"), c.rect, label));
+ ui.horizontal(|ui| {
+ ui.add_space(22.0);
+ let shown = if target == "empty" { "All Empty Tracks".to_string() } else { target.clone() };
+ ui.add_enabled_ui(*on, |ui| {
+ let r = egui::ComboBox::from_id_salt(("delete-tracks", kind)).selected_text(&shown).width(170.0).show_ui(ui, |ui| {
+ let e = ui.selectable_value(target, "empty".to_string(), "All Empty Tracks");
+ elems.push((format!("deleteTracks.{kind}.option.empty"), e.rect, "All Empty Tracks".into()));
+ for n in list {
+ let r = ui.selectable_value(target, n.clone(), n);
+ elems.push((format!("deleteTracks.{kind}.option.{n}"), r.rect, n.clone()));
+ }
+ });
+ elems.push((format!("deleteTracks.{kind}.target"), r.response.rect, shown));
+ });
+ });
+ }
+ ui.add_space(10.0);
+ ui.horizontal(|ui| {
+ let c = ui.button("Cancel");
+ elems.push(("deleteTracks.cancel".into(), c.rect, "Cancel".into()));
+ if c.clicked() {
+ keep = false;
+ }
+ let o =
+ ui.add_enabled(draft.video || draft.audio, egui::Button::new(egui::RichText::new("OK").color(egui::Color32::WHITE)).fill(app.tokens.accent));
+ elems.push(("deleteTracks.ok".into(), o.rect, "OK".into()));
+ if o.clicked() {
+ apply = true;
+ }
+ });
+ });
+ for (id, r, l) in elems {
+ app.auto.add(&id, r, &l);
+ }
+ if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
+ keep = false;
+ }
+ if apply {
+ let mut p = serde_json::Map::new();
+ if draft.video {
+ p.insert("video".into(), serde_json::json!(draft.video_target));
+ }
+ if draft.audio {
+ p.insert("audio".into(), serde_json::json!(draft.audio_target));
+ }
+ if let Err(e) = app.session.execute("sequence.deleteTracks", serde_json::Value::Object(p)) {
+ app.ui.status = e.to_string();
+ }
+ keep = false;
+ }
+ app.ui.delete_tracks = draft;
+ keep
+}
diff --git a/crates/ui-egui/src/panels/misc.rs b/crates/ui-egui/src/panels/misc.rs
index 53659aa0e..9727bf34b 100644
--- a/crates/ui-egui/src/panels/misc.rs
+++ b/crates/ui-egui/src/panels/misc.rs
@@ -52,39 +52,84 @@ pub fn history(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
}
+/// The marker colours of the Markers panel filter (each chip stands for the labels that share its
+/// marker colour).
+pub const MARKER_FILTER: [filmcraft_project::Label; 7] = {
+ use filmcraft_project::Label::*;
+ [Green, Rose, Purple, Mango, Yellow, Blue, Teal]
+};
+
+/// Markers panel: a colour filter row (click a chip to show/hide that colour; automation ids
+/// `markers.filter.<label>`), then the sequence markers (`markers.row.<id>`; click = go to it).
pub fn markers(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
let t = app.tokens;
let Some(seq) = app.session.active_sequence().cloned() else {
crate::dock::placeholder(ui, rect, &t, "(no sequence)");
return;
};
+ let hidden: Vec<[u8; 3]> = app.session.state.hidden_marker_colors.iter().map(|l| l.marker_rgb()).collect();
let mut child = ui.new_child(egui::UiBuilder::new().max_rect(rect.shrink(6.0)));
let mut go = None;
+ let mut toggle = None;
+ let mut elems: Vec<(String, Rect, String)> = Vec::new();
+ child.horizontal(|ui| {
+ for l in MARKER_FILTER {
+ let c = l.marker_rgb();
+ let on = !hidden.contains(&c);
+ let (r, resp) = ui.allocate_exact_size(vec2(16.0, 16.0), Sense::click());
+ let col = Color32::from_rgb(c[0], c[1], c[2]);
+ if on {
+ ui.painter().rect_filled(r.shrink(2.0), 3.0, col);
+ } else {
+ ui.painter().rect_stroke(r.shrink(2.5), 3.0, egui::Stroke::new(1.0, col), egui::StrokeKind::Inside);
+ }
+ elems.push((format!("markers.filter.{}", l.name()), r, format!("{} markers {}", l.name(), if on { "shown" } else { "hidden" })));
+ if resp.on_hover_text(format!("Show or hide {} markers", l.name())).clicked() {
+ toggle = Some((l, !on));
+ }
+ }
+ });
+ child.add_space(4.0);
egui::ScrollArea::vertical().auto_shrink([false, false]).show(&mut child, |ui| {
- for m in &seq.markers {
+ let mut shown = 0;
+ for m in seq.markers.iter().filter(|m| !hidden.contains(&m.color.marker_rgb())) {
+ shown += 1;
let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 38.0), Sense::click());
if resp.hovered() {
ui.painter().rect_filled(r, 3.0, t.hover);
}
- let c = m.color.rgb();
+ let c = m.color.marker_rgb();
ui.painter().rect_filled(Rect::from_min_size(r.min + vec2(4.0, 6.0), vec2(4.0, 26.0)), 2.0, Color32::from_rgb(c[0], c[1], c[2]));
- ui.painter().text(
- pos2(r.min.x + 16.0, r.min.y + 12.0),
- Align2::LEFT_CENTER,
- if m.name.is_empty() { "Marker" } else { &m.name },
- Tokens::ui(12.0),
- t.text,
- );
- let tc = format_time(m.start, seq.settings.frame_rate, seq.settings.drop_frame, TimeDisplay::Timecode, 48000);
+ let name = if m.name.is_empty() { "Marker" } else { &m.name };
+ ui.painter().text(pos2(r.min.x + 16.0, r.min.y + 12.0), Align2::LEFT_CENTER, name, Tokens::ui(12.0), t.text);
+ let mut tc = format_time(m.start, seq.settings.frame_rate, seq.settings.drop_frame, TimeDisplay::Timecode, 48000);
+ if m.duration > filmcraft_time::Tick::ZERO {
+ let d = format_time(m.duration, seq.settings.frame_rate, seq.settings.drop_frame, TimeDisplay::Timecode, 48000);
+ tc = format!("{tc} ({d})");
+ }
+ if m.kind == filmcraft_project::MarkerKind::Chapter {
+ tc = format!("{tc} Chapter");
+ }
ui.painter().text(pos2(r.min.x + 16.0, r.min.y + 27.0), Align2::LEFT_CENTER, tc, Tokens::mono(11.0), t.hot_text);
+ elems.push((format!("markers.row.{}", m.id.0), r, name.to_string()));
if resp.clicked() {
go = Some(m.start);
}
}
if seq.markers.is_empty() {
ui.label(egui::RichText::new("No markers. Press M to add one.").color(t.text_faint));
+ } else if shown == 0 {
+ ui.label(egui::RichText::new("All markers are hidden by the colour filter.").color(t.text_faint));
}
});
+ for (id, r, l) in elems {
+ app.auto.add(&id, r, &l);
+ }
+ if let Some((l, visible)) = toggle
+ && let Err(e) = app.session.execute("markers.filterColors", json!({"color": l.name(), "visible": visible}))
+ {
+ app.ui.status = e.to_string();
+ }
if let Some(g) = go {
app.session.set_playhead(g);
}
diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs
index a695ffaa8..fbc667082 100644
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@ -263,6 +263,17 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
draw_clip(app, &ctx, &p, body, it, r.kind, true, &t, rate);
}
}
+ // Show Through Edits: a small bow-tie on cuts between continuous pieces of one clip
+ if app.session.state.show_through_edits {
+ for te in filmcraft_edit::through::track_through_edits(tr) {
+ let x = layout.x_of(te.time);
+ if x < content.min.x - 6.0 || x > content.max.x + 6.0 {
+ continue;
+ }
+ let r = paint_through_edit(&p, x, r.rect);
+ app.auto.add(&format!("timeline.throughEdit.{}", te.right.0), r, "Through edit");
+ }
+ }
// selected edit points (trim mode): red brackets for ripple, yellow for roll / regular trim
super::trim_monitor::paint_edit_points(app, &p, &seq, tr, r, &layout);
// transitions
@@ -383,6 +394,22 @@ fn empty_state(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
}
+/// The through-edit mark: two small triangles pointing at the cut, centred on the track, with a
+/// dashed white line through the clip body. Returns the mark's rect.
+fn paint_through_edit(p: &egui::Painter, x: f32, row: Rect) -> Rect {
+ let cy = row.center().y.max(row.min.y + 10.0);
+ let (w, h) = (4.0, 4.0);
+ let col = Color32::from_white_alpha(230);
+ let mut y = row.min.y + 2.0;
+ while y < row.max.y - 2.0 {
+ p.line_segment([pos2(x, y), pos2(x, (y + 3.0).min(row.max.y - 2.0))], Stroke::new(1.0, Color32::from_white_alpha(140)));
+ y += 6.0;
+ }
+ p.add(egui::Shape::convex_polygon(vec![pos2(x - w, cy - h), pos2(x, cy), pos2(x - w, cy + h)], col, Stroke::new(0.5, Color32::BLACK)));
+ p.add(egui::Shape::convex_polygon(vec![pos2(x + w, cy - h), pos2(x + w, cy + h), pos2(x, cy)], col, Stroke::new(0.5, Color32::BLACK)));
+ Rect::from_center_size(pos2(x, cy), vec2(2.0 * w + 2.0, 2.0 * h + 2.0))
+}
+
fn lighten(c: Color32, f: f32) -> Color32 {
let l = |v: u8| (v as f32 + (255.0 - v as f32) * f).round() as u8;
Color32::from_rgb(l(c.r()), l(c.g()), l(c.b()))
@@ -868,6 +895,13 @@ fn draw_top(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect, seq: &Sequenc
ui.checkbox(&mut app.ui.timeline.show_thumbnails, "Show Video Thumbnails");
ui.checkbox(&mut app.ui.timeline.show_waveforms, "Show Audio Waveform");
ui.separator();
+ let mut te = app.session.state.show_through_edits;
+ let c = ui.checkbox(&mut te, "Show Through Edits");
+ app.auto.add("timeline.settings.showThroughEdits", c.rect, "Show Through Edits");
+ if c.changed() {
+ let _ = app.session.execute("sequence.showThroughEdits", json!({"on": te}));
+ }
+ ui.separator();
if ui.button("Expand All Tracks").clicked() {
app.ui.timeline.video_track_h = 64.0;
app.ui.timeline.audio_track_h = 64.0;
@@ -915,6 +949,23 @@ fn draw_top(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect, seq: &Sequenc
let b = layout.x_of(seq.mark_out.map(|o| o + rate.frame_duration()).unwrap_or(seq.duration()));
clip.rect_filled(Rect::from_min_max(pos2(a, label_y + 7.0), pos2(b, tick_base)), 0.0, Color32::from_rgb(0x5c, 0x5c, 0x5c));
}
+ // split points: a short bracket with a V or A tag (video above, audio below)
+ let sp = seq.split;
+ for (t, is_in, tag, low) in
+ [(sp.video_in, true, "V", false), (sp.video_out, false, "V", false), (sp.audio_in, true, "A", true), (sp.audio_out, false, "A", true)]
+ {
+ let Some(t) = t else { continue };
+ let x = layout.x_of(if is_in { t } else { t + rate.frame_duration() });
+ let y0 = if low { tick_base - 7.0 } else { label_y + 7.0 };
+ let col = Color32::from_rgb(0xd0, 0xd0, 0xd0);
+ let dx = if is_in { 4.0 } else { -4.0 };
+ clip.line_segment([pos2(x, y0), pos2(x, y0 + 7.0)], Stroke::new(1.5, col));
+ clip.line_segment([pos2(x, y0), pos2(x + dx, y0)], Stroke::new(1.5, col));
+ clip.text(pos2(x + 2.0 * dx, y0 + 3.5), Align2::CENTER_CENTER, tag, Tokens::ui(8.5), col);
+ let kind = if low { "audio" } else { "video" };
+ let side = if is_in { "In" } else { "Out" };
+ app.auto.add(&format!("timeline.split.{kind}{side}"), Rect::from_center_size(pos2(x, y0 + 3.5), vec2(12.0, 9.0)), &format!("Split {tag} {side}"));
+ }
let f0 = rate.frame_at(layout.tick_at(ruler.min.x)).max(0);
let f1 = rate.frame_at(layout.tick_at(ruler.max.x)) + 1;
let mut f = (f0 / minor) * minor;
@@ -1541,7 +1592,7 @@ fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &
resp.context_menu(|ui| {
ui.set_min_width(200.0);
let sel_n = app.session.state.selection.len();
- let items: [(&str, &str); 10] = [
+ let items: [(&str, &str); 11] = [
("Cut", "edit.cut"),
("Copy", "edit.copy"),
("Clear", "edit.clear"),
@@ -1552,6 +1603,7 @@ fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &
("Speed/Duration…", "clip.speedDuration"),
("Nest…", "clip.nest"),
("Scale to Frame Size", "clip.scaleToFrameSize"),
+ ("Join Through Edits", "sequence.joinThroughEdits"),
];
for (label, cmd) in items {
if ui.add_enabled(sel_n > 0 && app.session.is_enabled(cmd), egui::Button::new(label)).clicked() {
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index 3609f37c0..21b41c192 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -292,6 +292,9 @@ pub struct UiState {
/// Audio Gain dialog draft (mode, dB values).
#[serde(default)]
pub audio_gain: AudioGainDraft,
+ /// Delete Tracks dialog draft.
+ #[serde(default)]
+ pub delete_tracks: DeleteTracksDraft,
/// On-monitor text editing (Type tool / double-click on a text layer).
#[serde(default)]
pub gfx_edit: Option<GfxEdit>,
@@ -507,6 +510,23 @@ pub struct AudioGainDraft {
pub all_peaks_db: f64,
}
+/// The Delete Tracks dialog (Sequence ▸ Delete Tracks…): per kind, whether to delete and which
+/// track (`"empty"` = All Empty Tracks, or a track name such as `"V2"`).
+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
+#[serde(default)]
+pub struct DeleteTracksDraft {
+ pub video: bool,
+ pub video_target: String,
+ pub audio: bool,
+ pub audio_target: String,
+}
+
+impl Default for DeleteTracksDraft {
+ fn default() -> Self {
+ Self { video: false, video_target: "empty".into(), audio: false, audio_target: "empty".into() }
+ }
+}
+
/// The text layer being edited on the Program monitor: caret and selection anchor are byte
/// offsets into the layer's text.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
@@ -556,6 +576,7 @@ impl Default for UiState {
play_after_render: true,
mixer_fx_open: false,
audio_gain: AudioGainDraft::default(),
+ delete_tracks: DeleteTracksDraft::default(),
gfx_edit: None,
pen_points: vec![],
link_media: None,
diff --git a/crates/ui-egui/tests/sequence_ui.rs b/crates/ui-egui/tests/sequence_ui.rs
new file mode 100644
index 000000000..9ef4be9f8
--- /dev/null
+++ b/crates/ui-egui/tests/sequence_ui.rs
@@ -0,0 +1,157 @@
+//! Headless UI tests of the Sequence / Markers menu additions: the Delete Tracks dialog, the
+//! through-edit marks on the timeline, the Markers panel colour filter and the Shift+; gap key.
+//! The real `FilmcraftApp` under `egui_kittest`, driven over the control channel by automation id.
+
+use std::sync::mpsc::{Sender, channel};
+
+use egui_kittest::Harness;
+use filmcraft_engine::Session;
+use filmcraft_ui_egui::FilmcraftApp;
+use filmcraft_ui_egui::control::ControlRequest;
+use serde_json::{Value, json};
+
+struct Driver {
+ harness: Harness<'static, FilmcraftApp>,
+ tx: Sender<ControlRequest>,
+}
+
+impl Driver {
+ fn demo() -> Self {
+ let mut session = Session::default();
+ session.execute("file.openDemoProject", json!({})).expect("demo project");
+ let (tx, rx) = channel();
+ let app = FilmcraftApp::new(session).with_control(rx);
+ let harness = Harness::builder().with_size(egui::vec2(1600.0, 980.0)).with_max_steps(10_000).build_eframe(move |_cc| app);
+ let mut d = Driver { harness, tx };
+ d.frames(4);
+ d
+ }
+
+ fn frames(&mut self, n: usize) {
+ for _ in 0..n {
+ let ctx = self.harness.ctx.clone();
+ let mut raw = std::mem::take(self.harness.input_mut());
+ eframe::App::raw_input_hook(self.harness.state_mut(), &ctx, &mut raw);
+ *self.harness.input_mut() = raw;
+ self.harness.step();
+ }
+ }
+
+ fn call(&mut self, method: &str, params: Value) -> Value {
+ let (req, reply) = ControlRequest::new(method, params.clone());
+ self.tx.send(req).unwrap();
+ for _ in 0..600 {
+ self.frames(1);
+ if let Ok(v) = reply.try_recv() {
+ return v;
+ }
+ }
+ panic!("no reply to {method} {params}");
+ }
+
+ fn ok(&mut self, method: &str, params: Value) -> Value {
+ let v = self.call(method, params.clone());
+ assert_eq!(v["ok"], json!(true), "{method} {params} failed: {v}");
+ v["result"].clone()
+ }
+
+ fn exec(&mut self, command: &str, params: Value) -> Value {
+ self.ok("engine.execute", json!({"command": command, "params": params}))
+ }
+
+ fn click(&mut self, id: &str) {
+ self.ok("ui.click", json!({"id": id}));
+ self.frames(2);
+ }
+
+ fn ids(&mut self, prefix: &str) -> Vec<String> {
+ let v = self.ok("ui.elements", json!({"prefix": prefix}));
+ v.as_array().unwrap().iter().filter_map(|e| e["id"].as_str().map(str::to_string)).collect()
+ }
+}
+
+#[test]
+fn delete_tracks_dialog_deletes_empty_tracks() {
+ let mut d = Driver::demo();
+ let before = d.exec("sequence.inspect", json!({}));
+ let nv = before["video"].as_array().unwrap().len();
+ let na = before["audio"].as_array().unwrap().len();
+ let r = d.ok("ui.menu.invoke", json!({"id": "sequence.deleteTracks"}));
+ assert_eq!(r["dialog"], "deleteTracks", "{r}");
+ d.frames(3);
+ let ids = d.ids("deleteTracks.");
+ for id in ["deleteTracks.video", "deleteTracks.audio", "deleteTracks.video.target", "deleteTracks.audio.target", "deleteTracks.ok", "deleteTracks.cancel"] {
+ assert!(ids.iter().any(|i| i == id), "{id} missing: {ids:?}");
+ }
+ d.click("deleteTracks.video");
+ d.click("deleteTracks.audio");
+ d.click("deleteTracks.ok");
+ assert!(d.ids("deleteTracks.").is_empty(), "dialog closed");
+ let after = d.exec("sequence.inspect", json!({}));
+ let (nv2, na2) = (after["video"].as_array().unwrap().len(), after["audio"].as_array().unwrap().len());
+ assert!(nv2 < nv && na2 < na, "empty tracks deleted: {nv}->{nv2}, {na}->{na2}");
+ // Cancel leaves the sequence alone
+ d.ok("ui.menu.invoke", json!({"id": "sequence.deleteTracks"}));
+ d.frames(3);
+ d.click("deleteTracks.video");
+ d.click("deleteTracks.cancel");
+ assert_eq!(d.exec("sequence.inspect", json!({}))["video"].as_array().unwrap().len(), nv2);
+}
+
+#[test]
+fn through_edits_are_marked_on_the_timeline() {
+ let mut d = Driver::demo();
+ d.exec("playhead.set", json!({"frame": 30}));
+ d.exec("sequence.addEditAllTracks", json!({}));
+ d.frames(3);
+ assert!(d.ids("timeline.throughEdit.").is_empty(), "hidden until Show Through Edits");
+ d.ok("ui.menu.invoke", json!({"id": "sequence.showThroughEdits"}));
+ d.frames(3);
+ let marks = d.ids("timeline.throughEdit.");
+ assert!(marks.len() >= 2, "V1 + A1 marks: {marks:?}");
+ d.exec("sequence.joinThroughEdits", json!({"all": true}));
+ d.frames(3);
+ assert!(d.ids("timeline.throughEdit.").is_empty(), "joined");
+}
+
+#[test]
+fn markers_panel_colour_filter() {
+ let mut d = Driver::demo();
+ d.exec("markers.clearAll", json!({}));
+ d.exec("markers.add", json!({"frame": 10, "name": "green"}));
+ d.exec("markers.add", json!({"frame": 20, "name": "red", "color": "Rose"}));
+ d.ok("ui.panel.show", json!({"panel": "Markers"}));
+ d.frames(3);
+ assert_eq!(d.ids("markers.row.").len(), 2);
+ assert!(d.ids("markers.filter.").len() >= 7);
+ d.click("markers.filter.Rose");
+ d.frames(2);
+ assert_eq!(d.ids("markers.row.").len(), 1, "red hidden");
+ let m = d.ok("ui.menu.list", json!({}));
+ let show_all = m.as_array().unwrap().iter().find(|i| i["id"] == "markers.showAllMarkerColors").unwrap().clone();
+ assert_eq!(show_all["enabled"], json!(true));
+ d.ok("ui.menu.invoke", json!({"id": "markers.showAllMarkerColors"}));
+ d.frames(3);
+ assert_eq!(d.ids("markers.row.").len(), 2);
+}
+
+#[test]
+fn shift_semicolon_goes_to_the_next_gap() {
+ let mut d = Driver::demo();
+ d.exec("markers.markIn", json!({"frame": 48}));
+ d.exec("markers.markOut", json!({"frame": 71}));
+ d.exec("sequence.lift", json!({}));
+ d.exec("playhead.set", json!({"frame": 0}));
+ // the key a US layout sends for Shift+; is `:`
+ d.harness.input_mut().events.push(egui::Event::Key {
+ key: egui::Key::Colon,
+ physical_key: Some(egui::Key::Semicolon),
+ pressed: true,
+ repeat: false,
+ modifiers: egui::Modifiers::SHIFT,
+ });
+ d.frames(3);
+ let ph = d.exec("sequence.inspect", json!({}))["playhead"].clone();
+ let want = d.exec("playhead.set", json!({"frame": 48}))["time"].clone();
+ assert_eq!(ph, want);
+}