Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(audio): make the loop toggle reachable, and give voiceover a button

Ola Adebayo80c6d38dd52c
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsx
index 217b1ba29..7a9b73552 100644
--- a/src/components/ai-edition/NewEditorShell.tsx
+++ b/src/components/ai-edition/NewEditorShell.tsx
@@ -1459,6 +1459,7 @@ export function NewEditorShell() {
onTogglePlay={togglePlay}
onPrevClip={handlePrevClip}
onNextClip={handleNextClip}
+ onAddVoiceover={openVoiceoverFlow}
onEditClip={setEditClipTarget}
/>
</div>
diff --git a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
index dbd0d6466..1f2a9fb62 100644
--- a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
@@ -110,6 +110,7 @@ function renderTimeline(
onPrevClip={vi.fn()}
onNextClip={vi.fn()}
onEditClip={vi.fn()}
+ onAddVoiceover={vi.fn()}
/>,
);
return {
@@ -367,7 +368,7 @@ describe("V4Timeline audio lane drag", () => {
origin: "user" as const,
});
- function renderAudio() {
+ function renderAudio(trackOverrides: Partial<ReturnType<typeof makeTrack>> = {}) {
const placeAudioTrack = vi.fn(
async (_id: string, _span: { startMs: number; endMs: number; offsetMs?: number }) => {
/* the drag only awaits it */
@@ -385,7 +386,7 @@ describe("V4Timeline audio lane drag", () => {
selection: null,
multiSelection: [],
clipSelection: null,
- audioTracks: [makeTrack()],
+ audioTracks: [{ ...makeTrack(), ...trackOverrides }],
selectedAudioTrackId: null,
selectAudioTrack,
placeAudioTrack,
@@ -404,6 +405,7 @@ describe("V4Timeline audio lane drag", () => {
onPrevClip={vi.fn()}
onNextClip={vi.fn()}
onEditClip={vi.fn()}
+ onAddVoiceover={vi.fn()}
/>,
);
return { pill: screen.getByTitle("vo"), placeAudioTrack, selectAudioTrack };
@@ -461,6 +463,31 @@ describe("V4Timeline audio lane drag", () => {
expect(placement.offsetMs).toBe(0);
});
+ it("caps the out-point at the source length when the track does not loop", () => {
+ // A non-looping track has nothing to play past the end of its file, so the
+ // right edge stops there however far the pointer goes.
+ const { pill, placeAudioTrack } = renderAudio();
+ const handle = pill.lastElementChild as Element;
+ fireEvent.pointerDown(handle, { clientX: 0 });
+ window.dispatchEvent(new MouseEvent("pointermove", { clientX: 400 }));
+ window.dispatchEvent(new MouseEvent("pointerup", { clientX: 400 }));
+ const [, placement] = placeAudioTrack.mock.calls[0];
+ expect((placement.endMs - placement.startMs) / 1000).toBeCloseTo(60, 3);
+ });
+
+ it("lets a looping track be pulled out past the end of its file", () => {
+ // This is what makes the loop toggle mean anything: the span has to be able
+ // to EXCEED the source, or the audio always plays exactly once and turning
+ // loop on does nothing at all.
+ const { pill, placeAudioTrack } = renderAudio({ loop: true });
+ const handle = pill.lastElementChild as Element;
+ fireEvent.pointerDown(handle, { clientX: 0 });
+ window.dispatchEvent(new MouseEvent("pointermove", { clientX: 400 }));
+ window.dispatchEvent(new MouseEvent("pointerup", { clientX: 400 }));
+ const [, placement] = placeAudioTrack.mock.calls[0];
+ expect((placement.endMs - placement.startMs) / 1000).toBeGreaterThan(60);
+ });
+
it("right-handle drag pulls the out-point in, head fixed", () => {
const { pill, placeAudioTrack } = renderAudio();
// The right resize handle is the last child of the pill.
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
index bdac9ffa2..58660d366 100644
--- a/src/components/ai-edition/v4/V4Timeline.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -4,6 +4,7 @@ import {
Loader2,
Maximize2,
MessageSquare,
+ Mic,
Music,
Pencil,
Scissors,
@@ -444,6 +445,7 @@ export function V4Timeline({
onPrevClip,
onNextClip,
onEditClip,
+ onAddVoiceover,
}: {
tl: TimelineApi;
setCurrentTime: (sec: number) => void;
@@ -457,6 +459,9 @@ export function V4Timeline({
/** Opens the (now single, shell-level) EditClipModal for this clip —
* trim in/out and crop both live there per-clip. */
onEditClip: (clip: AxcutClip) => void;
+ /** Opens the voiceover recorder. Shell-level like the clip editor: the
+ * dialog owns the microphone and the shell owns the transport. */
+ onAddVoiceover: () => void;
}) {
const t = useScopedT("timeline");
// The camera lane borrows the Layout pane's "No Webcam" wording when there is no
@@ -905,7 +910,16 @@ export function V4Timeline({
const origStart = track.startMs / 1000;
const origTrimStart = track.offsetMs / 1000;
const origTrimEnd = origTrimStart + spanSec;
- const maxEnd = sourceLen > 0 ? sourceLen : origTrimEnd;
+ // A looping track may be pulled out PAST the end of its file — that is
+ // the whole point of looping, and capping at the source length is what
+ // made the loop toggle do nothing: the span could never exceed the
+ // window loop repeats, so it always played exactly once. Only the
+ // programme end bounds it (applied below).
+ const maxEnd = track.loop
+ ? Number.POSITIVE_INFINITY
+ : sourceLen > 0
+ ? sourceLen
+ : origTrimEnd;
// Snap the moving edge to clip boundaries and the timeline ends, same PILL_SNAP_PX
// magnet the region pills use.
const snapTargets = [
@@ -1567,15 +1581,26 @@ export function V4Timeline({
</button>
{/* Add audio sits right after Add annotation (issue #350). */}
{tool.id === "comment" ? (
- <button
- type="button"
- className={styles.tlToolBtn}
- title={ts("audioTrack.add")}
- aria-label={ts("audioTrack.add")}
- onClick={() => void tl.addAudio()}
- >
- <Music size={15} />
- </button>
+ <>
+ <button
+ type="button"
+ className={styles.tlToolBtn}
+ title={ts("audioTrack.add")}
+ aria-label={ts("audioTrack.add")}
+ onClick={() => void tl.addAudio()}
+ >
+ <Music size={15} />
+ </button>
+ <button
+ type="button"
+ className={styles.tlToolBtn}
+ title={t("audio.addVoiceover")}
+ aria-label={t("audio.addVoiceover")}
+ onClick={onAddVoiceover}
+ >
+ <Mic size={15} />
+ </button>
+ </>
) : null}
</Fragment>
))}
@@ -1752,7 +1777,9 @@ export function V4Timeline({
leftPct={pctOf(start)}
widthPct={pctOf(widthSec)}
sourceStartSec={trimStart}
- sourceEndSec={trimEnd}
+ // A looping pill can outrun its file; the waveform draws
+ // the source it actually has.
+ sourceEndSec={duration > 0 ? Math.min(trimEnd, duration) : trimEnd}
selected={tl.selectedAudioTrackId === track.id}
onStartDrag={startAudioDrag}
onSelect={tl.selectAudioTrack}
diff --git a/src/components/ai-edition/v4/V4Timeline.waveform.test.tsx b/src/components/ai-edition/v4/V4Timeline.waveform.test.tsx
index 5234cd225..64def94c6 100644
--- a/src/components/ai-edition/v4/V4Timeline.waveform.test.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.waveform.test.tsx
@@ -134,6 +134,7 @@ function renderBars(atGainDb: number): string[] {
onPrevClip={vi.fn()}
onNextClip={vi.fn()}
onEditClip={vi.fn()}
+ onAddVoiceover={vi.fn()}
/>,
);
const bars = Array.from(