mirror of
https://github.com/storytold/filmcraft.git
synced 2026-12-02 20:19:02 -05:00
Fix macOS Control-click for video-only multicam angle switches (#5365)
* fix(ui): honor macOS Control-click for video-only multicam switches * M5363: Preserve per-cut audio choices during multicam recording * M5363: Keep linked picture and audio edits aligned after recording * M5363: Preserve audio fades across recorded camera edits * M5363: Preserve the sound of overlapping multicamera fades
This commit is contained in:
1 parent
b8582269de
commit
e19d4961c6
9 files changed
+375
-84
No files matched your search
+17
-11
@@ -93,6 +93,22 @@ pub enum TrimMode {
|
||||
/// `links` maps old link groups to the new group for right-hand pieces (so linked partners split
|
||||
/// in the same operation stay linked to each other).
|
||||
pub fn split_track_at(track: &mut Track, t: Tick, ctx: &mut EditCtx, links: &mut HashMap<u64, u64>) -> Option<ClipId> {
|
||||
let (old_id, new_id) = split_track_item(track, t, ctx, links)?;
|
||||
// transitions: those after the cut that referenced the left piece now reference the right one;
|
||||
// a transition spanning the cut on this clip's interior is removed.
|
||||
track
|
||||
.transitions
|
||||
.retain(|tr| !(tr.start < t && t < tr.end() && (tr.from == Some(old_id) || tr.to == Some(old_id)) && !(tr.from.is_some() && tr.to.is_some())));
|
||||
for tr in &mut track.transitions {
|
||||
if tr.start >= t && tr.from == Some(old_id) {
|
||||
tr.from = Some(new_id);
|
||||
}
|
||||
}
|
||||
Some(new_id)
|
||||
}
|
||||
|
||||
/// Split the clip and its link group. The caller places any transitions on the resulting edges.
|
||||
fn split_track_item(track: &mut Track, t: Tick, ctx: &mut EditCtx, links: &mut HashMap<u64, u64>) -> Option<(ClipId, ClipId)> {
|
||||
let idx = track.items.iter().position(|i| i.start < t && t < i.end())?;
|
||||
let left = &mut track.items[idx];
|
||||
let mut right = left.clone();
|
||||
@@ -116,19 +132,9 @@ pub fn split_track_at(track: &mut Track, t: Tick, ctx: &mut EditCtx, links: &mut
|
||||
let nl = *links.entry(l).or_insert_with(|| ctx.alloc());
|
||||
right.link = Some(nl);
|
||||
}
|
||||
// transitions: those after the cut that referenced the left piece now reference the right one;
|
||||
// a transition spanning the cut on this clip's interior is removed.
|
||||
let old_id = track.items[idx].id;
|
||||
track
|
||||
.transitions
|
||||
.retain(|tr| !(tr.start < t && t < tr.end() && (tr.from == Some(old_id) || tr.to == Some(old_id)) && !(tr.from.is_some() && tr.to.is_some())));
|
||||
for tr in &mut track.transitions {
|
||||
if tr.start >= t && tr.from == Some(old_id) {
|
||||
tr.from = Some(new_id);
|
||||
}
|
||||
}
|
||||
track.items.insert(idx + 1, right);
|
||||
Some(new_id)
|
||||
Some((old_id, new_id))
|
||||
}
|
||||
|
||||
/// Remove all material in `range` on a track (splitting items at the boundaries).
|
||||
|
||||
+112
-48
@@ -4,12 +4,12 @@
|
||||
//! A multi-camera clip is a track item whose [`TrackItem::multicam`] is set; it refers to a
|
||||
//! multi-camera source sequence. Its angle is a camera index of that source.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
|
||||
use filmcraft_project::{ClipId, ItemId, MulticamSel, Sequence, Track, TrackId, TrackItem};
|
||||
use filmcraft_project::{ClipId, ItemId, MulticamSel, Sequence, Track, TrackId, TrackItem, TrackKind};
|
||||
use filmcraft_time::{Tick, TimeRange};
|
||||
|
||||
use crate::{EditCtx, EditError, Result, remove_orphan_transitions, split_track_at};
|
||||
use crate::{EditCtx, EditError, Result, remove_orphan_transitions, split_track_at, split_track_item};
|
||||
|
||||
/// Whether `it` is a multi-camera clip (enabled or not).
|
||||
pub fn is_multicam(it: &TrackItem) -> bool {
|
||||
@@ -54,30 +54,21 @@ pub fn set_enabled(seq: &mut Sequence, clips: &[ClipId], enabled: bool) -> usize
|
||||
|
||||
/// Two adjacent pieces of one multi-camera clip that a cut between them would not change.
|
||||
fn continuous(a: &TrackItem, b: &TrackItem) -> bool {
|
||||
a.end() == b.start
|
||||
&& a.item == b.item
|
||||
&& a.multicam.is_some()
|
||||
&& a.multicam == b.multicam
|
||||
&& a.speed == b.speed
|
||||
&& !a.reverse
|
||||
&& !b.reverse
|
||||
&& a.frame_hold.is_none()
|
||||
&& b.frame_hold.is_none()
|
||||
&& a.source_out() == b.source_in
|
||||
&& a.enabled == b.enabled
|
||||
&& a.gain_db == b.gain_db
|
||||
&& a.effects == b.effects
|
||||
a.multicam.is_some() && !a.reverse && a.frame_hold.is_none() && a.source_out() == b.source_in && crate::through::is_through_edit(a, b)
|
||||
}
|
||||
|
||||
/// Remove through edits between pieces of the same multi-camera clip showing the same angle,
|
||||
/// for edit points in `range` (inclusive of its ends). Returns the ids of the removed pieces.
|
||||
pub fn heal_track(track: &mut Track, range: TimeRange) -> Vec<ClipId> {
|
||||
heal_track_where(track, |a, b| b.start >= range.start && b.start <= range.end() && continuous(a, b))
|
||||
}
|
||||
|
||||
fn heal_track_where(track: &mut Track, can_join: impl Fn(&TrackItem, &TrackItem) -> bool) -> Vec<ClipId> {
|
||||
let mut removed = Vec::new();
|
||||
let mut i = 0;
|
||||
while i + 1 < track.items.len() {
|
||||
let (a, b) = (&track.items[i], &track.items[i + 1]);
|
||||
let at = b.start;
|
||||
if at >= range.start && at <= range.end() && continuous(a, b) {
|
||||
if can_join(a, b) {
|
||||
let (aid, bid) = (a.id, b.id);
|
||||
let dur = b.duration;
|
||||
track.items[i].duration += dur;
|
||||
@@ -105,47 +96,120 @@ pub fn heal_track(track: &mut Track, range: TimeRange) -> Vec<ClipId> {
|
||||
pub struct Cut {
|
||||
pub time: Tick,
|
||||
pub angle: u32,
|
||||
/// Whether linked audio follows this particular switch.
|
||||
pub switch_audio: bool,
|
||||
}
|
||||
|
||||
/// Apply a recording pass: on `tracks`, the multi-camera clips of `source` get angle `cuts[i].angle` from
|
||||
/// `cuts[i].time` until the next cut, the last one until `end`. Clips are split at each cut and at
|
||||
/// `end`; afterwards through edits inside the recorded range are healed, so pressing the angle that
|
||||
/// is already showing adds no edit. Locked tracks are skipped. Returns the number of edit points
|
||||
/// in the recorded range after the pass.
|
||||
pub fn record(seq: &mut Sequence, tracks: &[TrackId], source: ItemId, cuts: &[Cut], end: Tick, ctx: &mut EditCtx) -> usize {
|
||||
let mut cuts: Vec<Cut> = cuts.iter().copied().filter(|c| c.time < end).collect();
|
||||
cuts.sort_by_key(|c| c.time);
|
||||
// two presses at one time: the later wins
|
||||
let mut dedup: Vec<Cut> = Vec::new();
|
||||
for c in cuts {
|
||||
match dedup.last_mut() {
|
||||
Some(l) if l.time == c.time => *l = c,
|
||||
_ => dedup.push(c),
|
||||
}
|
||||
/// For simultaneous presses, keep the last one that applies to this track kind.
|
||||
fn track_cuts(cuts: impl Iterator<Item = Cut>) -> Vec<Cut> {
|
||||
let mut by_time = BTreeMap::new();
|
||||
for cut in cuts {
|
||||
by_time.insert(cut.time, cut);
|
||||
}
|
||||
let Some(first) = dedup.first().map(|c| c.time) else { return 0 };
|
||||
let mut links = HashMap::new();
|
||||
let mut points = 0;
|
||||
for tr in seq.all_tracks_mut() {
|
||||
if tr.locked || !tracks.contains(&tr.id) {
|
||||
continue;
|
||||
by_time.into_values().collect()
|
||||
}
|
||||
|
||||
/// A linked edit can disappear only when every member on both sides can join its
|
||||
/// partner at the same time. Decide on the unsimplified tracks so track order cannot
|
||||
/// change the outcome. Right-hand clip IDs stay valid across consecutive joins.
|
||||
fn recorded_joins(seq: &Sequence, participants: &HashSet<ClipId>, first: Tick, end: Tick) -> HashSet<ClipId> {
|
||||
let mut group_sizes = HashMap::<u64, usize>::new();
|
||||
let mut linked = HashMap::<(u64, u64, Tick), Vec<ClipId>>::new();
|
||||
let mut joins = HashSet::new();
|
||||
for track in seq.all_tracks() {
|
||||
for link in track.items.iter().filter_map(|item| item.link) {
|
||||
*group_sizes.entry(link).or_default() += 1;
|
||||
}
|
||||
let mc_at = |tr: &Track, t: Tick| tr.items.iter().any(|i| i.start < t && t < i.end() && is_multicam(i) && i.item == source);
|
||||
for t in dedup.iter().map(|c| c.time).chain([end]) {
|
||||
if mc_at(tr, t) {
|
||||
split_track_at(tr, t, ctx, &mut links);
|
||||
for pair in track.items.windows(2) {
|
||||
let (a, b) = (&pair[0], &pair[1]);
|
||||
if b.start < first || b.start > end || !participants.contains(&a.id) || !participants.contains(&b.id) {
|
||||
continue;
|
||||
}
|
||||
if !continuous(a, b) || track.transitions.iter().any(|tr| tr.from == Some(a.id) || tr.to == Some(b.id)) {
|
||||
continue;
|
||||
}
|
||||
match (a.link, b.link) {
|
||||
(Some(left), Some(right)) => linked.entry((left, right, b.start)).or_default().push(b.id),
|
||||
(None, None) => {
|
||||
joins.insert(b.id);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
for (k, c) in dedup.iter().enumerate() {
|
||||
let r_end = dedup.get(k + 1).map_or(end, |n| n.time);
|
||||
for it in tr.items.iter_mut().filter(|i| i.start >= c.time && i.end() <= r_end && i.item == source) {
|
||||
}
|
||||
for ((left, right, _), members) in linked {
|
||||
if group_sizes.get(&left) == Some(&members.len()) && group_sizes.get(&right) == Some(&members.len()) {
|
||||
joins.extend(members);
|
||||
}
|
||||
}
|
||||
joins
|
||||
}
|
||||
|
||||
/// Keep audio transitions attached to their actual clip edges. A fade keeps its
|
||||
/// full timeline range across a picture edit, even if the edge piece gets shorter.
|
||||
fn split_recorded_audio(track: &mut Track, at: Tick, ctx: &mut EditCtx, links: &mut HashMap<u64, u64>) -> Option<ClipId> {
|
||||
let (left, right) = split_track_item(track, at, ctx, links)?;
|
||||
for transition in &mut track.transitions {
|
||||
if transition.from == Some(left) {
|
||||
transition.from = Some(right);
|
||||
}
|
||||
}
|
||||
Some(right)
|
||||
}
|
||||
|
||||
/// Apply a live pass to the source's video and linked audio tracks. Each eligible cut runs
|
||||
/// until the next eligible cut on that track, or until the pass ends. Locked tracks are skipped.
|
||||
/// Through edits are healed; returns the number of edit points inside the recorded range.
|
||||
pub fn record(seq: &mut Sequence, tracks: &[TrackId], source: ItemId, cuts: &[Cut], end: Tick, ctx: &mut EditCtx) -> usize {
|
||||
let before_end = cuts.iter().copied().filter(|cut| cut.time < end);
|
||||
let video = track_cuts(before_end.clone());
|
||||
let audio = track_cuts(before_end.filter(|cut| cut.switch_audio));
|
||||
let Some(first) = video.first().map(|c| c.time) else { return 0 };
|
||||
let mut participants = HashSet::new();
|
||||
let mut video_links = HashSet::new();
|
||||
for tr in seq.video_tracks.iter().filter(|tr| tracks.contains(&tr.id) && !tr.locked) {
|
||||
for item in tr.items.iter().filter(|i| i.item == source && is_multicam(i) && i.end() >= first && i.start <= end) {
|
||||
participants.insert(item.id);
|
||||
video_links.extend(item.link);
|
||||
}
|
||||
}
|
||||
for tr in seq.audio_tracks.iter().filter(|tr| tracks.contains(&tr.id) && !tr.locked) {
|
||||
participants.extend(tr.items.iter().filter(|i| i.item == source && is_multicam(i) && i.link.is_some_and(|l| video_links.contains(&l))).map(|i| i.id));
|
||||
}
|
||||
|
||||
let mut links_by_time = HashMap::new();
|
||||
for tr in seq.all_tracks_mut().filter(|tr| !tr.locked && tracks.contains(&tr.id)) {
|
||||
// Split linked picture and sound together even when only one angle changes.
|
||||
// Right-to-left splitting gives both partners the same original link at each cut.
|
||||
let split = match tr.kind {
|
||||
TrackKind::Audio => split_recorded_audio,
|
||||
TrackKind::Video => split_track_at,
|
||||
};
|
||||
for t in std::iter::once(end).chain(video.iter().rev().map(|c| c.time)) {
|
||||
if tr.item_at(t).is_some_and(|i| i.start < t && participants.contains(&i.id))
|
||||
&& let Some(right) = split(tr, t, ctx, links_by_time.entry(t).or_default())
|
||||
{
|
||||
participants.insert(right);
|
||||
}
|
||||
}
|
||||
let cuts = match tr.kind {
|
||||
TrackKind::Video => &video,
|
||||
TrackKind::Audio => &audio,
|
||||
};
|
||||
for (k, c) in cuts.iter().enumerate() {
|
||||
let r_end = cuts.get(k + 1).map_or(end, |n| n.time);
|
||||
for it in tr.items.iter_mut().filter(|i| i.start >= c.time && i.end() <= r_end && participants.contains(&i.id)) {
|
||||
if let Some(m) = &mut it.multicam {
|
||||
m.angle = c.angle;
|
||||
}
|
||||
}
|
||||
}
|
||||
heal_track(tr, TimeRange::from_bounds(first, end));
|
||||
points += tr.items.iter().filter(|i| i.start > first && i.start < end).count();
|
||||
}
|
||||
let joins = recorded_joins(seq, &participants, first, end);
|
||||
let mut points = 0;
|
||||
for tr in seq.all_tracks_mut().filter(|tr| !tr.locked && tracks.contains(&tr.id)) {
|
||||
heal_track_where(tr, |_, b| joins.contains(&b.id));
|
||||
points += tr.items.iter().filter(|i| i.start > first && i.start < end && participants.contains(&i.id)).count();
|
||||
}
|
||||
points
|
||||
}
|
||||
|
||||
@@ -58,6 +58,10 @@ impl Alignment {
|
||||
/// outgoing clip's start, the cut and the incoming clip's end; for a fade to or from nothing the cut
|
||||
/// is its clip's edge. `None` when its clips are gone.
|
||||
pub fn bounds(track: &Track, tr: &Transition) -> Option<(Tick, Tick, Tick)> {
|
||||
if let Some(span) = track.multicam_fade_span(tr) {
|
||||
let cut = if tr.to.is_some() { span.start } else { span.end() };
|
||||
return Some((span.start, cut, span.end()));
|
||||
}
|
||||
let from = tr.from.and_then(|c| track.item(c));
|
||||
let to = tr.to.and_then(|c| track.item(c));
|
||||
match (from, to) {
|
||||
|
||||
@@ -955,21 +955,18 @@ fn cut(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// stopped: switch the clip at the playhead
|
||||
return switch_angle(s, p);
|
||||
}
|
||||
let (_, clip) = multicam_clip_at(s, t).ok_or_else(|| EngineError::Other("no multi-camera clip at the playhead".into()))?;
|
||||
let (video_track, clip) = multicam_clip_at(s, t).ok_or_else(|| EngineError::Other("no multi-camera clip at the playhead".into()))?;
|
||||
let angle = angle_p(s, p, clip.item, cmd)?;
|
||||
if s.mcrec.tracks.is_empty() {
|
||||
let q = s.active_sequence().ok_or(EngineError::NoSequence)?;
|
||||
let mut tracks: Vec<TrackId> =
|
||||
q.video_tracks.iter().filter(|tr| tr.item_at(t).is_some_and(|i| i.item == clip.item && i.multicam.is_some())).map(|tr| tr.id).collect();
|
||||
tracks.truncate(1);
|
||||
if s.state.multicam_audio_follows_video && !bool_p(p, "videoOnly").unwrap_or(false) {
|
||||
let partners = audio_partners(q, &clip);
|
||||
tracks.extend(q.audio_tracks.iter().filter(|tr| tr.items.iter().any(|i| partners.contains(&i.id))).map(|tr| tr.id));
|
||||
}
|
||||
let partners = audio_partners(q, &clip);
|
||||
let mut tracks = vec![video_track];
|
||||
tracks.extend(q.audio_tracks.iter().filter(|tr| tr.items.iter().any(|i| partners.contains(&i.id))).map(|tr| tr.id));
|
||||
s.mcrec.tracks = tracks;
|
||||
}
|
||||
s.mcrec.source = Some(clip.item);
|
||||
s.mcrec.cuts.push(Cut { time: t, angle });
|
||||
let switch_audio = s.state.multicam_audio_follows_video && !bool_p(p, "videoOnly").unwrap_or(false);
|
||||
s.mcrec.cuts.push(Cut { time: t, angle, switch_audio });
|
||||
// provisional: the new angle runs to the end of this multi-camera clip (its contiguous pieces)
|
||||
// until the pass stops
|
||||
let end = s
|
||||
|
||||
@@ -567,6 +567,141 @@ fn live_switch_recording_from_playback_clock() {
|
||||
assert_eq!(v1(&s), vec![(0, 1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mixed_recording_cuts_preserve_audio_scope() {
|
||||
let (mut s, _, _, _) = mc_session("switch");
|
||||
s.execute("multicam.audioFollowsVideo", json!({"enabled": true})).unwrap();
|
||||
let before = s.project.clone();
|
||||
s.execute("multicam.recordStart", json!({"frame": 0})).unwrap();
|
||||
let cut = |s: &mut Session, frame: i64, camera: u64, video_only: bool| {
|
||||
s.execute("multicam.cut", json!({"frame": frame, "camera": camera, "videoOnly": video_only})).unwrap();
|
||||
};
|
||||
cut(&mut s, 12, 3, true);
|
||||
assert_eq!(a1(&s), [(0, 0), (12, 0)]);
|
||||
cut(&mut s, 24, 2, false);
|
||||
cut(&mut s, 48, 3, true);
|
||||
assert_eq!(a1(&s), [(0, 0), (12, 0), (24, 1), (48, 1)], "a video-only cut keeps the preceding audio live");
|
||||
cut(&mut s, 72, 3, false);
|
||||
cut(&mut s, 72, 2, true);
|
||||
s.execute("multicam.recordStop", json!({"frame": 84})).unwrap();
|
||||
assert_eq!(v1(&s), [(0, 0), (12, 2), (24, 1), (48, 2), (72, 1), (84, 0)]);
|
||||
assert_eq!(a1(&s), [(0, 0), (12, 0), (24, 1), (48, 1), (72, 2), (84, 0)]);
|
||||
let q = s.active_sequence().unwrap();
|
||||
for frame in [0, 12, 24, 48, 72, 84] {
|
||||
let t = q.settings.frame_rate.tick_of(frame);
|
||||
let video = q.video_tracks[0].item_at(t).unwrap();
|
||||
let audio = q.audio_tracks[0].item_at(t).unwrap();
|
||||
assert!(video.link.is_some() && video.link == audio.link, "paired splits remain linked at frame {frame}");
|
||||
}
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(s.project, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recorded_video_only_cut_keeps_audio_for_a_later_camera_edit() {
|
||||
let (mut s, _, _, _) = mc_session("switch");
|
||||
s.execute("multicam.audioFollowsVideo", json!({"enabled": true})).unwrap();
|
||||
s.execute("multicam.recordStart", json!({"frame": 0})).unwrap();
|
||||
s.execute("multicam.cut", json!({"frame": 24, "camera": 2})).unwrap();
|
||||
s.execute("multicam.cut", json!({"frame": 48, "camera": 3, "videoOnly": true})).unwrap();
|
||||
s.execute("multicam.recordStop", json!({"frame": 84})).unwrap();
|
||||
s.execute("multicam.cutToCamera", json!({"frame": 60, "camera": 1})).unwrap();
|
||||
assert_eq!(v1(&s), [(0, 0), (24, 1), (48, 2), (60, 0), (84, 0)]);
|
||||
assert_eq!(a1(&s), [(0, 0), (24, 1), (48, 1), (60, 0), (84, 0)], "the later edit switches linked audio from frame 60");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recorded_audio_change_keeps_its_matching_picture_edit() {
|
||||
let (mut s, _, _, _) = mc_session("switch");
|
||||
s.execute("multicam.audioFollowsVideo", json!({"enabled": true})).unwrap();
|
||||
s.execute("multicam.recordStart", json!({"frame": 0})).unwrap();
|
||||
s.execute("multicam.cut", json!({"frame": 12, "camera": 2, "videoOnly": true})).unwrap();
|
||||
s.execute("multicam.cut", json!({"frame": 24, "camera": 2})).unwrap();
|
||||
s.execute("multicam.cut", json!({"frame": 36, "camera": 2})).unwrap();
|
||||
s.execute("multicam.recordStop", json!({"frame": 84})).unwrap();
|
||||
assert_eq!(v1(&s), [(0, 0), (12, 1), (24, 1), (84, 0)], "retain the audio change but heal the repeated switch");
|
||||
assert_eq!(a1(&s), [(0, 0), (12, 0), (24, 1), (84, 0)]);
|
||||
s.execute("multicam.switchAngle", json!({"frame": 30, "camera": 3})).unwrap();
|
||||
assert_eq!(v1(&s), [(0, 0), (12, 1), (24, 2), (84, 0)]);
|
||||
assert_eq!(a1(&s), [(0, 0), (12, 0), (24, 2), (84, 0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn video_only_recording_preserves_the_rendered_audio_fades() {
|
||||
let (mut s, _, _, _) = mc_session("switch");
|
||||
let clip = s.active_sequence().unwrap().audio_tracks[0].items[0].id.0;
|
||||
for edge in ["in", "out"] {
|
||||
s.execute("sequence.applyAudioTransition", json!({"clip": clip, "edge": edge, "frames": 40})).unwrap();
|
||||
}
|
||||
let mix = |s: &Session| {
|
||||
let provider = s.media.provider(s.project.clone(), s.services.clone());
|
||||
filmcraft_render::audio::mix_sequence(&s.project, s.active_sequence().unwrap(), 0, 4 * 48_000, &provider).channels
|
||||
};
|
||||
let before = mix(&s);
|
||||
assert!(before[0].iter().any(|sample| sample.abs() > 1e-3));
|
||||
s.execute("multicam.audioFollowsVideo", json!({"enabled": true})).unwrap();
|
||||
s.execute("multicam.recordStart", json!({"frame": 0})).unwrap();
|
||||
for (frame, camera) in [(12, 2), (24, 3), (72, 2)] {
|
||||
s.execute("multicam.cut", json!({"frame": frame, "camera": camera, "videoOnly": true})).unwrap();
|
||||
}
|
||||
s.execute("multicam.recordStop", json!({"frame": 84})).unwrap();
|
||||
let after = mix(&s);
|
||||
for (a, b) in before.iter().flatten().zip(after.iter().flatten()) {
|
||||
assert!((a - b).abs() < 1e-5, "a picture-only cut changed a faded sample: {a} vs {b}");
|
||||
}
|
||||
let seq = s.active_sequence().unwrap();
|
||||
let audio = &seq.audio_tracks[0];
|
||||
assert_eq!(audio.transitions.len(), 2);
|
||||
assert_eq!(audio.transitions[0].to, Some(audio.items.first().unwrap().id));
|
||||
assert_eq!(audio.transitions[1].from, Some(audio.items.last().unwrap().id));
|
||||
for (picture, sound) in seq.video_tracks[0].items.iter().zip(&audio.items) {
|
||||
assert_eq!(picture.range(), sound.range());
|
||||
assert!(picture.link.is_some() && picture.link == sound.link);
|
||||
}
|
||||
let fade = audio.transitions[0].id.0;
|
||||
let middle = audio.item_at(seq.settings.frame_rate.tick_of(30)).unwrap().id.0;
|
||||
for frames in [6, 40] {
|
||||
s.execute("sequence.setTransition", json!({"transition": fade, "frames": frames})).unwrap();
|
||||
let seq = s.active_sequence().unwrap();
|
||||
assert_eq!(seq.audio_tracks[0].transitions[0].duration, seq.settings.frame_rate.tick_of(frames));
|
||||
}
|
||||
s.execute("clip.audioGain", json!({"clips": [middle], "mode": "set", "db": -6.0})).unwrap();
|
||||
let adjusted = mix(&s);
|
||||
let window = 60_000..62_000; // frame 30, inside both the middle piece and the fade-in
|
||||
let gain = 10.0_f32.powf(-6.0 / 20.0);
|
||||
assert!(before[0][window.clone()].iter().any(|v| v.abs() > 1e-3));
|
||||
for (old, new) in before[0][window.clone()].iter().zip(&adjusted[0][window]) {
|
||||
assert!((new - old * gain).abs() < 1e-5, "the fade must follow the audio piece under the playhead");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlapping_multicam_fades_use_the_later_transition_in_the_overlap() {
|
||||
let (mut s, _, _, _) = mc_session("switch");
|
||||
let clip = s.active_sequence().unwrap().audio_tracks[0].items[0].id.0;
|
||||
s.execute("sequence.applyAudioTransition", json!({"clip": clip, "edge": "in", "frames": 12})).unwrap();
|
||||
s.execute("sequence.applyAudioTransition", json!({"clip": clip, "edge": "out", "frames": 48})).unwrap();
|
||||
let fade_in = s.active_sequence().unwrap().audio_tracks[0].transitions[0].id.0;
|
||||
// Frames 52..60 of a 96-frame clip initially contain only the fade-out.
|
||||
let render_overlap = |s: &Session| {
|
||||
let provider = s.media.provider(s.project.clone(), s.services.clone());
|
||||
filmcraft_render::audio::mix_sequence(&s.project, s.active_sequence().unwrap(), 52 * 2000, 8 * 2000, &provider).channels
|
||||
};
|
||||
let fade_out_alone = render_overlap(&s);
|
||||
assert!(fade_out_alone[0].iter().any(|sample| sample.abs() > 1e-3));
|
||||
s.execute("sequence.setTransition", json!({"transition": fade_in, "frames": 72})).unwrap();
|
||||
let check = |s: &Session| {
|
||||
for (actual, expected) in render_overlap(s).iter().flatten().zip(fade_out_alone.iter().flatten()) {
|
||||
assert!((actual - expected).abs() < 1e-5, "overlapping an earlier fade changed the fade-out: {actual} vs {expected}");
|
||||
}
|
||||
};
|
||||
check(&s);
|
||||
s.execute("multicam.recordStart", json!({"frame": 0})).unwrap();
|
||||
s.execute("multicam.cut", json!({"frame": 56, "camera": 2, "videoOnly": true})).unwrap();
|
||||
s.execute("multicam.recordStop", json!({"frame": 84})).unwrap();
|
||||
check(&s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_replaces_with_camera_clips() {
|
||||
let (mut s, items, _, _) = mc_session("switch");
|
||||
|
||||
@@ -354,6 +354,43 @@ impl Track {
|
||||
let idx = self.items.partition_point(|i| i.start <= t);
|
||||
idx.checked_sub(1).map(|i| &self.items[i]).filter(|i| t < i.end())
|
||||
}
|
||||
/// A one-sided audio fade can span several pieces after a multicamera switch.
|
||||
/// Follow contiguous pieces of the same source so a shortened fade can grow again.
|
||||
pub fn multicam_fade_span(&self, fade: &Transition) -> Option<TimeRange> {
|
||||
if self.kind != TrackKind::Audio {
|
||||
return None;
|
||||
}
|
||||
let (anchor, incoming) = match (fade.from, fade.to) {
|
||||
(None, Some(id)) => (id, true),
|
||||
(Some(id), None) => (id, false),
|
||||
_ => return None,
|
||||
};
|
||||
let index = self.items.iter().position(|item| item.id == anchor)?;
|
||||
let item = &self.items[index];
|
||||
item.multicam.as_ref()?;
|
||||
let continues = |a: &TrackItem, b: &TrackItem| {
|
||||
a.end() == b.start
|
||||
&& a.item == b.item
|
||||
&& a.multicam.is_some()
|
||||
&& b.multicam.is_some()
|
||||
&& a.speed == b.speed
|
||||
&& a.reverse == b.reverse
|
||||
&& a.frame_hold == b.frame_hold
|
||||
&& a.source_time_at(b.start).0.abs_diff(b.source_time_at(b.start).0) <= 1
|
||||
};
|
||||
let (mut first, mut last) = (index, index);
|
||||
if incoming {
|
||||
while self.items.get(last + 1).is_some_and(|next| continues(&self.items[last], next)) {
|
||||
last += 1;
|
||||
}
|
||||
} else {
|
||||
while first > 0 && continues(&self.items[first - 1], &self.items[first]) {
|
||||
first -= 1;
|
||||
}
|
||||
}
|
||||
Some(TimeRange::from_bounds(self.items[first].start, self.items[last].end()))
|
||||
}
|
||||
|
||||
pub fn item(&self, id: ClipId) -> Option<&TrackItem> {
|
||||
self.items.iter().find(|i| i.id == id)
|
||||
}
|
||||
|
||||
@@ -107,15 +107,35 @@ pub(crate) fn track_input_at(
|
||||
let live =
|
||||
ClipLive { vol: ovs.get(&(track.id, CLIP_LANE_VOLUME.to_string())).copied(), pan: ovs.get(&(track.id, CLIP_LANE_PAN.to_string())).copied(), depth };
|
||||
let range = TimeRange::from_bounds(Tick::from_units(start, sr as i64), Tick::from_units(start + frames as i64, sr as i64));
|
||||
let mut tbuf = AudioBuffer::silence(sr, w, frames);
|
||||
let mut dry = AudioBuffer::silence(sr, w, frames);
|
||||
for item in track.items.iter().filter(|i| i.enabled && i.range().overlaps(&range)) {
|
||||
mix_item(project, item, item, win, sources, &mut tbuf, &live);
|
||||
mix_item(project, item, item, win, sources, &mut dry, &live);
|
||||
}
|
||||
// audio transitions: attenuate the covered region of each side
|
||||
// Each transition replaces its span in track order. Keep the underlying clip mix
|
||||
// available so an overlapping fade always starts from the audio of the active piece.
|
||||
let mut transitioned = None;
|
||||
for tr in &track.transitions {
|
||||
if !tr.range().overlaps(&range) {
|
||||
continue;
|
||||
}
|
||||
let output = transitioned.get_or_insert_with(|| dry.clone());
|
||||
// A one-sided fade across multicamera edits follows what each piece actually
|
||||
// plays. Reading only the anchor's handles would play its angle over later cuts.
|
||||
if let Some(span) = track.multicam_fade_span(tr) {
|
||||
let fade_start = tr.start.to_units_floor(sr as i64);
|
||||
let duration = tr.duration.to_units_floor(sr as i64).max(1) as f32;
|
||||
let first = start.max(fade_start).max(span.start.to_units_floor(sr as i64));
|
||||
let end = (start + frames as i64).min(tr.end().to_units_floor(sr as i64)).min(span.end().to_units_floor(sr as i64));
|
||||
for sample in first..end {
|
||||
let (outgoing, incoming) = transitions::audio_gains(&tr.effect.effect, (sample - fade_start) as f32 / duration);
|
||||
let gain = if tr.to.is_some() { incoming } else { outgoing };
|
||||
let i = (sample - start) as usize;
|
||||
for (dst, src) in output.channels.iter_mut().zip(&dry.channels) {
|
||||
dst[i] = src[i] * gain;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Re-mix: recompute the covered samples with crossfade gains. Both sides play over the
|
||||
// whole transition, into their handles as the picture does, so a transition centred on a
|
||||
// cut overlaps the two clips instead of only fading each on its own side of the cut.
|
||||
@@ -129,9 +149,6 @@ pub(crate) fn track_input_at(
|
||||
}
|
||||
let n = (s1 - s0) as usize;
|
||||
let off = (s0 - start) as usize;
|
||||
for ch in tbuf.channels.iter_mut() {
|
||||
ch[off..off + n].fill(0.0);
|
||||
}
|
||||
let mut a = AudioBuffer::silence(sr, w, n);
|
||||
let mut b = AudioBuffer::silence(sr, w, n);
|
||||
if let (Some(f), Some(orig)) = (&from, from_src) {
|
||||
@@ -146,11 +163,11 @@ pub(crate) fn track_input_at(
|
||||
let p = (base + i as f32) / dur;
|
||||
let (ga, gb) = transitions::audio_gains(&tr.effect.effect, p);
|
||||
for c in 0..w {
|
||||
tbuf.channels[c][off + i] += a.channels[c][i] * ga + b.channels[c][i] * gb;
|
||||
output.channels[c][off + i] = a.channels[c][i] * ga + b.channels[c][i] * gb;
|
||||
}
|
||||
}
|
||||
}
|
||||
tbuf
|
||||
transitioned.unwrap_or(dry)
|
||||
}
|
||||
|
||||
/// `item` lengthened to cover `[t0, t1)` with its media timing unchanged: the part before its in
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
//! `mcam.marker`, `mcam.offset`, `mcam.audio.<camera1|all|switch>`,
|
||||
//! `mcam.cameraNames.<clip|track|metadata>`, `mcam.processedBin`, `mcam.ok`, `mcam.cancel`.
|
||||
|
||||
use egui::{Align2, Color32, Rect, RichText, Sense, Stroke, StrokeKind, pos2, vec2};
|
||||
use egui::{Align2, Color32, PointerButton, Rect, RichText, Sense, Stroke, StrokeKind, pos2, vec2};
|
||||
use filmcraft_project::ItemId;
|
||||
use filmcraft_time::Tick;
|
||||
use serde_json::{Value, json};
|
||||
@@ -296,6 +296,34 @@ fn grid_revision(app: &FilmcraftApp, src: ItemId) -> u64 {
|
||||
h.finish()
|
||||
}
|
||||
|
||||
/// Whether this activation switches only video. On macOS the runtime delivers Control-click as a secondary click.
|
||||
fn angle_click(response: &egui::Response) -> Option<bool> {
|
||||
let button = if response.clicked() {
|
||||
PointerButton::Primary
|
||||
} else if response.clicked_by(PointerButton::Secondary) && craft_ui::runtime::windows::os_of(&response.ctx) == craft_host::target::Os::Mac {
|
||||
PointerButton::Secondary
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
// A modifier can be released later in the same frame. Use the button release on this cell
|
||||
// when present, and the current modifiers for a keyboard or accessibility activation.
|
||||
let modifiers = response.ctx.input(|input| {
|
||||
for event in input.events.iter().rev() {
|
||||
if let egui::Event::PointerButton { pos, button: released, pressed: false, modifiers } = event
|
||||
&& *released == button
|
||||
&& response.interact_rect.contains(*pos)
|
||||
{
|
||||
return *modifiers;
|
||||
}
|
||||
}
|
||||
input.modifiers
|
||||
});
|
||||
if button == PointerButton::Secondary {
|
||||
return (modifiers.ctrl && !modifiers.alt && !modifiers.command).then_some(true);
|
||||
}
|
||||
Some(modifiers.ctrl || modifiers.command)
|
||||
}
|
||||
|
||||
/// The angle grid of the Multi-Camera view in `area`.
|
||||
pub fn grid(app: &mut FilmcraftApp, ui: &mut egui::Ui, area: Rect) {
|
||||
let t = app.tokens;
|
||||
@@ -362,12 +390,7 @@ pub fn grid(app: &mut FilmcraftApp, ui: &mut egui::Ui, area: Rect) {
|
||||
let name = cams.cameras.get(angle).map(|c| c.name.clone()).unwrap_or_default();
|
||||
let resp = ui.interact(cell, egui::Id::unique(("multicam-angle", k)), Sense::click()).on_hover_text(tlf!("Camera {n} — {name}", n = k + 1, name));
|
||||
app.auto.add(&format!("program.multicam.angle.{}", k + 1), cell, &name);
|
||||
if resp.clicked() {
|
||||
// modifiers held now, or carried by the click event (synthetic input)
|
||||
let video_only = ui.input(|i| {
|
||||
let ev = i.events.iter().any(|e| matches!(e, egui::Event::PointerButton { modifiers: m, .. } if m.ctrl || m.command));
|
||||
i.modifiers.ctrl || i.modifiers.command || ev
|
||||
});
|
||||
if let Some(video_only) = angle_click(&resp) {
|
||||
click = Some((k + 1, video_only));
|
||||
}
|
||||
if resp.hovered() {
|
||||
|
||||
@@ -115,7 +115,15 @@ fn create_multicam_dialog_view_and_live_switching() {
|
||||
d.click("program.multicam.angle.2");
|
||||
assert_eq!(d.angles(false), [1]);
|
||||
assert_eq!(d.angles(true), [1], "audio followed");
|
||||
// Ctrl-click: video only
|
||||
// An ordinary right-click leaves both tracks alone.
|
||||
d.ok("ui.click", json!({"id": "program.multicam.angle.4", "button": "right"}));
|
||||
d.frames(3);
|
||||
assert_eq!((d.angles(false), d.angles(true)), (vec![1], vec![1]));
|
||||
// The platform command modifier (Command on macOS, Ctrl elsewhere) switches video only.
|
||||
d.ok("ui.click", json!({"id": "program.multicam.angle.4", "modifiers": {"command": true}}));
|
||||
d.frames(3);
|
||||
assert_eq!((d.angles(false), d.angles(true)), (vec![3], vec![1]));
|
||||
// Physical Control is delivered as a secondary click on macOS.
|
||||
d.ok("ui.click", json!({"id": "program.multicam.angle.3", "modifiers": {"ctrl": true}}));
|
||||
d.frames(3);
|
||||
assert_eq!((d.angles(false), d.angles(true)), (vec![2], vec![1]));
|
||||
|
||||
Reference in new issue
Block a user