mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
* fix(core): harden audio FX and group identity * fix(core): address audio group review feedback * fix(core): align preview transport with grouped audio * test(core): pin audio group gain ceiling * fix(core): preserve solo bridge through stack * fix(engine): harden grouped audio rendering * docs(engine): explain grouped mix fallback invariant * test(engine): allow grouped mixes to finish on Windows * feat(lint): validate audio group membership and timing * test(lint): pin audio group membership guards * fix(studio): unify audio IDs and group state * fix(studio): make audio-group edits transactional * fix(studio): keep preview state synchronized
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
/**
|
|
* The playhead in composition seconds, live while the transport runs.
|
|
*
|
|
* The RAF loop deliberately does not push every frame through the store — it
|
|
* notifies `liveTime` instead, so the playhead can move without re-rendering the
|
|
* app. A panel that wants to follow it therefore has to subscribe itself, and
|
|
* throttle: 30 Hz reads as continuous and costs an order of magnitude less than a
|
|
* render per frame.
|
|
*
|
|
* Paused, the store is the truth — a seek or a scrub lands there — so this returns
|
|
* that instead, which is what lets a readout follow the playhead while it is being
|
|
* dragged as well as while it is playing.
|
|
*/
|
|
import { useEffect, useRef, useState } from "react";
|
|
// The store's own module, not the `player` barrel: the barrel pulls the whole
|
|
// timeline in, and a timeline component importing this hook closes a cycle.
|
|
import { liveTime, usePlayerStore } from "../player/store/playerStore";
|
|
|
|
/** Long enough to be much cheaper than a frame, short enough to read as motion. */
|
|
const THROTTLE_MS = 33;
|
|
|
|
export function useLivePlayheadTime(): number {
|
|
const storeTime = usePlayerStore((s) => s.currentTime);
|
|
const isPlaying = usePlayerStore((s) => s.isPlaying);
|
|
const liveRef = useRef(storeTime);
|
|
const [, forceRender] = useState(0);
|
|
|
|
// Paused, the ref tracks the store so the first frame of playback is never a
|
|
// stale value from the last time the transport ran.
|
|
if (!isPlaying) liveRef.current = storeTime;
|
|
|
|
useEffect(() => {
|
|
if (!isPlaying) return;
|
|
let timerId: ReturnType<typeof setTimeout> | 0 = 0;
|
|
const unsubscribe = liveTime.subscribe((t) => {
|
|
liveRef.current = t;
|
|
if (!timerId) {
|
|
timerId = setTimeout(() => {
|
|
timerId = 0;
|
|
forceRender((v) => v + 1);
|
|
}, THROTTLE_MS);
|
|
}
|
|
});
|
|
return () => {
|
|
unsubscribe();
|
|
if (timerId) clearTimeout(timerId);
|
|
};
|
|
}, [isPlaying]);
|
|
|
|
return isPlaying ? liveRef.current : storeTime;
|
|
}
|