Skip to content

Write HTML. Render video. Built for agents.

fix(studio): an audio track can be muted again after it is unmuted (#4977)

Miguel Ángel98763899d6ae
diff --git a/packages/studio/src/components/StudioRightPanels.tsx b/packages/studio/src/components/StudioRightPanels.tsx
index f4446a3f33..7c907a3ebd 100644
--- a/packages/studio/src/components/StudioRightPanels.tsx
+++ b/packages/studio/src/components/StudioRightPanels.tsx
@@ -170,12 +170,9 @@ export const StudioRightPanels = memo(function StudioRightPanels({
);
const handleHideAllSelected = useCallback(() => {
// Audio has no visual to hide, and `data-hidden` on an audio element is what
- // MUTES it — preview silences it and the render drops it from the mix. The
- // timeline withholds the eye on an audio track for that reason
- // (`visible={!isAudioTrack}`), and the single-selection panel gates the same
- // write on `audioSelection`; this multi-selection path was the way back to
- // it. Checked here as well as in the panel because the button is not the
- // only caller.
+ // mutes it — preview silences it and the render drops it from the mix; the
+ // timeline offers that write as a mute. Checked here as well as in the panel
+ // because the button is not the only caller.
if (!canHideSelections(domEditGroupSelections)) {
showToast("Audio can't be hidden — use the group's own controls", "info");
return;
diff --git a/packages/studio/src/components/editor/PropertyPanel.test.tsx b/packages/studio/src/components/editor/PropertyPanel.test.tsx
index 12a4ef45f5..5cfdf7659f 100644
--- a/packages/studio/src/components/editor/PropertyPanel.test.tsx
+++ b/packages/studio/src/components/editor/PropertyPanel.test.tsx
@@ -4,6 +4,7 @@ import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { PropertyPanelProps } from "./propertyPanelHelpers";
+import type { TimelineEditCallbacks } from "../../player/components/timelineCallbacks";
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
@@ -235,7 +236,13 @@ async function renderPanel(
flatEnabled: boolean,
elementOverride: NonNullable<PropertyPanelProps["element"]> = baseElement(),
propsOverride: Partial<PropertyPanelProps> = {},
- currentTime?: number,
+ options: {
+ currentTime?: number;
+ selectedElementId?: string;
+ timelineEdit?: TimelineEditCallbacks;
+ refreshSelection?: (selection: unknown) => void;
+ selectionRef?: { current: unknown };
+ } = {},
) {
vi.resetModules();
vi.doMock("./manualEditingAvailability", async () => {
@@ -244,32 +251,57 @@ async function renderPanel(
);
return { ...actual, STUDIO_FLAT_INSPECTOR_ENABLED: flatEnabled };
});
- // Seed the playhead on the SAME store instance PropertyPanel.tsx will read via
- // usePlayerStore (module-fresh since the resetModules() above) — must happen
- // before PropertyPanel is imported/rendered so its initial render sees it.
- if (currentTime !== undefined) {
- const { usePlayerStore } = await import("../../player/store/playerStore");
- usePlayerStore.getState().setCurrentTime(currentTime);
+ vi.doMock("../../contexts/DomEditContext", async () => {
+ const actual = await vi.importActual<typeof import("../../contexts/DomEditContext")>(
+ "../../contexts/DomEditContext",
+ );
+ const { refreshSelection: refresh, selectionRef } = options;
+ return refresh && selectionRef
+ ? {
+ ...actual,
+ useDomEditActionsContextOptional: () => ({
+ refreshDomEditSelectionFromPreview: refresh,
+ domEditSelectionRef: selectionRef,
+ }),
+ }
+ : actual;
+ });
+ // Seed the playhead and selection on the same store instance PropertyPanel.tsx
+ // reads (module-fresh after the resetModules() above), before it is imported so
+ // its first render sees them.
+ const { usePlayerStore } = await import("../../player/store/playerStore");
+ if (options.currentTime !== undefined) {
+ usePlayerStore.getState().setCurrentTime(options.currentTime);
}
+ if (options.selectedElementId)
+ usePlayerStore.setState({ selectedElementId: options.selectedElementId });
const { PropertyPanel } = await import("./PropertyPanel");
+ const { TimelineEditProvider } = await import("../../contexts/TimelineEditContext");
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
- // Only the props the render path touches are supplied; the rest are unused at
- // mount (handlers fire on interaction), so cast a minimal object to the full
- // props shape rather than stubbing all ~15 required fields.
- const props = {
- element: elementOverride,
- assets: [],
- onSetStyle: vi.fn(),
- onSetText: vi.fn(),
- onSetAttributeLive: vi.fn(),
- ...propsOverride,
- } as unknown as PropertyPanelProps;
- act(() => {
- root.render(<PropertyPanel {...props} />);
- });
- return { host, root };
+ const render = (element: NonNullable<PropertyPanelProps["element"]>) => {
+ // Only the props the render path touches are supplied; the rest are unused at
+ // mount (handlers fire on interaction), so cast a minimal object to the full
+ // props shape rather than stubbing all ~15 required fields.
+ const props = {
+ element,
+ assets: [],
+ onSetStyle: vi.fn(),
+ onSetText: vi.fn(),
+ onSetAttributeLive: vi.fn(),
+ ...propsOverride,
+ } as unknown as PropertyPanelProps;
+ act(() => {
+ root.render(
+ <TimelineEditProvider value={options.timelineEdit ?? {}}>
+ <PropertyPanel {...props} />
+ </TimelineEditProvider>,
+ );
+ });
+ };
+ render(elementOverride);
+ return { host, root, render };
}
// renderPanel resetModules()+dynamic-imports PropertyPanel (needed for a fresh
@@ -561,7 +593,7 @@ describe("PropertyPanel — flat Layout/Motion timing agreement (whole-plan cohe
true,
inferredMotionElement(),
{ gsapAnimations: [INFERRED_TIMING_ANIMATION], onSeekToTime },
- 2,
+ { currentTime: 2 },
);
openFlatGroup(host, "Layout");
const layoutGroup = host.querySelector('[data-flat-group-open="true"]');
@@ -606,7 +638,7 @@ describe("PropertyPanel — flat Layout currentPct basis (currentPct follow-up f
true,
inferredMotionElement(),
{ gsapAnimations: [INFERRED_TIMING_ANIMATION] },
- 3.5,
+ { currentTime: 3.5 },
);
openFlatGroup(host, "Layout");
const layoutGroup = host.querySelector('[data-flat-group-open="true"]');
@@ -643,7 +675,7 @@ describe("PropertyPanel — flat Layout currentPct basis (currentPct follow-up f
true,
inferredMotionElement(),
{ gsapAnimations: [INFERRED_TIMING_ANIMATION], onSeekToTime },
- 3.5,
+ { currentTime: 3.5 },
);
openFlatGroup(host, "Layout");
const layoutGroup = host.querySelector('[data-flat-group-open="true"]');
@@ -1038,6 +1070,98 @@ describe("PropertyPanel — Motion is for things that move", () => {
RENDER_TIMEOUT_MS,
);
+ it(
+ "offers a mute on an audible audio clip and toggles it through the timeline",
+ async () => {
+ const onToggleElementHidden = vi.fn();
+ const { host, root } = await renderPanel(
+ true,
+ audioClipElement(),
+ { onToggleElementHidden },
+ { selectedElementId: "vo-1" },
+ );
+ act(() => host.querySelector<HTMLElement>('button[aria-label="Mute element"]')!.click());
+ expect(onToggleElementHidden).toHaveBeenCalledWith("vo-1", true);
+ act(() => root.unmount());
+ },
+ RENDER_TIMEOUT_MS,
+ );
+
+ // A bus has no timeline row, so the panel is its only mute; it must go both ways.
+ it(
+ "mutes, unmutes and mutes an audio group from the panel header",
+ async () => {
+ const bus = (hidden: boolean) => {
+ const element = audioBusElement();
+ return {
+ ...element,
+ dataAttributes: { ...element.dataAttributes, ...(hidden ? { hidden: "" } : {}) },
+ };
+ };
+ let hidden = true;
+ const onSetAudioGroupAttributeQuiet = vi.fn(
+ async (_id: string, _attr: string, value: string | null, _label: string) => {
+ hidden = value !== null;
+ },
+ );
+ // The panel re-reads its selection after the write; nothing else re-renders it here.
+ const { host, root, render } = await renderPanel(
+ true,
+ bus(true),
+ {},
+ {
+ timelineEdit: { onSetAudioGroupAttributeQuiet },
+ selectionRef: { current: bus(true) },
+ refreshSelection: () => render(bus(hidden)),
+ },
+ );
+ const press = async (label: string) => {
+ const button = host.querySelector<HTMLElement>(`button[aria-label="${label}"]`);
+ if (!button) throw new Error(`Expected a "${label}" button`);
+ await act(async () => button.click());
+ };
+ await press("Unmute element");
+ await press("Mute element");
+ await press("Unmute element");
+ expect(onSetAudioGroupAttributeQuiet.mock.calls).toEqual([
+ ["voiceover", "data-hidden", null, "Unmute element"],
+ ["voiceover", "data-hidden", "", "Mute element"],
+ ["voiceover", "data-hidden", null, "Unmute element"],
+ ]);
+ act(() => root.unmount());
+ },
+ RENDER_TIMEOUT_MS,
+ );
+
+ it(
+ "re-reads the current selection, not the muted bus, once the write lands",
+ async () => {
+ let land = () => {};
+ const onSetAudioGroupAttributeQuiet = vi.fn(
+ () => new Promise<void>((resolve) => (land = resolve)),
+ );
+ const selectionRef: { current: unknown } = { current: audioBusElement() };
+ const refreshSelection = vi.fn();
+ const { host, root } = await renderPanel(
+ true,
+ audioBusElement(),
+ {},
+ {
+ timelineEdit: { onSetAudioGroupAttributeQuiet },
+ selectionRef,
+ refreshSelection,
+ },
+ );
+ act(() => host.querySelector<HTMLElement>('button[aria-label="Mute element"]')!.click());
+ const next = audioClipElement();
+ selectionRef.current = next;
+ await act(async () => land());
+ expect(refreshSelection.mock.calls).toEqual([[next]]);
+ act(() => root.unmount());
+ },
+ RENDER_TIMEOUT_MS,
+ );
+
it(
"offers a bus neither — it has no clip range to edit",
async () => {
diff --git a/packages/studio/src/components/editor/PropertyPanel.tsx b/packages/studio/src/components/editor/PropertyPanel.tsx
index 487c22dc55..f882e39bd4 100644
--- a/packages/studio/src/components/editor/PropertyPanel.tsx
+++ b/packages/studio/src/components/editor/PropertyPanel.tsx
@@ -119,18 +119,7 @@ export const PropertyPanel = memo(function PropertyPanel(props: PropertyPanelPro
const selectedElementId = usePlayerStore((s) => s.selectedElementId);
const selectedElementHidden = isSelectedElementHidden(timelineElements, selectedElementId);
const visibilityToggleLabel = selectedElementHidden ? "Show element" : "Hide element";
- /**
- * An audio element gets no hide control here.
- *
- * On an audio track "hidden" and "muted" are not similar operations, they are
- * the SAME operation with two names (groups doc §2.1) — which is why the
- * timeline's eye became the mute rather than growing a sibling. A second copy
- * in the panel, still called "Hide element", is precisely the thing that step
- * removed: "Two controls that silence a track, sitting next to each other,
- * differing only in a distinction the author cannot see." An
- * `<hf-audio-group>` has no visual to hide at all, and its mute lives on its
- * own row.
- */
+ // Audio gets no visibility toggle in this classic panel; the timeline and the flat panel offer it as a mute.
const audioSelection = isAudioDomElement(element?.element);
// Live during playback, the store's when paused — see the hook. Shared with the
// audio FX panel, which follows the playhead for the same reason: a value the
diff --git a/packages/studio/src/components/editor/PropertyPanelEmptyState.test.tsx b/packages/studio/src/components/editor/PropertyPanelEmptyState.test.tsx
index ed2059bfc0..2ce69a2404 100644
--- a/packages/studio/src/components/editor/PropertyPanelEmptyState.test.tsx
+++ b/packages/studio/src/components/editor/PropertyPanelEmptyState.test.tsx
@@ -96,9 +96,8 @@ describe("PropertyPanelEmptyState — flat multi-select", () => {
/>,
);
expect(host.querySelector('[data-flat-multiselect-group="true"]')).toBeNull();
- // Hiding is visibility, and `data-hidden` on audio is what MUTES it — the
- // timeline withholds the eye on an audio track for that reason, and this
- // panel was the way back to the same write.
+ // Hiding is visibility, and `data-hidden` on audio is what mutes it; the
+ // timeline owns that write as a mute.
expect(host.querySelector('[data-flat-multiselect-hide-all="true"]')).toBeNull();
// The list still names what is selected; only the actions go.
expect(host.textContent).toContain("2 elements selected");
diff --git a/packages/studio/src/components/editor/PropertyPanelEmptyState.tsx b/packages/studio/src/components/editor/PropertyPanelEmptyState.tsx
index dbbb45f864..c3d873460f 100644
--- a/packages/studio/src/components/editor/PropertyPanelEmptyState.tsx
+++ b/packages/studio/src/components/editor/PropertyPanelEmptyState.tsx
@@ -133,11 +133,9 @@ function FlatMultiSelectState({
an empty frame. Grouping is the LAYOUT grouper — a positioned wrapper
around a bounding box, and an <audio> clip has none (grouping two
produced a 0x0 div with inline left/top on elements that are never
- laid out). Hiding is visibility, which for audio doubles as mute; the
- timeline already withholds the eye on an audio track
- (`visible={!isAudioTrack}`) and this panel was the way back to the
- same write. Both handlers refuse it too — they own keyboard paths no
- hidden button can gate. */}
+ laid out). Hiding is visibility, which for audio is mute, and the
+ timeline owns that as a mute control. Both handlers refuse it too —
+ they own keyboard paths no hidden button can gate. */}
{!hasAudio && (
<div className="flex gap-2">
<button
diff --git a/packages/studio/src/components/editor/PropertyPanelFlat.tsx b/packages/studio/src/components/editor/PropertyPanelFlat.tsx
index 035a4a3dc4..d254216719 100644
--- a/packages/studio/src/components/editor/PropertyPanelFlat.tsx
+++ b/packages/studio/src/components/editor/PropertyPanelFlat.tsx
@@ -9,6 +9,7 @@ import { useLinkedSpeedCommit, withLinkedPlaybackRate } from "./linkedSpeedEdits
import { formatPxMetricValue } from "./propertyPanelHelpers";
import { audioFxSummary } from "./audioFxSummary";
import { resolveAudioGroups } from "@hyperframes/core/audio-groups";
+import { usePanelHiddenToggle } from "./usePanelHiddenToggle";
import { PropertyPanelFlatHeader } from "./PropertyPanelFlatHeader";
import { PropertyPanelFlatFooter } from "./PropertyPanelFlatFooter";
import { closedGroupHeader, isSelectionHidden } from "./propertyPanelFlatClosedGroup";
@@ -206,6 +207,12 @@ export function PropertyPanelFlat({
* selected the clip and then appeared to do nothing.
*/
const hiddenNow = isSelectionHidden(selectedElementHidden, element);
+ const toggleHidden = usePanelHiddenToggle({
+ element,
+ hidden: hiddenNow,
+ selectedElementId,
+ onToggleElementHidden,
+ });
const reveal = useAudioFxRevealSection({
elementId: element?.id,
@@ -531,28 +538,8 @@ export function PropertyPanelFlat({
meta={`${sourceLabel} · ${element.tagName}`}
elementKind={elementKind}
hidden={hiddenNow}
- // Audio gets no hide control here. On an audio track "hidden" and
- // "muted" are not similar operations, they are the SAME operation
- // with two names (groups doc §2.1) — which is why the timeline's eye
- // BECAME the mute rather than growing a sibling. A second copy in
- // the panel, still called "Hide element", is exactly what that step
- // set out to remove: "Two controls that silence a track, sitting
- // next to each other, differing only in a distinction the author
- // cannot see." An `<hf-audio-group>` has no visual to hide at all.
- //
- // EXCEPT while it is already hidden — the same door-from-the-inside
- // the timeline's eye keeps for an audio track
- // (`TimelineTrackPlainHeader`). Withholding it unconditionally
- // withheld the only way back: a `data-hidden` group is silent in
- // preview (the bus's mute gain) and absent from the render (every
- // member dropped), and the group header carries no visibility
- // control of its own now that mute and solo are gone. Only
- // hand-editing the HTML brought the audio back.
- onToggleHidden={
- selectedElementId && onToggleElementHidden && (!audioSelection || hiddenNow)
- ? () => void onToggleElementHidden(selectedElementId, !hiddenNow)
- : undefined
- }
+ asMute={audioSelection}
+ onToggleHidden={toggleHidden}
copied={clipboardCopied}
onCopy={onCopyElementInfo}
onClear={onClearSelection}
diff --git a/packages/studio/src/components/editor/PropertyPanelFlatHeader.test.tsx b/packages/studio/src/components/editor/PropertyPanelFlatHeader.test.tsx
index f5722aa3b2..2521310756 100644
--- a/packages/studio/src/components/editor/PropertyPanelFlatHeader.test.tsx
+++ b/packages/studio/src/components/editor/PropertyPanelFlatHeader.test.tsx
@@ -77,10 +77,6 @@ describe("PropertyPanelFlatHeader", () => {
expect(withUngroup.querySelector('[aria-label="Ungroup"]')).not.toBeNull();
});
- // The panel's hide control is withheld for audio by its caller — on an audio
- // track "hidden" and "muted" are the same operation with two names (groups
- // doc §2.1), and the timeline already carries it, correctly labelled. This
- // pins the header's half of that contract: no handler, no button.
it("renders no visibility control when its caller withholds the handler", () => {
const { host } = renderHeader({ onToggleHidden: undefined });
const labels = Array.from(host.querySelectorAll("button")).map((b) =>
@@ -90,6 +86,13 @@ describe("PropertyPanelFlatHeader", () => {
expect(labels).not.toContain("Show element");
});
+ it("names a mute on an audio selection", () => {
+ const { host } = renderHeader({ onToggleHidden: vi.fn(), asMute: true });
+ expect(host.querySelector('button[aria-label="Mute element"]')).not.toBeNull();
+ const { host: muted } = renderHeader({ onToggleHidden: vi.fn(), asMute: true, hidden: true });
+ expect(muted.querySelector('button[aria-label="Unmute element"]')).not.toBeNull();
+ });
+
it("renders it when the handler is supplied", () => {
const { host } = renderHeader({ onToggleHidden: vi.fn() });
const labels = Array.from(host.querySelectorAll("button")).map((b) =>
diff --git a/packages/studio/src/components/editor/PropertyPanelFlatHeader.tsx b/packages/studio/src/components/editor/PropertyPanelFlatHeader.tsx
index d19ac73fbc..52c4bfe016 100644
--- a/packages/studio/src/components/editor/PropertyPanelFlatHeader.tsx
+++ b/packages/studio/src/components/editor/PropertyPanelFlatHeader.tsx
@@ -1,4 +1,4 @@
-import { Eye, EyeSlash } from "@phosphor-icons/react";
+import { HiddenToggleIcon, hiddenToggleVerb } from "../../player/components/hiddenToggle";
import { useTrackDesignInput } from "../../contexts/DesignPanelInputContext";
import { ClipboardList, Film, Square, Type, X } from "../../icons/SystemIcons";
@@ -14,6 +14,7 @@ export function PropertyPanelFlatHeader({
meta,
elementKind,
hidden,
+ asMute = false,
onToggleHidden,
copied,
onCopy,
@@ -25,6 +26,7 @@ export function PropertyPanelFlatHeader({
meta: string;
elementKind: "text" | "media" | "other";
hidden: boolean;
+ asMute?: boolean;
onToggleHidden?: () => void;
copied: boolean;
onCopy: () => void;
@@ -34,7 +36,7 @@ export function PropertyPanelFlatHeader({
}) {
const track = useTrackDesignInput();
const Icon = ICON_BY_KIND[elementKind];
- const visibilityLabel = hidden ? "Show element" : "Hide element";
+ const visibilityLabel = `${hiddenToggleVerb(asMute, hidden)} element`;
return (
<div className="flex items-center gap-2.5 border-b border-panel-hairline px-4 py-3">
@@ -81,7 +83,7 @@ export function PropertyPanelFlatHeader({
onToggleHidden();
}}
>
- {hidden ? <EyeSlash size={13} weight="bold" /> : <Eye size={13} weight="bold" />}
+ <HiddenToggleIcon asMute={asMute} hidden={hidden} size={13} />
</button>
)}
<button
diff --git a/packages/studio/src/components/editor/usePanelHiddenToggle.ts b/packages/studio/src/components/editor/usePanelHiddenToggle.ts
new file mode 100644
index 0000000000..e5996c39ea
--- /dev/null
+++ b/packages/studio/src/components/editor/usePanelHiddenToggle.ts
@@ -0,0 +1,44 @@
+import { HF_AUDIO_GROUP_TAG } from "@hyperframes/core/audio-groups";
+import { useDomEditActionsContextOptional } from "../../contexts/DomEditContext";
+import { useTimelineEditContextOptional } from "../../contexts/TimelineEditContext";
+import { hiddenToggleVerb } from "../../player/components/hiddenToggle";
+import type { DomEditSelection } from "./domEditingTypes";
+
+/** The panel header's hide toggle, or undefined when this selection has no writer for it. */
+export function usePanelHiddenToggle({
+ element,
+ hidden,
+ selectedElementId,
+ onToggleElementHidden,
+}: {
+ element: Pick<DomEditSelection, "id" | "tagName">;
+ hidden: boolean;
+ selectedElementId: string | null | undefined;
+ onToggleElementHidden?: (elementKey: string, hidden: boolean) => void | Promise<void>;
+}): (() => void) | undefined {
+ const { onSetAudioGroupAttributeQuiet } = useTimelineEditContextOptional();
+ const domEditActions = useDomEditActionsContextOptional();
+ // A bus has no timeline row, so it mutes through the group's own writer.
+ const audioGroupId = element.tagName.toLowerCase() === HF_AUDIO_GROUP_TAG ? element.id : null;
+ const write = audioGroupId
+ ? onSetAudioGroupAttributeQuiet &&
+ (() =>
+ onSetAudioGroupAttributeQuiet(
+ audioGroupId,
+ "data-hidden",
+ hidden ? null : "",
+ `${hiddenToggleVerb(true, hidden)} element`,
+ ))
+ : selectedElementId && onToggleElementHidden
+ ? () => onToggleElementHidden(selectedElementId, !hidden)
+ : undefined;
+ // The label reads the selection snapshot, so re-read whatever is selected once the write lands.
+ return (
+ write &&
+ (() =>
+ void Promise.resolve(write()).then(() => {
+ const selection = domEditActions?.domEditSelectionRef.current;
+ if (selection) void domEditActions?.refreshDomEditSelectionFromPreview(selection);
+ }))
+ );
+}
diff --git a/packages/studio/src/contexts/DomEditContext.tsx b/packages/studio/src/contexts/DomEditContext.tsx
index 40b2b74285..3f180321d0 100644
--- a/packages/studio/src/contexts/DomEditContext.tsx
+++ b/packages/studio/src/contexts/DomEditContext.tsx
@@ -77,6 +77,7 @@ const SAVES_AN_EDIT = {
handleUnroll: true,
invalidateGsapCache: false,
previewIframeRef: false,
+ domEditSelectionRef: false,
commitMutation: true,
applyMarqueeSelection: false,
handleUpdateKeyframeEase: true,
@@ -329,6 +330,7 @@ export function DomEditProvider({
handleUnroll,
invalidateGsapCache,
previewIframeRef,
+ domEditSelectionRef,
commitMutation: stableCommitMutation,
applyMarqueeSelection,
handleUpdateKeyframeEase,
@@ -406,6 +408,7 @@ export function DomEditProvider({
handleUnroll,
invalidateGsapCache,
previewIframeRef,
+ domEditSelectionRef,
stableCommitMutation,
applyMarqueeSelection,
handleUpdateKeyframeEase,
diff --git a/packages/studio/src/hooks/timelineTrackVisibility.ts b/packages/studio/src/hooks/timelineTrackVisibility.ts
index 19bbb88c8f..fcae78f409 100644
--- a/packages/studio/src/hooks/timelineTrackVisibility.ts
+++ b/packages/studio/src/hooks/timelineTrackVisibility.ts
@@ -8,7 +8,8 @@ import {
trackDisplaySuffix,
} from "../player/components/timelineTrackDisplay";
import { saveProjectFilesWithHistory } from "../utils/studioFileHistory";
-import { isAudioTimelineElement } from "../utils/timelineInspector";
+import { isAudioOnlyTrack } from "../utils/timelineInspector";
+import { hiddenToggleVerb } from "../player/components/hiddenToggle";
import type { PatchOperation } from "../utils/sourcePatcher";
import {
findTimelineElementInIframe,
@@ -206,14 +207,8 @@ export async function toggleTimelineTrackHidden({
displayNumber ?? trackDisplayNumber(timelineTrackOrder(timelineElements), track),
);
const trackElements = timelineElements.filter((element) => element.track === track);
- const isAudioOnlyTrack = trackElements.length > 0 && trackElements.every(isAudioTimelineElement);
- const label = isAudioOnlyTrack
- ? hidden
- ? `Mute track${suffix}`
- : `Unmute track${suffix}`
- : hidden
- ? `Hide track${suffix}`
- : `Show track${suffix}`;
+ const hiddenBefore = !hidden;
+ const label = `${hiddenToggleVerb(isAudioOnlyTrack(trackElements), hiddenBefore)} track${suffix}`;
return setElementsHidden({
projectId,
activeCompPath,
@@ -240,19 +235,14 @@ export async function toggleTimelineElementHidden({
}: ToggleTimelineElementHiddenInput): Promise<string[]> {
const keys = new Set(typeof elementKey === "string" ? [elementKey] : elementKey);
const elements = timelineElements.filter((item) => keys.has(item.key ?? item.id));
+ const hiddenBefore = !hidden;
+ const verb = hiddenToggleVerb(isAudioOnlyTrack(elements), hiddenBefore);
return setElementsHidden({
projectId,
activeCompPath,
elements,
hidden,
- label:
- elements.length > 1
- ? hidden
- ? `Hide ${elements.length} elements`
- : `Show ${elements.length} elements`
- : hidden
- ? "Hide element"
- : "Show element",
+ label: elements.length > 1 ? `${verb} ${elements.length} elements` : `${verb} element`,
previewIframe,
writeProjectFile,
recordEdit,
diff --git a/packages/studio/src/player/components/Timeline.test.ts b/packages/studio/src/player/components/Timeline.test.ts
index 84b1406e7a..d7aa1f7921 100644
--- a/packages/studio/src/player/components/Timeline.test.ts
+++ b/packages/studio/src/player/components/Timeline.test.ts
@@ -499,6 +499,54 @@ describe("Timeline provider boundary", () => {
act(() => root.unmount());
});
+ // An agent writes music alternatives muted; the author unmutes one and must be
+ // able to mute it again from the same row.
+ it("mutes, unmutes and mutes an audio track again from its header", () => {
+ const host = createSizedTimelineHost(640);
+ usePlayerStore.setState({
+ duration: 4,
+ timelineReady: true,
+ elements: [{ id: "music-b", tag: "audio", start: 0, duration: 4, track: 0, hidden: true }],
+ });
+ const onToggleTrackHidden = vi.fn((track: number, hidden: boolean) => {
+ usePlayerStore.setState({
+ elements: usePlayerStore
+ .getState()
+ .elements.map((el) => (el.track === track ? { ...el, hidden } : el)),
+ });
+ });
+ const root = createRoot(host);
+ act(() => {
+ root.render(
+ React.createElement(
+ TimelineEditProvider,
+ { value: { onToggleTrackHidden } },
+ React.createElement(Timeline),
+ ),
+ );
+ });
+ act(() => {});
+
+ const press = (label: string) => {
+ const button = host.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`);
+ if (!button) throw new Error(`Expected a "${label}" button`);
+ act(() => button.click());
+ };
+ press("Unmute track 1");
+ press("Mute track 1");
+ press("Unmute track 1");
+ press("Mute track 1");
+
+ expect(onToggleTrackHidden.mock.calls.map((call) => call[1])).toEqual([
+ false,
+ true,
+ false,
+ true,
+ ]);
+ expect(usePlayerStore.getState().elements[0]?.hidden).toBe(true);
+ act(() => root.unmount());
+ });
+
it("splits all tracks once when shift-clicking the timeline with the razor", () => {
const host = createSizedTimelineHost(640);
usePlayerStore.setState({
diff --git a/packages/studio/src/player/components/TimelineTrackHeader.test.tsx b/packages/studio/src/player/components/TimelineTrackHeader.test.tsx
index 1d36898aa8..d69a37efbf 100644
--- a/packages/studio/src/player/components/TimelineTrackHeader.test.tsx
+++ b/packages/studio/src/player/components/TimelineTrackHeader.test.tsx
@@ -256,43 +256,35 @@ describe("TimelineTrackHeader", () => {
act(() => view.root.unmount());
});
- // The visibility control is the old hide eye. On an audio track it silences
- // rather than hides, and the row already says so with a speaker elsewhere —
- // so the eye's slot stays empty there. A non-audio track is untouched.
- it("keeps the visibility control off audio track headers", () => {
+ // `data-hidden` silences an audio track, so its toggle is a mute, offered in
+ // both states: an agent writes alternatives muted and the author flips them.
+ it.each([
+ [false, "Mute track 1"],
+ [true, "Unmute track 1"],
+ ])("offers the audio track toggle when hidden=%s", (isTrackHidden, label) => {
const audio: TimelineElement = { ...ELEMENT, tag: "audio" };
const view = renderHeader({
keyframeClip: audio,
trackElements: [audio],
isAudioTrack: true,
+ isTrackHidden,
animations: [],
});
- const labels = Array.from(view.host.querySelectorAll("button")).map((b) =>
- b.getAttribute("aria-label"),
- );
- expect(labels.some((l) => l && /^(Hide|Show) track/.test(l))).toBe(false);
- expect(labels).not.toContain("Mute");
+ expect(view.host.querySelector(`button[aria-label="${label}"]`)).not.toBeNull();
act(() => view.root.unmount());
});
- // The escape hatch. `data-hidden` on audio silences it in preview and drops it
- // from the render; the panel's "Muted" is the unrelated HTML `muted`
- // attribute, and nothing else writes it. Withholding the eye unconditionally
- // meant a track hidden by "Hide all" (or by hand, or before that rule existed)
- // was silent with no control anywhere to bring it back.
- it("offers the eye on an audio track that is already hidden, so it can be restored", () => {
- const audio: TimelineElement = { ...ELEMENT, tag: "audio" };
+ // Same rule as the undo entry: a track with any visual clip hides, it does not mute.
+ it("offers the eye on a track mixing audio and a visual clip", () => {
+ const audio: TimelineElement = { ...ELEMENT, id: "vo", tag: "audio" };
const view = renderHeader({
keyframeClip: audio,
- trackElements: [audio],
+ trackElements: [audio, ELEMENT],
+ clipCount: 2,
isAudioTrack: true,
- isTrackHidden: true,
animations: [],
});
- const labels = Array.from(view.host.querySelectorAll("button")).map((b) =>
- b.getAttribute("aria-label"),
- );
- expect(labels.some((l) => l && /^Show track/.test(l))).toBe(true);
+ expect(view.host.querySelector('button[aria-label="Hide track 1"]')).not.toBeNull();
act(() => view.root.unmount());
});
diff --git a/packages/studio/src/player/components/TimelineTrackHeader.tsx b/packages/studio/src/player/components/TimelineTrackHeader.tsx
index 5b0da20c94..09b87a4f91 100644
--- a/packages/studio/src/player/components/TimelineTrackHeader.tsx
+++ b/packages/studio/src/player/components/TimelineTrackHeader.tsx
@@ -12,6 +12,7 @@ import { useTimelineEditContextOptional } from "../../contexts/TimelineEditConte
import { useDomEditActionsContextOptional } from "../../contexts/DomEditContext";
import { mintGroupId } from "../../components/editor/useFxCarveGrouping";
import { runtimeAudioId } from "../lib/timelineElementHelpers";
+import { isAudioOnlyTrack } from "../../utils/timelineInspector";
import { TimelineFxButton } from "./TimelineFxButton";
import { getTimelinePropertyLanes } from "./TimelinePropertyLanes";
import { elementFxChain, groupAutomationLanes, isCarveLane } from "./automationLaneData";
@@ -203,6 +204,7 @@ export function TimelineTrackHeader({
// disclosability swapped it for the keyframe-layer row (a `◇`, no indent) the
// moment an envelope appeared.
const isKeyframeLayer = !!keyframeClip && disclosable && !isAudioTrack;
+ const isAudioOnly = isAudioOnlyTrack(trackElements);
// What the lane disclosure calls this row. A row of several clips is named
// for the TRACK, not for whichever is selected — the lanes are the track's,
// shared per property, so "Narration 2 lanes" read as if they were that one
@@ -312,6 +314,7 @@ export function TimelineTrackHeader({
showTrackLabel={showTrackLabel}
isTrackHidden={isTrackHidden}
isAudioTrack={isAudioTrack}
+ isAudioOnly={isAudioOnly}
onToggleTrackHidden={onToggleTrackHidden}
// On the control line rather than a third row of its own.
trailing={
@@ -383,8 +386,7 @@ export function TimelineTrackHeader({
hidden={isTrackHidden}
trackNumber={trackNumber}
trackDisplayNumber={trackDisplayNumber}
- // Audio: only while hidden — see the plain header.
- visible={!isAudioTrack || isTrackHidden}
+ asMute={isAudioOnly}
onToggle={onToggleTrackHidden}
/>
</LayerDisclosureRow>
diff --git a/packages/studio/src/player/components/TimelineTrackPlainHeader.test.tsx b/packages/studio/src/player/components/TimelineTrackPlainHeader.test.tsx
index 6ff0240934..03943c03eb 100644
--- a/packages/studio/src/player/components/TimelineTrackPlainHeader.test.tsx
+++ b/packages/studio/src/player/components/TimelineTrackPlainHeader.test.tsx
@@ -1,17 +1,8 @@
// @vitest-environment happy-dom
/**
- * The visibility control's accessible contract.
- *
- * The wording ran behind the `audio-track-mute` canary at 0%, so it had never
- * rendered in any suite: it returned "Muted" / "Mute", which named the CURRENT
- * state rather than the action, and dropped the track suffix so every audio row
- * shared one accessible name. Pinned here because the label, the icon and the
- * callback's arguments are the whole identity of this control.
- *
- * The mute presentation itself is gone (`remove mute and solo from tracks and
- * groups`): the control is the visibility eye it always was, and an audio row
- * renders it only when already hidden, which is the way back out.
+ * The track toggle's accessible contract: the label names the action, carries
+ * the display row, and reads mute on an audio-only track.
*/
import React, { act } from "react";
@@ -27,7 +18,7 @@ afterEach(() => {
function renderButton(props: {
hidden: boolean;
- visible?: boolean;
+ asMute?: boolean;
trackDisplayNumber: number | null;
}): { host: HTMLElement; unmount: () => void; onToggle: ReturnType<typeof vi.fn> } {
const host = document.createElement("div");
@@ -40,7 +31,7 @@ function renderButton(props: {
hidden: props.hidden,
trackNumber: 7,
trackDisplayNumber: props.trackDisplayNumber,
- visible: props.visible ?? true,
+ asMute: props.asMute ?? false,
onToggle,
}),
),
@@ -80,13 +71,13 @@ describe("VisibilityButton", () => {
view.unmount();
});
- // `visible={false}` renders a SPACER, not nothing: every row's control
- // columns have to line up whether or not this row offers the control.
- it("holds the column with a spacer when withheld", () => {
- const view = renderButton({ hidden: false, visible: false, trackDisplayNumber: 2 });
- expect(view.host.querySelector("button")).toBeNull();
- expect(view.host.querySelector("span")).toBeTruthy();
- view.unmount();
+ it("names a mute on an audio-only track", () => {
+ const audible = renderButton({ hidden: false, asMute: true, trackDisplayNumber: 2 });
+ expect(labelOf(audible.host)).toBe("Mute track 2");
+ audible.unmount();
+ const muted = renderButton({ hidden: true, asMute: true, trackDisplayNumber: 2 });
+ expect(labelOf(muted.host)).toBe("Unmute track 2");
+ muted.unmount();
});
});
@@ -104,6 +95,7 @@ describe("PlainTrackHeader", () => {
clipCount: 1,
isTrackHidden: false,
isAudioTrack: true,
+ isAudioOnly: true,
onToggleTrackHidden: vi.fn(),
showTrackLabel: true,
...overrides,
@@ -113,26 +105,20 @@ describe("PlainTrackHeader", () => {
return { host, unmount: () => act(() => root.unmount()) };
}
- // A row that says what it is with a speaker does not also need the hide
- // affordance sitting in the eye's slot.
- it("withholds the eye from an audible audio track", () => {
+ it("offers a mute on an audible audio track", () => {
const view = renderHeader();
- expect(view.host.querySelector("button")).toBeNull();
+ expect(labelOf(view.host)).toBe("Mute track 1");
view.unmount();
});
- // Withholding it unconditionally withheld the only way back: `data-hidden`
- // silences the clip in preview and drops it from the render, and nothing else
- // writes it, so a track hidden by hand or by "Hide all" was silent with no
- // control anywhere to restore it.
- it("offers it back once the audio track is hidden", () => {
+ it("offers the unmute on a muted audio track", () => {
const view = renderHeader({ isTrackHidden: true });
- expect(labelOf(view.host)).toBe("Show track 1");
+ expect(labelOf(view.host)).toBe("Unmute track 1");
view.unmount();
});
it("keeps the eye on a visual track", () => {
- const view = renderHeader({ isAudioTrack: false });
+ const view = renderHeader({ isAudioTrack: false, isAudioOnly: false });
expect(labelOf(view.host)).toBe("Hide track 1");
view.unmount();
});
diff --git a/packages/studio/src/player/components/TimelineTrackPlainHeader.tsx b/packages/studio/src/player/components/TimelineTrackPlainHeader.tsx
index 1f506c8ecf..eb2957cfcf 100644
--- a/packages/studio/src/player/components/TimelineTrackPlainHeader.tsx
+++ b/packages/studio/src/player/components/TimelineTrackPlainHeader.tsx
@@ -1,39 +1,28 @@
import type React from "react";
-import { Eye, EyeSlash } from "@phosphor-icons/react";
import { Music } from "../../icons/SystemIcons";
import type { TimelineEditCallbacks } from "./timelineCallbacks";
import { TrackClipCount } from "./TrackClipCount";
import { trackDisplaySuffix } from "./timelineTrackDisplay";
-
-// Hide, plainly. The speaker variant was the mute presentation; with mute gone
-// this is the visibility eye it always was, and audio rows do not render it.
-function visibilityButtonLabel(hidden: boolean, suffix: string): string {
- return hidden ? `Show track${suffix}` : `Hide track${suffix}`;
-}
-
-function visibilityButtonIcon(hidden: boolean) {
- const Icon = hidden ? EyeSlash : Eye;
- return <Icon size={14} weight="bold" aria-hidden="true" />;
-}
+import { HiddenToggleIcon, hiddenToggleVerb } from "./hiddenToggle";
export function VisibilityButton({
hidden,
trackNumber,
trackDisplayNumber,
- visible,
+ asMute,
onToggle,
}: {
hidden: boolean;
trackNumber: number;
trackDisplayNumber: number | null;
- visible: boolean;
+ /** `data-hidden` silences an audio-only track, so its toggle is a mute. */
+ asMute: boolean;
onToggle: TimelineEditCallbacks["onToggleTrackHidden"];
}) {
- if (!visible) return <span aria-hidden="true" className="h-6 w-6 shrink-0" />;
// Display number in the text, real key in the callback. The two must not be
// conflated in either direction.
const suffix = trackDisplaySuffix(trackDisplayNumber);
- const label = visibilityButtonLabel(hidden, suffix);
+ const label = `${hiddenToggleVerb(asMute, hidden)} track${suffix}`;
return (
<button
type="button"
@@ -52,7 +41,7 @@ export function VisibilityButton({
void onToggle?.(trackNumber, !hidden, trackDisplayNumber);
}}
>
- {visibilityButtonIcon(hidden)}
+ <HiddenToggleIcon asMute={asMute} hidden={hidden} size={14} />
</button>
);
}
@@ -67,6 +56,7 @@ export function PlainTrackHeader({
showTrackLabel,
isTrackHidden,
isAudioTrack,
+ isAudioOnly,
onToggleTrackHidden,
trailing,
}: {
@@ -76,6 +66,7 @@ export function PlainTrackHeader({
clipCount: number;
isTrackHidden: boolean;
isAudioTrack: boolean;
+ isAudioOnly: boolean;
onToggleTrackHidden: TimelineEditCallbacks["onToggleTrackHidden"];
showTrackLabel: boolean;
/** Trailing controls that belong on the control line — the FX entry points,
@@ -111,25 +102,11 @@ export function PlainTrackHeader({
truncating name leaves, so the controls sit on the edge whatever the
name's length. */}
<div className="ml-auto flex shrink-0 items-center gap-1">
- {/* Not on an audio track. The control is the old visibility eye, and
- on audio it silences rather than hides — but a row that already says
- what it is with a speaker does not also need the hide affordance
- sitting in the eye's slot. `visible={false}` rather than omitting the
- element, so the spacer keeps every row's control columns aligned.
-
- EXCEPT when the audio track is ALREADY hidden. Withholding the
- control unconditionally withheld the only way back: `data-hidden`
- silences the clip in preview and drops it from the render, the
- panel's "Muted" is the unrelated HTML `muted` attribute, and nothing
- else writes it — so a track hidden before this rule (or by "Hide
- all", or by hand) was silent with no control anywhere to restore it.
- Offering the eye only in that state keeps the affordance off a normal
- audio row while leaving the door open from the inside. */}
<VisibilityButton
hidden={isTrackHidden}
trackNumber={trackNumber}
trackDisplayNumber={trackDisplayNumber}
- visible={!isAudioTrack || isTrackHidden}
+ asMute={isAudioOnly}
onToggle={onToggleTrackHidden}
/>
{trailing}
diff --git a/packages/studio/src/player/components/hiddenToggle.tsx b/packages/studio/src/player/components/hiddenToggle.tsx
new file mode 100644
index 0000000000..2d69fc8897
--- /dev/null
+++ b/packages/studio/src/player/components/hiddenToggle.tsx
@@ -0,0 +1,20 @@
+import { Eye, EyeSlash, SpeakerHigh, SpeakerSlash } from "@phosphor-icons/react";
+
+/** The action a hide toggle offers from the current `hidden` state; on audio `data-hidden` is a mute. */
+export function hiddenToggleVerb(asMute: boolean, hidden: boolean): string {
+ if (asMute) return hidden ? "Unmute" : "Mute";
+ return hidden ? "Show" : "Hide";
+}
+
+export function HiddenToggleIcon({
+ asMute,
+ hidden,
+ size,
+}: {
+ asMute: boolean;
+ hidden: boolean;
+ size: number;
+}) {
+ const Icon = asMute ? (hidden ? SpeakerSlash : SpeakerHigh) : hidden ? EyeSlash : Eye;
+ return <Icon size={size} weight="bold" aria-hidden="true" />;
+}
diff --git a/packages/studio/src/utils/timelineInspector.ts b/packages/studio/src/utils/timelineInspector.ts
index 7bae863084..1f652b123c 100644
--- a/packages/studio/src/utils/timelineInspector.ts
+++ b/packages/studio/src/utils/timelineInspector.ts
@@ -34,6 +34,13 @@ export function isAudioTimelineElement(
return Boolean(element.src && AUDIO_SOURCE_EXT_RE.test(element.src));
}
+/** A track whose hide toggle reads as mute: the header button and its undo entry. */
+export function isAudioOnlyTrack(
+ elements: readonly Pick<TimelineElement, "tag" | "src">[],
+): boolean {
+ return elements.length > 0 && elements.every(isAudioTimelineElement);
+}
+
/** The two tags the property panel lets you put a volume automation lane on.
* Single owner: `groupAutomationLanes`, `automationLaneCountOf` and
* `TimelineAutomationLaneSlot`'s clip filter all have to agree on this set. */
@@ -108,11 +115,9 @@ export function resolveBeatSourceTrack(
* May this multi-selection be hidden as one action?
*
* Audio has no visual to hide, and `data-hidden` on an audio element is what
- * MUTES it — preview silences it and the render drops it from the mix. The
- * timeline withholds the eye on an audio track for that reason
- * (`visible={!isAudioTrack}`), and the single-selection panel gates the same
- * write on `audioSelection`. The multi-selection "Hide all" was the one path
- * left back to it, on a control whose label promises visibility.
+ * mutes it: preview silences it and the render drops it from the mix. The timeline
+ * and the single-selection panel offer it as a mute; "Hide all" would reach it on a
+ * control whose label promises visibility.
*
* A shared predicate rather than a check in the handler so the panel's button
* and the handler's refusal cannot disagree — the button is not the only caller.