Skip to content

Open source CapCut alternative.

TypeScript

feat(site): the Effects tab has a Sound family

David Lea5e51b0d14ee
diff --git a/site/src/cut/components/EffectsPanel.tsx b/site/src/cut/components/EffectsPanel.tsx
index aca232d8..678442a0 100644
--- a/site/src/cut/components/EffectsPanel.tsx
+++ b/site/src/cut/components/EffectsPanel.tsx
@@ -2,10 +2,12 @@
import { useEffect, useRef, useState } from "react";
import {
- EFFECT_IDS,
+ ALL_EFFECT_IDS,
+ audioFxBars,
EFFECT_LABELS,
effectPreviewState,
grainTileUrl,
+ isAudioEffect,
LEAK_TINT,
leakGradient,
streakGradient,
@@ -23,13 +25,18 @@ import { ScrollArea } from "@/components/ui/scroll-area";
import "./grain.css";
/**
- * The Effects tab: time-ranged treatments over the finished picture — the
- * footage and everything laid over it. A segmented toggle splits the grid
- * into two families: Moving, the effects that play over their stretch of
- * timeline (zoom, grain, VHS, glitch, light leak, flash, shake), and
- * Filters, the still treatments and graded looks (blur, vignette, vintage,
- * noir, halation…). Drag one onto the timeline to place it; a click only
- * picks the tile, the same as every other panel.
+ * The Effects tab: time-ranged treatments over the finished cut. A segmented
+ * toggle splits the grid into three families: Moving, the effects that play
+ * over their stretch of timeline (zoom, grain, VHS, glitch, light leak, flash,
+ * shake), Filters, the still treatments and graded looks (blur, vignette,
+ * vintage, noir, halation…), and Sound, the treatments over the audio under
+ * the window (echo, reverb, muffle, telephone…). Drag one onto the timeline
+ * to place it; a click only picks the tile, the same as every other panel.
+ *
+ * The picture effects treat the footage and everything laid over it; the audio
+ * ones treat everything audible under them — clip sound, upper tracks and the
+ * soundtrack, mixed. A cut's own crossfade at a join stays where it belongs,
+ * on the transition bar.
*
* Select an effect on the timeline and the tab follows it: its family opens,
* its tile is the marked one, and a click on another tile changes that
@@ -37,16 +44,20 @@ import "./grain.css";
* it retunes what is already there, and with nothing selected it just picks.
*/
-type EffectGroup = "moving" | "filters";
+type EffectGroup = "moving" | "filters" | "audio";
const GROUPS = [
{ id: "moving", label: "Moving" },
{ id: "filters", label: "Filters" },
+ // "Sound", because the rail's own Audio tab is where music and voiceover
+ // live; this family is the treatments over whatever is already audible.
+ { id: "audio", label: "Sound" },
] as const;
const MOVING: EffectId[] = ["zoom", "grain", "vhs", "glitch", "lightleak", "flash", "shake"];
-const groupOf = (id: EffectId): EffectGroup => (MOVING.includes(id) ? "moving" : "filters");
+const groupOf = (id: EffectId): EffectGroup =>
+ isAudioEffect(id) ? "audio" : MOVING.includes(id) ? "moving" : "filters";
export function EffectsPanel() {
const live = useEditor((s) => {
@@ -76,7 +87,7 @@ export function EffectsPanel() {
cut off there. */}
<ScrollArea className="min-h-0 flex-1" contentClassName="px-3.5 pt-1 pb-4">
<div className="grid grid-cols-2 gap-2" onKeyDown={pickGridNav}>
- {EFFECT_IDS.filter((id) => groupOf(id) === group).map((id) => (
+ {ALL_EFFECT_IDS.filter((id) => groupOf(id) === group).map((id) => (
<EffectTile key={id} id={id} live={live} frame={frame} />
))}
</div>
@@ -100,11 +111,12 @@ function EffectTile({
}) {
const { picked, pick } = useAssetPick(`effect:${id}`);
const [hover, setHover] = useState(false);
- // A moving effect's whole point is its motion, so its swatch always plays;
- // a filter swatch stands still until the pointer asks it to run. The leak's
- // motion is a slow continuous wander — the shared 1.4s loop samples a sliver
- // of it and snaps back, so its clock never wraps and the bloom just roams.
- const t = useSwatchClock(hover || groupOf(id) === "moving", id === "lightleak" ? Infinity : LOOP_S);
+ // A moving effect's whole point is its motion, so its swatch always plays,
+ // and an audio figure is motion by nature; a filter swatch stands still
+ // until the pointer asks it to run. The leak's motion is a slow continuous
+ // wander — the shared 1.4s loop samples a sliver of it and snaps back, so
+ // its clock never wraps and the bloom just roams.
+ const t = useSwatchClock(hover || groupOf(id) !== "filters", id === "lightleak" ? Infinity : LOOP_S);
const ref = useRef<HTMLButtonElement>(null);
// What the selection means for this tile: it wears the ring when it is the
// selected element's effect, and a click swaps that element onto it.
@@ -139,12 +151,20 @@ function EffectTile({
// ring is the focus indicator; the browser outline stays off.
className="flex scroll-m-2 flex-col gap-1.5 text-[11px] font-medium text-muted-foreground outline-none transition-colors hover:text-foreground"
>
- <EffectSwatch
- id={id}
- t={t}
- frame={frame}
- className={cn("w-full rounded-lg border border-border", marked && PICKED_RING)}
- />
+ {isAudioEffect(id) ? (
+ <AudioSwatch
+ id={id}
+ t={t}
+ className={cn("w-full rounded-lg border border-border", marked && PICKED_RING)}
+ />
+ ) : (
+ <EffectSwatch
+ id={id}
+ t={t}
+ frame={frame}
+ className={cn("w-full rounded-lg border border-border", marked && PICKED_RING)}
+ />
+ )}
<span className="leading-none">{EFFECT_LABELS[id]}</span>
</button>
);
@@ -256,6 +276,53 @@ export function SwatchScene({
);
}
+/**
+ * What an audio effect does to the sound: the bar figure its recipe shapes,
+ * rolling on the shared swatch clock.
+ *
+ * The figure comes off the same recipe the mix is built from — a delay tap
+ * shows as its repeat, a low pass rounds the bars off, a wobble swings them —
+ * so a tile can only show what the effect actually does.
+ */
+export function AudioSwatch({
+ id,
+ t = SWATCH_T,
+ className,
+}: {
+ id: EffectId;
+ t?: number;
+ className?: string;
+}) {
+ const bars = audioFxBars(id, t, undefined, 0.9);
+ const w = 100 / (bars.length * 1.7);
+ return (
+ <span
+ data-drag-object
+ className={cn(
+ "relative block aspect-square overflow-hidden rounded-md bg-neutral-900",
+ className
+ )}
+ >
+ <svg viewBox="0 0 100 100" aria-hidden className="absolute inset-0 size-full">
+ {bars.map((v, i) => {
+ const h = Math.max(w, v * 76);
+ return (
+ <rect
+ key={i}
+ x={((i + 0.5) / bars.length) * 100 - w / 2}
+ y={50 - h / 2}
+ width={w}
+ height={h}
+ rx={w / 2}
+ className="fill-white/85"
+ />
+ );
+ })}
+ </svg>
+ </span>
+ );
+}
+
/** What an effect does to the picture: the same preview state the canvas pass
* reads, applied over the swatch scene. */
export function EffectSwatch({
diff --git a/site/src/cut/components/StageEffects.tsx b/site/src/cut/components/StageEffects.tsx
index 3fb1ea71..60e9005f 100644
--- a/site/src/cut/components/StageEffects.tsx
+++ b/site/src/cut/components/StageEffects.tsx
@@ -3,6 +3,7 @@
import { useEffect, useMemo, useRef } from "react";
import {
grainTileUrl,
+ isAudioEffect,
LEAK_TINT,
leakGradient,
streakGradient,
@@ -87,13 +88,18 @@ export function StagePictureFx({ children }: { children: React.ReactNode }) {
);
}
-/** The lanes effects sit on, whether or not one is live right now. The stage
- * splits on these, so its slices stay put while the playhead moves and only
- * change when a row does. */
+/** The lanes picture effects sit on, whether or not one is live right now. The
+ * stage splits on these, so its slices stay put while the playhead moves and
+ * only change when a row does. An audio effect treats the mix, so its row
+ * splits nothing. */
export function useEffectLanes(): number[] {
const overlays = useEditor((s) => s.overlays);
return useMemo(
- () => [...new Set(overlays.filter(isEffectOverlay).map(laneOf))].sort((a, b) => a - b),
+ () => [
+ ...new Set(
+ overlays.filter((o) => isEffectOverlay(o) && !isAudioEffect(o.effect)).map(laneOf)
+ ),
+ ].sort((a, b) => a - b),
[overlays]
);
}
diff --git a/site/src/cut/components/SubTabs.tsx b/site/src/cut/components/SubTabs.tsx
index f542138f..374cddcb 100644
--- a/site/src/cut/components/SubTabs.tsx
+++ b/site/src/cut/components/SubTabs.tsx
@@ -3,7 +3,7 @@
import { cn } from "@/lib/utils";
/** The segmented sub-tab toggle at the top of a side-panel tab — Voice/Music
- * on Audio, Moving/Filters on Effects, Stickers/Shapes on Elements. */
+ * on Audio, Moving/Filters/Audio on Effects, Stickers/Shapes on Elements. */
export function SubTabs<T extends string>({
tabs,
value,
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsx
index bfb3bff1..48b83a32 100644
--- a/site/src/cut/components/Timeline.tsx
+++ b/site/src/cut/components/Timeline.tsx
@@ -50,7 +50,7 @@ import type { VideoTrackPlacement } from "@/cut/lib/store";
import { playheadAt, setSkim, skimAt, subscribePlayhead, usePlayhead, useSkim } from "@/cut/lib/playhead";
import { laneHidden, subtitleLaneCount } from "@/cut/lib/subtitles";
import { formatTime, formatTimecode } from "@/cut/lib/time";
-import { EFFECT_LABELS } from "@donkeycut/effects-kit";
+import { EFFECT_LABELS, isAudioEffect, type EffectId } from "@donkeycut/effects-kit";
import { emptySubtitles, IMAGE_CLIP_SECONDS, SHAPE_LABELS, TRANSITION_DEFAULT_SECONDS, TRANSITION_MAX, TRANSITION_STYLE_LABELS, type ShapeKind } from "@/cut/lib/types";
import type { AudioClip, ClipSpan, ColorGrade, MediaAsset, Overlay, Selection, StickerOverlay, SubtitleCue, TimelineTransition, TransitionStyle, VideoClip } from "@/cut/lib/types";
import { isLottieAsset } from "@/cut/lib/lottieAssets";
@@ -231,6 +231,13 @@ const XBAR_MAGNET_PX = 16;
const overlayFamily = (o: Overlay): OverlayFamily =>
o.kind === "effect" ? "effect" : o.kind === "shape" || o.kind === "sticker" ? "element" : "text";
+/** The glyph on an effect's bar: a waveform for the treatments that work on
+ * the sound, sparkles for the ones that work on the picture. */
+function EffectChipIcon({ effect }: { effect: EffectId }) {
+ const Icon = isAudioEffect(effect) ? AudioLines : Sparkles;
+ return <Icon className="mr-1 size-2.5 shrink-0" />;
+}
+
/** The stretch a panel element takes when dropped — `addElement`'s default
* length — so the landing ghost matches what the drop makes. */
const ELEMENT_DROP_SECONDS = 3;
@@ -2182,7 +2189,7 @@ export function Timeline() {
</>
) : el?.kind === "effect" ? (
<>
- <Sparkles className="mr-1 size-2.5 shrink-0" />
+ <EffectChipIcon effect={el.effect} />
{EFFECT_LABELS[el.effect]}
</>
) : (
@@ -4695,7 +4702,7 @@ function TextBar({
</>
) : o.kind === "effect" ? (
<>
- <Sparkles className="mr-1 size-2.5 shrink-0" />
+ <EffectChipIcon effect={o.effect} />
{EFFECT_LABELS[o.effect]}
</>
) : (
diff --git a/site/src/cut/lib/effectStack.ts b/site/src/cut/lib/effectStack.ts
index b2a9f3f0..60919efd 100644
--- a/site/src/cut/lib/effectStack.ts
+++ b/site/src/cut/lib/effectStack.ts
@@ -11,7 +11,7 @@
* The math is here, apart from React, because both exports walk the same stack.
*/
-import { effectPreviewState, type EffectPreviewState } from "@donkeycut/effects-kit";
+import { effectPreviewState, isAudioEffect, type EffectPreviewState } from "@donkeycut/effects-kit";
import { isEffectOverlay, laneOf, type Overlay } from "./types";
/** One effect live at a moment, with the lane that places it in the stack. */
@@ -24,7 +24,8 @@ export interface LiveEffect {
export function liveEffectsAt(overlays: Overlay[], t: number): LiveEffect[] {
const live: LiveEffect[] = [];
for (const o of overlays) {
- if (!isEffectOverlay(o) || o.hidden || t < o.start || t > o.end) continue;
+ if (!isEffectOverlay(o) || isAudioEffect(o.effect)) continue;
+ if (o.hidden || t < o.start || t > o.end) continue;
live.push({
lane: laneOf(o),
state: effectPreviewState(o.effect, o.amount, t - o.start, o.focus, o.ramp, o.end - o.start),
@@ -34,8 +35,10 @@ export function liveEffectsAt(overlays: Overlay[], t: number): LiveEffect[] {
}
/** Whether any effect could be live at all. The stage asks before doing the
- * per-frame work of finding out which ones are. */
-export const hasEffects = (overlays: Overlay[]) => overlays.some(isEffectOverlay);
+ * per-frame work of finding out which ones are; the audio ones treat the mix
+ * rather than the picture, so they never build a slice. */
+export const hasEffects = (overlays: Overlay[]) =>
+ overlays.some((o) => isEffectOverlay(o) && !isAudioEffect(o.effect));
/** How the content under an effect moves: a zoom's push in, a shake, and the
* horizontal jump that reads as tearing. Empty for the effects that only