Skip to content

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

NEST2: Nest and Make Subsequence as Premiere Pro 26.5.2 does them

justjohn12345ca489f9fcef0
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index c88d87947..9ad24f753 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -2577,25 +2577,68 @@ fn nest(s: &mut Session, p: &Value) -> Result<Value> {
if items.is_empty() {
return Err(EngineError::Other("nothing selected".into()));
}
- let nested_ids: Vec<ClipId> = items.iter().map(|i| i.2.id).collect();
let start = items.iter().map(|i| i.2.start).min().unwrap_or_default();
let end = items.iter().map(|i| i.2.end()).max().unwrap_or_default();
- let lowest_v = items.iter().filter(|i| i.0 == TrackKind::Video).map(|i| i.1).min();
- let lowest_a = items.iter().filter(|i| i.0 == TrackKind::Audio).map(|i| i.1).min();
- s.edit("Nest", |pr, st| {
- let nid = pr.new_sequence(&name, q.settings.clone(), q.video_tracks.len(), q.audio_tracks.len(), None);
+ let span = TimeRange::new(start, end - start);
+ let tracks_of = |kind: TrackKind| -> Vec<usize> {
+ let mut v: Vec<usize> = items.iter().filter(|i| i.0 == kind).map(|i| i.1).collect();
+ v.sort_unstable();
+ v.dedup();
+ v
+ };
+ let (video_tracks, audio_tracks) = (tracks_of(TrackKind::Video), tracks_of(TrackKind::Audio));
+ // Premiere (26.5.2): the nest is a linked picture + sound pair only when the selected sound is
+ // on one track and that track is free for the nest's whole length. With sound on several
+ // tracks, or another clip in the way on its track, the nest is picture only: the selected sound
+ // stays where it is in this sequence, and a copy of it goes into the nest.
+ let sound_blocked = |ai: usize| q.audio_tracks.get(ai).is_none_or(|t| t.items.iter().any(|i| !sel.contains(&i.id) && i.range().overlaps(&span)));
+ let video_only = !video_tracks.is_empty() && (audio_tracks.len() > 1 || audio_tracks.first().is_some_and(|ai| sound_blocked(*ai)));
+ let (lowest_v, lowest_a) = (video_tracks.first().copied(), audio_tracks.first().copied().filter(|_| !video_only));
+ // In the nest, picture tracks keep their positions (V1 up to the highest one used). Sound
+ // tracks do not: A1 is always there, and the other tracks used follow it in order
+ // (A1 + A3 become A1, A2; A3 alone becomes an empty A1 and A2).
+ let nv = video_tracks.last().map_or(1, |i| i + 1);
+ let audio_at: std::collections::HashMap<usize, usize> =
+ audio_tracks.iter().filter(|i| **i != 0).enumerate().map(|(n, i)| (*i, n + 1)).chain(std::iter::once((0, 0))).collect();
+ let na = audio_at.values().max().map_or(1, |i| i + 1);
+ let nested_track = |k: TrackKind, ti: usize| if k == TrackKind::Audio { audio_at.get(&ti).copied().unwrap_or(ti) } else { ti };
+ // what leaves this sequence: everything nested, less the sound that stays behind
+ let removed: Vec<ClipId> = items.iter().filter(|i| !(video_only && i.0 == TrackKind::Audio)).map(|i| i.2.id).collect();
+ let stays = |k: TrackKind| video_only && k == TrackKind::Audio;
+ let r = s.edit("Nest", |pr, st| {
+ let nid = pr.new_sequence(&name, q.settings.clone(), nv, na, None);
+ // copies of clips and transitions that also stay behind need ids of their own
+ let fresh_clips: std::collections::HashMap<ClipId, ClipId> = items.iter().filter(|i| stays(i.0)).map(|i| (i.2.id, ClipId(pr.alloc_id()))).collect();
+ let fresh_transitions: Vec<Option<u64>> = transitions.iter().map(|t| stays(t.0).then(|| pr.alloc_id())).collect();
+ let copy = |c: ClipId| fresh_clips.get(&c).copied().unwrap_or(c);
{
let nq = pr.sequence_mut(nid).ok_or(EngineError::NoSequence)?;
- crate::sequence_tools::lay_out_tracks_like(nq, &q);
+ // tracks take the name and channel layout of the track their clips came from
+ for (tr, src) in nq.video_tracks.iter_mut().zip(&q.video_tracks) {
+ tr.name = src.name.clone();
+ }
+ for (from, to) in &audio_at {
+ if let (Some(tr), Some(src)) = (nq.audio_tracks.get_mut(*to), q.audio_tracks.get(*from)) {
+ tr.channels = src.channels;
+ if from == to {
+ tr.name = src.name.clone();
+ }
+ }
+ }
for (k, ti, it) in &items {
let mut it = it.clone();
+ it.id = copy(it.id);
it.start -= start;
- nq.tracks_mut(*k).get_mut(*ti).ok_or(EngineError::NoSequence)?.items.push(it);
+ nq.tracks_mut(*k).get_mut(nested_track(*k, *ti)).ok_or(EngineError::NoSequence)?.items.push(it);
}
- for (k, ti, trn) in &transitions {
+ for ((k, ti, trn), fresh) in transitions.iter().zip(&fresh_transitions) {
let mut trn = trn.clone();
+ if let Some(id) = fresh {
+ trn.id = filmcraft_project::TransitionId(*id);
+ }
+ (trn.from, trn.to) = (trn.from.map(copy), trn.to.map(copy));
trn.start -= start;
- nq.tracks_mut(*k).get_mut(*ti).ok_or(EngineError::NoSequence)?.transitions.push(trn);
+ nq.tracks_mut(*k).get_mut(nested_track(*k, *ti)).ok_or(EngineError::NoSequence)?.transitions.push(trn);
}
for t in nq.all_tracks_mut() {
t.sort();
@@ -2604,39 +2647,65 @@ fn nest(s: &mut Session, p: &Value) -> Result<Value> {
nq.check().map_err(EngineError::Other)?;
}
let rate = q.settings.frame_rate;
- let mut v = pr
- .make_track_item(nid, TrackKind::Video, start, TimeRange::new(Tick::ZERO, end - start), rate)
- .ok_or_else(|| EngineError::Other("cannot place the nested sequence".into()))?;
+ // the nest shows its sequence from the beginning, for the length of what was nested
+ let whole = TimeRange::new(Tick::ZERO, span.duration);
+ let mut v =
+ pr.make_track_item(nid, TrackKind::Video, start, whole, rate).ok_or_else(|| EngineError::Other("cannot place the nested sequence".into()))?;
for e in &mut v.effects {
resolve_auto_points(e, (q.settings.width, q.settings.height), (q.settings.width, q.settings.height));
}
- let a = pr
- .make_track_item(nid, TrackKind::Audio, start, TimeRange::new(Tick::ZERO, end - start), rate)
- .ok_or_else(|| EngineError::Other("cannot place the nested sequence".into()))?;
- let link = pr.alloc_id();
+ let a = pr.make_track_item(nid, TrackKind::Audio, start, whole, rate).ok_or_else(|| EngineError::Other("cannot place the nested sequence".into()))?;
+ let (link, new_video, new_audio) = (pr.alloc_id(), pr.alloc_id(), pr.alloc_id());
let seq = pr.sequence_mut(seq_id).ok_or(EngineError::NoSequence)?;
- edit::delete_items(seq, &nested_ids);
- let mut ids = Vec::new();
- if let Some(vi) = lowest_v {
- let mut v = v;
- v.link = lowest_a.map(|_| link);
- ids.push(v.id);
- let t = &mut seq.video_tracks[vi];
- t.items.push(v);
- t.sort();
+ edit::delete_items(seq, &removed);
+ // sound left behind has lost its picture: it is no longer linked
+ if video_only {
+ let links: Vec<u64> = items.iter().filter(|i| i.0 == TrackKind::Video).filter_map(|i| i.2.link).collect();
+ for it in seq.audio_tracks.iter_mut().flat_map(|t| t.items.iter_mut()) {
+ if it.link.is_some_and(|l| links.contains(&l)) {
+ it.link = None;
+ }
+ }
}
- if let Some(ai) = lowest_a {
- let mut a = a;
- a.link = lowest_v.map(|_| link);
- ids.push(a.id);
- let t = &mut seq.audio_tracks[ai];
- t.items.push(a);
+ // Where the nest goes, as Premiere Pro 26.5.2 places it (about 35 nests observed). With L
+ // the lowest video track of the selection and `a` the number of the highest audio track
+ // holding selected sound, the picture takes the lowest track T from L up such that
+ // 1. T is free of other clips for the nest's whole length, and
+ // 2. so is every video track numbered from T up to a - 1 that the selection had clips on.
+ // If no track will do, a new one is added on top. So the nest never lands on another clip,
+ // and it can be pushed above an unselected clip that shares a track with the selection
+ // when the sound sits on a higher-numbered track. The sound of a linked nest is on the one
+ // track its clips came from, which is free (a selection of sound alone moves up to the
+ // first free track).
+ let highest_sound = audio_tracks.last().map_or(0, |i| i + 1);
+ let mut ids = Vec::new();
+ for (kind, lowest, mut clip, new_track) in [(TrackKind::Video, lowest_v, v, new_video), (TrackKind::Audio, lowest_a, a, new_audio)] {
+ let Some(lowest) = lowest else { continue };
+ let tracks = seq.tracks_mut(kind);
+ let clear = |i: usize| tracks.get(i).is_some_and(|t| !t.locked && edit::track_range_empty(t, span));
+ let selection_clear = |t: usize| kind != TrackKind::Video || video_tracks.iter().filter(|i| **i >= t && **i + 1 < highest_sound).all(|i| clear(*i));
+ let free = (lowest..tracks.len()).find(|t| clear(*t) && selection_clear(*t));
+ let at = match free {
+ Some(i) => i,
+ None => {
+ let (word, n) = (if kind == TrackKind::Video { "Video" } else { "Audio" }, tracks.len() + 1);
+ tracks.push(filmcraft_project::Track::new(TrackId(new_track), kind, format!("{word} {n}")));
+ tracks.len() - 1
+ }
+ };
+ clip.link = (lowest_v.is_some() && lowest_a.is_some()).then_some(link);
+ ids.push(clip.id);
+ let t = tracks.get_mut(at).ok_or(EngineError::NoSequence)?;
+ t.items.push(clip);
t.sort();
}
- st.selection = ids;
- Ok(nid)
- })
- .map(|n| json!({"sequence": n.0}))
+ seq.check().map_err(EngineError::Other)?;
+ // like Premiere: nothing stays selected in the timeline; the new sequence is selected in the Project panel
+ st.selection.clear();
+ st.project_selection = vec![nid];
+ Ok((nid, ids))
+ });
+ r.map(|(n, ids)| json!({"sequence": n.0, "clips": ids.iter().map(|c| c.0).collect::<Vec<_>>()}))
}
/// `effects.list`: every effect definition with its Effects-panel folder (optionally filtered by
diff --git a/crates/engine/src/nesting_tests.rs b/crates/engine/src/nesting_tests.rs
index a7a3a1489..92bc1ebd0 100644
--- a/crates/engine/src/nesting_tests.rs
+++ b/crates/engine/src/nesting_tests.rs
@@ -71,7 +71,9 @@ fn a_sequence_cannot_be_placed_in_a_sequence_it_contains() {
fn pasting_a_nest_into_its_own_sequence_is_refused() {
let mut s = demo();
let (_, nested) = nest_one(&mut s, "Inner");
- // copy the nest clip (selected by Nest…), open the nested sequence and paste it there
+ // copy the nest clip, open the nested sequence and paste it there
+ let nest = s.active_sequence().unwrap().video_tracks[0].items.iter().find(|i| i.item == nested).unwrap().id;
+ s.execute("timeline.select", json!({"clips": [nest.0]})).unwrap();
s.execute("edit.copy", json!({})).unwrap();
s.execute("sequence.open", json!({"item": nested.0})).unwrap();
refused(&mut s, "edit.paste", json!({}));
@@ -122,7 +124,7 @@ fn nest_keeps_transitions_track_names_and_channel_layouts() {
s.edit_sequence("setup", |q, _, _| {
q.video_tracks[0].name = "Picture".into();
q.audio_tracks[0].name = "Dialogue".into();
- q.audio_tracks[1].channels = filmcraft_project::AudioChannels::Mono;
+ q.audio_tracks[0].channels = filmcraft_project::AudioChannels::Mono;
Ok(())
})
.unwrap();
@@ -148,7 +150,9 @@ fn nest_keeps_transitions_track_names_and_channel_layouts() {
// tracks are laid out like the parent's
assert_eq!(q.video_tracks[0].name, "Picture");
assert_eq!(q.audio_tracks[0].name, "Dialogue");
- assert_eq!(q.audio_tracks[1].channels, filmcraft_project::AudioChannels::Mono);
+ assert_eq!(q.audio_tracks[0].channels, filmcraft_project::AudioChannels::Mono);
+ // and there are only as many as the nested clips need (Premiere: V1 + A1 here, not the parent's three each)
+ assert_eq!((q.video_tracks.len(), q.audio_tracks.len()), (1, 1));
// the parent no longer holds the transition, and shows the same picture through the nest
assert!(outer_q.video_tracks[0].transitions.iter().all(|t| t.id != trn.id));
outer_q.check().unwrap();
@@ -277,3 +281,245 @@ fn the_outer_sequence_shows_changes_made_inside_a_nest() {
let after = frame_at(&s, t);
assert!(before.px != after.px, "the outer sequence shows the nest's new contents");
}
+
+// ---- Nest… as Premiere Pro 26.5.2 does it (observed in the app, 2026-10-06)
+
+#[test]
+fn after_nest_nothing_is_selected_and_the_new_sequence_is_selected_in_the_project() {
+ let mut s = demo();
+ let v = clip_ids(&s, TrackKind::Video, 0)[1];
+ s.execute("timeline.select", json!({"clips": [v]})).unwrap();
+ let r = s.execute("clip.nest", json!({"name": "Inner"})).unwrap();
+ let nested = ItemId(r["sequence"].as_u64().unwrap());
+ assert!(s.state.selection.is_empty());
+ assert_eq!(s.state.project_selection, vec![nested]);
+ // the result names the nest's clips: one picture and one sound clip, linked, where the clips were
+ let clips: Vec<ClipId> = r["clips"].as_array().unwrap().iter().map(|c| ClipId(c.as_u64().unwrap())).collect();
+ let q = s.active_sequence().unwrap();
+ let (vt, vc) = q.find_item(clips[0]).unwrap();
+ let (at, ac) = q.find_item(clips[1]).unwrap();
+ assert_eq!((vt, at), (q.video_tracks[0].id, q.audio_tracks[0].id));
+ assert!(vc.item == nested && ac.item == nested && vc.link.is_some() && vc.link == ac.link);
+ // each shows the nested sequence from its start, for the length of what was nested
+ let inner = s.project.sequence(nested).unwrap().duration();
+ assert_eq!((vc.source_in, vc.duration, ac.source_in, ac.duration), (Tick::ZERO, inner, Tick::ZERO, inner));
+ assert_eq!(clips.len(), 2);
+}
+
+/// Move the sound of V1 clip `n` alone to audio track `track` ("A3"), keeping its time.
+fn move_sound(s: &mut Session, n: usize, track: &str) -> (filmcraft_project::TrackItem, filmcraft_project::TrackItem) {
+ let q = s.active_sequence().unwrap();
+ let picture = q.video_tracks[0].items[n].clone();
+ let sound = q.all_tracks().flat_map(|t| t.items.iter()).find(|i| i.id != picture.id && i.link == picture.link).unwrap().clone();
+ s.execute("timeline.move", json!({"moves": [{"clip": sound.id.0, "track": track, "time": sound.start.0}], "linked": false})).unwrap();
+ let sound = s.active_sequence().unwrap().find_item(sound.id).unwrap().1.clone();
+ (picture, sound)
+}
+
+fn nest_of(s: &mut Session, clips: &[ClipId], name: &str) -> (ItemId, Vec<ClipId>) {
+ s.execute("timeline.select", json!({"clips": clips.iter().map(|c| c.0).collect::<Vec<_>>()})).unwrap();
+ let r = s.execute("clip.nest", json!({"name": name})).unwrap();
+ (ItemId(r["sequence"].as_u64().unwrap()), r["clips"].as_array().unwrap().iter().map(|c| ClipId(c.as_u64().unwrap())).collect())
+}
+
+fn track_index(s: &Session, kind: TrackKind, clip: ClipId) -> usize {
+ let q = s.active_sequence().unwrap();
+ let (track, _) = q.find_item(clip).unwrap();
+ q.tracks(kind).iter().position(|t| t.id == track).unwrap()
+}
+
+#[test]
+fn clips_on_two_video_tracks_with_their_sound_on_one_track_nest_as_a_linked_pair() {
+ let mut s = demo();
+ // two neighbouring V1 clips with their sound on A1; the second one's picture goes up to V2
+ let (first, second) = {
+ let v1 = &s.active_sequence().unwrap().video_tracks[0].items;
+ (v1[4].clone(), v1[5].clone())
+ };
+ s.execute("timeline.move", json!({"moves": [{"clip": second.id.0, "track": "V2", "time": second.start.0}], "linked": false})).unwrap();
+ assert_eq!((track_index(&s, TrackKind::Video, first.id), track_index(&s, TrackKind::Video, second.id)), (0, 1));
+ let (nested, clips) = nest_of(&mut s, &[first.id, second.id], "Stack");
+ assert_eq!(clips.len(), 2, "picture and sound");
+ let q = s.active_sequence().unwrap();
+ q.check().unwrap();
+ let (picture, sound) = (q.find_item(clips[0]).unwrap().1, q.find_item(clips[1]).unwrap().1);
+ assert!(picture.item == nested && sound.item == nested && picture.link.is_some() && picture.link == sound.link);
+ assert_eq!((track_index(&s, TrackKind::Video, clips[0]), track_index(&s, TrackKind::Audio, clips[1])), (0, 0));
+ // inside: the pictures on V1 and V2, both sounds on A1
+ let inner = s.project.sequence(nested).unwrap();
+ assert_eq!((inner.video_tracks.len(), inner.audio_tracks.len()), (2, 1));
+ assert!(inner.video_tracks[0].item(first.id).is_some() && inner.video_tracks[1].item(second.id).is_some());
+ assert_eq!(inner.audio_tracks[0].items.len(), 2);
+}
+
+#[test]
+fn clips_with_their_sound_on_several_tracks_nest_as_picture_only_and_the_sound_stays() {
+ let mut s = demo();
+ // two neighbouring V1 clips; the second one's sound goes to A3
+ let first = s.active_sequence().unwrap().video_tracks[0].items[3].clone();
+ let first_sound = s.active_sequence().unwrap().audio_tracks[0].items.iter().find(|i| i.link == first.link).unwrap().clone();
+ let (second, second_sound) = move_sound(&mut s, 4, "A3");
+ assert_eq!(track_index(&s, TrackKind::Audio, second_sound.id), 2);
+ let (nested, clips) = nest_of(&mut s, &[first.id, second.id], "Picture");
+ let q = s.active_sequence().unwrap();
+ q.check().unwrap();
+ // one clip came back: the picture, unlinked, on V1
+ assert_eq!(clips.len(), 1);
+ let nest = q.find_item(clips[0]).unwrap().1;
+ assert!(nest.item == nested && nest.link.is_none());
+ assert_eq!(track_index(&s, TrackKind::Video, clips[0]), 0);
+ assert!(q.audio_tracks.iter().all(|t| t.items.iter().all(|i| i.item != nested)), "no sound clip for the nest");
+ // the sound is where it was, the same clips, no longer linked to a picture
+ for (sound, at) in [(&first_sound, 0), (&second_sound, 2)] {
+ let left = q.audio_tracks[at].item(sound.id).expect("the sound stays in the sequence");
+ assert_eq!((left.range(), left.link), (sound.range(), None));
+ }
+ // inside: both pictures on V1; copies of the sound, linked to their pictures, on A1 and A2
+ // (the tracks used follow A1 without the gap)
+ let inner = s.project.sequence(nested).unwrap();
+ inner.check().unwrap();
+ assert_eq!((inner.video_tracks.len(), inner.audio_tracks.len()), (1, 2));
+ for (track, sound, picture) in [(0, &first_sound, &first), (1, &second_sound, &second)] {
+ let copy = &inner.audio_tracks[track].items[0];
+ assert!(copy.id != sound.id && copy.item == sound.item && copy.link == picture.link, "track {track}");
+ }
+}
+
+#[test]
+fn a_nest_whose_sound_track_is_taken_is_picture_only_and_moves_up_a_video_track() {
+ let mut s = demo();
+ // the first and third V1 clips, but not the second: the nest spans all three, and the second
+ // clip and its sound are in the way on V1 and A1
+ let (first, between, third) = {
+ let v1 = &s.active_sequence().unwrap().video_tracks[0].items;
+ (v1[0].clone(), v1[1].clone(), v1[2].clone())
+ };
+ let sounds: Vec<filmcraft_project::TrackItem> =
+ s.active_sequence().unwrap().audio_tracks[0].items.iter().filter(|i| i.link == first.link || i.link == third.link).cloned().collect();
+ let before = (*s.project).clone();
+ let (nested, clips) = nest_of(&mut s, &[first.id, third.id], "Around");
+ let q = s.active_sequence().unwrap();
+ q.check().expect("no two clips overlap on a track");
+ assert_eq!(clips.len(), 1, "picture only");
+ let nest = q.find_item(clips[0]).unwrap().1.clone();
+ assert!(nest.item == nested && nest.link.is_none());
+ // V1 still holds the clip in between, so the nest took the first track above that was free for its whole length
+ let index = track_index(&s, TrackKind::Video, clips[0]);
+ assert!(index > 0 && q.video_tracks[0].item(between.id).is_some());
+ let was = before.sequence(s.state.active_sequence.unwrap()).unwrap();
+ let free = |i: usize| was.video_tracks.get(i).is_none_or(|t| !t.items.iter().any(|x| x.range().overlaps(&nest.range())));
+ assert!(free(index) && (1..index).all(|i| !free(i)), "track {index}");
+ // the sound stays on A1
+ for sound in &sounds {
+ assert_eq!(q.audio_tracks[0].item(sound.id).map(|i| (i.range(), i.link)), Some((sound.range(), None)));
+ }
+}
+
+#[test]
+fn sound_on_a_track_other_than_a1_keeps_an_empty_a1_in_the_nest() {
+ let mut s = demo();
+ // one clip whose sound is on A3: a linked nest with its sound still on A3
+ let (picture, sound) = move_sound(&mut s, 1, "A3");
+ let (nested, clips) = nest_of(&mut s, &[picture.id], "Third");
+ assert_eq!(clips.len(), 2);
+ assert_eq!((track_index(&s, TrackKind::Video, clips[0]), track_index(&s, TrackKind::Audio, clips[1])), (0, 2));
+ // inside: A1 is there and empty, the sound is on A2
+ let inner = s.project.sequence(nested).unwrap();
+ assert_eq!((inner.video_tracks.len(), inner.audio_tracks.len()), (1, 2));
+ assert!(inner.audio_tracks[0].items.is_empty());
+ assert!(inner.audio_tracks[1].item(sound.id).is_some());
+}
+
+/// The arrangement Premiere was probed with: the 4th V1 clip stays on V1 with its sound on
+/// `sound_track`; the 5th and 6th clips' pictures go up to V2, unlinked from their sound. Nesting
+/// the 4th and 6th leaves the 5th's picture on V2, a track the selection has a clip on, inside the
+/// nest's span. Returns the clips to nest and the one in the way.
+fn stacked(s: &mut Session, sound_track: &str) -> ([ClipId; 2], ClipId) {
+ let (first, between, last) = {
+ let v1 = &s.active_sequence().unwrap().video_tracks[0].items;
+ (v1[3].id, v1[4].clone(), v1[5].clone())
+ };
+ if sound_track != "A1" {
+ move_sound(s, 3, sound_track);
+ }
+ for clip in [&between, &last] {
+ s.execute("timeline.select", json!({"clips": [clip.id.0]})).unwrap();
+ s.execute("clip.link", json!({})).unwrap();
+ s.execute("timeline.move", json!({"moves": [{"clip": clip.id.0, "track": "V2", "time": clip.start.0}], "linked": false})).unwrap();
+ }
+ assert_eq!((track_index(s, TrackKind::Video, between.id), track_index(s, TrackKind::Video, last.id)), (1, 1));
+ ([first, last.id], between.id)
+}
+
+#[test]
+fn a_clip_sharing_a_track_with_the_selection_pushes_the_nest_above_it_when_the_sound_is_on_a_higher_track() {
+ // sound on A3 (free): a linked nest, on V3 because V2 holds another clip and is numbered below the sound's track
+ let mut s = demo();
+ let (picked, in_the_way) = stacked(&mut s, "A3");
+ let (nested, clips) = nest_of(&mut s, &picked, "Above");
+ assert_eq!(clips.len(), 2, "linked: the sound track is free");
+ assert_eq!((track_index(&s, TrackKind::Video, clips[0]), track_index(&s, TrackKind::Audio, clips[1])), (2, 2));
+ let q = s.active_sequence().unwrap();
+ q.check().unwrap();
+ assert!(q.video_tracks[0].items.iter().all(|i| !i.range().overlaps(&q.find_item(clips[0]).unwrap().1.range())), "V1 was free all along");
+ assert_eq!(track_index(&s, TrackKind::Video, in_the_way), 1);
+ assert_eq!(s.project.sequence(nested).unwrap().video_tracks.len(), 2);
+}
+
+#[test]
+fn a_clip_on_a_selected_track_numbered_at_or_above_the_sound_track_does_not_push_the_nest() {
+ // sound on A2 (taken by the score, so picture only): V2 is not below the sound's track, the nest stays on V1
+ let mut s = demo();
+ let (picked, in_the_way) = stacked(&mut s, "A2");
+ let (_, clips) = nest_of(&mut s, &picked, "Second");
+ assert_eq!(clips.len(), 1, "picture only: A2 is taken");
+ assert_eq!(track_index(&s, TrackKind::Video, clips[0]), 0);
+ assert_eq!(track_index(&s, TrackKind::Video, in_the_way), 1);
+ s.active_sequence().unwrap().check().unwrap();
+
+ // sound on A1 (taken by the clip in between's sound): the same
+ let mut s = demo();
+ let (picked, _) = stacked(&mut s, "A1");
+ let (_, clips) = nest_of(&mut s, &picked, "First");
+ assert_eq!(clips.len(), 1);
+ assert_eq!(track_index(&s, TrackKind::Video, clips[0]), 0);
+ s.active_sequence().unwrap().check().unwrap();
+}
+
+#[test]
+fn a_nest_with_no_track_to_go_on_gets_a_new_one() {
+ // as the first case, with V3 taken as well: a fourth video track is added for the nest
+ let mut s = demo();
+ let (picked, _) = stacked(&mut s, "A3");
+ let (overlay, at) = {
+ let q = s.active_sequence().unwrap();
+ (q.video_tracks[1].items[0].id, q.find_item(picked[0]).unwrap().1.start)
+ };
+ s.execute("timeline.move", json!({"moves": [{"clip": overlay.0, "track": "V3", "time": at.0}], "linked": false})).unwrap();
+ assert_eq!(track_index(&s, TrackKind::Video, overlay), 2);
+ let tracks = s.active_sequence().unwrap().video_tracks.len();
+ let (_, clips) = nest_of(&mut s, &picked, "Top");
+ let q = s.active_sequence().unwrap();
+ q.check().unwrap();
+ assert_eq!((tracks, q.video_tracks.len()), (3, 4));
+ assert_eq!(track_index(&s, TrackKind::Video, clips[0]), 3);
+ // one undo takes the nest and its track away again
+ s.execute("edit.undo", json!({})).unwrap();
+ assert_eq!(s.active_sequence().unwrap().video_tracks.len(), 3);
+}
+
+#[test]
+fn make_subsequence_loads_the_new_sequence_in_the_source_monitor() {
+ let mut s = demo();
+ let outer = s.state.active_sequence.unwrap();
+ let v = clip_ids(&s, TrackKind::Video, 0)[1];
+ s.execute("timeline.select", json!({"clips": [v]})).unwrap();
+ let sub = ItemId(s.execute("sequence.makeSubsequence", json!({})).unwrap()["sequence"].as_u64().unwrap());
+ assert_eq!(s.state.source_item, Some(sub));
+ assert_eq!(s.state.project_selection, vec![sub]);
+ // it is not opened in the Timeline, and the selection is left alone
+ assert_eq!(s.state.active_sequence, Some(outer));
+ assert!(!s.state.open_sequences.contains(&sub));
+ assert!(s.state.selection.contains(&ClipId(v)));
+ assert!(s.drain_events().iter().any(|e| matches!(e, Event::OpenSource(i) if *i == sub)));
+}
diff --git a/crates/engine/src/sequence_tools.rs b/crates/engine/src/sequence_tools.rs
index 8f64464f7..3d679ada2 100644
--- a/crates/engine/src/sequence_tools.rs
+++ b/crates/engine/src/sequence_tools.rs
@@ -445,8 +445,12 @@ fn make_subsequence(s: &mut Session, p: &Value) -> Result<Value> {
}
nq.check().map_err(EngineError::Other)?;
st.project_selection = vec![nid];
+ // like Premiere: the subsequence is loaded in the Source Monitor, ready to edit from
+ st.source_item = Some(nid);
+ st.source_playhead = Tick::ZERO;
Ok(nid)
})?;
+ s.events.push(crate::Event::OpenSource(id));
Ok(json!({"sequence": id.0, "name": name}))
}
diff --git a/crates/ui-egui/tests/nested_ui.rs b/crates/ui-egui/tests/nested_ui.rs
index c318d7318..cebf0286d 100644
--- a/crates/ui-egui/tests/nested_ui.rs
+++ b/crates/ui-egui/tests/nested_ui.rs
@@ -84,8 +84,8 @@ fn the_empty_end_of_a_nest_is_marked_in_the_timeline() {
(v1.items[3].clone(), v1.items[4].clone())
};
d.exec("timeline.select", json!({"clips": [a.id.0, b.id.0]}));
- let nested = d.exec("clip.nest", json!({"name": "Inner"}))["sequence"].as_u64().unwrap();
- let nest = d.app().session.state.selection[0].0;
+ let r = d.exec("clip.nest", json!({"name": "Inner"}));
+ let (nested, nest) = (r["sequence"].as_u64().unwrap(), r["clips"][0].as_u64().unwrap());
d.frames(3);
let clip = d.rect(&format!("timeline.clip.{nest}")).expect("the nest clip is on screen");
assert!(d.rect(&format!("timeline.clip.{nest}.empty")).is_none(), "a full nest has no empty part");