Skip to content

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

fix: resolve GitHub issues #177, #111/#99, #156, #102 and shader singularities

maubrickastuto1ec267a5ecf6
diff --git a/scripts/models.py b/scripts/models.py
index 3fa4bea0..053a554f 100755
--- a/scripts/models.py
+++ b/scripts/models.py
@@ -13,13 +13,21 @@ says what they are and where they come from; this script is what fills the
mirror from upstream, and what turns the table into the manifest.json every
release ships beside its bundles. See that file for the shape of a row.
"""
+from __future__ import annotations
+
import argparse
import hashlib
import json
import pathlib
import re
import sys
-import tomllib
+try:
+ import tomllib
+except ModuleNotFoundError:
+ try:
+ import tomli as tomllib
+ except ModuleNotFoundError:
+ tomllib = None
import urllib.request
ROOT = pathlib.Path(__file__).resolve().parent.parent
@@ -64,7 +72,34 @@ BUNDLES = [
def table() -> dict:
- return tomllib.loads(MANIFEST.read_text(encoding="utf-8"))
+ text = MANIFEST.read_text(encoding="utf-8")
+ if tomllib is not None:
+ return tomllib.loads(text)
+ data: dict = {"model": []}
+ current: dict | None = None
+ for line in text.splitlines():
+ line = line.strip()
+ if not line or line.startswith("#"):
+ continue
+ if line == "[[model]]":
+ current = {}
+ data["model"].append(current)
+ continue
+ if "=" in line:
+ k, v = line.split("=", 1)
+ k = k.strip()
+ v = v.strip()
+ if v.startswith('"') and v.endswith('"'):
+ val = v[1:-1]
+ elif v.isdigit():
+ val = int(v)
+ else:
+ val = v
+ if current is not None:
+ current[k] = val
+ else:
+ data[k] = val
+ return data
def hf_mirror(url: str) -> str | None:
@@ -160,7 +195,7 @@ def check() -> int:
# against a digest nothing was mirrored under can never pass.
for family, path in TABLES.items():
rows = [model for model in models if model.get("family") == family]
- text = path.read_text(encoding="utf-8").split("#[cfg(test)]")[0]
+ text = re.split(r'\n(?:#\[cfg\(test\)\]\s*)?mod tests?\s*\{', path.read_text(encoding="utf-8"))[0]
ids = set(re.findall(r'^\s*(?:pub )?id: "([^"]+)"', text, re.M))
if family == "cutout":
ids = set(re.findall(r'^\s*file: "([^"]+)"', text, re.M))
diff --git a/src/crates/concat-effects/packages/concat.film-reel/effect.wgsl b/src/crates/concat-effects/packages/concat.film-reel/effect.wgsl
index f9e2f7d3..68d77eec 100644
--- a/src/crates/concat-effects/packages/concat.film-reel/effect.wgsl
+++ b/src/crates/concat-effects/packages/concat.film-reel/effect.wgsl
@@ -28,17 +28,16 @@ fn effect(uv: vec2<f32>) -> vec4<f32> {
let cross_x = smoothstep(0.002, 0.0, abs(uv.x - 0.5)) * step(r, 0.3);
let cross_y = smoothstep(0.002, 0.0, abs(uv.y - 0.5)) * step(r, 0.3);
let angle = (atan2(d.y, d.x) + 3.14159) / 6.28318;
- let sweep = fract(frame.time);
- let arm = smoothstep(0.01, 0.0, abs(angle - sweep)) * step(r, 0.28);
- let reticle = max(max(outer_ring, inner_ring), max(cross_x, cross_y)) + arm;
-
- let sec = i32(frame.time) % 4;
- var num = 0.0;
- if (sec < 3) {
+ var leader = 0.0;
+ if (frame.clip_time < 3.0) {
+ let sweep = fract(frame.clip_time);
+ let arm = smoothstep(0.01, 0.0, abs(angle - sweep)) * step(r, 0.28);
+ let reticle = max(max(outer_ring, inner_ring), max(cross_x, cross_y)) + arm;
+ let sec = i32(frame.clip_time);
let num_p = (uv - vec2<f32>(0.485, 0.46)) / vec2<f32>(0.01, 0.016);
- num = draw_digit(num_p, 3 - sec);
+ let num = draw_digit(num_p, 3 - sec);
+ leader = clamp(reticle + num, 0.0, 1.0);
}
- let leader = clamp(reticle + num, 0.0, 1.0);
col = mix(col, vec3<f32>(0.92, 0.88, 0.75), leader * 0.75);
return vec4<f32>(clamp01(col + vec3<f32>(grain_val)), c.a);
diff --git a/src/crates/concat-effects/packages/concat.fisheye/effect.wgsl b/src/crates/concat-effects/packages/concat.fisheye/effect.wgsl
index dea7f53c..ff89de46 100644
--- a/src/crates/concat-effects/packages/concat.fisheye/effect.wgsl
+++ b/src/crates/concat-effects/packages/concat.fisheye/effect.wgsl
@@ -6,7 +6,8 @@ fn effect(uv: vec2<f32>) -> vec4<f32> {
let aspect = frame.size.x / frame.size.y;
var p = (uv - vec2<f32>(0.5)) * vec2<f32>(2.0 * aspect, 2.0);
let r2 = dot(p, p);
- p = p * (1.0 - k * r2) / (1.0 - k * (aspect * aspect + 1.0) * 0.5);
+ let denom = max(1.0 - k * (aspect * aspect + 1.0) * 0.5, 0.05);
+ p = p * (1.0 - k * r2) / denom;
let q = p / vec2<f32>(2.0 * aspect, 2.0) + vec2<f32>(0.5);
if (q.x < 0.0 || q.x > 1.0 || q.y < 0.0 || q.y > 1.0) {
return vec4<f32>(0.0, 0.0, 0.0, 0.0);
diff --git a/src/crates/concat-speech/src/chatterbox.rs b/src/crates/concat-speech/src/chatterbox.rs
index c5a34700..d28ffbd1 100644
--- a/src/crates/concat-speech/src/chatterbox.rs
+++ b/src/crates/concat-speech/src/chatterbox.rs
@@ -72,10 +72,6 @@ struct KnownModel {
sha256: &'static str,
}
-/// Where every file comes from; the test holds the table to it.
-#[cfg(test)]
-const UPSTREAM: &str = "https://huggingface.co/ResembleAI/chatterbox-turbo-ONNX/resolve/main/";
-
/// The nine files, largest last so a torn download costs the least.
const FILES: &[KnownModel] = &[
KnownModel {
@@ -629,6 +625,9 @@ pub fn bundle_dir(models: &Path) -> PathBuf {
mod tests {
use super::*;
+ const UPSTREAM: &str =
+ "https://huggingface.co/ResembleAI/chatterbox-turbo-ONNX/resolve/main/";
+
#[test]
fn the_table_names_nine_distinct_files_with_the_bundle_in_front() {
assert_eq!(FILES.len(), 9);
diff --git a/src/crates/concat/src/panes/timeline.rs b/src/crates/concat/src/panes/timeline.rs
index 1cfebd15..bc3442a3 100644
--- a/src/crates/concat/src/panes/timeline.rs
+++ b/src/crates/concat/src/panes/timeline.rs
@@ -123,7 +123,14 @@ impl TimelinePane {
studio.prefs.save(&studio.host.dirs);
}
TimelineMsg::Scrolled(seconds) => self.scroll_left = seconds.max(0.0),
- TimelineMsg::Zoomed { factor, anchor } => self.zoom(factor, anchor),
+ TimelineMsg::Zoomed { factor, anchor } => {
+ let anchor = if anchor < 0.0 {
+ self.default_anchor(studio)
+ } else {
+ anchor
+ };
+ self.zoom(factor, anchor);
+ }
TimelineMsg::ZoomToFit(width) => {
let span = studio.duration().max(1.0) * 1.05;
if width > 1.0 {
@@ -131,8 +138,14 @@ impl TimelinePane {
self.scroll_left = 0.0;
}
}
- TimelineMsg::ZoomIn => self.zoom(1.0 / ZOOM_STEP, -1.0),
- TimelineMsg::ZoomOut => self.zoom(ZOOM_STEP, -1.0),
+ TimelineMsg::ZoomIn => {
+ let anchor = self.default_anchor(studio);
+ self.zoom(1.0 / ZOOM_STEP, anchor);
+ }
+ TimelineMsg::ZoomOut => {
+ let anchor = self.default_anchor(studio);
+ self.zoom(ZOOM_STEP, anchor);
+ }
TimelineMsg::Resized(width) => self.width = width.max(0.0),
TimelineMsg::Reset => {
self.scroll_left = 0.0;
@@ -141,6 +154,21 @@ impl TimelinePane {
}
}
+ /// The anchor point for a zoom that has no pointer position (e.g. keyboard
+ /// shortcut or tray buttons): the playhead if on screen, else the center of
+ /// the visible timeline.
+ fn default_anchor(&self, studio: &Studio) -> f32 {
+ let playhead = f64::from(studio.playhead) as f32;
+ let screen = self.width * self.seconds_per_pixel;
+ if screen > 0.0 && (self.scroll_left..=self.scroll_left + screen).contains(&playhead) {
+ playhead
+ } else if screen > 0.0 {
+ self.scroll_left + screen / 2.0
+ } else {
+ playhead.max(0.0)
+ }
+ }
+
/// Zooms by a factor about an instant, so the instant under the pointer
/// stays under it; an anchor below zero holds the left edge instead.
fn zoom(&mut self, factor: f32, anchor: f32) {
diff --git a/src/crates/concat/ui/timeline/lanes.slint b/src/crates/concat/ui/timeline/lanes.slint
index 990832f2..f2ab6db5 100644
--- a/src/crates/concat/ui/timeline/lanes.slint
+++ b/src/crates/concat/ui/timeline/lanes.slint
@@ -123,6 +123,7 @@ component Ramps inherits Rectangle {
component Clip inherits Rectangle {
in property <ClipData> item;
in property <length> px-per-second;
+ in property <length> viewport-width: 1920px;
in property <TimelineTool> tool;
/// how close to an edge counts as grabbing it
in property <length> edge-grab: 6px;
@@ -285,7 +286,16 @@ component Clip inherits Rectangle {
property <length> tile-w: Math.max(4px,
self.height * root.item.strip.frame-width / Math.max(1, root.item.strip.height));
- property <int> tiles: Math.min(400, Math.ceil(parent.width / self.tile-w));
+
+ // Window tiles to the visible screen area so zooming in never leaves
+ // all tiles off-screen to the left (fixes #156):
+ property <length> vis-start: Math.min(root.width, Math.max(0px, -root.x));
+ property <length> vis-end: Math.max(0px, Math.min(root.width, -root.x + root.viewport-width));
+ property <int> first-tile: Math.max(0, Math.floor(self.vis-start / self.tile-w));
+ property <int> total-tiles: Math.max(1, Math.ceil(root.width / self.tile-w));
+ property <int> tiles: self.vis-end <= self.vis-start ? 0
+ : Math.max(0, Math.min(Math.min(120, self.total-tiles - self.first-tile),
+ Math.ceil((self.vis-end - self.vis-start) / self.tile-w) + 1));
/// The fraction of the clip under the middle of tile `i`'s
/// visible part.
@@ -294,8 +304,8 @@ component Clip inherits Rectangle {
/ 2 / Math.max(1px, self.width);
}
- for i in self.tiles: Image {
- x: i * parent.tile-w;
+ for j in self.tiles: Image {
+ x: (parent.first-tile + j) * parent.tile-w;
y: 0;
width: parent.tile-w;
height: parent.height;
@@ -303,7 +313,7 @@ component Clip inherits Rectangle {
image-fit: fill;
source-clip-x: Math.clamp(
Math.floor(root.item.strip.frames
- * (root.item.strip.start + root.item.strip.span * parent.at(i))),
+ * (root.item.strip.start + root.item.strip.span * parent.at(parent.first-tile + j))),
0, root.item.strip.frames - 1) * root.item.strip.frame-width;
source-clip-y: 0;
source-clip-width: root.item.strip.frame-width;
@@ -1097,6 +1107,7 @@ export component Lanes inherits Rectangle {
item: entry;
px-per-second: root.px-per-second;
+ viewport-width: parent.width;
tool: root.tool;
// Read back through the lane the clip sits on rather than carried
// on the clip: locking is a property of the lane, and copying it
@@ -1342,7 +1353,7 @@ export component Lanes inherits Rectangle {
last-x = self.mouse-x;
}
if (event.kind == PointerEventKind.move && self.pressed) {
- let delta = last-x - self.mouse-x;
+ let delta = self.mouse-x - last-x;
root.scrolled(Math.max(0.0, root.scroll-left - delta / root.px-per-second));
last-x = self.mouse-x;
}
diff --git a/src/crates/concat/ui/title-bar.slint b/src/crates/concat/ui/title-bar.slint
index 79230eda..e629f60c 100644
--- a/src/crates/concat/ui/title-bar.slint
+++ b/src/crates/concat/ui/title-bar.slint
@@ -141,6 +141,10 @@ export component TitleBar inherits Rectangle {
height: 32px;
background: Theme.panel;
+ property <bool> drag-armed: false;
+ property <length> press-x: 0px;
+ property <length> press-y: 0px;
+
// Whatever is not a control drags the window. Declared first so every
// control sits above it and takes its own presses; Texts and plain
// Rectangles are not hit targets, so presses on them fall through here.
@@ -148,10 +152,25 @@ export component TitleBar inherits Rectangle {
pointer-event(event) => {
if (event.kind == PointerEventKind.down
&& event.button == PointerEventButton.left) {
- root.begin-drag();
+ root.drag-armed = true;
+ root.press-x = self.mouse-x;
+ root.press-y = self.mouse-y;
+ } else if (event.kind == PointerEventKind.up
+ || event.kind == PointerEventKind.cancel) {
+ root.drag-armed = false;
+ }
+ }
+ moved => {
+ if (root.drag-armed && self.pressed) {
+ if (Math.abs(self.mouse-x - root.press-x) > 4px
+ || Math.abs(self.mouse-y - root.press-y) > 4px) {
+ root.drag-armed = false;
+ root.begin-drag();
+ }
}
}
double-clicked => {
+ root.drag-armed = false;
root.toggle-maximize();
}
}