@hyperframes/studio 0.9.56 → 0.9.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/hyperframes-player-bya4hgms.js +573 -0
- package/dist/assets/{index-yuN1pZrv.js → index--dcfSUzI.js} +1 -1
- package/dist/assets/{index-CgyBYe2L.js → index-Bxh5lW0C.js} +178 -178
- package/dist/assets/{pausedVideoDecoder-DtvSF8bV.js → pausedVideoDecoder-BKym1jA6.js} +1 -1
- package/dist/index.d.ts +88 -3
- package/dist/index.html +1 -1
- package/dist/index.js +912 -814
- package/package.json +8 -8
- package/src/components/nle/NLEPreview.test.ts +35 -3
- package/src/components/nle/NLEPreview.tsx +5 -4
- package/src/hooks/gsapRuntimePatch.ts +2 -3
- package/src/hooks/gsapRuntimeReaders.test.ts +5 -40
- package/src/hooks/gsapRuntimeReaders.ts +3 -27
- package/src/hooks/useExternalFileChangeCoordinator.test.tsx +20 -0
- package/src/hooks/useExternalFileChangeCoordinator.ts +1 -1
- package/src/hooks/useMusicBeatAnalysis.test.tsx +131 -0
- package/src/hooks/useMusicBeatAnalysis.ts +51 -66
- package/src/hooks/useRenderClipContent.test.ts +21 -0
- package/src/hooks/useRenderClipContent.ts +3 -1
- package/src/index.ts +18 -0
- package/src/player/components/studioShortcuts.ts +3 -2
- package/src/player/hooks/timelinePlayerTestHarness.ts +2 -0
- package/src/player/hooks/timelineSyncHydration.test.ts +28 -2
- package/src/player/hooks/timelineSyncHydration.ts +3 -7
- package/src/player/hooks/usePlaybackKeyboard.test.ts +107 -2
- package/src/player/hooks/usePlaybackKeyboard.ts +38 -1
- package/src/player/hooks/useShadowPreviewReload.ts +131 -14
- package/src/player/hooks/useTimelinePlayer.reloadStill.test.ts +241 -0
- package/src/player/hooks/useTimelinePlayer.ts +13 -1
- package/src/player/hooks/useTimelineSyncCallbacks.ts +4 -0
- package/src/player/lib/previewElements.test.ts +4 -0
- package/src/player/lib/previewElements.ts +1 -0
- package/src/sealedPreviewExports.test.ts +21 -0
- package/src/utils/externalConflictStorage.test.ts +66 -14
- package/src/utils/externalConflictStorage.ts +36 -82
- package/src/utils/gsapSoftReload.ts +2 -14
- package/src/utils/timelineInspector.test.ts +49 -2
- package/src/utils/timelineInspector.ts +21 -2
- package/dist/assets/hyperframes-player-SRLbmEDB.js +0 -565
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.59",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"dockview-react": "8.3.1",
|
|
65
65
|
"gsap": "^3.13.0",
|
|
66
66
|
"mediabunny": "^1.66.0",
|
|
67
|
-
"@hyperframes/core": "0.9.
|
|
68
|
-
"@hyperframes/parsers": "0.9.
|
|
69
|
-
"@hyperframes/sdk": "0.9.
|
|
70
|
-
"@hyperframes/
|
|
71
|
-
"@hyperframes/
|
|
72
|
-
"@hyperframes/
|
|
67
|
+
"@hyperframes/core": "0.9.59",
|
|
68
|
+
"@hyperframes/parsers": "0.9.59",
|
|
69
|
+
"@hyperframes/sdk": "0.9.59",
|
|
70
|
+
"@hyperframes/player": "0.9.59",
|
|
71
|
+
"@hyperframes/shader-transitions": "0.9.59",
|
|
72
|
+
"@hyperframes/studio-server": "0.9.59"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"vite": "^6.4.5",
|
|
87
87
|
"vitest": "^4.1.12",
|
|
88
88
|
"zustand": "^5.0.0",
|
|
89
|
-
"@hyperframes/producer": "0.9.
|
|
89
|
+
"@hyperframes/producer": "0.9.59"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"react": "19",
|
|
@@ -56,10 +56,9 @@ class MockResizeObserver {
|
|
|
56
56
|
constructor(cb: ResizeObserverCallback) {
|
|
57
57
|
this.cb = cb;
|
|
58
58
|
}
|
|
59
|
+
// A browser calls back at its next frame, never inside observe(); renderPreview fires them.
|
|
59
60
|
observe() {
|
|
60
|
-
|
|
61
|
-
resizeCallbacks.push(fire);
|
|
62
|
-
fire();
|
|
61
|
+
resizeCallbacks.push(() => this.cb([], this as unknown as ResizeObserver));
|
|
63
62
|
}
|
|
64
63
|
disconnect() {}
|
|
65
64
|
}
|
|
@@ -67,6 +66,8 @@ class MockResizeObserver {
|
|
|
67
66
|
const originalResizeObserver = globalThis.ResizeObserver;
|
|
68
67
|
|
|
69
68
|
function setRect(node: Element, rect: { width: number; height: number }) {
|
|
69
|
+
Object.defineProperty(node, "clientWidth", { configurable: true, value: rect.width });
|
|
70
|
+
Object.defineProperty(node, "clientHeight", { configurable: true, value: rect.height });
|
|
70
71
|
Object.defineProperty(node, "getBoundingClientRect", {
|
|
71
72
|
configurable: true,
|
|
72
73
|
value: () => ({
|
|
@@ -493,6 +494,37 @@ describe("NLEPreview", () => {
|
|
|
493
494
|
filled.cleanup();
|
|
494
495
|
});
|
|
495
496
|
|
|
497
|
+
it("sizes the stage within the resize callback, so the frame painted after a resize is never at the old size", () => {
|
|
498
|
+
const view = renderPreview(undefined, { box: { width: 640, height: 360 }, fillBox: true });
|
|
499
|
+
setRect(view.viewport, { width: 1920, height: 1080 });
|
|
500
|
+
// Outside act: the browser paints right after this callback returns.
|
|
501
|
+
for (const fire of resizeCallbacks) fire();
|
|
502
|
+
expect([view.stage.style.width, view.stage.style.height]).toEqual(["1920px", "1080px"]);
|
|
503
|
+
view.cleanup();
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it("sizes the stage from the box's own size while a host scales the box on screen", () => {
|
|
507
|
+
const view = renderPreview(undefined, { box: { width: 640, height: 360 }, fillBox: true });
|
|
508
|
+
setRect(view.viewport, { width: 1920, height: 1080 });
|
|
509
|
+
// A host growing the preview from a quarter of its size: on screen the box is 480 x 270 for now.
|
|
510
|
+
Object.defineProperty(view.viewport, "getBoundingClientRect", {
|
|
511
|
+
configurable: true,
|
|
512
|
+
value: () => ({
|
|
513
|
+
x: 0,
|
|
514
|
+
y: 0,
|
|
515
|
+
left: 0,
|
|
516
|
+
top: 0,
|
|
517
|
+
right: 480,
|
|
518
|
+
bottom: 270,
|
|
519
|
+
width: 480,
|
|
520
|
+
height: 270,
|
|
521
|
+
}),
|
|
522
|
+
});
|
|
523
|
+
for (const fire of resizeCallbacks) fire();
|
|
524
|
+
expect([view.stage.style.width, view.stage.style.height]).toEqual(["1920px", "1080px"]);
|
|
525
|
+
view.cleanup();
|
|
526
|
+
});
|
|
527
|
+
|
|
496
528
|
it("takes the host's composition size as the stage's shape until the preview measures its own", () => {
|
|
497
529
|
const box = { width: 800, height: 600 };
|
|
498
530
|
const plain = renderPreview(undefined, { box });
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
useState,
|
|
12
12
|
type RefObject,
|
|
13
13
|
} from "react";
|
|
14
|
+
import { flushSync } from "react-dom";
|
|
14
15
|
import { Player } from "../../player";
|
|
15
16
|
import { postFrameDisplayScale } from "../../player/lib/runtimeProtocol";
|
|
16
17
|
import type { NLEContextValue } from "./NLEContext";
|
|
@@ -148,11 +149,10 @@ export const NLEPreview = memo(function NLEPreview({
|
|
|
148
149
|
if (!viewport) return;
|
|
149
150
|
|
|
150
151
|
const updateStageSize = () => {
|
|
151
|
-
const rect = viewport.getBoundingClientRect();
|
|
152
152
|
setStageSize(
|
|
153
153
|
resolvePreviewStageSize(
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
viewport.clientWidth,
|
|
155
|
+
viewport.clientHeight,
|
|
156
156
|
compositionSize ??
|
|
157
157
|
(hintWidth && hintHeight ? { width: hintWidth, height: hintHeight } : null),
|
|
158
158
|
portrait,
|
|
@@ -163,7 +163,8 @@ export const NLEPreview = memo(function NLEPreview({
|
|
|
163
163
|
};
|
|
164
164
|
|
|
165
165
|
updateStageSize();
|
|
166
|
-
const
|
|
166
|
+
const resizeBeforePaint = () => flushSync(updateStageSize);
|
|
167
|
+
const observer = new ResizeObserver(resizeBeforePaint);
|
|
167
168
|
observer.observe(viewport);
|
|
168
169
|
return () => observer.disconnect();
|
|
169
170
|
}, [compositionSize, hintWidth, hintHeight, portrait, gutterPx, insetPx]);
|
|
@@ -250,9 +250,8 @@ function changeTouchesOpacity(change: RuntimeTweenChange): boolean {
|
|
|
250
250
|
|
|
251
251
|
/**
|
|
252
252
|
* A tween re-initialization (invalidate, or kill+recreate for keyframe-rebuild)
|
|
253
|
-
* captures opacity from the element's CURRENT inline style — for a
|
|
254
|
-
*
|
|
255
|
-
* runtime transient, not the authored value, and the capture makes it permanent.
|
|
253
|
+
* captures opacity from the element's CURRENT inline style — for a mid-flight
|
|
254
|
+
* tween that's a runtime transient, not the authored value, and the capture makes it permanent.
|
|
256
255
|
* Restore the runtime's parse-time authored capture (data-hf-authored-opacity)
|
|
257
256
|
* first; the re-seek after the patch re-renders the animated value anyway.
|
|
258
257
|
* Duck-typed (no instanceof): the targets live in the preview iframe's realm.
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
import { afterEach, describe, expect, it } from "vitest";
|
|
3
3
|
import { gsap } from "gsap";
|
|
4
4
|
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
|
|
5
|
-
import {
|
|
6
|
-
COLOR_GRADING_SOURCE_HIDDEN_ATTR,
|
|
7
|
-
HF_COLOR_GRADING_CANVAS_ID_PREFIX,
|
|
8
|
-
} from "@hyperframes/core/color-grading";
|
|
5
|
+
import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "@hyperframes/core/color-grading";
|
|
9
6
|
import { readAllAnimatedProperties, readGsapProperty } from "./gsapRuntimeReaders";
|
|
10
7
|
|
|
11
8
|
/**
|
|
@@ -68,46 +65,14 @@ describe("readAllAnimatedProperties group filter", () => {
|
|
|
68
65
|
});
|
|
69
66
|
|
|
70
67
|
describe("color-grading opacity truth", () => {
|
|
71
|
-
|
|
68
|
+
it("reads a graded source's opacity from GSAP, as for any element", () => {
|
|
72
69
|
const el = document.createElement("img");
|
|
73
70
|
el.id = "clip";
|
|
74
|
-
el.setAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR, "");
|
|
75
|
-
const canvas = document.createElement("canvas");
|
|
76
|
-
canvas.id = `${HF_COLOR_GRADING_CANVAS_ID_PREFIX}clip`;
|
|
77
|
-
canvas.style.opacity = "0.98";
|
|
78
|
-
document.body.append(el, canvas);
|
|
79
|
-
return el;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
it("resolves opacity from the grading canvas, not the runtime hide", () => {
|
|
83
|
-
const el = gradedElement();
|
|
84
|
-
const iframe = fakeIframe(el, { gsapValues: { opacity: 0 } });
|
|
85
|
-
const anim = {
|
|
86
|
-
id: "#clip-from-200-visual",
|
|
87
|
-
targetSelector: "#clip",
|
|
88
|
-
method: "from",
|
|
89
|
-
properties: { opacity: 0.5 },
|
|
90
|
-
} as unknown as GsapAnimation;
|
|
91
|
-
|
|
92
|
-
const result = readAllAnimatedProperties(iframe, "#clip", anim);
|
|
93
|
-
|
|
94
|
-
expect(result.opacity).toBe(0.98);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("readGsapProperty takes the same detour", () => {
|
|
98
|
-
const el = gradedElement();
|
|
99
|
-
const iframe = fakeIframe(el, { gsapValues: { opacity: 0 } });
|
|
100
|
-
|
|
101
|
-
expect(readGsapProperty(iframe, "#clip", "opacity")).toBe(0.98);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("reads GSAP directly when the source is not grading-hidden", () => {
|
|
105
|
-
const el = document.createElement("div");
|
|
106
|
-
el.id = "clip";
|
|
71
|
+
el.setAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR, "true");
|
|
107
72
|
document.body.appendChild(el);
|
|
108
|
-
const iframe = fakeIframe(el, { gsapValues: { opacity: 0.
|
|
73
|
+
const iframe = fakeIframe(el, { gsapValues: { opacity: 0.98 } });
|
|
109
74
|
|
|
110
|
-
expect(readGsapProperty(iframe, "#clip", "opacity")).toBe(0.
|
|
75
|
+
expect(readGsapProperty(iframe, "#clip", "opacity")).toBe(0.98);
|
|
111
76
|
});
|
|
112
77
|
});
|
|
113
78
|
|
|
@@ -3,34 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
|
|
5
5
|
import { classifyPropertyGroup, type PropertyGroupName } from "@hyperframes/core/gsap-parser";
|
|
6
|
-
import {
|
|
7
|
-
COLOR_GRADING_SOURCE_HIDDEN_ATTR,
|
|
8
|
-
HF_COLOR_GRADING_CANVAS_ID_PREFIX,
|
|
9
|
-
} from "@hyperframes/core/color-grading";
|
|
10
|
-
import { getIframeGsap, queryIframeElement, type IframeGsap } from "./gsapShared";
|
|
6
|
+
import { getIframeGsap, queryIframeElement } from "./gsapShared";
|
|
11
7
|
import { gsapWritesChannels } from "./gsapRuntimeKeyframes";
|
|
12
8
|
import { roundTo3 } from "../utils/rounding";
|
|
13
9
|
|
|
14
|
-
/**
|
|
15
|
-
* The element's live value for `prop` as GSAP drives it. Opacity on a
|
|
16
|
-
* color-grading-hidden source needs a detour: the runtime hides the source
|
|
17
|
-
* with inline `opacity: 0 !important`, so computed opacity is the hide, not
|
|
18
|
-
* the animated value. The grading canvas mirrors the source's effective
|
|
19
|
-
* opacity every frame, so it is the truth for that one property — reading the
|
|
20
|
-
* raw 0 here is what bakes `opacity: 0` into committed keyframes.
|
|
21
|
-
*/
|
|
22
|
-
function readLiveGsapValue(gsap: IframeGsap, el: Element, prop: string): number {
|
|
23
|
-
if (prop === "opacity" && el.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR) != null && el.id) {
|
|
24
|
-
const canvas = el.ownerDocument.getElementById(HF_COLOR_GRADING_CANVAS_ID_PREFIX + el.id);
|
|
25
|
-
const win = el.ownerDocument.defaultView;
|
|
26
|
-
if (canvas && win) {
|
|
27
|
-
const val = Number(win.getComputedStyle(canvas).opacity);
|
|
28
|
-
if (Number.isFinite(val)) return val;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return Number(gsap.getProperty(el, prop));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
10
|
export function readGsapProperty(
|
|
35
11
|
iframe: HTMLIFrameElement | null,
|
|
36
12
|
selector: string | null,
|
|
@@ -42,7 +18,7 @@ export function readGsapProperty(
|
|
|
42
18
|
const el = queryIframeElement(iframe, selector);
|
|
43
19
|
if (!el) return null;
|
|
44
20
|
try {
|
|
45
|
-
const val =
|
|
21
|
+
const val = Number(gsap.getProperty(el, prop));
|
|
46
22
|
if (!Number.isFinite(val)) return null;
|
|
47
23
|
return POSITION_PROPS.has(prop) ? Math.round(val) : roundTo3(val);
|
|
48
24
|
} catch {
|
|
@@ -89,7 +65,7 @@ export function readAllAnimatedProperties(
|
|
|
89
65
|
const groupedPropKeys = new Set([...propKeys].filter(inGroup));
|
|
90
66
|
|
|
91
67
|
for (const prop of groupedPropKeys) {
|
|
92
|
-
const val =
|
|
68
|
+
const val = Number(gsap.getProperty(el, prop));
|
|
93
69
|
if (Number.isFinite(val)) {
|
|
94
70
|
result[prop] = POSITION_PROPS.has(prop) ? Math.round(val) : roundTo3(val);
|
|
95
71
|
}
|
|
@@ -837,6 +837,26 @@ describe("external file change coordinator", () => {
|
|
|
837
837
|
});
|
|
838
838
|
});
|
|
839
839
|
|
|
840
|
+
// Studio settles which composition is open just after load, while the draft's file stays the same.
|
|
841
|
+
it("keeps a restored draft when the open composition changes but the draft's file does not", async () => {
|
|
842
|
+
const { captured, rerender } = await mountCoordinator({
|
|
843
|
+
recoveryFilePath: "index.html",
|
|
844
|
+
loadConflictSnapshot: vi.fn(async () => ({
|
|
845
|
+
kind: "conflict" as const,
|
|
846
|
+
projectId: "project-a",
|
|
847
|
+
filePath: "index.html",
|
|
848
|
+
externalVersion: "v2",
|
|
849
|
+
externalContent: "external",
|
|
850
|
+
studioContent: "studio",
|
|
851
|
+
createdAt: 100,
|
|
852
|
+
})),
|
|
853
|
+
});
|
|
854
|
+
await vi.waitFor(() => expect(captured.handle?.blocked?.status).toBe("conflict"));
|
|
855
|
+
|
|
856
|
+
await rerender({ activeCompPath: null });
|
|
857
|
+
await vi.waitFor(() => expect(captured.handle?.blocked?.status).toBe("conflict"));
|
|
858
|
+
});
|
|
859
|
+
|
|
840
860
|
it("retains the final local candidate when a drain fails", async () => {
|
|
841
861
|
const failure = new Error("network unavailable");
|
|
842
862
|
const persistFailureSnapshot = vi.fn(async () => undefined);
|
|
@@ -248,7 +248,7 @@ export function useExternalFileChangeCoordinator({
|
|
|
248
248
|
return () => {
|
|
249
249
|
cancelled = true;
|
|
250
250
|
};
|
|
251
|
-
}, [loadConflictSnapshot, projectId, recoveryFilePath, setBlocked]);
|
|
251
|
+
}, [loadConflictSnapshot, projectId, activeCompPath, recoveryFilePath, setBlocked]);
|
|
252
252
|
|
|
253
253
|
// What a settled change owes: thumbnails (unless its own write's echo brings them), then reloads.
|
|
254
254
|
const deliverOwed = useCallback(
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import React, { act } from "react";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import type { TimelineElement } from "../player";
|
|
5
|
+
import { usePlayerStore } from "../player/store/playerStore";
|
|
6
|
+
import { FileManagerProvider } from "../contexts/FileManagerContext";
|
|
7
|
+
import { mountReactHarness } from "./domSelectionTestHarness";
|
|
8
|
+
|
|
9
|
+
const analyze = vi.hoisted(() => vi.fn());
|
|
10
|
+
vi.mock("@hyperframes/core/beats", async (actual) => ({
|
|
11
|
+
...(await actual<typeof import("@hyperframes/core/beats")>()),
|
|
12
|
+
analyzeMusicFromUrl: analyze,
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const { useMusicBeatAnalysis } = await import("./useMusicBeatAnalysis");
|
|
16
|
+
const { serializeBeats } = await import("@hyperframes/core/beats");
|
|
17
|
+
|
|
18
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
19
|
+
|
|
20
|
+
const clip = (overrides: Partial<TimelineElement>) =>
|
|
21
|
+
({
|
|
22
|
+
id: "talk",
|
|
23
|
+
domId: "talk",
|
|
24
|
+
key: "talk",
|
|
25
|
+
tag: "audio",
|
|
26
|
+
src: "assets/talk.m4a",
|
|
27
|
+
start: 0,
|
|
28
|
+
duration: 180,
|
|
29
|
+
track: 3,
|
|
30
|
+
...overrides,
|
|
31
|
+
}) as TimelineElement;
|
|
32
|
+
|
|
33
|
+
let savedBeats = "";
|
|
34
|
+
const files = {
|
|
35
|
+
readOptionalProjectFile: async () => savedBeats,
|
|
36
|
+
writeProjectFile: async () => {},
|
|
37
|
+
} as unknown as React.ComponentProps<typeof FileManagerProvider>["value"];
|
|
38
|
+
|
|
39
|
+
function Probe() {
|
|
40
|
+
useMusicBeatAnalysis();
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Studio's timeline opened on `elements`: which files beat analysis decoded, and the beat times it shows. The hook
|
|
45
|
+
* caches an analysis per file, so each case names its own. */
|
|
46
|
+
async function opened(elements: TimelineElement[]) {
|
|
47
|
+
usePlayerStore.setState({ elements, beatAnalysis: null });
|
|
48
|
+
const root = mountReactHarness(
|
|
49
|
+
<FileManagerProvider value={files}>
|
|
50
|
+
<Probe />
|
|
51
|
+
</FileManagerProvider>,
|
|
52
|
+
);
|
|
53
|
+
await act(async () => {
|
|
54
|
+
for (let i = 0; i < 5; i += 1) await Promise.resolve();
|
|
55
|
+
});
|
|
56
|
+
const beats = usePlayerStore.getState().beatAnalysis?.beatTimes ?? null;
|
|
57
|
+
act(() => root.unmount());
|
|
58
|
+
return { decoded: analyze.mock.calls.map(([src]) => src), beats };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
beforeEach(() => {
|
|
62
|
+
savedBeats = "";
|
|
63
|
+
analyze.mockReset();
|
|
64
|
+
analyze.mockResolvedValue({ beatTimes: [1, 2], beatStrengths: [1, 1], bpm: 120 });
|
|
65
|
+
});
|
|
66
|
+
afterEach(() =>
|
|
67
|
+
usePlayerStore.setState({ elements: [], beatEdits: null, beatUndo: [], beatRedo: [] }),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// fails without the fix: a 62-minute recording with no role was picked as the music and decoded whole (1.4 GB on
|
|
71
|
+
// a Mac, which ran a person's page out of memory while their talk was still being transcribed).
|
|
72
|
+
describe("beat analysis decodes only a file no longer than a song", () => {
|
|
73
|
+
it("leaves a 62-minute unlabelled recording alone", async () => {
|
|
74
|
+
const talk = clip({ src: "assets/talk.m4a", duration: 3720, sourceDuration: 3720 });
|
|
75
|
+
expect((await opened([talk])).decoded).toEqual([]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("leaves a 3-minute clip of a 62-minute file alone, since the decode reads the whole file", async () => {
|
|
79
|
+
const cut = clip({ src: "assets/cut.m4a", duration: 180, sourceDuration: 3720 });
|
|
80
|
+
expect((await opened([cut])).decoded).toEqual([]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("leaves a recording alone while its file's length is unknown", async () => {
|
|
84
|
+
expect((await opened([clip({ src: "assets/unread.m4a", duration: 180 })])).decoded).toEqual([]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("shows a 62-minute music track's saved beats without decoding it", async () => {
|
|
88
|
+
savedBeats = serializeBeats([1, 2], [1, 1], "assets/mix.m4a");
|
|
89
|
+
const mix = clip({
|
|
90
|
+
src: "assets/mix.m4a",
|
|
91
|
+
timelineRole: "music",
|
|
92
|
+
duration: 3720,
|
|
93
|
+
sourceDuration: 3720,
|
|
94
|
+
});
|
|
95
|
+
expect(await opened([mix])).toEqual({ decoded: [], beats: [1, 2] });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("still finds the beats of a 3-minute song", async () => {
|
|
99
|
+
const song = clip({ src: "assets/song.mp3", sourceDuration: 180 });
|
|
100
|
+
expect(await opened([song])).toEqual({ decoded: ["assets/song.mp3"], beats: [1, 2] });
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// fails without the fix: the length arriving after the saved beats showed loaded the track again, which dropped the
|
|
105
|
+
// person's beat edit and its undo.
|
|
106
|
+
it("keeps a music track's beat edits and undo when its file's length arrives", async () => {
|
|
107
|
+
savedBeats = serializeBeats([1, 2], [1, 1], "assets/edited.m4a");
|
|
108
|
+
const music = { src: "assets/edited.m4a", timelineRole: "music" as const, duration: 180 };
|
|
109
|
+
const settle = () =>
|
|
110
|
+
act(async () => {
|
|
111
|
+
for (let i = 0; i < 5; i += 1) await Promise.resolve();
|
|
112
|
+
});
|
|
113
|
+
usePlayerStore.setState({ elements: [clip(music)], beatAnalysis: null, beatEdits: null });
|
|
114
|
+
const root = mountReactHarness(
|
|
115
|
+
<FileManagerProvider value={files}>
|
|
116
|
+
<Probe />
|
|
117
|
+
</FileManagerProvider>,
|
|
118
|
+
);
|
|
119
|
+
await settle();
|
|
120
|
+
const edit = { src: "assets/edited.m4a", added: [{ time: 1.5, strength: 1 }], removed: [] };
|
|
121
|
+
act(() => usePlayerStore.getState().commitBeatEdits(edit, "add beat"));
|
|
122
|
+
act(() => usePlayerStore.setState({ elements: [clip({ ...music, sourceDuration: 180 })] }));
|
|
123
|
+
await settle();
|
|
124
|
+
const { beatEdits, beatUndo, beatAnalysis } = usePlayerStore.getState();
|
|
125
|
+
act(() => root.unmount());
|
|
126
|
+
expect({ beatEdits, undo: beatUndo.length, beats: beatAnalysis?.beatTimes }).toEqual({
|
|
127
|
+
beatEdits: edit,
|
|
128
|
+
undo: 1,
|
|
129
|
+
beats: [1, 2],
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import { usePlayerStore } from "../player/store/playerStore";
|
|
3
|
-
import { resolveBeatSourceTrack } from "../utils/timelineInspector";
|
|
3
|
+
import { fitsBeatAnalysis, resolveBeatSourceTrack } from "../utils/timelineInspector";
|
|
4
4
|
import { analyzeMusicFromUrl } from "@hyperframes/core/beats";
|
|
5
5
|
import { whenTimelineIdle } from "../player/components/timelineMotion";
|
|
6
6
|
import { useFileManagerContextOptional } from "../contexts/FileManagerContext";
|
|
@@ -32,67 +32,66 @@ function cacheAnalysis(url: string, promise: ReturnType<typeof analyzeMusicFromU
|
|
|
32
32
|
|
|
33
33
|
type ProjectIo = { readOptionalProjectFile: (p: string) => Promise<string> };
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
* Resolve the effective beat list for a track: a saved file with real beats
|
|
37
|
-
* wins; otherwise the detected beats are used (and `hasFile` is false so the
|
|
38
|
-
* caller seeds a new file). An empty saved file is ignored so detection retries.
|
|
39
|
-
*/
|
|
40
|
-
async function resolveBeats(
|
|
41
|
-
beatPath: string | null,
|
|
42
|
-
detected: { times: number[]; strengths: number[] },
|
|
43
|
-
io: ProjectIo,
|
|
44
|
-
): Promise<{ times: number[]; strengths: number[]; hasFile: boolean }> {
|
|
45
|
-
if (!beatPath) return { ...detected, hasFile: false };
|
|
46
|
-
try {
|
|
47
|
-
const content = await io.readOptionalProjectFile(beatPath);
|
|
48
|
-
const parsed = content ? parseBeats(content) : null;
|
|
49
|
-
if (parsed && parsed.times.length > 0) {
|
|
50
|
-
return { times: parsed.times, strengths: parsed.strengths, hasFile: true };
|
|
51
|
-
}
|
|
52
|
-
} catch {
|
|
53
|
-
/* fall back to detected beats */
|
|
54
|
-
}
|
|
55
|
-
return { ...detected, hasFile: false };
|
|
56
|
-
}
|
|
35
|
+
type Beats = { times: number[]; strengths: number[] };
|
|
57
36
|
|
|
58
|
-
/**
|
|
59
|
-
async function
|
|
37
|
+
/** The track's saved beats file, or null when it is missing, unreadable or holds no beat (detection then retries). */
|
|
38
|
+
async function readSavedBeats(io: ProjectIo, beatPath: string): Promise<Beats | null> {
|
|
60
39
|
try {
|
|
61
40
|
const content = await io.readOptionalProjectFile(beatPath);
|
|
62
41
|
const parsed = content ? parseBeats(content) : null;
|
|
63
|
-
return
|
|
42
|
+
return parsed && parsed.times.length > 0
|
|
43
|
+
? { times: parsed.times, strengths: parsed.strengths }
|
|
44
|
+
: null;
|
|
64
45
|
} catch {
|
|
65
|
-
return
|
|
46
|
+
return null;
|
|
66
47
|
}
|
|
67
48
|
}
|
|
68
49
|
|
|
69
50
|
type MusicAnalysis = Awaited<ReturnType<typeof analyzeMusicFromUrl>>;
|
|
70
51
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*/
|
|
76
|
-
async function loadBeatAnalysis(
|
|
77
|
-
musicSrc: string,
|
|
78
|
-
beatPath: string,
|
|
79
|
-
io: ProjectIo,
|
|
80
|
-
): Promise<{ analysis: MusicAnalysis; times: number[]; strengths: number[] } | null> {
|
|
52
|
+
type Loaded = { analysis: MusicAnalysis } & Beats;
|
|
53
|
+
|
|
54
|
+
/** A track's analysis (memoized per URL), or null when decode or analysis fails. */
|
|
55
|
+
async function decodeTrack(musicSrc: string): Promise<MusicAnalysis | null> {
|
|
81
56
|
let promise = analysisCache.get(musicSrc);
|
|
82
57
|
if (!promise) {
|
|
83
58
|
promise = analyzeMusicFromUrl(musicSrc, { pause: whenTimelineIdle });
|
|
84
59
|
cacheAnalysis(musicSrc, promise);
|
|
85
60
|
}
|
|
86
|
-
|
|
87
|
-
const analysis = await promise;
|
|
88
|
-
const detected = { times: analysis.beatTimes, strengths: analysis.beatStrengths };
|
|
89
|
-
const { times, strengths } = await resolveBeats(beatPath, detected, io);
|
|
90
|
-
return { analysis, times, strengths };
|
|
91
|
-
} catch {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
61
|
+
return promise.catch(() => null);
|
|
94
62
|
}
|
|
95
63
|
|
|
64
|
+
/** What a track shows. A fallback track (audio dropped in with no role) is analysed so the Beat tool works at once; a
|
|
65
|
+
* marked music track only once the person saved beats for it, so unrelated assets add no beat lines. A file that does
|
|
66
|
+
* not fit the decode keeps its saved beats, with no strengths measured from the audio. */
|
|
67
|
+
async function loadTrack(
|
|
68
|
+
musicSrc: string,
|
|
69
|
+
beatPath: string,
|
|
70
|
+
io: ProjectIo,
|
|
71
|
+
isFallbackTrack: boolean,
|
|
72
|
+
decodable: boolean,
|
|
73
|
+
): Promise<Loaded | null> {
|
|
74
|
+
const saved = await readSavedBeats(io, beatPath);
|
|
75
|
+
if (!isFallbackTrack && !saved) return null;
|
|
76
|
+
if (!decodable) return saved && { analysis: savedOnly(saved), ...saved };
|
|
77
|
+
const analysis = await decodeTrack(musicSrc);
|
|
78
|
+
if (!analysis) return null;
|
|
79
|
+
return {
|
|
80
|
+
analysis,
|
|
81
|
+
...(saved ?? { times: analysis.beatTimes, strengths: analysis.beatStrengths }),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const savedOnly = ({ times, strengths }: Beats): MusicAnalysis => ({
|
|
86
|
+
beatTimes: times,
|
|
87
|
+
beatStrengths: strengths,
|
|
88
|
+
bpm: null,
|
|
89
|
+
bpmConfidence: "uncertain",
|
|
90
|
+
channelData: null,
|
|
91
|
+
sampleRate: 0,
|
|
92
|
+
peak: 0,
|
|
93
|
+
});
|
|
94
|
+
|
|
96
95
|
/** The current beat analysis, remapped onto the composition's edited beat grid. */
|
|
97
96
|
export function useAdjustedBeatAnalysis() {
|
|
98
97
|
const beatAnalysis = usePlayerStore((s) => s.beatAnalysis);
|
|
@@ -123,16 +122,19 @@ export function useMusicBeatAnalysis(): void {
|
|
|
123
122
|
? { readOptionalProjectFile, writeProjectFile }
|
|
124
123
|
: null;
|
|
125
124
|
|
|
126
|
-
const { musicSrc, isFallbackTrack } = useMemo(() => {
|
|
125
|
+
const { musicSrc, isFallbackTrack, decodable } = useMemo(() => {
|
|
127
126
|
const resolved = resolveBeatSourceTrack(elements);
|
|
128
127
|
return {
|
|
129
128
|
musicSrc: resolved?.element.src ?? null,
|
|
130
129
|
isFallbackTrack: resolved?.isFallback ?? false,
|
|
130
|
+
decodable: resolved ? fitsBeatAnalysis(resolved.element) : false,
|
|
131
131
|
};
|
|
132
132
|
}, [elements]);
|
|
133
|
+
// Read at load, never a reason to load again: a file length arriving for the same track must keep its edits.
|
|
134
|
+
const decodableRef = useRef(decodable);
|
|
135
|
+
decodableRef.current = decodable;
|
|
133
136
|
|
|
134
|
-
// ── Load:
|
|
135
|
-
// otherwise seed it from detection. Resets edits + history on track change. ──
|
|
137
|
+
// ── Load: the track's beats (loadTrack). Resets edits + history on track change. ──
|
|
136
138
|
useEffect(() => {
|
|
137
139
|
if (!musicSrc) {
|
|
138
140
|
setBeatAnalysis(null);
|
|
@@ -150,26 +152,9 @@ export function useMusicBeatAnalysis(): void {
|
|
|
150
152
|
const beatPath = beatFilePathForSrc(musicSrc);
|
|
151
153
|
const io = ioRef.current;
|
|
152
154
|
|
|
153
|
-
// For explicitly tagged/named music tracks: only run expensive audio decode
|
|
154
|
-
// + beat analysis when the user has an explicit beats file saved. Without
|
|
155
|
-
// one, skip entirely — no surprise green lines on the timeline after
|
|
156
|
-
// dragging unrelated assets.
|
|
157
|
-
//
|
|
158
|
-
// For fallback tracks (audio dropped from Finder with no role/music-id):
|
|
159
|
-
// always run analysis so the Beat tool becomes usable immediately.
|
|
160
155
|
(async () => {
|
|
161
156
|
if (!beatPath || !io) return;
|
|
162
|
-
|
|
163
|
-
const hasSavedBeats = await readHasSavedBeats(io, beatPath);
|
|
164
|
-
if (cancelled) return;
|
|
165
|
-
if (!hasSavedBeats) {
|
|
166
|
-
setBeatAnalysis(null);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (cancelled) return;
|
|
171
|
-
|
|
172
|
-
const result = await loadBeatAnalysis(musicSrc, beatPath, io);
|
|
157
|
+
const result = await loadTrack(musicSrc, beatPath, io, isFallbackTrack, decodableRef.current);
|
|
173
158
|
if (cancelled) return;
|
|
174
159
|
if (!result) {
|
|
175
160
|
setBeatAnalysis(null);
|
|
@@ -190,6 +190,27 @@ describe("useRenderClipContent", () => {
|
|
|
190
190
|
if (isValidElement(content)) expect(content.type).toBe(AudioWaveform);
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
+
it("decodes a file from outside the project only when it is short and its length is known", () => {
|
|
194
|
+
const remote = (sourceDuration?: number) =>
|
|
195
|
+
renderClipContent({
|
|
196
|
+
id: "talk",
|
|
197
|
+
tag: "audio",
|
|
198
|
+
start: 0,
|
|
199
|
+
duration: 4,
|
|
200
|
+
track: 1,
|
|
201
|
+
src: "https://cdn.example.com/talk.mp3",
|
|
202
|
+
sourceDuration,
|
|
203
|
+
});
|
|
204
|
+
const audioUrlOf = (content: ReactNode) =>
|
|
205
|
+
isValidElement<{ audioUrl: string; waveformUrl?: string }>(content)
|
|
206
|
+
? [content.props.audioUrl, content.props.waveformUrl]
|
|
207
|
+
: null;
|
|
208
|
+
|
|
209
|
+
expect(audioUrlOf(remote(180))).toEqual(["https://cdn.example.com/talk.mp3", undefined]);
|
|
210
|
+
expect(audioUrlOf(remote(62 * 60))).toEqual(["", undefined]);
|
|
211
|
+
expect(audioUrlOf(remote())).toEqual(["", undefined]);
|
|
212
|
+
});
|
|
213
|
+
|
|
193
214
|
it("routes root-relative iframe media back through the active project", () => {
|
|
194
215
|
usePlayerStore.setState({ thumbnailMode: "adaptive" });
|
|
195
216
|
const resolvedRootMedia = `${window.location.origin}/assets/clip.mp4`;
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
import { usePlayerStore } from "../player/store/playerStore";
|
|
26
26
|
import { thumbnailRevisionOf } from "../player/store/thumbnailSlice";
|
|
27
27
|
import { effectiveThumbnailMode } from "../player/lib/thumbnailPolicy";
|
|
28
|
+
import { fitsBeatAnalysis } from "../utils/timelineInspector";
|
|
28
29
|
|
|
29
30
|
export function normalizeCompositionSrc(
|
|
30
31
|
compSrc: string,
|
|
@@ -84,8 +85,9 @@ function renderAudioClip(
|
|
|
84
85
|
? buildProjectApiPath(pid, `/waveform/${encodedRelative}`)
|
|
85
86
|
: undefined;
|
|
86
87
|
const { start, end } = trimFractions(el);
|
|
88
|
+
const serverPeaksOrShortFile = waveformUrl !== undefined || fitsBeatAnalysis(el);
|
|
87
89
|
const waveform = createElement(AudioWaveform, {
|
|
88
|
-
audioUrl,
|
|
90
|
+
audioUrl: serverPeaksOrShortFile ? audioUrl : "",
|
|
89
91
|
waveformUrl,
|
|
90
92
|
label: "",
|
|
91
93
|
labelColor,
|
package/src/index.ts
CHANGED
|
@@ -46,6 +46,24 @@ export {
|
|
|
46
46
|
} from "./player";
|
|
47
47
|
export { usePreviewIframeStore } from "./player/store/previewIframeStore";
|
|
48
48
|
export { previewEditingClient, previewFrameOpaque } from "./player/lib/previewChannel";
|
|
49
|
+
export {
|
|
50
|
+
describePreviewElements,
|
|
51
|
+
previewAncestors,
|
|
52
|
+
previewElementsAtPoint,
|
|
53
|
+
previewGeometry,
|
|
54
|
+
previewLayers,
|
|
55
|
+
previewPointerTargets,
|
|
56
|
+
queryPreviewElements,
|
|
57
|
+
type PreviewElement,
|
|
58
|
+
type PreviewElementHit,
|
|
59
|
+
} from "./player/lib/previewElements";
|
|
60
|
+
export {
|
|
61
|
+
findPreviewElementForSelection,
|
|
62
|
+
findPreviewElementForTimelineElement,
|
|
63
|
+
readable,
|
|
64
|
+
standInFor,
|
|
65
|
+
standInHandle,
|
|
66
|
+
} from "./components/editor/previewSelection";
|
|
49
67
|
export { PREVIEW_QUALITY_LEVELS, type PreviewQuality } from "@hyperframes/core/preview-quality";
|
|
50
68
|
export type {
|
|
51
69
|
PlaybackHealth,
|