Skip to content

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

feat(transitions): a transition's own knobs can be set on its cut - Push's direction, a wipe's softness, a whip's speed

Jareerce64dae5c350
diff --git a/src/crates/concat-export/src/flatten.rs b/src/crates/concat-export/src/flatten.rs
index 9a692e71..c8c1d445 100644
--- a/src/crates/concat-export/src/flatten.rs
+++ b/src/crates/concat-export/src/flatten.rs
@@ -133,6 +133,7 @@ pub fn flatten_timeline_in(
.map(|transition| TransitionSpec {
kind: transition.id.clone(),
duration: transition.duration,
+ params: transition.params.clone(),
}),
media_width: media.width,
media_height: media.height,
diff --git a/src/crates/concat-export/src/lib.rs b/src/crates/concat-export/src/lib.rs
index 821eef7c..58978eaa 100644
--- a/src/crates/concat-export/src/lib.rs
+++ b/src/crates/concat-export/src/lib.rs
@@ -381,6 +381,10 @@ pub struct TransitionSpec {
pub kind: String,
/// Seconds the transition covers.
pub duration: f64,
+ /// A packaged transition's knobs as set on the cut; the package's
+ /// defaults for any left out.
+ #[serde(default)]
+ pub params: BTreeMap<String, f64>,
}
fn yes() -> bool {
@@ -654,6 +658,7 @@ fn resolve_transitions_at(
outgoing,
kind: transition.kind.clone(),
duration: transition.duration.max(0.0),
+ params: transition.params.clone(),
}),
_ => {}
}
@@ -802,7 +807,7 @@ fn resolve_transitions_at(
end,
to_track: b.track,
id: cut.kind.clone(),
- params: BTreeMap::new(),
+ params: cut.params.clone(),
});
}
// A kind this build does not know renders as a plain cut rather
@@ -821,6 +826,7 @@ struct Cut {
outgoing: usize,
kind: String,
duration: f64,
+ params: BTreeMap<String, f64>,
}
/// What [`overlap`] built a transition on.
@@ -2594,6 +2600,7 @@ mod tests {
Some(TransitionSpec {
kind: kind.to_owned(),
duration,
+ params: BTreeMap::new(),
})
}
@@ -3332,6 +3339,20 @@ mod tests {
assert_eq!(keys_on(&clips[1], "scale"), vec![(0.5 / 4.5, 2.0)]);
}
+ /// A packaged transition's knobs, as set on the cut, reach the span
+ /// the compositor combines with: before, every span was built empty and
+ /// every transition drew at its defaults, whatever the cut held.
+ #[test]
+ fn a_packaged_transitions_knobs_reach_its_span() {
+ let mut clips = cut_with_handles();
+ let mut transition = spec("concat.push", 1.0).expect("a spec");
+ transition.params.insert("direction".to_owned(), 2.0);
+ clips[1].transition = Some(transition);
+ let spans = resolve_transitions(&mut clips, FrameRate::THIRTY);
+ assert_eq!(spans.len(), 1);
+ assert_eq!(spans[0].params.get("direction"), Some(&2.0));
+ }
+
#[test]
fn a_packaged_transition_id_overlaps_the_clip_and_emits_a_span() {
// A transition named by its package id (not one of the seven legacy
diff --git a/src/crates/concat-host/tests/export.rs b/src/crates/concat-host/tests/export.rs
index 0b1e295a..c5cb47f3 100644
--- a/src/crates/concat-host/tests/export.rs
+++ b/src/crates/concat-host/tests/export.rs
@@ -1095,6 +1095,7 @@ fn fades_and_wipes_reach_the_picture() {
transition_in: Some(Some(Transition {
id: kind.to_owned(),
duration: 1.0,
+ params: Default::default(),
})),
..ClipPatch::default()
},
@@ -1582,6 +1583,7 @@ fn every_edit_still_exports() {
transition_in: Some(Some(Transition {
id: kind.to_owned(),
duration: 0.5,
+ params: Default::default(),
})),
..ClipPatch::default()
},
diff --git a/src/crates/concat-project/src/lib.rs b/src/crates/concat-project/src/lib.rs
index 147c97ea..36b10075 100644
--- a/src/crates/concat-project/src/lib.rs
+++ b/src/crates/concat-project/src/lib.rs
@@ -1469,6 +1469,7 @@ mod tests {
.transition_in = Some(crate::model::Transition {
id: "cross-fade".into(),
duration: 0.4,
+ params: Default::default(),
});
assert!(
crate::consolidation_clips(
@@ -1948,6 +1949,7 @@ mod tests {
transition_in: Some(Some(crate::model::Transition {
id: "cross-fade".to_owned(),
duration: f64::NAN,
+ params: Default::default(),
})),
..Default::default()
},
@@ -2930,6 +2932,7 @@ mod tests {
transition_in: Some(Some(crate::model::Transition {
id: "cross-fade".to_owned(),
duration: 1.5,
+ params: Default::default(),
})),
..ClipPatch::default()
},
diff --git a/src/crates/concat-project/src/model.rs b/src/crates/concat-project/src/model.rs
index 04414998..88e97d6f 100644
--- a/src/crates/concat-project/src/model.rs
+++ b/src/crates/concat-project/src/model.rs
@@ -1308,6 +1308,11 @@ pub struct Transition {
/// Seconds the transition covers.
#[serde(default = "unity")]
pub duration: f64,
+ /// The package's knobs as set on this cut, by key; a knob left out is
+ /// at its default. Empty for every transition saved before knobs could
+ /// be set, which play exactly as they did.
+ #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
+ pub params: BTreeMap<String, f64>,
}
/// How a title's lines sit within their block, and which point of the block
diff --git a/src/crates/concat-render/src/gpu/tests.rs b/src/crates/concat-render/src/gpu/tests.rs
index 3da3837a..a1803464 100644
--- a/src/crates/concat-render/src/gpu/tests.rs
+++ b/src/crates/concat-render/src/gpu/tests.rs
@@ -835,6 +835,34 @@ fn halfway_through_a_packaged_transition_is_not_a_dissolve() {
eprintln!("{}", report.join("\n"));
}
+/// A transition's knob, set on the cut, changes what the shader draws:
+/// Push to the right is not Push to the left.
+#[test]
+fn a_transitions_knob_changes_what_it_draws() {
+ let Some(mut gpu) = gpu() else { return };
+ let (width, height) = (64, 36);
+ let (from, to) = (
+ gradient(width, height),
+ solid(width, height, [30, 200, 60, 255]),
+ );
+ let catalogue = concat_effects::Catalogue::builtin();
+ let draw = |gpu: &mut WgpuCompositor, direction: f64| {
+ let params = BTreeMap::from([("direction".to_owned(), direction)]);
+ let pass = catalogue
+ .transition_pass("concat.push", &params, 0.5)
+ .expect("push has a pass");
+ gpu.combine(width, height, 0.0, &from, &to, &pass)
+ .expect("combines")
+ };
+ let left = draw(&mut gpu, 0.0);
+ let right = draw(&mut gpu, 1.0);
+ assert_ne!(
+ left.pixels(),
+ right.pixels(),
+ "the direction knob reached the shader"
+ );
+}
+
/// A texture read back into a frame, for comparing a picture that stayed
/// on the device with one that was read back on the way.
fn read_texture(gpu: &WgpuCompositor, texture: &wgpu::Texture) -> Frame {
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index e3110f95..fbe00af2 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -1483,6 +1483,9 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::
editor.on_transition_duration_set(on_window!(|state, seconds: f32| {
state.set_transition_duration(seconds as f64);
}));
+ editor.on_transition_param_set(on_window!(|state, key: SharedString, value: f32| {
+ state.set_transition_param(key.as_str(), f64::from(value));
+ }));
// ── the context menu ──
editor.on_clip_context(on_window!(|state, id: SharedString| {
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index bf5fc61b..01b8c5fe 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -4228,6 +4228,7 @@ impl Studio {
transition_in: Some(Some(Transition {
id: id.to_owned(),
duration,
+ params: Default::default(),
})),
..ClipPatch::default()
},
@@ -4278,6 +4279,39 @@ impl Studio {
self.set_clip_transition_duration(&clip_id, seconds);
}
+ /// Sets one of the selected transition's own knobs, held inside the
+ /// range its package gives it. A knob the package does not have is
+ /// refused rather than stored.
+ pub fn set_transition_param(&mut self, key: &str, value: f64) {
+ let Some(clip_id) = self.transition_target() else {
+ return;
+ };
+ let Some(existing) = self
+ .clip(&clip_id)
+ .and_then(|clip| clip.transition_in.clone())
+ else {
+ return;
+ };
+ let Some(param) = Catalogue::builtin()
+ .get(&existing.id)
+ .and_then(|package| package.manifest.param(key).cloned())
+ else {
+ return;
+ };
+ if !value.is_finite() {
+ return;
+ }
+ let mut params = existing.params.clone();
+ params.insert(key.to_owned(), value.clamp(param.min, param.max));
+ self.apply(Command::UpdateClip {
+ clip_id,
+ patch: ClipPatch {
+ transition_in: Some(Some(Transition { params, ..existing })),
+ ..ClipPatch::default()
+ },
+ });
+ }
+
/// Sets `clip_id`'s transition to `seconds`, clamped to what the cut can
/// actually support.
pub fn set_clip_transition_duration(&mut self, clip_id: &str, seconds: f64) {
@@ -9006,6 +9040,9 @@ impl Studio {
editor.set_selected_clip(self.selected());
editor.set_selected_transition(self.selected_transition_data());
+ let (knobs, choices) = self.transition_knobs();
+ editor.set_transition_knobs(ModelRc::new(VecModel::from(knobs)));
+ editor.set_transition_choices(ModelRc::new(VecModel::from(choices)));
// The background and Fit and Fill, on their own global: the Details
// panel, the Video panel and the phone all read it.
self.publish_backdrop(app);
@@ -10192,6 +10229,89 @@ impl Studio {
}
}
+ /// The selected transition's own knobs as the panel draws them: the
+ /// choices as segments, the numbers as sliders, each at what the cut
+ /// holds or the package's default.
+ fn transition_knobs(&self) -> (Vec<AppliedParamData>, Vec<crate::ui::TransitionChoiceData>) {
+ let Some(transition) = self
+ .selected_transition()
+ .and_then(|clip| clip.transition_in.as_ref())
+ else {
+ return Default::default();
+ };
+ let Some(package) = Catalogue::builtin().get(&transition.id) else {
+ return Default::default();
+ };
+ let (mut knobs, mut choices) = (Vec::new(), Vec::new());
+ for param in &package.manifest.params {
+ let value = transition
+ .params
+ .get(&param.key)
+ .copied()
+ .unwrap_or(param.default);
+ match param.kind {
+ ParamType::Enum if !param.values.is_empty() => {
+ let options: Vec<SharedString> = param
+ .values
+ .iter()
+ .enumerate()
+ .map(|(index, at)| {
+ param
+ .labels
+ .get(index)
+ .cloned()
+ .unwrap_or_else(|| format!("{at}"))
+ .into()
+ })
+ .collect();
+ let current = param
+ .values
+ .iter()
+ .position(|at| (at - value).abs() < 1e-9)
+ .unwrap_or(0);
+ choices.push(crate::ui::TransitionChoiceData {
+ key: param.key.as_str().into(),
+ label: param.label.as_str().into(),
+ options: ModelRc::new(VecModel::from(options)),
+ values: ModelRc::new(VecModel::from(
+ param.values.iter().map(|at| *at as f32).collect::<Vec<_>>(),
+ )),
+ current: current as i32,
+ });
+ }
+ ParamType::Float | ParamType::Int => {
+ let step = if param.step > 0.0 {
+ param.step
+ } else if param.kind == ParamType::Int {
+ 1.0
+ } else {
+ (param.max - param.min) / 200.0
+ };
+ knobs.push(AppliedParamData {
+ entry: 0,
+ key: param.key.as_str().into(),
+ label: param.label.as_str().into(),
+ group: "".into(),
+ unit: param.unit.as_str().into(),
+ min: param.min as f32,
+ max: param.max as f32,
+ step: step as f32,
+ default_value: param.default as f32,
+ value: value as f32,
+ fmt: format_of(&param.unit),
+ keyable: false,
+ keyed: false,
+ here: false,
+ prev: false,
+ next: false,
+ });
+ }
+ _ => {}
+ }
+ }
+ (knobs, choices)
+ }
+
fn selected(&self) -> SelectedClipData {
// Titles share their styling controls; a sound batch exposes volume
// alone, using the first unlocked clip as the displayed reference.
diff --git a/src/crates/concat/ui/app.slint b/src/crates/concat/ui/app.slint
index d4cc0e27..aba26820 100644
--- a/src/crates/concat/ui/app.slint
+++ b/src/crates/concat/ui/app.slint
@@ -39,6 +39,7 @@ import { TitleBar } from "title-bar.slint";
import { PhoneEditor } from "phone/editor.slint";
import {
AppliedEntryData, AppliedParamData, CatalogueEntryData, Library, LibraryViewData,
+ TransitionChoiceData,
} from "inspector/clip-inspector.slint";
import { ParamFormat } from "inspector/controls.slint";
import { ToastData, ToastLayer } from "primitives/toast.slint";
@@ -58,6 +59,7 @@ import { KeyEditor, KeyMarkData, KeyRowData } from "workspace/keyframes-pane.sli
export {
Curves, Fmt, Focus, Payload, Theme, Bezier, Editor, I18n,
AppliedEntryData, AppliedParamData, CatalogueEntryData, Library, LibraryViewData, ParamFormat,
+ TransitionChoiceData,
DockDivider, DockSide, PaneKind, SeatBox,
EffectData, FontSearch, Meters, MediaFilter, MediaItemData, MediaKind, SourcePreview, TextPresetData,
Backdrop, BackdropData, ClipData, ClipField, ClipKeyData, ClipKind, ClipTextField, DropData, Keyframes,
diff --git a/src/crates/concat/ui/editor.slint b/src/crates/concat/ui/editor.slint
index f4631d80..0ec50ece 100644
--- a/src/crates/concat/ui/editor.slint
+++ b/src/crates/concat/ui/editor.slint
@@ -3,7 +3,7 @@
import { EffectData } from "demo/effects-panel.slint";
import {
- AppliedEntryData, AppliedParamData, CatalogueEntryData, ColourKnobData,
+ AppliedEntryData, AppliedParamData, CatalogueEntryData, ColourKnobData, TransitionChoiceData,
} from "inspector/clip-inspector.slint";
import {
CurveData, CurveGroupData, WheelData, WheelGroupData,
@@ -185,6 +185,9 @@ export global Editor {
in-out property <[AppliedEntryData]> applied-visual;
in-out property <[AppliedEntryData]> applied-audio;
in-out property <[AppliedParamData]> visual-params;
+ /// The selected transition's own knobs: the numbers, and the choices.
+ in-out property <[AppliedParamData]> transition-knobs;
+ in-out property <[TransitionChoiceData]> transition-choices;
in-out property <[AppliedParamData]> audio-params;
/// The Adjust tab: the colour package's knobs for the selected clip.
in-out property <[AppliedParamData]> adjust-params;
@@ -299,6 +302,7 @@ export global Editor {
/// The transition riding into the selected clip; see VideoPanel.
callback transition-remove();
callback transition-duration-set(seconds: float);
+ callback transition-param-set(key: string, value: float);
// ── the timeline ──
in-out property <[TimelineTabData]> timeline-tabs;
diff --git a/src/crates/concat/ui/inspector/clip-inspector.slint b/src/crates/concat/ui/inspector/clip-inspector.slint
index 2176630e..22b0dd08 100644
--- a/src/crates/concat/ui/inspector/clip-inspector.slint
+++ b/src/crates/concat/ui/inspector/clip-inspector.slint
@@ -157,6 +157,17 @@ export struct AppliedParamData {
next: bool,
}
+/// One knob of a transition that is a choice among a few - Push's
+/// direction - drawn as segments: a direction is picked, not dialled.
+export struct TransitionChoiceData {
+ key: string,
+ label: string,
+ options: [string],
+ /// The value each option stores, in the same order.
+ values: [float],
+ current: int,
+}
+
/// One colour knob of one link - a key's screen colour - drawn as a swatch
/// that opens the picker, with the hex beside it.
export struct ColourKnobData {
@@ -2075,12 +2086,17 @@ export component EnhancePanel inherits VerticalLayout {
/// clips rather than to either of them.
export component TransitionPanel inherits VerticalLayout {
in property <SelectedTransitionData> transition;
+ /// The package's own knobs, numbers and choices, as set on this cut.
+ in property <[AppliedParamData]> knobs;
+ in property <[TransitionChoiceData]> choices;
/// Taken off, leaving a plain cut.
callback remove();
/// Set to a new length - clamped as applying one is, so this can never
/// ask for more than the cut can give it.
callback duration-set(seconds: float);
+ /// One of the package's knobs moved.
+ callback param-set(key: string, value: float);
property <float> duration;
@@ -2142,6 +2158,43 @@ export component TransitionPanel inherits VerticalLayout {
fmt: ParamFormat.seconds2;
changed(v) => { root.duration-set(v); }
}
+
+ for choice in root.choices: VerticalLayout {
+ padding-left: Theme.pad;
+ padding-right: Theme.pad;
+ padding-top: 4px;
+ padding-bottom: 4px;
+ spacing: 4px;
+
+ Text {
+ text: choice.label;
+ color: Theme.fg-muted;
+ font-size: Theme.fs-sm;
+ }
+ SegmentedControl {
+ options: choice.options;
+ current: choice.current;
+ changed(index) => { root.param-set(choice.key, choice.values[index]); }
+ }
+ }
+
+ for p in root.knobs: Rectangle {
+ property <AppliedParamData> data: p;
+ height: knob.preferred-height;
+ changed data => { knob.value = self.data.value; }
+
+ knob := Param {
+ unit: p.unit;
+ label: p.label;
+ value: p.value;
+ minimum: p.min;
+ maximum: p.max;
+ step: p.step;
+ default-value: p.default-value;
+ fmt: p.fmt;
+ changed(v) => { root.param-set(p.key, v); }
+ }
+ }
}
}
}
diff --git a/src/crates/concat/ui/workspace/config-pane.slint b/src/crates/concat/ui/workspace/config-pane.slint
index 5bad0e68..1d713d71 100644
--- a/src/crates/concat/ui/workspace/config-pane.slint
+++ b/src/crates/concat/ui/workspace/config-pane.slint
@@ -9,6 +9,7 @@ import { PaneKind, PaneSwitcher } from "pane-switcher.slint";
import { EffectData } from "../demo/effects-panel.slint";
import {
AdjustPanel, AppliedEntryData, AppliedParamData, AudioPanel, BackgroundRows, ProcessorRows,
+ TransitionChoiceData,
CatalogueEntryData, ColourKnobData, EnhancePanel, FilterPanel, PresetStack, SpeedPanel,
TransitionPanel, VideoPanel,
} from "../inspector/clip-inspector.slint";
@@ -113,6 +114,8 @@ export component ConfigPane inherits Rectangle {
property <bool> has-selection: root.selected.present;
/// The transition selected on its own on the lanes, when no clip is.
in property <SelectedTransitionData> transition;
+ in property <[AppliedParamData]> transition-knobs;
+ in property <[TransitionChoiceData]> transition-choices;
property <bool> on-transition: root.transition.present && !root.has-selection;
in property <string> project-name: I18n.t("common.untitledProject");
in property <string> project-folder: "—";
@@ -211,6 +214,7 @@ export component ConfigPane inherits Rectangle {
callback clip-enhance-run();
callback transition-remove();
callback transition-duration-set(seconds: float);
+ callback transition-param-set(key: string, value: float);
// The tab strip follows the selection, and stays short: three tabs at
@@ -521,6 +525,9 @@ export component ConfigPane inherits Rectangle {
PaneScroll {
TransitionPanel {
transition: root.transition;
+ knobs: root.transition-knobs;
+ choices: root.transition-choices;
+ param-set(key, value) => { root.transition-param-set(key, value); }
remove => { root.transition-remove(); }
duration-set(seconds) => { root.transition-duration-set(seconds); }
}
diff --git a/src/crates/concat/ui/workspace/seat.slint b/src/crates/concat/ui/workspace/seat.slint
index b8ae930e..c0d13e61 100644
--- a/src/crates/concat/ui/workspace/seat.slint
+++ b/src/crates/concat/ui/workspace/seat.slint
@@ -280,6 +280,7 @@ export component Seat inherits Rectangle {
clip-enhance-run => { Editor.clip-enhance-run(); }
transition-remove => { Editor.transition-remove(); }
transition-duration-set(seconds) => { Editor.transition-duration-set(seconds); }
+ transition-param-set(key, value) => { Editor.transition-param-set(key, value); }
project-name: Editor.project-name;
project-folder: Editor.project-folder;
@@ -294,6 +295,8 @@ export component Seat inherits Rectangle {
selected: Editor.selected-clip;
transition: Editor.selected-transition;
+ transition-knobs: Editor.transition-knobs;
+ transition-choices: Editor.transition-choices;
clip-set(field, value) => { Editor.clip-set(field, value); }
clip-set-text(field, value) => { Editor.clip-set-text(field, value); }
clip-set-colour(field, value) => { Editor.clip-set-colour(field, value); }