The VS Code of video editing, built for agents.
TypeScript
Enhance AudioSettings integration in Inspector for improved audio management
konstantin-paulusaa7929a4a589
diff --git a/apps/web/src/components/sidebar-right/inspector/audio.tsx b/apps/web/src/components/sidebar-right/inspector/audio.tsxindex 6404160e..c577552f 100644--- a/apps/web/src/components/sidebar-right/inspector/audio.tsx+++ b/apps/web/src/components/sidebar-right/inspector/audio.tsx@@ -7,15 +7,15 @@ import { ControlRow } from "@/components/ui/control-group";import { Icon } from "@/components/ui/icon";import { PanelSection } from "@/components/ui/panel-section";import { ControlledTextField } from "@/components/ui/text-field";-import { Keyframe } from "@/components/ui/keyframe-bitecs";+import { Keyframe } from "@/components/ui/keyframe";import { useVolumeMeter, type ChannelLevels } from "@/hooks/use-volume-meter";import { cx } from "@/lib/cva";+import { useHas, useTrait, useWorld } from "@diffusionstudio/koota-solid";+import { AudioBusHandle, Computed, Muted, Soloed } from "@diffusionstudio/runtime";+import { useDerived, useEditor } from "@/engine/hooks";+import { syncKeyframe } from "@/engine/keyframes";-import { useEntityState, useEntityTag } from "../../engine/hooks";-import { addComponent, removeComponent, setComponent } from "../../engine";-import { useEngine } from "@/context/engine";-import { hasComponent } from 'bitecs';-+import type { Entity } from "koota";const MIN_DB = -60;const MAX_DB = 12;@@ -242,35 +242,37 @@ function VolumeKnob(props: VolumeKnobProps) {}type AudioSettingsProps = {- selection: Set<number>;+ selection: Entity[];};+/**+ * The node's audio: its gain in decibels, mute and solo, and the live level+ * of its bus. `volume` and `muted` are props (0 dB is unity, so a volume+ * left there is unset); solo is the runtime's own tag with no JSX spelling,+ * written to the trait alone and gone on the next recompile, which is what a+ * monitoring toggle should be.+ */export function AudioSettings(props: AudioSettingsProps) {- const { world } = useEngine();- const c = world.components;+ const world = useWorld();+ const editor = useEditor();const meter = useVolumeMeter();+ const entity = () => props.selection[0]!;- const eid = () => props.selection.values().next().value!;-- const volume = useEntityState(c.Computed.volume, eid, 0);- const muted = useEntityTag(c.Muted, eid);- const soloed = useEntityTag(c.Soloed, eid);- const audioBus = useEntityState(c.AudioBus, eid);+ // Computed is written by the systems without change events.+ const volume = useDerived(() => entity().get(Computed)?.volume ?? 0);+ const muted = useHas(entity, Muted);+ const soloed = useHas(entity, Soloed);+ // The bus is spun up by the playback system once the node has audio, and+ // set back to null when its decoders are released.+ const audioBus = useTrait(entity, AudioBusHandle);const toggleMuted = () => {- if (hasComponent(world, eid(), c.Muted)) {- removeComponent(world, eid(), c.Muted);- } else {- addComponent(world, eid(), c.Muted);- }+ editor.editProperty(entity(), "muted", !muted());};const toggleSoloed = () => {- if (hasComponent(world, eid(), c.Soloed)) {- removeComponent(world, eid(), c.Soloed);- } else {- addComponent(world, eid(), c.Soloed);- }+ if (soloed()) entity().remove(Soloed);+ else entity().add(Soloed);};createEffect(() => {@@ -286,7 +288,11 @@ export function AudioSettings(props: AudioSettingsProps) {const handleVolumeChange = (value: number | undefined) => {if (value === undefined) return;- setComponent(world, eid(), c.Volume, normalizeDb(value));+ // Whole decibels: the field and the knob both show the value rounded,+ // and a dragged knob would otherwise write a new fraction per frame.+ const next = Math.round(normalizeDb(value));+ editor.editProperty(entity(), "volume", next === 0 ? false : next);+ syncKeyframe(world, editor, entity(), "volume", next);};return (@@ -308,7 +314,7 @@ export function AudioSettings(props: AudioSettingsProps) {unit="dB"showSignautoSelect- keyframe={<Keyframe target={eid()} property="volume" />}+ keyframe={<Keyframe target={entity()} property="volume" />}/><div class="h-7 flex gap-px rounded-md overflow-hidden shrink-0">diff --git a/apps/web/src/components/sidebar-right/inspector/inspector.tsx b/apps/web/src/components/sidebar-right/inspector/inspector.tsxindex 54569c8c..c0157261 100644--- a/apps/web/src/components/sidebar-right/inspector/inspector.tsx+++ b/apps/web/src/components/sidebar-right/inspector/inspector.tsx@@ -37,7 +37,7 @@ import { EffectsSettings } from "./effects";import { AnimationsSettings } from "./animations";import { TransitionSettings } from "./transition";import { MasksSettings } from "./masks";-// import { AudioSettings } from "./audio";+import { AudioSettings } from "./audio";// import { InterpolationSettings } from "./interpolation";import type { Entity } from "koota";@@ -177,9 +177,9 @@ export function Inspector() {<MasksSettings selection={nodes()} /></Show>- {/* <Show when={includesTarget("shape", "audio", "group")}>+ <Show when={includesTarget("shape", "audio", "group")}><AudioSettings selection={nodes()} />- </Show> */}+ </Show><Show when={includesTarget("asset")}><AssetInfoPanel />diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.mdindex dcfb1d84..9b8fd6f5 100644--- a/packages/runtime/MIGRATION.md+++ b/packages/runtime/MIGRATION.md@@ -76,7 +76,7 @@ Done:| Draw tools + toolbar (armed tool is the `Tool` world trait) | `components/canvas/draw-overlay.tsx` || Input, HUD, camera, alignment | `engine/input/`, `engine/hud/`, `engine/align.ts` || Project config (per-scene export settings in package.json) | `engine/project-config.ts` |-| Panels: header, background, scene template, asset info, time, appearance, alignment, export, layout, text, strokes, shadows, effects, animations, transition, masks | `components/sidebar-right/inspector/` |+| Panels: header, background, scene template, asset info, time, appearance, alignment, export, layout, text, strokes, shadows, effects, animations, transition, masks, audio | `components/sidebar-right/inspector/` || Local font families (web fonts and loading are the runtime's) | `engine/fonts.ts` (`getLocalFonts`) |Hosted JSX surface is `COMPOSITION_TAGS` (`packages/jsx/src/source.ts`): the structural tags, the media tags, `<captions>`, the paint family, `<stroke>`, `<shadow>`, `<effect>`, `<animation>`, `<keyframeTrack>`/`<keyframe>`, `<html>`/`<surface>`. `mask` is a `<rect>` prop, not a tag.@@ -95,7 +95,7 @@ Conventions worth repeating when migrating the next panel:- Reordering siblings is a swap through `editor.reparent`, not an index write: `ItemIndex` is the document's to assign (`insertNode` renumbers the whole sibling list), and a move needs an anchor, since `reparent` appends without one and refuses an append into the parent the element already has. So "move later" moves the *next* sibling in front of this one.- A shared control that knows *which* prop it edits keyframes it itself, off an `Entity` (`ColorOpacityPicker`'s `keyframeTarget`, now koota's); only a control that cannot know takes the diamond as a slot (`ControlledTextField`, `ColorOpacityRow`). Moving one of these moves it whole: the bitecs panels still calling it lose their diamonds until they migrate, and its recent-colors palette now queries the koota world for them too (both providers are mounted).-Still on bitecs: transform, caption-settings, fills, audio, interpolation panels; the timeline's keyframe layer; the whole timeline UI.+Still on bitecs: transform, caption-settings, fills, interpolation panels; the timeline's keyframe layer; the whole timeline UI.The stroke panel moved with the model: `StrokeStyle` is the stroke's, not the node's (as `<stroke width join cap miterLimit>` always was), so Weight/Join/Miter sit under each stroke's row instead of once per node. `<stroke>` is a solid paint that takes no paint children, so its picker is the color one alone, with no gradient or asset tab and no `FillPicker` behind it. `cap` still has no control (it shows only on open paths, and there are no icons for it).@@ -107,6 +107,10 @@ The transition panel is the odd one of the three: `transition` is a prop of theThe masks panel got shorter with the model. A mask is `<rect mask>`, a rect like any other, so it needs no inspector of its own: a row selects it and the transform, time and appearance panels are then its own. Three things the bitecs "Add mask" authored are gone with them: the white solid fill and the trim to the parent's window (a mask is never drawn, and without an `end` it already clips for the parent's whole window), and the `[Mask Shape]` name suffix, which was there for a timeline that could not tell a mask apart otherwise. What it still authors is the parent's own size (a mask without one is 500x500, which is what an empty group gets) at a 20px inset, so the new mask shows itself instead of landing invisibly on top of the parent. `Expanded` is not set on the parent: that is app-side timeline state the koota side has not picked up yet.+The audio panel kept its knob, meter and buttons; what moved is where they write. `volume` (decibels, unset at 0 since that is unity) and `muted` are props; **solo is not** — `Soloed` is a runtime-only tag with no JSX spelling, so the button writes the trait alone and the solo is gone on the next recompile, which is what a monitoring toggle should be. The knob writes whole decibels: it is what the field and the knob both display, and a dragged knob would otherwise mint a new fraction (and a new keyframe) per frame. The meter is unchanged, reading `AudioBusHandle` through `useTrait` (the playback system spins the bus up once the node has audio, and sets it back to null when the decoders are released, so the accessor holds null while the trait is still there).++**Known bug, not this panel's**: the `gain` animation writes a 0-1 linear ramp into `Computed.volume` (`motion.ts`, `AnimationType.GAIN`), which everything else reads as decibels (`audio-bus.ts` does `10 ** (db / 20)`). So a Volume animation ramps 0 dB to 1 dB, which is inaudible, instead of silence to unity. Carried over from bitecs; the fix is in the motion system, not in the panel.+The shadow panel kept the shape it had: a row per `<shadow>` opening a floating inspector, since nothing in the shadow model moved the way the stroke's line style did. The one thing it says that the file does not is what "Add shadow" authors (`opacity` 0.25, `blur` 4, `offsetY` 4): `<shadow>`'s own defaults are all zero, which casts the silhouette back onto itself, so a shadow added from the panel has to spell out where it sits. Every control unsets at the prop's default (0 for the offsets and the blur, 1 for opacity); `color` is required and always written.Two deliberate departures from the old text panel: `letterSpacing` is shown in px (the trait's unit and the prop's; the bitecs panel showed the same number as a percentage), and the font a text is set in — family, weight, size — is written out plainly rather than unset at its default, since a font is what a text *is* and not a modifier of it. `<captions>` has no host yet, so the caption half of the panel is unreachable and was carried over as it stood.