Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ same time.
**Motion**

- Keyframe animation on ~25 properties with easing
- **Keyframe markers on clips** — diamonds on the clip body at each unique
keyframe time (tooltip lists channels; a count badge when several share a
time). <kbd>Ctrl/Cmd+←</kbd> / <kbd>Ctrl/Cmd+→</kbd> jumps the playhead to
the previous / next keyframe (selected clips first, else clips under the
playhead)
- **Keyframe graphs** — toggle a property’s curve in the inspector to show an
interpolated value graph beside the program monitor; click the graph to seek
- **Speed ramps** — keyframe `speed` and the engine time-remaps video *and* the
export audio mix (the fast-into-slow-mo reel move)
- **Camera shake** and **RGB-split/chromatic aberration**, both animatable
Expand Down
288 changes: 281 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const state = {
binTab: "project", // project | elements | sfx | svg
disabledTracks: new Set(), // mirror of project.disabledTracks for fast lookup
transFocus: null, // "in" | "out" — inspector transition row highlighted
kfGraphs: new Set(), // animatable prop keys with open monitor graphs
};
function normalizeDisabledTracks(raw) {
if (raw == null) return [];
Expand Down Expand Up @@ -320,7 +321,7 @@ const els = {
projectName: $("projectName"), monitorRes: $("monitorRes"),
aspectSel: $("aspectSel"), btnGuides: $("btnGuides"), safeOverlay: $("safeOverlay"),
btnSpeed: $("btnSpeed"),
monitorStage: $("monitorStage"),
monitorStage: $("monitorStage"), kfGraphs: $("kfGraphs"),
exportSetup: $("exportSetup"), engineFast: $("engineFast"), engineRealtime: $("engineRealtime"),
};
const ctx2d = els.preview.getContext("2d");
Expand Down Expand Up @@ -2041,6 +2042,39 @@ function transitionMarksHtml(c, trackH) {
wedge(c.transitionOut, "out");
return html;
}
/* Group keyframes by clip-local time → [{ t, keys: ["opacity","scale"] }, …]. */
function clipKeyframeGroups(c) {
if (!c?.keyframes) return [];
const byT = new Map();
for (const [channel, arr] of Object.entries(c.keyframes)) {
if (!Array.isArray(arr)) continue;
for (const kf of arr) {
const t = +kf.t;
if (!Number.isFinite(t)) continue;
const key = t.toFixed(4);
let g = byT.get(key);
if (!g) { g = { t, keys: [] }; byT.set(key, g); }
if (!g.keys.includes(channel)) g.keys.push(channel);
}
}
return [...byT.values()].sort((a, b) => a.t - b.t);
}
const clipKeyframeLocalTimes = (c) => clipKeyframeGroups(c).map((g) => g.t);
/* Diamond marks on the clip body — one per unique time; count badge if multi-channel. */
function clipKeyframesHtml(c) {
const groups = clipKeyframeGroups(c);
if (!groups.length || !(c.duration > 0)) return "";
let html = `<div class="clip-kfs">`;
for (const { t, keys } of groups) {
if (t < -1e-6 || t > c.duration + 1e-6) continue;
const pct = Math.max(0, Math.min(100, (t / c.duration) * 100));
const label = keys.join(", ") + " @ " + fmt(c.start + t);
const badge = keys.length > 1 ? `<span class="clip-kf-n">${keys.length}</span>` : "";
const multi = keys.length > 1 ? " multi" : "";
html += `<div class="clip-kf${multi}" style="left:${pct}%" data-t="${t}" title="${label}">${badge}</div>`;
}
return html + `</div>`;
}
function rebuildClips() {
const w = contentWidth();
els.tracksContent.style.width = w + "px";
Expand Down Expand Up @@ -2073,6 +2107,7 @@ function rebuildClips() {
: (c.name || "");
body += `<div class="fade"></div>
<div class="clip-label">${badge}${escapeHtml(label)}</div>`;
body += clipKeyframesHtml(c);
let inner = `<div class="clip-body">${body}</div>`;
inner += transitionMarksHtml(c, tr.h);
inner += `<div class="handle l"></div><div class="handle r"></div>`;
Expand Down Expand Up @@ -2304,6 +2339,13 @@ els.tracksContent.addEventListener("pointerdown", (e) => {
}
const c = getClip(clipDiv.dataset.id);
if (!c) return;
const kfMark = e.target.closest(".clip-kf");
if (kfMark) {
e.preventDefault();
selectClip(c.id);
setTime(c.start + (+kfMark.dataset.t || 0));
return;
}
const transHandle = e.target.closest(".trans-dur-handle");
if (transHandle) {
const wrap = transHandle.closest(".trans-mark");
Expand Down Expand Up @@ -2551,6 +2593,47 @@ function setTime(t) {
if (state.audioHold) scheduleAudioHoldRefresh();
}

/* Absolute timeline times of every keyframe on the given clips (deduped). */
function keyframeTimelineTimes(clips) {
const seen = new Set();
const out = [];
for (const c of clips) {
for (const local of clipKeyframeLocalTimes(c)) {
const t = +(c.start + local).toFixed(4);
if (seen.has(t)) continue;
seen.add(t);
out.push(t);
}
}
out.sort((a, b) => a - b);
return out;
}
/* Jump playhead to previous (−1) or next (+1) keyframe.
Prefers selected clips; falls back to clips under the playhead.
Keyboard counterpart to Avid’s Ctrl/Cmd-click snap-to-audio-keyframe. */
function goToKeyframe(dir) {
let clips = state.selIds.size ? selectedClips() : [];
if (!clips.some((c) => clipKeyframeLocalTimes(c).length)) {
const t = state.time;
clips = project.clips.filter((c) =>
clipKeyframeLocalTimes(c).length &&
t >= c.start - 1e-6 && t <= c.start + c.duration + 1e-6);
}
const times = keyframeTimelineTimes(clips);
if (!times.length) { toast("No keyframes"); return; }
const eps = 0.5 / Math.max(1, project.fps || 30);
if (dir > 0) {
const next = times.find((t) => t > state.time + eps);
if (next == null) { toast("No next keyframe"); return; }
setTime(next);
} else {
let prev = null;
for (const t of times) if (t < state.time - eps) prev = t;
if (prev == null) { toast("No previous keyframe"); return; }
setTime(prev);
}
}

/* Add a marker at the playhead, or remove one already there (M key).
Works while playing — tap M on the beat to lay down a beat grid. */
function toggleMarker() {
Expand Down Expand Up @@ -2793,6 +2876,7 @@ function renderInspector(lite) {
const c = getClip(state.selId);
if (!c) {
els.inspector.innerHTML = `<div class="inspector-empty">Select a clip to edit its<br>transform, effects &amp; audio.</div>`;
renderKfGraphsPanel();
return;
}
if (lite) { // during gestures, just refresh timing numbers if present
Expand All @@ -2805,16 +2889,28 @@ function renderInspector(lite) {
const kfCount = (k) => (c.keyframes && c.keyframes[k] ? c.keyframes[k].length : 0);
const kfCtl = (k) => !ANIMATABLE.includes(k) ? "" :
`<span class="kf-ctl"><button class="kf-btn${kfCount(k) ? " has" : ""}" data-kf="${k}" title="Set keyframe at playhead">◆${kfCount(k) || ""}</button>${kfCount(k) ? `<button class="kf-btn" data-kfclear="${k}" title="Clear keyframes">✕</button>` : ""}</span>`;
/* reset: prop key(s) for Ctrl-click on the label; defaults to k when that key is in DEFAULT_PROPS. */
const row = (label, inner, k = "", reset) => {
/* Label carries two affordances that key off different click modifiers:
plain click toggles the keyframe graph (animatable props), Ctrl/Cmd-click
resets the prop(s). `reset` overrides which keys reset; defaults to k. */
const propLabel = (label, k = "", reset) => {
const keys = reset !== undefined ? reset : k;
const list = (Array.isArray(keys) ? keys : String(keys || "").split(",")).map((s) => s.trim()).filter(Boolean);
const canReset = list.some((rk) => Object.hasOwn(DEFAULT_PROPS, rk) || rk === "transIn" || rk === "transOut");
const lab = canReset
? `<label class="insp-reset" data-reset="${list.join(",")}" title="Ctrl-click to reset">${label}</label>`
: `<label>${label}</label>`;
return `<div class="insp-row">${lab}${inner}${k ? kfCtl(k) : ""}</div>`;
const isGraph = !!k && ANIMATABLE.includes(k);
if (!isGraph && !canReset) return `<label>${label}</label>`;
const cls = [
isGraph ? "kf-graph-toggle" : "",
isGraph && state.kfGraphs.has(k) ? "on" : "",
isGraph && kfCount(k) ? "has-kf" : "",
canReset ? "insp-reset" : "",
].filter(Boolean).join(" ");
const attrs = (isGraph ? ` data-kfgraph="${k}"` : "") + (canReset ? ` data-reset="${list.join(",")}"` : "");
const title = isGraph && canReset ? "Click: keyframe graph · Ctrl-click: reset"
: isGraph ? "Show / hide keyframe graph" : "Ctrl-click to reset";
return `<label class="${cls}"${attrs} title="${title}">${label}</label>`;
};
const row = (label, inner, k = "", reset) =>
`<div class="insp-row">${propLabel(label, k, reset)}${inner}${k ? kfCtl(k) : ""}</div>`;
const slider = (k, min, max, step, val, unit = "") =>
row(k[0].toUpperCase() + k.slice(1),
`<input type="range" data-k="${k}" min="${min}" max="${max}" step="${step}" value="${val}">
Expand Down Expand Up @@ -3090,6 +3186,179 @@ function renderInspector(lite) {
const row = els.inspector.querySelector(`[data-k="${k}"]`)?.closest(".insp-row");
row?.scrollIntoView({ block: "nearest", behavior: "smooth" });
}
els.inspector.querySelectorAll("[data-kfgraph]").forEach((lab) => {
lab.addEventListener("click", (e) => {
if (e.ctrlKey || e.metaKey) return; // Ctrl/Cmd-click is reserved for prop reset
e.preventDefault();
toggleKfGraph(lab.dataset.kfgraph);
});
});
renderKfGraphsPanel();
}

/* ── Keyframe graphs (program-monitor left gutter) ── */
const KF_GRAPH_LABEL = {
x: "Pos X", y: "Pos Y", scale: "Scale", rotation: "Rotation", opacity: "Opacity",
volume: "Volume", speed: "Speed", brightness: "Bright", contrast: "Contrast",
saturation: "Sat", hue: "Hue", blur: "Blur", grayscale: "Gray", sepia: "Sepia",
invert: "Invert", temperature: "Temp", tint: "Tint", vignette: "Vignette",
cornerRadius: "Radius", shake: "Shake", rgbSplit: "RGB", grain: "Grain",
fontSize: "Size", letterSpacing: "Track", glow: "Glow",
};
function toggleKfGraph(key) {
if (!ANIMATABLE.includes(key)) return;
if (state.kfGraphs.has(key)) state.kfGraphs.delete(key);
else state.kfGraphs.add(key);
renderInspector(); // refresh label .on state + panel
}
function renderKfGraphsPanel() {
const root = els.kfGraphs;
if (!root) return;
const c = getClip(state.selId);
const keys = [...state.kfGraphs].filter((k) => ANIMATABLE.includes(k));
if (!c || !keys.length) {
root.innerHTML = "";
root.hidden = true;
return;
}
root.hidden = false;
root.innerHTML = keys.map((k) => {
const label = KF_GRAPH_LABEL[k] || k;
return `<div class="kf-graph" data-kfgraph-card="${k}">
<div class="kf-graph-head"><span>${label}</span>
<button type="button" data-kfgraph-close="${k}" title="Close graph">✕</button></div>
<canvas width="160" height="52"></canvas>
</div>`;
}).join("");
root.querySelectorAll("[data-kfgraph-close]").forEach((btn) => {
btn.addEventListener("click", (e) => {
e.stopPropagation();
state.kfGraphs.delete(btn.dataset.kfgraphClose);
renderInspector();
});
});
root.querySelectorAll(".kf-graph canvas").forEach((cv) => {
const key = cv.closest("[data-kfgraph-card]")?.dataset.kfgraphCard;
cv.addEventListener("pointerdown", (e) => seekKfGraph(e, cv, key));
});
updateKfGraphs();
}
function seekKfGraph(e, cv, key) {
const c = getClip(state.selId);
if (!c || !key) return;
const { t0, t1 } = kfGraphRange(c, key);
const rect = cv.getBoundingClientRect();
const u = clamp((e.clientX - rect.left) / Math.max(1, rect.width), 0, 1);
setTime(c.start + t0 + u * Math.max(1e-6, t1 - t0));
updateKfGraphs();
}
/* Value + time window for a graph. When keyframes exist, zoom X to their span
(with padding) instead of the full clip duration. */
function kfGraphRange(c, key) {
const fallback = +(c.props?.[key] ?? DEFAULT_PROPS[key] ?? 0);
const dur = Math.max(MIN_DUR, c.duration);
const kfs = Array.isArray(c.keyframes?.[key]) ? c.keyframes[key] : [];
const vals = kfs.length ? kfs.map((kf) => +kf.v) : [fallback];
let lo = Math.min(...vals), hi = Math.max(...vals);
if (!isFinite(lo) || !isFinite(hi)) { lo = 0; hi = 1; }
if (Math.abs(hi - lo) < 1e-6) {
const pad = Math.max(0.05, Math.abs(lo) * 0.1 || 0.5);
lo -= pad; hi += pad;
} else {
const pad = (hi - lo) * 0.12;
lo -= pad; hi += pad;
}

let t0 = 0, t1 = dur;
if (kfs.length === 1) {
const t = clamp(+kfs[0].t || 0, 0, dur);
const half = Math.max(0.15, dur * 0.08);
t0 = Math.max(0, t - half);
t1 = Math.min(dur, t + half);
} else if (kfs.length >= 2) {
const ts = kfs.map((kf) => +kf.t || 0);
const a = Math.min(...ts), b = Math.max(...ts);
const pad = Math.max(0.05, (b - a) * 0.1, dur * 0.02);
t0 = Math.max(0, a - pad);
t1 = Math.min(dur, b + pad);
}
if (t1 - t0 < 1e-3) { t0 = 0; t1 = dur; }
return { lo, hi, fallback, t0, t1, dur };
}
function updateKfGraphs() {
const root = els.kfGraphs;
if (!root || root.hidden) return;
const c = getClip(state.selId);
if (!c) return;
root.querySelectorAll(".kf-graph").forEach((card) => {
const key = card.dataset.kfgraphCard;
const cv = card.querySelector("canvas");
if (key && cv) drawKfGraph(cv, c, key);
});
}
function drawKfGraph(cv, c, key) {
const dpr = window.devicePixelRatio || 1;
const cssW = cv.clientWidth || 160, cssH = cv.clientHeight || 52;
if (cv.width !== Math.round(cssW * dpr) || cv.height !== Math.round(cssH * dpr)) {
cv.width = Math.round(cssW * dpr);
cv.height = Math.round(cssH * dpr);
}
const g = cv.getContext("2d");
g.setTransform(dpr, 0, 0, dpr, 0, 0);
const W = cssW, H = cssH;
g.clearRect(0, 0, W, H);
const { lo, hi, fallback, t0, t1 } = kfGraphRange(c, key);
const span = Math.max(1e-6, t1 - t0);
const yAt = (v) => H - 4 - ((v - lo) / (hi - lo)) * (H - 8);
const xAt = (t) => 3 + ((t - t0) / span) * (W - 6);

// mid / zero guide
g.strokeStyle = "#ffffff10";
g.lineWidth = 1;
g.beginPath();
const y0 = yAt(0);
if (y0 > 4 && y0 < H - 4) { g.moveTo(3, y0); g.lineTo(W - 3, y0); g.stroke(); }

// interpolated curve (only the zoomed window)
g.strokeStyle = "#7b6cff";
g.lineWidth = 1.5;
g.beginPath();
const steps = Math.max(24, Math.floor(W));
for (let i = 0; i <= steps; i++) {
const t = t0 + (i / steps) * span;
const v = kfChannel(c, key, t, fallback);
const x = xAt(t), y = yAt(v);
if (i === 0) g.moveTo(x, y); else g.lineTo(x, y);
}
g.stroke();

// keyframe diamonds
const kfs = c.keyframes?.[key];
if (Array.isArray(kfs)) {
g.fillStyle = "#ffd166";
for (const kf of kfs) {
const x = xAt(kf.t), y = yAt(kf.v);
g.beginPath();
g.moveTo(x, y - 3.5); g.lineTo(x + 3.5, y); g.lineTo(x, y + 3.5); g.lineTo(x - 3.5, y);
g.closePath(); g.fill();
}
}

// playhead (drawn only when inside the zoomed window)
const lt = state.time - c.start;
if (lt >= t0 - 1e-6 && lt <= t1 + 1e-6) {
const px = xAt(clamp(lt, t0, t1));
g.strokeStyle = "#ff4d6a";
g.lineWidth = 1;
g.beginPath();
g.moveTo(px, 1); g.lineTo(px, H - 1);
g.stroke();
const cur = kfChannel(c, key, clamp(lt, t0, t1), fallback);
g.fillStyle = "#ff4d6a";
g.beginPath();
g.arc(px, yAt(cur), 2.5, 0, Math.PI * 2);
g.fill();
}
}

/* ═══════════════════════════ PLAYBACK ENGINE ═══════════════════════════ */
Expand Down Expand Up @@ -4910,6 +5179,7 @@ function loop(ts) {
els.playhead.style.left = state.time * state.pps + "px";
drawRuler();
updateSafeOverlay();
updateKfGraphs();
updateMeterUI(dt);
els.tcCurrent.textContent = fmt(state.time);
els.tcTotal.textContent = fmt(dur);
Expand Down Expand Up @@ -5365,6 +5635,10 @@ window.addEventListener("keydown", (e) => {
e.shiftKey ? trimToWorkArea() : splitAtWorkArea();
}
else if (k === "Delete" || k === "Backspace") deleteSelected();
else if ((e.ctrlKey || e.metaKey) && !e.altKey && (k === "ArrowLeft" || k === "ArrowRight")) {
e.preventDefault();
goToKeyframe(k === "ArrowRight" ? 1 : -1);
}
else if (k === "ArrowLeft") setTime(state.time - (e.shiftKey ? 1 : 1 / project.fps));
else if (k === "ArrowRight") setTime(state.time + (e.shiftKey ? 1 : 1 / project.fps));
else if (k === "Home") gotoHome();
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<div class="sa-ui-bottom"></div>
<div class="sa-ui-right"></div>
</div>
<div class="kf-graphs" id="kfGraphs" hidden></div>
<div class="vu-meter" id="vuMeter" title="Click to switch RMS / LUFS / Peak"></div>
</div>
<div class="transport">
Expand Down Expand Up @@ -207,6 +208,7 @@ <h2>Keyboard shortcuts</h2>
<tr><td><kbd>Ctrl</kbd>+click clip</td><td>Add / remove from selection</td></tr>
<tr><td><kbd>Ctrl</kbd>+<kbd>A</kbd> / <kbd>Esc</kbd></td><td>Select all / deselect</td></tr>
<tr><td><kbd>←</kbd> <kbd>→</kbd></td><td>Step 1 frame (⇧ = 1 second)</td></tr>
<tr><td><kbd>Ctrl</kbd>+<kbd>←</kbd> / <kbd>Ctrl</kbd>+<kbd>→</kbd></td><td>Go to previous / next keyframe</td></tr>
<tr><td><kbd>[</kbd> / <kbd>]</kbd></td><td>Trim selected in / out to playhead</td></tr>
<tr><td><kbd>Home</kbd> / <kbd>End</kbd></td><td>Jump to start / end</td></tr>
</table>
Expand Down
Loading
Loading