@hyperframes/studio 0.9.58 → 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-ww7-RmuM.js → index--dcfSUzI.js} +1 -1
- package/dist/assets/{index-D7ICtobF.js → index-Bxh5lW0C.js} +117 -117
- package/dist/assets/{pausedVideoDecoder-Dbe8Cmab.js → pausedVideoDecoder-BKym1jA6.js} +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.html +1 -1
- package/dist/index.js +45 -40
- package/package.json +8 -8
- 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 +1 -0
- package/src/player/lib/previewElements.test.ts +4 -0
- package/src/player/lib/previewElements.ts +1 -0
- package/src/sealedPreviewExports.test.ts +1 -0
- package/src/utils/timelineInspector.test.ts +49 -2
- package/src/utils/timelineInspector.ts +21 -2
- package/dist/assets/hyperframes-player-B78JDyI_.js +0 -565
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Input as V,ALL_FORMATS as G,UrlSource as K,VideoSampleSink as Q}from"./index
|
|
1
|
+
import{Input as V,ALL_FORMATS as G,UrlSource as K,VideoSampleSink as Q}from"./index--dcfSUzI.js";import{l as X}from"./index-Bxh5lW0C.js";const x=1e-5,k=1e-9,T=h=>!h.variableFrameRate&&(h.frameRate??0)>0;function Y(h,s){const{sourceLead:r,inputLead:l,timeResolution:d,frameRate:p=0}=s;if(!T(s))return Math.max(l,h-r+l)+k;const w=Math.max(0,Math.floor((h-r)*p+k)),f=l+w/p;return(d>0?Math.round(f*d)/d:f)+x}function J(h,s,r){const{frameRate:l=0,sourceLead:d,inputLead:p}=r,w=T(r)?Math.round((h-p)*l)/l+d:h-p+d,f=Math.min(s,w);return{timestamp:f,duration:Math.max(T(r)?1/l:0,s-f+x)}}const E=64*1024*1024,M=4,Z=.5,$=2e3;async function q(h,s){if(!h.transparent)return h.sink.getSample(s);let r=null;try{for await(const l of h.sink.samplesAtTimestamps([s]))r==null||r.close(),r=l;return r}catch(l){throw r==null||r.close(),l}}function ot(h){const s=new Map,r=new Map,l=new Map,d=new Map,p=new Map;let w=0,f=!1;const _=t=>{var o,n;let e=new URL(t,location.href).pathname;try{e=decodeURIComponent(e)}catch{}return(n=Object.entries(((o=h.contentWindow)==null?void 0:o.__HF_MEDIA_SOURCE_FACTS__)??{}).filter(([i])=>e.endsWith(i)).sort(([i],[a])=>a.length-i.length)[0])==null?void 0:n[1]},b=(t=E)=>{for(const[e,o]of p){if(w<=t)break;e.pins>0||(p.delete(e),o.cache.delete(e.timestamp),w-=e.bytes,e.image.close())}},v=async t=>{if(t.disposed)return;t.disposed=!0,clearTimeout(t.idleTimer),r.get(t.key)===t&&r.delete(t.key);const e=(async()=>{t.transparent&&await t.tail,t.cancelReads(),t.input.dispose(),await y(t).catch(()=>{});for(const o of t.cache.values())p.delete(o),w-=o.bytes,o.image.close();t.cache.clear(),t.canvas.width=t.canvas.height=0})();return t.transparent?new Promise((o,n)=>{const i=setTimeout(()=>{t.cancelReads(),o()},$);e.then(o,n).finally(()=>clearTimeout(i))}):e},P=t=>{clearTimeout(t.idleTimer),!(t.disposed||t.users>0||[...t.cache.values()].some(e=>e.pins>0))&&(t.idleTimer=setTimeout(()=>{t.users>0||[...t.cache.values()].some(e=>e.pins>0)||r.get(t.key)===t&&(s.delete(t.key),v(t))},1e4))},D=async t=>{const e=X("thumbnail"),o=new V({source:new K(t,e),formats:G});l.set(o,e.cancelReads);try{const n=await o.getPrimaryVideoTrack();if(!n||f)throw new Error("Preview video unavailable");const[i,a,u,c,m,S,F,B,j]=await Promise.all([n.getDisplayWidth(),n.getDisplayHeight(),n.getFirstTimestamp(),n.getTimeResolution(),n.getSquarePixelWidth(),n.getSquarePixelHeight(),n.getRotation(),n.getFlip(),n.canBeTransparent()]),g=document.createElement("canvas");g.width=Math.max(1,Math.ceil(i));const z=F%180===0?m/S:S/m;return g.height=Math.max(1,Math.round(g.width/z)),{key:t,input:o,cancelReads:e.cancelReads,sink:new Q(n),canvas:g,rotation:F,flip:B,width:i,height:a,lead:u,ticks:c,transparent:j,tail:Promise.resolve(),iterator:null,iteratorEnd:0,lastTime:-1/0,cache:new Map,users:0,disposed:!1}}catch(n){throw o.dispose(),e.cancelReads(),n}finally{l.delete(o)}},I=()=>{for(const[t]of s){if(s.size<M)break;const e=r.get(t);e&&e.users===0&&![...e.cache.values()].some(o=>o.pins>0)&&(s.delete(t),v(e))}if(s.size>=M)throw new Error("Preview decoder budget reached")},L=async t=>{const e=t;if((d.get(e)??0)>performance.now())throw new Error("Preview decoder cooling down");let o=s.get(e);o||(I(),o=D(t),s.set(e,o)),s.delete(e),s.set(e,o);let n;try{n=await o}catch(i){throw s.get(e)===o&&(s.delete(e),d.set(e,performance.now()+5e3)),i}if(f||n.disposed)throw new DOMException("Preview disposed","AbortError");return r.set(e,n),n.users++,clearTimeout(n.idleTimer),n},y=async t=>{const e=t.iterator;t.iterator=null,await(e==null?void 0:e.return())},R=(t,e)=>{if(e.throwIfAborted(),f||t.disposed)throw new Error("Preview disposed")},O=async(t,e,o)=>{for(t.iterator||(t.iteratorEnd=e+8,t.iterator=t.sink.samples(e,t.iteratorEnd));;){R(t,o);const n=await t.iterator.next();if(n.done)return null;const i=n.value;let a=!1;try{if(R(t,o),i.timestamp>e+1e-6)return null;if(a=i.timestamp+i.duration>e+1e-6,a)return i}finally{a||i.close()}}},A=(t,e)=>(e.pins++,p.delete(e),p.set(e,t),e),W=async(t,e,o,n,i)=>{const a=t.canvas.getContext("2d",{alpha:!0});if(!a)throw new Error("Preview canvas unavailable");a.clearRect(0,0,t.canvas.width,t.canvas.height),a.imageSmoothingQuality="high",e.drawWithFit(a,{fit:"fill",rotation:t.rotation,flip:t.flip});const u=await createImageBitmap(t.canvas);if(i.aborted||f||t.disposed)throw u.close(),i.throwIfAborted(),new Error("Preview disposed");const c={image:u,...J(e.timestamp,o,n),bytes:u.width*u.height*4,pins:1},m=t.cache.get(c.timestamp);if(m)return m.duration=Math.max(m.duration,c.duration),u.close(),A(t,m);if(b(E-c.bytes),w+c.bytes>E)throw u.close(),new Error("Preview frame budget reached");return t.cache.set(c.timestamp,c),p.set(c,t),w+=c.bytes,c},U=(t,e,o)=>!t.transparent&&!o.variableFrameRate&&(o.frameRate??0)>0&&e>t.lastTime+1e-6&&e-t.lastTime<=Z,C=async(t,e,o,n)=>{R(t,n);const i=[...t.cache.values()].find(m=>e>=m.timestamp-1e-6&&e<m.timestamp+m.duration-1e-6);if(i)return A(t,i);const a=Y(e,o),u=U(t,e,o);let c=null;try{if((!u||a>=t.iteratorEnd)&&await y(t),c=u?await O(t,a,n):null,c||(await y(t),c=await q(t,a)),!c)throw new Error("No preview frame at requested time");return R(t,n),t.lastTime=e,await W(t,c,e,o,n)}finally{c==null||c.close(),(n.aborted||f)&&await y(t).catch(()=>{})}},H=(t,e)=>{const o=_(t.source);return{frameRate:o==null?void 0:o.frameRate,variableFrameRate:o==null?void 0:o.variableFrameRate,sourceLead:e.lead,inputLead:e.lead,timeResolution:e.ticks}},N=async(t,e)=>{e.throwIfAborted();const o=t.source;if(!o)throw new Error("Preview source unavailable");const n=await L(o);try{const i=H(t,n),a=n.tail.then(()=>C(n,t.time,i,e));n.tail=a.then(()=>{},()=>{});const u=await a;let c=!1;return b(),{source:u.image,timestamp:u.timestamp,duration:u.duration,width:n.width,height:n.height,release(){c||(c=!0,u.pins--,b(),P(n))}}}finally{n.users--,P(n)}};return{async decode(t,e){if(f)throw new DOMException("Preview disposed","AbortError");if(new Set(t.map(({source:a})=>a)).size>M)throw new Error("Preview decoder budget reached");const o=await Promise.allSettled(t.map(a=>N(a,e))),n=o.find(a=>a.status==="rejected"),i=o.flatMap(a=>a.status==="fulfilled"?[a.value]:[]);if(n||f||e.aborted){for(const a of i)a.release();throw n?n.reason:new DOMException("Preview cancelled","AbortError")}return i},async suspend(){const t=[...s.values()].map(e=>e.then(v).catch(()=>{}));s.clear();for(const[e,o]of l)o(),e.dispose();await Promise.all(t)},dispose(){if(!f){f=!0;for(const[t,e]of l)e(),t.dispose();for(const t of s.values())t.then(v).catch(()=>{});s.clear(),d.clear()}}}}export{ot as createPausedVideoDecoder};
|
package/dist/index.d.ts
CHANGED
|
@@ -2458,6 +2458,7 @@ type Found = PreviewElement | null | undefined;
|
|
|
2458
2458
|
declare function findPreviewElementForSelection(iframe: HTMLIFrameElement, selection: SelectionLookupTarget, activeCompositionPath: string | null): Promise<Found>;
|
|
2459
2459
|
/** `findElementForTimelineElement` over the frame's runtime. */
|
|
2460
2460
|
declare function findPreviewElementForTimelineElement(iframe: HTMLIFrameElement, element: TimelineElementDomTarget, options: TimelineElementDomTargetOptions): Promise<Found>;
|
|
2461
|
+
declare const standInHandle: (element: Element) => string | undefined;
|
|
2461
2462
|
|
|
2462
2463
|
interface AudioGainDialogState {
|
|
2463
2464
|
targetKeys: readonly string[] | null;
|
|
@@ -4501,4 +4502,4 @@ declare function buildStudioTools(depsRef: {
|
|
|
4501
4502
|
readonly current: StudioAgentToolsDeps;
|
|
4502
4503
|
}): ModelContextTool[];
|
|
4503
4504
|
|
|
4504
|
-
export { type AgentModalAnchorPoint, type AgentPromptElementInfo, AskAgentModal, type AskAgentModalProps, AudioMeterStrip, type AudioMeterStripProps, AudioWaveform, type AudioWaveformProps, type BlockedTimelineEditIntent, type CanEditTimelineElement, ColorField, CompositionBreadcrumb, type CompositionDimensions, type CompositionLevel, CompositionThumbnail, ConnectedDomEditOverlay, type ConnectedDomEditOverlayProps, DEFAULT_SHORTCUT_SECTIONS, Dock, type DockController, type DomEditCapabilities, type DomEditCommitDeclineReason, type DomEditCommitOutcome, type DomEditGroupPathOffsetCommit, DomEditOverlay, type DomEditOverlayProps, DomEditProvider, type DomEditSelection, type DomEditZOrder, type DomGeometryCommits, type EditHistoryHandle, EditorShell, type EditorShellProps, type ExternalFileChangeBlockedState, type ExternalFileChangeCoordinatorHandle, ExternalFileConflictBanner, type FadeEdge, type FadeHandleBox, type FadeHandleClipBox, type FfmpegStatus, FileTree, GradientField, GridOverlay, ImageThumbnail, type ImageThumbnailProps, LayersPanel, type LayersPanelHost, type LinkShortcutCallbacks, type MarqueeBand, type MarqueeGestures, type MarqueeGesturesDeps, MarqueeOverlay, type MarqueeOverlayProps, type Rect$1 as MarqueeRect, type MarqueeSelectionMode, type ModelContextTool, NLEPreview, type PanelId, type PatchOperation, type PersistedRenderSettings, type PickedElement, type PlaybackHealth, PlayerControls, type PlayerHandle, type PlayerHandleElement, type PlayerHandleListener, type PlayerHandleTimeListener, type DomEditCompositionRect as PreviewCompositionRect, type PreviewCopies, type PreviewElement, type PreviewElementHit, type PreviewFacts, PreviewGuides, PreviewOverlayProvider, type PreviewOverlayProviderProps, type PreviewPromotion, type PreviewQualityChosenBy, PreviewReadOnlyProvider, type PreviewSnapPreferences, PropertyPanel, type RenderJob, RenderQueue, type RenderQueueProps, type ResolutionPreset, SNAP_THRESHOLD_PX, type ShortcutHint, type ShortcutSection, ShortcutsButton, type ShortcutsButtonProps, type SnapContext, type SnapEdge, type SnapGuide, SnapGuideOverlay, type SnapGuideOverlayProps, type SnapGuidesState, type Rect as SnapRect, type SnapResult, type SnapTarget, SnapToolbar, SourceEditor, type SpacingGuide, type StartRenderOptions, type StudioAgentToolsDeps, StudioApp, StudioFileConflictError, StudioKeyAction, StudioKeys, type StudioLookSnapshot, type StudioPendingEditsDrainResult, TRACK_H, type ThumbnailPriority, type ThumbnailStill, Timeline, TimelineClipMenu, type TimelineClipMenuItem, type TimelineClipRenderContext, type TimelineEditCallbacks, type TimelineEditOutcome, type TimelineEditPermission, TimelineEditPopover, TimelineEditProvider, type TimelineElement, TimelineEmptyStatePart, TimelineFrame, TimelineGapMenu, TimelineHistoryButtons, type TimelineHistoryButtonsProps, TimelineKeyframeMenu, TimelineLanes, TimelineOverlays, TimelinePane, type TimelinePaneProps, TimelinePlayhead, TimelineProvider, TimelineRazorGuide, TimelineRuler, TimelineShortcutHint, type TimelineTheme, type TimelineTimeRange$1 as TimelineTimeRange, TimelineToolbar, type TimelineToolbarProps, type TimelineTrackPadding, type TimelineZIndexReorderCommit, type ToolResult, type UseClipboardOptions, type UseDomEditSessionParams, type UseDomGeometryCommitOptions, type UseDomStyleCommitOptions, type UseEditHistoryActionsOptions, type UsePersistentEditHistoryOptions, type UsePreviewPersistenceParams, type UseProjectFileWriterOptions, type UseRenderClipContentOptions, type UseThumbnailStillOptions, type UseTimelineEditingOptions, VideoThumbnail, type ZOrderAction, announcePreviewDocumentLoaded, applyPatch, buildCompositionSnapTarget, buildGridSnapEdges, buildPickerAgentContextPreview, buildPickerAgentPrompt, buildShortcutSections, buildStudioTools, cancelNewestStudioWaitingPress, collectSnapContext, collectStudioLookScene, currentTimelineRange, describePreviewElements, dispatchLinkShortcut, displayTrackOrder, extractSnapTargets, fadeHandleBoxes, findElementBlock, findPreviewElementForSelection, findPreviewElementForTimelineElement, flushStudioPendingEdits, formatTime, getPersistedRenderSettings, getStudioKeys, liveTime, mergeStyleIntoTag, openAudioGainDialog, parseStyleString, persistRenderSettings, previewAncestors, previewEditingClient, previewElementsAtPoint, previewFrameOpaque, previewGeometry, previewLayers, previewPointerTargets, queryPreviewElements, readable, resolveDomEditSelection, resolveEquidistanceGuides, resolveGuideLineRect, resolveIframe, resolveMarqueeMode, resolveSnapAdjustment, resolveSourceFile, revertNewestStudioPendingEdit, setStudioKeys, snapEngagedForTravel, standInFor, studioKeyClash, useAudioGainDialogStore, useAudioMetersVisible, useClipboard, useCompositionStack, useDockLayoutStore, useDomEditSelectionContext, useDomEditSession, useDomEditZOrder, useDomGeometryCommit, useDomStyleCommit, useEditHistoryActions, useElementPicker, useLivePreviewIframe, useMarqueeGestures, usePersistentEditHistory, usePlayerHandle, usePlayerStore, usePreviewCompositionRect, usePreviewGuidesStore, usePreviewIframeStore, usePreviewOverlayContext, usePreviewPersistence, useProjectFileWriter, useRenderClipContent, useRenderQueue, useStudioKeys, useThumbnailStill, useTimelineContext, useTimelineEditing, useTimelinePlayer, zoomTimelineToRange };
|
|
4505
|
+
export { type AgentModalAnchorPoint, type AgentPromptElementInfo, AskAgentModal, type AskAgentModalProps, AudioMeterStrip, type AudioMeterStripProps, AudioWaveform, type AudioWaveformProps, type BlockedTimelineEditIntent, type CanEditTimelineElement, ColorField, CompositionBreadcrumb, type CompositionDimensions, type CompositionLevel, CompositionThumbnail, ConnectedDomEditOverlay, type ConnectedDomEditOverlayProps, DEFAULT_SHORTCUT_SECTIONS, Dock, type DockController, type DomEditCapabilities, type DomEditCommitDeclineReason, type DomEditCommitOutcome, type DomEditGroupPathOffsetCommit, DomEditOverlay, type DomEditOverlayProps, DomEditProvider, type DomEditSelection, type DomEditZOrder, type DomGeometryCommits, type EditHistoryHandle, EditorShell, type EditorShellProps, type ExternalFileChangeBlockedState, type ExternalFileChangeCoordinatorHandle, ExternalFileConflictBanner, type FadeEdge, type FadeHandleBox, type FadeHandleClipBox, type FfmpegStatus, FileTree, GradientField, GridOverlay, ImageThumbnail, type ImageThumbnailProps, LayersPanel, type LayersPanelHost, type LinkShortcutCallbacks, type MarqueeBand, type MarqueeGestures, type MarqueeGesturesDeps, MarqueeOverlay, type MarqueeOverlayProps, type Rect$1 as MarqueeRect, type MarqueeSelectionMode, type ModelContextTool, NLEPreview, type PanelId, type PatchOperation, type PersistedRenderSettings, type PickedElement, type PlaybackHealth, PlayerControls, type PlayerHandle, type PlayerHandleElement, type PlayerHandleListener, type PlayerHandleTimeListener, type DomEditCompositionRect as PreviewCompositionRect, type PreviewCopies, type PreviewElement, type PreviewElementHit, type PreviewFacts, PreviewGuides, PreviewOverlayProvider, type PreviewOverlayProviderProps, type PreviewPromotion, type PreviewQualityChosenBy, PreviewReadOnlyProvider, type PreviewSnapPreferences, PropertyPanel, type RenderJob, RenderQueue, type RenderQueueProps, type ResolutionPreset, SNAP_THRESHOLD_PX, type ShortcutHint, type ShortcutSection, ShortcutsButton, type ShortcutsButtonProps, type SnapContext, type SnapEdge, type SnapGuide, SnapGuideOverlay, type SnapGuideOverlayProps, type SnapGuidesState, type Rect as SnapRect, type SnapResult, type SnapTarget, SnapToolbar, SourceEditor, type SpacingGuide, type StartRenderOptions, type StudioAgentToolsDeps, StudioApp, StudioFileConflictError, StudioKeyAction, StudioKeys, type StudioLookSnapshot, type StudioPendingEditsDrainResult, TRACK_H, type ThumbnailPriority, type ThumbnailStill, Timeline, TimelineClipMenu, type TimelineClipMenuItem, type TimelineClipRenderContext, type TimelineEditCallbacks, type TimelineEditOutcome, type TimelineEditPermission, TimelineEditPopover, TimelineEditProvider, type TimelineElement, TimelineEmptyStatePart, TimelineFrame, TimelineGapMenu, TimelineHistoryButtons, type TimelineHistoryButtonsProps, TimelineKeyframeMenu, TimelineLanes, TimelineOverlays, TimelinePane, type TimelinePaneProps, TimelinePlayhead, TimelineProvider, TimelineRazorGuide, TimelineRuler, TimelineShortcutHint, type TimelineTheme, type TimelineTimeRange$1 as TimelineTimeRange, TimelineToolbar, type TimelineToolbarProps, type TimelineTrackPadding, type TimelineZIndexReorderCommit, type ToolResult, type UseClipboardOptions, type UseDomEditSessionParams, type UseDomGeometryCommitOptions, type UseDomStyleCommitOptions, type UseEditHistoryActionsOptions, type UsePersistentEditHistoryOptions, type UsePreviewPersistenceParams, type UseProjectFileWriterOptions, type UseRenderClipContentOptions, type UseThumbnailStillOptions, type UseTimelineEditingOptions, VideoThumbnail, type ZOrderAction, announcePreviewDocumentLoaded, applyPatch, buildCompositionSnapTarget, buildGridSnapEdges, buildPickerAgentContextPreview, buildPickerAgentPrompt, buildShortcutSections, buildStudioTools, cancelNewestStudioWaitingPress, collectSnapContext, collectStudioLookScene, currentTimelineRange, describePreviewElements, dispatchLinkShortcut, displayTrackOrder, extractSnapTargets, fadeHandleBoxes, findElementBlock, findPreviewElementForSelection, findPreviewElementForTimelineElement, flushStudioPendingEdits, formatTime, getPersistedRenderSettings, getStudioKeys, liveTime, mergeStyleIntoTag, openAudioGainDialog, parseStyleString, persistRenderSettings, previewAncestors, previewEditingClient, previewElementsAtPoint, previewFrameOpaque, previewGeometry, previewLayers, previewPointerTargets, queryPreviewElements, readable, resolveDomEditSelection, resolveEquidistanceGuides, resolveGuideLineRect, resolveIframe, resolveMarqueeMode, resolveSnapAdjustment, resolveSourceFile, revertNewestStudioPendingEdit, setStudioKeys, snapEngagedForTravel, standInFor, standInHandle, studioKeyClash, useAudioGainDialogStore, useAudioMetersVisible, useClipboard, useCompositionStack, useDockLayoutStore, useDomEditSelectionContext, useDomEditSession, useDomEditZOrder, useDomGeometryCommit, useDomStyleCommit, useEditHistoryActions, useElementPicker, useLivePreviewIframe, useMarqueeGestures, usePersistentEditHistory, usePlayerHandle, usePlayerStore, usePreviewCompositionRect, usePreviewGuidesStore, usePreviewIframeStore, usePreviewOverlayContext, usePreviewPersistence, useProjectFileWriter, useRenderClipContent, useRenderQueue, useStudioKeys, useThumbnailStill, useTimelineContext, useTimelineEditing, useTimelinePlayer, zoomTimelineToRange };
|
package/dist/index.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
document.documentElement.dataset.theme = "paper";
|
|
15
15
|
}
|
|
16
16
|
</script>
|
|
17
|
-
<script type="module" crossorigin src="/assets/index-
|
|
17
|
+
<script type="module" crossorigin src="/assets/index-Bxh5lW0C.js"></script>
|
|
18
18
|
<link rel="stylesheet" crossorigin href="/assets/index-CRiuMxyq.css">
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
package/dist/index.js
CHANGED
|
@@ -1605,6 +1605,12 @@ function isMusicTrack(element) {
|
|
|
1605
1605
|
const id = element.domId ?? element.id ?? "";
|
|
1606
1606
|
return MUSIC_ID_RE.test(id);
|
|
1607
1607
|
}
|
|
1608
|
+
var MAX_BEAT_SOURCE_SECONDS = 15 * 60;
|
|
1609
|
+
function fitsBeatAnalysis({
|
|
1610
|
+
sourceDuration
|
|
1611
|
+
}) {
|
|
1612
|
+
return sourceDuration != null && sourceDuration <= MAX_BEAT_SOURCE_SECONDS;
|
|
1613
|
+
}
|
|
1608
1614
|
function resolveBeatSourceTrack(elements) {
|
|
1609
1615
|
const explicit = elements.find(isMusicTrack);
|
|
1610
1616
|
if (explicit) return { element: explicit, isFallback: false };
|
|
@@ -1612,6 +1618,7 @@ function resolveBeatSourceTrack(elements) {
|
|
|
1612
1618
|
for (const el of elements) {
|
|
1613
1619
|
if (!isMusicSourceElement(el)) continue;
|
|
1614
1620
|
if (el.timelineRole && el.timelineRole !== "music") continue;
|
|
1621
|
+
if (!fitsBeatAnalysis(el)) continue;
|
|
1615
1622
|
if (!best || el.duration > best.duration) best = el;
|
|
1616
1623
|
}
|
|
1617
1624
|
return best ? { element: best, isFallback: true } : null;
|
|
@@ -2021,42 +2028,43 @@ function cacheAnalysis(url, promise) {
|
|
|
2021
2028
|
analysisCache.delete(oldest);
|
|
2022
2029
|
}
|
|
2023
2030
|
}
|
|
2024
|
-
async function
|
|
2025
|
-
if (!beatPath) return { ...detected, hasFile: false };
|
|
2031
|
+
async function readSavedBeats(io, beatPath) {
|
|
2026
2032
|
try {
|
|
2027
2033
|
const content = await io.readOptionalProjectFile(beatPath);
|
|
2028
2034
|
const parsed = content ? parseBeats(content) : null;
|
|
2029
|
-
|
|
2030
|
-
return { times: parsed.times, strengths: parsed.strengths, hasFile: true };
|
|
2031
|
-
}
|
|
2035
|
+
return parsed && parsed.times.length > 0 ? { times: parsed.times, strengths: parsed.strengths } : null;
|
|
2032
2036
|
} catch {
|
|
2033
|
-
|
|
2034
|
-
return { ...detected, hasFile: false };
|
|
2035
|
-
}
|
|
2036
|
-
async function readHasSavedBeats(io, beatPath) {
|
|
2037
|
-
try {
|
|
2038
|
-
const content = await io.readOptionalProjectFile(beatPath);
|
|
2039
|
-
const parsed = content ? parseBeats(content) : null;
|
|
2040
|
-
return !!(parsed && parsed.times.length > 0);
|
|
2041
|
-
} catch {
|
|
2042
|
-
return false;
|
|
2037
|
+
return null;
|
|
2043
2038
|
}
|
|
2044
2039
|
}
|
|
2045
|
-
async function
|
|
2040
|
+
async function decodeTrack(musicSrc) {
|
|
2046
2041
|
let promise = analysisCache.get(musicSrc);
|
|
2047
2042
|
if (!promise) {
|
|
2048
2043
|
promise = analyzeMusicFromUrl(musicSrc, { pause: whenTimelineIdle });
|
|
2049
2044
|
cacheAnalysis(musicSrc, promise);
|
|
2050
2045
|
}
|
|
2051
|
-
|
|
2052
|
-
const analysis = await promise;
|
|
2053
|
-
const detected = { times: analysis.beatTimes, strengths: analysis.beatStrengths };
|
|
2054
|
-
const { times, strengths } = await resolveBeats(beatPath, detected, io);
|
|
2055
|
-
return { analysis, times, strengths };
|
|
2056
|
-
} catch {
|
|
2057
|
-
return null;
|
|
2058
|
-
}
|
|
2046
|
+
return promise.catch(() => null);
|
|
2059
2047
|
}
|
|
2048
|
+
async function loadTrack(musicSrc, beatPath, io, isFallbackTrack, decodable) {
|
|
2049
|
+
const saved2 = await readSavedBeats(io, beatPath);
|
|
2050
|
+
if (!isFallbackTrack && !saved2) return null;
|
|
2051
|
+
if (!decodable) return saved2 && { analysis: savedOnly(saved2), ...saved2 };
|
|
2052
|
+
const analysis = await decodeTrack(musicSrc);
|
|
2053
|
+
if (!analysis) return null;
|
|
2054
|
+
return {
|
|
2055
|
+
analysis,
|
|
2056
|
+
...saved2 ?? { times: analysis.beatTimes, strengths: analysis.beatStrengths }
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
var savedOnly = ({ times, strengths }) => ({
|
|
2060
|
+
beatTimes: times,
|
|
2061
|
+
beatStrengths: strengths,
|
|
2062
|
+
bpm: null,
|
|
2063
|
+
bpmConfidence: "uncertain",
|
|
2064
|
+
channelData: null,
|
|
2065
|
+
sampleRate: 0,
|
|
2066
|
+
peak: 0
|
|
2067
|
+
});
|
|
2060
2068
|
function useAdjustedBeatAnalysis() {
|
|
2061
2069
|
const beatAnalysis = usePlayerStore((s) => s.beatAnalysis);
|
|
2062
2070
|
const musicElement = usePlayerStore((s) => getTimelineElementIndexes(s.elements).musicElement);
|
|
@@ -2077,13 +2085,16 @@ function useMusicBeatAnalysis() {
|
|
|
2077
2085
|
const writeProjectFile = fileManager?.writeProjectFile;
|
|
2078
2086
|
const ioRef = useRef5(null);
|
|
2079
2087
|
ioRef.current = readOptionalProjectFile && writeProjectFile ? { readOptionalProjectFile, writeProjectFile } : null;
|
|
2080
|
-
const { musicSrc, isFallbackTrack } = useMemo2(() => {
|
|
2088
|
+
const { musicSrc, isFallbackTrack, decodable } = useMemo2(() => {
|
|
2081
2089
|
const resolved2 = resolveBeatSourceTrack(elements);
|
|
2082
2090
|
return {
|
|
2083
2091
|
musicSrc: resolved2?.element.src ?? null,
|
|
2084
|
-
isFallbackTrack: resolved2?.isFallback ?? false
|
|
2092
|
+
isFallbackTrack: resolved2?.isFallback ?? false,
|
|
2093
|
+
decodable: resolved2 ? fitsBeatAnalysis(resolved2.element) : false
|
|
2085
2094
|
};
|
|
2086
2095
|
}, [elements]);
|
|
2096
|
+
const decodableRef = useRef5(decodable);
|
|
2097
|
+
decodableRef.current = decodable;
|
|
2087
2098
|
useEffect5(() => {
|
|
2088
2099
|
if (!musicSrc) {
|
|
2089
2100
|
setBeatAnalysis(null);
|
|
@@ -2102,16 +2113,7 @@ function useMusicBeatAnalysis() {
|
|
|
2102
2113
|
const io = ioRef.current;
|
|
2103
2114
|
(async () => {
|
|
2104
2115
|
if (!beatPath || !io) return;
|
|
2105
|
-
|
|
2106
|
-
const hasSavedBeats = await readHasSavedBeats(io, beatPath);
|
|
2107
|
-
if (cancelled) return;
|
|
2108
|
-
if (!hasSavedBeats) {
|
|
2109
|
-
setBeatAnalysis(null);
|
|
2110
|
-
return;
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
if (cancelled) return;
|
|
2114
|
-
const result = await loadBeatAnalysis(musicSrc, beatPath, io);
|
|
2116
|
+
const result = await loadTrack(musicSrc, beatPath, io, isFallbackTrack, decodableRef.current);
|
|
2115
2117
|
if (cancelled) return;
|
|
2116
2118
|
if (!result) {
|
|
2117
2119
|
setBeatAnalysis(null);
|
|
@@ -38585,6 +38587,7 @@ function readHit(value) {
|
|
|
38585
38587
|
function readPreviewElement(value) {
|
|
38586
38588
|
if (!readHit(value) || !isFields(value)) return null;
|
|
38587
38589
|
if (value.parent !== null && !isHandle(value.parent)) return null;
|
|
38590
|
+
if (value.label !== void 0 && !isText(value.label)) return null;
|
|
38588
38591
|
if (!isTextOrNull(value.id) || !isTextOrNull(value.selector)) return null;
|
|
38589
38592
|
if (!isSource(value.source) || typeof value.locked !== "boolean") return null;
|
|
38590
38593
|
if (!isTextRecord(value.inlineStyles) || !isText(value.text)) return null;
|
|
@@ -55574,8 +55577,9 @@ function renderAudioClip(el, pid, sessionEpoch, labelColor, context, labelInset)
|
|
|
55574
55577
|
const encodedRelative = srcRelative ? encodePreviewPath(srcRelative) : null;
|
|
55575
55578
|
const waveformUrl = encodedRelative ? buildProjectApiPath(pid, `/waveform/${encodedRelative}`) : void 0;
|
|
55576
55579
|
const { start, end } = trimFractions(el);
|
|
55580
|
+
const serverPeaksOrShortFile = waveformUrl !== void 0 || fitsBeatAnalysis(el);
|
|
55577
55581
|
const waveform = createElement(AudioWaveform, {
|
|
55578
|
-
audioUrl,
|
|
55582
|
+
audioUrl: serverPeaksOrShortFile ? audioUrl : "",
|
|
55579
55583
|
waveformUrl,
|
|
55580
55584
|
label: "",
|
|
55581
55585
|
labelColor,
|
|
@@ -69247,7 +69251,7 @@ import { timeAtSourceTime as timeAtSourceTime2 } from "@hyperframes/core/speed-r
|
|
|
69247
69251
|
var DECODE_SAMPLE_RATE2 = 48e3;
|
|
69248
69252
|
function useFxLevelling(element, chain, automation, onSetAttributeQuiet, onSetAttributeLive, setAnalysing) {
|
|
69249
69253
|
const decoded = useRef109(null);
|
|
69250
|
-
const
|
|
69254
|
+
const decodeTrack2 = async () => {
|
|
69251
69255
|
const el = element.element;
|
|
69252
69256
|
const src = el?.getAttribute("src");
|
|
69253
69257
|
const doc = el?.ownerDocument;
|
|
@@ -69279,7 +69283,7 @@ function useFxLevelling(element, chain, automation, onSetAttributeQuiet, onSetAt
|
|
|
69279
69283
|
const runLeveller = async () => {
|
|
69280
69284
|
setAnalysing(true);
|
|
69281
69285
|
try {
|
|
69282
|
-
const audio = await
|
|
69286
|
+
const audio = await decodeTrack2();
|
|
69283
69287
|
if (!audio) return;
|
|
69284
69288
|
const result = measureLevelling(audio);
|
|
69285
69289
|
if (!result) return;
|
|
@@ -69311,7 +69315,7 @@ function useFxLevelling(element, chain, automation, onSetAttributeQuiet, onSetAt
|
|
|
69311
69315
|
const startLevelAudition = async (run) => {
|
|
69312
69316
|
setAuditioningLevel(true);
|
|
69313
69317
|
try {
|
|
69314
|
-
const audio = await
|
|
69318
|
+
const audio = await decodeTrack2();
|
|
69315
69319
|
if (!audio || run !== auditionRun.current) return;
|
|
69316
69320
|
const result = measureLevelling(audio);
|
|
69317
69321
|
if (!result || run !== auditionRun.current) return;
|
|
@@ -104919,6 +104923,7 @@ export {
|
|
|
104919
104923
|
setStudioKeys,
|
|
104920
104924
|
snapEngagedForTravel,
|
|
104921
104925
|
standInFor,
|
|
104926
|
+
standInHandle,
|
|
104922
104927
|
studioKeyClash,
|
|
104923
104928
|
useAudioGainDialogStore,
|
|
104924
104929
|
useAudioMetersVisible,
|
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/
|
|
68
|
-
"@hyperframes/
|
|
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",
|
|
@@ -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
|
@@ -62,6 +62,7 @@ export {
|
|
|
62
62
|
findPreviewElementForTimelineElement,
|
|
63
63
|
readable,
|
|
64
64
|
standInFor,
|
|
65
|
+
standInHandle,
|
|
65
66
|
} from "./components/editor/previewSelection";
|
|
66
67
|
export { PREVIEW_QUALITY_LEVELS, type PreviewQuality } from "@hyperframes/core/preview-quality";
|
|
67
68
|
export type {
|