diff --git a/packages/core/src/runtime/audioFx.ts b/packages/core/src/runtime/audioFx.ts index cec709e7a8..d2b6789767 100644 --- a/packages/core/src/runtime/audioFx.ts +++ b/packages/core/src/runtime/audioFx.ts @@ -69,6 +69,18 @@ function readChain(el: { getAttribute?(name: string): string | null }): { } } +/** + * An element's automation lanes, bound to whatever chain it carries. + * + * FX lanes need the chain to resolve their target's range, so they are dropped + * for an element with no chain; a volume lane is always readable. + */ +export function readElementAutomation(el: { + getAttribute?(name: string): string | null; +}): HfAutomation { + return readAutomation(el, readChain(el).chain); +} + /** * Splice an element's FX chain between a decoded source and its gain stage. * diff --git a/packages/core/src/runtime/webAudioTransport.ts b/packages/core/src/runtime/webAudioTransport.ts index d77aa7152a..e2e2dc66ed 100644 --- a/packages/core/src/runtime/webAudioTransport.ts +++ b/packages/core/src/runtime/webAudioTransport.ts @@ -1,5 +1,10 @@ -import { attachElementFxChain, type ElementFxHandle } from "./audioFx.js"; -import type { AutomationTiming } from "../audio/audioFxAutomation.js"; +import { attachElementFxChain, readElementAutomation, type ElementFxHandle } from "./audioFx.js"; +import { + scheduleParamLane, + volumeLane, + type AutomationTiming, +} from "../audio/audioFxAutomation.js"; +import { VOLUME_RANGE } from "../audioAutomation.js"; import { swallow } from "./diagnostics"; import { getDebugSurface } from "./globals.js"; @@ -58,6 +63,20 @@ function startBoundedSource( return true; } +/** + * The volume lane rides the fader, after the effects — where a DAW puts it, + * and the order the render bakes it in. + */ +function scheduleVolumeLane( + el: HTMLMediaElement, + gainNode: GainNode, + timing: AutomationTiming, +): void { + const lane = volumeLane(readElementAutomation(el)); + if (!lane) return; + scheduleParamLane([{ param: gainNode.gain }], lane, VOLUME_RANGE.scale, timing); +} + export type ScheduledSource = { el: HTMLMediaElement; sourceNode: AudioBufferSourceNode; @@ -200,6 +219,8 @@ export class WebAudioTransport { const fx = attachElementFxChain(this._ctx, el, sourceNode, gainNode, timing); gainNode.connect(this._masterGain); + scheduleVolumeLane(el, gainNode, timing); + this._rate = safeRate; this._rateAnchorCtx = scheduledAt; this._rateAnchorComp = compositionTime;