Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(editor): add bounded clip audio controls
Richie McIlroy060664902c94
diff --git a/apps/desktop/src/routes/editor/clip-audio.test.ts b/apps/desktop/src/routes/editor/clip-audio.test.tsnew file mode 100644index 000000000..e5a783c37--- /dev/null+++ b/apps/desktop/src/routes/editor/clip-audio.test.ts@@ -0,0 +1,23 @@+import { describe, expect, it } from "vitest";+import { clipAudioMuted, clipVolume } from "./clip-audio";++describe("clip audio", () => {+ it("keeps old clips at full volume and bounds saved values", () => {+ expect(clipVolume({})).toBe(1);+ expect(clipVolume({ volume: null })).toBe(1);+ expect(clipVolume({ volume: 0.35 })).toBe(0.35);+ expect(clipVolume({ volume: -1 })).toBe(0);+ expect(clipVolume({ volume: 3 })).toBe(2);+ expect(clipVolume({ volume: Number.NaN })).toBe(1);+ expect(clipVolume({ volume: Number.POSITIVE_INFINITY })).toBe(1);+ });++ it("mutes normal clips explicitly and sped-up clips by default", () => {+ expect(clipAudioMuted({ timescale: 1 })).toBe(false);+ expect(clipAudioMuted({ timescale: 1, speedAudioMode: "mute" })).toBe(true);+ expect(clipAudioMuted({ timescale: 2 })).toBe(true);+ for (const speedAudioMode of ["maintainPitch", "matchSpeed"] as const) {+ expect(clipAudioMuted({ timescale: 2, speedAudioMode })).toBe(false);+ }+ });+});diff --git a/apps/desktop/src/routes/editor/clip-audio.ts b/apps/desktop/src/routes/editor/clip-audio.tsnew file mode 100644index 000000000..847e8338b--- /dev/null+++ b/apps/desktop/src/routes/editor/clip-audio.ts@@ -0,0 +1,14 @@+import type { TimelineSegment } from "~/utils/tauri";++export function clipVolume(segment: Pick<TimelineSegment, "volume">): number {+ const volume = segment.volume ?? 1;+ return Number.isFinite(volume) ? Math.min(2, Math.max(0, volume)) : 1;+}++export function clipAudioMuted(+ segment: Pick<TimelineSegment, "timescale" | "speedAudioMode">,+): boolean {+ return segment.timescale === 1+ ? segment.speedAudioMode === "mute"+ : (segment.speedAudioMode ?? "mute") === "mute";+}