-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add Waveform as Background of the Trim Track - Easier to size the Trim #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
davideme
wants to merge
19
commits into
siddharthvaddem:main
Choose a base branch
from
davideme:claude/trusting-mcnulty-1089a4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8413095
feat: audio waveform on trim track + Timeline Settings toggle
davideme 70c7d20
fix: timeline waveform in dedicated Timeline panel, disabled by default
davideme 5b4f31f
chore: swap AudioWaveform icon for Brackets, improve toggle label
davideme 46732fc
revert: restore hint text opacity to 0.12 in Row
davideme a72aa1a
refactor: extract audio peak decoding into useAudioPeaks hook
davideme 514943c
refactor: extract loadFileAsArrayBuffer to eliminate duplicated file …
davideme f67e997
refactor: offload peak computation to Web Worker, replace module cach…
davideme b7d7c08
i18n: add Timeline panel translations for all 12 locales
davideme 98f7441
refactor: rename RowWaveform to BackgroundWaveform, drop wrapper div
davideme f19d1bc
fix: clear stale peaks before decoding a new source
davideme 87f7268
i18n(zh-TW): align waveform label with existing trim terminology
davideme 9f55611
fix: always clear canvas before bailing on empty peaks
davideme 9a72f31
docs: add missing JSDoc to satisfy docstring coverage threshold
davideme 928cabc
fix: add AbortSignal to worker, fix data: URL filename in loadSourceFile
davideme d06bf37
fix: propagate Content-Type from fetch through loadFileAsArrayBuffer
davideme 69d0aa4
refactor: split loadSourceFile into loadLocalSourceFile and loadRemot…
davideme db1d6bf
refactor: rewrite loadFileAsArrayBuffer using static loadLocalSourceF…
davideme c0b929d
refactor: simplify function signatures and reduce line breaks for rea…
davideme 3a2f907
chore: restore original VideoFrame formatting in streamingDecoder.ts
davideme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/components/video-editor/timeline/BackgroundWaveform.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { useTimelineContext } from "dnd-timeline"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
|
|
||
| export interface BackgroundWaveformProps { | ||
| /** Pre-computed peaks array: pairs of [min, max] per block (length = 2 * N). */ | ||
| peaks: Float32Array | null; | ||
| videoDurationMs: number; | ||
| } | ||
|
|
||
| /** | ||
| * Renders a faint audio waveform on a `<canvas>` that fills its containing | ||
| * block. Designed to be passed as the `background` prop of `<Row>`, which | ||
| * already provides `relative overflow-hidden` — no wrapper element needed. | ||
| * | ||
| * - Accepts pre-computed `peaks` from the caller (see `useAudioPeaks`). | ||
| * - Redraws whenever the timeline zoom/pan range changes. | ||
| * - `pointer-events: none` — never blocks drag-to-create interactions. | ||
| */ | ||
| export default function BackgroundWaveform({ peaks, videoDurationMs }: BackgroundWaveformProps) { | ||
| const { range } = useTimelineContext(); | ||
| const canvasRef = useRef<HTMLCanvasElement>(null); | ||
| const [canvasSize, setCanvasSize] = useState({ w: 0, h: 0 }); | ||
|
|
||
| // Observe the canvas itself — Row's `relative overflow-hidden` parent | ||
| // makes it fill the row exactly, so no wrapper div is needed. | ||
| useEffect(() => { | ||
| const canvas = canvasRef.current; | ||
| if (!canvas) return; | ||
| const ro = new ResizeObserver((entries) => { | ||
| const { width, height } = entries[0].contentRect; | ||
| setCanvasSize({ w: width, h: height }); | ||
| }); | ||
| ro.observe(canvas); | ||
| return () => ro.disconnect(); | ||
| }, []); | ||
|
|
||
| // Redraw whenever peaks, range, or canvas size changes. | ||
| useEffect(() => { | ||
| const canvas = canvasRef.current; | ||
| if (!canvas || canvasSize.w <= 0 || canvasSize.h <= 0) return; | ||
|
|
||
| const dpr = window.devicePixelRatio || 1; | ||
| canvas.width = Math.round(canvasSize.w * dpr); | ||
| canvas.height = Math.round(canvasSize.h * dpr); | ||
|
|
||
| const ctx = canvas.getContext("2d"); | ||
| if (!ctx) return; | ||
|
|
||
| ctx.scale(dpr, dpr); | ||
| ctx.clearRect(0, 0, canvasSize.w, canvasSize.h); | ||
|
|
||
| if (!peaks || peaks.length === 0) return; | ||
|
|
||
| const W = canvasSize.w; | ||
| const H = canvasSize.h; | ||
| const mid = H / 2; | ||
| const amp = mid * 0.9; | ||
| const rangeMs = range.end - range.start; | ||
| if (rangeMs <= 0 || videoDurationMs <= 0) return; | ||
|
|
||
| const N = peaks.length / 2; | ||
|
|
||
| ctx.beginPath(); | ||
| ctx.strokeStyle = "rgba(255, 255, 255, 0.12)"; | ||
| ctx.lineWidth = 1; | ||
|
|
||
| for (let x = 0; x < W; x++) { | ||
| const startMs = range.start + (x / W) * rangeMs; | ||
| const endMs = range.start + ((x + 1) / W) * rangeMs; | ||
| const lo = Math.max(0, Math.floor((startMs / videoDurationMs) * N)); | ||
| const hi = Math.min(N - 1, Math.ceil((endMs / videoDurationMs) * N)); | ||
|
|
||
| let minVal = 0; | ||
| let maxVal = 0; | ||
| for (let i = lo; i <= hi; i++) { | ||
| const mn = peaks[i * 2]; | ||
| const mx = peaks[i * 2 + 1]; | ||
| if (mn < minVal) minVal = mn; | ||
| if (mx > maxVal) maxVal = mx; | ||
| } | ||
|
|
||
| ctx.moveTo(x + 0.5, mid - maxVal * amp); | ||
| ctx.lineTo(x + 0.5, mid - minVal * amp); | ||
| } | ||
|
|
||
| ctx.stroke(); | ||
| }, [peaks, range, canvasSize, videoDurationMs]); | ||
|
|
||
| return <canvas ref={canvasRef} className="absolute inset-0 pointer-events-none w-full h-full" />; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.